diff --git a/cli/src/main/java/com/devonfw/tools/ide/tool/intellij/Intellij.java b/cli/src/main/java/com/devonfw/tools/ide/tool/intellij/Intellij.java index c78a12968..869200d10 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/tool/intellij/Intellij.java +++ b/cli/src/main/java/com/devonfw/tools/ide/tool/intellij/Intellij.java @@ -1,5 +1,10 @@ package com.devonfw.tools.ide.tool.intellij; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.attribute.PosixFilePermission; +import java.nio.file.attribute.PosixFilePermissions; import java.util.Set; import com.devonfw.tools.ide.cli.CliArgument; @@ -7,6 +12,8 @@ import com.devonfw.tools.ide.context.IdeContext; import com.devonfw.tools.ide.environment.EnvironmentVariables; import com.devonfw.tools.ide.environment.EnvironmentVariablesType; +import com.devonfw.tools.ide.io.FileAccessImpl; +import com.devonfw.tools.ide.os.SystemInfoImpl; import com.devonfw.tools.ide.process.ProcessMode; import com.devonfw.tools.ide.tool.ide.IdeToolCommandlet; import com.devonfw.tools.ide.tool.ide.PluginDescriptor; @@ -42,18 +49,6 @@ public void runTool(ProcessMode processMode, VersionIdentifier toolVersion, Stri super.runTool(ProcessMode.BACKGROUND, toolVersion, args); } - @Override - protected String getBinaryName() { - - if (this.context.getSystemInfo().isWindows()) { - return IDEA64_EXE; - } else if (this.context.getSystemInfo().isLinux()) { - return IDEA_BASH_SCRIPT; - } else { - return IDEA; - } - } - @Override public boolean install(boolean silent) { @@ -68,6 +63,56 @@ protected void postInstall() { EnvironmentVariables envVars = this.context.getVariables().getByType(EnvironmentVariablesType.CONF); envVars.set("IDEA_PROPERTIES", this.context.getWorkspacePath().resolve("idea.properties").toString(), true); envVars.save(); + createStartupCommandScript(); + } + + private void createStartupCommandScript() { + this.context.getFileAccess().mkdirs(getToolPath().resolve("bin")); + Path bashFile; + String bashFileContentStart = "#!/usr/bin/env bash\n'"; + String bashFileContentEnd = "' $*"; + if (this.context.getSystemInfo().isMac()) { + try { + bashFile = Files.createFile(getToolBinPath().resolve(getName())); + Files.writeString(bashFile, + bashFileContentStart + getToolPath().resolve("IntelliJ IDEA CE.app").resolve("Contents").resolve("MacOS").resolve(IDEA) + bashFileContentEnd); + } catch (IOException e) { + throw new RuntimeException(e); + } + // Setting execute permissions is only required if executed on a real MacOS, won't work on Windows. + if (SystemInfoImpl.INSTANCE.isMac()) { + setMacOsFilePermissions(bashFile); + } + } else if (this.context.getSystemInfo().isWindows()) { + try { + bashFile = Files.createFile(getToolBinPath().resolve(getName())); + Files.writeString(bashFile, + bashFileContentStart + getToolBinPath().resolve(IDEA64_EXE) + bashFileContentEnd); + } catch (IOException e) { + throw new RuntimeException(e); + } + } else { + try { + bashFile = Files.createFile(getToolBinPath().resolve(getName())); + Files.writeString(bashFile, + bashFileContentStart + getToolBinPath().resolve(IDEA_BASH_SCRIPT) + bashFileContentEnd); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + } + + private void setMacOsFilePermissions(Path binaryFile) { + + if (Files.exists(binaryFile)) { + String permissionStr = FileAccessImpl.generatePermissionString(111); + Set permissions = PosixFilePermissions.fromString(permissionStr); + try { + Files.setPosixFilePermissions(binaryFile, permissions); + } catch (IOException e) { + throw new RuntimeException(e); + } + } } @Override