diff --git a/src/main/java/rife/bld/operations/JlinkOperation.java b/src/main/java/rife/bld/operations/JlinkOperation.java index c87aa92..0bf7994 100644 --- a/src/main/java/rife/bld/operations/JlinkOperation.java +++ b/src/main/java/rife/bld/operations/JlinkOperation.java @@ -85,14 +85,4 @@ public class JlinkOperation extends AbstractToolProviderOperation fileOptions() { return fileOptions_; } - - /** - * List available plugins. - * - * @return this operation instance - */ - public JlinkOperation listPlugins() { - toolArgs("--list-plugins"); - return this; - } } diff --git a/src/main/java/rife/bld/operations/JlinkOptions.java b/src/main/java/rife/bld/operations/JlinkOptions.java index 89de52e..869c8b6 100644 --- a/src/main/java/rife/bld/operations/JlinkOptions.java +++ b/src/main/java/rife/bld/operations/JlinkOptions.java @@ -15,7 +15,7 @@ import java.util.List; * @since 2.0.2 */ public class JlinkOptions extends HashMap { - /**ranran + /** * All Modules Path. */ @SuppressWarnings("unused") @@ -50,16 +50,12 @@ public class JlinkOptions extends HashMap { } /** - * Compression to use in compressing resources. - *

- * Where {@link ZipCompression#ZIP_0 ZIP_0} provides no compression and {@link ZipCompression#ZIP_9 ZIP_9} provides - * the best compression. - *

Default is {@link ZipCompression#ZIP_6 ZIP_6} + * Enable compression of resources. * - * @param compression the {@link ZipCompression compression} level + * @param compression the {@link CompressionLevel compression} level * @return this map of options */ - public JlinkOptions compress(ZipCompression compression) { + public JlinkOptions compress(CompressionLevel compression) { put("--compress", compression.level); return this; } @@ -106,21 +102,6 @@ public class JlinkOptions extends HashMap { return this; } - /** - * Exclude include header files. - * - * @param noHeaderFiles {@code true} to exclude header files, {@code false} otherwise - * @return this map of options - */ - public JlinkOptions noHeaderFiles(boolean noHeaderFiles) { - if (noHeaderFiles) { - put("--no-header-files"); - } else { - remove("--no-header-files"); - } - return this; - } - /** * Add a launcher command of the given name for the module and the main class. * @@ -159,6 +140,21 @@ public class JlinkOptions extends HashMap { return this; } + /** + * Exclude include header files. + * + * @param noHeaderFiles {@code true} to exclude header files, {@code false} otherwise + * @return this map of options + */ + public JlinkOptions noHeaderFiles(boolean noHeaderFiles) { + if (noHeaderFiles) { + put("--no-header-files"); + } else { + remove("--no-header-files"); + } + return this; + } + /** * Exclude man pages. * @@ -174,16 +170,6 @@ public class JlinkOptions extends HashMap { return this; } - /** - * Associates {@code null} with the specified key in this map. If the map previously contained a mapping for the - * key, the old value is replaced. - * - * @param key key with which the specified value is to be associated - */ - public void put(String key) { - put(key, null); - } - /** * Location of output path. * @@ -195,6 +181,16 @@ public class JlinkOptions extends HashMap { return this; } + /** + * Associates {@code null} with the specified key in this map. If the map previously contained a mapping for the + * key, the old value is replaced. + * + * @param key key with which the specified value is to be associated + */ + public void put(String key) { + put(key, null); + } + /** * Suggest providers that implement the given service types from the module path. * @@ -222,7 +218,7 @@ public class JlinkOptions extends HashMap { } /** - * Strip the native commands. + * Strip native commands. * * @param stripNativeCommands {@code true} to strip, {@code false} otherwise * @return this map of options @@ -286,4 +282,27 @@ public class JlinkOptions extends HashMap { } } + /** + * Resources compression levels. + */ + public enum CompressionLevel { + /** + * Level 0: No compression + */ + NO_COMPRESSION("0"), + /** + * Level 1: Constant string sharing + */ + CONSTANT_STRING_SHARING("1"), + /** + * Level 2: ZIP + */ + ZIP("2"); + + public final String level; + + CompressionLevel(String level) { + this.level = level; + } + } } diff --git a/src/main/java/rife/bld/operations/JmodOptions.java b/src/main/java/rife/bld/operations/JmodOptions.java index b564595..9fa7878 100644 --- a/src/main/java/rife/bld/operations/JmodOptions.java +++ b/src/main/java/rife/bld/operations/JmodOptions.java @@ -38,21 +38,6 @@ public class JmodOptions extends HashMap { return this; } - /** - * Compression to use when creating the JMOD archive. - *

- * Where {@link ZipCompression#ZIP_0 ZIP_0} provides no compression and {@link ZipCompression#ZIP_9 ZIP_9} provides the - * best compression. - *

Default is {@link ZipCompression#ZIP_6 ZIP_6} - * - * @param compression the {@link ZipCompression compression} level - * @return this map of options - */ - public JmodOptions compress(ZipCompression compression) { - put("--compress", compression.level); - return this; - } - /** * Location of user-editable config files * @@ -135,16 +120,6 @@ public class JmodOptions extends HashMap { return this; } - /** - * Associates {@code null} with the specified key in this map. If the map previously contained a mapping for the - * key, the old value is replaced. - * - * @param key key with which the specified value is to be associated - */ - public void put(String key) { - put(key, null); - } - /** * Compute and record hashes to tie a packaged module with modules matching the given regular expression pattern and * depending upon it directly or indirectly. The hashes are recorded in the JMOD file being created, or a JMOD file @@ -235,6 +210,16 @@ public class JmodOptions extends HashMap { return this; } + /** + * Associates {@code null} with the specified key in this map. If the map previously contained a mapping for the + * key, the old value is replaced. + * + * @param key key with which the specified value is to be associated + */ + public void put(String key) { + put(key, null); + } + /** * Target platform. * diff --git a/src/main/java/rife/bld/operations/ZipCompression.java b/src/main/java/rife/bld/operations/ZipCompression.java deleted file mode 100644 index 4d5722a..0000000 --- a/src/main/java/rife/bld/operations/ZipCompression.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Copyright 2024 Erik C. Thauvin (https://erik.thauvin.net/) - * Licensed under the Apache License, Version 2.0 (the "License") - */ -package rife.bld.operations; - -/** - * The zip compression levels for jlink and jmod. - * - * @author Erik C. Thauvin - * @since 2.0.2 - */ -public enum ZipCompression { - ZIP_0("zip-0"), - ZIP_1("zip-1"), - ZIP_2("zip-2"), - ZIP_3("zip-3"), - ZIP_4("zip-4"), - ZIP_5("zip-5"), - ZIP_6("zip-6"), - ZIP_7("zip-7"), - ZIP_8("zip-8"), - ZIP_9("zip-9"); - - public final String level; - - ZipCompression(String level) { - this.level = level; - } -} diff --git a/src/test/java/rife/bld/operations/TestJlinkOperation.java b/src/test/java/rife/bld/operations/TestJlinkOperation.java index cee13ff..ff76635 100644 --- a/src/test/java/rife/bld/operations/TestJlinkOperation.java +++ b/src/test/java/rife/bld/operations/TestJlinkOperation.java @@ -17,6 +17,7 @@ import java.nio.file.Files; import java.util.HashMap; import static org.junit.jupiter.api.Assertions.*; +import static rife.bld.operations.JlinkOptions.CompressionLevel; public class TestJlinkOperation { private final ByteArrayOutputStream outputStreamCaptor = new ByteArrayOutputStream(); @@ -32,7 +33,7 @@ public class TestJlinkOperation { var args = new HashMap(); args.put("--add-modules", "module-1,module-2"); args.put("--bind-services", null); - args.put("--compress", "zip-6"); + args.put("--compress", "2"); args.put("--endian", "big"); args.put("--ignore-signing-information", null); args.put("--launcher", "name=module/mainclass"); @@ -49,7 +50,7 @@ public class TestJlinkOperation { var options = new JlinkOptions() .addModules(args.get("--add-modules").split(",")) .bindServices(true) - .compress(ZipCompression.ZIP_6) + .compress(CompressionLevel.ZIP) .endian(JlinkOptions.Endian.BIG) .ignoreSigningInformation(true) .launcher("name", "module", "mainclass") @@ -80,7 +81,7 @@ public class TestJlinkOperation { var jlink = new JlinkOperation() .disablePlugin("vm") .disablePlugin("system-modules") - .listPlugins(); + .toolArgs("--list-plugins"); assertDoesNotThrow(jlink::execute); var out = outputStreamCaptor.toString(); assertTrue(out.contains("List of available plugins:"), out); @@ -96,6 +97,7 @@ public class TestJlinkOperation { .modulePath("src/test/resources/jlink/build/jmod") .addModules("dev.mccue.tree") .launcher("tree", "dev.mccue.tree", "dev.mccue.tree.Tree") + .compress(CompressionLevel.NO_COMPRESSION) .output(output.getAbsolutePath()); var jlink = new JlinkOperation().jlinkOptions(options); diff --git a/src/test/java/rife/bld/operations/TestJmodOperation.java b/src/test/java/rife/bld/operations/TestJmodOperation.java index 390ef20..8b6c98e 100644 --- a/src/test/java/rife/bld/operations/TestJmodOperation.java +++ b/src/test/java/rife/bld/operations/TestJmodOperation.java @@ -56,7 +56,6 @@ public class TestJmodOperation { var options = new JmodOptions() .classpath(args.get("--class-path")) .cmds(args.get("--cmds")) - .compress(ZipCompression.ZIP_5) .config(args.get("--config")) .date(ZonedDateTime.of(1997, 8, 29, 2, 14, 0, 0, ZoneId.of("America/Los_Angeles"))) .dir(args.get("--dir")) diff --git a/src/test/java/rife/bld/operations/TestJpackageOperation.java b/src/test/java/rife/bld/operations/TestJpackageOperation.java index 0b28c80..82c4aaf 100644 --- a/src/test/java/rife/bld/operations/TestJpackageOperation.java +++ b/src/test/java/rife/bld/operations/TestJpackageOperation.java @@ -166,14 +166,17 @@ public class TestJpackageOperation { void testCreatePackage() throws Exception { var tmpdir = Files.createTempDirectory("bld-jpackage-test").toFile(); try { + var jlinkOptions = new JlinkOptions() + .compress(JlinkOptions.CompressionLevel.ZIP) + .stripNativeCommands(true); var options = new JpackageOptions() .input("lib/bld") .name("bld") .mainJar("bld-wrapper.jar") .javaOptions("--enable-preview") .dest(tmpdir.getAbsolutePath()) - .verbose(true); - + .verbose(true) + .jlinkOptions(jlinkOptions); var os = System.getProperty("os.version"); if (os.endsWith("MANJARO")) { options.type(PackageType.DEB);