Skip to content

Commit

Permalink
devonfw#440: refactorings
Browse files Browse the repository at this point in the history
refactored create start script code into createStartScript method
added createStartScript to android-studio
added execute permissions to android-studio test files
removed getBinaryName from android-studio
added postExtract to android-studio
  • Loading branch information
jan-vcapgemini committed Sep 10, 2024
1 parent 7bc2933 commit 722b229
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.devonfw.tools.ide.tool.androidstudio;

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

import com.devonfw.tools.ide.cli.CliArgument;
Expand Down Expand Up @@ -33,18 +34,6 @@ public AndroidStudio(IdeContext context) {
super(context, "android-studio", Set.of(Tag.ANDROID_STUDIO));
}

@Override
protected String getBinaryName() {

if (this.context.getSystemInfo().isWindows()) {
return STUDIO64_EXE;
} else if (this.context.getSystemInfo().isLinux()) {
return STUDIO_BASH;
} else {
return STUDIO;
}
}

@Override
public void runTool(ProcessMode processMode, VersionIdentifier toolVersion, String... args) {

Expand All @@ -63,4 +52,19 @@ protected void postInstall() {
envVars.set("STUDIO_PROPERTIES", this.context.getWorkspacePath().resolve("studio.properties").toString(), true);
envVars.save();
}

@Override
protected void postExtract(Path extractedDir) {

super.postExtract(extractedDir);
String binaryName;
if (this.context.getSystemInfo().isWindows()) {
binaryName = STUDIO64_EXE;
} else if (this.context.getSystemInfo().isMac()) {
binaryName = STUDIO;
} else {
binaryName = STUDIO_BASH;
}
createStartScript(extractedDir, binaryName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,34 @@ private String getFileExtensionFromUrl(String urlString) throws IOException {
default -> "";
};
}

/**
* Creates a start script for the tool using the tool name.
*
* @param extractedDir path to extracted tool directory.
* @param binaryName name of the binary to add to start script.
*/
protected void createStartScript(Path extractedDir, String binaryName) {
Path binFolder = extractedDir.resolve("bin");
if (!Files.exists(binFolder)) {
if (this.context.getSystemInfo().isMac()) {
MacOsHelper macOsHelper = getMacOsHelper();
Path appDir = macOsHelper.findAppDir(extractedDir);
binFolder = macOsHelper.findLinkDir(appDir, binaryName);
} else {
binFolder = extractedDir;
}
assert (Files.exists(binFolder));
}
Path bashFile = binFolder.resolve(getName());
String bashFileContentStart = "#!/usr/bin/env bash\n\"$(dirname $0)/";
String bashFileContentEnd = "\" $*";
try {
Files.writeString(bashFile, bashFileContentStart + binaryName + bashFileContentEnd);
} catch (IOException e) {
throw new RuntimeException(e);
}
assert (Files.exists(bashFile));
context.getFileAccess().makeExecutable(bashFile);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.devonfw.tools.ide.tool.intellij;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Set;

Expand All @@ -10,7 +8,6 @@
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.os.MacOsHelper;
import com.devonfw.tools.ide.process.ProcessMode;
import com.devonfw.tools.ide.tool.ide.IdeToolCommandlet;
import com.devonfw.tools.ide.tool.ide.IdeaBasedIdeToolCommandlet;
Expand Down Expand Up @@ -66,35 +63,15 @@ protected void postInstall() {
protected void postExtract(Path extractedDir) {

super.postExtract(extractedDir);
Path binFolder = extractedDir.resolve("bin");
if (!Files.exists(binFolder)) {
if (this.context.getSystemInfo().isMac()) {
MacOsHelper macOsHelper = getMacOsHelper();
Path appDir = macOsHelper.findAppDir(extractedDir);
binFolder = macOsHelper.findLinkDir(appDir, IDEA);
} else {
binFolder = extractedDir;
}
assert (Files.exists(binFolder));
String binaryName;
if (this.context.getSystemInfo().isWindows()) {
binaryName = IDEA64_EXE;
} else if (this.context.getSystemInfo().isMac()) {
binaryName = IDEA;
} else {
binaryName = IDEA_BASH_SCRIPT;
}
Path bashFile = binFolder.resolve(getName());
String bashFileContentStart = "#!/usr/bin/env bash\n\"$(dirname $0)/";
String bashFileContentEnd = "\" $*";
try {
String OsType;
if (this.context.getSystemInfo().isWindows()) {
OsType = IDEA64_EXE;
} else if (this.context.getSystemInfo().isMac()) {
OsType = IDEA;
} else {
OsType = IDEA_BASH_SCRIPT;
}
Files.writeString(bashFile, bashFileContentStart + OsType + bashFileContentEnd);
} catch (IOException e) {
throw new RuntimeException(e);
}
assert (Files.exists(bashFile));
context.getFileAccess().makeExecutable(bashFile);
createStartScript(extractedDir, binaryName);
}

}
Empty file.
Empty file.
Empty file.

0 comments on commit 722b229

Please sign in to comment.