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

#898: Improved output of get-version/edition and uninstall/-plugin #903

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ This file documents all notable changes to https://github.com/devonfw/IDEasy[IDE

Release with new features and bugfixes:

* https://github.com/devonfw/IDEasy/issues/898[#898]: Improved feedback messages
* https://github.com/devonfw/IDEasy/issues/888[#888]: Removed gu update functionality (needs to be run manually for old versions now).
* https://github.com/devonfw/IDEasy/issues/885[#885]: Gcviewer starts in foreground fixed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,9 @@ public void run() {

ToolCommandlet commandlet = this.tool.getValue();
String configuredEdition = commandlet.getConfiguredEdition();
String installedEdition = commandlet.getInstalledEdition();
IdeSubLogger logger = this.context.level(IdeLogLevel.PROCESSABLE);

if (this.installed.isTrue() && !this.configured.isTrue()) { // get installed edition
String installedEdition = commandlet.getInstalledEdition();
if (commandlet.getInstalledVersion() == null) {
// note: getInstalledEdition() will fallback to configured edition and not return null, therefore we use getInstalledVersion()
toolInstallInfo(commandlet.getName(), configuredEdition, null, commandlet);
Expand All @@ -66,25 +65,34 @@ public void run() {
}
} else if (!this.installed.isTrue() && this.configured.isTrue()) { // get configured edition
logger.log(configuredEdition);
} else { // get both configured and installed edition
String installedEdition = commandlet.getInstalledEdition();
if (configuredEdition.equals(installedEdition)) {
logger.log(installedEdition);
} else if (this.installed.isTrue() && this.configured.isTrue()) { // get both configured and installed edition
logger.log(configuredEdition);
if (!configuredEdition.equals(installedEdition)) {
if (commandlet.getInstalledVersion() != null) {
logger.log(installedEdition);
} else {
logger.log("No installed edition detected");
}
}
} else { // get configured or installed depending on if the tool is installed or not
if (commandlet.getInstalledVersion() == null) {
logger.log(configuredEdition);
} else {
toolInstallInfo(commandlet.getName(), configuredEdition, installedEdition, commandlet);
logger.log(installedEdition);
}
}
}

private void toolInstallInfo(String toolName, String configuredEdition, String installedEdition, ToolCommandlet commandlet) {

IdeSubLogger logger = this.context.level(IdeLogLevel.PROCESSABLE);
if (installedEdition == null) {
this.context.warning("No installation of tool {} was found.", commandlet.getName());
logger.log("No installation of tool {} was found.", commandlet.getName());
} else {
this.context.info("The installed edition for tool {} is {}", commandlet.getName(), installedEdition);
logger.log("The installed edition for tool {} is {}", commandlet.getName(), installedEdition);
}
this.context.info("The configured edition for tool {} is {}", toolName, configuredEdition);
this.context.info("To install that edition call the following command:");
this.context.info("ide install {}", toolName);
logger.log("The configured edition for tool {} is {}", toolName, configuredEdition);
logger.log("To install that edition call the following command:");
logger.log("ide install {}", toolName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ public void run() {

for (int i = 0; i < this.tools.getValueCount(); i++) {
ToolCommandlet toolCommandlet = this.tools.getValue(i);

toolCommandlet.uninstall();
if (toolCommandlet.getInstalledVersion() != null) {
toolCommandlet.uninstall();
} else {
this.context.warning("Couldn't uninstall " + toolCommandlet.getName() + " because we could not find an installation");
}

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ public void run() {
String plugin = this.plugin.getValue();

if (commandlet instanceof PluginBasedCommandlet cmd) {
cmd.uninstallPlugin(cmd.getPlugin(plugin));
if (cmd.uninstallPlugin(cmd.getPlugin(plugin)) == 0) {
context.info("Successfully uninstalled plugin " + plugin);
} else {
context.error("Could not uninstall plugin " + plugin + " because we could not find an installation");
}
} else {
context.warning("Tool {} does not support plugins.", tool.getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,36 +55,45 @@ public void run() {

ToolCommandlet commandlet = this.tool.getValue();
VersionIdentifier configuredVersion = commandlet.getConfiguredVersion();
VersionIdentifier installedVersion = commandlet.getInstalledVersion();
IdeSubLogger logger = this.context.level(IdeLogLevel.PROCESSABLE);
if (this.installed.isTrue() && !this.configured.isTrue()) {// get installed version
VersionIdentifier installedVersion = commandlet.getInstalledVersion();
if (installedVersion == null) {
toolInstallInfo(commandlet.getName(), configuredVersion, null, commandlet);
} else {
logger.log(installedVersion.toString());
}
} else if (!this.installed.isTrue() && this.configured.isTrue()) {// get configured version
logger.log(configuredVersion.toString());
} else { // get both configured and installed version
VersionIdentifier installedVersion = commandlet.getInstalledVersion();
if (configuredVersion.matches(installedVersion)) {
logger.log(installedVersion.toString());
} else if (this.installed.isTrue() && this.configured.isTrue()) {// get both configured and installed version
logger.log(configuredVersion.toString());
if (!configuredVersion.matches(installedVersion)) {
if (installedVersion != null) {
logger.log(installedVersion.toString());
} else {
logger.log("No installed version detected");
}
}
} else {
if (installedVersion == null) {
logger.log(configuredVersion.toString());
} else {
toolInstallInfo(commandlet.getName(), configuredVersion, installedVersion, commandlet);
logger.log(installedVersion.toString());
}
}
}

private void toolInstallInfo(String toolName, VersionIdentifier configuredVersion, VersionIdentifier installedVersion, ToolCommandlet commandlet) {

IdeSubLogger logger = this.context.level(IdeLogLevel.PROCESSABLE);
if (installedVersion == null) {
this.context.info("No installation of tool {} was found.", commandlet.getName());
logger.log("No installation of tool {} was found.", commandlet.getName());
} else {
this.context.info("The installed version for tool {} is {}", commandlet.getName(), installedVersion);
logger.log("The installed version for tool {} is {}", commandlet.getName(), installedVersion);
}
this.context.info("The configured version for tool {} is {}", toolName, configuredVersion);
this.context.info("To install that version call the following command:");
this.context.info("ide install {}", toolName);
logger.log("The configured version for tool {} is {}", toolName, configuredVersion);
logger.log("To install that version call the following command:");
logger.log("ide install {}", toolName);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,23 +131,25 @@ protected void installPlugins(Collection<ToolPluginDescriptor> plugins) {

/**
* @param plugin the {@link ToolPluginDescriptor} to uninstall.
* @return 0 if the uninstallation was successfull and 1 if it failed
*/
public void uninstallPlugin(ToolPluginDescriptor plugin) {
public int uninstallPlugin(ToolPluginDescriptor plugin) {

Path pluginsPath = getPluginsInstallationPath();
if (!Files.isDirectory(pluginsPath)) {
this.context.debug("Omitting to uninstall plugin {} ({}) as plugins folder does not exist at {}",
plugin.name(), plugin.id(), pluginsPath);
return;
return 1;
}
FileAccess fileAccess = this.context.getFileAccess();
Path match = fileAccess.findFirst(pluginsPath, p -> p.getFileName().toString().startsWith(plugin.id()), false);
if (match == null) {
this.context.debug("Omitting to uninstall plugin {} ({}) as plugins folder does not contain a match at {}",
plugin.name(), plugin.id(), pluginsPath);
return;
return 1;
}
fileAccess.delete(match);
return 0;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,7 @@ public void testEditionGetCommandletToolNotInstalled() {
editionGet.tool.setValueAsString("az", context);
editionGet.run();
// assert
assertThat(context).log().hasEntries(IdeLogEntry.ofWarning("No installation of tool az was found."),
IdeLogEntry.ofInfo("The configured edition for tool az is az"),
IdeLogEntry.ofInfo("To install that edition call the following command:"),
IdeLogEntry.ofInfo("ide install az"));
assertThat(context).logAtProcessable().hasMessage("az");
}

/** Test of {@link EditionGetCommandlet} run, with --installed flag, when Installed Version is null. */
Expand All @@ -90,10 +87,10 @@ public void testEditionGetCommandletInstalledEditionToolNotInstalled() {
// act
editionGet.run();
// assert
assertThat(context).log().hasEntries(IdeLogEntry.ofWarning("No installation of tool java was found."),
IdeLogEntry.ofInfo("The configured edition for tool java is java"),
IdeLogEntry.ofInfo("To install that edition call the following command:"),
IdeLogEntry.ofInfo("ide install java"));
assertThat(context).log().hasEntries(IdeLogEntry.ofProcessable("No installation of tool java was found."),
IdeLogEntry.ofProcessable("The configured edition for tool java is java"),
IdeLogEntry.ofProcessable("To install that edition call the following command:"),
IdeLogEntry.ofProcessable("ide install java"));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void testUninstallCommandletRun_WithExistingCommandlet() {
uninstallCommandlet.run();
// assert
assertThat(context).log().hasEntries(IdeLogEntry.ofSuccess("Successfully uninstalled " + npm),
IdeLogEntry.ofWarning("An installed version of " + dotnet + " does not exist"));
IdeLogEntry.ofWarning("Couldn't uninstall " + dotnet + " because we could not find an installation"));
assertThat(context.getSoftwarePath().resolve(npm)).doesNotExist();
}

Expand All @@ -65,7 +65,7 @@ public void testUninstallCommandletRun_WithNonExistingCommandlet() {
// act
uninstallCommandlet.run();
// assert
assertThat(context).logAtWarning().hasMessage("An installed version of " + eclipse + " does not exist");
assertThat(context).logAtWarning().hasMessage("Couldn't uninstall " + eclipse + " because we could not find an installation");
assertThat(Files.notExists(context.getSoftwarePath().resolve(eclipse)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ public void testVersionGetCommandletNotInstalledRun() {
// act
versionGet.run();
// assert
assertThat(context).logAtInfo().hasEntries("No installation of tool java was found.",
"The configured version for tool java is 17*",
"To install that version call the following command:",
"ide install java");
assertThat(context).logAtProcessable().hasMessage("17*");
}

@Test
Expand All @@ -43,7 +40,7 @@ public void testVersionGetCommandletNotInstalledRunInstalledFlag() {
// act
versionGet.run();
// assert
assertThat(context).logAtInfo().hasEntries("No installation of tool java was found.",
assertThat(context).logAtProcessable().hasEntries("No installation of tool java was found.",
"The configured version for tool java is 17*",
"To install that version call the following command:",
"ide install java");
Expand Down Expand Up @@ -130,10 +127,7 @@ public void testVersionGetCommandletNeitherInstalledNorConfigured() {
versionGet.tool.setValueAsString("java", context);
versionGet.run();
// assert
assertThat(context).logAtInfo().hasEntries("No installation of tool java was found.",
"The configured version for tool java is *",
"To install that version call the following command:",
"ide install java");
assertThat(context).logAtProcessable().hasMessage("*");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,8 @@ public IdeTestLoggerAssertion logAtError() {
return log(IdeLogLevel.ERROR);
}

public IdeTestLoggerAssertion logAtProcessable() {
return log(IdeLogLevel.PROCESSABLE);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
11.0.0
Loading