Skip to content

Commit

Permalink
#12: Implement ToolCommandlet for Android Studio (#299)
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-vcapgemini authored Jul 12, 2024
1 parent 295e130 commit 07e8cb2
Show file tree
Hide file tree
Showing 11 changed files with 180 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@

# special handling for test files
studio64.exe text
idea64.exe text
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.property.KeywordProperty;
import com.devonfw.tools.ide.property.Property;
import com.devonfw.tools.ide.tool.androidstudio.AndroidStudio;
import com.devonfw.tools.ide.tool.aws.Aws;
import com.devonfw.tools.ide.tool.az.Azure;
import com.devonfw.tools.ide.tool.cobigen.Cobigen;
Expand Down Expand Up @@ -105,6 +106,7 @@ public CommandletManagerImpl(IdeContext context) {
add(new Jasypt(context));
add(new Docker(context));
add(new Sonar(context));
add(new AndroidStudio(context));
add(new GraalVm(context));
add(new PgAdmin(context));
add(new LazyDocker(context));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package com.devonfw.tools.ide.tool.androidstudio;

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.process.ProcessMode;
import com.devonfw.tools.ide.tool.ide.IdeToolCommandlet;
import com.devonfw.tools.ide.tool.ide.PluginDescriptor;
import com.devonfw.tools.ide.version.VersionIdentifier;

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

/**
* {@link IdeToolCommandlet} for <a href="https://developer.android.com/studio">AndroidStudio</a>.
*/
public class AndroidStudio extends IdeToolCommandlet {

private static final String STUDIO = "studio";

private static final String STUDIO64_EXE = STUDIO + "64.exe";

private static final String STUDIO_BASH = STUDIO + ".sh";

/**
* The constructor.
*
* @param context the {@link IdeContext}.
*/
public AndroidStudio(IdeContext context) {

super(context, "android-studio", Set.of(Tag.ANDROID_STUDIO));
}

@Override
protected String getBinaryName() {

Path toolBinPath = getToolBinPath();
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) {

args = CliArgument.prepend(args, this.context.getWorkspacePath().toString());

install(true);
super.runTool(processMode, toolVersion, args);

}

@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);
}
}
}

@Override
public void installPlugin(PluginDescriptor plugin) {

}
}
2 changes: 2 additions & 0 deletions cli/src/main/resources/nls/Help.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
cmd.--version=Print the version of IDEasy.
cmd.--version.detail=TODO --version
cmd.android-studio=Tool commandlet for Android Studio (IDE).
cmd.android-studio.detail=The android-studio commandlet allows to install, configure, and launch Android Studio. To launch Android Studio for your current workspace and IDEasy installation, simply run: ide android-studio. Detailed documentation can be found at https://developer.android.com/studio/.
cmd.aws=Tool commandlet for AWS CLI.
cmd.aws.detail=The AWS Command Line Interface (AWS CLI) is an open source tool for managing AWS resources. Detailed documentation can be found at https://docs.aws.amazon.com/cli/
cmd.az=Tool commandlet for Azure CLI.
Expand Down
2 changes: 2 additions & 0 deletions cli/src/main/resources/nls/Help_de.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
cmd.--version=Gibt die Version von IDEasy aus.
cmd.--version.detail=TODO DE --version
cmd.android-studio=Werkzeug Kommando für Android Studio (IDE).
cmd.android-studio.detail=Das android-studio Kommando ermöglicht die Installation, Konfiguration und den Start von Android Studio. Um Android Studio für Ihren aktuellen Arbeitsbereich und die IDEasy-Installation zu starten, führen Sie einfach: 'ide android-studio' aus. Detaillierte Dokumentation finden Sie unter https://developer.android.com/studio/.
cmd.aws=Werkzeug Kommando für AWS Kommandoschnittstelle.
cmd.aws.detail=Das AWS Command Line Interface (AWS CLI) ist ein Open-Source-Werkzeug zur Verwaltung von AWS Ressourcen. Detaillierte Dokumentation ist zu finden unter https://docs.aws.amazon.com/cli/
cmd.az=Werkzeug Kommando für Azure Kommandoschnittstelle.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.devonfw.tools.ide.tool.androidstudio;

import com.devonfw.tools.ide.context.AbstractIdeContextTest;
import com.devonfw.tools.ide.context.IdeTestContext;
import com.devonfw.tools.ide.log.IdeLogLevel;
import com.devonfw.tools.ide.os.SystemInfo;
import com.devonfw.tools.ide.os.SystemInfoMock;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

/**
* Test class for {@link AndroidStudio Android Studio IDE} tests.
*/
public class AndroidStudioTest extends AbstractIdeContextTest {

private static final String ANDROID_STUDIO = "android-studio";

private final IdeTestContext context = newContext(ANDROID_STUDIO);

/**
* Tests if {@link AndroidStudio Android Studio IDE} can be installed.
*
* @param os String of the OS to use.
*/
@ParameterizedTest
@ValueSource(strings = { "windows", "mac", "linux" })
public void testAndroidStudioInstall(String os) {
// arrange
SystemInfo systemInfo = SystemInfoMock.of(os);
this.context.setSystemInfo(systemInfo);
AndroidStudio commandlet = new AndroidStudio(this.context);

// act
commandlet.install();

// assert
checkInstallation(this.context);
}

/**
* Tests if {@link AndroidStudio Android Studio IDE} can be run.
*
* @param os String of the OS to use.
*/
@ParameterizedTest
@ValueSource(strings = { "windows", "mac", "linux" })
public void testAndroidStudioRun(String os) {
// arrange
SystemInfo systemInfo = SystemInfoMock.of(os);
this.context.setSystemInfo(systemInfo);
AndroidStudio commandlet = new AndroidStudio(this.context);

// act
commandlet.run();

// assert
if (this.context.getSystemInfo().isMac()) {
assertLogMessage(this.context, IdeLogLevel.INFO, ANDROID_STUDIO + " mac " + this.context.getWorkspacePath());
} else if (this.context.getSystemInfo().isLinux()) {
assertLogMessage(this.context, IdeLogLevel.INFO, ANDROID_STUDIO + " linux " + this.context.getWorkspacePath());
} else if (this.context.getSystemInfo().isWindows()) {
assertLogMessage(this.context, IdeLogLevel.INFO, ANDROID_STUDIO + " windows " + this.context.getWorkspacePath());
}

checkInstallation(this.context);
}

private void checkInstallation(IdeTestContext context) {
// commandlet - android-studio
assertThat(context.getSoftwarePath().resolve("android-studio/.ide.software.version")).exists().hasContent("2024.1.1.1");
assertLogMessage(context, IdeLogLevel.SUCCESS, "Successfully installed android-studio in version 2024.1.1.1");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ANDROID-STUDIO_VERSION=2024.1.1.1
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
echo "android-studio linux $*"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
echo "android-studio mac $*"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
echo "android-studio windows $*"

0 comments on commit 07e8cb2

Please sign in to comment.