From 384e1f263f9fd004c4a753ad5338dbbd394ebf26 Mon Sep 17 00:00:00 2001 From: Alexey Loubyansky Date: Mon, 3 Mar 2025 22:59:20 +0100 Subject: [PATCH] Fix loading of Maven workspaces that use revision properties using effective model building (cherry picked from commit c34f25fadb3e13c9cc97e1ec8ff063fcd028c767) --- .../maven/workspace/WorkspaceLoader.java | 13 ++++++++++-- .../test/LocalWorkspaceDiscoveryTest.java | 21 +++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) 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 8e6cf95ca6c77..8453ddc4b2562 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 @@ -209,15 +209,24 @@ private void loadModule(RawModule rawModule, Collection 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)); } 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 38102fceec402..d45af6239d000 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 @@ -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);