8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24
25 /*
26 * @test
27 * @summary Test all aspects of sjavac.
28 * @bug 8004658 8042441 8042699 8054461 8054474
29 *
30 * @build Wrapper
31 * @run main Wrapper SJavac
32 */
33
34 import java.util.*;
35 import java.io.*;
36 import java.nio.file.*;
37 import java.nio.file.attribute.*;
38 import java.nio.charset.*;
39
40 import com.sun.tools.sjavac.Main;
41
42 public class SJavac {
43
44 public static void main(String... args) throws Exception {
45 try {
46 SJavac s = new SJavac();
47 s.test();
48 } finally {
49 System.out.println("\ntest complete\n");
50 }
51 }
52
53 FileSystem defaultfs = FileSystems.getDefault();
54 String serverArg = "--server:"
55 + "portfile=testportfile,"
56 + "background=false";
57
58 // Where to put generated sources that will
59 // test aspects of sjavac, ie JTWork/scratch/gensrc
60 Path gensrc;
61 // More gensrc dirs are used to test merging of serveral source roots.
62 Path gensrc2;
63 Path gensrc3;
64
65 // Where to put compiled classes.
66 Path bin;
67 // Where to put c-header files.
68 Path headers;
69
70 // The sjavac compiler.
71 Main main = new Main();
72
73 // Remember the previous bin and headers state here.
74 Map<String,Long> previous_bin_state;
75 Map<String,Long> previous_headers_state;
76
77 public void test() throws Exception {
78 gensrc = defaultfs.getPath("gensrc");
79 gensrc2 = defaultfs.getPath("gensrc2");
80 gensrc3 = defaultfs.getPath("gensrc3");
81 bin = defaultfs.getPath("bin");
82 headers = defaultfs.getPath("headers");
83
84 Files.createDirectory(gensrc);
85 Files.createDirectory(gensrc2);
86 Files.createDirectory(gensrc3);
87 Files.createDirectory(bin);
88 Files.createDirectory(headers);
89
90 initialCompile();
91 incrementalCompileNoChanges();
92 incrementalCompileDroppingClasses();
93 incrementalCompileWithChange();
94 incrementalCompileDropAllNatives();
95 incrementalCompileAddNative();
96 incrementalCompileChangeNative();
97 compileWithOverrideSource();
98 compileWithInvisibleSources();
99 compileCircularSources();
100 compileExcludingDependency();
101 incrementalCompileTestFullyQualifiedRef();
102 compileWithAtFile();
103 testStateDir();
104
105 delete(gensrc);
106 delete(gensrc2);
107 delete(gensrc3);
108 delete(bin);
109 delete(headers);
110 }
111
112 void initialCompile() throws Exception {
113 System.out.println("\nInitial compile of gensrc.");
114 System.out.println("----------------------------");
115 populate(gensrc,
116 "alfa/omega/AINT.java",
117 "package alfa.omega; public interface AINT { void aint(); }",
118
119 "alfa/omega/A.java",
120 "package alfa.omega; public class A implements AINT { "+
121 "public final static int DEFINITION = 17; public void aint() { } }",
449
450 // Change pubapi of A, this should trigger a recompile of B.
451 populate(gensrc,
452 "alfa/omega/A.java",
453 "package alfa.omega; public class A { "+
454 " public final static int DEFINITION = 19; "+
455 " public void hello() { }"+
456 "}");
457
458 compile("gensrc", "-d", "bin", "-j", "1",
459 serverArg, "--log=debug");
460 Map<String,Long> new_bin_state = collectState(bin);
461
462 verifyNewerFiles(previous_bin_state, new_bin_state,
463 "bin/alfa/omega/A.class",
464 "bin/beta/B.class",
465 "bin/javac_state");
466 }
467
468 /**
469 * Tests @atfile
470 * @throws Exception If test fails
471 */
472 void compileWithAtFile() throws Exception {
473 System.out.println("\nTest @atfile with command line content.");
474 System.out.println("---------------------------------------");
475
476 delete(gensrc);
477 delete(gensrc2);
478 delete(bin);
479
480 populate(gensrc,
481 "list.txt",
482 "-if */alfa/omega/A.java\n-if */beta/B.java\ngensrc\n-d bin\n",
483 "alfa/omega/A.java",
484 "package alfa.omega; import beta.B; public class A { B b; }",
485 "beta/B.java",
486 "package beta; public class B { }",
487 "beta/C.java",
488 "broken");
|
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24
25 /*
26 * @test
27 * @summary Test all aspects of sjavac.
28 * @bug 8004658 8042441 8042699 8054461 8054474 8054717
29 *
30 * @build Wrapper
31 * @run main Wrapper SJavac
32 */
33
34 import java.util.*;
35 import java.io.*;
36 import java.nio.file.*;
37 import java.nio.file.attribute.*;
38 import java.nio.charset.*;
39
40 import com.sun.tools.sjavac.Main;
41
42 public class SJavac {
43
44 public static void main(String... args) throws Exception {
45 try {
46 SJavac s = new SJavac();
47 s.test();
48 } finally {
49 System.out.println("\ntest complete\n");
50 }
51 }
52
53 FileSystem defaultfs = FileSystems.getDefault();
54 String serverArg = "--server:"
55 + "portfile=testportfile,"
56 + "background=false";
57
58 // Where to put generated sources that will
59 // test aspects of sjavac, ie JTWork/scratch/gensrc
60 Path gensrc;
61 // More gensrc dirs are used to test merging of serveral source roots.
62 Path gensrc2;
63 Path gensrc3;
64
65 // Where to put compiled classes.
66 Path bin;
67 Path bin2;
68 // Where to put c-header files.
69 Path headers;
70
71 // The sjavac compiler.
72 Main main = new Main();
73
74 // Remember the previous bin and headers state here.
75 Map<String,Long> previous_bin_state;
76 Map<String,Long> previous_bin2_state;
77 Map<String,Long> previous_headers_state;
78
79 public void test() throws Exception {
80 gensrc = defaultfs.getPath("gensrc");
81 gensrc2 = defaultfs.getPath("gensrc2");
82 gensrc3 = defaultfs.getPath("gensrc3");
83 bin = defaultfs.getPath("bin");
84 bin2 = defaultfs.getPath("bin2");
85 headers = defaultfs.getPath("headers");
86
87 Files.createDirectory(gensrc);
88 Files.createDirectory(gensrc2);
89 Files.createDirectory(gensrc3);
90 Files.createDirectory(bin);
91 Files.createDirectory(bin2);
92 Files.createDirectory(headers);
93
94 initialCompile();
95 incrementalCompileNoChanges();
96 incrementalCompileDroppingClasses();
97 incrementalCompileWithChange();
98 incrementalCompileDropAllNatives();
99 incrementalCompileAddNative();
100 incrementalCompileChangeNative();
101 compileWithOverrideSource();
102 compileWithInvisibleSources();
103 compileCircularSources();
104 compileExcludingDependency();
105 incrementalCompileTestFullyQualifiedRef();
106 compileTestingClasspathPubapis();
107 compileWithAtFile();
108 testStateDir();
109
110 delete(gensrc);
111 delete(gensrc2);
112 delete(gensrc3);
113 delete(bin);
114 delete(headers);
115 }
116
117 void initialCompile() throws Exception {
118 System.out.println("\nInitial compile of gensrc.");
119 System.out.println("----------------------------");
120 populate(gensrc,
121 "alfa/omega/AINT.java",
122 "package alfa.omega; public interface AINT { void aint(); }",
123
124 "alfa/omega/A.java",
125 "package alfa.omega; public class A implements AINT { "+
126 "public final static int DEFINITION = 17; public void aint() { } }",
454
455 // Change pubapi of A, this should trigger a recompile of B.
456 populate(gensrc,
457 "alfa/omega/A.java",
458 "package alfa.omega; public class A { "+
459 " public final static int DEFINITION = 19; "+
460 " public void hello() { }"+
461 "}");
462
463 compile("gensrc", "-d", "bin", "-j", "1",
464 serverArg, "--log=debug");
465 Map<String,Long> new_bin_state = collectState(bin);
466
467 verifyNewerFiles(previous_bin_state, new_bin_state,
468 "bin/alfa/omega/A.class",
469 "bin/beta/B.class",
470 "bin/javac_state");
471 }
472
473 /**
474 * Tests that we track the pubapis of classes on the classpath.
475 * @throws Exception If test fails
476 */
477 void compileTestingClasspathPubapis() throws Exception {
478 System.out.println("\nTest pubapi changes of classes on the classpath.");
479 System.out.println("--------------------------------------------------");
480
481 delete(gensrc);
482 delete(gensrc2);
483 delete(bin);
484 delete(bin2);
485
486 populate(gensrc,
487 "alfa/omega/A.java",
488 "package alfa.omega; import beta.B; public class A { B b; }",
489 "beta/B.java",
490 "package beta; public class B { }");
491
492 populate(gensrc2,
493 "gamma/C.java",
494 "package gamma; import alfa.omega.A; public class C { A a; }");
495 System.out.println("Compiling bin...");
496 compile("-src", "gensrc", "-d", "bin", "--server:portfile=testserver,background=false");
497 System.out.println("Compiling bin2...");
498 compile("-classpath", "bin", "-src", "gensrc2", "-d", "bin2", "--server:portfile=testserver,background=false");
499
500 previous_bin2_state = collectState(bin2);
501 populate(gensrc,
502 "alfa/omega/AA.java",
503 "package alfa.omega; public class AA { }");
504
505 System.out.println("Compiling bin again...");
506 compile("-src", "gensrc", "-d", "bin", "--server:portfile=testserver,background=false");
507 System.out.println("Compiling bin2 again...");
508 compile("-classpath", "bin", "-src", "gensrc2", "-d", "bin2", "--server:portfile=testserver,background=false");
509
510 Map<String,Long> new_bin2_state = collectState(bin2);
511 // Adding the class AA to alfa.A does not change the pubapi of the classes in alfa.A that
512 // is actually used. Thus there should be no change of bin2. If alfa.A had been inside a jar
513 // file, then bin2/javac_state would have been updated with a new timestamp for the jar.
514 verifyNewerFiles(previous_bin2_state, new_bin2_state,
515 "bin2/javac_state");
516
517 // Now modify pubapi of A
518 previous_bin2_state = collectState(bin2);
519 populate(gensrc,
520 "alfa/omega/A.java",
521 "package alfa.omega; import beta.B; public class A { B b; public int a; }");
522
523 System.out.println("Compiling bin again...");
524 compile("-src", "gensrc", "-d", "bin", "--server:portfile=testserver,background=false");
525 System.out.println("Compiling bin2 again");
526 compile("-classpath", "bin", "-src", "gensrc2", "-d", "bin2", "--server:portfile=testserver,background=false");
527
528 new_bin2_state = collectState(bin2);
529 // Check that C was really recompiled due to the change in A:s pubapi.
530 verifyNewerFiles(previous_bin2_state, new_bin2_state,
531 "bin2/gamma/C.class",
532 "bin2/javac_state");
533
534 }
535
536 /**
537 * Tests @atfile
538 * @throws Exception If test fails
539 */
540 void compileWithAtFile() throws Exception {
541 System.out.println("\nTest @atfile with command line content.");
542 System.out.println("---------------------------------------");
543
544 delete(gensrc);
545 delete(gensrc2);
546 delete(bin);
547
548 populate(gensrc,
549 "list.txt",
550 "-if */alfa/omega/A.java\n-if */beta/B.java\ngensrc\n-d bin\n",
551 "alfa/omega/A.java",
552 "package alfa.omega; import beta.B; public class A { B b; }",
553 "beta/B.java",
554 "package beta; public class B { }",
555 "beta/C.java",
556 "broken");
|