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

Update Play source for build compability with JDK9+ #1252

Merged
merged 10 commits into from
Aug 7, 2018
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ samples-and-tests/test-scala/logs
samples-and-tests/i-am-a-developer/i-am-working-here
samples-and-tests/i-am-a-developer/i-am-creating-jobs-here
samples-and-tests/i-am-a-developer/i-am-testing-log-levels-here
samples-and-tests/i-am-a-developer/i-am-testing-ssl-config-here
samples-and-tests/just-test-cases/attachments
samples-and-tests/booking/logs
samples-and-tests/booking/tmp
Expand Down
7 changes: 3 additions & 4 deletions framework/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,9 @@
<tag name="play.todo" scope="all" description="To do:"/>
<tag name="todo" scope="all" description="To do:"/>
<group title="Libs" packages="play.libs.*"/>
<link offline="false" href="http://docs.oracle.com/javaee/7/api/" />
<link offline="false" href="https://docs.oracle.com/javase/8/docs/api//" />
<link offline="false" href="https://docs.oracle.com/javase/" />
<link offline="false" href="http://commons.apache.org/proper/commons-fileupload/apidocs/" />
<link offline="false" href="https://static.javadoc.io/com.google.code.gson/gson/2.8.0/" />
<link offline="false" href="https://www.javadoc.io/doc/com.google.code.gson/gson" />
<link offline="false" href="https://docs.jboss.org/hibernate/orm/4.2/javadocs/" />
<link offline="false" href="http://www.mchange.com/projects/c3p0/apidocs/" />
</javadoc>
Expand Down Expand Up @@ -234,7 +233,7 @@
<!-- Tests -->

<target name="compile-tests" depends="compile">
<javac encoding="utf-8" nowarn="${compile.nowarn}" debug="true" destdir="classes" classpathref="project.classpath" srcdir="tests/src" source="1.8" target="1.8">
<javac encoding="utf-8" nowarn="${compile.nowarn}" debug="true" destdir="classes" classpathref="project.classpath" srcdir="tests/src" source="1.8" target="1.8">
<include name="**/*.java"/>
</javac>
</target>
Expand Down
16 changes: 8 additions & 8 deletions framework/dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ transitiveDependencies: false
require: &allDependencies
- antlr 2.7.7
- com.mchange -> c3p0 0.9.5.2
- com.zaxxer -> HikariCP 2.7.9
- org.ow2.asm -> asm-all 5.2
- cglib -> cglib 3.2.4
- com.google.code.gson -> gson 2.8.0
- com.zaxxer -> HikariCP 3.2.0
- org.ow2.asm -> asm 6.2
- cglib -> cglib 3.2.7
- com.google.code.gson -> gson 2.8.5
- com.jamonapi -> jamon 2.81
- com.ning -> async-http-client 1.9.40
- commons-beanutils 1.9.2
Expand Down Expand Up @@ -45,15 +45,15 @@ require: &allDependencies
- org.apache.ivy -> ivy 2.4.0
- org.bouncycastle -> bcprov-jdk15on 1.60
- org.bouncycastle -> bcpkix-jdk15on 1.60
- org.codehaus.groovy -> groovy-all 2.4.15
- org.eclipse.jdt.core 3.12.3
- org.codehaus.groovy -> groovy 2.5.1
- org.codehaus.groovy -> groovy-xml 2.5.1
- org.eclipse.jdt -> org.eclipse.jdt.core 3.14.0
- org.hibernate -> hibernate-core 5.2.10.patched
- org.hibernate.common -> hibernate-commons-annotations 5.0.1.Final
- org.hibernate -> hibernate-entitymanager 5.2.10.Final
- org.hibernate -> hibernate-validator 5.4.1.Final
- org.jboss.logging -> jboss-logging 3.3.0.Final
- org.jboss.spec.javax.transaction -> jboss-transaction-api_1.2_spec 1.0.1.Final
- org.hibernate.javax.persistence -> hibernate-jpa-2.1-api 1.0.0.Final
- org.hibernate.javax.persistence -> hibernate-jpa-2.1-api 1.0.0.Final
- com.fasterxml -> classmate 1.3.3
- org.hibernate -> hibernate-c3p0 5.2.10.Final
- org.hibernate -> hibernate-ehcache 5.2.10.Final
Expand Down
Binary file added framework/lib-test/byte-buddy-1.8.15.jar
Binary file not shown.
Binary file removed framework/lib-test/mockito-all-1.10.19.jar
Binary file not shown.
Binary file added framework/lib-test/mockito-core-2.21.0.jar
Binary file not shown.
Binary file added framework/lib-test/objenesis-2.6.jar
Binary file not shown.
Binary file removed framework/lib/HikariCP-2.7.9.jar
Binary file not shown.
Binary file added framework/lib/HikariCP-3.2.0.jar
Binary file not shown.
Binary file added framework/lib/asm-6.2.jar
Binary file not shown.
Binary file not shown.
Binary file added framework/lib/groovy-2.5.1.jar
Binary file not shown.
Binary file removed framework/lib/groovy-all-2.4.15.jar
Binary file not shown.
Binary file added framework/lib/groovy-xml-2.5.1.jar
Binary file not shown.
Binary file removed framework/lib/gson-2.8.0.jar
Binary file not shown.
Binary file added framework/lib/gson-2.8.5.jar
Binary file not shown.
Binary file removed framework/lib/org.eclipse.jdt.core-3.12.3.jar
Binary file not shown.
Binary file added framework/lib/org.eclipse.jdt.core-3.14.0.jar
Binary file not shown.
38 changes: 23 additions & 15 deletions framework/src/play/classloading/ApplicationCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ public class ApplicationCompiler {
Map<String, Boolean> packagesCache = new HashMap<>();
ApplicationClasses applicationClasses;
Map<String, String> settings;
private static final String JAVA_SOURCE_DEFAULT_VERSION = "1.8";
static final Map<String, String> compatibleJavaVersions = new HashMap<>();

static {
compatibleJavaVersions.put("1.8", CompilerOptions.VERSION_1_8);
compatibleJavaVersions.put("9", CompilerOptions.VERSION_9);
compatibleJavaVersions.put("10", CompilerOptions.VERSION_10);
}

/**
* Try to guess the magic configuration options
Expand All @@ -53,21 +61,22 @@ public ApplicationCompiler(ApplicationClasses applicationClasses) {
this.settings.put(CompilerOptions.OPTION_ReportUnusedImport, CompilerOptions.IGNORE);
this.settings.put(CompilerOptions.OPTION_Encoding, "UTF-8");
this.settings.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.GENERATE);
String javaVersion = CompilerOptions.VERSION_1_8;
if (System.getProperty("java.version").startsWith("1.5") || System.getProperty("java.version").startsWith("1.6")
|| System.getProperty("java.version").startsWith("1.7")) {
throw new CompilationException("Java version prior to 1.8 are not supported");

final String runningJavaVersion = System.getProperty("java.version");
if (runningJavaVersion.startsWith("1.5") || runningJavaVersion.startsWith("1.6") || runningJavaVersion.startsWith("1.7")) {
throw new CompilationException("JDK version prior to 1.8 are not supported to run the application");
}

if ("1.5".equals(Play.configuration.get("java.source")) || "1.6".equals(Play.configuration.get("java.source"))
|| "1.7".equals(Play.configuration.get("java.source"))) {
throw new CompilationException("Java version prior to 1.8 are not supported");
final String configSourceVersion = Play.configuration.getProperty("java.source", JAVA_SOURCE_DEFAULT_VERSION);
final String jdtVersion = compatibleJavaVersions.get(configSourceVersion);
if (jdtVersion == null) {
throw new CompilationException(String.format("Incompatible Java version specified (%s). Compatible versions are: %s",
configSourceVersion, compatibleJavaVersions.keySet()));
}

this.settings.put(CompilerOptions.OPTION_Source, javaVersion);
this.settings.put(CompilerOptions.OPTION_TargetPlatform, javaVersion);
this.settings.put(CompilerOptions.OPTION_Source, jdtVersion);
this.settings.put(CompilerOptions.OPTION_TargetPlatform, jdtVersion);
this.settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.PRESERVE);
this.settings.put(CompilerOptions.OPTION_Compliance, javaVersion);
this.settings.put(CompilerOptions.OPTION_Compliance, jdtVersion);
this.settings.put(CompilerOptions.OPTION_MethodParametersAttribute, CompilerOptions.GENERATE);
}

Expand Down Expand Up @@ -161,8 +170,8 @@ public NameEnvironmentAnswer findType(char[][] compoundTypeName) {
@Override
public NameEnvironmentAnswer findType(char[] typeName, char[][] packageName) {
StringBuilder result = new StringBuilder(packageName.length * 7 + 1 + typeName.length);
for (int i = 0; i < packageName.length; i++) {
result.append(packageName[i]);
for (final char[] element : packageName) {
result.append(element);
result.append('.');
}
result.append(typeName);
Expand Down Expand Up @@ -271,8 +280,7 @@ public void acceptResult(CompilationResult result) {
}
// Something has been compiled
ClassFile[] clazzFiles = result.getClassFiles();
for (int i = 0; i < clazzFiles.length; i++) {
ClassFile clazzFile = clazzFiles[i];
for (final ClassFile clazzFile : clazzFiles) {
char[][] compoundName = clazzFile.getCompoundName();
StringBuilder clazzName = new StringBuilder();
for (int j = 0; j < compoundName.length; j++) {
Expand Down
3 changes: 3 additions & 0 deletions framework/src/play/data/parsing/MultipartStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ private void notifyListener() {
* @deprecated Use {@link #MultipartStream(InputStream, byte[], ProgressNotifier)},
* or {@link #MultipartStream(InputStream, byte[], int, ProgressNotifier)}
*/
@Deprecated
public MultipartStream() {
this(null, null, null);
}
Expand All @@ -256,6 +257,7 @@ public MultipartStream() {
* @see #MultipartStream(InputStream, byte[], ProgressNotifier)
* @deprecated Use {@link #MultipartStream(InputStream, byte[], int, ProgressNotifier)}.
*/
@Deprecated
public MultipartStream(InputStream input, byte[] boundary, int bufSize) {
this(input, boundary, bufSize, null);
}
Expand Down Expand Up @@ -328,6 +330,7 @@ public MultipartStream(InputStream input, byte[] boundary, int bufSize) {
* ProgressNotifier)}.
* @see #MultipartStream(InputStream, byte[], int, ProgressNotifier)
*/
@Deprecated
public MultipartStream(InputStream input,
byte[] boundary) {
this(input, boundary, DEFAULT_BUFSIZE, null);
Expand Down
8 changes: 3 additions & 5 deletions framework/src/play/db/DB.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@
import javax.sql.DataSource;
import javax.sql.RowSet;
import javax.sql.rowset.CachedRowSet;
import javax.sql.rowset.RowSetProvider;

import org.hibernate.jpa.HibernateEntityManager;
import org.hibernate.internal.SessionImpl;

import com.sun.rowset.CachedRowSetImpl;

import play.Logger;
import play.db.jpa.JPA;
import play.exceptions.DatabaseException;
Expand Down Expand Up @@ -178,7 +176,7 @@ public static void close(String name) {
public static Connection getConnection(String name) {
try {
if (JPA.isEnabled()) {
return ((SessionImpl) ((HibernateEntityManager) JPA.em(name)).getSession()).connection();
return ((SessionImpl) ((org.hibernate.Session) JPA.em(name)).getSession()).connection();
}

Connection localConnection = getLocalConnection(name);
Expand Down Expand Up @@ -274,7 +272,7 @@ public static RowSet executeQuery(String name, String SQL) {
// Need to use a CachedRowSet that caches its rows in memory, which
// makes it possible to operate without always being connected to
// its data source
CachedRowSet rowset = new CachedRowSetImpl();
CachedRowSet rowset = RowSetProvider.newFactory().createCachedRowSet();
rowset.populate(rs);
return rowset;
} catch (SQLException ex) {
Expand Down
21 changes: 10 additions & 11 deletions framework/src/play/db/evolutions/EvolutionQuery.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
package play.db.evolutions;

import play.Logger;
import play.Play;
import play.db.Configuration;
import play.db.DB;
import play.db.SQLSplitter;
import play.db.jpa.JPAPlugin;
import play.exceptions.UnexpectedException;

import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
Expand All @@ -17,10 +9,17 @@

import javax.sql.RowSet;
import javax.sql.rowset.CachedRowSet;
import javax.sql.rowset.RowSetProvider;

import org.apache.commons.lang.StringUtils;

import com.sun.rowset.CachedRowSetImpl;
import play.Logger;
import play.Play;
import play.db.Configuration;
import play.db.DB;
import play.db.SQLSplitter;
import play.db.jpa.JPAPlugin;
import play.exceptions.UnexpectedException;


public class EvolutionQuery{
Expand Down Expand Up @@ -158,7 +157,7 @@ public static RowSet getEvolutionsToApply(Connection connection, String moduleKe
// Need to use a CachedRowSet that caches its rows in memory, which
// makes it possible to operate without always being connected to
// its data source
CachedRowSet rowset = new CachedRowSetImpl();
CachedRowSet rowset = RowSetProvider.newFactory().createCachedRowSet();
rowset.populate(resultSet);
return rowset;
} catch (SQLException e) {
Expand All @@ -180,7 +179,7 @@ public static RowSet getEvolutions(Connection connection, String moduleKey) thro
// Need to use a CachedRowSet that caches its rows in memory, which
// makes it possible to operate without always being connected to
// its data source
CachedRowSet rowset = new CachedRowSetImpl();
CachedRowSet rowset = RowSetProvider.newFactory().createCachedRowSet();
rowset.populate(resultSet);
return rowset;
} catch (SQLException e) {
Expand Down
39 changes: 13 additions & 26 deletions framework/src/play/templates/GroovyTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,20 @@ public Class defineTemplate(String name, byte[] byteCode) {
}
}

@SuppressWarnings("unchecked")
@Override
void directLoad(byte[] code) throws Exception {
TClassLoader tClassLoader = new TClassLoader();
String[] lines = new String(code, "utf-8").split("\n");
this.linesMatrix = (HashMap<Integer, Integer>) Java.deserialize(Codec.decodeBASE64(lines[1]));
this.doBodyLines = (HashSet<Integer>) Java.deserialize(Codec.decodeBASE64(lines[3]));
for (int i = 4; i < lines.length; i = i + 2) {
String className = lines[i];
byte[] byteCode = Codec.decodeBASE64(lines[i + 1]);
Class c = tClassLoader.defineTemplate(className, byteCode);
if (compiledTemplate == null) {
compiledTemplate = c;
}
try (TClassLoader tClassLoader = new TClassLoader()) {
String[] lines = new String(code, "utf-8").split("\n");
this.linesMatrix = (HashMap<Integer, Integer>) Java.deserialize(Codec.decodeBASE64(lines[1]));
this.doBodyLines = (HashSet<Integer>) Java.deserialize(Codec.decodeBASE64(lines[3]));
for (int i = 4; i < lines.length; i = i + 2) {
String className = lines[i];
byte[] byteCode = Codec.decodeBASE64(lines[i + 1]);
Class c = tClassLoader.defineTemplate(className, byteCode);
if (compiledTemplate == null) {
compiledTemplate = c;
}
}
}
}

Expand Down Expand Up @@ -446,20 +446,7 @@ public void invokeTag(Integer fromLine, String tag, Map<String, Object> attrs, C
TagContext.exitTag();
}

/**
* @param className
* The class name
* @return The given class
* @throws Exception
* if problem occured when loading the class
* @deprecated '_' should not be used as an identifier, since it is a reserved keyword from source level 1.8 on
* use {@link #__loadClass} instead
*/
@Deprecated
public Class _(String className) throws Exception {
return __loadClass(className);
}


/**
* Load the class from Pay Class loader
*
Expand Down
8 changes: 4 additions & 4 deletions framework/src/play/templates/GroovyTemplateCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ public int compare(String o1, String o2) {
if (names.size() <= 1 || source.contains("new ")) {
for (String cName : names) { // dynamic class binding
source = source.replaceAll("new " + Pattern.quote(cName) + "(\\([^)]*\\))",
"_('" + originalNames.get(cName).replace("$", "\\$") + "').newInstance$1");
"__loadClass('" + originalNames.get(cName).replace("$", "\\$") + "').newInstance$1");
}
}

if (names.size() <= 1 || source.contains("instanceof")) {
for (String cName : names) { // dynamic class binding
source = source.replaceAll("([a-zA-Z0-9.-_$]+)\\s+instanceof\\s+" + Pattern.quote(cName),
"_('" + originalNames.get(cName).replace("$", "\\$") + "').isAssignableFrom($1.class)");
"__loadClass('" + originalNames.get(cName).replace("$", "\\$") + "').isAssignableFrom($1.class)");

}
}
Expand Down Expand Up @@ -149,7 +149,7 @@ protected void head() {
println(" extends play.templates.GroovyTemplate.ExecutableTemplate {");
println("public Object run() { use(play.templates.JavaExtensions) {");
for (String n : extensionsClassnames) {
println("use(_('" + n + "')) {");
println("use(__loadClass('" + n + "')) {");
}
}

Expand Down Expand Up @@ -390,7 +390,7 @@ protected void endTag() {
}
if (m != null) {
print("play.templates.TagContext.enterTag('" + tag.name + "');");
print("_('" + m.getDeclaringClass().getName() + "')._" + tName + "(attrs" + tagIndex + ",body" + tagIndex
print("__loadClass('" + m.getDeclaringClass().getName() + "')._" + tName + "(attrs" + tagIndex + ",body" + tagIndex
+ ", out, this, " + tag.startLine + ");");
print("play.templates.TagContext.exitTag();");
} else {
Expand Down
4 changes: 2 additions & 2 deletions framework/test-src/play/templates/JavaExtensionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public void testContains() {

@Test
public void testAdd() {
String[] testArray = {"a", "b", "c"};
assertThat(JavaExtensions.add(new String[]{"a", "b"}, "c")).hasSize(3).contains(testArray);
final String[] items = JavaExtensions.add(new String[]{"a", "b"}, "c");
assertThat(items).hasSize(3).contains((Object[]) new String[] {"a", "b", "c"});

}

Expand Down
4 changes: 2 additions & 2 deletions modules/crud/app/views/tags/crud/form.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
%{
if(_object) {
currentObject = _object
currentType = _('controllers.CRUD$ObjectType').forClass(_object.getClass().getName())
currentType = __loadClass('controllers.CRUD$ObjectType').forClass(_object.getClass().getName())
} else if(_class) {
currentObject = null;
currentType = _('controllers.CRUD$ObjectType').forClass(_class)
currentType = __loadClass('controllers.CRUD$ObjectType').forClass(_class)
} else {
currentObject = _caller.object
currentType = _caller.type
Expand Down
8 changes: 4 additions & 4 deletions modules/crud/app/views/tags/crud/types.tag
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
%{
models = [];
for(controllerClass in play.Play.classloader.getAssignableClasses(_('controllers.CRUD'))) {
resourceModel = _('controllers.CRUD$ObjectType').get(controllerClass)
for(controllerClass in play.Play.classloader.getAssignableClasses(__loadClass('controllers.CRUD'))) {
resourceModel = __loadClass('controllers.CRUD$ObjectType').get(controllerClass)
if(resourceModel != null) {
models.add(resourceModel)
}
}
for(controllerClass in play.Play.classloader.getAssignableClasses(_('play.scalasupport.crud.CRUDWrapper'))) {
resourceModel = _('controllers.CRUD$ObjectType').get(controllerClass)
for(controllerClass in play.Play.classloader.getAssignableClasses(__loadClass('play.scalasupport.crud.CRUDWrapper'))) {
resourceModel = __loadClass('controllers.CRUD$ObjectType').get(controllerClass)
if(resourceModel != null) {
models.add(resourceModel)
}
Expand Down
2 changes: 1 addition & 1 deletion modules/docviewer/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

<target name="compile">
<mkdir dir="tmp/classes" />
<javac srcdir="src" destdir="tmp/classes" source="1.6" target="1.6" debug="true">
<javac srcdir="src" destdir="tmp/classes" debug="true" source="1.8" target="1.8">
<classpath refid="project.classpath" />
</javac>
</target>
Expand Down
2 changes: 1 addition & 1 deletion modules/grizzly/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

<target name="compile">
<mkdir dir="tmp/classes" />
<javac srcdir="src" destdir="tmp/classes" source="1.6" target="1.6" debug="true">
<javac srcdir="src" destdir="tmp/classes" debug="true" source="1.8" target="1.8">
<classpath refid="project.classpath" />
</javac>
</target>
Expand Down
Loading