Skip to content

Commit

Permalink
[playframework#1252] revert back method to static. Fix calls to depre…
Browse files Browse the repository at this point in the history
…cated '_' method, replaced by __loadClass because '_' is a reserved keyword from jdk9

* [playframework#1252] set java source and target version to use for the build, and remove unused conf file created by mistake
* [playframework#1252] ugly fix to make test pass with annotation parameter values with or without quotes, because I do not know how to assert an OR condition in Selenium IDE
* [playframework#1252] fix failing tests due to upgrade to JDK9. Upgrade test libraries and remove as much compilation warnings as possible
* [playframework#1252]  add version 9
* [playframework#1252] update java source detection mechanism to use the version specified in application conf file. Currently supported versions (by jdt compiler) are JDK 1.8 and 10
* [playframework#1252] fix selenium test
* [playframework#1252] fix previous loading class method using _ character now reserved in jdk9+
* [playframework#1252] update Play for build with jdk9+. Update libs
* update documentation for java.source
  • Loading branch information
tomparle authored and Alexandre Chatiron committed Aug 23, 2018
1 parent c6630cf commit bf22784
Show file tree
Hide file tree
Showing 34 changed files with 87 additions and 89 deletions.
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
2 changes: 1 addition & 1 deletion documentation/manual/configuration.textile
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ Java source level, which overrides the @java.version@ system property. For examp

bc. java.source=1.8

Values: @1.7@ (No longer supported since 1.5.0), @1.8@.
Values: @1.7@ (No longer supported since 1.5.0), @1.8@, @9@, @10@.

Default: @1.8@

Expand Down
2 changes: 1 addition & 1 deletion documentation/manual/install.textile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ h1. Installation guide

h2. <a name="prerequisites">Prerequisites</a>

To run the Play framework, you need "Java 6 or later":http://java.sun.com. If you wish to build Play from source, you will need the "Git source control client":http://git-scm.com/ to fetch the source code and "Ant":http://ant.apache.org/ to build it.
To run the Play framework, you need "Java 8 or later":http://java.sun.com. If you wish to build Play from source, you will need the "Git source control client":http://git-scm.com/ to fetch the source code and "Ant":http://ant.apache.org/ to build it.

Be sure to have Java in the current path (enter @java -version@ to check). Play will use the default Java or the one available at the @$JAVA_HOME@ path if defined.

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
Loading

0 comments on commit bf22784

Please sign in to comment.