### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java,v retrieving revision 1.140 diff -u -r1.140 BatchCompilerTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java 30 Nov 2007 13:50:41 -0000 1.140 +++ src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java 13 Dec 2007 14:45:35 -0000 @@ -53,6 +53,183 @@ return buildUniqueComplianceTestSuite(testClass(), ClassFileConstants.JDK1_5); } +protected void tearDown() throws Exception { + disposeCascadedJars(); + super.tearDown(); +} + +// PREMATURE find a way to build the jars once for the whole suite +private boolean cascadedJarsCreated; +private String cascadedJarsDirectoryPath; +private void createCascadedJars() { + if (!this.cascadedJarsCreated) { + this.cascadedJarsDirectoryPath = ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString(); + if (!this.cascadedJarsDirectoryPath.endsWith(File.separator)) { + this.cascadedJarsDirectoryPath = this.cascadedJarsDirectoryPath + File.separator; + } + try { + Util.createJar( + new String[] { + "p/A.java", + "package p;\n" + + "public class A {\n" + + "}", + }, + new String[] { + "META-INF/MANIFEST.MF", + "Manifest-Version: 1.0\n" + + "Created-By: Eclipse JDT Test Harness\n" + + "Class-Path: lib2.jar\n", + }, + this.cascadedJarsDirectoryPath + "lib1.jar", + JavaCore.VERSION_1_4); + Util.createJar( + new String[] { + "p/B.java", + "package p;\n" + + "public class B {\n" + + "}", + "p/R.java", + "package p;\n" + + "public class R {\n" + + " public static final int R2 = 2;\n" + + "}", + }, + this.cascadedJarsDirectoryPath + "lib2.jar", + JavaCore.VERSION_1_4); + Util.createJar( + new String[] { + "p/C.java", + "package p;\n" + + "public class C {\n" + + "}", + "p/R.java", + "package p;\n" + + "public class R {\n" + + " public static final int R3 = 3;\n" + + "}", + }, + new String[] { + "META-INF/MANIFEST.MF", + "Manifest-Version: 1.0\n" + + "Created-By: Eclipse JDT Test Harness\n" + + "Class-Path: lib4.jar\n", + }, + this.cascadedJarsDirectoryPath + "lib3.jar", + JavaCore.VERSION_1_4); + Util.createJar( + new String[] { + "p/D.java", + "package p;\n" + + "public class D {\n" + + "}", + }, + new String[] { + "META-INF/MANIFEST.MF", + "Manifest-Version: 1.0\n" + + "Created-By: Eclipse JDT Test Harness\n" + + "Class-Path: lib1.jar lib3.jar\n", + }, + this.cascadedJarsDirectoryPath + "lib4.jar", + JavaCore.VERSION_1_4); + Util.createJar( + new String[] { + "p/C.java", + "package p;\n" + + "public class C {\n" + + "}", + "p/R.java", + "package p;\n" + + "public class R {\n" + + " public static final int R3 = 3;\n" + + "}", + }, + new String[] { + "META-INF/MANIFEST.MF", + "Manifest-Version: 1.0\n" + + "Created-By: Eclipse JDT Test Harness\n" + + "Class-Path: s/lib6.jar\n", + }, + this.cascadedJarsDirectoryPath + "lib5.jar", + JavaCore.VERSION_1_4); + new File(this.cascadedJarsDirectoryPath + "s").mkdir(); + Util.createJar( + new String[] { + "p/D.java", + "package p;\n" + + "public class D {\n" + + "}", + }, + new String[] { + "META-INF/MANIFEST.MF", + "Manifest-Version: 1.0\n" + + "Created-By: Eclipse JDT Test Harness\n" + + "Class-Path: ../lib7.jar\n", + }, + this.cascadedJarsDirectoryPath + "s" + File.separator + "lib6.jar", + JavaCore.VERSION_1_4); + Util.createJar( + new String[] { + "p/A.java", + "package p;\n" + + "public class A {\n" + + "}", + }, + new String[] { + "META-INF/MANIFEST.MF", + "Manifest-Version: 1.0\n" + + "Created-By: Eclipse JDT Test Harness\n" + + "Class-Path: lib2.jar\n", + }, + this.cascadedJarsDirectoryPath + "lib7.jar", + JavaCore.VERSION_1_4); + Util.createJar( + new String[] { + "p/F.java", + "package p;\n" + + "public class F {\n" + + "}", + }, + new String[] { + "META-INF/MANIFEST.MF", + "Manifest-Version: 1.0\n" + + "Created-By: Eclipse JDT Test Harness\n" + + "Class-Path: " + this.cascadedJarsDirectoryPath + "lib3.jar lib1.jar\n", + }, + this.cascadedJarsDirectoryPath + "lib8.jar", + JavaCore.VERSION_1_4); + Util.createJar( + new String[] { + "p/G.java", + "package p;\n" + + "public class G {\n" + + "}", + }, + new String[] { + "META-INF/MANIFEST.MF", + "Manifest-Version: 1.0\n" + + "Created-By: Eclipse JDT Test Harness\n" + + "Class-Path: lib1.jar\n" + + "Class-Path: lib3.jar\n", + }, + this.cascadedJarsDirectoryPath + "lib9.jar", + JavaCore.VERSION_1_4); + this.cascadedJarsCreated = true; + } catch (IOException e) { + // ignore + } + } +} +private void disposeCascadedJars() { + if (this.cascadedJarsCreated) { + Util.delete(this.cascadedJarsDirectoryPath + "lib1.jar"); + Util.delete(this.cascadedJarsDirectoryPath + "lib2.jar"); + Util.delete(this.cascadedJarsDirectoryPath + "lib3.jar"); + Util.delete(this.cascadedJarsDirectoryPath + "lib4.jar"); + this.cascadedJarsCreated = false; + } +} + private String getLibraryClassesAsQuotedString() { String[] paths = Util.getJavaClassLibs(); StringBuffer buffer = new StringBuffer(); @@ -7815,6 +7992,372 @@ "1 problem (1 warning)", true); } +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=97332 - jars pointed by jars +// basic link: a jar only referenced in the manifest of the first one is found +public void test214_jar_ref_in_jar(){ + createCascadedJars(); + this.runConformTest( + new String[] { + "src/p/X.java", + "package p;\n" + + "/** */\n" + + "public class X {\n" + + " A a;\n" + + " B b;\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "src/p/X.java\"" + + " -cp \"" + this.cascadedJarsDirectoryPath + "lib1.jar\"" + + " -cp \"" + this.cascadedJarsDirectoryPath + "lib2.jar\"" // WORK SIMULATED SO FAR + + " -sourcepath \"" + OUTPUT_DIR + File.separator + "src\"" + + " -1.5 -g -preserveAllLocals" + + " -proceedOnError -referenceInfo" + + " -d \"" + OUTPUT_DIR + File.separator + "bin\" ", + "", + "", + true); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=97332 - jars pointed by jars +// may want a specific option to mimick javac 1.4 +// caveat: javac 1.5 with -source 1.4 and -target 1.4 still uses the links +public void _test215_jar_ref_in_jar(){ + createCascadedJars(); + this.runNegativeTest( + new String[] { + "src/p/X.java", + "package p;\n" + + "/** */\n" + + "public class X {\n" + + " A a;\n" + + " B b;\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "src/p/X.java\"" + + " -cp \"" + this.cascadedJarsDirectoryPath + "lib1.jar\"" + + " -sourcepath \"" + OUTPUT_DIR + File.separator + "src\"" + + " -ignoreJarClassPath -g -preserveAllLocals" + + " -proceedOnError -referenceInfo" + + " -d \"" + OUTPUT_DIR + File.separator + "bin\" ", + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/p/X.java (at line 5)\n" + + " B b;\n" + + " ^\n" + + "B cannot be resolved to a type\n" + + "----------\n" + + "1 problem (1 error)", + true); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=97332 - jars pointed by jars +// links are followed recursively, eliminating dupes +public void test216_jar_ref_in_jar(){ + createCascadedJars(); + this.runConformTest( + new String[] { + "src/p/X.java", + "package p;\n" + + "/** */\n" + + "public class X {\n" + + " A a;\n" + + " B b;\n" + + " C c;\n" + + " D d;\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "src/p/X.java\"" + + " -cp \"" + this.cascadedJarsDirectoryPath + "lib3.jar\"" + + " -cp \"" + this.cascadedJarsDirectoryPath + "lib4.jar\"" // WORK SIMULATED SO FAR + + " -cp \"" + this.cascadedJarsDirectoryPath + "lib1.jar\"" // WORK SIMULATED SO FAR + + " -cp \"" + this.cascadedJarsDirectoryPath + "lib2.jar\"" // WORK SIMULATED SO FAR + + " -sourcepath \"" + OUTPUT_DIR + File.separator + "src\"" + + " -1.5 -g -preserveAllLocals" + + " -proceedOnError -referenceInfo" + + " -d \"" + OUTPUT_DIR + File.separator + "bin\" ", + "", + "", + true); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=97332 - jars pointed by jars +// at first level, this is depth first, masking tailing libs +public void test217_jar_ref_in_jar(){ + createCascadedJars(); + this.runNegativeTest( + new String[] { + "src/p/X.java", + "package p;\n" + + "/** */\n" + + "public class X {\n" + + " int i = R.R2;\n" + + " int j = R.R3;\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "src/p/X.java\"" + + " -cp \"" + this.cascadedJarsDirectoryPath + "lib1.jar\"" + + " -cp \"" + this.cascadedJarsDirectoryPath + "lib2.jar\"" // WORK SIMULATED SO FAR + + " -cp \"" + this.cascadedJarsDirectoryPath + "lib3.jar\"" + + " -sourcepath \"" + OUTPUT_DIR + File.separator + "src\"" + + " -1.5 -g -preserveAllLocals" + + " -proceedOnError -referenceInfo" + + " -d \"" + OUTPUT_DIR + File.separator + "bin\" ", + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/p/X.java (at line 5)\n" + + " int j = R.R3;\n" + + " ^^^^\n" + + "R.R3 cannot be resolved\n" + + "----------\n" + + "1 problem (1 error)", + true); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=97332 - jars pointed by jars +// using only links, we adopt a depth first algorithm +public void test218_jar_ref_in_jar(){ + createCascadedJars(); + this.runNegativeTest( + new String[] { + "src/p/X.java", + "package p;\n" + + "/** */\n" + + "public class X {\n" + + " int i = R.R2;\n" + + " int j = R.R3;\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "src/p/X.java\"" + + " -cp \"" + this.cascadedJarsDirectoryPath + "lib4.jar\"" + + " -cp \"" + this.cascadedJarsDirectoryPath + "lib1.jar\"" // WORK SIMULATED SO FAR + + " -cp \"" + this.cascadedJarsDirectoryPath + "lib2.jar\"" // WORK SIMULATED SO FAR + + " -cp \"" + this.cascadedJarsDirectoryPath + "lib3.jar\"" // WORK SIMULATED SO FAR + + " -sourcepath \"" + OUTPUT_DIR + File.separator + "src\"" + + " -1.5 -g -preserveAllLocals" + + " -proceedOnError -referenceInfo" + + " -d \"" + OUTPUT_DIR + File.separator + "bin\" ", + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/p/X.java (at line 5)\n" + + " int j = R.R3;\n" + + " ^^^^\n" + + "R.R3 cannot be resolved\n" + + "----------\n" + + "1 problem (1 error)", + true); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=97332 - jars pointed by jars +// managing subdirectories and .. properly +public void test219_jar_ref_in_jar(){ + createCascadedJars(); + this.runConformTest( + new String[] { + "src/p/X.java", + "package p;\n" + + "/** */\n" + + "public class X {\n" + + " A a;\n" + + " B b;\n" + + " C c;\n" + + " D d;\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "src/p/X.java\"" + + " -cp \"" + this.cascadedJarsDirectoryPath + "lib5.jar\"" + + " -cp \"" + this.cascadedJarsDirectoryPath + "s" + File.separator + "lib6.jar\"" // WORK SIMULATED SO FAR + + " -cp \"" + this.cascadedJarsDirectoryPath + "lib7.jar\"" // WORK SIMULATED SO FAR + + " -cp \"" + this.cascadedJarsDirectoryPath + "lib2.jar\"" // WORK SIMULATED SO FAR + + " -sourcepath \"" + OUTPUT_DIR + File.separator + "src\"" + + " -1.5 -g -preserveAllLocals" + + " -proceedOnError -referenceInfo" + + " -d \"" + OUTPUT_DIR + File.separator + "bin\" ", + "", + "", + true); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=97332 - jars pointed by jars +// variant: the second jar on a line is found as well +public void test220_jar_ref_in_jar(){ + createCascadedJars(); + this.runConformTest( + new String[] { + "src/p/X.java", + "package p;\n" + + "/** */\n" + + "public class X {\n" + + " C c;\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "src/p/X.java\"" + + " -cp \"" + this.cascadedJarsDirectoryPath + "lib4.jar\"" + + " -cp \"" + this.cascadedJarsDirectoryPath + "lib3.jar\"" // WORK SIMULATED SO FAR + + " -sourcepath \"" + OUTPUT_DIR + File.separator + "src\"" + + " -1.5 -g -preserveAllLocals" + + " -proceedOnError -referenceInfo" + + " -d \"" + OUTPUT_DIR + File.separator + "bin\" ", + "", + "", + true); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=97332 - jars pointed by jars +// we eat up absolute links silently +public void test221_jar_ref_in_jar(){ + createCascadedJars(); + this.runConformTest( + new String[] { + "src/p/X.java", + "package p;\n" + + "/** */\n" + + "public class X {\n" + + " F f;\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "src/p/X.java\"" + + " -cp \"" + this.cascadedJarsDirectoryPath + "lib8.jar\"" + + " -sourcepath \"" + OUTPUT_DIR + File.separator + "src\"" + + " -1.5 -g -preserveAllLocals" + + " -proceedOnError -referenceInfo" + + " -d \"" + OUTPUT_DIR + File.separator + "bin\" ", + "", + "", + true); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=97332 - jars pointed by jars +// absolute links do not mask following relative links +public void test222_jar_ref_in_jar(){ + createCascadedJars(); + this.runConformTest( + new String[] { + "src/p/X.java", + "package p;\n" + + "/** */\n" + + "public class X {\n" + + " A a;\n" + + " F f;\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "src/p/X.java\"" + + " -cp \"" + this.cascadedJarsDirectoryPath + "lib8.jar\"" + + " -cp \"" + this.cascadedJarsDirectoryPath + "lib1.jar\"" // WORK SIMULATED SO FAR + + " -sourcepath \"" + OUTPUT_DIR + File.separator + "src\"" + + " -1.5 -g -preserveAllLocals" + + " -proceedOnError -referenceInfo" + + " -d \"" + OUTPUT_DIR + File.separator + "bin\" ", + "", + "", + true); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=97332 - jars pointed by jars +// absolute links are not followed +public void test223_jar_ref_in_jar(){ + createCascadedJars(); + this.runNegativeTest( + new String[] { + "src/p/X.java", + "package p;\n" + + "/** */\n" + + "public class X {\n" + + " C c;\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "src/p/X.java\"" + + " -cp \"" + this.cascadedJarsDirectoryPath + "lib8.jar\"" + + " -sourcepath \"" + OUTPUT_DIR + File.separator + "src\"" + + " -1.5 -g -preserveAllLocals" + + " -proceedOnError -referenceInfo" + + " -d \"" + OUTPUT_DIR + File.separator + "bin\" ", + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/p/X.java (at line 4)\n" + + " C c;\n" + + " ^\n" + + "C cannot be resolved to a type\n" + + "----------\n" + + "1 problem (1 error)", + true); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=97332 - jars pointed by jars +// we accept duplicate classpath lines in manifest and we follow the first line +// WORK javac emits a warning - what do we want to do +public void test224_jar_ref_in_jar(){ + createCascadedJars(); + this.runConformTest( + new String[] { + "src/p/X.java", + "package p;\n" + + "/** */\n" + + "public class X {\n" + + " A a;\n" + + " G g;\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "src/p/X.java\"" + + " -cp \"" + this.cascadedJarsDirectoryPath + "lib9.jar\"" + + " -cp \"" + this.cascadedJarsDirectoryPath + "lib1.jar\"" // WORK SIMULATED SO FAR + + " -sourcepath \"" + OUTPUT_DIR + File.separator + "src\"" + + " -1.5 -g -preserveAllLocals" + + " -proceedOnError -referenceInfo" + + " -d \"" + OUTPUT_DIR + File.separator + "bin\" ", + "", + "", + true); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=97332 - jars pointed by jars +// we accept duplicate classpath lines in manifest and we follow the jars of the +// second and following lines as well +// WORK javac emits a warning - what do we want to do +public void test225_jar_ref_in_jar(){ + createCascadedJars(); + this.runConformTest( + new String[] { + "src/p/X.java", + "package p;\n" + + "/** */\n" + + "public class X {\n" + + " C c;\n" + + " G g;\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "src/p/X.java\"" + + " -cp \"" + this.cascadedJarsDirectoryPath + "lib9.jar\"" + + " -cp \"" + this.cascadedJarsDirectoryPath + "lib3.jar\"" // WORK SIMULATED SO FAR + + " -sourcepath \"" + OUTPUT_DIR + File.separator + "src\"" + + " -1.5 -g -preserveAllLocals" + + " -proceedOnError -referenceInfo" + + " -d \"" + OUTPUT_DIR + File.separator + "bin\" ", + "", + "", + true); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=97332 - jars pointed by jars +// bootclasspath does not get expanded +// WORK would need taylored jars that can replace the runtime +// if we manage to do this one, we should also track extensions +public void _test226_jar_ref_in_jar(){ + createCascadedJars(); + this.runNegativeTest( + new String[] { + "src/p/X.java", + "package p;\n" + + "/** */\n" + + "public class X {\n" + + " A a;\n" + + " C c;\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "src/p/X.java\"" + + " -bootclasspath " + getLibraryClassesAsQuotedString() + + File.pathSeparator + "\"" + OUTPUT_DIR + File.separator + this.cascadedJarsDirectoryPath + "lib1.jar\"" + + " -sourcepath \"" + OUTPUT_DIR + File.separator + "src\"" + + " -1.5 -g -preserveAllLocals" + + " -proceedOnError -referenceInfo" + + " -d \"" + OUTPUT_DIR + File.separator + "bin\" ", + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/p/X.java (at line 5)\n" + + " C c;\n" + + " ^\n" + + "C cannot be resolved to a type\n" + + "----------\n" + + "1 problem (1 error)", + true); +} public static Class testClass() { return BatchCompilerTest.class; }