author | lancea |
Wed, 03 Apr 2019 11:30:23 -0400 | |
changeset 54413 | 30067047ed88 |
parent 52723 | f24ae8376e71 |
permissions | -rw-r--r-- |
36511 | 1 |
/* |
54413
30067047ed88
8216539: tools/jar/modularJar/Basic.java times out
lancea
parents:
52723
diff
changeset
|
2 |
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. |
36511 | 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 |
import java.io.*; |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
25 |
import java.lang.module.ModuleDescriptor; |
36511 | 26 |
import java.lang.reflect.Method; |
54413
30067047ed88
8216539: tools/jar/modularJar/Basic.java times out
lancea
parents:
52723
diff
changeset
|
27 |
import java.nio.file.Files; |
30067047ed88
8216539: tools/jar/modularJar/Basic.java times out
lancea
parents:
52723
diff
changeset
|
28 |
import java.nio.file.Path; |
30067047ed88
8216539: tools/jar/modularJar/Basic.java times out
lancea
parents:
52723
diff
changeset
|
29 |
import java.nio.file.Paths; |
36511 | 30 |
import java.util.*; |
31 |
import java.util.function.Consumer; |
|
32 |
import java.util.jar.JarEntry; |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
33 |
import java.util.jar.JarFile; |
36511 | 34 |
import java.util.jar.JarInputStream; |
38468
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
35 |
import java.util.jar.Manifest; |
36511 | 36 |
import java.util.regex.Pattern; |
54413
30067047ed88
8216539: tools/jar/modularJar/Basic.java times out
lancea
parents:
52723
diff
changeset
|
37 |
import java.util.spi.ToolProvider; |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
38 |
import java.util.stream.Collectors; |
36511 | 39 |
import java.util.stream.Stream; |
40 |
||
45286
cd809e28c082
8180887: move FileUtils to top level testlibrary
iignatyev
parents:
45004
diff
changeset
|
41 |
import jdk.test.lib.util.FileUtils; |
51687
1e39953aaed8
8182404: remove jdk.testlibrary.JDKToolFinder and JDKToolLauncher
iignatyev
parents:
50130
diff
changeset
|
42 |
import jdk.test.lib.JDKToolFinder; |
36511 | 43 |
import org.testng.annotations.BeforeTest; |
44267
00898a596f31
8176772: jar tool support to report automatic module names
chegar
parents:
43797
diff
changeset
|
44 |
import org.testng.annotations.DataProvider; |
36511 | 45 |
import org.testng.annotations.Test; |
46 |
||
47 |
import static java.lang.String.format; |
|
48 |
import static java.lang.System.out; |
|
49 |
||
50 |
/* |
|
51 |
* @test |
|
52723
f24ae8376e71
8210454: jar tool does not allow setting the module version without also setting the main class
lancea
parents:
51687
diff
changeset
|
52 |
* @bug 8167328 8171830 8165640 8174248 8176772 8196748 8191533 8210454 |
51687
1e39953aaed8
8182404: remove jdk.testlibrary.JDKToolFinder and JDKToolLauncher
iignatyev
parents:
50130
diff
changeset
|
53 |
* @library /test/lib |
38468
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
54 |
* @modules jdk.compiler |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
55 |
* jdk.jartool |
45467
99c87a16a8e4
8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests
iignatyev
parents:
45286
diff
changeset
|
56 |
* @build jdk.test.lib.Platform |
99c87a16a8e4
8181761: add explicit @build actions for jdk.test.lib classes in all :tier2 tests
iignatyev
parents:
45286
diff
changeset
|
57 |
* jdk.test.lib.util.FileUtils |
51687
1e39953aaed8
8182404: remove jdk.testlibrary.JDKToolFinder and JDKToolLauncher
iignatyev
parents:
50130
diff
changeset
|
58 |
* jdk.test.lib.JDKToolFinder |
36511 | 59 |
* @compile Basic.java |
60 |
* @run testng Basic |
|
38468
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
61 |
* @summary Tests for plain Modular jars & Multi-Release Modular jars |
36511 | 62 |
*/ |
63 |
||
64 |
public class Basic { |
|
54413
30067047ed88
8216539: tools/jar/modularJar/Basic.java times out
lancea
parents:
52723
diff
changeset
|
65 |
|
30067047ed88
8216539: tools/jar/modularJar/Basic.java times out
lancea
parents:
52723
diff
changeset
|
66 |
private static final ToolProvider JAR_TOOL = ToolProvider.findFirst("jar") |
30067047ed88
8216539: tools/jar/modularJar/Basic.java times out
lancea
parents:
52723
diff
changeset
|
67 |
.orElseThrow(() |
30067047ed88
8216539: tools/jar/modularJar/Basic.java times out
lancea
parents:
52723
diff
changeset
|
68 |
-> new RuntimeException("jar tool not found") |
30067047ed88
8216539: tools/jar/modularJar/Basic.java times out
lancea
parents:
52723
diff
changeset
|
69 |
); |
30067047ed88
8216539: tools/jar/modularJar/Basic.java times out
lancea
parents:
52723
diff
changeset
|
70 |
private static final ToolProvider JAVAC_TOOL = ToolProvider.findFirst("javac") |
30067047ed88
8216539: tools/jar/modularJar/Basic.java times out
lancea
parents:
52723
diff
changeset
|
71 |
.orElseThrow(() |
30067047ed88
8216539: tools/jar/modularJar/Basic.java times out
lancea
parents:
52723
diff
changeset
|
72 |
-> new RuntimeException("javac tool not found") |
30067047ed88
8216539: tools/jar/modularJar/Basic.java times out
lancea
parents:
52723
diff
changeset
|
73 |
); |
30067047ed88
8216539: tools/jar/modularJar/Basic.java times out
lancea
parents:
52723
diff
changeset
|
74 |
|
36511 | 75 |
static final Path TEST_SRC = Paths.get(System.getProperty("test.src", ".")); |
76 |
static final Path TEST_CLASSES = Paths.get(System.getProperty("test.classes", ".")); |
|
77 |
static final Path MODULE_CLASSES = TEST_CLASSES.resolve("build"); |
|
38468
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
78 |
static final Path MRJAR_DIR = MODULE_CLASSES.resolve("mrjar"); |
36511 | 79 |
|
38762
2956ccc7cb77
8157850: Jar tests should pass through VM options
anazarov
parents:
38468
diff
changeset
|
80 |
static final String VM_OPTIONS = System.getProperty("test.vm.opts", ""); |
2956ccc7cb77
8157850: Jar tests should pass through VM options
anazarov
parents:
38468
diff
changeset
|
81 |
static final String TOOL_VM_OPTIONS = System.getProperty("test.tool.vm.opts", ""); |
2956ccc7cb77
8157850: Jar tests should pass through VM options
anazarov
parents:
38468
diff
changeset
|
82 |
static final String JAVA_OPTIONS = System.getProperty("test.java.opts", ""); |
2956ccc7cb77
8157850: Jar tests should pass through VM options
anazarov
parents:
38468
diff
changeset
|
83 |
|
36511 | 84 |
// Details based on the checked in module source |
85 |
static TestModuleData FOO = new TestModuleData("foo", |
|
86 |
"1.123", |
|
87 |
"jdk.test.foo.Foo", |
|
38468
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
88 |
"Hello World!!!", |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
89 |
null, // no hashes |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
90 |
Set.of("java.base"), |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
91 |
Set.of("jdk.test.foo"), |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
92 |
null, // no uses |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
93 |
null, // no provides |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
94 |
Set.of("jdk.test.foo.internal", |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
95 |
"jdk.test.foo.resources")); |
36511 | 96 |
static TestModuleData BAR = new TestModuleData("bar", |
97 |
"4.5.6.7", |
|
98 |
"jdk.test.bar.Bar", |
|
38468
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
99 |
"Hello from Bar!", |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
100 |
null, // no hashes |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
101 |
Set.of("java.base", "foo"), |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
102 |
null, // no exports |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
103 |
null, // no uses |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
104 |
null, // no provides |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
105 |
Set.of("jdk.test.bar", |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
106 |
"jdk.test.bar.internal")); |
36511 | 107 |
|
108 |
static class TestModuleData { |
|
109 |
final String moduleName; |
|
38468
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
110 |
final Set<String> requires; |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
111 |
final Set<String> exports; |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
112 |
final Set<String> uses; |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
113 |
final Set<String> provides; |
36511 | 114 |
final String mainClass; |
115 |
final String version; |
|
116 |
final String message; |
|
117 |
final String hashes; |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
118 |
final Set<String> packages; |
38468
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
119 |
|
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
120 |
TestModuleData(String mn, String v, String mc, String m, String h, |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
121 |
Set<String> requires, Set<String> exports, Set<String> uses, |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
122 |
Set<String> provides, Set<String> contains) { |
36511 | 123 |
moduleName = mn; mainClass = mc; version = v; message = m; hashes = h; |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
124 |
this.requires = requires != null ? requires : Collections.emptySet(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
125 |
this.exports = exports != null ? exports : Collections.emptySet(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
126 |
this.uses = uses != null ? uses : Collections.emptySet();; |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
127 |
this.provides = provides != null ? provides : Collections.emptySet(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
128 |
this.packages = Stream.concat(this.exports.stream(), contains.stream()) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
129 |
.collect(Collectors.toSet()); |
36511 | 130 |
} |
131 |
static TestModuleData from(String s) { |
|
132 |
try { |
|
133 |
BufferedReader reader = new BufferedReader(new StringReader(s)); |
|
134 |
String line; |
|
135 |
String message = null; |
|
136 |
String name = null, version = null, mainClass = null; |
|
137 |
String hashes = null; |
|
38468
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
138 |
Set<String> requires, exports, uses, provides, conceals; |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
139 |
requires = exports = uses = provides = conceals = null; |
36511 | 140 |
while ((line = reader.readLine()) != null) { |
141 |
if (line.startsWith("message:")) { |
|
142 |
message = line.substring("message:".length()); |
|
143 |
} else if (line.startsWith("nameAndVersion:")) { |
|
144 |
line = line.substring("nameAndVersion:".length()); |
|
145 |
int i = line.indexOf('@'); |
|
146 |
if (i != -1) { |
|
147 |
name = line.substring(0, i); |
|
148 |
version = line.substring(i + 1, line.length()); |
|
149 |
} else { |
|
150 |
name = line; |
|
151 |
} |
|
152 |
} else if (line.startsWith("mainClass:")) { |
|
153 |
mainClass = line.substring("mainClass:".length()); |
|
38468
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
154 |
} else if (line.startsWith("requires:")) { |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
155 |
line = line.substring("requires:".length()); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
156 |
requires = stringToSet(line); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
157 |
} else if (line.startsWith("exports:")) { |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
158 |
line = line.substring("exports:".length()); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
159 |
exports = stringToSet(line); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
160 |
} else if (line.startsWith("uses:")) { |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
161 |
line = line.substring("uses:".length()); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
162 |
uses = stringToSet(line); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
163 |
} else if (line.startsWith("provides:")) { |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
164 |
line = line.substring("provides:".length()); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
165 |
provides = stringToSet(line); |
36511 | 166 |
} else if (line.startsWith("hashes:")) { |
167 |
hashes = line.substring("hashes:".length()); |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
168 |
} else if (line.startsWith("contains:")) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
169 |
line = line.substring("contains:".length()); |
38468
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
170 |
conceals = stringToSet(line); |
49212
48452579de86
8196748: tools/jar tests need to tolerate unrelated warnings
sherman
parents:
47216
diff
changeset
|
171 |
} else if (line.contains("VM warning:")) { |
48452579de86
8196748: tools/jar tests need to tolerate unrelated warnings
sherman
parents:
47216
diff
changeset
|
172 |
continue; // ignore server vm warning see#8196748 |
36511 | 173 |
} else { |
174 |
throw new AssertionError("Unknown value " + line); |
|
175 |
} |
|
176 |
} |
|
177 |
||
38468
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
178 |
return new TestModuleData(name, version, mainClass, message, |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
179 |
hashes, requires, exports, uses, |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
180 |
provides, conceals); |
36511 | 181 |
} catch (IOException x) { |
182 |
throw new UncheckedIOException(x); |
|
183 |
} |
|
184 |
} |
|
38468
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
185 |
static Set<String> stringToSet(String commaList) { |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
186 |
Set<String> s = new HashSet<>(); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
187 |
int i = commaList.indexOf(','); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
188 |
if (i != -1) { |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
189 |
String[] p = commaList.split(","); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
190 |
Stream.of(p).forEach(s::add); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
191 |
} else { |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
192 |
s.add(commaList); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
193 |
} |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
194 |
return s; |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
195 |
} |
36511 | 196 |
} |
197 |
||
198 |
static void assertModuleData(Result r, TestModuleData expected) { |
|
199 |
//out.printf("%s%n", r.output); |
|
200 |
TestModuleData received = TestModuleData.from(r.output); |
|
201 |
if (expected.message != null) |
|
202 |
assertTrue(expected.message.equals(received.message), |
|
203 |
"Expected message:", expected.message, ", got:", received.message); |
|
204 |
assertTrue(expected.moduleName.equals(received.moduleName), |
|
205 |
"Expected moduleName: ", expected.moduleName, ", got:", received.moduleName); |
|
206 |
assertTrue(expected.version.equals(received.version), |
|
207 |
"Expected version: ", expected.version, ", got:", received.version); |
|
208 |
assertTrue(expected.mainClass.equals(received.mainClass), |
|
209 |
"Expected mainClass: ", expected.mainClass, ", got:", received.mainClass); |
|
38468
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
210 |
assertSetsEqual(expected.requires, received.requires); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
211 |
assertSetsEqual(expected.exports, received.exports); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
212 |
assertSetsEqual(expected.uses, received.uses); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
213 |
assertSetsEqual(expected.provides, received.provides); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
214 |
assertSetsEqual(expected.packages, received.packages); |
38468
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
215 |
} |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
216 |
|
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
217 |
static void assertSetsEqual(Set<String> s1, Set<String> s2) { |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
218 |
if (!s1.equals(s2)) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
219 |
org.testng.Assert.assertTrue(false, s1 + " vs " + s2); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
220 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
221 |
} |
36511 | 222 |
|
223 |
@BeforeTest |
|
224 |
public void compileModules() throws Exception { |
|
225 |
compileModule(FOO.moduleName); |
|
226 |
compileModule(BAR.moduleName, MODULE_CLASSES); |
|
227 |
compileModule("baz"); // for service provider consistency checking |
|
38468
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
228 |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
229 |
// copy resources |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
230 |
copyResource(TEST_SRC.resolve("src").resolve(FOO.moduleName), |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
231 |
MODULE_CLASSES.resolve(FOO.moduleName), |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
232 |
"jdk/test/foo/resources/foo.properties"); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
233 |
|
38468
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
234 |
setupMRJARModuleInfo(FOO.moduleName); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
235 |
setupMRJARModuleInfo(BAR.moduleName); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
236 |
setupMRJARModuleInfo("baz"); |
36511 | 237 |
} |
238 |
||
239 |
@Test |
|
240 |
public void createFoo() throws IOException { |
|
241 |
Path mp = Paths.get("createFoo"); |
|
242 |
createTestDir(mp); |
|
243 |
Path modClasses = MODULE_CLASSES.resolve(FOO.moduleName); |
|
244 |
Path modularJar = mp.resolve(FOO.moduleName + ".jar"); |
|
245 |
||
246 |
jar("--create", |
|
247 |
"--file=" + modularJar.toString(), |
|
248 |
"--main-class=" + FOO.mainClass, |
|
249 |
"--module-version=" + FOO.version, |
|
250 |
"--no-manifest", |
|
251 |
"-C", modClasses.toString(), ".") |
|
252 |
.assertSuccess(); |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
253 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
254 |
assertSetsEqual(readPackagesAttribute(modularJar), |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
255 |
Set.of("jdk.test.foo", |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
256 |
"jdk.test.foo.resources", |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
257 |
"jdk.test.foo.internal")); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
258 |
|
36511 | 259 |
java(mp, FOO.moduleName + "/" + FOO.mainClass) |
260 |
.assertSuccess() |
|
261 |
.resultChecker(r -> assertModuleData(r, FOO)); |
|
262 |
try (InputStream fis = Files.newInputStream(modularJar); |
|
263 |
JarInputStream jis = new JarInputStream(fis)) { |
|
264 |
assertTrue(!jarContains(jis, "./"), |
|
265 |
"Unexpected ./ found in ", modularJar.toString()); |
|
266 |
} |
|
267 |
} |
|
268 |
||
38468
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
269 |
/** Similar to createFoo, but with a Multi-Release Modular jar. */ |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
270 |
@Test |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
271 |
public void createMRMJarFoo() throws IOException { |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
272 |
Path mp = Paths.get("createMRMJarFoo"); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
273 |
createTestDir(mp); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
274 |
Path modClasses = MODULE_CLASSES.resolve(FOO.moduleName); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
275 |
Path mrjarDir = MRJAR_DIR.resolve(FOO.moduleName); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
276 |
Path modularJar = mp.resolve(FOO.moduleName + ".jar"); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
277 |
|
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
278 |
// Positive test, create |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
279 |
jar("--create", |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
280 |
"--file=" + modularJar.toString(), |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
281 |
"--main-class=" + FOO.mainClass, |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
282 |
"--module-version=" + FOO.version, |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
283 |
"-m", mrjarDir.resolve("META-INF/MANIFEST.MF").toRealPath().toString(), |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
284 |
"-C", mrjarDir.toString(), "META-INF/versions/9/module-info.class", |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
285 |
"-C", modClasses.toString(), ".") |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
286 |
.assertSuccess(); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
287 |
java(mp, FOO.moduleName + "/" + FOO.mainClass) |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
288 |
.assertSuccess() |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
289 |
.resultChecker(r -> assertModuleData(r, FOO)); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
290 |
} |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
291 |
|
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
292 |
|
36511 | 293 |
@Test |
294 |
public void updateFoo() throws IOException { |
|
295 |
Path mp = Paths.get("updateFoo"); |
|
296 |
createTestDir(mp); |
|
297 |
Path modClasses = MODULE_CLASSES.resolve(FOO.moduleName); |
|
298 |
Path modularJar = mp.resolve(FOO.moduleName + ".jar"); |
|
299 |
||
300 |
jar("--create", |
|
301 |
"--file=" + modularJar.toString(), |
|
302 |
"--no-manifest", |
|
303 |
"-C", modClasses.toString(), "jdk") |
|
304 |
.assertSuccess(); |
|
305 |
jar("--update", |
|
306 |
"--file=" + modularJar.toString(), |
|
307 |
"--main-class=" + FOO.mainClass, |
|
308 |
"--module-version=" + FOO.version, |
|
309 |
"--no-manifest", |
|
310 |
"-C", modClasses.toString(), "module-info.class") |
|
311 |
.assertSuccess(); |
|
312 |
java(mp, FOO.moduleName + "/" + FOO.mainClass) |
|
313 |
.assertSuccess() |
|
314 |
.resultChecker(r -> assertModuleData(r, FOO)); |
|
315 |
} |
|
316 |
||
317 |
@Test |
|
38468
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
318 |
public void updateMRMJarFoo() throws IOException { |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
319 |
Path mp = Paths.get("updateMRMJarFoo"); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
320 |
createTestDir(mp); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
321 |
Path modClasses = MODULE_CLASSES.resolve(FOO.moduleName); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
322 |
Path mrjarDir = MRJAR_DIR.resolve(FOO.moduleName); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
323 |
Path modularJar = mp.resolve(FOO.moduleName + ".jar"); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
324 |
|
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
325 |
jar("--create", |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
326 |
"--file=" + modularJar.toString(), |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
327 |
"--no-manifest", |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
328 |
"-C", modClasses.toString(), "jdk") |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
329 |
.assertSuccess(); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
330 |
jar("--update", |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
331 |
"--file=" + modularJar.toString(), |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
332 |
"--main-class=" + FOO.mainClass, |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
333 |
"--module-version=" + FOO.version, |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
334 |
"-m", mrjarDir.resolve("META-INF/MANIFEST.MF").toRealPath().toString(), |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
335 |
"-C", mrjarDir.toString(), "META-INF/versions/9/module-info.class", |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
336 |
"-C", modClasses.toString(), "module-info.class") |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
337 |
.assertSuccess(); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
338 |
java(mp, FOO.moduleName + "/" + FOO.mainClass) |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
339 |
.assertSuccess() |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
340 |
.resultChecker(r -> assertModuleData(r, FOO)); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
341 |
} |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
342 |
|
43797
dab6fb7f37a3
8174248: partialUpdateFooMainClass test in tools/jar/modularJar/Basic.java needs to be re-examined
sherman
parents:
43731
diff
changeset
|
343 |
@Test |
36511 | 344 |
public void partialUpdateFooMainClass() throws IOException { |
345 |
Path mp = Paths.get("partialUpdateFooMainClass"); |
|
346 |
createTestDir(mp); |
|
347 |
Path modClasses = MODULE_CLASSES.resolve(FOO.moduleName); |
|
348 |
Path modularJar = mp.resolve(FOO.moduleName + ".jar"); |
|
349 |
||
350 |
// A "bad" main class in first create ( and no version ) |
|
351 |
jar("--create", |
|
352 |
"--file=" + modularJar.toString(), |
|
43797
dab6fb7f37a3
8174248: partialUpdateFooMainClass test in tools/jar/modularJar/Basic.java needs to be re-examined
sherman
parents:
43731
diff
changeset
|
353 |
"--main-class=" + "jdk.test.foo.IAmNotTheEntryPoint", |
36511 | 354 |
"--no-manifest", |
355 |
"-C", modClasses.toString(), ".") // includes module-info.class |
|
356 |
.assertSuccess(); |
|
357 |
jar("--update", |
|
358 |
"--file=" + modularJar.toString(), |
|
359 |
"--main-class=" + FOO.mainClass, |
|
360 |
"--module-version=" + FOO.version, |
|
361 |
"--no-manifest") |
|
362 |
.assertSuccess(); |
|
363 |
java(mp, FOO.moduleName + "/" + FOO.mainClass) |
|
364 |
.assertSuccess() |
|
365 |
.resultChecker(r -> assertModuleData(r, FOO)); |
|
366 |
} |
|
367 |
||
368 |
@Test |
|
369 |
public void partialUpdateFooVersion() throws IOException { |
|
370 |
Path mp = Paths.get("partialUpdateFooVersion"); |
|
371 |
createTestDir(mp); |
|
372 |
Path modClasses = MODULE_CLASSES.resolve(FOO.moduleName); |
|
373 |
Path modularJar = mp.resolve(FOO.moduleName + ".jar"); |
|
374 |
||
375 |
// A "bad" version in first create ( and no main class ) |
|
376 |
jar("--create", |
|
377 |
"--file=" + modularJar.toString(), |
|
378 |
"--module-version=" + "100000000", |
|
379 |
"--no-manifest", |
|
380 |
"-C", modClasses.toString(), ".") // includes module-info.class |
|
381 |
.assertSuccess(); |
|
382 |
jar("--update", |
|
383 |
"--file=" + modularJar.toString(), |
|
384 |
"--main-class=" + FOO.mainClass, |
|
385 |
"--module-version=" + FOO.version, |
|
386 |
"--no-manifest") |
|
387 |
.assertSuccess(); |
|
388 |
java(mp, FOO.moduleName + "/" + FOO.mainClass) |
|
389 |
.assertSuccess() |
|
390 |
.resultChecker(r -> assertModuleData(r, FOO)); |
|
391 |
} |
|
392 |
||
393 |
@Test |
|
394 |
public void partialUpdateFooNotAllFiles() throws IOException { |
|
395 |
Path mp = Paths.get("partialUpdateFooNotAllFiles"); |
|
396 |
createTestDir(mp); |
|
397 |
Path modClasses = MODULE_CLASSES.resolve(FOO.moduleName); |
|
398 |
Path modularJar = mp.resolve(FOO.moduleName + ".jar"); |
|
399 |
||
400 |
// Not all files, and none from non-exported packages, |
|
401 |
// i.e. no concealed list in first create |
|
402 |
jar("--create", |
|
403 |
"--file=" + modularJar.toString(), |
|
404 |
"--no-manifest", |
|
405 |
"-C", modClasses.toString(), "module-info.class", |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
406 |
"-C", modClasses.toString(), "jdk/test/foo/Foo.class", |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
407 |
"-C", modClasses.toString(), "jdk/test/foo/resources/foo.properties") |
36511 | 408 |
.assertSuccess(); |
409 |
jar("--update", |
|
410 |
"--file=" + modularJar.toString(), |
|
411 |
"--main-class=" + FOO.mainClass, |
|
412 |
"--module-version=" + FOO.version, |
|
413 |
"--no-manifest", |
|
414 |
"-C", modClasses.toString(), "jdk/test/foo/internal/Message.class") |
|
415 |
.assertSuccess(); |
|
416 |
java(mp, FOO.moduleName + "/" + FOO.mainClass) |
|
417 |
.assertSuccess() |
|
418 |
.resultChecker(r -> assertModuleData(r, FOO)); |
|
419 |
} |
|
420 |
||
421 |
@Test |
|
38468
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
422 |
public void partialUpdateMRMJarFooNotAllFiles() throws IOException { |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
423 |
Path mp = Paths.get("partialUpdateMRMJarFooNotAllFiles"); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
424 |
createTestDir(mp); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
425 |
Path modClasses = MODULE_CLASSES.resolve(FOO.moduleName); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
426 |
Path mrjarDir = MRJAR_DIR.resolve(FOO.moduleName); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
427 |
Path modularJar = mp.resolve(FOO.moduleName + ".jar"); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
428 |
|
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
429 |
jar("--create", |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
430 |
"--file=" + modularJar.toString(), |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
431 |
"--module-version=" + FOO.version, |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
432 |
"-C", modClasses.toString(), ".") |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
433 |
.assertSuccess(); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
434 |
jar("--update", |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
435 |
"--file=" + modularJar.toString(), |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
436 |
"--main-class=" + FOO.mainClass, |
43095
336dfda4ae89
8172432: jar cleanup/update for module and mrm jar
sherman
parents:
42345
diff
changeset
|
437 |
"--module-version=" + FOO.version, |
38468
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
438 |
"-m", mrjarDir.resolve("META-INF/MANIFEST.MF").toRealPath().toString(), |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
439 |
"-C", mrjarDir.toString(), "META-INF/versions/9/module-info.class") |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
440 |
.assertSuccess(); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
441 |
java(mp, FOO.moduleName + "/" + FOO.mainClass) |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
442 |
.assertSuccess() |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
443 |
.resultChecker(r -> assertModuleData(r, FOO)); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
444 |
} |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
445 |
|
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
446 |
@Test |
36511 | 447 |
public void partialUpdateFooAllFilesAndAttributes() throws IOException { |
448 |
Path mp = Paths.get("partialUpdateFooAllFilesAndAttributes"); |
|
449 |
createTestDir(mp); |
|
450 |
Path modClasses = MODULE_CLASSES.resolve(FOO.moduleName); |
|
451 |
Path modularJar = mp.resolve(FOO.moduleName + ".jar"); |
|
452 |
||
453 |
// all attributes and files |
|
454 |
jar("--create", |
|
455 |
"--file=" + modularJar.toString(), |
|
456 |
"--main-class=" + FOO.mainClass, |
|
457 |
"--module-version=" + FOO.version, |
|
458 |
"--no-manifest", |
|
459 |
"-C", modClasses.toString(), ".") |
|
460 |
.assertSuccess(); |
|
461 |
jar("--update", |
|
462 |
"--file=" + modularJar.toString(), |
|
463 |
"--main-class=" + FOO.mainClass, |
|
464 |
"--module-version=" + FOO.version, |
|
465 |
"--no-manifest", |
|
466 |
"-C", modClasses.toString(), ".") |
|
467 |
.assertSuccess(); |
|
468 |
java(mp, FOO.moduleName + "/" + FOO.mainClass) |
|
469 |
.assertSuccess() |
|
470 |
.resultChecker(r -> assertModuleData(r, FOO)); |
|
471 |
} |
|
472 |
||
473 |
@Test |
|
474 |
public void partialUpdateFooModuleInfo() throws IOException { |
|
475 |
Path mp = Paths.get("partialUpdateFooModuleInfo"); |
|
476 |
createTestDir(mp); |
|
477 |
Path modClasses = MODULE_CLASSES.resolve(FOO.moduleName); |
|
478 |
Path modularJar = mp.resolve(FOO.moduleName + ".jar"); |
|
479 |
Path barModInfo = MODULE_CLASSES.resolve(BAR.moduleName); |
|
480 |
||
481 |
jar("--create", |
|
482 |
"--file=" + modularJar.toString(), |
|
483 |
"--main-class=" + FOO.mainClass, |
|
484 |
"--module-version=" + FOO.version, |
|
485 |
"--no-manifest", |
|
486 |
"-C", modClasses.toString(), ".") |
|
487 |
.assertSuccess(); |
|
488 |
jar("--update", |
|
489 |
"--file=" + modularJar.toString(), |
|
490 |
"--no-manifest", |
|
491 |
"-C", barModInfo.toString(), "module-info.class") // stuff in bar's info |
|
492 |
.assertSuccess(); |
|
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38762
diff
changeset
|
493 |
jar("-d", |
36511 | 494 |
"--file=" + modularJar.toString()) |
495 |
.assertSuccess() |
|
496 |
.resultChecker(r -> { |
|
45004
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
497 |
// Expect "bar jar:file:/.../!module-info.class" |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
498 |
// conceals jdk.test.foo, conceals jdk.test.foo.internal" |
45004
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
499 |
String uri = "jar:" + modularJar.toUri().toString() + "/!module-info.class"; |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
500 |
assertTrue(r.output.contains("bar " + uri), |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
501 |
"Expecting to find \"bar " + uri + "\"", |
36511 | 502 |
"in output, but did not: [" + r.output + "]"); |
45004
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
503 |
Pattern p = Pattern.compile( |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
504 |
"contains\\s+jdk.test.foo\\s+contains\\s+jdk.test.foo.internal"); |
36511 | 505 |
assertTrue(p.matcher(r.output).find(), |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
506 |
"Expecting to find \"contains jdk.test.foo,...\"", |
36511 | 507 |
"in output, but did not: [" + r.output + "]"); |
508 |
}); |
|
509 |
} |
|
510 |
||
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
511 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
512 |
@Test |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
513 |
public void partialUpdateFooPackagesAttribute() throws IOException { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
514 |
Path mp = Paths.get("partialUpdateFooPackagesAttribute"); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
515 |
createTestDir(mp); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
516 |
Path modClasses = MODULE_CLASSES.resolve(FOO.moduleName); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
517 |
Path modularJar = mp.resolve(FOO.moduleName + ".jar"); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
518 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
519 |
// Not all files, and none from non-exported packages, |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
520 |
// i.e. no concealed list in first create |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
521 |
jar("--create", |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
522 |
"--file=" + modularJar.toString(), |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
523 |
"--no-manifest", |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
524 |
"-C", modClasses.toString(), "module-info.class", |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
525 |
"-C", modClasses.toString(), "jdk/test/foo/Foo.class") |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
526 |
.assertSuccess(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
527 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
528 |
assertSetsEqual(readPackagesAttribute(modularJar), |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
529 |
Set.of("jdk.test.foo")); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
530 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
531 |
jar("--update", |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
532 |
"--file=" + modularJar.toString(), |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
533 |
"-C", modClasses.toString(), "jdk/test/foo/resources/foo.properties") |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
534 |
.assertSuccess(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
535 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
536 |
assertSetsEqual(readPackagesAttribute(modularJar), |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
537 |
Set.of("jdk.test.foo", "jdk.test.foo.resources")); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
538 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
539 |
jar("--update", |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
540 |
"--file=" + modularJar.toString(), |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
541 |
"--main-class=" + FOO.mainClass, |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
542 |
"--module-version=" + FOO.version, |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
543 |
"--no-manifest", |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
544 |
"-C", modClasses.toString(), "jdk/test/foo/internal/Message.class") |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
545 |
.assertSuccess(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
546 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
547 |
assertSetsEqual(readPackagesAttribute(modularJar), |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
548 |
Set.of("jdk.test.foo", |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
549 |
"jdk.test.foo.resources", |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
550 |
"jdk.test.foo.internal")); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
551 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
552 |
java(mp, FOO.moduleName + "/" + FOO.mainClass) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
553 |
.assertSuccess() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
554 |
.resultChecker(r -> assertModuleData(r, FOO)); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
555 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
556 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
557 |
private Set<String> readPackagesAttribute(Path jar) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
558 |
return getModuleDescriptor(jar).packages(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
559 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
560 |
|
36511 | 561 |
@Test |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
562 |
public void hashBarInFooModule() throws IOException { |
36511 | 563 |
Path mp = Paths.get("dependencesFooBar"); |
564 |
createTestDir(mp); |
|
565 |
||
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
566 |
Path modClasses = MODULE_CLASSES.resolve(BAR.moduleName); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
567 |
Path modularJar = mp.resolve(BAR.moduleName + ".jar"); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
568 |
jar("--create", |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
569 |
"--file=" + modularJar.toString(), |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
570 |
"--main-class=" + BAR.mainClass, |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
571 |
"--module-version=" + BAR.version, |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
572 |
"--no-manifest", |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
573 |
"-C", modClasses.toString(), ".") |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
574 |
.assertSuccess(); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
575 |
|
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
576 |
modClasses = MODULE_CLASSES.resolve(FOO.moduleName); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
577 |
modularJar = mp.resolve(FOO.moduleName + ".jar"); |
36511 | 578 |
jar("--create", |
579 |
"--file=" + modularJar.toString(), |
|
580 |
"--main-class=" + FOO.mainClass, |
|
581 |
"--module-version=" + FOO.version, |
|
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38762
diff
changeset
|
582 |
"--module-path=" + mp.toString(), |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
583 |
"--hash-modules=" + "bar", |
36511 | 584 |
"--no-manifest", |
585 |
"-C", modClasses.toString(), ".") |
|
586 |
.assertSuccess(); |
|
587 |
||
588 |
java(mp, BAR.moduleName + "/" + BAR.mainClass, |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
589 |
"--add-exports", "java.base/jdk.internal.misc=bar", |
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38762
diff
changeset
|
590 |
"--add-exports", "java.base/jdk.internal.module=bar") |
36511 | 591 |
.assertSuccess() |
592 |
.resultChecker(r -> { |
|
593 |
assertModuleData(r, BAR); |
|
594 |
TestModuleData received = TestModuleData.from(r.output); |
|
595 |
assertTrue(received.hashes != null, "Expected non-null hashes value."); |
|
596 |
}); |
|
597 |
} |
|
598 |
||
599 |
@Test |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
600 |
public void invalidHashInFooModule() throws IOException { |
36511 | 601 |
Path mp = Paths.get("badDependencyFooBar"); |
602 |
createTestDir(mp); |
|
603 |
||
604 |
Path barClasses = MODULE_CLASSES.resolve(BAR.moduleName); |
|
605 |
Path barJar = mp.resolve(BAR.moduleName + ".jar"); |
|
606 |
jar("--create", |
|
607 |
"--file=" + barJar.toString(), |
|
608 |
"--main-class=" + BAR.mainClass, |
|
609 |
"--module-version=" + BAR.version, |
|
610 |
"--no-manifest", |
|
611 |
"-C", barClasses.toString(), ".").assertSuccess(); |
|
612 |
||
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
613 |
Path fooClasses = MODULE_CLASSES.resolve(FOO.moduleName); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
614 |
Path fooJar = mp.resolve(FOO.moduleName + ".jar"); |
36511 | 615 |
jar("--create", |
616 |
"--file=" + fooJar.toString(), |
|
617 |
"--main-class=" + FOO.mainClass, |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
618 |
"--module-version=" + FOO.version, |
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38762
diff
changeset
|
619 |
"-p", mp.toString(), // test short-form |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
620 |
"--hash-modules=" + "bar", |
36511 | 621 |
"--no-manifest", |
622 |
"-C", fooClasses.toString(), ".").assertSuccess(); |
|
623 |
||
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
624 |
// Rebuild bar.jar with a change that will cause its hash to be different |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
625 |
FileUtils.deleteFileWithRetry(barJar); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
626 |
jar("--create", |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
627 |
"--file=" + barJar.toString(), |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
628 |
"--main-class=" + BAR.mainClass, |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
629 |
"--module-version=" + BAR.version + ".1", // a newer version |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
630 |
"--no-manifest", |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
631 |
"-C", barClasses.toString(), ".").assertSuccess(); |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
632 |
|
36511 | 633 |
java(mp, BAR.moduleName + "/" + BAR.mainClass, |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
634 |
"--add-exports", "java.base/jdk.internal.misc=bar", |
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38762
diff
changeset
|
635 |
"--add-exports", "java.base/jdk.internal.module=bar") |
36511 | 636 |
.assertFailure() |
637 |
.resultChecker(r -> { |
|
638 |
// Expect similar output: "java.lang.module.ResolutionException: Hash |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
639 |
// of bar (WdktSIQSkd4+CEacpOZoeDrCosMATNrIuNub9b5yBeo=) differs to |
36511 | 640 |
// expected hash (iepvdv8xTeVrFgMtUhcFnmetSub6qQHCHc92lSaSEg0=)" |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
641 |
Pattern p = Pattern.compile(".*Hash of bar.*differs to expected hash.*"); |
36511 | 642 |
assertTrue(p.matcher(r.output).find(), |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
643 |
"Expecting error message containing \"Hash of bar ... differs to" |
36511 | 644 |
+ " expected hash...\" but got: [", r.output + "]"); |
645 |
}); |
|
646 |
} |
|
647 |
||
648 |
@Test |
|
649 |
public void badOptionsFoo() throws IOException { |
|
650 |
Path mp = Paths.get("badOptionsFoo"); |
|
651 |
createTestDir(mp); |
|
652 |
Path modClasses = MODULE_CLASSES.resolve(FOO.moduleName); |
|
653 |
Path modularJar = mp.resolve(FOO.moduleName + ".jar"); |
|
654 |
||
655 |
jar("--create", |
|
656 |
"--file=" + modularJar.toString(), |
|
657 |
"--module-version=" + 1.1, // no module-info.class |
|
658 |
"-C", modClasses.toString(), "jdk") |
|
659 |
.assertFailure(); // TODO: expected failure message |
|
660 |
||
661 |
jar("--create", |
|
662 |
"--file=" + modularJar.toString(), |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
663 |
"--hash-modules=" + ".*", // no module-info.class |
36511 | 664 |
"-C", modClasses.toString(), "jdk") |
665 |
.assertFailure(); // TODO: expected failure message |
|
666 |
} |
|
667 |
||
668 |
@Test |
|
669 |
public void servicesCreateWithoutFailure() throws IOException { |
|
670 |
Path mp = Paths.get("servicesCreateWithoutFailure"); |
|
671 |
createTestDir(mp); |
|
672 |
Path modClasses = MODULE_CLASSES.resolve("baz"); |
|
673 |
Path modularJar = mp.resolve("baz" + ".jar"); |
|
674 |
||
675 |
// Positive test, create |
|
676 |
jar("--create", |
|
677 |
"--file=" + modularJar.toString(), |
|
678 |
"-C", modClasses.toString(), "module-info.class", |
|
679 |
"-C", modClasses.toString(), "jdk/test/baz/BazService.class", |
|
680 |
"-C", modClasses.toString(), "jdk/test/baz/internal/BazServiceImpl.class") |
|
681 |
.assertSuccess(); |
|
50130
aefd3c7f5373
8191533: jar --describe-module prints service provider class names in lower case
sherman
parents:
49212
diff
changeset
|
682 |
|
aefd3c7f5373
8191533: jar --describe-module prints service provider class names in lower case
sherman
parents:
49212
diff
changeset
|
683 |
for (String option : new String[] {"--describe-module", "-d" }) { |
aefd3c7f5373
8191533: jar --describe-module prints service provider class names in lower case
sherman
parents:
49212
diff
changeset
|
684 |
jar(option, |
aefd3c7f5373
8191533: jar --describe-module prints service provider class names in lower case
sherman
parents:
49212
diff
changeset
|
685 |
"--file=" + modularJar.toString()) |
aefd3c7f5373
8191533: jar --describe-module prints service provider class names in lower case
sherman
parents:
49212
diff
changeset
|
686 |
.assertSuccess() |
aefd3c7f5373
8191533: jar --describe-module prints service provider class names in lower case
sherman
parents:
49212
diff
changeset
|
687 |
.resultChecker(r -> |
aefd3c7f5373
8191533: jar --describe-module prints service provider class names in lower case
sherman
parents:
49212
diff
changeset
|
688 |
assertTrue(r.output.contains("provides jdk.test.baz.BazService with jdk.test.baz.internal.BazServiceImpl"), |
aefd3c7f5373
8191533: jar --describe-module prints service provider class names in lower case
sherman
parents:
49212
diff
changeset
|
689 |
"Expected to find ", "provides jdk.test.baz.BazService with jdk.test.baz.internal.BazServiceImpl", |
aefd3c7f5373
8191533: jar --describe-module prints service provider class names in lower case
sherman
parents:
49212
diff
changeset
|
690 |
" in [", r.output, "]") |
aefd3c7f5373
8191533: jar --describe-module prints service provider class names in lower case
sherman
parents:
49212
diff
changeset
|
691 |
); |
aefd3c7f5373
8191533: jar --describe-module prints service provider class names in lower case
sherman
parents:
49212
diff
changeset
|
692 |
} |
36511 | 693 |
} |
694 |
||
695 |
@Test |
|
696 |
public void servicesCreateWithoutServiceImpl() throws IOException { |
|
697 |
Path mp = Paths.get("servicesWithoutServiceImpl"); |
|
698 |
createTestDir(mp); |
|
699 |
Path modClasses = MODULE_CLASSES.resolve("baz"); |
|
700 |
Path modularJar = mp.resolve("baz" + ".jar"); |
|
701 |
||
702 |
// Omit service impl |
|
703 |
jar("--create", |
|
704 |
"--file=" + modularJar.toString(), |
|
705 |
"-C", modClasses.toString(), "module-info.class", |
|
706 |
"-C", modClasses.toString(), "jdk/test/baz/BazService.class") |
|
707 |
.assertFailure(); |
|
708 |
} |
|
709 |
||
710 |
@Test |
|
711 |
public void servicesUpdateWithoutFailure() throws IOException { |
|
712 |
Path mp = Paths.get("servicesUpdateWithoutFailure"); |
|
713 |
createTestDir(mp); |
|
714 |
Path modClasses = MODULE_CLASSES.resolve("baz"); |
|
715 |
Path modularJar = mp.resolve("baz" + ".jar"); |
|
716 |
||
717 |
// Positive test, update |
|
718 |
jar("--create", |
|
719 |
"--file=" + modularJar.toString(), |
|
720 |
"-C", modClasses.toString(), "jdk/test/baz/BazService.class", |
|
721 |
"-C", modClasses.toString(), "jdk/test/baz/internal/BazServiceImpl.class") |
|
722 |
.assertSuccess(); |
|
723 |
jar("--update", |
|
724 |
"--file=" + modularJar.toString(), |
|
725 |
"-C", modClasses.toString(), "module-info.class") |
|
726 |
.assertSuccess(); |
|
727 |
} |
|
728 |
||
729 |
@Test |
|
730 |
public void servicesUpdateWithoutServiceImpl() throws IOException { |
|
731 |
Path mp = Paths.get("servicesUpdateWithoutServiceImpl"); |
|
732 |
createTestDir(mp); |
|
733 |
Path modClasses = MODULE_CLASSES.resolve("baz"); |
|
734 |
Path modularJar = mp.resolve("baz" + ".jar"); |
|
735 |
||
736 |
// Omit service impl |
|
737 |
jar("--create", |
|
738 |
"--file=" + modularJar.toString(), |
|
739 |
"-C", modClasses.toString(), "jdk/test/baz/BazService.class") |
|
740 |
.assertSuccess(); |
|
741 |
jar("--update", |
|
742 |
"--file=" + modularJar.toString(), |
|
743 |
"-C", modClasses.toString(), "module-info.class") |
|
744 |
.assertFailure(); |
|
745 |
} |
|
746 |
||
747 |
@Test |
|
38468
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
748 |
public void servicesCreateWithoutFailureMRMJAR() throws IOException { |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
749 |
Path mp = Paths.get("servicesCreateWithoutFailureMRMJAR"); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
750 |
createTestDir(mp); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
751 |
Path modClasses = MODULE_CLASSES.resolve("baz"); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
752 |
Path mrjarDir = MRJAR_DIR.resolve("baz"); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
753 |
Path modularJar = mp.resolve("baz" + ".jar"); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
754 |
|
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
755 |
jar("--create", |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
756 |
"--file=" + modularJar.toString(), |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
757 |
"-m", mrjarDir.resolve("META-INF/MANIFEST.MF").toRealPath().toString(), |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
758 |
"-C", modClasses.toString(), "module-info.class", |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
759 |
"-C", mrjarDir.toString(), "META-INF/versions/9/module-info.class", |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
760 |
"-C", modClasses.toString(), "jdk/test/baz/BazService.class", |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
761 |
"-C", modClasses.toString(), "jdk/test/baz/internal/BazServiceImpl.class") |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
762 |
.assertSuccess(); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
763 |
} |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
764 |
|
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
765 |
@Test |
43731
bc7110b230c1
8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents:
43712
diff
changeset
|
766 |
public void servicesCreateWithoutFailureNonRootMRMJAR() throws IOException { |
bc7110b230c1
8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents:
43712
diff
changeset
|
767 |
// without a root module-info.class |
bc7110b230c1
8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents:
43712
diff
changeset
|
768 |
Path mp = Paths.get("servicesCreateWithoutFailureNonRootMRMJAR"); |
bc7110b230c1
8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents:
43712
diff
changeset
|
769 |
createTestDir(mp); |
bc7110b230c1
8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents:
43712
diff
changeset
|
770 |
Path modClasses = MODULE_CLASSES.resolve("baz"); |
bc7110b230c1
8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents:
43712
diff
changeset
|
771 |
Path mrjarDir = MRJAR_DIR.resolve("baz"); |
bc7110b230c1
8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents:
43712
diff
changeset
|
772 |
Path modularJar = mp.resolve("baz.jar"); |
bc7110b230c1
8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents:
43712
diff
changeset
|
773 |
|
bc7110b230c1
8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents:
43712
diff
changeset
|
774 |
jar("--create", |
bc7110b230c1
8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents:
43712
diff
changeset
|
775 |
"--file=" + modularJar.toString(), |
bc7110b230c1
8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents:
43712
diff
changeset
|
776 |
"--main-class=" + "jdk.test.baz.Baz", |
bc7110b230c1
8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents:
43712
diff
changeset
|
777 |
"-m", mrjarDir.resolve("META-INF/MANIFEST.MF").toRealPath().toString(), |
bc7110b230c1
8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents:
43712
diff
changeset
|
778 |
"-C", mrjarDir.toString(), "META-INF/versions/9/module-info.class", |
bc7110b230c1
8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents:
43712
diff
changeset
|
779 |
"-C", modClasses.toString(), "jdk/test/baz/BazService.class", |
bc7110b230c1
8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents:
43712
diff
changeset
|
780 |
"-C", modClasses.toString(), "jdk/test/baz/Baz.class", |
bc7110b230c1
8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents:
43712
diff
changeset
|
781 |
"-C", modClasses.toString(), "jdk/test/baz/internal/BazServiceImpl.class") |
bc7110b230c1
8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents:
43712
diff
changeset
|
782 |
.assertSuccess(); |
bc7110b230c1
8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents:
43712
diff
changeset
|
783 |
|
bc7110b230c1
8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents:
43712
diff
changeset
|
784 |
|
44267
00898a596f31
8176772: jar tool support to report automatic module names
chegar
parents:
43797
diff
changeset
|
785 |
for (String option : new String[] {"--describe-module", "-d" }) { |
43731
bc7110b230c1
8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents:
43712
diff
changeset
|
786 |
|
bc7110b230c1
8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents:
43712
diff
changeset
|
787 |
jar(option, |
45004
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
788 |
"--file=" + modularJar.toString(), |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
789 |
"--release", "9") |
43731
bc7110b230c1
8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents:
43712
diff
changeset
|
790 |
.assertSuccess() |
bc7110b230c1
8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents:
43712
diff
changeset
|
791 |
.resultChecker(r -> |
bc7110b230c1
8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents:
43712
diff
changeset
|
792 |
assertTrue(r.output.contains("main-class jdk.test.baz.Baz"), |
bc7110b230c1
8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents:
43712
diff
changeset
|
793 |
"Expected to find ", "main-class jdk.test.baz.Baz", |
bc7110b230c1
8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents:
43712
diff
changeset
|
794 |
" in [", r.output, "]")); |
bc7110b230c1
8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents:
43712
diff
changeset
|
795 |
|
45004
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
796 |
jarWithStdin(modularJar.toFile(), option, "--release", "9") |
43731
bc7110b230c1
8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents:
43712
diff
changeset
|
797 |
.assertSuccess() |
bc7110b230c1
8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents:
43712
diff
changeset
|
798 |
.resultChecker(r -> |
bc7110b230c1
8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents:
43712
diff
changeset
|
799 |
assertTrue(r.output.contains("main-class jdk.test.baz.Baz"), |
bc7110b230c1
8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents:
43712
diff
changeset
|
800 |
"Expected to find ", "main-class jdk.test.baz.Baz", |
bc7110b230c1
8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents:
43712
diff
changeset
|
801 |
" in [", r.output, "]")); |
bc7110b230c1
8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents:
43712
diff
changeset
|
802 |
|
bc7110b230c1
8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents:
43712
diff
changeset
|
803 |
} |
45004
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
804 |
// run module main class |
43731
bc7110b230c1
8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents:
43712
diff
changeset
|
805 |
java(mp, "baz/jdk.test.baz.Baz") |
bc7110b230c1
8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents:
43712
diff
changeset
|
806 |
.assertSuccess() |
bc7110b230c1
8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents:
43712
diff
changeset
|
807 |
.resultChecker(r -> |
bc7110b230c1
8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents:
43712
diff
changeset
|
808 |
assertTrue(r.output.contains("mainClass:jdk.test.baz.Baz"), |
bc7110b230c1
8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents:
43712
diff
changeset
|
809 |
"Expected to find ", "mainClass:jdk.test.baz.Baz", |
bc7110b230c1
8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents:
43712
diff
changeset
|
810 |
" in [", r.output, "]")); |
bc7110b230c1
8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents:
43712
diff
changeset
|
811 |
} |
bc7110b230c1
8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents:
43712
diff
changeset
|
812 |
|
bc7110b230c1
8165640: Enhance jar tool to allow module-info in versioned directories but not in base in modular multi-release jar files
sherman
parents:
43712
diff
changeset
|
813 |
@Test |
43095
336dfda4ae89
8172432: jar cleanup/update for module and mrm jar
sherman
parents:
42345
diff
changeset
|
814 |
public void exportCreateWithMissingPkg() throws IOException { |
336dfda4ae89
8172432: jar cleanup/update for module and mrm jar
sherman
parents:
42345
diff
changeset
|
815 |
|
336dfda4ae89
8172432: jar cleanup/update for module and mrm jar
sherman
parents:
42345
diff
changeset
|
816 |
Path foobar = TEST_SRC.resolve("src").resolve("foobar"); |
336dfda4ae89
8172432: jar cleanup/update for module and mrm jar
sherman
parents:
42345
diff
changeset
|
817 |
Path dst = Files.createDirectories(MODULE_CLASSES.resolve("foobar")); |
336dfda4ae89
8172432: jar cleanup/update for module and mrm jar
sherman
parents:
42345
diff
changeset
|
818 |
javac(dst, null, sourceList(foobar)); |
336dfda4ae89
8172432: jar cleanup/update for module and mrm jar
sherman
parents:
42345
diff
changeset
|
819 |
|
336dfda4ae89
8172432: jar cleanup/update for module and mrm jar
sherman
parents:
42345
diff
changeset
|
820 |
Path mp = Paths.get("exportWithMissingPkg"); |
336dfda4ae89
8172432: jar cleanup/update for module and mrm jar
sherman
parents:
42345
diff
changeset
|
821 |
createTestDir(mp); |
336dfda4ae89
8172432: jar cleanup/update for module and mrm jar
sherman
parents:
42345
diff
changeset
|
822 |
Path modClasses = dst; |
336dfda4ae89
8172432: jar cleanup/update for module and mrm jar
sherman
parents:
42345
diff
changeset
|
823 |
Path modularJar = mp.resolve("foofoo.jar"); |
336dfda4ae89
8172432: jar cleanup/update for module and mrm jar
sherman
parents:
42345
diff
changeset
|
824 |
|
336dfda4ae89
8172432: jar cleanup/update for module and mrm jar
sherman
parents:
42345
diff
changeset
|
825 |
jar("--create", |
336dfda4ae89
8172432: jar cleanup/update for module and mrm jar
sherman
parents:
42345
diff
changeset
|
826 |
"--file=" + modularJar.toString(), |
336dfda4ae89
8172432: jar cleanup/update for module and mrm jar
sherman
parents:
42345
diff
changeset
|
827 |
"-C", modClasses.toString(), "module-info.class", |
336dfda4ae89
8172432: jar cleanup/update for module and mrm jar
sherman
parents:
42345
diff
changeset
|
828 |
"-C", modClasses.toString(), "jdk/test/foo/Foo.class") |
336dfda4ae89
8172432: jar cleanup/update for module and mrm jar
sherman
parents:
42345
diff
changeset
|
829 |
.assertFailure(); |
336dfda4ae89
8172432: jar cleanup/update for module and mrm jar
sherman
parents:
42345
diff
changeset
|
830 |
} |
336dfda4ae89
8172432: jar cleanup/update for module and mrm jar
sherman
parents:
42345
diff
changeset
|
831 |
|
336dfda4ae89
8172432: jar cleanup/update for module and mrm jar
sherman
parents:
42345
diff
changeset
|
832 |
@Test |
44267
00898a596f31
8176772: jar tool support to report automatic module names
chegar
parents:
43797
diff
changeset
|
833 |
public void describeModuleFoo() throws IOException { |
00898a596f31
8176772: jar tool support to report automatic module names
chegar
parents:
43797
diff
changeset
|
834 |
Path mp = Paths.get("describeModuleFoo"); |
36511 | 835 |
createTestDir(mp); |
836 |
Path modClasses = MODULE_CLASSES.resolve(FOO.moduleName); |
|
837 |
Path modularJar = mp.resolve(FOO.moduleName + ".jar"); |
|
838 |
||
839 |
jar("--create", |
|
840 |
"--file=" + modularJar.toString(), |
|
841 |
"--main-class=" + FOO.mainClass, |
|
842 |
"--module-version=" + FOO.version, |
|
843 |
"--no-manifest", |
|
844 |
"-C", modClasses.toString(), ".") |
|
845 |
.assertSuccess(); |
|
846 |
||
44267
00898a596f31
8176772: jar tool support to report automatic module names
chegar
parents:
43797
diff
changeset
|
847 |
for (String option : new String[] {"--describe-module", "-d" }) { |
36511 | 848 |
jar(option, |
849 |
"--file=" + modularJar.toString()) |
|
850 |
.assertSuccess() |
|
851 |
.resultChecker(r -> |
|
852 |
assertTrue(r.output.contains(FOO.moduleName + "@" + FOO.version), |
|
853 |
"Expected to find ", FOO.moduleName + "@" + FOO.version, |
|
854 |
" in [", r.output, "]") |
|
855 |
); |
|
42345 | 856 |
|
857 |
jar(option, |
|
858 |
"--file=" + modularJar.toString(), |
|
859 |
modularJar.toString()) |
|
860 |
.assertFailure(); |
|
861 |
||
862 |
jar(option, modularJar.toString()) |
|
863 |
.assertFailure(); |
|
36511 | 864 |
} |
865 |
} |
|
866 |
||
867 |
@Test |
|
44267
00898a596f31
8176772: jar tool support to report automatic module names
chegar
parents:
43797
diff
changeset
|
868 |
public void describeModuleFooFromStdin() throws IOException { |
00898a596f31
8176772: jar tool support to report automatic module names
chegar
parents:
43797
diff
changeset
|
869 |
Path mp = Paths.get("describeModuleFooFromStdin"); |
36511 | 870 |
createTestDir(mp); |
871 |
Path modClasses = MODULE_CLASSES.resolve(FOO.moduleName); |
|
872 |
Path modularJar = mp.resolve(FOO.moduleName + ".jar"); |
|
873 |
||
874 |
jar("--create", |
|
875 |
"--file=" + modularJar.toString(), |
|
876 |
"--main-class=" + FOO.mainClass, |
|
877 |
"--module-version=" + FOO.version, |
|
878 |
"--no-manifest", |
|
879 |
"-C", modClasses.toString(), ".") |
|
880 |
.assertSuccess(); |
|
881 |
||
44267
00898a596f31
8176772: jar tool support to report automatic module names
chegar
parents:
43797
diff
changeset
|
882 |
for (String option : new String[] {"--describe-module", "-d" }) { |
36511 | 883 |
jarWithStdin(modularJar.toFile(), |
884 |
option) |
|
885 |
.assertSuccess() |
|
886 |
.resultChecker(r -> |
|
887 |
assertTrue(r.output.contains(FOO.moduleName + "@" + FOO.version), |
|
888 |
"Expected to find ", FOO.moduleName + "@" + FOO.version, |
|
889 |
" in [", r.output, "]") |
|
890 |
); |
|
891 |
} |
|
892 |
} |
|
893 |
||
52723
f24ae8376e71
8210454: jar tool does not allow setting the module version without also setting the main class
lancea
parents:
51687
diff
changeset
|
894 |
/** |
f24ae8376e71
8210454: jar tool does not allow setting the module version without also setting the main class
lancea
parents:
51687
diff
changeset
|
895 |
* Validate that you can update a jar only specifying --module-version |
f24ae8376e71
8210454: jar tool does not allow setting the module version without also setting the main class
lancea
parents:
51687
diff
changeset
|
896 |
* @throws IOException |
f24ae8376e71
8210454: jar tool does not allow setting the module version without also setting the main class
lancea
parents:
51687
diff
changeset
|
897 |
*/ |
f24ae8376e71
8210454: jar tool does not allow setting the module version without also setting the main class
lancea
parents:
51687
diff
changeset
|
898 |
@Test |
f24ae8376e71
8210454: jar tool does not allow setting the module version without also setting the main class
lancea
parents:
51687
diff
changeset
|
899 |
public void updateFooModuleVersion() throws IOException { |
f24ae8376e71
8210454: jar tool does not allow setting the module version without also setting the main class
lancea
parents:
51687
diff
changeset
|
900 |
Path mp = Paths.get("updateFooModuleVersion"); |
f24ae8376e71
8210454: jar tool does not allow setting the module version without also setting the main class
lancea
parents:
51687
diff
changeset
|
901 |
createTestDir(mp); |
f24ae8376e71
8210454: jar tool does not allow setting the module version without also setting the main class
lancea
parents:
51687
diff
changeset
|
902 |
Path modClasses = MODULE_CLASSES.resolve(FOO.moduleName); |
f24ae8376e71
8210454: jar tool does not allow setting the module version without also setting the main class
lancea
parents:
51687
diff
changeset
|
903 |
Path modularJar = mp.resolve(FOO.moduleName + ".jar"); |
f24ae8376e71
8210454: jar tool does not allow setting the module version without also setting the main class
lancea
parents:
51687
diff
changeset
|
904 |
String newFooVersion = "87.0"; |
f24ae8376e71
8210454: jar tool does not allow setting the module version without also setting the main class
lancea
parents:
51687
diff
changeset
|
905 |
|
f24ae8376e71
8210454: jar tool does not allow setting the module version without also setting the main class
lancea
parents:
51687
diff
changeset
|
906 |
jar("--create", |
f24ae8376e71
8210454: jar tool does not allow setting the module version without also setting the main class
lancea
parents:
51687
diff
changeset
|
907 |
"--file=" + modularJar.toString(), |
f24ae8376e71
8210454: jar tool does not allow setting the module version without also setting the main class
lancea
parents:
51687
diff
changeset
|
908 |
"--main-class=" + FOO.mainClass, |
f24ae8376e71
8210454: jar tool does not allow setting the module version without also setting the main class
lancea
parents:
51687
diff
changeset
|
909 |
"--module-version=" + FOO.version, |
f24ae8376e71
8210454: jar tool does not allow setting the module version without also setting the main class
lancea
parents:
51687
diff
changeset
|
910 |
"--no-manifest", |
f24ae8376e71
8210454: jar tool does not allow setting the module version without also setting the main class
lancea
parents:
51687
diff
changeset
|
911 |
"-C", modClasses.toString(), ".") |
f24ae8376e71
8210454: jar tool does not allow setting the module version without also setting the main class
lancea
parents:
51687
diff
changeset
|
912 |
.assertSuccess(); |
f24ae8376e71
8210454: jar tool does not allow setting the module version without also setting the main class
lancea
parents:
51687
diff
changeset
|
913 |
|
f24ae8376e71
8210454: jar tool does not allow setting the module version without also setting the main class
lancea
parents:
51687
diff
changeset
|
914 |
jarWithStdin(modularJar.toFile(), "--describe-module") |
f24ae8376e71
8210454: jar tool does not allow setting the module version without also setting the main class
lancea
parents:
51687
diff
changeset
|
915 |
.assertSuccess() |
f24ae8376e71
8210454: jar tool does not allow setting the module version without also setting the main class
lancea
parents:
51687
diff
changeset
|
916 |
.resultChecker(r -> |
f24ae8376e71
8210454: jar tool does not allow setting the module version without also setting the main class
lancea
parents:
51687
diff
changeset
|
917 |
assertTrue(r.output.contains(FOO.moduleName + "@" + FOO.version), |
f24ae8376e71
8210454: jar tool does not allow setting the module version without also setting the main class
lancea
parents:
51687
diff
changeset
|
918 |
"Expected to find ", FOO.moduleName + "@" + FOO.version, |
f24ae8376e71
8210454: jar tool does not allow setting the module version without also setting the main class
lancea
parents:
51687
diff
changeset
|
919 |
" in [", r.output, "]") |
f24ae8376e71
8210454: jar tool does not allow setting the module version without also setting the main class
lancea
parents:
51687
diff
changeset
|
920 |
); |
f24ae8376e71
8210454: jar tool does not allow setting the module version without also setting the main class
lancea
parents:
51687
diff
changeset
|
921 |
|
f24ae8376e71
8210454: jar tool does not allow setting the module version without also setting the main class
lancea
parents:
51687
diff
changeset
|
922 |
jar("--update", |
f24ae8376e71
8210454: jar tool does not allow setting the module version without also setting the main class
lancea
parents:
51687
diff
changeset
|
923 |
"--file=" + modularJar.toString(), |
f24ae8376e71
8210454: jar tool does not allow setting the module version without also setting the main class
lancea
parents:
51687
diff
changeset
|
924 |
"--module-version=" + newFooVersion) |
f24ae8376e71
8210454: jar tool does not allow setting the module version without also setting the main class
lancea
parents:
51687
diff
changeset
|
925 |
.assertSuccess(); |
f24ae8376e71
8210454: jar tool does not allow setting the module version without also setting the main class
lancea
parents:
51687
diff
changeset
|
926 |
|
f24ae8376e71
8210454: jar tool does not allow setting the module version without also setting the main class
lancea
parents:
51687
diff
changeset
|
927 |
for (String option : new String[] {"--describe-module", "-d" }) { |
f24ae8376e71
8210454: jar tool does not allow setting the module version without also setting the main class
lancea
parents:
51687
diff
changeset
|
928 |
jarWithStdin(modularJar.toFile(), |
f24ae8376e71
8210454: jar tool does not allow setting the module version without also setting the main class
lancea
parents:
51687
diff
changeset
|
929 |
option) |
f24ae8376e71
8210454: jar tool does not allow setting the module version without also setting the main class
lancea
parents:
51687
diff
changeset
|
930 |
.assertSuccess() |
f24ae8376e71
8210454: jar tool does not allow setting the module version without also setting the main class
lancea
parents:
51687
diff
changeset
|
931 |
.resultChecker(r -> |
f24ae8376e71
8210454: jar tool does not allow setting the module version without also setting the main class
lancea
parents:
51687
diff
changeset
|
932 |
assertTrue(r.output.contains(FOO.moduleName + "@" + newFooVersion), |
f24ae8376e71
8210454: jar tool does not allow setting the module version without also setting the main class
lancea
parents:
51687
diff
changeset
|
933 |
"Expected to find ", FOO.moduleName + "@" + newFooVersion, |
f24ae8376e71
8210454: jar tool does not allow setting the module version without also setting the main class
lancea
parents:
51687
diff
changeset
|
934 |
" in [", r.output, "]") |
f24ae8376e71
8210454: jar tool does not allow setting the module version without also setting the main class
lancea
parents:
51687
diff
changeset
|
935 |
); |
f24ae8376e71
8210454: jar tool does not allow setting the module version without also setting the main class
lancea
parents:
51687
diff
changeset
|
936 |
} |
f24ae8376e71
8210454: jar tool does not allow setting the module version without also setting the main class
lancea
parents:
51687
diff
changeset
|
937 |
} |
44267
00898a596f31
8176772: jar tool support to report automatic module names
chegar
parents:
43797
diff
changeset
|
938 |
|
00898a596f31
8176772: jar tool support to report automatic module names
chegar
parents:
43797
diff
changeset
|
939 |
@DataProvider(name = "autoNames") |
00898a596f31
8176772: jar tool support to report automatic module names
chegar
parents:
43797
diff
changeset
|
940 |
public Object[][] autoNames() { |
00898a596f31
8176772: jar tool support to report automatic module names
chegar
parents:
43797
diff
changeset
|
941 |
return new Object[][] { |
00898a596f31
8176772: jar tool support to report automatic module names
chegar
parents:
43797
diff
changeset
|
942 |
// JAR file name module-name[@version] |
00898a596f31
8176772: jar tool support to report automatic module names
chegar
parents:
43797
diff
changeset
|
943 |
{ "foo.jar", "foo" }, |
44545
83b611b88ac8
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44267
diff
changeset
|
944 |
{ "foo1.jar", "foo1" }, |
44267
00898a596f31
8176772: jar tool support to report automatic module names
chegar
parents:
43797
diff
changeset
|
945 |
{ "foo4j.jar", "foo4j", }, |
00898a596f31
8176772: jar tool support to report automatic module names
chegar
parents:
43797
diff
changeset
|
946 |
{ "foo-1.2.3.4.jar", "foo@1.2.3.4" }, |
00898a596f31
8176772: jar tool support to report automatic module names
chegar
parents:
43797
diff
changeset
|
947 |
{ "foo-bar.jar", "foo.bar" }, |
00898a596f31
8176772: jar tool support to report automatic module names
chegar
parents:
43797
diff
changeset
|
948 |
{ "foo-1.2-SNAPSHOT.jar", "foo@1.2-SNAPSHOT" }, |
00898a596f31
8176772: jar tool support to report automatic module names
chegar
parents:
43797
diff
changeset
|
949 |
}; |
00898a596f31
8176772: jar tool support to report automatic module names
chegar
parents:
43797
diff
changeset
|
950 |
} |
00898a596f31
8176772: jar tool support to report automatic module names
chegar
parents:
43797
diff
changeset
|
951 |
|
00898a596f31
8176772: jar tool support to report automatic module names
chegar
parents:
43797
diff
changeset
|
952 |
@Test(dataProvider = "autoNames") |
00898a596f31
8176772: jar tool support to report automatic module names
chegar
parents:
43797
diff
changeset
|
953 |
public void describeAutomaticModule(String jarName, String mid) |
00898a596f31
8176772: jar tool support to report automatic module names
chegar
parents:
43797
diff
changeset
|
954 |
throws IOException |
00898a596f31
8176772: jar tool support to report automatic module names
chegar
parents:
43797
diff
changeset
|
955 |
{ |
00898a596f31
8176772: jar tool support to report automatic module names
chegar
parents:
43797
diff
changeset
|
956 |
Path mp = Paths.get("describeAutomaticModule"); |
00898a596f31
8176772: jar tool support to report automatic module names
chegar
parents:
43797
diff
changeset
|
957 |
createTestDir(mp); |
00898a596f31
8176772: jar tool support to report automatic module names
chegar
parents:
43797
diff
changeset
|
958 |
Path regularJar = mp.resolve(jarName); |
00898a596f31
8176772: jar tool support to report automatic module names
chegar
parents:
43797
diff
changeset
|
959 |
Path t = Paths.get("t"); |
00898a596f31
8176772: jar tool support to report automatic module names
chegar
parents:
43797
diff
changeset
|
960 |
if (Files.notExists(t)) |
00898a596f31
8176772: jar tool support to report automatic module names
chegar
parents:
43797
diff
changeset
|
961 |
Files.createFile(t); |
00898a596f31
8176772: jar tool support to report automatic module names
chegar
parents:
43797
diff
changeset
|
962 |
|
00898a596f31
8176772: jar tool support to report automatic module names
chegar
parents:
43797
diff
changeset
|
963 |
jar("--create", |
00898a596f31
8176772: jar tool support to report automatic module names
chegar
parents:
43797
diff
changeset
|
964 |
"--file=" + regularJar.toString(), |
00898a596f31
8176772: jar tool support to report automatic module names
chegar
parents:
43797
diff
changeset
|
965 |
t.toString()) |
00898a596f31
8176772: jar tool support to report automatic module names
chegar
parents:
43797
diff
changeset
|
966 |
.assertSuccess(); |
00898a596f31
8176772: jar tool support to report automatic module names
chegar
parents:
43797
diff
changeset
|
967 |
|
00898a596f31
8176772: jar tool support to report automatic module names
chegar
parents:
43797
diff
changeset
|
968 |
for (String option : new String[] {"--describe-module", "-d" }) { |
00898a596f31
8176772: jar tool support to report automatic module names
chegar
parents:
43797
diff
changeset
|
969 |
jar(option, |
00898a596f31
8176772: jar tool support to report automatic module names
chegar
parents:
43797
diff
changeset
|
970 |
"--file=" + regularJar.toString()) |
00898a596f31
8176772: jar tool support to report automatic module names
chegar
parents:
43797
diff
changeset
|
971 |
.assertSuccess() |
00898a596f31
8176772: jar tool support to report automatic module names
chegar
parents:
43797
diff
changeset
|
972 |
.resultChecker(r -> { |
00898a596f31
8176772: jar tool support to report automatic module names
chegar
parents:
43797
diff
changeset
|
973 |
assertTrue(r.output.contains("No module descriptor found")); |
00898a596f31
8176772: jar tool support to report automatic module names
chegar
parents:
43797
diff
changeset
|
974 |
assertTrue(r.output.contains("Derived automatic module")); |
45004
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
44545
diff
changeset
|
975 |
assertTrue(r.output.contains(mid + " automatic"), |
44267
00898a596f31
8176772: jar tool support to report automatic module names
chegar
parents:
43797
diff
changeset
|
976 |
"Expected [", "module " + mid,"] in [", r.output, "]"); |
00898a596f31
8176772: jar tool support to report automatic module names
chegar
parents:
43797
diff
changeset
|
977 |
} |
00898a596f31
8176772: jar tool support to report automatic module names
chegar
parents:
43797
diff
changeset
|
978 |
); |
00898a596f31
8176772: jar tool support to report automatic module names
chegar
parents:
43797
diff
changeset
|
979 |
} |
00898a596f31
8176772: jar tool support to report automatic module names
chegar
parents:
43797
diff
changeset
|
980 |
} |
00898a596f31
8176772: jar tool support to report automatic module names
chegar
parents:
43797
diff
changeset
|
981 |
|
36511 | 982 |
// -- Infrastructure |
983 |
||
984 |
static Result jarWithStdin(File stdinSource, String... args) { |
|
985 |
String jar = getJDKTool("jar"); |
|
986 |
List<String> commands = new ArrayList<>(); |
|
987 |
commands.add(jar); |
|
38762
2956ccc7cb77
8157850: Jar tests should pass through VM options
anazarov
parents:
38468
diff
changeset
|
988 |
if (!TOOL_VM_OPTIONS.isEmpty()) { |
2956ccc7cb77
8157850: Jar tests should pass through VM options
anazarov
parents:
38468
diff
changeset
|
989 |
commands.addAll(Arrays.asList(TOOL_VM_OPTIONS.split("\\s+", -1))); |
2956ccc7cb77
8157850: Jar tests should pass through VM options
anazarov
parents:
38468
diff
changeset
|
990 |
} |
2956ccc7cb77
8157850: Jar tests should pass through VM options
anazarov
parents:
38468
diff
changeset
|
991 |
Stream.of(args).forEach(commands::add); |
36511 | 992 |
ProcessBuilder p = new ProcessBuilder(commands); |
54413
30067047ed88
8216539: tools/jar/modularJar/Basic.java times out
lancea
parents:
52723
diff
changeset
|
993 |
if (stdinSource != null) { |
36511 | 994 |
p.redirectInput(stdinSource); |
54413
30067047ed88
8216539: tools/jar/modularJar/Basic.java times out
lancea
parents:
52723
diff
changeset
|
995 |
} |
36511 | 996 |
return run(p); |
997 |
} |
|
998 |
||
999 |
static Result jar(String... args) { |
|
54413
30067047ed88
8216539: tools/jar/modularJar/Basic.java times out
lancea
parents:
52723
diff
changeset
|
1000 |
return run(JAR_TOOL, args); |
36511 | 1001 |
} |
1002 |
||
1003 |
static Path compileModule(String mn) throws IOException { |
|
1004 |
return compileModule(mn, null); |
|
1005 |
} |
|
1006 |
||
1007 |
static Path compileModule(String mn, Path mp) |
|
1008 |
throws IOException |
|
1009 |
{ |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
1010 |
Path sourcePath = TEST_SRC.resolve("src").resolve(mn); |
36511 | 1011 |
Path build = Files.createDirectories(MODULE_CLASSES.resolve(mn)); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
1012 |
javac(build, mp, sourceList(sourcePath)); |
36511 | 1013 |
return build; |
1014 |
} |
|
1015 |
||
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
1016 |
static void copyResource(Path srcDir, Path dir, String resource) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
1017 |
throws IOException |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
1018 |
{ |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
1019 |
Path dest = dir.resolve(resource); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
1020 |
Files.deleteIfExists(dest); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
1021 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
1022 |
Files.createDirectories(dest.getParent()); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
1023 |
Files.copy(srcDir.resolve(resource), dest); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
1024 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
1025 |
|
38468
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
1026 |
static void setupMRJARModuleInfo(String moduleName) throws IOException { |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
1027 |
Path modClasses = MODULE_CLASSES.resolve(moduleName); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
1028 |
Path metaInfDir = MRJAR_DIR.resolve(moduleName).resolve("META-INF"); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
1029 |
Path versionSection = metaInfDir.resolve("versions").resolve("9"); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
1030 |
createTestDir(versionSection); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
1031 |
|
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
1032 |
Path versionModuleInfo = versionSection.resolve("module-info.class"); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
1033 |
System.out.println("copying " + modClasses.resolve("module-info.class") + " to " + versionModuleInfo); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
1034 |
Files.copy(modClasses.resolve("module-info.class"), versionModuleInfo); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
1035 |
|
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
1036 |
Manifest manifest = new Manifest(); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
1037 |
manifest.getMainAttributes().putValue("Manifest-Version", "1.0"); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
1038 |
manifest.getMainAttributes().putValue("Multi-Release", "true"); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
1039 |
try (OutputStream os = Files.newOutputStream(metaInfDir.resolve("MANIFEST.MF"))) { |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
1040 |
manifest.write(os); |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
1041 |
} |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
1042 |
} |
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
1043 |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
1044 |
static ModuleDescriptor getModuleDescriptor(Path jar) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
1045 |
ClassLoader cl = ClassLoader.getSystemClassLoader(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
1046 |
try (JarFile jf = new JarFile(jar.toFile())) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
1047 |
JarEntry entry = jf.getJarEntry("module-info.class"); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
1048 |
try (InputStream in = jf.getInputStream(entry)) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
1049 |
return ModuleDescriptor.read(in); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
1050 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
1051 |
} catch (IOException ioe) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
1052 |
throw new UncheckedIOException(ioe); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
1053 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
1054 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
1055 |
|
36511 | 1056 |
// Re-enable when there is support in javax.tools for module path |
1057 |
// static void javac(Path dest, Path... sourceFiles) throws IOException { |
|
1058 |
// out.printf("Compiling %d source files %s%n", sourceFiles.length, |
|
1059 |
// Arrays.asList(sourceFiles)); |
|
1060 |
// JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); |
|
1061 |
// try (StandardJavaFileManager fileManager = |
|
1062 |
// compiler.getStandardFileManager(null, null, null)) { |
|
1063 |
// |
|
1064 |
// List<File> files = Stream.of(sourceFiles) |
|
1065 |
// .map(p -> p.toFile()) |
|
1066 |
// .collect(Collectors.toList()); |
|
1067 |
// List<File> dests = Stream.of(dest) |
|
1068 |
// .map(p -> p.toFile()) |
|
1069 |
// .collect(Collectors.toList()); |
|
1070 |
// Iterable<? extends JavaFileObject> compilationUnits = |
|
1071 |
// fileManager.getJavaFileObjectsFromFiles(files); |
|
1072 |
// fileManager.setLocation(StandardLocation.CLASS_OUTPUT, dests); |
|
1073 |
// JavaCompiler.CompilationTask task = |
|
1074 |
// compiler.getTask(null, fileManager, null, null, null, compilationUnits); |
|
1075 |
// boolean passed = task.call(); |
|
1076 |
// if (!passed) |
|
1077 |
// throw new RuntimeException("Error compiling " + files); |
|
1078 |
// } |
|
1079 |
// } |
|
1080 |
||
1081 |
static void javac(Path dest, Path... sourceFiles) throws IOException { |
|
1082 |
javac(dest, null, sourceFiles); |
|
1083 |
} |
|
1084 |
||
1085 |
static void javac(Path dest, Path modulePath, Path... sourceFiles) |
|
1086 |
throws IOException |
|
1087 |
{ |
|
1088 |
||
1089 |
List<String> commands = new ArrayList<>(); |
|
38762
2956ccc7cb77
8157850: Jar tests should pass through VM options
anazarov
parents:
38468
diff
changeset
|
1090 |
if (!TOOL_VM_OPTIONS.isEmpty()) { |
2956ccc7cb77
8157850: Jar tests should pass through VM options
anazarov
parents:
38468
diff
changeset
|
1091 |
commands.addAll(Arrays.asList(TOOL_VM_OPTIONS.split("\\s+", -1))); |
2956ccc7cb77
8157850: Jar tests should pass through VM options
anazarov
parents:
38468
diff
changeset
|
1092 |
} |
36511 | 1093 |
commands.add("-d"); |
1094 |
commands.add(dest.toString()); |
|
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38762
diff
changeset
|
1095 |
if (dest.toString().contains("bar")) { |
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38762
diff
changeset
|
1096 |
commands.add("--add-exports"); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
1097 |
commands.add("java.base/jdk.internal.misc=bar"); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
1098 |
commands.add("--add-exports"); |
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38762
diff
changeset
|
1099 |
commands.add("java.base/jdk.internal.module=bar"); |
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38762
diff
changeset
|
1100 |
} |
36511 | 1101 |
if (modulePath != null) { |
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38762
diff
changeset
|
1102 |
commands.add("--module-path"); |
36511 | 1103 |
commands.add(modulePath.toString()); |
1104 |
} |
|
1105 |
Stream.of(sourceFiles).map(Object::toString).forEach(x -> commands.add(x)); |
|
1106 |
||
54413
30067047ed88
8216539: tools/jar/modularJar/Basic.java times out
lancea
parents:
52723
diff
changeset
|
1107 |
StringWriter sw = new StringWriter(); |
30067047ed88
8216539: tools/jar/modularJar/Basic.java times out
lancea
parents:
52723
diff
changeset
|
1108 |
try (PrintWriter pw = new PrintWriter(sw)) { |
30067047ed88
8216539: tools/jar/modularJar/Basic.java times out
lancea
parents:
52723
diff
changeset
|
1109 |
int rc = JAVAC_TOOL.run(pw, pw, commands.toArray(new String[0])); |
30067047ed88
8216539: tools/jar/modularJar/Basic.java times out
lancea
parents:
52723
diff
changeset
|
1110 |
if(rc != 0) { |
30067047ed88
8216539: tools/jar/modularJar/Basic.java times out
lancea
parents:
52723
diff
changeset
|
1111 |
throw new RuntimeException(sw.toString()); |
30067047ed88
8216539: tools/jar/modularJar/Basic.java times out
lancea
parents:
52723
diff
changeset
|
1112 |
} |
30067047ed88
8216539: tools/jar/modularJar/Basic.java times out
lancea
parents:
52723
diff
changeset
|
1113 |
} |
36511 | 1114 |
} |
1115 |
||
1116 |
static Result java(Path modulePath, String entryPoint, String... args) { |
|
1117 |
String java = getJDKTool("java"); |
|
1118 |
||
1119 |
List<String> commands = new ArrayList<>(); |
|
1120 |
commands.add(java); |
|
38762
2956ccc7cb77
8157850: Jar tests should pass through VM options
anazarov
parents:
38468
diff
changeset
|
1121 |
if (!VM_OPTIONS.isEmpty()) { |
2956ccc7cb77
8157850: Jar tests should pass through VM options
anazarov
parents:
38468
diff
changeset
|
1122 |
commands.addAll(Arrays.asList(VM_OPTIONS.split("\\s+", -1))); |
2956ccc7cb77
8157850: Jar tests should pass through VM options
anazarov
parents:
38468
diff
changeset
|
1123 |
} |
2956ccc7cb77
8157850: Jar tests should pass through VM options
anazarov
parents:
38468
diff
changeset
|
1124 |
if (!JAVA_OPTIONS.isEmpty()) { |
2956ccc7cb77
8157850: Jar tests should pass through VM options
anazarov
parents:
38468
diff
changeset
|
1125 |
commands.addAll(Arrays.asList(JAVA_OPTIONS.split("\\s+", -1))); |
2956ccc7cb77
8157850: Jar tests should pass through VM options
anazarov
parents:
38468
diff
changeset
|
1126 |
} |
36511 | 1127 |
Stream.of(args).forEach(x -> commands.add(x)); |
40261
86a49ba76f52
8136930: Simplify use of module-system options by custom launchers
mchung
parents:
38762
diff
changeset
|
1128 |
commands.add("--module-path"); |
36511 | 1129 |
commands.add(modulePath.toString()); |
1130 |
commands.add("-m"); |
|
1131 |
commands.add(entryPoint); |
|
1132 |
||
1133 |
return run(new ProcessBuilder(commands)); |
|
1134 |
} |
|
1135 |
||
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
1136 |
static Path[] sourceList(Path directory) throws IOException { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
1137 |
return Files.find(directory, Integer.MAX_VALUE, |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
1138 |
(file, attrs) -> (file.toString().endsWith(".java"))) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
40261
diff
changeset
|
1139 |
.toArray(Path[]::new); |
36511 | 1140 |
} |
1141 |
||
1142 |
static void createTestDir(Path p) throws IOException{ |
|
1143 |
if (Files.exists(p)) |
|
1144 |
FileUtils.deleteFileTreeWithRetry(p); |
|
38468
d459a0f8fe72
8156497: Add jar tool support for Multi-Release Modular JARs
chegar
parents:
37779
diff
changeset
|
1145 |
Files.createDirectories(p); |
36511 | 1146 |
} |
1147 |
||
1148 |
static boolean jarContains(JarInputStream jis, String entryName) |
|
1149 |
throws IOException |
|
1150 |
{ |
|
1151 |
JarEntry e; |
|
1152 |
while((e = jis.getNextJarEntry()) != null) { |
|
1153 |
if (e.getName().equals(entryName)) |
|
1154 |
return true; |
|
1155 |
} |
|
1156 |
return false; |
|
1157 |
} |
|
1158 |
||
54413
30067047ed88
8216539: tools/jar/modularJar/Basic.java times out
lancea
parents:
52723
diff
changeset
|
1159 |
static Result run(ToolProvider tp, String[] commands) { |
30067047ed88
8216539: tools/jar/modularJar/Basic.java times out
lancea
parents:
52723
diff
changeset
|
1160 |
int rc = 0; |
30067047ed88
8216539: tools/jar/modularJar/Basic.java times out
lancea
parents:
52723
diff
changeset
|
1161 |
StringWriter sw = new StringWriter(); |
30067047ed88
8216539: tools/jar/modularJar/Basic.java times out
lancea
parents:
52723
diff
changeset
|
1162 |
try (PrintWriter pw = new PrintWriter(sw)) { |
30067047ed88
8216539: tools/jar/modularJar/Basic.java times out
lancea
parents:
52723
diff
changeset
|
1163 |
rc = tp.run(pw, pw, commands); |
30067047ed88
8216539: tools/jar/modularJar/Basic.java times out
lancea
parents:
52723
diff
changeset
|
1164 |
} |
30067047ed88
8216539: tools/jar/modularJar/Basic.java times out
lancea
parents:
52723
diff
changeset
|
1165 |
return new Result(rc, sw.toString()); |
36511 | 1166 |
} |
1167 |
||
1168 |
static Result run(ProcessBuilder pb) { |
|
1169 |
Process p; |
|
1170 |
out.printf("Running: %s%n", pb.command()); |
|
1171 |
try { |
|
1172 |
p = pb.start(); |
|
1173 |
} catch (IOException e) { |
|
1174 |
throw new RuntimeException( |
|
1175 |
format("Couldn't start process '%s'", pb.command()), e); |
|
1176 |
} |
|
1177 |
||
1178 |
String output; |
|
1179 |
try { |
|
1180 |
output = toString(p.getInputStream(), p.getErrorStream()); |
|
1181 |
} catch (IOException e) { |
|
1182 |
throw new RuntimeException( |
|
1183 |
format("Couldn't read process output '%s'", pb.command()), e); |
|
1184 |
} |
|
1185 |
||
1186 |
try { |
|
1187 |
p.waitFor(); |
|
1188 |
} catch (InterruptedException e) { |
|
1189 |
throw new RuntimeException( |
|
1190 |
format("Process hasn't finished '%s'", pb.command()), e); |
|
1191 |
} |
|
1192 |
return new Result(p.exitValue(), output); |
|
1193 |
} |
|
1194 |
||
1195 |
static final String DEFAULT_IMAGE_BIN = System.getProperty("java.home") |
|
1196 |
+ File.separator + "bin" + File.separator; |
|
1197 |
||
1198 |
static String getJDKTool(String name) { |
|
1199 |
try { |
|
1200 |
return JDKToolFinder.getJDKTool(name); |
|
1201 |
} catch (Exception x) { |
|
1202 |
return DEFAULT_IMAGE_BIN + name; |
|
1203 |
} |
|
1204 |
} |
|
1205 |
||
1206 |
static String toString(InputStream in1, InputStream in2) throws IOException { |
|
1207 |
try (ByteArrayOutputStream dst = new ByteArrayOutputStream(); |
|
1208 |
InputStream concatenated = new SequenceInputStream(in1, in2)) { |
|
1209 |
concatenated.transferTo(dst); |
|
1210 |
return new String(dst.toByteArray(), "UTF-8"); |
|
1211 |
} |
|
1212 |
} |
|
1213 |
||
1214 |
static class Result { |
|
1215 |
final int ec; |
|
1216 |
final String output; |
|
1217 |
||
1218 |
private Result(int ec, String output) { |
|
1219 |
this.ec = ec; |
|
1220 |
this.output = output; |
|
1221 |
} |
|
1222 |
Result assertSuccess() { |
|
1223 |
assertTrue(ec == 0, "Expected ec 0, got: ", ec, " , output [", output, "]"); |
|
1224 |
return this; |
|
1225 |
} |
|
1226 |
Result assertFailure() { |
|
1227 |
assertTrue(ec != 0, "Expected ec != 0, got:", ec, " , output [", output, "]"); |
|
1228 |
return this; |
|
1229 |
} |
|
1230 |
Result resultChecker(Consumer<Result> r) { r.accept(this); return this; } |
|
1231 |
} |
|
1232 |
||
1233 |
static void assertTrue(boolean cond, Object ... failedArgs) { |
|
1234 |
if (cond) |
|
1235 |
return; |
|
1236 |
StringBuilder sb = new StringBuilder(); |
|
1237 |
for (Object o : failedArgs) |
|
1238 |
sb.append(o); |
|
1239 |
org.testng.Assert.assertTrue(false, sb.toString()); |
|
1240 |
} |
|
1241 |
||
1242 |
// Standalone entry point. |
|
1243 |
public static void main(String[] args) throws Throwable { |
|
1244 |
Basic test = new Basic(); |
|
1245 |
test.compileModules(); |
|
1246 |
for (Method m : Basic.class.getDeclaredMethods()) { |
|
1247 |
if (m.getAnnotation(Test.class) != null) { |
|
1248 |
System.out.println("Invoking " + m.getName()); |
|
1249 |
m.invoke(test); |
|
1250 |
} |
|
1251 |
} |
|
1252 |
} |
|
1253 |
} |