Skip to content

Commit

Permalink
Oxygen (SR1a) JDT Patch for Groovy Eclipse: JDT commit 2cf2e0d
Browse files Browse the repository at this point in the history
Fix for issue #318: Groovy and Java 9 support
  • Loading branch information
eric-milles committed Sep 25, 2017
1 parent 670a112 commit 3f4f702
Show file tree
Hide file tree
Showing 443 changed files with 28,871 additions and 3,537 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -109,19 +109,19 @@ static class JavacCompiler {
}
}
}
if (rawVersion.indexOf("1.4") != -1 ||
this.javacPathName.indexOf("1.4") != -1
/* in fact, SUN javac 1.4 does not support the -version option;
* this is a imperfect heuristic to catch the case */) {
if (rawVersion.indexOf(JavaCore.VERSION_1_4) != -1 || this.javacPathName.indexOf(JavaCore.VERSION_1_4) != -1
/* in fact, SUN javac 1.4 does not support the -version option; this is a imperfect heuristic to catch the case */) {
this.version = JavaCore.VERSION_1_4;
} else if (rawVersion.indexOf("1.5") != -1) {
} else if (rawVersion.indexOf(JavaCore.VERSION_1_5) != -1) {
this.version = JavaCore.VERSION_1_5;
} else if (rawVersion.indexOf("1.6") != -1) {
} else if (rawVersion.indexOf(JavaCore.VERSION_1_6) != -1) {
this.version = JavaCore.VERSION_1_6;
} else if (rawVersion.indexOf("1.7") != -1) {
} else if (rawVersion.indexOf(JavaCore.VERSION_1_7) != -1) {
this.version = JavaCore.VERSION_1_7;
} else if (rawVersion.indexOf("1.8") != -1) {
this.version = "1.8";//JavaCore.VERSION_1_8;
} else if (rawVersion.indexOf(VERSION_1_8) != -1) {
this.version = VERSION_1_8;
} else if (rawVersion.indexOf(VERSION_1_9) != -1) {
this.version = VERSION_1_9;
} else {
throw new RuntimeException("unknown javac version: " + rawVersion);
}
Expand Down Expand Up @@ -824,6 +824,8 @@ protected void compileAndDeploy(String source, String directoryName, String clas
buffer.append("\" -1.7");
} else if (this.complianceLevel == JDK1_8) {
buffer.append("\" -1.8");
} else if (this.complianceLevel == JDK1_9) {
buffer.append("\" -1.9");
}
buffer
.append(" -preserveAllLocals -nowarn -g -classpath \"")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import junit.framework.Test;
import junit.framework.TestSuite;

import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.tests.compiler.regression.RegressionTestSetup;
Expand All @@ -36,11 +35,20 @@ public abstract class AbstractCompilerTest extends TestCase {
public static final int F_1_6 = 0x08;
public static final int F_1_7 = 0x10;
public static final int F_1_8 = 0x20;
public static final int F_1_9 = 0x40;

// here for now as CompilerOptions.version_1_8 exists only if using the java8 patched jdt
protected static final String VERSION_1_8 = "1.8";
protected static final String VERSION_1_9 = "1.9";
protected static final int MAJOR_VERSION_1_8 = 52;
protected static final int MAJOR_VERSION_1_9 = 53;
public static final long JDK1_8 = ((long) MAJOR_VERSION_1_8 << 16) + ClassFileConstants.MINOR_VERSION_0;
public static final long JDK1_9 = ((long) MAJOR_VERSION_1_9 << 16) + ClassFileConstants.MINOR_VERSION_0;

public static final boolean RUN_JAVAC = CompilerOptions.ENABLED.equals(System.getProperty("run.javac"));
private static final int UNINITIALIZED = -1;
private static final int NONE = 0;
private static int possibleComplianceLevels = UNINITIALIZED;
public static final boolean RUN_JAVAC = CompilerOptions.ENABLED.equals(System.getProperty("run.javac"));

protected long complianceLevel;

Expand All @@ -59,25 +67,28 @@ public static Test buildAllCompliancesTestSuite(Class<? extends Test> evaluation
}

public static void buildAllCompliancesTestSuite(TestSuite suite, Class<? extends Test> evaluationTestClass) {
int complianceLevels = AbstractCompilerTest.getPossibleComplianceLevels();
if ((complianceLevels & AbstractCompilerTest.F_1_3) != 0) {
int complianceLevels = getPossibleComplianceLevels();
if ((complianceLevels & F_1_3) != 0) {
suite.addTest(buildUniqueComplianceTestSuite(evaluationTestClass, ClassFileConstants.JDK1_3));
}
if ((complianceLevels & AbstractCompilerTest.F_1_4) != 0) {
if ((complianceLevels & F_1_4) != 0) {
suite.addTest(buildUniqueComplianceTestSuite(evaluationTestClass, ClassFileConstants.JDK1_4));
}
if ((complianceLevels & AbstractCompilerTest.F_1_5) != 0) {
if ((complianceLevels & F_1_5) != 0) {
suite.addTest(buildUniqueComplianceTestSuite(evaluationTestClass, ClassFileConstants.JDK1_5));
}
if ((complianceLevels & AbstractCompilerTest.F_1_6) != 0) {
if ((complianceLevels & F_1_6) != 0) {
suite.addTest(buildUniqueComplianceTestSuite(evaluationTestClass, ClassFileConstants.JDK1_6));
}
if ((complianceLevels & AbstractCompilerTest.F_1_7) != 0) {
if ((complianceLevels & F_1_7) != 0) {
suite.addTest(buildUniqueComplianceTestSuite(evaluationTestClass, ClassFileConstants.JDK1_7));
}
if ((complianceLevels & AbstractCompilerTest.F_1_8) != 0) {
if ((complianceLevels & F_1_8) != 0) {
suite.addTest(buildUniqueComplianceTestSuite(evaluationTestClass, JDK1_8));
}
if ((complianceLevels & F_1_9) != 0) {
suite.addTest(buildUniqueComplianceTestSuite(evaluationTestClass, JDK1_9));
}
}

/**
Expand All @@ -92,25 +103,28 @@ public static void buildAllCompliancesTestSuite(TestSuite suite, Class<? extends
*/
public static Test buildAllCompliancesTestSuite(Class<? extends Test> testSuiteClass, Class<? extends TestSuite> setupClass, List<Class<? extends Test>> testClasses) {
TestSuite suite = new TestSuite(testSuiteClass.getName());
int complianceLevels = AbstractCompilerTest.getPossibleComplianceLevels();
if ((complianceLevels & AbstractCompilerTest.F_1_3) != 0) {
int complianceLevels = getPossibleComplianceLevels();
if ((complianceLevels & F_1_3) != 0) {
suite.addTest(buildComplianceTestSuite(testClasses, setupClass, ClassFileConstants.JDK1_3));
}
if ((complianceLevels & AbstractCompilerTest.F_1_4) != 0) {
if ((complianceLevels & F_1_4) != 0) {
suite.addTest(buildComplianceTestSuite(testClasses, setupClass, ClassFileConstants.JDK1_4));
}
if ((complianceLevels & AbstractCompilerTest.F_1_5) != 0) {
if ((complianceLevels & F_1_5) != 0) {
suite.addTest(buildComplianceTestSuite(testClasses, setupClass, ClassFileConstants.JDK1_5));
}
if ((complianceLevels & AbstractCompilerTest.F_1_6) != 0) {
if ((complianceLevels & F_1_6) != 0) {
suite.addTest(buildComplianceTestSuite(testClasses, setupClass, ClassFileConstants.JDK1_6));
}
if ((complianceLevels & AbstractCompilerTest.F_1_7) != 0) {
if ((complianceLevels & F_1_7) != 0) {
suite.addTest(buildComplianceTestSuite(testClasses, setupClass, ClassFileConstants.JDK1_7));
}
if ((complianceLevels & AbstractCompilerTest.F_1_8) != 0) {
if ((complianceLevels & F_1_8) != 0) {
suite.addTest(buildComplianceTestSuite(testClasses, setupClass, JDK1_8));
}
if ((complianceLevels & F_1_9) != 0) {
suite.addTest(buildComplianceTestSuite(testClasses, setupClass, JDK1_9));
}
return suite;
}

Expand Down Expand Up @@ -181,55 +195,63 @@ private static Test buildComplianceTestSuite(List<Class<? extends Test>> testCla
*/
public static Test buildMinimalComplianceTestSuite(Class<? extends Test> evaluationTestClass, int minimalCompliance) {
TestSuite suite = new TestSuite(evaluationTestClass.getName());
int complianceLevels = AbstractCompilerTest.getPossibleComplianceLevels();
int level13 = complianceLevels & AbstractCompilerTest.F_1_3;
if (level13 != 0) {
if (level13 < minimalCompliance) {
int complianceLevels = getPossibleComplianceLevels();
int level3 = complianceLevels & F_1_3;
if (level3 != 0) {
if (level3 < minimalCompliance) {
System.err.println("Cannot run "+evaluationTestClass.getName()+" at compliance "+CompilerOptions.versionFromJdkLevel(ClassFileConstants.JDK1_3)+"!");
} else {
suite.addTest(buildUniqueComplianceTestSuite(evaluationTestClass, ClassFileConstants.JDK1_3));
}
}
int level14 = complianceLevels & AbstractCompilerTest.F_1_4;
if (level14 != 0) {
if (level14 < minimalCompliance) {
int level4 = complianceLevels & F_1_4;
if (level4 != 0) {
if (level4 < minimalCompliance) {
System.err.println("Cannot run "+evaluationTestClass.getName()+" at compliance "+CompilerOptions.versionFromJdkLevel(ClassFileConstants.JDK1_4)+"!");
} else {
suite.addTest(buildUniqueComplianceTestSuite(evaluationTestClass, ClassFileConstants.JDK1_4));
}
}
int level15 = complianceLevels & AbstractCompilerTest.F_1_5;
if (level15 != 0) {
if (level15 < minimalCompliance) {
int level5 = complianceLevels & F_1_5;
if (level5 != 0) {
if (level5 < minimalCompliance) {
System.err.println("Cannot run "+evaluationTestClass.getName()+" at compliance "+CompilerOptions.versionFromJdkLevel(ClassFileConstants.JDK1_5)+"!");
} else {
suite.addTest(buildUniqueComplianceTestSuite(evaluationTestClass, ClassFileConstants.JDK1_5));
}
}
int level16 = complianceLevels & AbstractCompilerTest.F_1_6;
if (level16 != 0) {
if (level16 < minimalCompliance) {
int level6 = complianceLevels & F_1_6;
if (level6 != 0) {
if (level6 < minimalCompliance) {
System.err.println("Cannot run "+evaluationTestClass.getName()+" at compliance "+CompilerOptions.versionFromJdkLevel(ClassFileConstants.JDK1_6)+"!");
} else {
suite.addTest(buildUniqueComplianceTestSuite(evaluationTestClass, ClassFileConstants.JDK1_6));
}
}
int level17 = complianceLevels & AbstractCompilerTest.F_1_7;
if (level17 != 0) {
if (level17 < minimalCompliance) {
int level7 = complianceLevels & F_1_7;
if (level7 != 0) {
if (level7 < minimalCompliance) {
System.err.println("Cannot run "+evaluationTestClass.getName()+" at compliance "+CompilerOptions.versionFromJdkLevel(ClassFileConstants.JDK1_7)+"!");
} else {
suite.addTest(buildUniqueComplianceTestSuite(evaluationTestClass, ClassFileConstants.JDK1_7));
}
}
int level18 = complianceLevels & AbstractCompilerTest.F_1_8;
if (level18 != 0) {
if (level18 < minimalCompliance) {
int level8 = complianceLevels & F_1_8;
if (level8 != 0) {
if (level8 < minimalCompliance) {
System.err.println("Cannot run "+evaluationTestClass.getName()+" at compliance "+CompilerOptions.versionFromJdkLevel(JDK1_8)+"!");
} else {
suite.addTest(buildUniqueComplianceTestSuite(evaluationTestClass, JDK1_8));
}
}
int level9 = complianceLevels & F_1_9;
if (level9 != 0) {
if (level9 < minimalCompliance) {
System.err.println("Cannot run "+evaluationTestClass.getName()+" at compliance "+CompilerOptions.versionFromJdkLevel(JDK1_9)+"!");
} else {
suite.addTest(buildUniqueComplianceTestSuite(evaluationTestClass, JDK1_9));
}
}
return suite;
}

Expand Down Expand Up @@ -260,30 +282,28 @@ public static Test buildUniqueComplianceTestSuite(Class<? extends Test> evaluati
* Returns the highest compliance level this VM instance can run.
*/
public static long highestComplianceLevels() {
int complianceLevels = AbstractCompilerTest.getPossibleComplianceLevels();
if ((complianceLevels & AbstractCompilerTest.F_1_8) != 0) {
int complianceLevels = getPossibleComplianceLevels();
if ((complianceLevels & F_1_9) != 0) {
return JDK1_9;
}
if ((complianceLevels & F_1_8) != 0) {
return JDK1_8;
}
if ((complianceLevels & AbstractCompilerTest.F_1_7) != 0) {
if ((complianceLevels & F_1_7) != 0) {
return ClassFileConstants.JDK1_7;
}
if ((complianceLevels & AbstractCompilerTest.F_1_6) != 0) {
if ((complianceLevels & F_1_6) != 0) {
return ClassFileConstants.JDK1_6;
}
if ((complianceLevels & AbstractCompilerTest.F_1_5) != 0) {
if ((complianceLevels & F_1_5) != 0) {
return ClassFileConstants.JDK1_5;
}
if ((complianceLevels & AbstractCompilerTest.F_1_4) != 0) {
if ((complianceLevels & F_1_4) != 0) {
return ClassFileConstants.JDK1_4;
}
return ClassFileConstants.JDK1_3;
}

// here for now as CompilerOptions.version_1_8 exists only if using the java8 patched jdt
protected static final String VERSION_1_8 = "1.8";
protected static final int MAJOR_VERSION_1_8 = 52;
public static final long JDK1_8 = ((long) MAJOR_VERSION_1_8 << 16) + ClassFileConstants.MINOR_VERSION_0;

/*
* Returns the possible compliance levels this VM instance can run.
*/
Expand All @@ -303,6 +323,8 @@ public static int getPossibleComplianceLevels() {
possibleComplianceLevels = F_1_7;
} else if (VERSION_1_8.equals(compliance)) {
possibleComplianceLevels = F_1_8;
} else if (VERSION_1_9.equals(compliance)) {
possibleComplianceLevels = F_1_9;
} else {
System.out.println("Invalid compliance specified (" + compliance + ")");
System.out.print("Use one of ");
Expand All @@ -312,17 +334,18 @@ public static int getPossibleComplianceLevels() {
System.out.print(CompilerOptions.VERSION_1_6 + ", ");
System.out.print(CompilerOptions.VERSION_1_7 + ", ");
System.out.println(VERSION_1_8);
System.out.println(VERSION_1_9);
System.out.println("Defaulting to all possible compliances");
}
}
if (possibleComplianceLevels == UNINITIALIZED) {
String specVersion = System.getProperty("java.specification.version");
if (!RUN_JAVAC) {
possibleComplianceLevels = F_1_3;
boolean canRun1_4 = !"1.0".equals(specVersion)
&& !CompilerOptions.VERSION_1_1.equals(specVersion)
&& !CompilerOptions.VERSION_1_2.equals(specVersion)
&& !CompilerOptions.VERSION_1_3.equals(specVersion);
boolean canRun1_4 = !"1.0".equals(specVersion) &&
!CompilerOptions.VERSION_1_1.equals(specVersion) &&
!CompilerOptions.VERSION_1_2.equals(specVersion) &&
!CompilerOptions.VERSION_1_3.equals(specVersion);
if (canRun1_4) {
possibleComplianceLevels |= F_1_4;
}
Expand All @@ -342,11 +365,15 @@ public static int getPossibleComplianceLevels() {
if (canRun1_8) {
possibleComplianceLevels |= F_1_8;
}
} else if ("1.0".equals(specVersion)
|| CompilerOptions.VERSION_1_1.equals(specVersion)
|| CompilerOptions.VERSION_1_2.equals(specVersion)
|| CompilerOptions.VERSION_1_3.equals(specVersion)
|| CompilerOptions.VERSION_1_4.equals(specVersion)) {
boolean canRun1_9 = canRun1_7 && !VERSION_1_8.equals(specVersion);
if (canRun1_9) {
possibleComplianceLevels |= F_1_9;
}
} else if ("1.0".equals(specVersion) ||
CompilerOptions.VERSION_1_1.equals(specVersion) ||
CompilerOptions.VERSION_1_2.equals(specVersion) ||
CompilerOptions.VERSION_1_3.equals(specVersion) ||
CompilerOptions.VERSION_1_4.equals(specVersion)) {
possibleComplianceLevels = NONE;
} else {
possibleComplianceLevels = F_1_5;
Expand All @@ -356,6 +383,9 @@ public static int getPossibleComplianceLevels() {
possibleComplianceLevels |= F_1_7;
if (!CompilerOptions.VERSION_1_7.equals(specVersion)) {
possibleComplianceLevels |= F_1_8;
if (!CompilerOptions.VERSION_1_8.equals(specVersion)) {
possibleComplianceLevels |= F_1_9;
}
}
}
}
Expand All @@ -374,14 +404,14 @@ public static int getPossibleComplianceLevels() {
*/
public static Test suite(String suiteName, Class<? extends TestSuite> setupClass, List<Class<? extends junit.framework.TestCase>> testClasses) {
TestSuite all = new TestSuite(suiteName);
int complianceLevels = AbstractCompilerTest.getPossibleComplianceLevels();
if ((complianceLevels & AbstractCompilerTest.F_1_3) != 0) {
int complianceLevels = getPossibleComplianceLevels();
if ((complianceLevels & F_1_3) != 0) {
all.addTest(suiteForComplianceLevel(ClassFileConstants.JDK1_3, setupClass, testClasses));
}
if ((complianceLevels & AbstractCompilerTest.F_1_4) != 0) {
if ((complianceLevels & F_1_4) != 0) {
all.addTest(suiteForComplianceLevel(ClassFileConstants.JDK1_4, setupClass, testClasses));
}
if ((complianceLevels & AbstractCompilerTest.F_1_5) != 0) {
if ((complianceLevels & F_1_5) != 0) {
all.addTest(suiteForComplianceLevel(ClassFileConstants.JDK1_5, setupClass, testClasses));
}
return all;
Expand Down Expand Up @@ -454,7 +484,7 @@ public static Test buildTestSuite(Class<? extends Test> evaluationTestClass, lon


public static boolean isJRELevel(int compliance) {
return (AbstractCompilerTest.getPossibleComplianceLevels() & compliance) != 0;
return (getPossibleComplianceLevels() & compliance) != 0;
}

public AbstractCompilerTest(String name) {
Expand Down Expand Up @@ -485,9 +515,13 @@ protected Map<String, String> getCompilerOptions() {
options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_7);
options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_7);
} else if (this.complianceLevel == JDK1_8) {
options.put(CompilerOptions.OPTION_Compliance, "1.8"/*CompilerOptions.VERSION_1_8*/);
options.put(CompilerOptions.OPTION_Source, "1.8"/*CompilerOptions.VERSION_1_8*/);
options.put(CompilerOptions.OPTION_TargetPlatform, "1.8"/*CompilerOptions.VERSION_1_8*/);
options.put(CompilerOptions.OPTION_Compliance, VERSION_1_8);
options.put(CompilerOptions.OPTION_Source, VERSION_1_8);
options.put(CompilerOptions.OPTION_TargetPlatform, VERSION_1_8);
} else if (this.complianceLevel == JDK1_9) {
options.put(CompilerOptions.OPTION_Compliance, VERSION_1_9);
options.put(CompilerOptions.OPTION_Source, VERSION_1_9);
options.put(CompilerOptions.OPTION_TargetPlatform, VERSION_1_9);
}
return options;
}
Expand Down
Loading

0 comments on commit 3f4f702

Please sign in to comment.