From 722b2295db3889eb72f59a47f3fe9f57b01afa8f Mon Sep 17 00:00:00 2001 From: jan-vcapgemini Date: Tue, 10 Sep 2024 12:19:56 +0200 Subject: [PATCH] #440: refactorings 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 --- .../ide/tool/androidstudio/AndroidStudio.java | 28 +++++++------ .../tool/ide/IdeaBasedIdeToolCommandlet.java | 30 ++++++++++++++ .../tools/ide/tool/intellij/Intellij.java | 39 ++++--------------- .../default/linux/bin/studio.sh | 0 .../Contents/MacOS/studio | 0 .../default/windows/bin/studio64.exe | 0 6 files changed, 54 insertions(+), 43 deletions(-) mode change 100644 => 100755 cli/src/test/resources/ide-projects/android-studio/repository/android-studio/android-studio/default/linux/bin/studio.sh mode change 100644 => 100755 cli/src/test/resources/ide-projects/android-studio/repository/android-studio/android-studio/default/mac/Android Studio Preview.app/Contents/MacOS/studio mode change 100644 => 100755 cli/src/test/resources/ide-projects/android-studio/repository/android-studio/android-studio/default/windows/bin/studio64.exe diff --git a/cli/src/main/java/com/devonfw/tools/ide/tool/androidstudio/AndroidStudio.java b/cli/src/main/java/com/devonfw/tools/ide/tool/androidstudio/AndroidStudio.java index 98779382e..8fc8d1ffe 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/tool/androidstudio/AndroidStudio.java +++ b/cli/src/main/java/com/devonfw/tools/ide/tool/androidstudio/AndroidStudio.java @@ -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; @@ -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) { @@ -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); + } } diff --git a/cli/src/main/java/com/devonfw/tools/ide/tool/ide/IdeaBasedIdeToolCommandlet.java b/cli/src/main/java/com/devonfw/tools/ide/tool/ide/IdeaBasedIdeToolCommandlet.java index 64f3de0fa..61b3d3f60 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/tool/ide/IdeaBasedIdeToolCommandlet.java +++ b/cli/src/main/java/com/devonfw/tools/ide/tool/ide/IdeaBasedIdeToolCommandlet.java @@ -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); + } } 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 282b17af9..c55255080 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,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; @@ -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; @@ -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); } } diff --git a/cli/src/test/resources/ide-projects/android-studio/repository/android-studio/android-studio/default/linux/bin/studio.sh b/cli/src/test/resources/ide-projects/android-studio/repository/android-studio/android-studio/default/linux/bin/studio.sh old mode 100644 new mode 100755 diff --git a/cli/src/test/resources/ide-projects/android-studio/repository/android-studio/android-studio/default/mac/Android Studio Preview.app/Contents/MacOS/studio b/cli/src/test/resources/ide-projects/android-studio/repository/android-studio/android-studio/default/mac/Android Studio Preview.app/Contents/MacOS/studio old mode 100644 new mode 100755 diff --git a/cli/src/test/resources/ide-projects/android-studio/repository/android-studio/android-studio/default/windows/bin/studio64.exe b/cli/src/test/resources/ide-projects/android-studio/repository/android-studio/android-studio/default/windows/bin/studio64.exe old mode 100644 new mode 100755