IncCompileWithChanges.java revision 3034:c8206f440046
1/* 2 * Copyright (c) 2014, 2015, 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 * @build Wrapper ToolBox 37 * @run main Wrapper IncCompileWithChanges 38 */ 39 40import java.util.*; 41import java.nio.file.*; 42 43public class IncCompileWithChanges extends SJavacTester { 44 public static void main(String... args) throws Exception { 45 IncCompileWithChanges wc = new IncCompileWithChanges(); 46 wc.test(); 47 } 48 49 // Remember the previous bin and headers state here. 50 Map<String,Long> previous_bin_state; 51 Map<String,Long> previous_headers_state; 52 ToolBox tb = new ToolBox(); 53 54 void test() throws Exception { 55 clean(TEST_ROOT); 56 Files.createDirectories(GENSRC); 57 Files.createDirectories(BIN); 58 Files.createDirectories(HEADERS); 59 60 initialCompile(); 61 incrementalCompileWithChange(); 62 } 63 64 /* Update A.java with a new timestamp and new final static definition. 65 * This should trigger a recompile, not only of alfa, but also beta. 66 * Generated native header should not be updated since native api of B was not modified. 67 */ 68 void incrementalCompileWithChange() throws Exception { 69 previous_bin_state = collectState(BIN); 70 previous_headers_state = collectState(HEADERS); 71 System.out.println("\nIn incrementalCompileWithChange() "); 72 System.out.println("A.java updated to trigger a recompile"); 73 System.out.println("Generated native header should not be updated since native api of B was not modified"); 74 tb.writeFile(GENSRC.resolve("alfa/omega/A.java"), 75 "package alfa.omega; public class A implements AINT { " + 76 "public final static int DEFINITION = 18;" + 77 "public void aint() { } private void foo() { } }"); 78 79 compile(GENSRC.toString(), 80 "-d", BIN.toString(), 81 "--state-dir=" + BIN, 82 "-h", HEADERS.toString(), 83 "-j", "1", 84 SERVER_ARG, 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