Skip to content

Commit

Permalink
Merge pull request #25 from jperedadnr/master
Browse files Browse the repository at this point in the history
#22 Remove vm options from jlink command line
  • Loading branch information
José Pereda committed Jun 21, 2019
2 parents 25a0b89 + 39f9f3f commit af589f2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ The same command line options for `jlink` can be set:
- `bindServices`: Adds the option to bind services. Values: false (default) or true
- `ignoreSigningInformation`: Adds the option to ignore signing information. Values: false (default) or true
- `jlinkVerbose`: Adds the verbose option. Values: false (default) or true
- `launcher`: Adds a launcher script with the given name
- `launcher`: Adds a launcher script with the given name.
- If `options` are defined, these will be passed to the launcher script as vm options.
- If `commandLineArgs` are defined, these will be passed to the launcher script as command line arguments.
- `jlinkImageName`: The name of the folder with the resulting runtime image
- `jlinkZipName`: When set, creates a zip of the resulting runtime image
- `jlinkExecutable`: The `jlink` executable. It can be a full path or the name of the executable, if it is in the PATH.
Expand Down
44 changes: 36 additions & 8 deletions src/main/java/org/openjfx/JavaFXJLinkMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

@Mojo(name = "jlink", requiresDependencyResolution = ResolutionScope.RUNTIME)
public class JavaFXJLinkMojo extends JavaFXBaseMojo {
Expand Down Expand Up @@ -181,6 +183,40 @@ public void execute() throws MojoExecutionException {
throw new MojoExecutionException(message);
}

if (launcher != null && ! launcher.isEmpty()) {
Path launcherPath = Paths.get(builddir.getAbsolutePath(), jlinkImageName, "bin", launcher);
if (options != null) {
String optionsString = options.stream()
.filter(Objects::nonNull)
.filter(String.class::isInstance)
.map(String.class::cast)
.collect(Collectors.joining(" "));

// Add vm options to launcher script
List<String> lines = Files.lines(launcherPath)
.map(line -> {
if ("JLINK_VM_OPTIONS=".equals(line)) {
return "JLINK_VM_OPTIONS=\"" + optionsString + "\"";
}
return line;
})
.collect(Collectors.toList());
Files.write(launcherPath, lines);
}
if (commandlineArgs != null) {
// Add options to launcher script
List<String> lines = Files.lines(launcherPath)
.map(line -> {
if (line.endsWith("$@")) {
return line.replace("$@", commandlineArgs + " $@");
}
return line;
})
.collect(Collectors.toList());
Files.write(launcherPath, lines);
}
}

if (jlinkZipName != null && ! jlinkZipName.isEmpty()) {
getLog().debug("Creating zip of runtime image");
File createZipArchiveFromImage = createZipArchiveFromImage();
Expand All @@ -204,14 +240,6 @@ public void execute() throws MojoExecutionException {
private void handleArguments(List<String> commandArguments) throws MojoExecutionException, MojoFailureException {
preparePaths();

if (options != null) {
options.stream()
.filter(Objects::nonNull)
.filter(String.class::isInstance)
.map(String.class::cast)
.forEach(commandArguments::add);
}

if (modulepathElements != null && !modulepathElements.isEmpty()) {
commandArguments.add(" --module-path");
String modulePath = StringUtils.join(modulepathElements.iterator(), File.pathSeparator);
Expand Down

0 comments on commit af589f2

Please sign in to comment.