Skip to content

Commit

Permalink
Merge pull request #48 from ethauvin/main
Browse files Browse the repository at this point in the history
More cleanups to jlink, jmod & jpackage operations and options
  • Loading branch information
gbevin authored Aug 26, 2024
2 parents b8a63dd + c15a8d3 commit d68905b
Show file tree
Hide file tree
Showing 8 changed files with 384 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@

import rife.bld.operations.exceptions.ExitStatusException;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.Reader;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -67,25 +69,23 @@ public void execute() throws Exception {
/**
* Adds arguments to pass to the tool.
*
* @param arg one or more argument
* @param args tbe list of arguments
* @return this operation
*/
@SuppressWarnings("unchecked")
public T toolArgs(String... arg) {
toolArgs(List.of(arg));
@SuppressWarnings({"unchecked"})
public T toolArgs(List<String> args) {
toolArgs_.addAll(args);
return (T) this;
}

/**
* Adds arguments to pass to the tool.
*
* @param args the argument to add
* @param args one or more arguments
* @return this operation
*/
@SuppressWarnings({"unchecked", "UnusedReturnValue"})
public T toolArgs(List<String> args) {
toolArgs_.addAll(args);
return (T) this;
public T toolArgs(String... args) {
return toolArgs(List.of(args));
}

/**
Expand All @@ -97,15 +97,70 @@ public List<String> toolArgs() {
return toolArgs_;
}

/**
* Parses arguments to pass to the tool from the given files.
*
* @param files one or more files
* @return this operation instance
* @throws FileNotFoundException if a file cannot be found
*/
public T toolArgsFromFile(String... files) throws IOException {
return toolArgsFromFileStrings(List.of(files));
}

/**
* Parses arguments to pass to the tool from the given files.
*
* @param files one or more files
* @return this operation instance
* @throws FileNotFoundException if a file cannot be found
*/
public T toolArgsFromFile(Path... files) throws IOException {
return toolArgsFromFilePaths(List.of(files));
}

/**
* Parses arguments to pass to the tool from the given files.
*
* @param files the list of files
* @return this operation instance
* @throws FileNotFoundException if a file cannot be found
*/
@SuppressWarnings({"unchecked", "UnusedReturnValue"})
public T toolArgsFromFile(List<String> files) throws IOException {
public T toolArgsFromFile(List<File> files) throws IOException {
return toolArgsFromFileStrings(files.stream().map(File::getAbsolutePath).toList());
}

/**
* Parses arguments to pass to the tool from the given files.
*
* @param files one or more files
* @return this operation instance
* @throws FileNotFoundException if a file cannot be found
*/
public T toolArgsFromFile(File... files) throws IOException {
return toolArgsFromFile(List.of(files));
}

/**
* Parses arguments to pass to the tool from the given files.
*
* @param files the list of files
* @return this operation instance
* @throws FileNotFoundException if a file cannot be found
*/
public T toolArgsFromFilePaths(List<Path> files) throws IOException {
return toolArgsFromFileStrings(files.stream().map(Path::toFile).map(File::getAbsolutePath).toList());
}

/**
* Parses arguments to pass to the tool from the given files.
*
* @param files the list of files
* @return this operation instance
* @throws FileNotFoundException if a file cannot be found
*/
@SuppressWarnings({"unchecked"})
public T toolArgsFromFileStrings(List<String> files) throws IOException {
var args = new ArrayList<String>();

for (var file : files) {
Expand Down
69 changes: 54 additions & 15 deletions src/main/java/rife/bld/operations/JlinkOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.io.File;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

Expand All @@ -29,33 +28,63 @@ public JlinkOperation() {
/**
* Read options and/or mode from file(s).
*
* @param file one or more file
* @param files one or more files
* @return this operation instance
*/
public JlinkOperation cmdFiles(String... file) {
cmdFiles_.addAll(List.of(file));
public JlinkOperation cmdFiles(String... files) {
return cmdFilesStrings(List.of(files));
}

/**
* Read options and/or mode from file(s).
*
* @param files one or more files
* @return this operation instance
*/
public JlinkOperation cmdFiles(List<File> files) {
cmdFiles_.addAll(files.stream().map(File::getAbsolutePath).toList());
return this;
}

/**
* Read options and/or mode from file(s).
*
* @param file one or more file
* @param files one or more files
* @return this operation instance
*/
public JlinkOperation cmdFiles(File... files) {
return cmdFiles(List.of(files));
}

/**
* Read options and/or mode from file(s).
*
* @param files one or more files
* @return this operation instance
*/
public JlinkOperation cmdFiles(File... file) {
cmdFiles_.addAll(Arrays.stream(file).map(File::getAbsolutePath).toList());
public JlinkOperation cmdFiles(Path... files) {
return cmdFilesPaths(List.of(files));
}

/**
* Read options and/or mode from file(s).
*
* @param files one or more files
* @return this operation instance
*/
public JlinkOperation cmdFilesPaths(List<Path> files) {
cmdFiles_.addAll(files.stream().map(Path::toFile).map(File::getAbsolutePath).toList());
return this;
}

/**
* Read options and/or mode from file(s).
*
* @param file one or more file
* @param files one or more files
* @return this operation instance
*/
public JlinkOperation cmdFiles(Path... file) {
cmdFiles_.addAll(Arrays.stream(file).map(Path::toFile).map(File::getAbsolutePath).toList());
public JlinkOperation cmdFilesStrings(List<String> files) {
cmdFiles_.addAll(files);
return this;
}

Expand All @@ -69,19 +98,29 @@ public List<String> cmdFiles() {
}

/**
* Disable the plugin mentioned.
* Disable the plugin(s) mentioned.
*
* @param plugin the plugin name
* @param plugins the plugin name(s)
* @return this map of options
*/
public JlinkOperation disablePlugin(String... plugin) {
disabledPlugins_.addAll(List.of(plugin));
public JlinkOperation disablePlugin(List<String> plugins) {
disabledPlugins_.addAll(plugins);
return this;
}

/**
* Disable the plugin(s) mentioned.
*
* @param plugins the plugin name(s)
* @return this map of options
*/
public JlinkOperation disablePlugin(String... plugins) {
return disablePlugin(List.of(plugins));
}

@Override
public void execute() throws Exception {
toolArgsFromFile(cmdFiles_);
toolArgsFromFileStrings(cmdFiles_);
disabledPlugins_.forEach(plugin -> toolArgs("--disable-plugin", plugin));
toolArgs(jlinkOptions_);
super.execute();
Expand Down
51 changes: 41 additions & 10 deletions src/main/java/rife/bld/operations/JlinkOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import java.io.File;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;

/**
Expand All @@ -16,7 +16,7 @@
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
* @since 2.1.0
*/
public class JlinkOptions extends HashMap<String, String> {
public class JlinkOptions extends LinkedHashMap<String, String> {
/**
* All Modules Path.
*/
Expand All @@ -28,14 +28,26 @@ public class JlinkOptions extends HashMap<String, String> {
* <p>
* Module can also be {@link #ALL_MODULE_PATH}
*
* @param modules one or more module
* @param modules one or more modules
* @return this map of options
*/
public JlinkOptions addModules(String... modules) {
public JlinkOptions addModules(List<String> modules) {
put("--add-modules", String.join(",", modules));
return this;
}

/**
* Root modules to resolve in addition to the initial modules.
* <p>
* Module can also be {@link #ALL_MODULE_PATH}
*
* @param modules one or more modules
* @return this map of options
*/
public JlinkOptions addModules(String... modules) {
return addModules(List.of(modules));
}

/**
* Link in service provider modules and their dependencies.
*
Expand Down Expand Up @@ -141,13 +153,22 @@ public JlinkOptions launcher(String name, String module, String mainClass) {
/**
* Limit the universe of observable modules.
*
* @param module one or more module
* @param modules one or more modules
* @return this map of options
*/
public JlinkOptions limitModule(String... module) {
put("--limit-modules", String.join(",", module));
public JlinkOptions limitModule(List<String> modules) {
put("--limit-modules", String.join(",", modules));
return this;
}
/**
* Limit the universe of observable modules.
*
* @param modules one or more modules
* @return this map of options
*/
public JlinkOptions limitModule(String... modules) {
return limitModule(List.of(modules));
}

/**
* Module path.
Expand Down Expand Up @@ -304,14 +325,24 @@ public JlinkOptions stripNativeCommands(boolean stripNativeCommands) {
/**
* Suggest providers that implement the given service types from the module path.
*
* @param name one or more provider name
* @param names one or more provider names
* @return this map of options
*/
public JlinkOptions suggestProviders(String... name) {
put("--suggest-providers", String.join(",", name));
public JlinkOptions suggestProviders(List<String> names) {
put("--suggest-providers", String.join(",", names));
return this;
}

/**
* Suggest providers that implement the given service types from the module path.
*
* @param names one or more provider names
* @return this map of options
*/
public JlinkOptions suggestProviders(String... names) {
return suggestProviders(List.of(names));
}

public List<String> toList() {
var list = new ArrayList<String>();
forEach((k, v) -> {
Expand Down
Loading

0 comments on commit d68905b

Please sign in to comment.