Skip to content

Commit

Permalink
Use shell scripts for launching tools
Browse files Browse the repository at this point in the history
  • Loading branch information
sciencewhiz committed Sep 14, 2024
1 parent be9df73 commit bb81e1d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private void runToolWindows() {
private void runToolUnix() {
Directory toolsFolder = this.toolsFolder.get();
String toolName = this.toolName.get();
File outputFile = toolsFolder.file(toolName + ".py").getAsFile();
File outputFile = toolsFolder.file(toolName + ".sh").getAsFile();
getProject().exec(spec -> {
spec.setExecutable(outputFile.getAbsolutePath());
spec.args(getArgumentPath(toolName.toLowerCase()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ private static void extractScriptWindows(Directory toolsFolder, String toolName)
}

private static void extractScriptUnix(Project project, Directory toolsFolder, String toolName) {
File outputFile = toolsFolder.file(toolName + ".py").getAsFile();
try (InputStream it = ToolInstallTask.class.getResourceAsStream("/ScriptBase.py")) {
File outputFile = toolsFolder.file(toolName + ".sh").getAsFile();
try (InputStream it = ToolInstallTask.class.getResourceAsStream("/ScriptBase.sh")) {
ResourceGroovyMethods.setText(outputFile, IOGroovyMethods.getText(it));
} catch (IOException e) {
throw new RuntimeException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private void runToolWindows() {
private void runToolUnix() {
Directory toolsFolder = this.toolsFolder.get();
String toolName = this.toolName.get();
File outputFile = toolsFolder.file(toolName + ".py").getAsFile();
File outputFile = toolsFolder.file(toolName + ".sh").getAsFile();
getProject().exec(spec -> {
spec.setExecutable(outputFile.getAbsolutePath());
});
Expand Down
23 changes: 23 additions & 0 deletions src/main/resources/ScriptBase.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh

SCRIPT_PATH="$(dirname "$(realpath -s "$0")")"
SCRIPT_NAME="$(basename "$(realpath -s "$0")")"
SCRIPT_BASE="$(basename -s .sh "$SCRIPT_NAME")"
JAR_NAME="$SCRIPT_BASE.jar"
JDK_DIR="$(realpath "$SCRIPT_PATH/../jdk/bin/java")"

echo "SCRIPT_PATH: $SCRIPT_PATH"
echo "SCRIPT_NAME: $SCRIPT_NAME"
echo "SCRIPT_BASE: $SCRIPT_BASE"
echo "JAR_NAME: $JAR_NAME"
echo "JDK_DIR: $JDK_DIR"

if ! "$JDK_DIR" -jar "$JAR_NAME"; then
echo "ERROR launching $SCRIPT_BASE using $JDK_DIR"
if ! "$JAVA_HOME/bin/java" -jar "$JAR_NAME"; then
echo "ERROR launching $SCRIPT_BASE using $JAVA_HOME"
if ! java -jar "$JAR_NAME"; then
echo "ERROR launching $SCRIPT_BASE using java from path: $PATH"
fi
fi
fi

0 comments on commit bb81e1d

Please sign in to comment.