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 604e541f2328a..48408336ac644 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 @@ -186,7 +186,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(), @@ -195,6 +194,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 7f2f880961e4f..38102fceec402 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() @@ -716,15 +740,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 +