1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-25 07:57:12 -07:00

Changed fix for Gygwin/MinGW to handle Windows specifically.

Switched kotbaltw to bourne shell.
kobaltw.bat now created by default.
This commit is contained in:
Cedric Beust 2016-07-19 16:41:58 -07:00 committed by Erik C. Thauvin
parent 53ba3a4c0c
commit 6ec5aa8994
4 changed files with 34 additions and 11 deletions

2
dist/kobaltw vendored
View file

@ -1,2 +1,2 @@
#!/usr/bin/env bash
#!/usr/bin/env sh
java -jar $(dirname $0)/../kobalt/wrapper/kobalt-wrapper.jar $*

2
dist/kobaltw.bat vendored
View file

@ -1,2 +1,4 @@
@echo off
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
java -jar "%~dp0/../kobalt/wrapper/kobalt-wrapper.jar" %*

View file

@ -1,2 +1,2 @@
#!/usr/bin/env bash
#!/usr/bin/env sh
java -jar $(dirname $0)/kobalt/wrapper/kobalt-wrapper.jar $*

View file

@ -24,6 +24,7 @@ public class Main {
private static final String KOBALT_PROPERTIES = "kobalt.properties";
private static final String KOBALTW = "kobaltw";
private static final String KOBALTW_BAT = "kobaltw.bat";
private static final String KOBALT_WRAPPER_PROPERTIES = "kobalt-wrapper.properties";
private static final String PROPERTY_VERSION = "kobalt.version";
private static final String PROPERTY_DOWNLOAD_URL = "kobalt.downloadUrl";
@ -145,7 +146,7 @@ public class Main {
return System.getProperty("os.name").contains("Windows");
}
private static final String[] FILES = new String[] { KOBALTW, "kobalt/wrapper/" + FILE_NAME + "-wrapper.jar" };
private static final String[] FILES = new String[] { KOBALTW, KOBALTW_BAT, "kobalt/wrapper/" + FILE_NAME + "-wrapper.jar" };
private Path installDistribution() throws IOException {
String wrapperVersion;
@ -233,6 +234,8 @@ public class Main {
if (file.endsWith(KOBALTW)) {
generateKobaltW(Paths.get(KOBALTW));
} else if (file.endsWith(KOBALTW_BAT)) {
generateKobaltWBat(Paths.get(KOBALTW_BAT));
} else {
Path from = Paths.get(fromZipOutputDir, file);
try {
@ -270,19 +273,22 @@ public class Main {
//
// For kobaltw: try to generate it with the correct env shebang.
//
File envFile = new File("/bin/env");
if (!envFile.canExecute()) {
envFile = new File("/usr/bin/env");
String envPath;
if (isWindows()) {
envPath = "/usr/bin/env";
} else {
File envFile = new File("/bin/env");
if (!envFile.canExecute()) {
envFile = new File("/usr/bin/env");
}
envPath = envFile.getAbsolutePath();
}
String content = "";
String content = "#!" + envPath + " sh\n"
+ "java -jar $(dirname $0)/kobalt/wrapper/kobalt-wrapper.jar $*\n";
content = "#!" + envFile.getPath() + " bash\n";
log(2, " Generating " + KOBALTW + " with shebang.");
content += "java -jar $(dirname $0)/kobalt/wrapper/kobalt-wrapper.jar $*\n";
Files.write(filePath, content.getBytes());
if (!new File(KOBALTW).setExecutable(true)) {
@ -292,6 +298,21 @@ public class Main {
}
}
private void generateKobaltWBat(Path filePath) throws IOException {
if (isWindows() && filePath.toFile().exists()) {
log(2, " Windows detected, not overwriting " + filePath);
} else {
String content = "@echo off\r\n"
+ "set DIRNAME=%~dp0\r\n"
+ "if \"%DIRNAME%\" == \"\" set DIRNAME=.\r\n"
+ "java -jar \"%DIRNAME%/kobalt/wrapper/kobalt-wrapper.jar\" %*\r\n";
log(2, " Generating " + KOBALTW_BAT + " for Windows.");
Files.write(filePath, content.getBytes());
}
}
/**
* Extract the zip file in ~/.kobalt/wrapper/dist/$version
*/