Skip to content

Commit 4793ab8

Browse files
ali-incefawind
andauthored
fix: problems on windows (palantir#772)
* fix: java needs .exe suffix on windows * fix: classpath entries should use the correct separator * Add changelog Co-authored-by: Fabian Windheuser <fwindheuser@palantir.com>
1 parent c0b86d2 commit 4793ab8

4 files changed

Lines changed: 14 additions & 3 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
type: fix
2+
fix:
3+
description: Fix problems on windows
4+
links:
5+
- https://github.com/palantir/palantir-java-format/pull/772

‎idea-plugin/src/main/java/com/palantir/javaformat/intellij/FormatterProvider.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.intellij.openapi.projectRoots.JdkUtil;
2424
import com.intellij.openapi.projectRoots.Sdk;
2525
import com.intellij.openapi.roots.ProjectRootManager;
26+
import com.intellij.openapi.util.SystemInfo;
2627
import com.palantir.javaformat.bootstrap.BootstrappingFormatterService;
2728
import com.palantir.javaformat.java.FormatterService;
2829
import com.palantir.logsafe.Preconditions;
@@ -109,7 +110,7 @@ private static Path getJdkPath(Project project) {
109110
return getProjectJdk(project)
110111
.map(Sdk::getHomePath)
111112
.map(Path::of)
112-
.map(sdkHome -> sdkHome.resolve("bin").resolve("java"))
113+
.map(sdkHome -> sdkHome.resolve("bin").resolve("java" + (SystemInfo.isWindows ? ".exe" : "")))
113114
.filter(Files::exists)
114115
.orElseThrow(() -> new IllegalStateException("Could not determine jdk path for project " + project));
115116
}

‎palantir-java-format-jdk-bootstrap/src/main/java/com/palantir/javaformat/bootstrap/BootstrappingFormatterService.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ default List<String> toArgs() {
127127
"-cp",
128128
implementationClasspath().stream()
129129
.map(path -> path.toAbsolutePath().toString())
130-
.collect(Collectors.joining(":")))
130+
.collect(Collectors.joining(System.getProperty("path.separator"))))
131131
.add(FORMATTER_MAIN_CLASS);
132132

133133
if (!characterRanges().isEmpty()) {

‎palantir-java-format-jdk-bootstrap/src/test/java/com/palantir/javaformat/bootstrap/BootstrappingFormatterServiceTest.java‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.nio.file.Files;
2828
import java.nio.file.Path;
2929
import java.util.List;
30+
import java.util.Locale;
3031
import java.util.stream.Collectors;
3132
import org.junit.jupiter.api.Test;
3233

@@ -96,6 +97,10 @@ private static List<Path> getClasspath() {
9697

9798
private static Path javaBinPath() {
9899
String javaHome = Preconditions.checkNotNull(System.getProperty("java.home"), "java.home property not set");
99-
return Path.of(javaHome).resolve("bin").resolve("java");
100+
return Path.of(javaHome).resolve("bin").resolve("java" + (isWindows() ? ".exe" : ""));
101+
}
102+
103+
private static boolean isWindows() {
104+
return System.getProperty("os.name").toLowerCase(Locale.ROOT).startsWith("windows");
100105
}
101106
}

0 commit comments

Comments
 (0)