test/tools/sjavac/SJavac.java
Print this page
@@ -23,11 +23,11 @@
/*
* @test
* @summary Test all aspects of sjavac.
- * @bug 8004658 8042441 8042699 8054461 8054474
+ * @bug 8004658 8042441 8042699 8054461 8054474 8054717
*
* @build Wrapper
* @run main Wrapper SJavac
*/
@@ -62,31 +62,35 @@
Path gensrc2;
Path gensrc3;
// Where to put compiled classes.
Path bin;
+ Path bin2;
// Where to put c-header files.
Path headers;
// The sjavac compiler.
Main main = new Main();
// Remember the previous bin and headers state here.
Map<String,Long> previous_bin_state;
+ Map<String,Long> previous_bin2_state;
Map<String,Long> previous_headers_state;
public void test() throws Exception {
gensrc = defaultfs.getPath("gensrc");
gensrc2 = defaultfs.getPath("gensrc2");
gensrc3 = defaultfs.getPath("gensrc3");
bin = defaultfs.getPath("bin");
+ bin2 = defaultfs.getPath("bin2");
headers = defaultfs.getPath("headers");
Files.createDirectory(gensrc);
Files.createDirectory(gensrc2);
Files.createDirectory(gensrc3);
Files.createDirectory(bin);
+ Files.createDirectory(bin2);
Files.createDirectory(headers);
initialCompile();
incrementalCompileNoChanges();
incrementalCompileDroppingClasses();
@@ -97,10 +101,11 @@
compileWithOverrideSource();
compileWithInvisibleSources();
compileCircularSources();
compileExcludingDependency();
incrementalCompileTestFullyQualifiedRef();
+ compileTestingClasspathPubapis();
compileWithAtFile();
testStateDir();
delete(gensrc);
delete(gensrc2);
@@ -464,10 +469,73 @@
"bin/beta/B.class",
"bin/javac_state");
}
/**
+ * Tests that we track the pubapis of classes on the classpath.
+ * @throws Exception If test fails
+ */
+ void compileTestingClasspathPubapis() throws Exception {
+ System.out.println("\nTest pubapi changes of classes on the classpath.");
+ System.out.println("--------------------------------------------------");
+
+ delete(gensrc);
+ delete(gensrc2);
+ delete(bin);
+ delete(bin2);
+
+ populate(gensrc,
+ "alfa/omega/A.java",
+ "package alfa.omega; import beta.B; public class A { B b; }",
+ "beta/B.java",
+ "package beta; public class B { }");
+
+ populate(gensrc2,
+ "gamma/C.java",
+ "package gamma; import alfa.omega.A; public class C { A a; }");
+ System.out.println("Compiling bin...");
+ compile("-src", "gensrc", "-d", "bin", "--server:portfile=testserver,background=false");
+ System.out.println("Compiling bin2...");
+ compile("-classpath", "bin", "-src", "gensrc2", "-d", "bin2", "--server:portfile=testserver,background=false");
+
+ previous_bin2_state = collectState(bin2);
+ populate(gensrc,
+ "alfa/omega/AA.java",
+ "package alfa.omega; public class AA { }");
+
+ System.out.println("Compiling bin again...");
+ compile("-src", "gensrc", "-d", "bin", "--server:portfile=testserver,background=false");
+ System.out.println("Compiling bin2 again...");
+ compile("-classpath", "bin", "-src", "gensrc2", "-d", "bin2", "--server:portfile=testserver,background=false");
+
+ Map<String,Long> new_bin2_state = collectState(bin2);
+ // Adding the class AA to alfa.A does not change the pubapi of the classes in alfa.A that
+ // is actually used. Thus there should be no change of bin2. If alfa.A had been inside a jar
+ // file, then bin2/javac_state would have been updated with a new timestamp for the jar.
+ verifyNewerFiles(previous_bin2_state, new_bin2_state,
+ "bin2/javac_state");
+
+ // Now modify pubapi of A
+ previous_bin2_state = collectState(bin2);
+ populate(gensrc,
+ "alfa/omega/A.java",
+ "package alfa.omega; import beta.B; public class A { B b; public int a; }");
+
+ System.out.println("Compiling bin again...");
+ compile("-src", "gensrc", "-d", "bin", "--server:portfile=testserver,background=false");
+ System.out.println("Compiling bin2 again");
+ compile("-classpath", "bin", "-src", "gensrc2", "-d", "bin2", "--server:portfile=testserver,background=false");
+
+ new_bin2_state = collectState(bin2);
+ // Check that C was really recompiled due to the change in A:s pubapi.
+ verifyNewerFiles(previous_bin2_state, new_bin2_state,
+ "bin2/gamma/C.class",
+ "bin2/javac_state");
+
+ }
+
+ /**
* Tests @atfile
* @throws Exception If test fails
*/
void compileWithAtFile() throws Exception {
System.out.println("\nTest @atfile with command line content.");