IncCompileWithChanges.java revision 3294:9adfb22ff08f
1/*
2 * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
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 * @test
26 * @summary Verify incremental changes in gensrc are handled as expected
27 * @ignore Requires dependency code to deal with in-method dependencies.
28 * @bug 8054689
29 * @author Fredrik O
30 * @author sogoel (rewrite)
31 * @library /tools/lib
32 * @modules jdk.compiler/com.sun.tools.javac.api
33 *          jdk.compiler/com.sun.tools.javac.file
34 *          jdk.compiler/com.sun.tools.javac.main
35 *          jdk.compiler/com.sun.tools.sjavac
36 *          jdk.jdeps/com.sun.tools.javap
37 * @build Wrapper ToolBox
38 * @run main Wrapper IncCompileWithChanges
39 */
40
41import java.util.*;
42import java.nio.file.*;
43
44public class IncCompileWithChanges extends SJavacTester {
45    public static void main(String... args) throws Exception {
46        IncCompileWithChanges wc = new IncCompileWithChanges();
47        wc.test();
48    }
49
50    // Remember the previous bin and headers state here.
51    Map<String,Long> previous_bin_state;
52    Map<String,Long> previous_headers_state;
53    ToolBox tb = new ToolBox();
54
55    void test() throws Exception {
56        clean(TEST_ROOT);
57        Files.createDirectories(GENSRC);
58        Files.createDirectories(BIN);
59        Files.createDirectories(HEADERS);
60
61        initialCompile();
62        incrementalCompileWithChange();
63    }
64
65    /* Update A.java with a new timestamp and new final static definition.
66     * This should trigger a recompile, not only of alfa, but also beta.
67     * Generated native header should not be updated since native api of B was not modified.
68     */
69    void incrementalCompileWithChange() throws Exception {
70        previous_bin_state = collectState(BIN);
71        previous_headers_state = collectState(HEADERS);
72        System.out.println("\nIn incrementalCompileWithChange() ");
73        System.out.println("A.java updated to trigger a recompile");
74        System.out.println("Generated native header should not be updated since native api of B was not modified");
75        tb.writeFile(GENSRC.resolve("alfa/omega/A.java"),
76                     "package alfa.omega; public class A implements AINT { " +
77                     "public final static int DEFINITION = 18;" +
78                     "public void aint() { } private void foo() { } }");
79
80        compile(GENSRC.toString(),
81                "-d", BIN.toString(),
82                "--state-dir=" + BIN,
83                "-h", HEADERS.toString(),
84                "-j", "1",
85                "--log=debug");
86        Map<String,Long> new_bin_state = collectState(BIN);
87
88        verifyNewerFiles(previous_bin_state, new_bin_state,
89                         BIN + "/alfa/omega/A.class",
90                         BIN + "/alfa/omega/AINT.class",
91                         BIN + "/alfa/omega/AA$AAAA.class",
92                         BIN + "/alfa/omega/AAAAA.class",
93                         BIN + "/alfa/omega/AA$AAA.class",
94                         BIN + "/alfa/omega/AA.class",
95                         BIN + "/alfa/omega/AA$1.class",
96                         BIN + "/beta/B.class",
97                         BIN + "/beta/BINT.class",
98                         BIN + "/javac_state");
99        previous_bin_state = new_bin_state;
100
101        Map<String,Long> new_headers_state = collectState(HEADERS);
102        verifyEqual(new_headers_state, previous_headers_state);
103    }
104}
105