Skip to content

Commit 87f080b

Browse files
Add jlinkOptions configuration
1 parent 5e92071 commit 87f080b

File tree

5 files changed

+104
-39
lines changed

5 files changed

+104
-39
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ The same command line options for `jlink` can be set:
149149
- `bindServices`: Adds the option to bind services. Values: false (default) or true
150150
- `ignoreSigningInformation`: Adds the option to ignore signing information. Values: false (default) or true
151151
- `jlinkVerbose`: Adds the verbose option. Values: false (default) or true
152+
- `jlinkOptions`: A list of options passed to the jlink executable.
152153
- `launcher`: Adds a launcher script with the given name.
153154
- If `options` are defined, these will be passed to the launcher script as vm options.
154155
- If `commandLineArgs` are defined, these will be passed to the launcher script as command line arguments.

src/main/java/org/openjfx/JavaFXBaseMojo.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
import java.util.Map;
6363
import java.util.Objects;
6464
import java.util.Properties;
65+
import java.util.regex.Pattern;
6566
import java.util.stream.Collectors;
6667
import java.util.stream.Stream;
6768

@@ -456,6 +457,42 @@ String createMainClassString(String mainClass, JavaModuleDescriptor moduleDescri
456457
return mainClass;
457458
}
458459

460+
List<String> splitComplexArgumentString(String argumentString) {
461+
char[] strArr = argumentString.trim().toCharArray();
462+
463+
List<String> splitedArgs = new ArrayList<>();
464+
StringBuilder sb = new StringBuilder();
465+
466+
char expectedSeparator = ' ';
467+
for (int i = 0; i < strArr.length; i++) {
468+
char item = strArr[i];
469+
470+
if (item == expectedSeparator
471+
|| (expectedSeparator == ' ' && Pattern.matches("\\s", String.valueOf(item))) ) {
472+
473+
if (expectedSeparator == '"' || expectedSeparator == '\'') {
474+
sb.append(item);
475+
expectedSeparator = ' ';
476+
} else if (expectedSeparator == ' ' && sb.length() > 0) {
477+
splitedArgs.add(sb.toString());
478+
sb.delete(0, sb.length());
479+
}
480+
} else {
481+
if (expectedSeparator == ' ' && (item == '"' || item == '\'')) {
482+
expectedSeparator = item;
483+
}
484+
485+
sb.append(item);
486+
}
487+
488+
if (i == strArr.length - 1 && sb.length() > 0) {
489+
splitedArgs.add(sb.toString());
490+
}
491+
}
492+
493+
return splitedArgs;
494+
}
495+
459496
private static String findExecutable(final String executable, final List<String> paths) {
460497
File f = null;
461498
search: for (final String path : paths) {

src/main/java/org/openjfx/JavaFXJLinkMojo.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019 Gluon
2+
* Copyright 2019, 2020, Gluon
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -43,6 +43,7 @@
4343
import java.nio.file.Path;
4444
import java.nio.file.Paths;
4545
import java.util.ArrayList;
46+
import java.util.Collection;
4647
import java.util.Comparator;
4748
import java.util.List;
4849
import java.util.Map;
@@ -151,6 +152,12 @@ public class JavaFXJLinkMojo extends JavaFXBaseMojo {
151152
@Component(role = Archiver.class, hint = "zip")
152153
private ZipArchiver zipArchiver;
153154

155+
/**
156+
* A list of options passed to the jlink {@code executable}.
157+
*/
158+
@Parameter
159+
List<?> jlinkOptions;
160+
154161
public void execute() throws MojoExecutionException {
155162
if (skip) {
156163
getLog().info( "skipping execute as per configuration" );
@@ -166,7 +173,7 @@ public void execute() throws MojoExecutionException {
166173
}
167174

168175
handleWorkingDirectory();
169-
176+
170177
Map<String, String> enviro = handleSystemEnvVariables();
171178
CommandLine commandLine = getExecutablePath(jlinkExecutable, enviro, workingDirectory);
172179

@@ -182,7 +189,6 @@ public void execute() throws MojoExecutionException {
182189
}
183190

184191
try {
185-
186192
List<String> commandArguments = createCommandArguments();
187193
String[] args = commandArguments.toArray(new String[commandArguments.size()]);
188194
commandLine.addArguments(args, false);
@@ -290,6 +296,17 @@ private void patchLauncherScript(String launcherFilename) throws IOException {
290296
private List<String> createCommandArguments() throws MojoExecutionException, MojoFailureException {
291297
List<String> commandArguments = new ArrayList<>();
292298
preparePaths(getParent(Paths.get(jlinkExecutable), 2));
299+
300+
if (jlinkOptions != null) {
301+
jlinkOptions.stream()
302+
.filter(Objects::nonNull)
303+
.filter(String.class::isInstance)
304+
.map(String.class::cast)
305+
.map(this::splitComplexArgumentString)
306+
.flatMap(Collection::stream)
307+
.forEach(commandArguments::add);
308+
}
309+
293310
if (modulepathElements != null && !modulepathElements.isEmpty()) {
294311
commandArguments.add(" --module-path");
295312
String modulePath = StringUtils.join(modulepathElements.iterator(), File.pathSeparator);

src/main/java/org/openjfx/JavaFXRunMojo.java

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -181,42 +181,6 @@ private String createAddModulesString(JavaModuleDescriptor moduleDescriptor, Map
181181
return moduleDescriptor.name();
182182
}
183183

184-
private List<String> splitComplexArgumentString(String argumentString) {
185-
char[] strArr = argumentString.trim().toCharArray();
186-
187-
List<String> splitedArgs = new ArrayList<>();
188-
StringBuilder sb = new StringBuilder();
189-
190-
char expectedSeparator = ' ';
191-
for (int i = 0; i < strArr.length; i++) {
192-
char item = strArr[i];
193-
194-
if (item == expectedSeparator
195-
|| (expectedSeparator == ' ' && Pattern.matches("\\s", String.valueOf(item))) ) {
196-
197-
if (expectedSeparator == '"' || expectedSeparator == '\'') {
198-
sb.append(item);
199-
expectedSeparator = ' ';
200-
} else if (expectedSeparator == ' ' && sb.length() > 0) {
201-
splitedArgs.add(sb.toString());
202-
sb.delete(0, sb.length());
203-
}
204-
} else {
205-
if (expectedSeparator == ' ' && (item == '"' || item == '\'')) {
206-
expectedSeparator = item;
207-
}
208-
209-
sb.append(item);
210-
}
211-
212-
if (i == strArr.length - 1 && sb.length() > 0) {
213-
splitedArgs.add(sb.toString());
214-
}
215-
}
216-
217-
return splitedArgs;
218-
}
219-
220184
// for tests
221185

222186
void setExecutable(String executable) {

src/test/java/org/openjfx/JavaFXBaseMojoTest.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright 2019, 2020, Gluon
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package org.openjfx;
217

318
import org.codehaus.plexus.languages.java.jpms.JavaModuleDescriptor;
@@ -97,6 +112,37 @@ public void invalidPathWithDepthTest() {
97112
Assert.assertNull(JavaFXBaseMojo.getParent(Paths.get("/some-invalid-path"), 2));
98113
}
99114

115+
@Test
116+
public void testSplitComplexArgumentString() {
117+
String option = "param1 " +
118+
"param2 \n " +
119+
"param3\n" +
120+
"param4=\"/path/to/my file.log\" " +
121+
"'var\"foo var\"foo' " +
122+
"'var\"foo' " +
123+
"'var\"foo' " +
124+
"\"foo'var foo'var\" " +
125+
"\"foo'var\" " +
126+
"\"foo'var\"";
127+
128+
String expected = "START," +
129+
"param1," +
130+
"param2," +
131+
"param3," +
132+
"param4=\"/path/to/my file.log\"," +
133+
"'var\"foo var\"foo'," +
134+
"'var\"foo'," +
135+
"'var\"foo'," +
136+
"\"foo'var foo'var\"," +
137+
"\"foo'var\"," +
138+
"\"foo'var\"";
139+
140+
String splitedOption = new JavaFXRunMojo().splitComplexArgumentStringAdapter(option)
141+
.stream().reduce("START", (s1, s2) -> s1 + "," + s2);
142+
143+
Assert.assertEquals(expected, splitedOption);
144+
}
145+
100146
@AfterClass
101147
public static void destroy() throws IOException {
102148
Files.walk(path.getParent())

0 commit comments

Comments
 (0)