Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HHH-14370 + HHH-14371 + HHH-14372 - Add required --add-opens options for Gradle, Weld, Javassist #3677

Merged
merged 9 commits into from
Dec 14, 2020
5 changes: 3 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Keep all these properties in sync unless you know what you are doing!
org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=256m -XX:+HeapDumpOnOutOfMemoryError -Duser.language=en -Duser.country=US -Duser.timezone=UTC -Dfile.encoding=UTF-8
toolchain.compiler.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=256m -XX:+HeapDumpOnOutOfMemoryError -Duser.language=en -Duser.country=US -Duser.timezone=UTC -Dfile.encoding=UTF-8
# Needs add-opens because of https://github.com/gradle/gradle/issues/15538
toolchain.compiler.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=256m -XX:+HeapDumpOnOutOfMemoryError -Duser.language=en -Duser.country=US -Duser.timezone=UTC -Dfile.encoding=UTF-8 --add-opens jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
toolchain.javadoc.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=256m -XX:+HeapDumpOnOutOfMemoryError -Duser.language=en -Duser.country=US -Duser.timezone=UTC -Dfile.encoding=UTF-8
toolchain.launcher.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=256m -XX:+HeapDumpOnOutOfMemoryError -Duser.language=en -Duser.country=US -Duser.timezone=UTC -Dfile.encoding=UTF-8

Expand All @@ -13,4 +14,4 @@ toolchain.launcher.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=256m -XX:+HeapDumpOnOutOf
org.gradle.java.installations.auto-detect=false
# We can't rely on Gradle's auto-download of JDKs as it doesn't support EA releases.
# See https://github.com/gradle/gradle/blob/fc7ea24f3c525d8d12a4346eb0f15976a6be9414/subprojects/platform-jvm/src/main/java/org/gradle/jvm/toolchain/install/internal/AdoptOpenJdkRemoteBinary.java#L114
org.gradle.java.installations.auto-download=false
org.gradle.java.installations.auto-download=false
2 changes: 1 addition & 1 deletion gradle/java-module.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ if ( gradle.ext.javaToolchainEnabled ) {
}

// Configure JVM Options
jvmArgs.addAll( getProperty( 'toolchain.launcher.jvmargs' ).toString().split( ' ' ) )
jvmArgs( getProperty( 'toolchain.launcher.jvmargs' ).toString().split( ' ' ) )

// Display version of Java tools
doFirst {
Expand Down
2 changes: 1 addition & 1 deletion gradle/libraries.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ext {
elVersion = '3.0.1-b09'

cdiVersion = '2.0'
weldVersion = '3.0.0.Final'
weldVersion = '3.1.5.Final'

javassistVersion = '3.27.0-GA'
byteBuddyVersion = '1.10.17'
Expand Down
16 changes: 15 additions & 1 deletion hibernate-core/hibernate-core.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,15 @@ artifacts {

test {
systemProperty 'file.encoding', 'utf-8'

if ( gradle.ext.javaVersions.test.launcher.asInt() >= 9 ) {
// See org.hibernate.boot.model.naming.NamingHelperTest.DefaultCharset.set
jvmArgs( ['--add-opens', 'java.base/java.nio.charset=ALL-UNNAMED'] )
// Weld needs this to generate proxies
jvmArgs( ['--add-opens', 'java.base/java.security=ALL-UNNAMED'] )
jvmArgs( ['--add-opens', 'java.base/java.lang=ALL-UNNAMED'] )
}

beforeTest { descriptor ->
//println "Starting test: " + descriptor
}
Expand All @@ -260,13 +269,18 @@ task testJavassist(type: Test) {
}

// Configure JVM Options
jvmArgs.addAll( getProperty( 'toolchain.launcher.jvmargs' ).toString().split( ' ' ) )
jvmArgs( getProperty( 'toolchain.launcher.jvmargs' ).toString().split( ' ' ) )

// Display version of Java tools
doFirst {
logger.lifecycle "Testing javassist with '${javaLauncher.get().metadata.installationPath}'"
}
}

if ( gradle.ext.javaVersions.test.launcher.asInt() >= 9 ) {
// Javassist needs this to generate proxies
jvmArgs( ['--add-opens', 'java.base/java.lang=ALL-UNNAMED'] )
}
}

check.dependsOn testJavassist
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import org.hibernate.bytecode.internal.javassist.BulkAccessor;
import org.hibernate.bytecode.spi.BytecodeProvider;
import org.hibernate.bytecode.spi.ReflectionOptimizer;
import org.hibernate.cfg.Environment;
Expand All @@ -21,15 +20,6 @@
* @author Steve Ebersole
*/
public class ReflectionOptimizerTest extends BaseUnitTestCase {
@Test
public void testBulkAccessorDirectly() {
BulkAccessor bulkAccessor = BulkAccessor.create(
Bean.class,
BeanReflectionHelper.getGetterNames(),
BeanReflectionHelper.getSetterNames(),
BeanReflectionHelper.getTypes()
);
}

@Test
public void testReflectionOptimization() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.bytecode.javassist;
import java.text.ParseException;
import java.util.Date;

/**
* @author Steve Ebersole
*/
public class Bean {
private String someString;
private Long someLong;
private Integer someInteger;
private Date someDate;
private long somelong;
private int someint;
private Object someObject;


public String getSomeString() {
return someString;
}

public void setSomeString(String someString) {
this.someString = someString;
}

public Long getSomeLong() {
return someLong;
}

public void setSomeLong(Long someLong) {
this.someLong = someLong;
}

public Integer getSomeInteger() {
return someInteger;
}

public void setSomeInteger(Integer someInteger) {
this.someInteger = someInteger;
}

public Date getSomeDate() {
return someDate;
}

public void setSomeDate(Date someDate) {
this.someDate = someDate;
}

public long getSomelong() {
return somelong;
}

public void setSomelong(long somelong) {
this.somelong = somelong;
}

public int getSomeint() {
return someint;
}

public void setSomeint(int someint) {
this.someint = someint;
}

public Object getSomeObject() {
return someObject;
}

public void setSomeObject(Object someObject) {
this.someObject = someObject;
}

public void throwException() throws ParseException {
throw new ParseException( "you asked for it...", 0 );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.bytecode.javassist;
import java.util.Date;

import org.hibernate.property.access.internal.PropertyAccessStrategyBasicImpl;
import org.hibernate.property.access.spi.Getter;
import org.hibernate.property.access.spi.PropertyAccess;
import org.hibernate.property.access.spi.Setter;

/**
* @author Steve Ebersole
*/
public class BeanReflectionHelper {

public static final Object[] TEST_VALUES = new Object[] {
"hello", new Long(1), new Integer(1), new Date(), new Long(1), new Integer(1), new Object()
};

private static final String[] getterNames = new String[7];
private static final String[] setterNames = new String[7];
private static final Class[] types = new Class[7];

static {
final PropertyAccessStrategyBasicImpl propertyAccessStrategy = new PropertyAccessStrategyBasicImpl();

PropertyAccess propertyAccess = propertyAccessStrategy.buildPropertyAccess( Bean.class, "someString" );
Getter getter = propertyAccess.getGetter();
Setter setter = propertyAccess.getSetter();
getterNames[0] = getter.getMethodName();
types[0] = getter.getReturnType();
setterNames[0] = setter.getMethodName();

propertyAccess = propertyAccessStrategy.buildPropertyAccess( Bean.class, "someLong" );
getter = propertyAccess.getGetter();
setter = propertyAccess.getSetter();
getterNames[1] = getter.getMethodName();
types[1] = getter.getReturnType();
setterNames[1] = setter.getMethodName();

propertyAccess = propertyAccessStrategy.buildPropertyAccess( Bean.class, "someInteger" );
getter = propertyAccess.getGetter();
setter = propertyAccess.getSetter();
getterNames[2] = getter.getMethodName();
types[2] = getter.getReturnType();
setterNames[2] = setter.getMethodName();

propertyAccess = propertyAccessStrategy.buildPropertyAccess( Bean.class, "someDate" );
getter = propertyAccess.getGetter();
setter = propertyAccess.getSetter();
getterNames[3] = getter.getMethodName();
types[3] = getter.getReturnType();
setterNames[3] = setter.getMethodName();

propertyAccess = propertyAccessStrategy.buildPropertyAccess( Bean.class, "somelong" );
getter = propertyAccess.getGetter();
setter = propertyAccess.getSetter();
getterNames[4] = getter.getMethodName();
types[4] = getter.getReturnType();
setterNames[4] = setter.getMethodName();

propertyAccess = propertyAccessStrategy.buildPropertyAccess( Bean.class, "someint" );
getter = propertyAccess.getGetter();
setter = propertyAccess.getSetter();
getterNames[5] = getter.getMethodName();
types[5] = getter.getReturnType();
setterNames[5] = setter.getMethodName();

propertyAccess = propertyAccessStrategy.buildPropertyAccess( Bean.class, "someObject" );
getter = propertyAccess.getGetter();
setter = propertyAccess.getSetter();
getterNames[6] = getter.getMethodName();
types[6] = getter.getReturnType();
setterNames[6] = setter.getMethodName();
}

public static String[] getGetterNames() {
return getterNames;
}

public static String[] getSetterNames() {
return setterNames;
}

public static Class[] getTypes() {
return types;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.bytecode.javassist;

import org.hibernate.bytecode.internal.javassist.BulkAccessor;

import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.junit.Test;

/**
* @author Steve Ebersole
*/
// Extracted from org.hibernate.test.bytecode.ReflectionOptimizerTest.
// I (Yoann) don't know what this tests does, but it's definitely specific to javassist.
public class BulkAccessorTest extends BaseUnitTestCase {

@Test
public void testBulkAccessorDirectly() {
BulkAccessor bulkAccessor = BulkAccessor.create(
Bean.class,
BeanReflectionHelper.getGetterNames(),
BeanReflectionHelper.getSetterNames(),
BeanReflectionHelper.getTypes()
);
}
}
12 changes: 12 additions & 0 deletions hibernate-proxool/hibernate-proxool.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,15 @@ dependencies {
compile( libraries.proxool )
testCompile project( ':hibernate-testing' )
}

test {
if ( gradle.ext.javaVersions.test.launcher.asInt() >= 9 ) {
// Proxool needs this to define classes for some reason. Stack trace:
// at org.logicalcobwebs.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:372)
// at org.logicalcobwebs.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:193)
// at org.logicalcobwebs.cglib.core.KeyFactory$Generator.create(KeyFactory.java:177)
// at org.logicalcobwebs.cglib.core.KeyFactory.create(KeyFactory.java:149)
// at org.logicalcobwebs.cglib.proxy.Enhancer.<clinit>(Enhancer.java:96)
jvmArgs( ['--add-opens', 'java.base/java.lang=ALL-UNNAMED'] )
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,10 @@ else {
logger.warn( "[WARN] Toolchains are not yet supported for Groovy compilation." +
" Using the JDK that runs Gradle for Groovy compilation." )
}

tasks.test {
if ( gradle.ext.javaVersions.test.launcher.asInt() >= 9 ) {
// Needs add-opens because Gradle uses illegal accesses to inject... mocks? Something like that.
jvmArgs( ['--add-opens', 'java.base/java.lang=ALL-UNNAMED'] )
}
}