Skip to content

Commit d6f1463

Browse files
author
Alexey Semenyuk
committed
8233332: Need to create exploded tests covering all forms of modules
Reviewed-by: herrick, almatvee
1 parent f2a0bf3 commit d6f1463

File tree

3 files changed

+64
-6
lines changed

3 files changed

+64
-6
lines changed

test/jdk/tools/jpackage/helpers/jdk/jpackage/test/HelloApp.java

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,14 @@
3434
import java.util.Map;
3535
import java.util.Optional;
3636
import java.util.concurrent.atomic.AtomicBoolean;
37+
import java.util.function.Predicate;
3738
import java.util.function.Supplier;
3839
import java.util.regex.Matcher;
3940
import java.util.regex.Pattern;
4041
import java.util.stream.Collectors;
42+
import java.util.zip.ZipEntry;
43+
import java.util.zip.ZipFile;
44+
import jdk.jpackage.test.Functional.ThrowingConsumer;
4145
import jdk.jpackage.test.Functional.ThrowingFunction;
4246
import jdk.jpackage.test.Functional.ThrowingSupplier;
4347

@@ -225,16 +229,15 @@ static void verifyOutputFile(Path outputFile, List<String> args,
225229
public static Path createBundle(JavaAppDesc appDesc, Path outputDir) {
226230
String jmodFileName = appDesc.jmodFileName();
227231
if (jmodFileName != null) {
228-
final Path jmodFilePath = outputDir.resolve(jmodFileName);
232+
final Path jmodPath = outputDir.resolve(jmodFileName);
229233
TKit.withTempDirectory("jmod-workdir", jmodWorkDir -> {
230234
var jarAppDesc = JavaAppDesc.parse(appDesc.toString())
231235
.setBundleFileName("tmp.jar");
232236
Path jarPath = createBundle(jarAppDesc, jmodWorkDir);
233237
Executor exec = new Executor()
234238
.setToolProvider(JavaTool.JMOD)
235239
.addArguments("create", "--class-path")
236-
.addArgument(jarPath)
237-
.addArgument(jmodFilePath);
240+
.addArgument(jarPath);
238241

239242
if (appDesc.isWithMainClass()) {
240243
exec.addArguments("--main-class", appDesc.className());
@@ -244,11 +247,50 @@ public static Path createBundle(JavaAppDesc appDesc, Path outputDir) {
244247
exec.addArguments("--module-version", appDesc.moduleVersion());
245248
}
246249

247-
Files.createDirectories(jmodFilePath.getParent());
250+
final Path jmodFilePath;
251+
if (appDesc.isExplodedModule()) {
252+
jmodFilePath = jmodWorkDir.resolve("tmp.jmod");
253+
exec.addArgument(jmodFilePath);
254+
TKit.deleteDirectoryRecursive(jmodPath);
255+
} else {
256+
jmodFilePath = jmodPath;
257+
exec.addArgument(jmodFilePath);
258+
TKit.deleteIfExists(jmodPath);
259+
}
260+
261+
Files.createDirectories(jmodPath.getParent());
248262
exec.execute();
263+
264+
if (appDesc.isExplodedModule()) {
265+
TKit.trace(String.format("Explode [%s] module file...",
266+
jmodFilePath.toAbsolutePath().normalize()));
267+
// Explode contents of the root `classes` directory of
268+
// temporary .jmod file
269+
final Path jmodRootDir = Path.of("classes");
270+
try (var archive = new ZipFile(jmodFilePath.toFile())) {
271+
archive.stream()
272+
.filter(Predicate.not(ZipEntry::isDirectory))
273+
.sequential().forEachOrdered(ThrowingConsumer.toConsumer(
274+
entry -> {
275+
try (var in = archive.getInputStream(entry)) {
276+
Path entryName = Path.of(entry.getName());
277+
if (entryName.startsWith(jmodRootDir)) {
278+
entryName = jmodRootDir.relativize(entryName);
279+
}
280+
final Path fileName = jmodPath.resolve(entryName);
281+
TKit.trace(String.format(
282+
"Save [%s] zip entry in [%s] file...",
283+
entry.getName(),
284+
fileName.toAbsolutePath().normalize()));
285+
Files.createDirectories(fileName.getParent());
286+
Files.copy(in, fileName);
287+
}
288+
}));
289+
}
290+
}
249291
});
250292

251-
return jmodFilePath;
293+
return jmodPath;
252294
}
253295

254296
final JavaAppDesc jarAppDesc;

test/jdk/tools/jpackage/helpers/jdk/jpackage/test/JavaAppDesc.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ public String jarFileName() {
8484
}
8585

8686
public String jmodFileName() {
87+
if (isExplodedModule()) {
88+
return bundleFileName;
89+
}
90+
8791
if (bundleFileName != null && bundleFileName.endsWith(".jmod")) {
8892
return bundleFileName;
8993
}
@@ -94,6 +98,10 @@ public boolean isWithBundleFileName() {
9498
return bundleFileName != null;
9599
}
96100

101+
public boolean isExplodedModule() {
102+
return bundleFileName != null && bundleFileName.endsWith(".ejmod");
103+
}
104+
97105
public String moduleVersion() {
98106
return moduleVersion;
99107
}
@@ -127,7 +135,7 @@ public String toString() {
127135
* Create Java application description form encoded string value.
128136
*
129137
* Syntax of encoded Java application description is
130-
* [(jar_file|jmods_file):][module_name/]qualified_class_name[!][@module_version].
138+
* [(jar_file|jmods_file|exploded_jmods_file):][module_name/]qualified_class_name[!][@module_version].
131139
*
132140
* E.g.: `duke.jar:com.other/com.other.foo.bar.Buz!@3.7` encodes modular
133141
* application. Module name is `com.other`. Main class is
@@ -140,6 +148,12 @@ public String toString() {
140148
* `com.another.One`. Application will be
141149
* compiled and packed in `bar.jmod` jmod file.
142150
*
151+
* E.g.: `bar.ejmod:com.another/com.another.One` encodes modular
152+
* application. Module name is `com.another`. Main class is
153+
* `com.another.One`. Application will be
154+
* compiled and packed in temporary jmod file that will be exploded in
155+
* `bar.ejmod` directory.
156+
*
143157
* E.g.: `Ciao` encodes non-modular `Ciao` class in the default package.
144158
* jar command will not put main class attribute in the jar file.
145159
* Default name will be picked for jar file - `hello.jar`.

test/jdk/tools/jpackage/share/jdk/jpackage/tests/BasicTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,8 @@ public void testNoName() {
226226
@Parameter("com.other/com.other.Hello")
227227
// Modular app in .jmod file
228228
@Parameter("hello.jmod:com.other/com.other.Hello")
229+
// Modular app in exploded .jmod file
230+
@Parameter("hello.ejmod:com.other/com.other.Hello")
229231
public void testApp(String javaAppDesc) {
230232
JavaAppDesc appDesc = JavaAppDesc.parse(javaAppDesc);
231233
JPackageCommand cmd = JPackageCommand.helloAppImage(appDesc);

0 commit comments

Comments
 (0)