|
1 /* |
|
2 * Copyright (c) 2014, 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 native files are removed when native method is removed |
|
27 * @bug 8054689 |
|
28 * @author Fredrik O |
|
29 * @author sogoel (rewrite) |
|
30 * @library /tools/lib |
|
31 * @build Wrapper ToolBox |
|
32 * @run main Wrapper IncCompileChangeNative |
|
33 */ |
|
34 |
|
35 import java.util.*; |
|
36 import java.nio.file.*; |
|
37 |
|
38 public class IncCompileChangeNative extends SJavacTester { |
|
39 public static void main(String... args) throws Exception { |
|
40 IncCompileChangeNative cn = new IncCompileChangeNative(); |
|
41 cn.test(); |
|
42 } |
|
43 |
|
44 // Remember the previous bin and headers state here. |
|
45 Map<String,Long> previous_bin_state; |
|
46 Map<String,Long> previous_headers_state; |
|
47 ToolBox tb = new ToolBox(); |
|
48 |
|
49 void test() throws Exception { |
|
50 Files.createDirectory(GENSRC); |
|
51 Files.createDirectory(BIN); |
|
52 Files.createDirectory(HEADERS); |
|
53 |
|
54 initialCompile(); |
|
55 incrementalCompileDropAllNatives(); |
|
56 incrementalCompileAddNative(); |
|
57 |
|
58 clean(GENSRC, BIN, HEADERS); |
|
59 } |
|
60 |
|
61 // Update B.java with one less native method i.e. it has no longer any methods |
|
62 // Verify that beta_B.h is removed |
|
63 void incrementalCompileDropAllNatives() throws Exception { |
|
64 previous_bin_state = collectState(BIN); |
|
65 previous_headers_state = collectState(HEADERS); |
|
66 System.out.println("\nIn incrementalCompileDropAllNatives() "); |
|
67 System.out.println("Verify that beta_B.h is removed"); |
|
68 tb.writeFile(GENSRC.resolve("beta/B.java"), |
|
69 "package beta; import alfa.omega.A; public class B {"+ |
|
70 "private int b() { return A.DEFINITION; } }"); |
|
71 |
|
72 compile("gensrc", "-d", "bin", "-h", "headers", "-j", "1", |
|
73 SERVER_ARG, "--log=debug"); |
|
74 Map<String,Long> new_bin_state = collectState(BIN); |
|
75 verifyNewerFiles(previous_bin_state, new_bin_state, |
|
76 "bin/beta/B.class", |
|
77 "bin/beta/BINT.class", |
|
78 "bin/javac_state"); |
|
79 previous_bin_state = new_bin_state; |
|
80 |
|
81 Map<String,Long> new_headers_state = collectState(HEADERS); |
|
82 verifyThatFilesHaveBeenRemoved(previous_headers_state, new_headers_state, |
|
83 "headers/beta_B.h"); |
|
84 previous_headers_state = new_headers_state; |
|
85 } |
|
86 |
|
87 // Update the B.java with a final static annotated with @Native |
|
88 // Verify that beta_B.h is added again |
|
89 void incrementalCompileAddNative() throws Exception { |
|
90 System.out.println("\nIn incrementalCompileAddNative() "); |
|
91 System.out.println("Verify that beta_B.h is added again"); |
|
92 tb.writeFile(GENSRC.resolve("beta/B.java"), |
|
93 "package beta; import alfa.omega.A; public class B {"+ |
|
94 "private int b() { return A.DEFINITION; } "+ |
|
95 "@java.lang.annotation.Native final static int alfa = 42; }"); |
|
96 |
|
97 compile("gensrc", "-d", "bin", "-h", "headers", "-j", "1", |
|
98 SERVER_ARG, "--log=debug"); |
|
99 Map<String,Long> new_bin_state = collectState(BIN); |
|
100 verifyNewerFiles(previous_bin_state, new_bin_state, |
|
101 "bin/beta/B.class", |
|
102 "bin/beta/BINT.class", |
|
103 "bin/javac_state"); |
|
104 previous_bin_state = new_bin_state; |
|
105 |
|
106 Map<String,Long> new_headers_state = collectState(HEADERS); |
|
107 verifyThatFilesHaveBeenAdded(previous_headers_state, new_headers_state, |
|
108 "headers/beta_B.h"); |
|
109 previous_headers_state = new_headers_state; |
|
110 } |
|
111 } |