Skip to content

Commit

Permalink
Fix loading of Maven workspaces that use revision properties using ef…
Browse files Browse the repository at this point in the history
…fective model building

(cherry picked from commit c34f25f)
  • Loading branch information
aloubyansky authored and gsmet committed Mar 4, 2025
1 parent 79cf24f commit 384e1f2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,24 @@ private void loadModule(RawModule rawModule, Collection<RawModule> newModules) {
return;
}

final String rawVersion = ModelUtils.getRawVersion(rawModule.model);
final String version = ModelUtils.isUnresolvedVersion(rawVersion)
? ModelUtils.resolveVersion(rawVersion, rawModule.model)
: rawVersion;
var added = loadedModules.putIfAbsent(
new GAV(ModelUtils.getGroupId(rawModule.model), rawModule.model.getArtifactId(),
ModelUtils.getVersion(rawModule.model)),
new GAV(ModelUtils.getGroupId(rawModule.model), rawModule.model.getArtifactId(), version),
rawModule.model);
if (added != null) {
return;
}
newModules.add(rawModule);

if (!rawVersion.equals(version)) {
loadedModules.putIfAbsent(
new GAV(ModelUtils.getGroupId(rawModule.model), rawModule.model.getArtifactId(), rawVersion),
rawModule.model);
}

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 @@ -615,6 +615,27 @@ public void loadWorkspaceForModuleWithEmptyRelativePathParent() throws Exception
assertParents(project);
}

@Test
public void testVersionRevisionPropertyEffectiveModel() throws Exception {
final URL projectUrl = Thread.currentThread().getContextClassLoader().getResource("workspace-revision/root/module1");
assertNotNull(projectUrl);
final Path projectDir = Paths.get(projectUrl.toURI());
assertTrue(Files.exists(projectDir));

final LocalProject module1 = new BootstrapMavenContext(BootstrapMavenContext.config()
.setEffectiveModelBuilder(true)
.setCurrentProject(projectDir.toString()))
.getCurrentProject();
final LocalWorkspace ws = module1.getWorkspace();
var project = ws.getProject("org.acme", "root-module1");
assertNotNull(project);
assertEquals("1.2.3", project.getVersion());

project = ws.getProject("org.acme", "root");
assertNotNull(project);
assertEquals("1.2.3", project.getVersion());
}

@Test
public void testVersionRevisionProperty() throws Exception {
testMavenCiFriendlyVersion("${revision}", "workspace-revision", "1.2.3", true);
Expand Down

0 comments on commit 384e1f2

Please sign in to comment.