Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it possible to override the classpath #200

Merged
merged 1 commit into from Feb 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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