Skip to content

Commit

Permalink
#497: configured version shall match installed version supporting pat…
Browse files Browse the repository at this point in the history
…terns (#532)
  • Loading branch information
slskiba authored Aug 13, 2024
1 parent 752f41e commit 68406b6
Show file tree
Hide file tree
Showing 14 changed files with 192 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -48,33 +50,87 @@ 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
assertThat(context).logAtInfo().hasMessage("3.9.4");
}

/**
* 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");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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""");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"manual": false,
"urls": {
"-997329125": {
"success": {
"timestamp": "2023-04-28T07:12:26.601818Z"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"manual": false,
"urls": {
"-997329125": {
"success": {
"timestamp": "2023-04-28T07:12:26.601818Z"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"manual": false,
"urls": {
"-997329125": {
"success": {
"timestamp": "2023-04-28T07:12:26.601818Z"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"manual": false,
"urls": {
"-997329125": {
"success": {
"timestamp": "2023-04-28T07:12:26.601818Z"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#********************************************************************************
# This file contains project specific environment variables defined by the user
#********************************************************************************
MVN_VERSION=*
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#********************************************************************************
# This file contains the global configuration from the user HOME directory.
#********************************************************************************
MVN_VERSION=*
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#********************************************************************************
# This file contains project specific environment variables
#********************************************************************************
MVN_VERSION=*
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.9.4
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#********************************************************************************
# This file contains workspace specific environment variables
#********************************************************************************
MVN_VERSION=*
4 changes: 4 additions & 0 deletions cli/src/test/resources/ide-projects/settings/readme
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit 68406b6

Please sign in to comment.