Skip to content

Commit 231d9d9

Browse files
committed
[GR-24334] Fix native-image-maven-plugin for Windows.
PullRequest: graal/6528
2 parents fdd84a0 + 451279e commit 231d9d9

File tree

2 files changed

+6
-9
lines changed
  • substratevm/src

2 files changed

+6
-9
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/OS.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ public String asPackageName() {
5252
return name().toLowerCase();
5353
}
5454

55+
public boolean isCurrent() {
56+
return getCurrent() == this;
57+
}
58+
5559
private static OS findCurrent() {
5660
final String name = System.getProperty("os.name");
5761
if (name.equals("Linux")) {

substratevm/src/native-image-maven-plugin/src/main/java/com/oracle/substratevm/NativeImageMojo.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public void execute() throws MojoExecutionException {
175175
addClasspath(project.getArtifact());
176176
String classpathStr = classpath.stream().map(Path::toString).collect(Collectors.joining(File.pathSeparator));
177177

178-
Path nativeImageExecutable = getMojoJavaHome().resolve("bin").resolve(withExeSuffix("native-image"));
178+
Path nativeImageExecutable = getMojoJavaHome().resolve("bin").resolve("native-image" + (OS.WINDOWS.isCurrent() ? ".cmd" : ""));
179179
if (Files.isExecutable(nativeImageExecutable)) {
180180
String nativeImageExecutableVersion = "Unknown";
181181
Process versionCheckProcess = null;
@@ -268,13 +268,6 @@ public void execute() throws MojoExecutionException {
268268
}
269269
}
270270

271-
private String withExeSuffix(String basename) {
272-
if (OS.getCurrent() == OS.WINDOWS) {
273-
return basename + ".exe";
274-
}
275-
return basename;
276-
}
277-
278271
private void addClasspath(Artifact artifact) throws MojoExecutionException {
279272
if (!"jar".equals(artifact.getType())) {
280273
getLog().warn("Ignoring non-jar type ImageClasspath Entry " + artifact);
@@ -421,7 +414,7 @@ public Path getJavaHome() {
421414

422415
@Override
423416
public Path getJavaExecutable() {
424-
return getJavaHome().resolve("bin").resolve(withExeSuffix("java"));
417+
return getJavaHome().resolve("bin").resolve("java" + (OS.WINDOWS.isCurrent() ? ".exe" : ""));
425418
}
426419

427420
private List<Path> getSelectedArtifactPaths(String groupId, String... artifactIds) {

0 commit comments

Comments
 (0)