Skip to content

Commit

Permalink
devonfw#356: eclipse install plugin without extra window popping up, …
Browse files Browse the repository at this point in the history
…generic step logging for plugins
  • Loading branch information
hohwille committed Sep 25, 2024
1 parent f80dd25 commit 809e192
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void run() {
String plugin = this.plugin.getValue();

if (commandlet instanceof PluginBasedCommandlet cmd) {
cmd.installPlugin(cmd.getPlugin(plugin));
cmd.installPlugin(cmd.getPlugin(plugin), this.context.getCurrentStep());
} else {
context.warning("Tool {} does not support installation of plugins.", commandlet.getName());
}
Expand Down
49 changes: 9 additions & 40 deletions cli/src/main/java/com/devonfw/tools/ide/tool/eclipse/Eclipse.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
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.java.Java;
import com.devonfw.tools.ide.tool.plugin.ToolPluginDescriptor;
Expand All @@ -38,10 +39,11 @@ public Eclipse(IdeContext context) {
@Override
protected void configureToolBinary(ProcessContext pc, ProcessMode processMode, ProcessErrorHandling errorHandling) {

if (processMode == ProcessMode.DEFAULT_CAPTURE) {

if ((processMode == ProcessMode.DEFAULT_CAPTURE) && this.context.getSystemInfo().isWindows()) {
pc.executable(Path.of("eclipsec"));
} else {
super.configureToolBinary(pc, processMode, errorHandling);
}
super.configureToolBinary(pc, processMode, errorHandling);
}

@Override
Expand Down Expand Up @@ -71,44 +73,11 @@ protected void installDependencies() {
getCommandlet(Java.class).install();
}

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

Path toolPath = Path.of(getBinaryName());
ProcessContext pc = this.context.newProcess();
if (processMode == ProcessMode.DEFAULT_CAPTURE) {
pc.errorHandling(ProcessErrorHandling.LOG_ERROR);
}
pc.executable(toolPath);
Path configurationPath = getPluginsInstallationPath().resolve("configuration");
this.context.getFileAccess().mkdirs(configurationPath);
pc.addArg("-data").addArg(this.context.getWorkspacePath());
pc.addArg("-clean");
pc.addArg("-keyring").addArg(this.context.getUserHome().resolve(".eclipse").resolve(".keyring"));
pc.addArg("-configuration").addArg(configurationPath);
if (processMode == ProcessMode.DEFAULT_CAPTURE) {
pc.addArg("-consoleLog").addArg("-nosplash");
}
// TODO ability to use different Java version
Path javaPath = getCommandlet(Java.class).getToolBinPath();
pc.addArg("-vm").addArg(javaPath);
pc.addArgs(args);

return pc.run(processMode);

}

@Override
public void installPlugin(ToolPluginDescriptor plugin) {
public void installPlugin(ToolPluginDescriptor plugin, Step step) {

ProcessResult result = runEclipse(ProcessMode.DEFAULT_CAPTURE, "-application", "org.eclipse.equinox.p2.director", "-repository", plugin.url(),
"-installIU", plugin.id());
ProcessResult result = runTool(ProcessMode.DEFAULT_CAPTURE, null, ProcessErrorHandling.LOG_WARNING, "-application", "org.eclipse.equinox.p2.director",
"-repository", plugin.url(), "-installIU", plugin.id());
if (result.isSuccessful()) {
for (String line : result.getOut()) {
if (line.contains("Overall install request is satisfiable")) {
Expand All @@ -117,7 +86,7 @@ public void installPlugin(ToolPluginDescriptor plugin) {
}
}
this.context.error("Failed to install plugin {} ({}): exit code was {}", plugin.name(), plugin.id(), result.getExitCode());
log(IdeLogLevel.WARNING, result.getOut());
log(IdeLogLevel.DEBUG, result.getOut());
log(IdeLogLevel.ERROR, result.getErr());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,14 @@ protected void configureToolArgs(ProcessContext pc, ProcessMode processMode, Pro
}

@Override
public void installPlugin(ToolPluginDescriptor plugin) {
public void installPlugin(ToolPluginDescriptor plugin, Step step) {
String downloadUrl = getDownloadUrl(plugin);

String pluginId = plugin.id();

Path tmpDir = null;

Step step = this.context.newStep("Install plugin: " + pluginId);
try {

Path installationPath = this.getPluginsInstallationPath();
ensureInstallationPathExists(installationPath);

Expand All @@ -62,15 +60,13 @@ public void installPlugin(ToolPluginDescriptor plugin) {
extractDownloadedPlugin(fileAccess, downloadedFile, pluginId);

step.success();

} catch (IOException e) {
step.error(e);
throw new IllegalStateException("Failed to process installation of plugin: " + pluginId, e);
} finally {
if (tmpDir != null) {
context.getFileAccess().delete(tmpDir);
}
step.close();
}
}

Expand Down
2 changes: 1 addition & 1 deletion cli/src/main/java/com/devonfw/tools/ide/tool/mvn/Mvn.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ private Set<String> findVariables(String content) {
}

@Override
public void installPlugin(ToolPluginDescriptor plugin) {
public void installPlugin(ToolPluginDescriptor plugin, Step step) {

Path mavenPlugin = this.getToolPath().resolve("lib/ext/" + plugin.name() + ".jar");
this.context.getFileAccess().download(plugin.url(), mavenPlugin);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
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.step.Step;
import com.devonfw.tools.ide.tool.LocalToolCommandlet;
import com.devonfw.tools.ide.tool.ide.IdeToolCommandlet;

Expand Down Expand Up @@ -113,7 +114,9 @@ protected void postInstall(boolean newlyInstalled) {
protected void installPlugins(Collection<ToolPluginDescriptor> plugins) {
for (ToolPluginDescriptor plugin : plugins) {
if (plugin.active()) {
installPlugin(plugin);
try (Step step = this.context.newStep("Install plugin " + plugin.name())) {
installPlugin(plugin, step);
}
} else {
handleInstall4InactivePlugin(plugin);
}
Expand All @@ -122,8 +125,9 @@ protected void installPlugins(Collection<ToolPluginDescriptor> plugins) {

/**
* @param plugin the {@link ToolPluginDescriptor} to install.
* @param step the {@link Step} for the plugin installation.
*/
public abstract void installPlugin(ToolPluginDescriptor plugin);
public abstract void installPlugin(ToolPluginDescriptor plugin, Step step);

/**
* @param plugin the {@link ToolPluginDescriptor} to uninstall.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
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.step.Step;
import com.devonfw.tools.ide.tool.ToolCommandlet;
import com.devonfw.tools.ide.tool.ide.IdeToolCommandlet;
import com.devonfw.tools.ide.tool.plugin.ToolPluginDescriptor;
Expand Down Expand Up @@ -44,8 +45,10 @@ protected String getBinaryName() {
}

@Override
public void installPlugin(ToolPluginDescriptor plugin) {
throw new IllegalStateException(); // method not used
public void installPlugin(ToolPluginDescriptor plugin, Step step) {

doInstallPlugins(List.of(plugin));
step.success();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ public void testAndroidStudioRun(String os, WireMockRuntimeInfo wmRuntimeInfo) t
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).logAtSuccess().hasMessage("Successfully installed android-studio in version 2024.1.1.1");
assertThat(context).logAtSuccess().hasMessageContaining("Install plugin: mockedPlugin");
assertThat(context).logAtSuccess().hasEntries("Successfully ended step 'Install plugin MockedPlugin'.", //
"Successfully installed android-studio in version 2024.1.1.1");
assertThat(context.getPluginsPath().resolve("android-studio").resolve("mockedPlugin").resolve("MockedClass.class")).exists();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void testIntellijInstallPluginAfterwards(String os, WireMockRuntimeInfo w

// act
commandlet.install();
commandlet.installPlugin(commandlet.getPlugins().getById("mockedPlugin"));
commandlet.installPlugin(commandlet.getPlugins().getById("mockedPlugin"), this.context.newStep("Install plugin MockedPlugin"));

// assert
checkInstallation(this.context);
Expand Down Expand Up @@ -142,8 +142,8 @@ private void checkInstallation(IdeTestContext context) {

assertThat(context.getSoftwarePath().resolve("intellij/.ide.software.version")).exists().hasContent("2023.3.3");
assertThat(context).logAtSuccess().hasEntries("Successfully installed java in version 17.0.10_7",
"Successfully ended step 'Install plugin: mockedPlugin'.",
"Successfully installed intellij in version 2023.3.3");
assertThat(context).logAtSuccess().hasMessage("Successfully ended step 'Install plugin MockedPlugin'.");
assertThat(context.getPluginsPath().resolve("intellij").resolve("mockedPlugin").resolve("MockedClass.class")).exists();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import com.devonfw.tools.ide.common.Tag;
import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.step.Step;

/**
* Example implementation of {@link PluginBasedCommandlet} for testing.
Expand All @@ -23,7 +24,7 @@ public ExamplePluginBasedCommandlet(IdeContext context, String tool, Set<Tag> ta
}

@Override
public void installPlugin(ToolPluginDescriptor plugin) {
public void installPlugin(ToolPluginDescriptor plugin, Step step) {

}
}

0 comments on commit 809e192

Please sign in to comment.