Skip to content

Commit 5a32d9f

Browse files
committed
windows support added
1 parent 9716077 commit 5a32d9f

5 files changed

Lines changed: 22 additions & 5 deletions

File tree

src/main/java/airhacks/zb/hook/control/PostBuildHook.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import java.io.IOException;
44
import java.nio.file.Path;
5+
import java.util.List;
6+
import java.util.Locale;
57
import java.util.Optional;
68

79
import airhacks.zb.configuration.control.Configuration;
@@ -19,10 +21,21 @@ static Optional<String> configuredHook() {
1921
return Optional.of(hook);
2022
}
2123

24+
static boolean isWindows() {
25+
return System.getProperty("os.name", "").toLowerCase(Locale.ROOT).contains("win");
26+
}
27+
28+
static List<String> shellCommand(String command) {
29+
return isWindows()
30+
? List.of("cmd.exe", "/c", command)
31+
: List.of("sh", "-c", command);
32+
}
33+
2234
static void execute(String command, Path sourceDir, Path jarDir, String jarFileName) {
2335
Log.user("🪝 executing post-build hook: %s".formatted(command));
2436
try {
25-
var processBuilder = new ProcessBuilder("sh", "-c", command)
37+
var osDependentCommand = shellCommand(command);
38+
var processBuilder = new ProcessBuilder(osDependentCommand)
2639
.inheritIO()
2740
.directory(Path.of(".").toFile());
2841
var env = processBuilder.environment();

src/main/java/airhacks/zb/packer/control/Packer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ static String pathToJavaPackage(Path path) {
9696

9797
static void addEntry(JarOutputStream jos, Path relativePath, byte[] content) {
9898
try {
99-
var entry = new JarEntry(relativePath.toString());
99+
// JAR/ZIP entry names must use '/' regardless of the host OS separator
100+
var slashedPath = relativePath.toString().replace(File.separatorChar, '/');
101+
var entry = new JarEntry(slashedPath);
100102
jos.putNextEntry(entry);
101103
jos.write(content);
102104
jos.closeEntry();

src/main/resources/version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2026.06.25.01
1+
2026.06.26.01

src/main/sh/zb.bat

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@echo off
2+
java -jar "%~dp0zb.jar" %*

src/test/java/airhacks/zb/discovery/control/SourceLocationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ static void sourcesInTheRootDirectory() {
1313
var sourceDirectory = SourceLocator.detectSourceDirectory(Path.of("."));
1414
if (sourceDirectory.isEmpty())
1515
throw new AssertionError("expected source directory to be present");
16-
var actual = sourceDirectory.get().toString();
17-
if (!actual.endsWith("src/main/java"))
16+
var actual = sourceDirectory.get();
17+
if (!actual.endsWith(Path.of("src", "main", "java")))
1818
throw new AssertionError("expected path ending with src/main/java but got " + actual);
1919
}
2020
}

0 commit comments

Comments
 (0)