From ba06007387572ebabbc4f7e629384be898c2c0a6 Mon Sep 17 00:00:00 2001 From: Alexey Loubyansky Date: Wed, 13 Mar 2024 23:25:30 +0100 Subject: [PATCH] Make sure the current project location isn't overridden my other modules with the same groupId and artifactId (cherry picked from commit cd9313560a4d0bbc0d08b83da272e50f2494dd7b) --- .../maven/workspace/WorkspaceLoader.java | 3 +- .../test/LocalWorkspaceDiscoveryTest.java | 38 +++++++++++++++---- .../resources/duplicate-ga/module/pom.xml | 10 +++++ .../src/test/resources/duplicate-ga/pom.xml | 18 +++++++++ .../resources/duplicate-ga/test/case/pom.xml | 11 ++++++ 5 files changed, 72 insertions(+), 8 deletions(-) create mode 100644 independent-projects/bootstrap/maven-resolver/src/test/resources/duplicate-ga/module/pom.xml create mode 100644 independent-projects/bootstrap/maven-resolver/src/test/resources/duplicate-ga/pom.xml create mode 100644 independent-projects/bootstrap/maven-resolver/src/test/resources/duplicate-ga/test/case/pom.xml diff --git a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/workspace/WorkspaceLoader.java b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/workspace/WorkspaceLoader.java index 77cd35b4963fd..c6330cd7b8c0b 100644 --- a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/workspace/WorkspaceLoader.java +++ b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/workspace/WorkspaceLoader.java @@ -180,7 +180,6 @@ private void loadModule(RawModule rawModule, List newModules) { if (rawModule.model == null) { return; } - newModules.add(rawModule); var added = loadedModules.putIfAbsent( new GAV(ModelUtils.getGroupId(rawModule.model), rawModule.model.getArtifactId(), @@ -189,6 +188,8 @@ private void loadModule(RawModule rawModule, List newModules) { if (added != null) { return; } + newModules.add(rawModule); + for (var module : rawModule.model.getModules()) { queueModule(rawModule.model.getProjectDirectory().toPath().resolve(module)); } diff --git a/independent-projects/bootstrap/maven-resolver/src/test/java/io/quarkus/bootstrap/workspace/test/LocalWorkspaceDiscoveryTest.java b/independent-projects/bootstrap/maven-resolver/src/test/java/io/quarkus/bootstrap/workspace/test/LocalWorkspaceDiscoveryTest.java index 1af195dd079b7..47b5284dacc90 100644 --- a/independent-projects/bootstrap/maven-resolver/src/test/java/io/quarkus/bootstrap/workspace/test/LocalWorkspaceDiscoveryTest.java +++ b/independent-projects/bootstrap/maven-resolver/src/test/java/io/quarkus/bootstrap/workspace/test/LocalWorkspaceDiscoveryTest.java @@ -3,6 +3,7 @@ */ package io.quarkus.bootstrap.workspace.test; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; @@ -20,7 +21,6 @@ import org.apache.maven.model.Dependency; import org.apache.maven.model.Parent; -import org.assertj.core.api.Assertions; import org.eclipse.aether.artifact.DefaultArtifact; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; @@ -124,6 +124,30 @@ public static void cleanup() { IoUtils.recursiveDelete(workDir); } + /** + * This test is making sure the current module isn't overridden by another module + * from the workspace that happens to have the same group and artifact IDs + * + * @throws Exception + */ + @Test + public void workspaceWithDuplicateModuleGroupIdAndArtifactId() throws Exception { + final URL moduleUrl = Thread.currentThread().getContextClassLoader() + .getResource("duplicate-ga/test/case"); + assertNotNull(moduleUrl); + final Path moduleDir = Path.of(moduleUrl.toURI()); + assertNotNull(moduleUrl); + + final LocalWorkspace ws = LocalProject.loadWorkspace(moduleDir).getWorkspace(); + + LocalProject project = ws.getProject("org.acme", "acme-lib"); + assertNotNull(project); + assertThat(project.getDir()).isEqualTo(moduleDir); + + assertNotNull(ws.getProject("org.acme", "acme-parent")); + assertEquals(2, ws.getProjects().size()); + } + @Test public void moduleWithDifferentParentPomRawModel() throws Exception { final URL moduleUrl = Thread.currentThread().getContextClassLoader() @@ -696,15 +720,15 @@ private void testMavenCiFriendlyVersion(String placeholder, String testResourceD assertEquals(new File(rootPomUrl.toURI()), root); final WorkspaceModule wsModule = module1.toWorkspaceModule(); - Assertions.assertThat(wsModule.getModuleDir()).isEqualTo(module1Dir.toFile()); - Assertions.assertThat(wsModule.getBuildDir()).isEqualTo(module1Dir.resolve("target").toFile()); + assertThat(wsModule.getModuleDir()).isEqualTo(module1Dir.toFile()); + assertThat(wsModule.getBuildDir()).isEqualTo(module1Dir.resolve("target").toFile()); SourceDir src = wsModule.getMainSources().getResourceDirs().iterator().next(); PathTree sourceTree = src.getSourceTree(); - Assertions.assertThat(sourceTree).isNotNull(); + assertThat(sourceTree).isNotNull(); Collection roots = sourceTree.getRoots(); - Assertions.assertThat(roots).hasSize(1); - Assertions.assertThat(roots.iterator().next()).isEqualTo(module1Dir.resolve("build")); - Assertions.assertThat(src.getOutputDir()).isEqualTo(module1Dir.resolve("target/classes/META-INF/resources")); + assertThat(roots).hasSize(1); + assertThat(roots.iterator().next()).isEqualTo(module1Dir.resolve("build")); + assertThat(src.getOutputDir()).isEqualTo(module1Dir.resolve("target/classes/META-INF/resources")); } private void assertCompleteWorkspace(final LocalProject project) { diff --git a/independent-projects/bootstrap/maven-resolver/src/test/resources/duplicate-ga/module/pom.xml b/independent-projects/bootstrap/maven-resolver/src/test/resources/duplicate-ga/module/pom.xml new file mode 100644 index 0000000000000..04f82897d473f --- /dev/null +++ b/independent-projects/bootstrap/maven-resolver/src/test/resources/duplicate-ga/module/pom.xml @@ -0,0 +1,10 @@ + + + 4.0.0 + + org.acme + acme-parent + 1.0-SNAPSHOT + + acme-lib + diff --git a/independent-projects/bootstrap/maven-resolver/src/test/resources/duplicate-ga/pom.xml b/independent-projects/bootstrap/maven-resolver/src/test/resources/duplicate-ga/pom.xml new file mode 100644 index 0000000000000..f7676193a7070 --- /dev/null +++ b/independent-projects/bootstrap/maven-resolver/src/test/resources/duplicate-ga/pom.xml @@ -0,0 +1,18 @@ + + + 4.0.0 + + org.acme + acme-parent + 1.0-SNAPSHOT + pom + + + + extra-module + + module + + + + diff --git a/independent-projects/bootstrap/maven-resolver/src/test/resources/duplicate-ga/test/case/pom.xml b/independent-projects/bootstrap/maven-resolver/src/test/resources/duplicate-ga/test/case/pom.xml new file mode 100644 index 0000000000000..81669f0e9dcd3 --- /dev/null +++ b/independent-projects/bootstrap/maven-resolver/src/test/resources/duplicate-ga/test/case/pom.xml @@ -0,0 +1,11 @@ + + + 4.0.0 + + org.acme + acme-parent + 1.0-SNAPSHOT + ../.. + + acme-lib +