Skip to content

Commit

Permalink
Make it possible to override the classpath
Browse files Browse the repository at this point in the history
This is an internal implementation change so that plugins reusing
this code can customize the classpath provider.
  • Loading branch information
melix committed Feb 4, 2022
1 parent b07f2c7 commit 00a13a0
Showing 1 changed file with 22 additions and 6 deletions.
Expand Up @@ -109,12 +109,8 @@ public List<String> asArguments() {
List<String> cliArgs = new ArrayList<>(20);

cliArgs.add("-cp");
if (classpathJar.isPresent()) {
cliArgs.add(classpathJar.get().getAsFile().getAbsolutePath());
} else {
cliArgs.add(options.getClasspath().getAsPath());
}

String classpathString = buildClasspathString(options);
cliArgs.add(classpathString);
appendBooleanOption(cliArgs, options.getDebug(), "-H:GenerateDebugInfo=1");
appendBooleanOption(cliArgs, options.getFallback().map(NEGATE), "--no-fallback");
appendBooleanOption(cliArgs, options.getVerbose(), "--verbose");
Expand Down Expand Up @@ -152,6 +148,26 @@ public List<String> asArguments() {
return Collections.unmodifiableList(cliArgs);
}

/**
* Builds a classpath string from the given classpath elements.
* This can be overridden by subclasses for special needs. For
* example, the Micronaut plugin requires this because it's going
* to build images within a docker container, which makes it so
* that the paths in the options are invalid (they would be prefixed
* by a Windows path).
* @param options the native options
* @return the classpath string
*/
protected String buildClasspathString(NativeImageOptions options) {
String classpathString;
if (classpathJar.isPresent()) {
classpathString = classpathJar.get().getAsFile().getAbsolutePath();
} else {
classpathString = options.getClasspath().getAsPath();
}
return classpathString;
}

private static void appendBooleanOption(List<String> cliArgs, Provider<Boolean> provider, String whenTrue) {
if (provider.get()) {
cliArgs.add(whenTrue);
Expand Down

0 comments on commit 00a13a0

Please sign in to comment.