author | jjg |
Thu, 26 May 2016 10:45:13 -0700 | |
changeset 38611 | b5a479aff686 |
parent 37758 | 3ecf9b414e05 |
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 8145016 |
|
26 |
* @summary Javac doesn't report errors on service implementation which cannot be initialized |
|
27 |
* @library /tools/lib |
|
28 |
* @modules |
|
29 |
* jdk.compiler/com.sun.tools.javac.api |
|
30 |
* jdk.compiler/com.sun.tools.javac.main |
|
31 |
* jdk.jdeps/com.sun.tools.javap |
|
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 AbstractOrInnerClassServiceImplTest |
34 |
*/ |
|
35 |
||
36 |
import java.nio.file.Files; |
|
37 |
import java.nio.file.Path; |
|
38 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
39 |
import toolbox.JavacTask; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
40 |
import toolbox.Task; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
41 |
import toolbox.ToolBox; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
42 |
|
36526 | 43 |
public class AbstractOrInnerClassServiceImplTest extends ModuleTestBase { |
44 |
public static void main(String... args) throws Exception { |
|
45 |
AbstractOrInnerClassServiceImplTest t = new AbstractOrInnerClassServiceImplTest(); |
|
46 |
t.runTests(); |
|
47 |
} |
|
48 |
||
49 |
@Test |
|
37758 | 50 |
public void testAbstractServiceImpl(Path base) throws Exception { |
36526 | 51 |
Path src = base.resolve("src"); |
52 |
tb.writeJavaFiles(src, |
|
53 |
"module m { provides p1.Service with p2.Impl; }", |
|
54 |
"package p1; public interface Service { }", |
|
55 |
"package p2; public interface Impl extends p1.Service { }"); |
|
56 |
Path classes = base.resolve("classes"); |
|
57 |
Files.createDirectories(classes); |
|
58 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
59 |
String log = new JavacTask(tb) |
36526 | 60 |
.options("-XDrawDiagnostics") |
61 |
.outdir(classes) |
|
62 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
63 |
.run(Task.Expect.FAIL) |
36526 | 64 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
65 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 66 |
if (!log.contains("module-info.java:1:39: compiler.err.service.implementation.is.abstract: p2.Impl")) |
67 |
throw new Exception("expected output not found"); |
|
68 |
} |
|
69 |
||
70 |
@Test |
|
37758 | 71 |
public void testInnerClassServiceImpl(Path base) throws Exception { |
36526 | 72 |
Path src = base.resolve("src"); |
73 |
tb.writeJavaFiles(src, |
|
74 |
"module m { provides p1.Service with p2.Outer.Inner; }", |
|
75 |
"package p1; public interface Service { }", |
|
76 |
"package p2; public class Outer { public class Inner implements p1.Service {} }"); |
|
77 |
Path classes = base.resolve("classes"); |
|
78 |
Files.createDirectories(classes); |
|
79 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
80 |
String log = new JavacTask(tb) |
36526 | 81 |
.options("-XDrawDiagnostics") |
82 |
.outdir(classes) |
|
83 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
84 |
.run(Task.Expect.FAIL) |
36526 | 85 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
86 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 87 |
if (!log.contains("module-info.java:1:45: compiler.err.service.implementation.is.inner: p2.Outer.Inner")) |
88 |
throw new Exception("expected output not found"); |
|
89 |
} |
|
90 |
||
91 |
@Test |
|
37758 | 92 |
public void testInnerInterfaceServiceImpl(Path base) throws Exception { |
36526 | 93 |
Path src = base.resolve("src"); |
94 |
tb.writeJavaFiles(src, |
|
95 |
"module m { provides p1.Service with p2.Outer.Inner; }", |
|
96 |
"package p1; public interface Service { }", |
|
97 |
"package p2; public class Outer { public interface Inner extends p1.Service {} }"); |
|
98 |
Path classes = base.resolve("classes"); |
|
99 |
Files.createDirectories(classes); |
|
100 |
||
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
101 |
String log = new JavacTask(tb) |
36526 | 102 |
.options("-XDrawDiagnostics") |
103 |
.outdir(classes) |
|
104 |
.files(findJavaFiles(src)) |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
105 |
.run(Task.Expect.FAIL) |
36526 | 106 |
.writeAll() |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
107 |
.getOutput(Task.OutputKind.DIRECT); |
36526 | 108 |
if (!log.contains("module-info.java:1:45: compiler.err.service.implementation.is.abstract: p2.Outer.Inner")) |
109 |
throw new Exception("expected output not found"); |
|
110 |
} |
|
111 |
} |