Path: blob/master/test/langtools/tools/sjavac/IncCompileChangeNative.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 native files are removed when native method is removed26* @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* @build Wrapper toolbox.ToolBox34* @run main Wrapper IncCompileChangeNative35*/3637import java.util.*;38import java.nio.file.*;3940public class IncCompileChangeNative extends SJavacTester {41public static void main(String... args) throws Exception {42IncCompileChangeNative cn = new IncCompileChangeNative();43cn.test();44}4546// Remember the previous bin and headers state here.47Map<String,Long> previous_bin_state;48Map<String,Long> previous_headers_state;4950void test() throws Exception {51Files.createDirectories(GENSRC);52Files.createDirectories(BIN);53Files.createDirectories(HEADERS);5455initialCompile();56incrementalCompileDropAllNatives();57incrementalCompileAddNative();58}5960// Update B.java with one less native method i.e. it has no longer any methods61// Verify that beta_B.h is removed62void incrementalCompileDropAllNatives() throws Exception {63previous_bin_state = collectState(BIN);64previous_headers_state = collectState(HEADERS);65System.out.println("\nIn incrementalCompileDropAllNatives() ");66System.out.println("Verify that beta_B.h is removed");67tb.writeFile(GENSRC.resolve("beta/B.java"),68"package beta; import alfa.omega.A; " +69"public class B { private int b() { return A.DEFINITION; } }");7071compile(GENSRC.toString(),72"-d", BIN.toString(),73"--state-dir=" + BIN,74"-h", HEADERS.toString(),75"-j", "1",76"--log=debug");77Map<String,Long> new_bin_state = collectState(BIN);78verifyNewerFiles(previous_bin_state, new_bin_state,79BIN + "/beta/B.class",80BIN + "/beta/BINT.class",81BIN + "/javac_state");82previous_bin_state = new_bin_state;8384Map<String,Long> new_headers_state = collectState(HEADERS);85verifyThatFilesHaveBeenRemoved(previous_headers_state, new_headers_state,86HEADERS + "/beta_B.h");87previous_headers_state = new_headers_state;88}8990// Update the B.java with a final static annotated with @Native91// Verify that beta_B.h is added again92void incrementalCompileAddNative() throws Exception {93System.out.println("\nIn incrementalCompileAddNative() ");94System.out.println("Verify that beta_B.h is added again");95tb.writeFile(GENSRC.resolve("beta/B.java"),96"package beta; import alfa.omega.A; public class B {"+97"private int b() { return A.DEFINITION; } "+98"@java.lang.annotation.Native final static int alfa = 42; }");99100compile(GENSRC.toString(),101"-d", BIN.toString(),102"--state-dir=" + BIN,103"-h", HEADERS.toString(),104"-j", "1",105"--log=debug");106Map<String,Long> new_bin_state = collectState(BIN);107verifyNewerFiles(previous_bin_state, new_bin_state,108BIN + "/beta/B.class",109BIN + "/beta/BINT.class",110BIN + "/javac_state");111previous_bin_state = new_bin_state;112113Map<String,Long> new_headers_state = collectState(HEADERS);114verifyThatFilesHaveBeenAdded(previous_headers_state, new_headers_state,115HEADERS + "/beta_B.h");116previous_headers_state = new_headers_state;117}118}119120121