author | sadayapalam |
Mon, 06 Feb 2017 18:14:51 +0530 | |
changeset 43584 | 63e67712246b |
parent 42822 | a84956e7ee4d |
permissions | -rw-r--r-- |
42414
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
1 |
/* |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
4 |
* |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
8 |
* |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
13 |
* accompanied this code). |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
14 |
* |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
18 |
* |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
21 |
* questions. |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
22 |
*/ |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
23 |
|
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
24 |
/* |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
25 |
* @test |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
26 |
* @bug 8162712 |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
27 |
* @summary StandardJavaFileManager.getModuleLocation() can't find a module |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
28 |
* @library /tools/lib |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
29 |
* @modules |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
30 |
* jdk.compiler/com.sun.tools.javac.api |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
31 |
* jdk.compiler/com.sun.tools.javac.main |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
32 |
* @build toolbox.JavacTask toolbox.ToolBox |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
33 |
* @run main GetLocationForModuleTest |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
34 |
*/ |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
35 |
|
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
36 |
import java.io.IOException; |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
37 |
import java.nio.file.*; |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
38 |
import java.util.*; |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
39 |
import javax.tools.*; |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
40 |
import toolbox.JavacTask; |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
41 |
import toolbox.ToolBox; |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
42 |
|
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
43 |
public class GetLocationForModuleTest extends ModuleTestBase { |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
44 |
public static void main(String... args) throws Exception { |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
45 |
new GetLocationForModuleTest().run(Paths.get(".")); |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
46 |
} |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
47 |
|
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
48 |
public void run(Path base) throws Exception { |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
49 |
// Set up some trivial modules |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
50 |
Path moduleSrc = base.resolve("module-src"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42414
diff
changeset
|
51 |
Path m1 = moduleSrc.resolve("m1x"); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42414
diff
changeset
|
52 |
tb.writeJavaFiles(m1, "module m1x { }"); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42414
diff
changeset
|
53 |
Path m2 = moduleSrc.resolve("m2x"); |
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42414
diff
changeset
|
54 |
tb.writeJavaFiles(m2, "module m2x { }"); |
42414
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
55 |
|
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
56 |
Path modulePath = base.resolve("module-path"); |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
57 |
Files.createDirectories(modulePath); |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
58 |
new JavacTask(tb) |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
59 |
.options("--module-source-path", moduleSrc.toString()) |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
60 |
.outdir(modulePath) |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
61 |
.files(findJavaFiles(moduleSrc)) |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
62 |
.run() |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
63 |
.writeAll(); |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
64 |
|
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
65 |
// Init file manager |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
66 |
StandardJavaFileManager fm = |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
67 |
ToolProvider.getSystemJavaCompiler().getStandardFileManager(null, null, null); |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
68 |
fm.setLocationFromPaths(StandardLocation.MODULE_PATH, Arrays.asList(modulePath)); |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
69 |
|
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
70 |
// Test |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
71 |
test(fm, StandardLocation.SYSTEM_MODULES, "java.base", "java.compiler"); |
42822
a84956e7ee4d
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42414
diff
changeset
|
72 |
test(fm, StandardLocation.MODULE_PATH, "m1x", "m2x"); |
42414
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
73 |
} |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
74 |
|
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
75 |
void test(JavaFileManager fm, JavaFileManager.Location locn, String... mods) throws IOException { |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
76 |
for (String mod : mods) { |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
77 |
JavaFileManager.Location modLocn = fm.getLocationForModule(locn, mod); |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
78 |
if (modLocn == null) { |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
79 |
error(locn.getName() + ": can't find " + mod); |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
80 |
} else { |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
81 |
System.err.println(locn.getName() + ": found " + mod + ": " + modLocn.getName()); |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
82 |
} |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
83 |
} |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
84 |
} |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
85 |
} |
0ae183c295a0
8162712: StandardJavaFileManager.getModuleLocation() can't find a module
jjg
parents:
diff
changeset
|
86 |