Skip to content

Commit

Permalink
devonfw#505, devonfw#440: create startup script command
Browse files Browse the repository at this point in the history
added startup script command for Windows, Linux and MacOS (MacOS is not working yet)
removed getBinaryName
added WIP setMacOsFilePermissions
  • Loading branch information
jan-vcapgemini committed Aug 15, 2024
1 parent c8799e1 commit 6eb7ede
Showing 1 changed file with 57 additions and 12 deletions.
69 changes: 57 additions & 12 deletions cli/src/main/java/com/devonfw/tools/ide/tool/intellij/Intellij.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
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;
import com.devonfw.tools.ide.common.Tag;
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;
Expand Down Expand Up @@ -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) {

Expand All @@ -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<PosixFilePermission> permissions = PosixFilePermissions.fromString(permissionStr);
try {
Files.setPosixFilePermissions(binaryFile, permissions);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

@Override
Expand Down

0 comments on commit 6eb7ede

Please sign in to comment.