Skip to content

Commit

Permalink
#463: added fallback to USER_HOME for mvn repository (#522)
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-vcapgemini authored Aug 8, 2024
1 parent a175301 commit ba83c94
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ default String getMavenArgs() {
}

/**
* @return the String value for the variable M2_REPO, or null if called outside an IDEasy installation.
* @return the String value for the variable M2_REPO, or falls back to the default USER_HOME/.m2 location if called outside an IDEasy installation.
*/
default Path getMavenRepository() {

Expand All @@ -486,6 +486,9 @@ default Path getMavenRepository() {
Path m2LegacyFolder = confPath.resolve(Mvn.MVN_CONFIG_LEGACY_FOLDER);
if (Files.isDirectory(m2LegacyFolder)) {
m2Folder = m2LegacyFolder;
} else {
// fallback to USER_HOME/.m2 folder
m2Folder = getUserHome().resolve(Mvn.MVN_CONFIG_LEGACY_FOLDER);
}
}
return m2Folder.resolve("repository");
Expand Down
17 changes: 17 additions & 0 deletions cli/src/test/java/com/devonfw/tools/ide/tool/mvn/MvnTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.devonfw.tools.ide.commandlet.InstallCommandlet;
import com.devonfw.tools.ide.context.AbstractIdeContextTest;
import com.devonfw.tools.ide.context.IdeTestContext;
import com.devonfw.tools.ide.variable.IdeVariables;

/**
* Integration test of {@link Mvn}.
Expand Down Expand Up @@ -85,6 +86,22 @@ private void checkInstallation(IdeTestContext context) throws IOException {
assertFileContent(settingsSecurityFile, List.of("masterPassword"));
}

/**
* Tests if the user is starting IDEasy without a Maven repository, IDEasy should fall back to USER_HOME/.m2/repository.
* <p>
* See: <a href="https://github.com/devonfw/IDEasy/issues/463">#463</a>
*/
@Test
public void testMavenRepositoryPathFallsBackToUserHome() {
// arrange
String path = "project/workspaces";
// act
IdeTestContext context = newContext(PROJECT_MVN, path, false);
Path mavenRepository = context.getUserHome().resolve(".m2").resolve("repository");
// assert
assertThat(IdeVariables.M2_REPO.get(context)).isEqualTo(mavenRepository);
}

private void assertFileContent(Path filePath, List<String> expectedValues) throws IOException {

String content = new String(Files.readAllBytes(filePath));
Expand Down
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

0 comments on commit ba83c94

Please sign in to comment.