diff --git a/core/deployment/src/test/java/io/quarkus/deployment/runnerjar/BootstrapFromOriginalJarTestBase.java b/core/deployment/src/test/java/io/quarkus/deployment/runnerjar/BootstrapFromOriginalJarTestBase.java index f3a504b646fe5..c0943ba807657 100644 --- a/core/deployment/src/test/java/io/quarkus/deployment/runnerjar/BootstrapFromOriginalJarTestBase.java +++ b/core/deployment/src/test/java/io/quarkus/deployment/runnerjar/BootstrapFromOriginalJarTestBase.java @@ -38,6 +38,10 @@ protected boolean createWorkspace() { return false; } + protected boolean workspaceModuleParentHierarchy() { + return false; + } + protected void addWorkspaceModule(TsArtifact a) { if (wsModules.isEmpty()) { wsModules = new ArrayList<>(); @@ -76,14 +80,20 @@ protected QuarkusBootstrap.Builder initBootstrapBuilder() throws Exception { System.setProperty("basedir", ws.toAbsolutePath().toString()); final Model appPom = appJar.getPomModel(); - final List moduleDeps = appPom.getDependencies().stream() + final List bomModules = (appPom.getDependencyManagement() == null ? List. of() + : appPom.getDependencyManagement().getDependencies()).stream() + .filter(d -> "import".equals(d.getScope()) + && d.getGroupId().equals(appPom.getGroupId())) + .collect(Collectors.toList()); + + final List depModules = appPom.getDependencies().stream() .filter(d -> d.getGroupId().equals(appPom.getGroupId()) && (d.getType().isEmpty() || ArtifactCoords.TYPE_JAR.equals(d.getType()))) .collect(Collectors.toList()); final Path appModule; final Path appPomXml; - if (moduleDeps.isEmpty() || appPom.getParent() != null) { + if (depModules.isEmpty() && bomModules.isEmpty() || appPom.getParent() != null) { appModule = ws; appPomXml = ws.resolve("pom.xml"); ModelUtils.persistModel(appPomXml, appPom); @@ -100,6 +110,19 @@ protected QuarkusBootstrap.Builder initBootstrapBuilder() throws Exception { parent.setArtifactId(parentPom.getArtifactId()); parent.setVersion(parentPom.getVersion()); + // BOM modules + for (Dependency bomModule : bomModules) { + parentPom.getModules().add(bomModule.getArtifactId()); + final String moduleVersion = bomModule.getVersion(); + Model modulePom = ModelUtils.readModel(resolver + .resolve(ArtifactCoords.pom(bomModule.getGroupId(), bomModule.getArtifactId(), moduleVersion)) + .getResolvedPaths().getSinglePath()); + modulePom.setParent(parent); + final Path moduleDir = IoUtils.mkdirs(ws.resolve(modulePom.getArtifactId())); + ModelUtils.persistModel(moduleDir.resolve("pom.xml"), modulePom); + } + + // APP module parentPom.getModules().add(appPom.getArtifactId()); appModule = ws.resolve(appPom.getArtifactId()); Files.createDirectories(appModule); @@ -107,9 +130,10 @@ protected QuarkusBootstrap.Builder initBootstrapBuilder() throws Exception { appPomXml = appModule.resolve("pom.xml"); ModelUtils.persistModel(appPomXml, appPom); + // dependency modules final Map managedVersions = new HashMap<>(); collectManagedDeps(appPom, managedVersions); - for (Dependency moduleDep : moduleDeps) { + for (Dependency moduleDep : depModules) { parentPom.getModules().add(moduleDep.getArtifactId()); final String moduleVersion = moduleDep.getVersion() == null ? managedVersions.get(ArtifactKey.of(moduleDep.getGroupId(), moduleDep.getArtifactId(), @@ -196,6 +220,7 @@ protected QuarkusBootstrap.Builder initBootstrapBuilder() throws Exception { final LocalProject appProject = new BootstrapMavenContext(BootstrapMavenContext.config() .setWorkspaceDiscovery(true) + .setWorkspaceModuleParentHierarchy(workspaceModuleParentHierarchy()) .setRootProjectDir(ws) .setCurrentProject(appPomXml.toString())) .getCurrentProject(); diff --git a/core/deployment/src/test/java/io/quarkus/deployment/runnerjar/DependencyVersionOverridesManagedVersionTest.java b/core/deployment/src/test/java/io/quarkus/deployment/runnerjar/DependencyVersionOverridesManagedVersionTest.java index f08232527f8d3..b64cddb353339 100644 --- a/core/deployment/src/test/java/io/quarkus/deployment/runnerjar/DependencyVersionOverridesManagedVersionTest.java +++ b/core/deployment/src/test/java/io/quarkus/deployment/runnerjar/DependencyVersionOverridesManagedVersionTest.java @@ -1,8 +1,16 @@ package io.quarkus.deployment.runnerjar; +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.Set; +import java.util.stream.Collectors; + +import io.quarkus.bootstrap.model.ApplicationModel; import io.quarkus.bootstrap.resolver.TsArtifact; import io.quarkus.bootstrap.resolver.TsDependency; import io.quarkus.bootstrap.resolver.TsQuarkusExt; +import io.quarkus.bootstrap.workspace.WorkspaceModule; +import io.quarkus.bootstrap.workspace.WorkspaceModuleId; public class DependencyVersionOverridesManagedVersionTest extends BootstrapFromOriginalJarTestBase { @@ -11,6 +19,13 @@ protected boolean createWorkspace() { return true; } + @Override + protected boolean workspaceModuleParentHierarchy() { + // this is to simply make sure the workspace modules available + // through ApplicationModel.getWorkspaceModules() include parent POMs and BOMs + return true; + } + @Override protected TsArtifact composeApplication() { @@ -22,7 +37,7 @@ protected TsArtifact composeApplication() { final TsArtifact extB_100_rt = extB_100.getRuntime(); addToExpectedLib(extB_100_rt); - final TsArtifact bom = new TsArtifact("test.quarkus", "test-bom", null, "pom", "1.0.0"); + final TsArtifact bom = TsArtifact.pom("test-bom"); bom.addManagedDependency(platformDescriptor()); bom.addManagedDependency(platformProperties()); bom.addManagedDependency(new TsDependency(extA_100.getRuntime())); @@ -43,4 +58,15 @@ protected TsArtifact composeApplication() { return appJar; } + + @Override + protected void assertAppModel(ApplicationModel model) { + assertThat(model.getWorkspaceModules().stream().map(WorkspaceModule::getId).collect(Collectors.toSet())) + .isEqualTo(Set.of( + WorkspaceModuleId.of(TsArtifact.DEFAULT_GROUP_ID, "app-parent", TsArtifact.DEFAULT_VERSION), + WorkspaceModuleId.of(TsArtifact.DEFAULT_GROUP_ID, "test-bom", TsArtifact.DEFAULT_VERSION), + WorkspaceModuleId.of(TsArtifact.DEFAULT_GROUP_ID, "app", TsArtifact.DEFAULT_VERSION), + WorkspaceModuleId.of(TsArtifact.DEFAULT_GROUP_ID, "ext-a", "1.0.1"), + WorkspaceModuleId.of(TsArtifact.DEFAULT_GROUP_ID, "ext-b", "1.0.0"))); + } } diff --git a/devtools/maven/src/main/java/io/quarkus/maven/QuarkusProjectStateMojoBase.java b/devtools/maven/src/main/java/io/quarkus/maven/QuarkusProjectStateMojoBase.java index e880065c8789c..3ec34fbaaf3e9 100644 --- a/devtools/maven/src/main/java/io/quarkus/maven/QuarkusProjectStateMojoBase.java +++ b/devtools/maven/src/main/java/io/quarkus/maven/QuarkusProjectStateMojoBase.java @@ -5,7 +5,6 @@ import java.nio.file.Path; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.List; import org.apache.maven.cli.transfer.QuietMavenTransferListener; @@ -49,20 +48,11 @@ public void doExecute(QuarkusProject quarkusProject, MessageWriter log) throws M throw new MojoExecutionException("This goal requires a Quarkus extension registry client to be enabled"); } - // to support profiles - final String emb = System.getProperty("quarkus.bootstrap.effective-model-builder"); - System.setProperty("quarkus.bootstrap.effective-model-builder", "true"); - final Collection createdDirs = ensureResolvable(new DefaultArtifact(project.getGroupId(), project.getArtifactId(), ArtifactCoords.TYPE_POM, project.getVersion())); try { processProjectState(quarkusProject); } finally { - if (emb == null) { - System.clearProperty("quarkus.bootstrap.effective-model-builder"); - } else { - System.setProperty("quarkus.bootstrap.effective-model-builder", emb); - } for (Path p : createdDirs) { IoUtils.recursiveDelete(p); } @@ -84,7 +74,7 @@ protected ApplicationModel resolveApplicationModel() throws MojoExecutionExcepti private Collection ensureResolvable(Artifact a) throws MojoExecutionException { final DependencyNode root; try { - root = artifactResolver().collectDependencies(a, Collections.emptyList()).getRoot(); + root = artifactResolver().collectDependencies(a, List.of()).getRoot(); } catch (Exception e) { throw new MojoExecutionException("Failed to collect dependencies of " + a, e); } @@ -155,6 +145,10 @@ protected MavenArtifactResolver initArtifactResolver() throws MojoExecutionExcep .setRemoteRepositories(repos) // To support multi-module projects that haven't been installed .setPreferPomsFromWorkspace(true) + // to support profiles + .setEffectiveModelBuilder(true) + // to initialize WorkspaceModule parents and BOM modules + .setWorkspaceModuleParentHierarchy(true) .build(); } catch (BootstrapMavenException e) { throw new MojoExecutionException("Failed to initialize Maven artifact resolver", e); diff --git a/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/model/ApplicationModel.java b/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/model/ApplicationModel.java index 10f2fb69487f4..dfebda76a2d00 100644 --- a/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/model/ApplicationModel.java +++ b/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/model/ApplicationModel.java @@ -51,13 +51,31 @@ default WorkspaceModule getApplicationModule() { } default Collection getWorkspaceModules() { - final Map modules = new HashMap<>(); + final Map result = new HashMap<>(); + collectModules(getAppArtifact().getWorkspaceModule(), result); for (ResolvedDependency d : getDependencies()) { - final WorkspaceModule module = d.getWorkspaceModule(); - if (module != null) { - modules.putIfAbsent(module.getId(), module); + collectModules(d.getWorkspaceModule(), result); + } + return result.values(); + } + + private static void collectModules(WorkspaceModule module, Map collected) { + if (module == null) { + return; + } + collected.putIfAbsent(module.getId(), module); + + WorkspaceModule parent = module.getParent(); + if (parent != null) { + collectModules(parent, collected); + } + + for (Dependency d : module.getDirectDependencyConstraints()) { + if (!Dependency.SCOPE_IMPORT.equals(d.getScope()) + || !(d instanceof ResolvedDependency)) { + continue; } + collectModules(((ResolvedDependency) d).getWorkspaceModule(), collected); } - return modules.values(); } } diff --git a/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/workspace/DefaultWorkspaceModule.java b/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/workspace/DefaultWorkspaceModule.java index 63d07fd6ef810..dd6b849576a34 100644 --- a/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/workspace/DefaultWorkspaceModule.java +++ b/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/workspace/DefaultWorkspaceModule.java @@ -108,6 +108,12 @@ public Builder setAdditionalTestClasspathElements(Collection elements) { return this; } + @Override + public Builder setParent(WorkspaceModule parent) { + DefaultWorkspaceModule.this.parent = parent; + return this; + } + @Override public WorkspaceModule build() { final DefaultWorkspaceModule module = DefaultWorkspaceModule.this; @@ -176,6 +182,11 @@ public Collection getTestClasspathDependencyExclusions() { public Collection getAdditionalTestClasspathElements() { return DefaultWorkspaceModule.this.additionalTestClasspathElements; } + + @Override + public WorkspaceModule getParent() { + return parent; + } } private WorkspaceModuleId id; @@ -187,6 +198,7 @@ public Collection getAdditionalTestClasspathElements() { private List directDeps; private Collection testClasspathDependencyExclusions = List.of(); private Collection additionalTestClasspathElements = List.of(); + private WorkspaceModule parent; private DefaultWorkspaceModule() { } @@ -270,6 +282,11 @@ public Collection getAdditionalTestClasspathElements() { return additionalTestClasspathElements; } + @Override + public WorkspaceModule getParent() { + return parent; + } + @Override public Mutable mutable() { return new DefaultWorkspaceModule(this).new Builder(); diff --git a/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/workspace/WorkspaceModule.java b/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/workspace/WorkspaceModule.java index 304629d21a14e..dd00e3ee1fb9e 100644 --- a/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/workspace/WorkspaceModule.java +++ b/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/workspace/WorkspaceModule.java @@ -59,6 +59,8 @@ default PathTree getContentTree(String classifier) { Collection getAdditionalTestClasspathElements(); + WorkspaceModule getParent(); + Mutable mutable(); interface Mutable extends WorkspaceModule { @@ -85,6 +87,8 @@ interface Mutable extends WorkspaceModule { Mutable setAdditionalTestClasspathElements(Collection elements); + Mutable setParent(WorkspaceModule parent); + WorkspaceModule build(); default Mutable mutable() { diff --git a/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/maven/dependency/ArtifactDependency.java b/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/maven/dependency/ArtifactDependency.java index 6b4fe8e6c1efe..60d95c55395dc 100644 --- a/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/maven/dependency/ArtifactDependency.java +++ b/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/maven/dependency/ArtifactDependency.java @@ -17,7 +17,7 @@ public static Dependency of(String groupId, String artifactId, String version) { public ArtifactDependency(String groupId, String artifactId, String classifier, String type, String version) { super(groupId, artifactId, classifier, type, version); - this.scope = "compile"; + this.scope = SCOPE_COMPILE; flags = 0; } @@ -29,7 +29,7 @@ public ArtifactDependency(String groupId, String artifactId, String classifier, } public ArtifactDependency(ArtifactCoords coords, int... flags) { - this(coords, "compile", flags); + this(coords, SCOPE_COMPILE, flags); } public ArtifactDependency(ArtifactCoords coords, String scope, int... flags) { diff --git a/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/maven/dependency/Dependency.java b/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/maven/dependency/Dependency.java index fa93b39caa716..a29da99d679ec 100644 --- a/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/maven/dependency/Dependency.java +++ b/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/maven/dependency/Dependency.java @@ -2,6 +2,9 @@ public interface Dependency extends ArtifactCoords { + String SCOPE_COMPILE = "compile"; + String SCOPE_IMPORT = "import"; + public static Dependency of(String groupId, String artifactId) { return new ArtifactDependency(groupId, artifactId, null, ArtifactCoords.TYPE_JAR, null); } @@ -11,7 +14,7 @@ public static Dependency of(String groupId, String artifactId, String version) { } public static Dependency pomImport(String groupId, String artifactId, String version) { - return new ArtifactDependency(groupId, artifactId, null, ArtifactCoords.TYPE_POM, version, "import", false); + return new ArtifactDependency(groupId, artifactId, null, ArtifactCoords.TYPE_POM, version, SCOPE_IMPORT, false); } String getScope(); diff --git a/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/jbang/JBangDevModeLauncherImpl.java b/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/jbang/JBangDevModeLauncherImpl.java index f21bfdbbe428d..9c71629f8fc6f 100644 --- a/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/jbang/JBangDevModeLauncherImpl.java +++ b/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/jbang/JBangDevModeLauncherImpl.java @@ -8,7 +8,6 @@ import io.quarkus.maven.dependency.ArtifactCoords; import io.quarkus.maven.dependency.ArtifactDependency; import io.quarkus.maven.dependency.Dependency; -import io.quarkus.maven.dependency.GACTV; import io.quarkus.maven.dependency.ResolvedArtifactDependency; import io.quarkus.maven.dependency.ResolvedDependency; import io.quarkus.maven.dependency.ResolvedDependencyBuilder; @@ -100,7 +99,7 @@ public static Closeable main(String... args) { .setMode(QuarkusBootstrap.Mode.DEV) .setTargetDirectory(targetClasses) .setAppArtifact(appArtifact) - .setManagingProject(new GACTV("io.quarkus", "quarkus-bom", "", "pom", getQuarkusVersion())) + .setManagingProject(ArtifactCoords.pom("io.quarkus", "quarkus-bom", getQuarkusVersion())) .setForcedDependencies(deps.entrySet().stream().map(s -> { String[] parts = s.getKey().split(":"); Dependency artifact; diff --git a/independent-projects/bootstrap/core/src/test/java/io/quarkus/bootstrap/resolver/TsArtifact.java b/independent-projects/bootstrap/core/src/test/java/io/quarkus/bootstrap/resolver/TsArtifact.java index 75be008745e54..aab7d0c0f8bd5 100644 --- a/independent-projects/bootstrap/core/src/test/java/io/quarkus/bootstrap/resolver/TsArtifact.java +++ b/independent-projects/bootstrap/core/src/test/java/io/quarkus/bootstrap/resolver/TsArtifact.java @@ -48,6 +48,14 @@ public static TsArtifact jar(String artifactId, String version) { return new TsArtifact(DEFAULT_GROUP_ID, artifactId, EMPTY, TYPE_JAR, version); } + public static TsArtifact pom(String artifactId) { + return new TsArtifact(DEFAULT_GROUP_ID, artifactId, EMPTY, TYPE_POM, DEFAULT_VERSION); + } + + public static TsArtifact pom(String artifactId, String version) { + return new TsArtifact(DEFAULT_GROUP_ID, artifactId, EMPTY, TYPE_POM, version); + } + public static TsArtifact pom(String groupId, String artifactId, String version) { return new TsArtifact(groupId, artifactId, EMPTY, TYPE_POM, version); } diff --git a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/BootstrapAppModelResolver.java b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/BootstrapAppModelResolver.java index d61a8ace4792e..7f0dc13be3ea9 100644 --- a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/BootstrapAppModelResolver.java +++ b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/BootstrapAppModelResolver.java @@ -41,6 +41,7 @@ import org.eclipse.aether.resolution.ArtifactResolutionException; import org.eclipse.aether.resolution.ArtifactResult; import org.eclipse.aether.resolution.VersionRangeResult; +import org.eclipse.aether.util.artifact.JavaScopes; import org.eclipse.aether.util.graph.visitor.TreeDependencyVisitor; import org.eclipse.aether.version.Version; @@ -202,7 +203,7 @@ public ApplicationModel resolveModel(WorkspaceModule module) final Map managedMap = new HashMap<>(); for (io.quarkus.maven.dependency.Dependency d : module.getDirectDependencyConstraints()) { - if (d.getScope().equals("import")) { + if (io.quarkus.maven.dependency.Dependency.SCOPE_IMPORT.equals(d.getScope())) { mvn.resolveDescriptor(toAetherArtifact(d)).getManagedDependencies() .forEach(dep -> managedMap.putIfAbsent(getKey(dep.getArtifact()), dep)); } else { @@ -289,9 +290,9 @@ private Set getExcludedScopes() { return Set.of(); } if (devmode) { - return Set.of("test"); + return Set.of(JavaScopes.TEST); } - return Set.of("provided", "test"); + return Set.of(JavaScopes.PROVIDED, JavaScopes.TEST); } private ApplicationModel buildAppModel(ResolvedDependency appArtifact, CollectRequest collectRtDepsRequest, @@ -335,7 +336,8 @@ private io.quarkus.maven.dependency.ResolvedDependency resolve(ArtifactCoords ap } final WorkspaceModule resolvedModule = mvn.getProjectModuleResolver() == null ? null - : mvn.getProjectModuleResolver().getProjectModule(appArtifact.getGroupId(), appArtifact.getArtifactId()); + : mvn.getProjectModuleResolver().getProjectModule(appArtifact.getGroupId(), appArtifact.getArtifactId(), + appArtifact.getVersion()); if (resolvedArtifact != null && resolvedModule == null) { return resolvedArtifact; } @@ -523,5 +525,4 @@ private ArtifactDescriptorResult resolveDescriptor(Artifact artifact, List config() { return new BootstrapMavenContextConfig<>(); @@ -160,6 +160,7 @@ public BootstrapMavenContext(BootstrapMavenContextConfig config) } this.preferPomsFromWorkspace = config.preferPomsFromWorkspace; this.effectiveModelBuilder = config.effectiveModelBuilder; + this.wsModuleParentHierarchy = config.wsModuleParentHierarchy; this.userSettings = config.userSettings; if (config.currentProject != null) { this.currentProject = config.currentProject; @@ -187,8 +188,8 @@ public ArtifactCoords getCurrentProjectArtifact(String extension) throws Bootstr if (model == null) { return null; } - return new GACTV(ModelUtils.getGroupId(model), model.getArtifactId(), "", extension, - ModelUtils.getVersion(model)); + return ArtifactCoords.of(ModelUtils.getGroupId(model), model.getArtifactId(), ArtifactCoords.DEFAULT_CLASSIFIER, + extension, ModelUtils.getVersion(model)); } public LocalProject getCurrentProject() { @@ -566,11 +567,11 @@ private List resolveCurrentProjectRepos(List if (model == null) { return repos; } - projectArtifact = new DefaultArtifact(ModelUtils.getGroupId(model), model.getArtifactId(), null, "pom", - ModelUtils.getVersion(model)); + projectArtifact = new DefaultArtifact(ModelUtils.getGroupId(model), model.getArtifactId(), + ArtifactCoords.DEFAULT_CLASSIFIER, ArtifactCoords.TYPE_POM, ModelUtils.getVersion(model)); } else { - projectArtifact = new DefaultArtifact(currentProject.getGroupId(), currentProject.getArtifactId(), null, "pom", - currentProject.getVersion()); + projectArtifact = new DefaultArtifact(currentProject.getGroupId(), currentProject.getArtifactId(), + ArtifactCoords.DEFAULT_CLASSIFIER, ArtifactCoords.TYPE_POM, currentProject.getVersion()); } final List rawRepos; @@ -791,14 +792,14 @@ private Path resolveCurrentPom() { // check whether an alternate pom was provided as a CLI arg final String cliPomName = getCliOptions().getOptionValue(BootstrapMavenOptions.ALTERNATE_POM_FILE); if (cliPomName != null) { - alternatePom = Paths.get(cliPomName); + alternatePom = Path.of(cliPomName); } } final String basedirProp = PropertyUtils.getProperty(BASEDIR); if (basedirProp != null) { // this is the actual current project dir - return getPomForDirOrNull(Paths.get(basedirProp), alternatePom); + return getPomForDirOrNull(Path.of(basedirProp), alternatePom); } // we are not in the context of a Maven build @@ -807,7 +808,7 @@ private Path resolveCurrentPom() { } // trying the current dir as the basedir - final Path basedir = Paths.get("").normalize().toAbsolutePath(); + final Path basedir = Path.of("").normalize().toAbsolutePath(); if (alternatePom != null) { return pomXmlOrNull(basedir.resolve(alternatePom)); } @@ -851,7 +852,7 @@ public Path getCurrentProjectBaseDir() { return currentProject.getDir(); } final String basedirProp = PropertyUtils.getProperty(BASEDIR); - return basedirProp == null ? Paths.get("").normalize().toAbsolutePath() : Paths.get(basedirProp); + return basedirProp == null ? Path.of("").normalize().toAbsolutePath() : Paths.get(basedirProp); } public Path getRootProjectBaseDir() { @@ -874,6 +875,10 @@ public boolean isEffectiveModelBuilder() { return effectiveModelBuilder; } + public boolean isWorkspaceModuleParentHierarchy() { + return wsModuleParentHierarchy == null ? false : wsModuleParentHierarchy; + } + static final String BOOTSTRAP_MAVEN_REPOS = "BOOTSTRAP_MAVEN_REPOS"; static final String BOOTSTRAP_MAVEN_REPO_PREFIX = "BOOTSTRAP_MAVEN_REPO_"; static final String URL_SUFFIX = "_URL"; diff --git a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/BootstrapMavenContextConfig.java b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/BootstrapMavenContextConfig.java index b38ed5de486cb..fb3e218374916 100644 --- a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/BootstrapMavenContextConfig.java +++ b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/BootstrapMavenContextConfig.java @@ -30,6 +30,7 @@ public class BootstrapMavenContextConfig + * + * @param wsModuleParentHierarchy whether to initialize parents for {@link io.quarkus.bootstrap.workspace.WorkspaceModule} + * @return this instance + */ + @SuppressWarnings("unchecked") + public T setWorkspaceModuleParentHierarchy(boolean wsModuleParentHierarchy) { + this.wsModuleParentHierarchy = wsModuleParentHierarchy; + return (T) this; + } + private BootstrapMavenOptions getInitializedCliOptions() { return cliOptions == null ? cliOptions = BootstrapMavenOptions.newInstance() : cliOptions; } diff --git a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/BuildDependencyGraphVisitor.java b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/BuildDependencyGraphVisitor.java index 4cb0251ac4971..ff7ae17b067eb 100644 --- a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/BuildDependencyGraphVisitor.java +++ b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/BuildDependencyGraphVisitor.java @@ -145,7 +145,8 @@ private void visitLeave(DependencyNode node) throws BootstrapMavenException { } WorkspaceModule module = null; if (resolver.getProjectModuleResolver() != null) { - module = resolver.getProjectModuleResolver().getProjectModule(artifact.getGroupId(), artifact.getArtifactId()); + module = resolver.getProjectModuleResolver().getProjectModule(artifact.getGroupId(), artifact.getArtifactId(), + artifact.getVersion()); if (module != null) { flags |= DependencyFlags.WORKSPACE_MODULE; } diff --git a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/workspace/LocalProject.java b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/workspace/LocalProject.java index 7679c197e3edd..0ecf5f23b6001 100644 --- a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/workspace/LocalProject.java +++ b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/workspace/LocalProject.java @@ -13,6 +13,7 @@ import io.quarkus.maven.dependency.GAV; import io.quarkus.maven.dependency.ResolvedArtifactDependency; import io.quarkus.maven.dependency.ResolvedDependency; +import io.quarkus.maven.dependency.ResolvedDependencyBuilder; import io.quarkus.paths.DirectoryPathTree; import io.quarkus.paths.PathCollection; import io.quarkus.paths.PathFilter; @@ -23,9 +24,9 @@ import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.LinkedHashSet; import java.util.List; +import java.util.Map; import java.util.function.Function; import java.util.stream.Collectors; import org.apache.maven.model.Build; @@ -138,7 +139,8 @@ static Path locateCurrentProjectPom(Path path, boolean required) throws Bootstra private final LocalWorkspace workspace; final List modules = new ArrayList<>(0); private final ModelBuildingResult modelBuildingResult; - private WorkspaceModule module; + private volatile LocalProject parent; + private volatile WorkspaceModule module; LocalProject(ModelBuildingResult modelBuildingResult, LocalWorkspace workspace) { this.rawModel = modelBuildingResult.getRawModel(); @@ -175,6 +177,9 @@ static Path locateCurrentProjectPom(Path path, boolean required) throws Bootstra } public LocalProject getLocalParent() { + if (parent != null) { + return parent; + } if (workspace == null) { return null; } @@ -182,7 +187,7 @@ public LocalProject getLocalParent() { if (parent == null) { return null; } - return workspace.getProject(parent.getGroupId(), parent.getArtifactId()); + return this.parent = workspace.getProject(parent.getGroupId(), parent.getArtifactId()); } public String getGroupId() { @@ -247,7 +252,7 @@ public Path getSourcesDir() { } public PathCollection getResourcesSourcesDirs() { - final List resources = rawModel.getBuild() == null ? Collections.emptyList() + final List resources = rawModel.getBuild() == null ? List.of() : rawModel.getBuild().getResources(); if (resources.isEmpty()) { return PathList.of(resolveRelativeToBaseDir(null, "src/main/resources")); @@ -259,7 +264,7 @@ public PathCollection getResourcesSourcesDirs() { } public PathCollection getTestResourcesSourcesDirs() { - final List resources = rawModel.getBuild() == null ? Collections.emptyList() + final List resources = rawModel.getBuild() == null ? List.of() : rawModel.getBuild().getTestResources(); if (resources.isEmpty()) { return PathList.of(resolveRelativeToBaseDir(null, "src/test/resources")); @@ -330,107 +335,139 @@ private static String configuredBuildDir(LocalProject project, Function list = new ArrayList<>(excludes.length); - for (Xpp3Dom exclude : excludes) { - list.add(exclude.getValue()); + } else if (plugin.getArtifactId().equals("maven-surefire-plugin") && plugin.getConfiguration() != null) { + Object config = plugin.getConfiguration(); + if (config == null || !(config instanceof Xpp3Dom)) { + continue; + } + Xpp3Dom dom = (Xpp3Dom) config; + final Xpp3Dom depExcludes = dom.getChild("classpathDependencyExcludes"); + if (depExcludes != null) { + final Xpp3Dom[] excludes = depExcludes.getChildren("classpathDependencyExclude"); + if (excludes != null) { + final List list = new ArrayList<>(excludes.length); + for (Xpp3Dom exclude : excludes) { + list.add(exclude.getValue()); + } + moduleBuilder.setTestClasspathDependencyExclusions(list); } - moduleBuilder.setTestClasspathDependencyExclusions(list); } - } - final Xpp3Dom additionalElements = dom.getChild("additionalClasspathElements"); - if (additionalElements != null) { - final Xpp3Dom[] elements = additionalElements.getChildren("additionalClasspathElement"); - if (elements != null) { - final List list = new ArrayList<>(elements.length); - for (Xpp3Dom element : elements) { - for (String s : element.getValue().split(",")) { - list.add(stripProjectBasedirPrefix(s, PROJECT_BASEDIR)); + final Xpp3Dom additionalElements = dom.getChild("additionalClasspathElements"); + if (additionalElements != null) { + final Xpp3Dom[] elements = additionalElements.getChildren("additionalClasspathElement"); + if (elements != null) { + final List list = new ArrayList<>(elements.length); + for (Xpp3Dom element : elements) { + for (String s : element.getValue().split(",")) { + list.add(stripProjectBasedirPrefix(s, PROJECT_BASEDIR)); + } } + moduleBuilder.setAdditionalTestClasspathElements(list); } - moduleBuilder.setAdditionalTestClasspathElements(list); } } } } - } - if (addDefaultSourceSet) { - moduleBuilder.addArtifactSources(new DefaultArtifactSources(ArtifactSources.MAIN, - Collections.singletonList(new DefaultSourceDir(getSourcesSourcesDir(), getClassesDir())), - collectMainResources(null))); - } - if (!moduleBuilder.hasTestSources()) { - moduleBuilder.addArtifactSources(new DefaultArtifactSources(ArtifactSources.TEST, - Collections.singletonList( - new DefaultSourceDir(getTestSourcesSourcesDir(), getTestClassesDir())), - collectTestResources(null))); + if (addDefaultSourceSet) { + moduleBuilder.addArtifactSources(new DefaultArtifactSources(ArtifactSources.MAIN, + List.of(new DefaultSourceDir(getSourcesSourcesDir(), getClassesDir())), + collectMainResources(null))); + } + if (!moduleBuilder.hasTestSources()) { + moduleBuilder.addArtifactSources(new DefaultArtifactSources(ArtifactSources.TEST, + List.of(new DefaultSourceDir(getTestSourcesSourcesDir(), getTestClassesDir())), + collectTestResources(null))); + } } - moduleBuilder.setBuildFile(getRawModel().getPomFile().toPath()); - moduleBuilder.setDependencyConstraints(getRawModel().getDependencyManagement() == null ? Collections.emptyList() - : toArtifactDependencies(getRawModel().getDependencyManagement().getDependencies())); + if (ctx != null && ctx.isWorkspaceModuleParentHierarchy()) { + final LocalProject parent = getLocalParent(); + if (parent != null) { + moduleBuilder.setParent(parent.toWorkspaceModule(ctx)); + } + moduleBuilder.setDependencyConstraints(getRawModel().getDependencyManagement() == null ? List.of() + : toArtifactDependencies(getRawModel().getDependencyManagement().getDependencies(), ctx)); + } - final Model model = modelBuildingResult == null ? rawModel : modelBuildingResult.getEffectiveModel(); - moduleBuilder.setDependencies(toArtifactDependencies(model.getDependencies())); + moduleBuilder.setDependencies(toArtifactDependencies(model.getDependencies(), ctx)); return this.module = moduleBuilder.build(); } - private List toArtifactDependencies(final List rawModelDeps) { + private List toArtifactDependencies(List rawModelDeps, + BootstrapMavenContext ctx) { if (rawModelDeps.isEmpty()) { - return Collections.emptyList(); + return List.of(); } - final List directDeps = new ArrayList<>(rawModelDeps.size()); + final List result = new ArrayList<>(rawModelDeps.size()); for (Dependency d : rawModelDeps) { - directDeps.add(new ArtifactDependency(resolveElementValue(d.getGroupId()), - resolveElementValue(d.getArtifactId()), resolveElementValue(d.getClassifier()), - resolveElementValue(d.getType()), - resolveElementValue(d.getVersion()), d.getScope(), d.isOptional())); + final String groupId = resolveElementValue(d.getGroupId()); + final String artifactId = resolveElementValue(d.getArtifactId()); + final LocalProject bomProject; + if (workspace != null + && ctx != null && ctx.isWorkspaceModuleParentHierarchy() + && io.quarkus.maven.dependency.Dependency.SCOPE_IMPORT.equals(d.getScope()) + && ArtifactCoords.TYPE_POM.equals(d.getType()) + && (bomProject = workspace.getProject(groupId, artifactId)) != null + && bomProject.getVersion().equals(d.getVersion())) { + result.add(ResolvedDependencyBuilder.newInstance() + .setGroupId(groupId) + .setArtifactId(artifactId) + .setType(ArtifactCoords.TYPE_POM) + .setScope(io.quarkus.maven.dependency.Dependency.SCOPE_IMPORT) + .setVersion(resolveElementValue(d.getVersion())) + .setWorkspaceModule(bomProject.toWorkspaceModule(ctx)) + .setResolvedPath(bomProject.getRawModel().getPomFile().toPath()) + .build()); + } else { + result.add(new ArtifactDependency(groupId, artifactId, resolveElementValue(d.getClassifier()), + resolveElementValue(d.getType()), resolveElementValue(d.getVersion()), d.getScope(), d.isOptional())); + } } - return directDeps; + return result; } private String resolveElementValue(String elementValue) { @@ -451,10 +488,10 @@ private DefaultArtifactSources processJarPluginExecutionConfig(Object config, bo final List excludes = collectChildValues(dom.getChild("excludes")); final PathFilter filter = includes == null && excludes == null ? null : new PathFilter(includes, excludes); final String classifier = getClassifier(dom, test); - final Collection sources = Collections.singletonList( + final Collection sources = List.of( new DefaultSourceDir(new DirectoryPathTree(test ? getTestSourcesSourcesDir() : getSourcesSourcesDir()), new DirectoryPathTree(test ? getTestClassesDir() : getClassesDir(), filter), - Collections.emptyMap())); + Map.of())); final Collection resources = test ? collectTestResources(filter) : collectMainResources(filter); return new DefaultArtifactSources(classifier, sources, resources); } @@ -477,13 +514,13 @@ private static String getClassifier(Xpp3Dom dom, boolean test) { } private Collection collectMainResources(PathFilter filter) { - final List resources = rawModel.getBuild() == null ? Collections.emptyList() + final List resources = rawModel.getBuild() == null ? List.of() : rawModel.getBuild().getResources(); final Path classesDir = getClassesDir(); if (resources.isEmpty()) { - return Collections.singletonList(new DefaultSourceDir( + return List.of(new DefaultSourceDir( new DirectoryPathTree(resolveRelativeToBaseDir(null, "src/main/resources")), - new DirectoryPathTree(classesDir, filter), Collections.emptyMap())); + new DirectoryPathTree(classesDir, filter), Map.of())); } final List sourceDirs = new ArrayList<>(resources.size()); for (Resource r : resources) { @@ -493,19 +530,19 @@ private Collection collectMainResources(PathFilter filter) { new DirectoryPathTree((r.getTargetPath() == null ? classesDir : classesDir.resolve(stripProjectBasedirPrefix(r.getTargetPath(), PROJECT_OUTPUT_DIR))), filter), - Collections.emptyMap())); + Map.of())); } return sourceDirs; } private Collection collectTestResources(PathFilter filter) { - final List resources = rawModel.getBuild() == null ? Collections.emptyList() + final List resources = rawModel.getBuild() == null ? List.of() : rawModel.getBuild().getTestResources(); final Path testClassesDir = getTestClassesDir(); if (resources.isEmpty()) { - return Collections.singletonList(new DefaultSourceDir( + return List.of(new DefaultSourceDir( new DirectoryPathTree(resolveRelativeToBaseDir(null, "src/test/resources")), - new DirectoryPathTree(testClassesDir, filter), Collections.emptyMap())); + new DirectoryPathTree(testClassesDir, filter), Map.of())); } final List sourceDirs = new ArrayList<>(resources.size()); for (Resource r : resources) { @@ -515,7 +552,7 @@ private Collection collectTestResources(PathFilter filter) { new DirectoryPathTree((r.getTargetPath() == null ? testClassesDir : testClassesDir.resolve(stripProjectBasedirPrefix(r.getTargetPath(), PROJECT_OUTPUT_DIR))), filter), - Collections.emptyMap())); + Map.of())); } return sourceDirs; } diff --git a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/workspace/LocalWorkspace.java b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/workspace/LocalWorkspace.java index bf547ece2ccb3..479c110a3c593 100644 --- a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/workspace/LocalWorkspace.java +++ b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/workspace/LocalWorkspace.java @@ -242,8 +242,8 @@ void setBootstrapMavenContext(BootstrapMavenContext mvnCtx) { } @Override - public WorkspaceModule getProjectModule(ArtifactKey key) { - final LocalProject project = getProject(key); - return project == null ? null : project.toWorkspaceModule(); + public WorkspaceModule getProjectModule(String groupId, String artifactId, String version) { + final LocalProject project = getProject(groupId, artifactId); + return project == null || !project.getVersion().equals(version) ? null : project.toWorkspaceModule(mvnCtx); } } diff --git a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/workspace/ProjectModuleResolver.java b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/workspace/ProjectModuleResolver.java index 17b1524f79f18..49afc776452da 100644 --- a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/workspace/ProjectModuleResolver.java +++ b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/workspace/ProjectModuleResolver.java @@ -1,13 +1,8 @@ package io.quarkus.bootstrap.resolver.maven.workspace; import io.quarkus.bootstrap.workspace.WorkspaceModule; -import io.quarkus.maven.dependency.ArtifactKey; public interface ProjectModuleResolver { - default WorkspaceModule getProjectModule(String groupId, String artifactId) { - return getProjectModule(ArtifactKey.ga(groupId, artifactId)); - } - - WorkspaceModule getProjectModule(ArtifactKey key); + WorkspaceModule getProjectModule(String groupId, String artifactId, String version); } diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/buildfile/MavenBuildFile.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/buildfile/MavenBuildFile.java index aa32855538b2f..11589e2d8bad5 100644 --- a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/buildfile/MavenBuildFile.java +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/buildfile/MavenBuildFile.java @@ -55,7 +55,7 @@ public void writeToDisk() throws IOException { @Override protected boolean importBom(ArtifactCoords coords) { - if (!"pom".equalsIgnoreCase(coords.getType())) { + if (!ArtifactCoords.TYPE_POM.equals(coords.getType())) { throw new IllegalArgumentException(coords + " is not a POM"); } Model model = getModel(); @@ -63,7 +63,7 @@ protected boolean importBom(ArtifactCoords coords) { d.setGroupId(coords.getGroupId()); d.setArtifactId(coords.getArtifactId()); d.setType(coords.getType()); - d.setScope("import"); + d.setScope(io.quarkus.maven.dependency.Dependency.SCOPE_IMPORT); DependencyManagement dependencyManagement = model.getDependencyManagement(); if (dependencyManagement == null) { dependencyManagement = new DependencyManagement(); @@ -93,8 +93,8 @@ protected boolean addDependency(ArtifactCoords coords, boolean managed) { d.setClassifier(coords.getClassifier()); } d.setType(coords.getType()); - if ("pom".equalsIgnoreCase(coords.getType())) { - d.setScope("import"); + if (ArtifactCoords.TYPE_POM.equals(coords.getType())) { + d.setScope(io.quarkus.maven.dependency.Dependency.SCOPE_IMPORT); DependencyManagement dependencyManagement = model.getDependencyManagement(); if (dependencyManagement == null) { dependencyManagement = new DependencyManagement(); diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/buildfile/MavenProjectBuildFile.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/buildfile/MavenProjectBuildFile.java index fb90579030408..459d5a2cbb774 100644 --- a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/buildfile/MavenProjectBuildFile.java +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/buildfile/MavenProjectBuildFile.java @@ -212,7 +212,7 @@ public BuildTool getBuildTool() { @Override protected boolean importBom(ArtifactCoords coords) { - if (!"pom".equalsIgnoreCase(coords.getType())) { + if (!ArtifactCoords.TYPE_POM.equals(coords.getType())) { throw new IllegalArgumentException(coords + " is not a POM"); } final String depKey = depKey(coords.getGroupId(), coords.getArtifactId(), coords.getClassifier(), coords.getType()); @@ -222,14 +222,14 @@ protected boolean importBom(ArtifactCoords coords) { coords.getArtifactId().equals(getProperty("quarkus.platform.artifact-id")) ? "${quarkus.platform.artifact-id}" : coords.getArtifactId(), - "pom", "${quarkus.platform.version}"); + ArtifactCoords.TYPE_POM, "${quarkus.platform.version}"); } final Dependency d = new Dependency(); d.setGroupId(coords.getGroupId()); d.setArtifactId(coords.getArtifactId()); d.setType(coords.getType()); - d.setScope("import"); + d.setScope(io.quarkus.maven.dependency.Dependency.SCOPE_IMPORT); d.setVersion(coords.getVersion()); DependencyManagement dependencyManagement = model().getDependencyManagement(); if (dependencyManagement == null) { @@ -238,7 +238,7 @@ protected boolean importBom(ArtifactCoords coords) { } if (dependencyManagement.getDependencies() .stream() - .filter(t -> t.getScope().equals("import")) + .filter(t -> t.getScope().equals(io.quarkus.maven.dependency.Dependency.SCOPE_IMPORT)) .noneMatch(thisDep -> depKey.equals(resolveKey(thisDep)))) { dependencyManagement.addDependency(d); // the effective managed dependencies set may already include it @@ -263,8 +263,8 @@ protected boolean addDependency(ArtifactCoords coords, boolean managed) { d.setClassifier(coords.getClassifier()); } d.setType(coords.getType()); - if ("pom".equalsIgnoreCase(coords.getType())) { - d.setScope("import"); + if (ArtifactCoords.TYPE_POM.equals(coords.getType())) { + d.setScope(io.quarkus.maven.dependency.Dependency.SCOPE_IMPORT); DependencyManagement dependencyManagement = model().getDependencyManagement(); if (dependencyManagement == null) { dependencyManagement = new DependencyManagement(); diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/maven/utilities/PomTransformer.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/maven/utilities/PomTransformer.java index 93f8e99c5a34a..ca19830d9d913 100644 --- a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/maven/utilities/PomTransformer.java +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/maven/utilities/PomTransformer.java @@ -1,5 +1,7 @@ package io.quarkus.maven.utilities; +import io.quarkus.maven.dependency.ArtifactCoords; +import io.quarkus.maven.dependency.Dependency; import java.io.IOException; import java.io.StringReader; import java.io.StringWriter; @@ -552,7 +554,7 @@ public static Transformation addManagedPlugin(Plugin plugin) { public static class Gavtcs { public static Gavtcs importBom(String groupId, String artifactId, String version) { - return new Gavtcs(groupId, artifactId, version, "pom", null, "import"); + return new Gavtcs(groupId, artifactId, version, ArtifactCoords.TYPE_POM, null, Dependency.SCOPE_IMPORT); } public static Gavtcs of(String rawGavtcs) { diff --git a/integration-tests/gradle/src/test/java/io/quarkus/gradle/builder/QuarkusModelBuilderTest.java b/integration-tests/gradle/src/test/java/io/quarkus/gradle/builder/QuarkusModelBuilderTest.java index 15d1cec60f306..ccb64db50f69c 100644 --- a/integration-tests/gradle/src/test/java/io/quarkus/gradle/builder/QuarkusModelBuilderTest.java +++ b/integration-tests/gradle/src/test/java/io/quarkus/gradle/builder/QuarkusModelBuilderTest.java @@ -34,7 +34,7 @@ public void shouldLoadSimpleModuleTestModel() throws URISyntaxException, IOExcep assertNotNull(quarkusModel); assertNotNull(quarkusModel.getApplicationModule()); - assertThat(quarkusModel.getWorkspaceModules()).isEmpty(); + assertThat(quarkusModel.getWorkspaceModules().size()).isEqualTo(1); final ResolvedDependency appArtifact = quarkusModel.getAppArtifact(); assertThat(appArtifact).isNotNull(); @@ -50,7 +50,7 @@ public void shouldLoadSimpleModuleDevModel() throws URISyntaxException, IOExcept assertNotNull(quarkusModel); assertNotNull(quarkusModel.getApplicationModule()); - assertThat(quarkusModel.getWorkspaceModules()).isEmpty(); + assertThat(quarkusModel.getWorkspaceModules().size()).isEqualTo(1); final ResolvedDependency appArtifact = quarkusModel.getAppArtifact(); assertThat(appArtifact).isNotNull(); @@ -71,9 +71,10 @@ public void shouldLoadMultiModuleTestModel() throws URISyntaxException, IOExcept new File(projectDir, quarkusModel.getApplicationModule().getId().getArtifactId()), true); final Collection projectModules = quarkusModel.getWorkspaceModules(); - assertEquals(projectModules.size(), 1); + assertEquals(projectModules.size(), 2); for (WorkspaceModule p : projectModules) { - assertProjectModule(p, new File(projectDir, p.getId().getArtifactId()), false); + assertProjectModule(p, new File(projectDir, p.getId().getArtifactId()), + quarkusModel.getApplicationModule().getId().equals(p.getId())); } final ResolvedDependency appArtifact = quarkusModel.getAppArtifact(); @@ -104,9 +105,10 @@ public void shouldLoadMultiModuleDevModel() throws URISyntaxException, IOExcepti new File(projectDir, quarkusModel.getApplicationModule().getId().getArtifactId()), true); final Collection projectModules = quarkusModel.getWorkspaceModules(); - assertEquals(projectModules.size(), 1); + assertEquals(projectModules.size(), 2); for (WorkspaceModule p : projectModules) { - assertProjectModule(p, new File(projectDir, p.getId().getArtifactId()), false); + assertProjectModule(p, new File(projectDir, p.getId().getArtifactId()), + quarkusModel.getApplicationModule().getId().equals(p.getId())); } final ResolvedDependency appArtifact = quarkusModel.getAppArtifact();