author | jjg |
Wed, 03 Aug 2016 16:01:09 -0700 | |
changeset 40232 | 4995ab1a4558 |
parent 37758 | 3ecf9b414e05 |
child 40308 | 274367a99f98 |
permissions | -rw-r--r-- |
36526 | 1 |
/* |
2 |
* Copyright (c) 2015, 2016, 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 tests for output directory |
|
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 OutputDirTest |
33 |
*/ |
|
34 |
||
35 |
import java.io.IOException; |
|
36 |
import java.nio.file.Files; |
|
37 |
import java.nio.file.Path; |
|
38 |
import java.nio.file.Paths; |
|
39 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
40 |
import toolbox.JavacTask; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
41 |
import toolbox.Task; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
42 |
import toolbox.ToolBox; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
43 |
|
36526 | 44 |
public class OutputDirTest extends ModuleTestBase { |
45 |
public static void main(String... args) throws Exception { |
|
46 |
new OutputDirTest().run(); |
|
47 |
} |
|
48 |
||
49 |
Path src; |
|
50 |
||
51 |
void run() throws Exception { |
|
52 |
tb = new ToolBox(); |
|
53 |
||
54 |
src = Paths.get("src"); |
|
55 |
tb.writeJavaFiles(src.resolve("m"), |
|
56 |
"module m { }", |
|
57 |
"package p; class C { }"); |
|
58 |
||
59 |
runTests(); |
|
60 |
} |
|
61 |
||
62 |
@Test |
|
37758 | 63 |
public void testError(Path base) throws Exception { |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
64 |
String log = new JavacTask(tb) |
36526 | 65 |
.options("-XDrawDiagnostics", |
66 |
"-modulesourcepath", src.toString()) |
|
67 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
68 |
.run(Task.Expect.FAIL) |
36526 | 69 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
70 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 71 |
|
72 |
if (!log.contains("- compiler.err.no.output.dir")) |
|
73 |
throw new Exception("expected output not found"); |
|
74 |
} |
|
75 |
||
76 |
@Test |
|
37758 | 77 |
public void testProcOnly(Path base) throws IOException { |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
78 |
new JavacTask(tb) |
36526 | 79 |
.options("-XDrawDiagnostics", |
80 |
"-proc:only", |
|
81 |
"-modulesourcepath", src.toString()) |
|
82 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
83 |
.run(Task.Expect.SUCCESS) |
36526 | 84 |
.writeAll(); |
85 |
} |
|
86 |
||
87 |
@Test |
|
37758 | 88 |
public void testClassOutDir(Path base) throws IOException { |
36526 | 89 |
Path classes = base.resolve("classes"); |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
90 |
new JavacTask(tb) |
36526 | 91 |
.options("-XDrawDiagnostics", |
92 |
"-d", classes.toString(), |
|
93 |
"-modulesourcepath", src.toString()) |
|
94 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
95 |
.run(Task.Expect.SUCCESS) |
36526 | 96 |
.writeAll(); |
97 |
} |
|
98 |
||
99 |
@Test |
|
37758 | 100 |
public void testExplodedOutDir(Path base) throws Exception { |
36526 | 101 |
Path modSrc = base.resolve("modSrc"); |
102 |
tb.writeJavaFiles(modSrc, |
|
103 |
"module m1 { exports p; }", |
|
104 |
"package p; public class CC { }"); |
|
105 |
Path modClasses = base.resolve("modClasses"); |
|
106 |
Files.createDirectories(modClasses); |
|
107 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
108 |
new JavacTask(tb, Task.Mode.CMDLINE) |
36526 | 109 |
.outdir(modClasses) |
110 |
.files(findJavaFiles(modSrc)) |
|
111 |
.run() |
|
112 |
.writeAll(); |
|
113 |
||
114 |
Path src = base.resolve("src"); |
|
115 |
Path src_m = src.resolve("m"); |
|
116 |
tb.writeJavaFiles(src_m, |
|
117 |
"module m { requires m1 ; }", |
|
118 |
"class C { }"); |
|
119 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
120 |
String log = new JavacTask(tb, Task.Mode.CMDLINE) |
36526 | 121 |
.outdir(modClasses) // an exploded module |
122 |
.options("-XDrawDiagnostics", |
|
123 |
"-modulesourcepath", src.toString()) |
|
124 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
125 |
.run(Task.Expect.FAIL) |
36526 | 126 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
127 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 128 |
|
129 |
if (!log.contains("- compiler.err.multi-module.outdir.cannot.be.exploded.module: " + modClasses.toString())) |
|
130 |
throw new Exception("expected output not found"); |
|
131 |
} |
|
132 |
||
133 |
@Test |
|
37758 | 134 |
public void testInExplodedOutDir(Path base) throws Exception { |
36526 | 135 |
Path modSrc = base.resolve("modSrc"); |
136 |
tb.writeJavaFiles(modSrc, |
|
137 |
"module m1 { exports p; }", |
|
138 |
"package p; public class CC { }"); |
|
139 |
Path modClasses = base.resolve("modClasses"); |
|
140 |
Files.createDirectories(modClasses); |
|
141 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
142 |
new JavacTask(tb, Task.Mode.CMDLINE) |
36526 | 143 |
.outdir(modClasses) |
144 |
.files(findJavaFiles(modSrc)) |
|
145 |
.run() |
|
146 |
.writeAll(); |
|
147 |
||
148 |
Path src = base.resolve("src"); |
|
149 |
tb.writeJavaFiles(src, |
|
150 |
"module m { requires m1 ; }", |
|
151 |
"class C { }"); |
|
152 |
||
153 |
Path classes = modClasses.resolve("m"); |
|
154 |
Files.createDirectories(classes); |
|
155 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
156 |
String log = new JavacTask(tb, Task.Mode.CMDLINE) |
36526 | 157 |
.outdir(classes) // within an exploded module |
158 |
.options("-XDrawDiagnostics", |
|
159 |
"-Xlint", "-Werror", |
|
160 |
"-modulepath", modClasses.toString()) |
|
161 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
162 |
.run(Task.Expect.FAIL) |
36526 | 163 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
164 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 165 |
|
166 |
if (!log.contains("- compiler.warn.outdir.is.in.exploded.module: " + classes.toString())) |
|
167 |
throw new Exception("expected output not found"); |
|
168 |
} |
|
169 |
} |