Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#12: Implement ToolCommandlet for Android Studio #299

Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
686f27a
#12: added Android Studio IDE
jan-vcapgemini Apr 17, 2024
79b8c84
#12: inversed OS checks
jan-vcapgemini Apr 18, 2024
fe6feae
adjusted .gitattributes
jan-vcapgemini Apr 22, 2024
136a20d
fixed line endings
jan-vcapgemini Apr 22, 2024
c252306
Merge branch 'main' into feature/12-implement-androidstudio-commandlet
jan-vcapgemini Apr 22, 2024
f4171e4
#12: added test + resources
jan-vcapgemini Apr 22, 2024
590a40d
Merge branch 'main' into feature/12-implement-androidstudio-commandlet
jan-vcapgemini Apr 22, 2024
46ce1f9
#12: removed symlink creation
jan-vcapgemini Apr 22, 2024
a32cb19
#12: cleanup
jan-vcapgemini Apr 23, 2024
4acb2e7
#12: added proper MacOS implementation
jan-vcapgemini Apr 23, 2024
c4f32a3
#12: fixed extractDmg
jan-vcapgemini Apr 24, 2024
e135fda
#12: cleanup and fix open
jan-vcapgemini Apr 24, 2024
d6ada24
Merge branch 'main' into feature/12-implement-androidstudio-commandlet
jan-vcapgemini Apr 25, 2024
0b48221
#12: cleanup and fixes
jan-vcapgemini Apr 25, 2024
eedf62a
Merge branch 'main' into feature/12-implement-androidstudio-commandlet
jan-vcapgemini Apr 29, 2024
8d26469
#12: implemented requested change
jan-vcapgemini Apr 29, 2024
2efa498
#12: applied optimizations
jan-vcapgemini Apr 30, 2024
170c834
#12: re-added file permission setter
jan-vcapgemini May 3, 2024
aae698d
#12: fixed tests
jan-vcapgemini May 3, 2024
b50ed40
Merge branch 'main' into feature/12-implement-androidstudio-commandlet
jan-vcapgemini May 3, 2024
6f14628
Merge branch 'main' into feature/12-implement-androidstudio-commandlet
jan-vcapgemini May 7, 2024
43520de
Merge branch 'main' into feature/12-implement-androidstudio-commandlet
jan-vcapgemini May 8, 2024
01f4fde
Merge branch 'main' into feature/12-implement-androidstudio-commandlet
hohwille May 17, 2024
434bb4e
Merge branch 'main' into feature/12-implement-androidstudio-commandlet
jan-vcapgemini May 21, 2024
09952d6
Merge branch 'feature/12-implement-androidstudio-commandlet' of https…
jan-vcapgemini May 21, 2024
63e9a24
Merge branch 'main' into feature/12-implement-androidstudio-commandlet
jan-vcapgemini May 28, 2024
b6396e3
#12: added documentation file
jan-vcapgemini May 30, 2024
2639f51
Merge branch 'main' into feature/12-implement-androidstudio-commandlet
jan-vcapgemini May 30, 2024
bffb920
Merge branch 'main' into feature/12-implement-androidstudio-commandlet
jan-vcapgemini Jul 3, 2024
92b0150
Merge branch 'main' into feature/12-implement-androidstudio-commandlet
jan-vcapgemini Jul 5, 2024
ef61d5d
#12: applied changes from intellij
jan-vcapgemini Jul 5, 2024
bf413aa
Merge branch 'main' into feature/12-implement-androidstudio-commandlet
jan-vcapgemini Jul 5, 2024
f387f3b
#12: added detailed help
jan-vcapgemini Jul 5, 2024
36bf78d
Merge branch 'main' into feature/12-implement-androidstudio-commandlet
jan-vcapgemini Jul 8, 2024
4382b43
#12: removed documentation
jan-vcapgemini Jul 8, 2024
0ecd27e
#25: added missing binary
jan-vcapgemini Jul 8, 2024
1c13eb8
Merge branch 'main' into feature/12-implement-androidstudio-commandlet
jan-vcapgemini Jul 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@
*.tgz binary
*.tar binary
*.bz2 binary
*.gz binary
*.gz binary

# special handling for test files
hohwille marked this conversation as resolved.
Show resolved Hide resolved
cli/src/test/resources/ide-projects/android-studio/repository/android-studio/android-studio/default/windows/bin/studio64.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 @@ -96,6 +97,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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ public void extractDmg(Path file, Path targetDir) {
if (appPath == null) {
throw new IllegalStateException("Failed to unpack DMG as no MacOS *.app was found in file " + file);
}
copy(appPath, targetDir);
copy(appPath, targetDir, FileCopyMode.COPY_TREE_OVERRIDE_TREE);
pc.addArgs("detach", "-force", mountPath);
pc.run();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
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.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 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 void runIde(String... args) {

install(true);

Step stepRun = this.context.newStep("Running Android Studio");
try {
ProcessResult result;
if (this.context.getSystemInfo().isMac()) {
Path studioPath = getToolPath().resolve("Contents").resolve("MacOS").resolve(STUDIO);
result = runAndroidStudio(ProcessMode.BACKGROUND,
CliArgument.prepend(args, "-na", studioPath.toString(), "--args", 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 run Android Studio.");
} finally {
stepRun.end();
}

}

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

Path toolPath;
if (this.context.getSystemInfo().isWindows()) {
toolPath = getToolBinPath().resolve(STUDIO64_EXE);
} else if (this.context.getSystemInfo().isLinux()) {
toolPath = getToolBinPath().resolve(STUDIO_BASH);
} else {
toolPath = Path.of("open");
}

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) {

return super.install(silent);
}

@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
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
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 -na " + commandlet.getToolPath().resolve("Contents/MacOS/studio") + " --args " + 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());
}

assertLogMessage(this.context, IdeLogLevel.SUCCESS, "Running Android Studio successfully.");
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
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 $*"
Loading