2
0
Fork 0
mirror of https://github.com/ethauvin/bld.git synced 2025-04-25 00:07:12 -07:00

Added support for Java 20-21 specific options

This commit is contained in:
Erik C. Thauvin 2024-08-04 00:39:12 -07:00
parent 750758993d
commit e32e17403f
Signed by: erik
GPG key ID: 776702A6A2DA330E
6 changed files with 83 additions and 3 deletions

View file

@ -49,6 +49,23 @@ public class JlinkOptions extends HashMap<String, String> {
return this;
}
/**
* Compression to use in compressing resources.
* <p>
* <b>Requires Java 21 or higher</b>.
* <p>
* Where {@link ZipCompression#ZIP_0 ZIP_0} provides no compression and {@link ZipCompression#ZIP_9 ZIP_9} provides
* the best compression.
* <p>Default is {@link ZipCompression#ZIP_6 ZIP_6}
*
* @param compression the {@link ZipCompression compression} level
* @return this map of options
*/
public JlinkOptions compress(ZipCompression compression) {
put("--compress", compression.level);
return this;
}
/**
* Enable compression of resources.
*

View file

@ -38,6 +38,24 @@ public class JmodOptions extends HashMap<String, String> {
return this;
}
/**
* Compression to use when creating the JMOD archive.
* <p>
* <b>Requires Java 20 or higher</b>.
* <p>
* Where {@link ZipCompression#ZIP_0 ZIP_0} provides no compression and {@link ZipCompression#ZIP_9 ZIP_9} provides the
* best compression.
* <p>
* 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
*

View file

@ -27,8 +27,10 @@ public class JpackageOptions extends HashMap<String, String> {
/**
* List of application launchers.
* <p>
* The main application launcher will be built from the command line options. Additional alternative launchers
* can be built using this option, and this option can be used to build multiple additional launchers.
* The main application launcher will be built from the command line options.
* <p>
* Additional alternative launchers can be built using this option, and this option can be used to build multiple
* additional launchers.
*
* @param launcher one or more {@link Launcher}
* @return this map of options
@ -58,6 +60,8 @@ public class JpackageOptions extends HashMap<String, String> {
/**
* List of paths to files and/or directories to add to the application payload.
* <p>
* <b>Requires Java 20 or higher</b>.
*
* @param additionalContent one or more path
* @return this map of options
@ -213,6 +217,8 @@ public class JpackageOptions extends HashMap<String, String> {
/**
* Request to create an installer that will register the main application launcher as a background service-type
* application.
* <p>
* <b>Requires Java 20 or higher</b>.
*
* @param launcherAsService {@code true} to register the launcher as a service; {@code false} otherwise
* @return this map of options

View file

@ -0,0 +1,30 @@
/**
* 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 <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
* @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;
}
}

View file

@ -97,8 +97,13 @@ 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());
if (Runtime.version().version().get(0) >= 21) {
options.compress(ZipCompression.ZIP_6);
} else {
options.compress(CompressionLevel.ZIP);
}
var jlink = new JlinkOperation().jlinkOptions(options);
assertDoesNotThrow(jlink::execute);

View file

@ -109,6 +109,10 @@ public class TestJmodOperation {
var mod = new File(tmpdir, "dev.mccue.tree.jmod");
var options = new JmodOptions().classpath("src/test/resources/jlink/build/jar/dev.mccue.tree.jar");
if (Runtime.version().version().get(0) >= 20) {
options.compress(ZipCompression.ZIP_9);
}
var jmod = new JmodOperation()
.operationMode(OperationMode.CREATE)
.jmodFile(mod.getAbsolutePath())