diff --git a/cli/src/main/java/com/devonfw/tools/ide/commandlet/VersionGetCommandlet.java b/cli/src/main/java/com/devonfw/tools/ide/commandlet/VersionGetCommandlet.java index 533054c89..3b45c4768 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/commandlet/VersionGetCommandlet.java +++ b/cli/src/main/java/com/devonfw/tools/ide/commandlet/VersionGetCommandlet.java @@ -71,7 +71,7 @@ public void run() { } else { // get both configured and installed version VersionIdentifier installedVersion = commandlet.getInstalledVersion(); - if (configuredVersion.compareVersion(installedVersion).isEqual()) { + if (configuredVersion.matches(installedVersion)) { this.context.info(installedVersion.toString()); } else { if (installedVersion == null) { diff --git a/cli/src/test/java/com/devonfw/tools/ide/commandlet/VersionGetCommandletTest.java b/cli/src/test/java/com/devonfw/tools/ide/commandlet/VersionGetCommandletTest.java index e01f2540e..4a34dd219 100644 --- a/cli/src/test/java/com/devonfw/tools/ide/commandlet/VersionGetCommandletTest.java +++ b/cli/src/test/java/com/devonfw/tools/ide/commandlet/VersionGetCommandletTest.java @@ -10,6 +10,8 @@ */ public class VersionGetCommandletTest extends AbstractIdeContextTest { + private static final String PROJECT_SETTINGS = "settings"; + /** * Test of {@link VersionGetCommandlet} run, when Installed Version is null. */ @@ -48,13 +50,30 @@ public void testVersionGetCommandletNotInstalledRunInstalledFlag() { * Test of {@link VersionGetCommandlet} run. */ @Test - public void testVersionGetCommandletInstalledRun() { + public void testVersionGetCommandletConfiguredRun() { // arrange IdeTestContext context = newContext(PROJECT_BASIC, null, false); VersionGetCommandlet versionGet = context.getCommandletManager().getCommandlet(VersionGetCommandlet.class); // act versionGet.tool.setValueAsString("mvn", context); + versionGet.configured.setValue(true); + versionGet.run(); + // assert + assertThat(context).logAtInfo().hasMessage("3.9.1"); + } + + /** + * Test of {@link VersionGetCommandlet} run with the installed flag, where the installed version is 3.9.4. + */ + @Test + public void testVersionGetCommandletInstalledRun() { + + // arrange + IdeTestContext context = newContext(PROJECT_SETTINGS, null, false); + VersionGetCommandlet versionGet = context.getCommandletManager().getCommandlet(VersionGetCommandlet.class); + // act + versionGet.tool.setValueAsString("mvn", context); versionGet.installed.setValue(true); versionGet.run(); // assert @@ -62,19 +81,56 @@ public void testVersionGetCommandletInstalledRun() { } /** - * Test of {@link VersionGetCommandlet} run. + * Test of {@link VersionGetCommandlet} run with the "configured" flag, where the configured version is "any" (*). */ @Test - public void testVersionGetCommandletConfiguredRun() { + public void testVersionGetCommandletConfiguredStarRun() { // arrange - IdeTestContext context = newContext(PROJECT_BASIC, null, false); + IdeTestContext context = newContext(PROJECT_SETTINGS, null, false); VersionGetCommandlet versionGet = context.getCommandletManager().getCommandlet(VersionGetCommandlet.class); // act versionGet.tool.setValueAsString("mvn", context); versionGet.configured.setValue(true); versionGet.run(); // assert - assertThat(context).logAtInfo().hasMessage("3.9.1"); + assertThat(context).logAtInfo().hasMessage("*"); } + + /** + * Test of {@link VersionGetCommandlet} run, where a specific version is installed (mvn 3.9.4) but no specific version is configured (configured version *) + * The expected output is to be 3.9.4 only. + */ + @Test + public void testVersionGetCommandletMatchInstalledToConfiguredStarRun() { + + // arrange + IdeTestContext context = newContext(PROJECT_SETTINGS, null, false); + VersionGetCommandlet versionGet = context.getCommandletManager().getCommandlet(VersionGetCommandlet.class); + // act + versionGet.tool.setValueAsString("mvn", context); + versionGet.run(); + // assert + assertThat(context).logAtInfo().hasMessage("3.9.4"); + } + + /** + * Test of {@link VersionGetCommandlet} run, where the tool is neither installed nor configured. + */ + @Test + public void testVersionGetCommandletNeitherInstalledNorConfigured() { + + // arrange + IdeTestContext context = newContext(PROJECT_SETTINGS, null, false); + VersionGetCommandlet versionGet = context.getCommandletManager().getCommandlet(VersionGetCommandlet.class); + // act + versionGet.tool.setValueAsString("java", context); + versionGet.run(); + // assert + assertThat(context).logAtInfo().hasMessage("No installation of tool java was found."); + assertThat(context).logAtInfo().hasMessage("The configured version for tool java is *"); + assertThat(context).logAtInfo().hasMessage("To install that version call the following command:"); + assertThat(context).logAtInfo().hasMessage("ide install java"); + } + } diff --git a/cli/src/test/java/com/devonfw/tools/ide/commandlet/VersionSetCommandletTest.java b/cli/src/test/java/com/devonfw/tools/ide/commandlet/VersionSetCommandletTest.java index 2bad08fa4..b82c752d6 100644 --- a/cli/src/test/java/com/devonfw/tools/ide/commandlet/VersionSetCommandletTest.java +++ b/cli/src/test/java/com/devonfw/tools/ide/commandlet/VersionSetCommandletTest.java @@ -14,13 +14,15 @@ */ public class VersionSetCommandletTest extends AbstractIdeContextTest { + private static final String PROJECT_SETTINGS = "settings"; + /** * Test of {@link VersionSetCommandlet} run. * * @throws IOException on error. */ @Test - public void testVersionSetCommandletRun() throws IOException { + public void testVersionSetCommandletRun() { // arrange IdeContext context = newContext(PROJECT_BASIC); @@ -58,14 +60,14 @@ public void testVersionSetCommandletRun() throws IOException { * @throws IOException on error. */ @Test - public void testVersionSetCommandletConfRun() throws IOException { + public void testVersionSetCommandletConfRun() { // arrange - IdeContext context = newContext(PROJECT_BASIC); + IdeContext context = newContext(PROJECT_SETTINGS); VersionSetCommandlet versionSet = context.getCommandletManager().getCommandlet(VersionSetCommandlet.class); versionSet.tool.setValueAsString("mvn", context); - versionSet.version.setValueAsString("3.2.1", context); versionSet.cfg.setValue(EnvironmentVariablesFiles.CONF); + versionSet.version.setValueAsString("3.2.conf", context); // act versionSet.run(); // assert @@ -74,16 +76,66 @@ public void testVersionSetCommandletConfRun() throws IOException { #******************************************************************************** # This file contains project specific environment variables defined by the user #******************************************************************************** - M2_REPO=~/.m2/repository - MVN_VERSION=3.2.1 - SOME=some-${UNDEFINED} - TEST_ARGS1=${TEST_ARGS1} conf1 - TEST_ARGS2=${TEST_ARGS2} conf2 - TEST_ARGS5=${TEST_ARGS5} conf5 - TEST_ARGS6=${TEST_ARGS6} conf6 - TEST_ARGS7=${TEST_ARGS7} conf7 - TEST_ARGS8=${TEST_ARGS8} conf8 - TEST_ARGSa=${TEST_ARGS1} ${TEST_ARGS3} confa - TEST_ARGSc=${TEST_ARGSc} confc"""); + MVN_VERSION=3.2.conf"""); + } + + @Test + public void testVersionSetCommandletWorkspaceRun() { + + // arrange + IdeContext context = newContext(PROJECT_SETTINGS); + VersionSetCommandlet versionSet = context.getCommandletManager().getCommandlet(VersionSetCommandlet.class); + versionSet.tool.setValueAsString("mvn", context); + versionSet.cfg.setValue(EnvironmentVariablesFiles.WORKSPACE); + versionSet.version.setValueAsString("3.2.workspace", context); + // act + versionSet.run(); + // assert + Path confIdeProperties = context.getWorkspacePath().resolve("ide.properties"); + assertThat(confIdeProperties).hasContent(""" + #******************************************************************************** + # This file contains workspace specific environment variables + #******************************************************************************** + MVN_VERSION=3.2.workspace"""); + } + + @Test + public void testVersionSetCommandletUserRun() { + + // arrange + IdeContext context = newContext(PROJECT_SETTINGS); + VersionSetCommandlet versionSet = context.getCommandletManager().getCommandlet(VersionSetCommandlet.class); + versionSet.tool.setValueAsString("mvn", context); + versionSet.cfg.setValue(EnvironmentVariablesFiles.USER); + versionSet.version.setValueAsString("3.2.user", context); + // act + versionSet.run(); + // assert + Path confIdeProperties = context.getUserHome().resolve(".ide").resolve("ide.properties"); + assertThat(confIdeProperties).hasContent(""" + #******************************************************************************** + # This file contains the global configuration from the user HOME directory. + #******************************************************************************** + MVN_VERSION=3.2.user"""); + } + + @Test + public void testVersionSetCommandletSettingsRun() { + + // arrange + IdeContext context = newContext(PROJECT_SETTINGS); + VersionSetCommandlet versionSet = context.getCommandletManager().getCommandlet(VersionSetCommandlet.class); + versionSet.tool.setValueAsString("mvn", context); + versionSet.cfg.setValue(EnvironmentVariablesFiles.SETTINGS); + versionSet.version.setValueAsString("3.2.settings", context); + // act + versionSet.run(); + // assert + Path confIdeProperties = context.getSettingsPath().resolve("ide.properties"); + assertThat(confIdeProperties).hasContent(""" + #******************************************************************************** + # This file contains project specific environment variables + #******************************************************************************** + MVN_VERSION=3.2.settings"""); } } diff --git a/cli/src/test/resources/ide-projects/settings/_ide/urls/mvn/mvn/3.2.conf/status.json b/cli/src/test/resources/ide-projects/settings/_ide/urls/mvn/mvn/3.2.conf/status.json new file mode 100644 index 000000000..efe228f91 --- /dev/null +++ b/cli/src/test/resources/ide-projects/settings/_ide/urls/mvn/mvn/3.2.conf/status.json @@ -0,0 +1,10 @@ +{ + "manual": false, + "urls": { + "-997329125": { + "success": { + "timestamp": "2023-04-28T07:12:26.601818Z" + } + } + } +} diff --git a/cli/src/test/resources/ide-projects/settings/_ide/urls/mvn/mvn/3.2.settings/status.json b/cli/src/test/resources/ide-projects/settings/_ide/urls/mvn/mvn/3.2.settings/status.json new file mode 100644 index 000000000..efe228f91 --- /dev/null +++ b/cli/src/test/resources/ide-projects/settings/_ide/urls/mvn/mvn/3.2.settings/status.json @@ -0,0 +1,10 @@ +{ + "manual": false, + "urls": { + "-997329125": { + "success": { + "timestamp": "2023-04-28T07:12:26.601818Z" + } + } + } +} diff --git a/cli/src/test/resources/ide-projects/settings/_ide/urls/mvn/mvn/3.2.user/status.json b/cli/src/test/resources/ide-projects/settings/_ide/urls/mvn/mvn/3.2.user/status.json new file mode 100644 index 000000000..efe228f91 --- /dev/null +++ b/cli/src/test/resources/ide-projects/settings/_ide/urls/mvn/mvn/3.2.user/status.json @@ -0,0 +1,10 @@ +{ + "manual": false, + "urls": { + "-997329125": { + "success": { + "timestamp": "2023-04-28T07:12:26.601818Z" + } + } + } +} diff --git a/cli/src/test/resources/ide-projects/settings/_ide/urls/mvn/mvn/3.2.workspace/status.json b/cli/src/test/resources/ide-projects/settings/_ide/urls/mvn/mvn/3.2.workspace/status.json new file mode 100644 index 000000000..efe228f91 --- /dev/null +++ b/cli/src/test/resources/ide-projects/settings/_ide/urls/mvn/mvn/3.2.workspace/status.json @@ -0,0 +1,10 @@ +{ + "manual": false, + "urls": { + "-997329125": { + "success": { + "timestamp": "2023-04-28T07:12:26.601818Z" + } + } + } +} diff --git a/cli/src/test/resources/ide-projects/settings/project/conf/ide.properties b/cli/src/test/resources/ide-projects/settings/project/conf/ide.properties new file mode 100644 index 000000000..7648f1a1a --- /dev/null +++ b/cli/src/test/resources/ide-projects/settings/project/conf/ide.properties @@ -0,0 +1,4 @@ +#******************************************************************************** +# This file contains project specific environment variables defined by the user +#******************************************************************************** +MVN_VERSION=* diff --git a/cli/src/test/resources/ide-projects/settings/project/home/.ide/ide.properties b/cli/src/test/resources/ide-projects/settings/project/home/.ide/ide.properties new file mode 100644 index 000000000..484ac09af --- /dev/null +++ b/cli/src/test/resources/ide-projects/settings/project/home/.ide/ide.properties @@ -0,0 +1,4 @@ +#******************************************************************************** +# This file contains the global configuration from the user HOME directory. +#******************************************************************************** +MVN_VERSION=* diff --git a/cli/src/test/resources/ide-projects/settings/project/home/environment.properties b/cli/src/test/resources/ide-projects/settings/project/home/environment.properties new file mode 100644 index 000000000..c0a59da37 --- /dev/null +++ b/cli/src/test/resources/ide-projects/settings/project/home/environment.properties @@ -0,0 +1,2 @@ +# if this file is present, it will replace and mock System.getenv in the text context +PATH=${IDE_ROOT}/_ide/bin diff --git a/cli/src/test/resources/ide-projects/settings/project/settings/ide.properties b/cli/src/test/resources/ide-projects/settings/project/settings/ide.properties new file mode 100644 index 000000000..d44465ea9 --- /dev/null +++ b/cli/src/test/resources/ide-projects/settings/project/settings/ide.properties @@ -0,0 +1,4 @@ +#******************************************************************************** +# This file contains project specific environment variables +#******************************************************************************** +MVN_VERSION=* diff --git a/cli/src/test/resources/ide-projects/settings/project/software/mvn/.devon.software.version b/cli/src/test/resources/ide-projects/settings/project/software/mvn/.devon.software.version new file mode 100644 index 000000000..e0d61b5b0 --- /dev/null +++ b/cli/src/test/resources/ide-projects/settings/project/software/mvn/.devon.software.version @@ -0,0 +1 @@ +3.9.4 diff --git a/cli/src/test/resources/ide-projects/settings/project/workspaces/main/ide.properties b/cli/src/test/resources/ide-projects/settings/project/workspaces/main/ide.properties new file mode 100644 index 000000000..b21fcbd9a --- /dev/null +++ b/cli/src/test/resources/ide-projects/settings/project/workspaces/main/ide.properties @@ -0,0 +1,4 @@ +#******************************************************************************** +# This file contains workspace specific environment variables +#******************************************************************************** +MVN_VERSION=* diff --git a/cli/src/test/resources/ide-projects/settings/readme b/cli/src/test/resources/ide-projects/settings/readme new file mode 100644 index 000000000..ef4b2846e --- /dev/null +++ b/cli/src/test/resources/ide-projects/settings/readme @@ -0,0 +1,4 @@ +This project +- simulates having mvn installed at version 3.9.4 +- configures mvn to any version (*) in conf, home, settings as well as the workspace ide-properties +- makes fake mvn versions "3.2.conf", "3.2.home", "3.2.settings", and "3.2.workspace" available has a status.json file each, but does not provide urls files.