Skip to content

Commit 00a13a0

Browse files
committed
Make it possible to override the classpath
This is an internal implementation change so that plugins reusing this code can customize the classpath provider.
1 parent b07f2c7 commit 00a13a0

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

native-gradle-plugin/src/main/java/org/graalvm/buildtools/gradle/internal/NativeImageCommandLineProvider.java

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,8 @@ public List<String> asArguments() {
109109
List<String> cliArgs = new ArrayList<>(20);
110110

111111
cliArgs.add("-cp");
112-
if (classpathJar.isPresent()) {
113-
cliArgs.add(classpathJar.get().getAsFile().getAbsolutePath());
114-
} else {
115-
cliArgs.add(options.getClasspath().getAsPath());
116-
}
117-
112+
String classpathString = buildClasspathString(options);
113+
cliArgs.add(classpathString);
118114
appendBooleanOption(cliArgs, options.getDebug(), "-H:GenerateDebugInfo=1");
119115
appendBooleanOption(cliArgs, options.getFallback().map(NEGATE), "--no-fallback");
120116
appendBooleanOption(cliArgs, options.getVerbose(), "--verbose");
@@ -152,6 +148,26 @@ public List<String> asArguments() {
152148
return Collections.unmodifiableList(cliArgs);
153149
}
154150

151+
/**
152+
* Builds a classpath string from the given classpath elements.
153+
* This can be overridden by subclasses for special needs. For
154+
* example, the Micronaut plugin requires this because it's going
155+
* to build images within a docker container, which makes it so
156+
* that the paths in the options are invalid (they would be prefixed
157+
* by a Windows path).
158+
* @param options the native options
159+
* @return the classpath string
160+
*/
161+
protected String buildClasspathString(NativeImageOptions options) {
162+
String classpathString;
163+
if (classpathJar.isPresent()) {
164+
classpathString = classpathJar.get().getAsFile().getAbsolutePath();
165+
} else {
166+
classpathString = options.getClasspath().getAsPath();
167+
}
168+
return classpathString;
169+
}
170+
155171
private static void appendBooleanOption(List<String> cliArgs, Provider<Boolean> provider, String whenTrue) {
156172
if (provider.get()) {
157173
cliArgs.add(whenTrue);

0 commit comments

Comments
 (0)