-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added Android Studio IdeToolCommandlet with first runIde implementation for Windows and Mac added symlink creation
- Loading branch information
1 parent
6228841
commit 686f27a
Showing
4 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
cli/src/main/java/com/devonfw/tools/ide/tool/androidstudio/AndroidStudio.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters