author | mchung |
Mon, 12 Dec 2016 18:56:50 -0800 | |
changeset 42670 | d833113eb7d7 |
parent 42471 | 86b1da05a4b0 |
child 42690 | 93d0411bd67d |
permissions | -rw-r--r-- |
42471
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
1 |
/* |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
4 |
* |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
8 |
* |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
13 |
* accompanied this code). |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
14 |
* |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
18 |
* |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
21 |
* questions. |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
22 |
*/ |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
23 |
|
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
24 |
import java.io.File; |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
25 |
import java.io.FileReader; |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
26 |
import java.io.IOException; |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
27 |
import java.io.PrintWriter; |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
28 |
import java.io.StringWriter; |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
29 |
import java.nio.file.Path; |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
30 |
import java.util.Properties; |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
31 |
import java.util.spi.ToolProvider; |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
32 |
|
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
33 |
import tests.Helper; |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
34 |
import tests.JImageGenerator; |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
35 |
|
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
36 |
/* |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
37 |
* @test |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
38 |
* @bug 8168925 |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
39 |
* @summary MODULES property should be topologically ordered and space-separated list |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
40 |
* @library ../lib |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
41 |
* @build tests.* |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
42 |
* @run main ModuleNamesOrderTest |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
43 |
*/ |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
44 |
public class ModuleNamesOrderTest { |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
45 |
static final ToolProvider JLINK_TOOL = ToolProvider.findFirst("jlink") |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
46 |
.orElseThrow(() -> |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
47 |
new RuntimeException("jlink tool not found") |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
48 |
); |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
49 |
|
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
50 |
public static void main(String[] args) throws Exception { |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
51 |
Helper helper = Helper.newHelper(); |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
52 |
if (helper == null) { |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
53 |
System.err.println("Test not run"); |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
54 |
return; |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
55 |
} |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
56 |
|
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
57 |
Path outputDir = helper.createNewImageDir("image8168925"); |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
58 |
JImageGenerator.getJLinkTask() |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
59 |
.modulePath(helper.defaultModulePath()) |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
60 |
.output(outputDir) |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
61 |
.addMods("jdk.scripting.nashorn") |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
62 |
.call().assertSuccess(); |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
63 |
|
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
64 |
File release = new File(outputDir.toString(), "release"); |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
65 |
if (!release.exists()) { |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
66 |
throw new AssertionError("release not generated"); |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
67 |
} |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
68 |
|
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
69 |
Properties props = new Properties(); |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
70 |
try (FileReader reader = new FileReader(release)) { |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
71 |
props.load(reader); |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
72 |
} |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
73 |
|
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
74 |
String modules = props.getProperty("MODULES"); |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
75 |
if (!modules.startsWith("\"java.base ")) { |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
76 |
throw new AssertionError("MODULES should start with 'java.base'"); |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
77 |
} |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
78 |
|
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
79 |
if (!modules.endsWith(" jdk.scripting.nashorn\"")) { |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
80 |
throw new AssertionError("MODULES end with 'jdk.scripting.nashorn'"); |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
81 |
} |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
82 |
|
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
83 |
checkDependency(modules, "java.logging", "java.base"); |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
84 |
checkDependency(modules, "jdk.dynalink", "java.logging"); |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
85 |
checkDependency(modules, "java.scripting", "java.base"); |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
86 |
checkDependency(modules, "jdk.scripting.nashorn", "java.logging"); |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
87 |
checkDependency(modules, "jdk.scripting.nashorn", "jdk.dynalink"); |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
88 |
checkDependency(modules, "jdk.scripting.nashorn", "java.scripting"); |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
89 |
} |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
90 |
|
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
91 |
private static void checkDependency(String modules, String fromMod, String toMod) { |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
92 |
int fromModIdx = modules.indexOf(fromMod); |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
93 |
if (fromModIdx == -1) { |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
94 |
throw new AssertionError(fromMod + " is missing in MODULES"); |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
95 |
} |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
96 |
int toModIdx = modules.indexOf(toMod); |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
97 |
if (toModIdx == -1) { |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
98 |
throw new AssertionError(toMod + " is missing in MODULES"); |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
99 |
} |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
100 |
|
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
101 |
if (toModIdx > fromModIdx) { |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
102 |
throw new AssertionError("in MODULES, " + fromMod + " should appear after " + toMod); |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
103 |
} |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
104 |
} |
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
diff
changeset
|
105 |
} |