Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Herrmann2018-11-25 16:34:40 +0000
committerStephan Herrmann2018-11-25 17:32:44 +0000
commit1ce496b91ef9bc8c91563099445eaf4525567119 (patch)
treee01b8c2fbee94865c45385cb33606d7195323bc5
parentd8ffdd918ebf31b799e069f58df49e11d7863ef5 (diff)
downloadeclipse.jdt.core-1ce496b91ef9bc8c91563099445eaf4525567119.tar.gz
eclipse.jdt.core-1ce496b91ef9bc8c91563099445eaf4525567119.tar.xz
eclipse.jdt.core-1ce496b91ef9bc8c91563099445eaf4525567119.zip
Bug 404648 - [1.8][compiler] investigate differences between ECJ & JavacI20181126-0140I20181125-1800
- some tests need to call javac with --module-[source-]path Change-Id: I92283d650d377bd3246cfa32641494eefbf8a7e4
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java27
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest9.java12
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Deprecated9Test.java25
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ModuleCompilationTests.java6
4 files changed, 51 insertions, 19 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java
index 3c9022a29f..cffbceb0a6 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java
@@ -244,6 +244,10 @@ static class JavacCompiler {
StringBuffer classpathBuffer = new StringBuffer(" -classpath ");
this.classpath = classpathBuffer.toString();
}
+ /** Call this if " -classpath " should be replaced by some other option token. */
+ protected void usePathOption(String option) {
+ this.classpath = option;
+ }
static String getVersion(String javacPathName) throws IOException, InterruptedException {
Process fetchVersionProcess = null;
try {
@@ -1011,7 +1015,7 @@ protected static class JavacTestOptions {
// list of available javac compilers, as defined by the jdk.roots
// variable, which should hold a File.pathSeparatorChar separated
// list of paths for to-be-tested JDK root directories
- protected static List javacCompilers = null;
+ protected static List<JavacCompiler> javacCompilers = null;
public static final String OUTPUT_DIR = Util.getOutputDirectory() + File.separator + "regression";
public static final String LIB_DIR = Util.getOutputDirectory() + File.separator + "lib";
@@ -1864,7 +1868,15 @@ protected static class JavacTestOptions {
expectedSuccessOutputString,
null,
javacTestOptions);
+ }
+
+ protected static void javacUsePathOption(String option) {
+ if (AbstractRegressionTest.javacCompilers != null) {
+ for (JavacCompiler compiler : AbstractRegressionTest.javacCompilers) {
+ compiler.usePathOption(option);
+ }
}
+ }
/*
* Run Sun compilation using javac.
@@ -2179,9 +2191,9 @@ protected void runJavac(
}
}
String testName = testName();
- Iterator compilers = javacCompilers.iterator();
+ Iterator<JavacCompiler> compilers = javacCompilers.iterator();
while (compilers.hasNext()) {
- JavacCompiler compiler = (JavacCompiler) compilers.next();
+ JavacCompiler compiler = compilers.next();
if (!options.skip(compiler) && compiler.compliance == this.complianceLevel) {
// WORK this may exclude some compilers under some conditions (when
// complianceLevel is not set); consider accepting the compiler
@@ -2203,6 +2215,7 @@ protected void runJavac(
for (int i = 0, length = testFiles.length; i < length; ) {
String fileName = testFiles[i++];
String contents = testFiles[i++];
+ fileName = expandFileNameForJavac(fileName);
File file = new File(javacOutputDirectory, fileName);
if (fileName.lastIndexOf('/') >= 0) {
File dir = file.getParentFile();
@@ -2216,7 +2229,7 @@ protected void runJavac(
int testFilesLength = testFiles.length;
sourceFileNames = new String[testFilesLength / 2];
for (int i = 0, j = 0; i < testFilesLength; i += 2, j++) {
- sourceFileNames[j] = testFiles[i];
+ sourceFileNames[j] = expandFileNameForJavac(testFiles[i]);
}
// compile
@@ -2319,6 +2332,10 @@ protected void runJavac(
}
}
}
+/** Hook for AbstractRegressionTest9 */
+protected String expandFileNameForJavac(String fileName) {
+ return fileName;
+}
void handleMismatch(JavacCompiler compiler, String testName, String[] testFiles, String expectedCompilerLog,
String expectedOutputString, String expectedErrorString, StringBuffer compilerLog, String output, String err,
JavacTestOptions.Excuse excuse, int mismatch) {
@@ -3568,7 +3585,7 @@ protected void runNegativeTest(
System.out.println("* Sun Javac compiler output archived into file:");
System.out.println("* " + javacFullLogFileName);
System.out.println("***************************************************************************");
- javacCompilers = new ArrayList();
+ javacCompilers = new ArrayList<>();
String jdkRoots = System.getProperty("jdk.roots");
if (jdkRoots == null) {
javacCompilers.add(new JavacCompiler(jdkRootDirPath.toString()));
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest9.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest9.java
index cc4962530f..57db3e4ac1 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest9.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest9.java
@@ -89,6 +89,18 @@ public class AbstractRegressionTest9 extends AbstractRegressionTest {
return compilationUnits;
}
+ /**
+ * javac cannot leverage our internal map {@code file2module}, so we better
+ * neatly place each file into a sub directory matching the module name.
+ */
+ protected String expandFileNameForJavac(String fileName) {
+ String fileNameAsKey = fileName.replace(File.separator, "/");
+ if (this.file2module != null && this.file2module.containsKey(fileNameAsKey)) {
+ fileName = new String(this.file2module.get(fileNameAsKey))+File.separator+fileName;
+ }
+ return fileName;
+ }
+
private IModule extractModuleDesc(String fileName, String fileContent, ICompilationUnit cu) {
if (fileName.toLowerCase().endsWith(IModule.MODULE_INFO_JAVA)) {
Parser parser = createParser();
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Deprecated9Test.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Deprecated9Test.java
index 9a7deef067..6f12b7dd0e 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Deprecated9Test.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Deprecated9Test.java
@@ -688,7 +688,8 @@ public class Deprecated9Test extends AbstractRegressionTest9 {
runner.runNegativeTest();
}
public void testDeprecatedProvidedServices() {
- associateToModule("mod0", "p1/IServiceDep.java", "p1/IServiceDepSince.java", "p1/IServiceTermDep.java", "p1/IServiceTermDepSince.java");
+ javacUsePathOption(" --module-source-path ");
+ associateToModule("mod0", "module-info.java", "p1/IServiceDep.java", "p1/IServiceDepSince.java", "p1/IServiceTermDep.java", "p1/IServiceTermDepSince.java");
associateToModule("mod1", "p1impl/ServiceDep.java", "p1impl/ServiceDepSince.java", "p1impl/ServiceTermDep.java", "p1impl/ServiceTermDepSince.java");
Runner runner = new Runner();
runner.customOptions = new HashMap<>();
@@ -732,7 +733,7 @@ public class Deprecated9Test extends AbstractRegressionTest9 {
"package p1impl;\n" +
"@Deprecated(since=\"3\",forRemoval=true)\n" +
"public class ServiceTermDepSince implements p1.IServiceTermDepSince {}\n",
- "folder2/module-info.java",
+ "mod1/module-info.java",
"module mod1 {\n" +
" requires mod0;\n" +
" provides p1.IServiceDep with p1impl.ServiceDep;\n" +
@@ -743,42 +744,42 @@ public class Deprecated9Test extends AbstractRegressionTest9 {
};
runner.expectedCompilerLog =
"----------\n" +
- "1. INFO in folder2\\module-info.java (at line 3)\n" +
+ "1. INFO in mod1\\module-info.java (at line 3)\n" +
" provides p1.IServiceDep with p1impl.ServiceDep;\n" +
" ^^^^^^^^^^^\n" +
"The type IServiceDep is deprecated\n" +
"----------\n" +
- "2. INFO in folder2\\module-info.java (at line 3)\n" +
+ "2. INFO in mod1\\module-info.java (at line 3)\n" +
" provides p1.IServiceDep with p1impl.ServiceDep;\n" +
" ^^^^^^^^^^\n" +
"The type ServiceDep is deprecated\n" +
"----------\n" +
- "3. INFO in folder2\\module-info.java (at line 4)\n" +
+ "3. INFO in mod1\\module-info.java (at line 4)\n" +
" provides p1.IServiceDepSince with p1impl.ServiceDepSince;\n" +
" ^^^^^^^^^^^^^^^^\n" +
"The type IServiceDepSince is deprecated since version 2\n" +
"----------\n" +
- "4. INFO in folder2\\module-info.java (at line 4)\n" +
+ "4. INFO in mod1\\module-info.java (at line 4)\n" +
" provides p1.IServiceDepSince with p1impl.ServiceDepSince;\n" +
" ^^^^^^^^^^^^^^^\n" +
"The type ServiceDepSince is deprecated since version 2\n" +
"----------\n" +
- "5. WARNING in folder2\\module-info.java (at line 5)\n" +
+ "5. WARNING in mod1\\module-info.java (at line 5)\n" +
" provides p1.IServiceTermDep with p1impl.ServiceTermDep;\n" +
" ^^^^^^^^^^^^^^^\n" +
"The type IServiceTermDep has been deprecated and marked for removal\n" +
"----------\n" +
- "6. WARNING in folder2\\module-info.java (at line 5)\n" +
+ "6. WARNING in mod1\\module-info.java (at line 5)\n" +
" provides p1.IServiceTermDep with p1impl.ServiceTermDep;\n" +
" ^^^^^^^^^^^^^^\n" +
"The type ServiceTermDep has been deprecated and marked for removal\n" +
"----------\n" +
- "7. WARNING in folder2\\module-info.java (at line 6)\n" +
+ "7. WARNING in mod1\\module-info.java (at line 6)\n" +
" provides p1.IServiceTermDepSince with p1impl.ServiceTermDepSince;\n" +
" ^^^^^^^^^^^^^^^^^^^^\n" +
"The type IServiceTermDepSince has been deprecated since version 3 and marked for removal\n" +
"----------\n" +
- "8. WARNING in folder2\\module-info.java (at line 6)\n" +
+ "8. WARNING in mod1\\module-info.java (at line 6)\n" +
" provides p1.IServiceTermDepSince with p1impl.ServiceTermDepSince;\n" +
" ^^^^^^^^^^^^^^^^^^^\n" +
"The type ServiceTermDepSince has been deprecated since version 3 and marked for removal\n" +
@@ -786,6 +787,8 @@ public class Deprecated9Test extends AbstractRegressionTest9 {
runner.runWarningTest();
}
public void testDeprecatedUsedServices() {
+ javacUsePathOption(" --module-path ");
+
associateToModule("mod0", "p1/IServiceDep.java", "p1/IServiceDepSince.java", "p1/IServiceTermDep.java", "p1/IServiceTermDepSince.java");
Runner runner = new Runner();
runner.customOptions = new HashMap<>();
@@ -888,6 +891,8 @@ public class Deprecated9Test extends AbstractRegressionTest9 {
}
}
public void testBug533063_2() throws Exception {
+ javacUsePathOption(" --module-path ");
+
runConformTest(new String[] {
"dont.use/module-info.java",
"@Deprecated(forRemoval=true,since=\"9\") module dont.use {}\n"
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ModuleCompilationTests.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ModuleCompilationTests.java
index e6746496fe..6cda2da17e 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ModuleCompilationTests.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ModuleCompilationTests.java
@@ -162,8 +162,7 @@ public class ModuleCompilationTests extends AbstractBatchCompilerTest {
if (javacCommandLine == null) {
javacCommandLine = adjustForJavac(commandLine, null);
}
- for (Object comp : javacCompilers) {
- JavacCompiler javacCompiler = (JavacCompiler) comp;
+ for (JavacCompiler javacCompiler : javacCompilers) {
if (javacCompiler.compliance < ClassFileConstants.JDK9)
continue;
if (options.skip(javacCompiler)) {
@@ -240,8 +239,7 @@ public class ModuleCompilationTests extends AbstractBatchCompilerTest {
File outputDir = new File(OUTPUT_DIR);
final Set<String> outFiles = new HashSet<>();
walkOutFiles(output, outFiles, true);
- for (Object comp : javacCompilers) {
- JavacCompiler javacCompiler = (JavacCompiler) comp;
+ for (JavacCompiler javacCompiler : javacCompilers) {
if (javacCompiler.compliance < ClassFileConstants.JDK9)
continue;
JavacTestOptions.Excuse excuse = options.excuseFor(javacCompiler);

Back to the top