From ba83c94fbd661fcf8d3e728db7100f040f7f834b Mon Sep 17 00:00:00 2001 From: jan-vcapgemini <59438728+jan-vcapgemini@users.noreply.github.com> Date: Thu, 8 Aug 2024 09:04:34 +0200 Subject: [PATCH] #463: added fallback to USER_HOME for mvn repository (#522) --- .../devonfw/tools/ide/context/IdeContext.java | 5 ++++- .../com/devonfw/tools/ide/tool/mvn/MvnTest.java | 17 +++++++++++++++++ .../mvn/project/home/environment.properties | 2 ++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 cli/src/test/resources/ide-projects/mvn/project/home/environment.properties diff --git a/cli/src/main/java/com/devonfw/tools/ide/context/IdeContext.java b/cli/src/main/java/com/devonfw/tools/ide/context/IdeContext.java index 034831aac..f0251e19d 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/context/IdeContext.java +++ b/cli/src/main/java/com/devonfw/tools/ide/context/IdeContext.java @@ -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() { @@ -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"); diff --git a/cli/src/test/java/com/devonfw/tools/ide/tool/mvn/MvnTest.java b/cli/src/test/java/com/devonfw/tools/ide/tool/mvn/MvnTest.java index 0837cec15..3591f11c1 100644 --- a/cli/src/test/java/com/devonfw/tools/ide/tool/mvn/MvnTest.java +++ b/cli/src/test/java/com/devonfw/tools/ide/tool/mvn/MvnTest.java @@ -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}. @@ -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. + *
+ * See: #463
+ */
+ @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