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

#463: Set default Maven m2 repository location back to user home #522

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Loading