Skip to content

Commit

Permalink
#832: fixed tools not starting on Windows (#839)
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-vcapgemini authored Dec 5, 2024
1 parent 387b579 commit 4ca0d07
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,9 @@ public ProcessResult run(ProcessMode processMode) {

return result;
} finally {
process.destroy();
if (!processMode.isBackground()) {
process.destroy();
}
}
} catch (CliProcessException | IllegalStateException e) {
// these exceptions are thrown from performLogOnError and we do not want to wrap them (see #593)
Expand Down
15 changes: 0 additions & 15 deletions cli/src/main/java/com/devonfw/tools/ide/tool/ToolCommandlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -471,21 +471,6 @@ protected void createStartScript(Path targetDir, String binary, boolean backgrou
}
assert (Files.exists(binFolder));
}
if (this.context.getSystemInfo().isWindows()) {
Path batchFile = binFolder.resolve(getName() + ".bat");
String batchFileContentStart = "@echo off\nsetlocal\nset SCRIPT_DIR=%~dp0\nstart \"\" \"%SCRIPT_DIR%";
String batchFileContentEnd = "\" ";
if (background) {
batchFileContentEnd += " %*";
}
try {
Files.writeString(batchFile, batchFileContentStart + binary + batchFileContentEnd);
} catch (IOException e) {
throw new RuntimeException(e);
}
assert (Files.exists(batchFile));
context.getFileAccess().makeExecutable(batchFile);
}
Path bashFile = binFolder.resolve(getName());
String bashFileContentStart = "#!/usr/bin/env bash\n\"$(dirname \"$0\")/";
String bashFileContentEnd = "\" $@";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.devonfw.tools.ide.tool.androidstudio;

import java.nio.file.Path;
import java.util.Set;

import com.devonfw.tools.ide.common.Tag;
Expand All @@ -15,6 +14,12 @@
*/
public class AndroidStudio extends IdeaBasedIdeToolCommandlet {

private static final String STUDIO = "studio";

private static final String STUDIO64_EXE = STUDIO + "64.exe";

private static final String STUDIO_BASH_SCRIPT = STUDIO + ".sh";

/**
* The constructor.
*
Expand All @@ -26,24 +31,21 @@ public AndroidStudio(IdeContext context) {
}

@Override
protected void setEnvironment(EnvironmentContext environmentContext, ToolInstallation toolInstallation, boolean extraInstallation) {
protected String getBinaryName() {

super.setEnvironment(environmentContext, toolInstallation, extraInstallation);
environmentContext.withEnvVar("STUDIO_PROPERTIES", this.context.getWorkspacePath().resolve("studio.properties").toString());
}

@Override
protected void postExtract(Path extractedDir) {

super.postExtract(extractedDir);
String binaryName;
if (this.context.getSystemInfo().isWindows()) {
binaryName = "studio64.exe";
return STUDIO64_EXE;
} else if (this.context.getSystemInfo().isMac()) {
binaryName = "studio";
return STUDIO;
} else {
binaryName = "studio.sh";
return STUDIO_BASH_SCRIPT;
}
createStartScript(extractedDir, binaryName, true);
}

@Override
protected void setEnvironment(EnvironmentContext environmentContext, ToolInstallation toolInstallation, boolean extraInstallation) {

super.setEnvironment(environmentContext, toolInstallation, extraInstallation);
environmentContext.withEnvVar("STUDIO_PROPERTIES", this.context.getWorkspacePath().resolve("studio.properties").toString());
}
}
28 changes: 12 additions & 16 deletions cli/src/main/java/com/devonfw/tools/ide/tool/intellij/Intellij.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.devonfw.tools.ide.tool.intellij;

import java.nio.file.Path;
import java.util.Set;

import com.devonfw.tools.ide.common.Tag;
Expand Down Expand Up @@ -32,6 +31,18 @@ public Intellij(IdeContext context) {
super(context, "intellij", Set.of(Tag.INTELLIJ));
}

@Override
protected String getBinaryName() {

if (this.context.getSystemInfo().isWindows()) {
return IDEA64_EXE;
} else if (this.context.getSystemInfo().isMac()) {
return IDEA;
} else {
return IDEA_BASH_SCRIPT;
}
}

@Override
protected void setEnvironment(EnvironmentContext environmentContext, ToolInstallation toolInstallation, boolean extraInstallation) {

Expand All @@ -47,19 +58,4 @@ protected void installDependencies() {
getCommandlet(Java.class).install();
}

@Override
protected void postExtract(Path extractedDir) {

super.postExtract(extractedDir);
String binaryName;
if (this.context.getSystemInfo().isWindows()) {
binaryName = IDEA64_EXE;
} else if (this.context.getSystemInfo().isMac()) {
binaryName = IDEA;
} else {
binaryName = IDEA_BASH_SCRIPT;
}
createStartScript(extractedDir, binaryName, true);
}

}
27 changes: 14 additions & 13 deletions cli/src/main/java/com/devonfw/tools/ide/tool/tomcat/Tomcat.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
*/
public class Tomcat extends LocalToolCommandlet {

private static final String CATALINA = "catalina";
private static final String CATALINA_BAT = CATALINA + ".bat";
private static final String CATALINA_BASH_SCRIPT = CATALINA + ".sh";

/**
* The constructor.
*
Expand All @@ -39,6 +43,16 @@ public Tomcat(IdeContext context) {
super(context, "tomcat", Set.of(Tag.JAVA));
}

@Override
protected String getBinaryName() {

if (this.context.getSystemInfo().isWindows()) {
return CATALINA_BAT;
} else {
return CATALINA_BASH_SCRIPT;
}
}

@Override
public ProcessResult runTool(ProcessMode processMode, GenericVersionRange toolVersion, ProcessErrorHandling errorHandling, String... args) {

Expand All @@ -63,19 +77,6 @@ protected void setEnvironment(EnvironmentContext environmentContext, ToolInstall
environmentContext.withEnvVar("CATALINA_HOME", toolInstallation.linkDir().toString());
}

@Override
protected void postExtract(Path extractedDir) {

super.postExtract(extractedDir);
String binaryName;
if (this.context.getSystemInfo().isWindows()) {
binaryName = "catalina.bat";
} else {
binaryName = "catalina.sh";
}
createStartScript(extractedDir, binaryName, false);
}

private void printTomcatPort() {

String portNumber = findTomcatPort();
Expand Down
2 changes: 1 addition & 1 deletion cli/src/main/resources/nls/Help_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ cmd.help=Zeigt diese Hilfe an.
cmd.help.detail=Die Hilfe-Details eines Kommandos können mit dem Befehl "ide help <commandlet>" ausgegeben werden.
cmd.install=Installiert das selektierte Werkzeug.
cmd.install-plugin=Installiert die selektierte Erweiterung für das selektierte Werkzeug.
cmd.install-plugin.detail=Erweiterung können nur für Werkzeuge installiert werden die diese unterstützen. Erweiterungen müssen in den Projekteinstellungen definiert sein um zur Installation verfügbar zu sein. Falls eine gewünschte Erweiterung nicht verfügbar ist, bitte den ide-admin kontaktieren.
cmd.install-plugin.detail=Erweiterung können nur für Werkzeuge installiert werden, die diese unterstützen. Erweiterungen müssen in den Projekteinstellungen definiert sein um zur Installation verfügbar zu sein. Falls eine gewünschte Erweiterung nicht verfügbar ist, bitte den ide-admin kontaktieren.
cmd.install.detail=Die Liste an zur Installation verfügbaren Werkzeugen können mit dem Befehl "ide help" ausgegeben werden.
cmd.intellij=Werkzeug Kommando für Intellij (IDE)
cmd.intellij.detail=IntelliJ ist eine beliebte Java-Entwicklungsumgebung, von JetBrains entwickelt. Detaillierte Dokumentation ist zu finden unter https://www.jetbrains.com/idea/documentation/
Expand Down

0 comments on commit 4ca0d07

Please sign in to comment.