Skip to content

Commit

Permalink
devonfw#898 improved feedback messages
Browse files Browse the repository at this point in the history
Edition/VersionGetCommandlet changed them to log the configured option if the tool is not installed and the installed option if it is installed.
Changed the toolInstallInfo method to log into IdeSublogger instead of using context.info or context.warning.
Changed the uninstall commandlet to log a warning in case the requested commandlet is not installed.
Changed the uninstallPlugin commandlet to give feedback wether the plugin could be deleted or if there was not installation found.
Adjusted Tests for Edition/VersionGetCommandlet as well as Uninstall commandlet to expect the correct loglevel or content of logged messages.
Added logAtProccessable to IdeTestContextAssertions to check if a log-message was logged on PROCESSABLE-level.
Added .ide.software.version file to the npm software in the basic ide-test-project-ressource, since it was needed to test my implementation.
  • Loading branch information
WorkingAmeise committed Dec 19, 2024
1 parent 35fc679 commit 864a8a9
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 48 deletions.
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

0 comments on commit 864a8a9

Please sign in to comment.