author | sadayapalam |
Mon, 06 Feb 2017 18:14:51 +0530 | |
changeset 43584 | 63e67712246b |
parent 42822 | a84956e7ee4d |
permissions | -rw-r--r-- |
36526 | 1 |
/* |
2 |
* Copyright (c) 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 |
* @bug 8145013 |
|
27 |
* @summary Javac doesn't report warnings/errors if module provides unexported service and doesn't use it itself |
|
28 |
* @library /tools/lib |
|
29 |
* @modules |
|
30 |
* jdk.compiler/com.sun.tools.javac.api |
|
31 |
* jdk.compiler/com.sun.tools.javac.main |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
32 |
* @build toolbox.ToolBox toolbox.JavacTask ModuleTestBase |
36526 | 33 |
* @run main ServiceProvidedButNotExportedOrUsedTest |
34 |
*/ |
|
35 |
||
36 |
import java.nio.file.Files; |
|
37 |
import java.nio.file.Path; |
|
38 |
import java.util.Arrays; |
|
39 |
import java.util.List; |
|
40 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
41 |
import toolbox.JavacTask; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
42 |
import toolbox.Task; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
43 |
import toolbox.ToolBox; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
44 |
|
36526 | 45 |
public class ServiceProvidedButNotExportedOrUsedTest extends ModuleTestBase { |
46 |
public static void main(String... args) throws Exception { |
|
47 |
ServiceProvidedButNotExportedOrUsedTest t = new ServiceProvidedButNotExportedOrUsedTest(); |
|
48 |
t.runTests(); |
|
49 |
} |
|
50 |
||
51 |
@Test |
|
37758 | 52 |
public void testWarning(Path base) throws Exception { |
36526 | 53 |
Path src = base.resolve("src"); |
54 |
tb.writeJavaFiles(src, |
|
55 |
"module m { provides p1.C1 with p2.C2; }", |
|
56 |
"package p1; public class C1 { }", |
|
57 |
"package p2; public class C2 extends p1.C1 { }"); |
|
58 |
Path classes = base.resolve("classes"); |
|
59 |
Files.createDirectories(classes); |
|
60 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
61 |
List<String> output = new JavacTask(tb) |
36526 | 62 |
.outdir(classes) |
63 |
.options("-Werror", "-XDrawDiagnostics") |
|
64 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
65 |
.run(Task.Expect.FAIL) |
36526 | 66 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
67 |
.getOutputLines(Task.OutputKind.DIRECT); |
36526 | 68 |
List<String> expected = Arrays.asList( |
69 |
"module-info.java:1:12: compiler.warn.service.provided.but.not.exported.or.used: p1.C1", |
|
70 |
"- compiler.err.warnings.and.werror", |
|
71 |
"1 error", |
|
72 |
"1 warning"); |
|
73 |
if (!output.containsAll(expected)) { |
|
74 |
throw new Exception("Expected output not found"); |
|
75 |
} |
|
76 |
} |
|
77 |
||
78 |
@Test |
|
37758 | 79 |
public void testImplementationMustBeInSameModuleAsProvidesDirective(Path base) throws Exception { |
36526 | 80 |
Path src = base.resolve("src"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40308
diff
changeset
|
81 |
tb.writeJavaFiles(src.resolve("m1x"), |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40308
diff
changeset
|
82 |
"module m1x { exports p1; }", |
36526 | 83 |
"package p1; public class C1 { }"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40308
diff
changeset
|
84 |
tb.writeJavaFiles(src.resolve("m2x"), |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40308
diff
changeset
|
85 |
"module m2x { requires m1x; requires m3x; provides p1.C1 with p2.C2; }"); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40308
diff
changeset
|
86 |
tb.writeJavaFiles(src.resolve("m3x"), |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40308
diff
changeset
|
87 |
"module m3x { requires m1x; exports p2; }", |
36526 | 88 |
"package p2; public class C2 extends p1.C1 { }"); |
89 |
Path modules = base.resolve("modules"); |
|
90 |
Files.createDirectories(modules); |
|
91 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
92 |
List<String> output = new JavacTask(tb) |
40308
274367a99f98
8136930: Simplify use of module-system options by custom launchers
jjg
parents:
37758
diff
changeset
|
93 |
.options("-XDrawDiagnostics", "--module-source-path", src.toString()) |
36526 | 94 |
.outdir(modules) |
95 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
96 |
.run(Task.Expect.FAIL) |
36526 | 97 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
98 |
.getOutputLines(Task.OutputKind.DIRECT); |
36526 | 99 |
List<String> expected = Arrays.asList( |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
40308
diff
changeset
|
100 |
"module-info.java:1:42: compiler.err.service.implementation.not.in.right.module: m3x", |
36526 | 101 |
"1 error"); |
102 |
if (!output.containsAll(expected)) { |
|
103 |
throw new Exception("Expected output not found"); |
|
104 |
} |
|
105 |
} |
|
106 |
} |