Skip to content

Commit

Permalink
#339: refactor intellij and android-studio (#480)
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-vcapgemini authored Aug 1, 2024
1 parent 425723a commit d30694b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 56 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package com.devonfw.tools.ide.tool.androidstudio;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
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.io.FileAccess;
import com.devonfw.tools.ide.environment.EnvironmentVariables;
import com.devonfw.tools.ide.environment.EnvironmentVariablesType;
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 @@ -38,7 +36,6 @@ public AndroidStudio(IdeContext context) {
@Override
protected String getBinaryName() {

Path toolBinPath = getToolBinPath();
if (this.context.getSystemInfo().isWindows()) {
return STUDIO64_EXE;
} else if (this.context.getSystemInfo().isLinux()) {
Expand All @@ -58,35 +55,17 @@ public void runTool(ProcessMode processMode, VersionIdentifier toolVersion, Stri

}

@Override
public boolean install(boolean silent) {

return super.install(silent);
}

@Override
protected void postInstall() {

super.postInstall();
if (this.context.getSystemInfo().isMac()) {
setMacOsFilePermissions(getToolPath().resolve("Android Studio Preview.app").resolve("Contents").resolve("MacOS").resolve(STUDIO));
}
}

private void setMacOsFilePermissions(Path binaryFile) {

if (Files.exists(binaryFile)) {
FileAccess fileAccess = this.context.getFileAccess();
try {
fileAccess.makeExecutable(binaryFile);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
EnvironmentVariables envVars = this.context.getVariables().getByType(EnvironmentVariablesType.CONF);
envVars.set("STUDIO_PROPERTIES", this.context.getWorkspacePath().resolve("studio.properties").toString(), true);
envVars.save();
}

@Override
public void installPlugin(PluginDescriptor plugin) {

// TODO: needs to be implemented see: https://github.com/devonfw/IDEasy/issues/433
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
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;

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.FileAccess;
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 @@ -49,7 +45,6 @@ public void runTool(ProcessMode processMode, VersionIdentifier toolVersion, Stri
@Override
protected String getBinaryName() {

Path toolBinPath = getToolBinPath();
if (this.context.getSystemInfo().isWindows()) {
return IDEA64_EXE;
} else if (this.context.getSystemInfo().isLinux()) {
Expand All @@ -73,30 +68,6 @@ 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();
if (this.context.getSystemInfo().isMac()) {
setMacOsFilePermissions(getToolPath().resolve("IntelliJ IDEA" + generateMacEditionString() + ".app").resolve("Contents").resolve("MacOS").resolve(IDEA));
}
}

private String generateMacEditionString() {

String edition = "";
if (getConfiguredEdition().equals("intellij")) {
edition = " CE";
}
return edition;
}

private void setMacOsFilePermissions(Path binaryFile) {

if (Files.exists(binaryFile)) {
FileAccess fileAccess = this.context.getFileAccess();
try {
fileAccess.makeExecutable(binaryFile);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public void testAndroidStudioRun(String os) {
private void checkInstallation(IdeTestContext context) {
// commandlet - android-studio
assertThat(context.getSoftwarePath().resolve("android-studio/.ide.software.version")).exists().hasContent("2024.1.1.1");
assertThat(context.getVariables().get("STUDIO_PROPERTIES")).isEqualTo(context.getWorkspacePath().resolve("studio.properties").toString());
assertLogMessage(context, IdeLogLevel.SUCCESS, "Successfully installed android-studio in version 2024.1.1.1");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# here the STUDIO_PROPERTIES variable should be added by the test

0 comments on commit d30694b

Please sign in to comment.