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

More operation options cleanups

This commit is contained in:
Erik C. Thauvin 2024-08-03 09:51:09 -07:00
parent 91640e68ce
commit 1d615a501c
Signed by: erik
GPG key ID: 776702A6A2DA330E
7 changed files with 73 additions and 105 deletions

View file

@ -85,14 +85,4 @@ public class JlinkOperation extends AbstractToolProviderOperation<JlinkOperation
public List<String> fileOptions() {
return fileOptions_;
}
/**
* List available plugins.
*
* @return this operation instance
*/
public JlinkOperation listPlugins() {
toolArgs("--list-plugins");
return this;
}
}

View file

@ -15,7 +15,7 @@ import java.util.List;
* @since 2.0.2
*/
public class JlinkOptions extends HashMap<String, String> {
/**ranran
/**
* All Modules Path.
*/
@SuppressWarnings("unused")
@ -50,16 +50,12 @@ public class JlinkOptions extends HashMap<String, String> {
}
/**
* Compression to use in compressing resources.
* <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}
* 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<String, String> {
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<String, String> {
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<String, String> {
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<String, String> {
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<String, String> {
}
/**
* 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<String, String> {
}
}
/**
* 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;
}
}
}

View file

@ -38,21 +38,6 @@ public class JmodOptions extends HashMap<String, String> {
return this;
}
/**
* Compression to use when creating the JMOD archive.
* <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
*
@ -135,16 +120,6 @@ public class JmodOptions extends HashMap<String, String> {
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<String, String> {
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.
*

View file

@ -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 <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

@ -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<String, String>();
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);

View file

@ -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"))

View file

@ -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);