Skip to content

Commit

Permalink
#12: added Android Studio IDE
Browse files Browse the repository at this point in the history
added Android Studio IdeToolCommandlet with first runIde implementation for Windows and Mac
added symlink creation
  • Loading branch information
jan-vcapgemini committed Apr 17, 2024
1 parent 6228841 commit 686f27a
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 0 deletions.
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 @@ -95,6 +96,7 @@ public CommandletManagerImpl(IdeContext context) {
add(new Jasypt(context));
add(new Docker(context));
add(new Sonar(context));
add(new AndroidStudio(context));
}

private void add(Commandlet commandlet) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
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.ProcessContext;
import com.devonfw.tools.ide.process.ProcessErrorHandling;
import com.devonfw.tools.ide.process.ProcessMode;
import com.devonfw.tools.ide.process.ProcessResult;
import com.devonfw.tools.ide.step.Step;
import com.devonfw.tools.ide.tool.ide.IdeToolCommandlet;
import com.devonfw.tools.ide.tool.ide.PluginDescriptor;
import com.devonfw.tools.ide.tool.java.Java;

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_SCRIPT = STUDIO + ".sh";

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

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

@Override
protected void runIde(String... args) {

install(true);

Step stepRun = this.context.newStep("Running Android Studio");
try {
ProcessResult result;
if (this.context.getSystemInfo().isMac()) {
result = runAndroidStudio(ProcessMode.BACKGROUND, CliArgument.prepend(args, "open", "-na", this.context.getWorkspacePath().toString()));
} else {
result = runAndroidStudio(ProcessMode.BACKGROUND, CliArgument.prepend(args, this.context.getWorkspacePath().toString()));
}
if (result.isSuccessful()) {
stepRun.success("Running Android Studio successfully.");
} else {
stepRun.isFailure();
}

} catch (Exception e) {
stepRun.error(e, "Failed to do something.");
} finally {
stepRun.end();
}

}

/**
* Runs AndroidStudio application.
*
* @param processMode - the {@link ProcessMode}.
* @param args the individual arguments to pass to Android Studio.
* @return the {@link ProcessResult}.
*/
protected ProcessResult runAndroidStudio(ProcessMode processMode, String... args) {

Path toolPath;
// TODO: Check if this can be optimized.
if (this.context.getSystemInfo().isMac()) {
toolPath = getToolBinPath().resolve(STUDIO);
if (!Files.exists(toolPath)) {
toolPath = getToolPath().resolve(STUDIO);
}
} else {
toolPath = getToolBinPath().resolve(STUDIO64_EXE);
}
ProcessContext pc = this.context.newProcess();
pc.executable(toolPath);
if (processMode == ProcessMode.DEFAULT_CAPTURE) {
pc.errorHandling(ProcessErrorHandling.ERROR);
}
pc.addArgs(args);

return pc.run(processMode);
}

@Override
public boolean install(boolean silent) {

getCommandlet(Java.class).install();
return super.install(silent);
}

@Override
protected void postInstall() {

super.postInstall();
Path scriptPath = getToolBinPath().resolve(STUDIO_SCRIPT);

// TODO: Check if this is still needed.
if (Files.exists(scriptPath)) {
FileAccess fileAccess = this.context.getFileAccess();
fileAccess.symlink(scriptPath, getToolBinPath().resolve(STUDIO), true);
}
}

@Override
public void installPlugin(PluginDescriptor plugin) {

}
}
1 change: 1 addition & 0 deletions cli/src/main/resources/nls/Ide.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ usage=Usage:
values=Values:
commandlets=Available commandlets:
options=Options:
cmd-android-studio=Tool commandlet for Android Studio (IDE).
cmd-aws=Tool commandlet for AWS CLI.
cmd-az=Tool commandlet for Azure CLI.
cmd---version=Print the version of IDEasy.
Expand Down
1 change: 1 addition & 0 deletions cli/src/main/resources/nls/Ide_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ usage=Verwendung:
values=Werte:
commandlets=Verfügbare Kommandos:
options=Optionen:
cmd-android-studio=Werkzeug Kommando für Android Studio (IDE).
cmd-aws=Werkzeug Kommando für AWS Kommandoschnittstelle.
cmd-az=Werkzeug Kommando für Azure Kommandoschnittstelle.
cmd---version=Gibt die Version von IDEasy aus.
Expand Down

0 comments on commit 686f27a

Please sign in to comment.