Skip to content

Commit

Permalink
Make sure the current project location isn't overridden my other modules
Browse files Browse the repository at this point in the history
with the same groupId and artifactId

(cherry picked from commit cd93135)
  • Loading branch information
aloubyansky authored and gsmet committed Mar 15, 2024
1 parent cdc10b5 commit ba06007
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ private void loadModule(RawModule rawModule, List<RawModule> newModules) {
if (rawModule.model == null) {
return;
}
newModules.add(rawModule);

var added = loadedModules.putIfAbsent(
new GAV(ModelUtils.getGroupId(rawModule.model), rawModule.model.getArtifactId(),
Expand All @@ -189,6 +188,8 @@ private void loadModule(RawModule rawModule, List<RawModule> newModules) {
if (added != null) {
return;
}
newModules.add(rawModule);

for (var module : rawModule.model.getModules()) {
queueModule(rawModule.model.getProjectDirectory().toPath().resolve(module));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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<Path> 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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.acme</groupId>
<artifactId>acme-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>acme-lib</artifactId>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>

<groupId>org.acme</groupId>
<artifactId>acme-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>

<profiles>
<profile>
<id>extra-module</id>
<modules>
<module>module</module>
</modules>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.acme</groupId>
<artifactId>acme-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../..</relativePath>
</parent>
<artifactId>acme-lib</artifactId>
</project>

0 comments on commit ba06007

Please sign in to comment.