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 * @bug 8054689 28 * @author Fredrik O 29 * @author sogoel (rewrite) 30 * @library /tools/lib 31 * @modules jdk.compiler/com.sun.tools.javac.api 32 * jdk.compiler/com.sun.tools.javac.main 33 * jdk.compiler/com.sun.tools.sjavac 34 * jdk.jdeps/com.sun.tools.javap 35 * @ignore Requires dependency code to deal with in-method dependencies. 36 * @build Wrapper toolbox.ToolBox 37 * @run main Wrapper IncCompileWithChanges 38 */ 39 40 import java.util.*; 41 import java.nio.file.*; 42 43 import toolbox.ToolBox; 44 45 public class IncCompileWithChanges extends SJavacTester { 46 public static void main(String... args) throws Exception { 47 IncCompileWithChanges wc = new IncCompileWithChanges(); 48 wc.test(); 49 } 50 51 // Remember the previous bin and headers state here. 52 Map<String,Long> previous_bin_state; 53 Map<String,Long> previous_headers_state; 54 ToolBox tb = new ToolBox(); 55 56 void test() throws Exception { 57 clean(TEST_ROOT); 58 Files.createDirectories(GENSRC); 59 Files.createDirectories(BIN); 60 Files.createDirectories(HEADERS); 61 62 initialCompile(); 63 incrementalCompileWithChange(); 64 } 65 66 /* Update A.java with a new timestamp and new final static definition. 67 * This should trigger a recompile, not only of alfa, but also beta. 68 * Generated native header should not be updated since native api of B was not modified. 69 */ 70 void incrementalCompileWithChange() throws Exception { 71 previous_bin_state = collectState(BIN); 72 previous_headers_state = collectState(HEADERS); 73 System.out.println("\nIn incrementalCompileWithChange() "); 74 System.out.println("A.java updated to trigger a recompile"); 75 System.out.println("Generated native header should not be updated since native api of B was not modified"); 76 tb.writeFile(GENSRC.resolve("alfa/omega/A.java"), 77 "package alfa.omega; public class A implements AINT { " + 78 "public final static int DEFINITION = 18;" + 79 "public void aint() { } private void foo() { } }"); 80 81 compile(GENSRC.toString(), 82 "-d", BIN.toString(), 83 "--state-dir=" + BIN, 84 "-h", HEADERS.toString(), 85 "-j", "1", 86 "--log=debug"); 87 Map<String,Long> new_bin_state = collectState(BIN); 88 89 verifyNewerFiles(previous_bin_state, new_bin_state, 90 BIN + "/alfa/omega/A.class", 91 BIN + "/alfa/omega/AINT.class", 92 BIN + "/alfa/omega/AA$AAAA.class", 93 BIN + "/alfa/omega/AAAAA.class", 94 BIN + "/alfa/omega/AA$AAA.class", 95 BIN + "/alfa/omega/AA.class", 96 BIN + "/alfa/omega/AA$1.class", 97 BIN + "/beta/B.class", 98 BIN + "/beta/BINT.class", 99 BIN + "/javac_state"); 100 previous_bin_state = new_bin_state; 101 102 Map<String,Long> new_headers_state = collectState(HEADERS); 103 verifyEqual(new_headers_state, previous_headers_state); 104 } 105 }