IncCompileUpdateNative.java revision 3573:c4a18ee691c4
1101353Smike/* 2101353Smike * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved. 3101353Smike * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4101353Smike * 5101353Smike * This code is free software; you can redistribute it and/or modify it 6101353Smike * under the terms of the GNU General Public License version 2 only, as 7101353Smike * published by the Free Software Foundation. 8101353Smike * 9101353Smike * This code is distributed in the hope that it will be useful, but WITHOUT 10101353Smike * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11101353Smike * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12101353Smike * version 2 for more details (a copy is included in the LICENSE file that 13101353Smike * accompanied this code). 14101353Smike * 15101353Smike * You should have received a copy of the GNU General Public License version 16101353Smike * 2 along with this work; if not, write to the Free Software Foundation, 17101353Smike * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18101353Smike * 19101353Smike * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20101353Smike * or visit www.oracle.com if you need additional information or have any 21101353Smike * questions. 22101353Smike */ 23101353Smike 24101353Smike/* 25101353Smike * @test 26101353Smike * @summary Verify native files are rewritten 27101353Smike * @bug 8054689 28101353Smike * @author Fredrik O 29101353Smike * @author sogoel (rewrite) 30101353Smike * @library /tools/lib 31101353Smike * @modules jdk.compiler/com.sun.tools.javac.api 32101353Smike * jdk.compiler/com.sun.tools.javac.main 33101353Smike * jdk.compiler/com.sun.tools.sjavac 34101353Smike * @build Wrapper toolbox.ToolBox 35101353Smike * @run main Wrapper IncCompileUpdateNative 36101353Smike */ 37101353Smike 38101353Smikeimport java.util.*; 39101353Smikeimport java.nio.file.*; 40101353Smike 41101353Smikepublic class IncCompileUpdateNative extends SJavacTester { 42101353Smike public static void main(String... args) throws Exception { 43101353Smike IncCompileUpdateNative un = new IncCompileUpdateNative(); 44101353Smike un.test(); 45101353Smike } 46101353Smike 47101353Smike // Remember the previous bin and headers state here. 48101353Smike Map<String,Long> previous_bin_state; 49101353Smike Map<String,Long> previous_headers_state; 50101353Smike 51101353Smike void test() throws Exception { 52101353Smike Files.createDirectories(GENSRC); 53101353Smike Files.createDirectories(BIN); 54101353Smike Files.createDirectories(HEADERS); 55101353Smike 56101353Smike initialCompile(); 57101353Smike incrementalCompileChangeNative(); 58101353Smike } 59101353Smike 60101353Smike // Update B.java with a new value for the final static annotated with @Native 61101353Smike // Verify that beta_B.h is rewritten again 62101353Smike void incrementalCompileChangeNative() throws Exception { 63101353Smike previous_bin_state = collectState(BIN); 64101403Smike previous_headers_state = collectState(HEADERS); 65101403Smike System.out.println("\nIn incrementalCompileChangeNative() "); 66101353Smike System.out.println("Verify that beta_B.h is rewritten again"); 67101403Smike tb.writeFile(GENSRC.resolve("beta/B.java"), 68101353Smike "package beta; import alfa.omega.A; public class B {"+ 69101353Smike "private int b() { return A.DEFINITION; } "+ 70101353Smike "@java.lang.annotation.Native final static int alfa = 43; }"); 71101353Smike 72101353Smike compile(GENSRC.toString(), 73101353Smike "-d", BIN.toString(), 74101353Smike "--state-dir=" + BIN, 75102750Smike "-h", HEADERS.toString(), 76102750Smike "-j", "1", 77101353Smike "--log=debug"); 78102750Smike Map<String,Long> new_bin_state = collectState(BIN); 79101353Smike verifyNewerFiles(previous_bin_state, new_bin_state, 80101353Smike BIN + "/beta/B.class", 81101353Smike BIN + "/beta/BINT.class", 82101353Smike BIN + "/javac_state"); 83101353Smike previous_bin_state = new_bin_state; 84101353Smike 85101353Smike Map<String,Long> new_headers_state = collectState(HEADERS); 86101353Smike verifyNewerFiles(previous_headers_state, new_headers_state, 87101353Smike HEADERS + "/beta_B.h"); 88101353Smike previous_headers_state = new_headers_state; 89101353Smike } 90101353Smike} 91101353Smike