author | jjg |
Thu, 26 May 2016 10:45:13 -0700 | |
changeset 38611 | b5a479aff686 |
parent 37758 | 3ecf9b414e05 |
child 40308 | 274367a99f98 |
permissions | -rw-r--r-- |
36526 | 1 |
/* |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
2 |
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. |
36526 | 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 tests for subpackage issues |
|
27 |
* @library /tools/lib |
|
28 |
* @modules |
|
29 |
* jdk.compiler/com.sun.tools.javac.api |
|
30 |
* jdk.compiler/com.sun.tools.javac.main |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
31 |
* @build toolbox.ToolBox toolbox.JavacTask ModuleTestBase |
36526 | 32 |
* @run main SubpackageTest |
33 |
*/ |
|
34 |
||
35 |
import java.nio.file.Files; |
|
36 |
import java.nio.file.Path; |
|
37 |
import java.util.ArrayList; |
|
38 |
import java.util.Arrays; |
|
39 |
import java.util.Collections; |
|
40 |
import java.util.List; |
|
41 |
import java.util.stream.Collectors; |
|
42 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
43 |
import toolbox.JavacTask; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
44 |
import toolbox.Task; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
45 |
import toolbox.ToolBox; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
46 |
|
36526 | 47 |
public class SubpackageTest extends ModuleTestBase { |
48 |
||
49 |
public static void main(String... args) throws Exception { |
|
50 |
SubpackageTest t = new SubpackageTest(); |
|
51 |
t.runTests(); |
|
52 |
} |
|
53 |
||
54 |
@Test // based on JDK-8075435 |
|
37758 | 55 |
public void testUnnamedModule(Path base) throws Exception { |
36526 | 56 |
Path libsrc = base.resolve("lib/src"); |
57 |
tb.writeJavaFiles(libsrc, |
|
58 |
"package p; public class E extends Error { }"); |
|
59 |
Path libclasses = base.resolve("lib/classes"); |
|
60 |
Files.createDirectories(libclasses); |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
61 |
new JavacTask(tb) |
36526 | 62 |
.outdir(libclasses) |
63 |
.files(findJavaFiles(libsrc)) |
|
64 |
.run() |
|
65 |
.writeAll(); |
|
66 |
||
67 |
Path src = base.resolve("src"); |
|
68 |
tb.writeJavaFiles(src, |
|
69 |
"package p.q;\n" |
|
70 |
+ "import p.E;\n" |
|
71 |
+ "class Test {\n" |
|
72 |
+ " void m() { throw new E(); }\n" |
|
73 |
+ "}"); |
|
74 |
Path classes = base.resolve("classes"); |
|
75 |
Files.createDirectories(classes); |
|
76 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
77 |
new JavacTask(tb) |
36526 | 78 |
.classpath(libclasses) |
79 |
.outdir(classes) |
|
80 |
.files(findJavaFiles(src)) |
|
81 |
.run() |
|
82 |
.writeAll(); |
|
83 |
} |
|
84 |
||
85 |
@Test |
|
37758 | 86 |
public void testSimpleMulti(Path base) throws Exception { |
36526 | 87 |
Path src = base.resolve("src"); |
88 |
tb.writeJavaFiles(src.resolve("mp"), |
|
89 |
"module mp { exports p; }", |
|
90 |
"package p; public class C1 { }"); |
|
91 |
tb.writeJavaFiles(src.resolve("mpq"), |
|
92 |
"module mpq { exports p.q; }", |
|
93 |
"package p.q; public class C2 { }"); |
|
94 |
tb.writeJavaFiles(src.resolve("mpqr"), |
|
95 |
"module mpqr { exports p.q.r; }", |
|
96 |
"package p.q.r; public class C3 { }"); |
|
97 |
tb.writeJavaFiles(src.resolve("m"), |
|
98 |
"module m {" |
|
99 |
+ " requires mp;\n" |
|
100 |
+ " requires mpq;\n" |
|
101 |
+ " requires mpqr;\n" |
|
102 |
+ "}", |
|
103 |
"package x;\n" |
|
104 |
+ "class C {\n" |
|
105 |
+ " p.C1 c1;\n" |
|
106 |
+ " p.q.C2 c2;\n" |
|
107 |
+ " p.q.r.C3 c3;\n" |
|
108 |
+ "}"); |
|
109 |
Path modules = base.resolve("modules"); |
|
110 |
Files.createDirectories(modules); |
|
111 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
112 |
new JavacTask(tb) |
36526 | 113 |
.options("-modulesourcepath", src.toString()) |
114 |
.outdir(modules) |
|
115 |
.files(findJavaFiles(src)) |
|
116 |
.run() |
|
117 |
.writeAll(); |
|
118 |
} |
|
119 |
||
120 |
} |