Path: blob/master/test/langtools/tools/sjavac/IncCompileWithChanges.java
41144 views
/*1* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @summary Verify incremental changes in gensrc are handled as expected26* @bug 805468927* @author Fredrik O28* @author sogoel (rewrite)29* @library /tools/lib30* @modules jdk.compiler/com.sun.tools.javac.api31* jdk.compiler/com.sun.tools.javac.main32* jdk.compiler/com.sun.tools.sjavac33* @ignore Requires dependency code to deal with in-method dependencies.34* @build Wrapper toolbox.ToolBox35* @run main Wrapper IncCompileWithChanges36*/3738import java.util.*;39import java.nio.file.*;4041import toolbox.ToolBox;4243public class IncCompileWithChanges extends SJavacTester {44public static void main(String... args) throws Exception {45IncCompileWithChanges wc = new IncCompileWithChanges();46wc.test();47}4849// Remember the previous bin and headers state here.50Map<String,Long> previous_bin_state;51Map<String,Long> previous_headers_state;5253void test() throws Exception {54clean(TEST_ROOT);55Files.createDirectories(GENSRC);56Files.createDirectories(BIN);57Files.createDirectories(HEADERS);5859initialCompile();60incrementalCompileWithChange();61}6263/* Update A.java with a new timestamp and new final static definition.64* This should trigger a recompile, not only of alfa, but also beta.65* Generated native header should not be updated since native api of B was not modified.66*/67void incrementalCompileWithChange() throws Exception {68previous_bin_state = collectState(BIN);69previous_headers_state = collectState(HEADERS);70System.out.println("\nIn incrementalCompileWithChange() ");71System.out.println("A.java updated to trigger a recompile");72System.out.println("Generated native header should not be updated since native api of B was not modified");73tb.writeFile(GENSRC.resolve("alfa/omega/A.java"),74"package alfa.omega; public class A implements AINT { " +75"public final static int DEFINITION = 18;" +76"public void aint() { } private void foo() { } }");7778compile(GENSRC.toString(),79"-d", BIN.toString(),80"--state-dir=" + BIN,81"-h", HEADERS.toString(),82"-j", "1",83"--log=debug");84Map<String,Long> new_bin_state = collectState(BIN);8586verifyNewerFiles(previous_bin_state, new_bin_state,87BIN + "/alfa/omega/A.class",88BIN + "/alfa/omega/AINT.class",89BIN + "/alfa/omega/AA$AAAA.class",90BIN + "/alfa/omega/AAAAA.class",91BIN + "/alfa/omega/AA$AAA.class",92BIN + "/alfa/omega/AA.class",93BIN + "/alfa/omega/AA$1.class",94BIN + "/beta/B.class",95BIN + "/beta/BINT.class",96BIN + "/javac_state");97previous_bin_state = new_bin_state;9899Map<String,Long> new_headers_state = collectState(HEADERS);100verifyEqual(new_headers_state, previous_headers_state);101}102}103104105