diff --git a/core/deployment/src/main/java/io/quarkus/deployment/dev/testing/TestSupport.java b/core/deployment/src/main/java/io/quarkus/deployment/dev/testing/TestSupport.java index de8506d9e893d..3773e5467423e 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/dev/testing/TestSupport.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/dev/testing/TestSupport.java @@ -198,8 +198,10 @@ public void init() { //we always want to propagate parent first //so it is consistent. Some modules may not have quarkus dependencies //so they won't load junit parent first without this - for (var i : curatedApplication.getApplicationModel().getParentFirst()) { - builder.addParentFirstArtifact(i); + for (var i : curatedApplication.getApplicationModel().getDependencies()) { + if (i.isClassLoaderParentFirst()) { + builder.addParentFirstArtifact(i.getKey()); + } } var testCuratedApplication = builder // we want to re-discover the local dependencies with test scope .build() diff --git a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/JarResultBuildStep.java b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/JarResultBuildStep.java index 9486104637b4d..aaeec33f508e7 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/JarResultBuildStep.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/JarResultBuildStep.java @@ -83,6 +83,7 @@ import io.quarkus.fs.util.ZipUtils; import io.quarkus.maven.dependency.ArtifactKey; import io.quarkus.maven.dependency.Dependency; +import io.quarkus.maven.dependency.DependencyFlags; import io.quarkus.maven.dependency.GACT; import io.quarkus.maven.dependency.ResolvedDependency; import io.quarkus.paths.PathVisit; @@ -817,8 +818,12 @@ public void accept(Path path) { */ private Set getParentFirstKeys(CurateOutcomeBuildItem curateOutcomeBuildItem, ClassLoadingConfig classLoadingConfig) { - final Set parentFirstKeys = new HashSet<>( - curateOutcomeBuildItem.getApplicationModel().getRunnerParentFirst()); + final Set parentFirstKeys = new HashSet<>(); + curateOutcomeBuildItem.getApplicationModel().getDependencies().forEach(d -> { + if (d.isFlagSet(DependencyFlags.CLASSLOADER_RUNNER_PARENT_FIRST)) { + parentFirstKeys.add(d.getKey()); + } + }); classLoadingConfig.parentFirstArtifacts.ifPresent( parentFirstArtifacts -> { for (String artifact : parentFirstArtifacts) { diff --git a/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusDev.java b/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusDev.java index 63b8fbd7c5b84..8cc25aa9b50be 100644 --- a/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusDev.java +++ b/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusDev.java @@ -385,7 +385,6 @@ private QuarkusDevModeLauncher newLauncher() throws Exception { .setApplicationModel(appModel) .setApplicationRoot(PathsCollection.from(resourceDirs)) .setMode(QuarkusBootstrap.Mode.DEV) - .addParentFirstArtifacts(appModel.getParentFirst()) .build().getParentFirstArtifacts(); for (io.quarkus.maven.dependency.ResolvedDependency artifact : appModel.getDependencies()) { diff --git a/devtools/gradle/gradle-model/src/main/java/io/quarkus/gradle/dependency/ConditionalDependenciesEnabler.java b/devtools/gradle/gradle-model/src/main/java/io/quarkus/gradle/dependency/ConditionalDependenciesEnabler.java index d70a4861227ae..6ab5650d7b5a9 100644 --- a/devtools/gradle/gradle-model/src/main/java/io/quarkus/gradle/dependency/ConditionalDependenciesEnabler.java +++ b/devtools/gradle/gradle-model/src/main/java/io/quarkus/gradle/dependency/ConditionalDependenciesEnabler.java @@ -190,12 +190,12 @@ private boolean exist(List dependencies) { private boolean exists(Dependency dependency) { return existingArtifacts - .contains(ArtifactKey.gact(dependency.getGroup(), dependency.getName(), null, ArtifactCoords.TYPE_JAR)); + .contains(ArtifactKey.of(dependency.getGroup(), dependency.getName(), null, ArtifactCoords.TYPE_JAR)); } public boolean exists(ExtensionDependency dependency) { return existingArtifacts - .contains(ArtifactKey.gact(dependency.getGroup(), dependency.getName(), null, ArtifactCoords.TYPE_JAR)); + .contains(ArtifactKey.of(dependency.getGroup(), dependency.getName(), null, ArtifactCoords.TYPE_JAR)); } private static GACT getFeatureKey(ModuleVersionIdentifier version) { @@ -207,6 +207,6 @@ private static GACT getFeatureKey(Dependency version) { } private static ArtifactKey getKey(ResolvedArtifact a) { - return ArtifactKey.gact(a.getModuleVersion().getId().getGroup(), a.getName(), a.getClassifier(), a.getType()); + return ArtifactKey.of(a.getModuleVersion().getId().getGroup(), a.getName(), a.getClassifier(), a.getType()); } } diff --git a/devtools/gradle/gradle-model/src/main/java/io/quarkus/gradle/tooling/GradleApplicationModelBuilder.java b/devtools/gradle/gradle-model/src/main/java/io/quarkus/gradle/tooling/GradleApplicationModelBuilder.java index 6bfd7177c63af..967fdf7d48ab8 100644 --- a/devtools/gradle/gradle-model/src/main/java/io/quarkus/gradle/tooling/GradleApplicationModelBuilder.java +++ b/devtools/gradle/gradle-model/src/main/java/io/quarkus/gradle/tooling/GradleApplicationModelBuilder.java @@ -11,9 +11,7 @@ import java.util.Collection; import java.util.Collections; import java.util.HashSet; -import java.util.LinkedHashMap; import java.util.List; -import java.util.Map; import java.util.Properties; import java.util.Set; @@ -113,14 +111,10 @@ public Object buildAll(String modelName, ModelParameter parameter, Project proje .addReloadableWorkspaceModule(appArtifact.getKey()) .setPlatformImports(platformImports); - final Map appDependencies = new LinkedHashMap<>(); collectDependencies(classpathConfig.getResolvedConfiguration(), workspaceDiscovery, - project, appDependencies, modelBuilder, appArtifact.getWorkspaceModule().mutable()); - collectExtensionDependencies(project, deploymentConfig, appDependencies); + project, modelBuilder, appArtifact.getWorkspaceModule().mutable()); + collectExtensionDependencies(project, deploymentConfig, modelBuilder); - for (ResolvedDependencyBuilder d : appDependencies.values()) { - modelBuilder.addDependency(d.build()); - } return modelBuilder.build(); } @@ -169,7 +163,7 @@ private static void collectDestinationDirs(Collection sources, final } private void collectExtensionDependencies(Project project, Configuration deploymentConfiguration, - Map appDependencies) { + ApplicationModelBuilder modelBuilder) { final ResolvedConfiguration rc = deploymentConfiguration.getResolvedConfiguration(); for (ResolvedArtifact a : rc.getResolvedArtifacts()) { if (a.getId().getComponentIdentifier() instanceof ProjectComponentIdentifier) { @@ -178,15 +172,21 @@ private void collectExtensionDependencies(Project project, Configuration deploym final JavaPluginConvention javaExtension = projectDep == null ? null : projectDep.getConvention().findPlugin(JavaPluginConvention.class); SourceSet mainSourceSet = javaExtension.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME); - final ResolvedDependencyBuilder dep = appDependencies.computeIfAbsent( - toAppDependenciesKey(a.getModuleVersion().getId().getGroup(), a.getName(), a.getClassifier()), - k -> toDependency(a, mainSourceSet)); + ResolvedDependencyBuilder dep = modelBuilder.getDependency( + toAppDependenciesKey(a.getModuleVersion().getId().getGroup(), a.getName(), a.getClassifier())); + if (dep == null) { + dep = toDependency(a, mainSourceSet); + modelBuilder.addDependency(dep); + } dep.setDeploymentCp(); dep.clearFlag(DependencyFlags.RELOADABLE); } else if (isDependency(a)) { - final ResolvedDependencyBuilder dep = appDependencies.computeIfAbsent( - toAppDependenciesKey(a.getModuleVersion().getId().getGroup(), a.getName(), a.getClassifier()), - k -> toDependency(a)); + ResolvedDependencyBuilder dep = modelBuilder.getDependency( + toAppDependenciesKey(a.getModuleVersion().getId().getGroup(), a.getName(), a.getClassifier())); + if (dep == null) { + dep = toDependency(a); + modelBuilder.addDependency(dep); + } dep.setDeploymentCp(); dep.clearFlag(DependencyFlags.RELOADABLE); } @@ -194,8 +194,8 @@ private void collectExtensionDependencies(Project project, Configuration deploym } private void collectDependencies(ResolvedConfiguration configuration, - boolean workspaceDiscovery, Project project, Map appDependencies, - ApplicationModelBuilder modelBuilder, WorkspaceModule.Mutable wsModule) { + boolean workspaceDiscovery, Project project, ApplicationModelBuilder modelBuilder, + WorkspaceModule.Mutable wsModule) { final Set resolvedArtifacts = configuration.getResolvedArtifacts(); // if the number of artifacts is less than the number of files then probably @@ -206,7 +206,7 @@ private void collectDependencies(ResolvedConfiguration configuration, configuration.getFirstLevelModuleDependencies() .forEach(d -> { - collectDependencies(d, workspaceDiscovery, project, appDependencies, artifactFiles, new HashSet<>(), + collectDependencies(d, workspaceDiscovery, project, artifactFiles, new HashSet<>(), modelBuilder, wsModule, (byte) (COLLECT_TOP_EXTENSION_RUNTIME_NODES | COLLECT_DIRECT_DEPS | COLLECT_RELOADABLE_MODULES)); @@ -243,21 +243,20 @@ private void collectDependencies(ResolvedConfiguration configuration, .setDirect(true) .setRuntimeCp(); processQuarkusDependency(artifactBuilder, modelBuilder); - appDependencies.put(artifactBuilder.getKey(), artifactBuilder); + modelBuilder.addDependency(artifactBuilder); } } } private void collectDependencies(org.gradle.api.artifacts.ResolvedDependency resolvedDep, boolean workspaceDiscovery, - Project project, - Map appDependencies, Set artifactFiles, - Set processedModules, ApplicationModelBuilder modelBuilder, WorkspaceModule.Mutable parentModule, + Project project, Set artifactFiles, Set processedModules, ApplicationModelBuilder modelBuilder, + WorkspaceModule.Mutable parentModule, byte flags) { WorkspaceModule.Mutable projectModule = null; for (ResolvedArtifact a : resolvedDep.getModuleArtifacts()) { final ArtifactKey artifactKey = toAppDependenciesKey(a.getModuleVersion().getId().getGroup(), a.getName(), a.getClassifier()); - if (!isDependency(a) || appDependencies.containsKey(artifactKey)) { + if (!isDependency(a) || modelBuilder.getDependency(artifactKey) != null) { continue; } final ArtifactCoords depCoords = toArtifactCoords(a); @@ -320,7 +319,7 @@ private void collectDependencies(org.gradle.api.artifacts.ResolvedDependency res if (!isFlagOn(flags, COLLECT_RELOADABLE_MODULES)) { depBuilder.clearFlag(DependencyFlags.RELOADABLE); } - appDependencies.put(depBuilder.getKey(), depBuilder); + modelBuilder.addDependency(depBuilder); if (artifactFiles != null) { artifactFiles.add(a.getFile()); @@ -330,9 +329,8 @@ private void collectDependencies(org.gradle.api.artifacts.ResolvedDependency res processedModules.add(new GACT(resolvedDep.getModuleGroup(), resolvedDep.getModuleName())); for (org.gradle.api.artifacts.ResolvedDependency child : resolvedDep.getChildren()) { if (!processedModules.contains(new GACT(child.getModuleGroup(), child.getModuleName()))) { - collectDependencies(child, workspaceDiscovery, project, appDependencies, artifactFiles, processedModules, - modelBuilder, - projectModule, flags); + collectDependencies(child, workspaceDiscovery, project, artifactFiles, processedModules, + modelBuilder, projectModule, flags); } } } diff --git a/devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java b/devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java index 41c1f3b70c8b7..95af337ddf204 100644 --- a/devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java +++ b/devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java @@ -1084,7 +1084,6 @@ private QuarkusDevModeLauncher newLauncher() throws Exception { .setApplicationModel(appModel) .setApplicationRoot(PathsCollection.from(resourceDirs)) .setMode(QuarkusBootstrap.Mode.DEV) - .addParentFirstArtifacts(appModel.getParentFirst()) .build().getParentFirstArtifacts(); for (Artifact appDep : project.getArtifacts()) { diff --git a/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/model/AppModel.java b/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/model/AppModel.java index ea3a4a444b92c..f80655fed5429 100644 --- a/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/model/AppModel.java +++ b/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/model/AppModel.java @@ -26,6 +26,11 @@ @Deprecated public class AppModel implements ApplicationModel, Serializable { + public static final String PARENT_FIRST_ARTIFACTS = "parent-first-artifacts"; + public static final String RUNNER_PARENT_FIRST_ARTIFACTS = "runner-parent-first-artifacts"; + public static final String EXCLUDED_ARTIFACTS = "excluded-artifacts"; + public static final String LESSER_PRIORITY_ARTIFACTS = "lesser-priority-artifacts"; + private static final long serialVersionUID = 6728602422991848950L; private static final Logger log = Logger.getLogger(AppModel.class); 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 e3c8ee185fe0e..10f2fb69487f4 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 @@ -14,11 +14,6 @@ public interface ApplicationModel { - String PARENT_FIRST_ARTIFACTS = "parent-first-artifacts"; - String RUNNER_PARENT_FIRST_ARTIFACTS = "runner-parent-first-artifacts"; - String EXCLUDED_ARTIFACTS = "excluded-artifacts"; - String LESSER_PRIORITY_ARTIFACTS = "lesser-priority-artifacts"; - ResolvedDependency getAppArtifact(); Collection getDependencies(); diff --git a/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/model/ApplicationModelBuilder.java b/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/model/ApplicationModelBuilder.java index 42cb9de86ca56..cd4d9f76075a6 100644 --- a/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/model/ApplicationModelBuilder.java +++ b/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/model/ApplicationModelBuilder.java @@ -3,9 +3,10 @@ import io.quarkus.bootstrap.workspace.WorkspaceModule; import io.quarkus.bootstrap.workspace.WorkspaceModuleId; import io.quarkus.maven.dependency.ArtifactKey; -import io.quarkus.maven.dependency.Dependency; +import io.quarkus.maven.dependency.DependencyFlags; import io.quarkus.maven.dependency.GACT; import io.quarkus.maven.dependency.ResolvedDependency; +import io.quarkus.maven.dependency.ResolvedDependencyBuilder; import java.io.File; import java.util.ArrayList; import java.util.Collection; @@ -16,8 +17,6 @@ import java.util.Map; import java.util.Properties; import java.util.Set; -import java.util.function.Predicate; -import java.util.stream.Collectors; import org.jboss.logging.Logger; public class ApplicationModelBuilder { @@ -32,7 +31,7 @@ public class ApplicationModelBuilder { ResolvedDependency appArtifact; - final Map dependencies = new LinkedHashMap<>(); + final Map dependencies = new LinkedHashMap<>(); final Set parentFirstArtifacts = new HashSet<>(); final Set runnerParentFirstArtifacts = new HashSet<>(); final Set excludedArtifacts = new HashSet<>(); @@ -43,8 +42,6 @@ public class ApplicationModelBuilder { PlatformImports platformImports; final Map projectModules = new HashMap<>(); - private Predicate depPredicate; - public ApplicationModelBuilder setAppArtifact(ResolvedDependency appArtifact) { this.appArtifact = appArtifact; return this; @@ -60,20 +57,24 @@ public ApplicationModelBuilder addExtensionCapabilities(ExtensionCapabilities ex return this; } - public ApplicationModelBuilder addDependency(ResolvedDependency dep) { + public ApplicationModelBuilder addDependency(ResolvedDependencyBuilder dep) { dependencies.put(dep.getKey(), dep); return this; } - public ApplicationModelBuilder addDependencies(Collection deps) { + public ApplicationModelBuilder addDependencies(Collection deps) { deps.forEach(d -> addDependency(d)); return this; } - public Dependency getDependency(ArtifactKey key) { + public ResolvedDependencyBuilder getDependency(ArtifactKey key) { return dependencies.get(key); } + public Collection getDependencies() { + return dependencies.values(); + } + public ApplicationModelBuilder addParentFirstArtifact(ArtifactKey deps) { this.parentFirstArtifacts.add(deps); return this; @@ -208,22 +209,39 @@ public void handleExtensionProperties(Properties props, String extension) { } } - private Predicate dependencyPredicate() { - if (depPredicate == null) { - depPredicate = s -> { + private boolean isExcluded(ResolvedDependencyBuilder d) { + return excludedArtifacts.contains(d.getKey()) // we never include the ide launcher in the final app model - if (s.getGroupId().equals("io.quarkus") - && s.getArtifactId().equals("quarkus-ide-launcher")) { - return false; - } - return !excludedArtifacts.contains(s.getKey()); - }; - } - return depPredicate; + || (d.getArtifactId().equals("quarkus-ide-launcher") && d.getGroupId().equals("io.quarkus")); } - List filter(Collection deps) { - return deps.stream().filter(dependencyPredicate()).collect(Collectors.toList()); + List buildDependencies() { + for (ArtifactKey key : parentFirstArtifacts) { + final ResolvedDependencyBuilder d = dependencies.get(key); + if (d != null) { + d.setFlags(DependencyFlags.CLASSLOADER_PARENT_FIRST); + } + } + for (ArtifactKey key : runnerParentFirstArtifacts) { + final ResolvedDependencyBuilder d = dependencies.get(key); + if (d != null) { + d.setFlags(DependencyFlags.CLASSLOADER_RUNNER_PARENT_FIRST); + } + } + for (ArtifactKey key : lesserPriorityArtifacts) { + final ResolvedDependencyBuilder d = dependencies.get(key); + if (d != null) { + d.setFlags(DependencyFlags.CLASSLOADER_LESSER_PRIORITY); + } + } + + final List result = new ArrayList<>(dependencies.size()); + for (ResolvedDependencyBuilder db : this.dependencies.values()) { + if (!isExcluded(db)) { + result.add(db.build()); + } + } + return result; } public DefaultApplicationModel build() { diff --git a/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/model/DefaultApplicationModel.java b/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/model/DefaultApplicationModel.java index e98630ebd7c7e..945e37337031a 100644 --- a/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/model/DefaultApplicationModel.java +++ b/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/model/DefaultApplicationModel.java @@ -1,12 +1,15 @@ package io.quarkus.bootstrap.model; import io.quarkus.maven.dependency.ArtifactKey; +import io.quarkus.maven.dependency.Dependency; +import io.quarkus.maven.dependency.DependencyFlags; import io.quarkus.maven.dependency.ResolvedDependency; import java.io.Serializable; import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; public class DefaultApplicationModel implements ApplicationModel, Serializable { @@ -16,20 +19,14 @@ public class DefaultApplicationModel implements ApplicationModel, Serializable { private final List dependencies; private final PlatformImports platformImports; private final List capabilityContracts; - private final Set parentFirstArtifacts; - private final Set runnerParentFirstArtifacts; - private final Set lesserPriorityArtifacts; private final Set localProjectArtifacts; private final Map> excludedResources; public DefaultApplicationModel(ApplicationModelBuilder builder) { this.appArtifact = builder.appArtifact; - this.dependencies = builder.filter(builder.dependencies.values()); + this.dependencies = builder.buildDependencies(); this.platformImports = builder.platformImports; this.capabilityContracts = builder.extensionCapabilities; - this.parentFirstArtifacts = builder.parentFirstArtifacts; - this.runnerParentFirstArtifacts = builder.runnerParentFirstArtifacts; - this.lesserPriorityArtifacts = builder.lesserPriorityArtifacts; this.localProjectArtifacts = builder.reloadableWorkspaceModules; this.excludedResources = builder.excludedResources; } @@ -56,17 +53,20 @@ public Collection getExtensionCapabilities() { @Override public Set getParentFirst() { - return parentFirstArtifacts; + return getDependencies().stream().filter(Dependency::isClassLoaderParentFirst).map(Dependency::getKey) + .collect(Collectors.toSet()); } @Override public Set getRunnerParentFirst() { - return runnerParentFirstArtifacts; + return getDependencies().stream().filter(d -> d.isFlagSet(DependencyFlags.CLASSLOADER_RUNNER_PARENT_FIRST)) + .map(Dependency::getKey).collect(Collectors.toSet()); } @Override public Set getLowerPriorityArtifacts() { - return lesserPriorityArtifacts; + return getDependencies().stream().filter(d -> d.isFlagSet(DependencyFlags.CLASSLOADER_LESSER_PRIORITY)) + .map(Dependency::getKey).collect(Collectors.toSet()); } @Override diff --git a/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/model/MutableJarApplicationModel.java b/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/model/MutableJarApplicationModel.java index 7406568a1d83c..d311227800d56 100644 --- a/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/model/MutableJarApplicationModel.java +++ b/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/model/MutableJarApplicationModel.java @@ -30,9 +30,6 @@ public class MutableJarApplicationModel implements Serializable { private final SerializedDep appArtifact; private List dependencies; - private Set parentFirstArtifacts; - private Set runnerParentFirstArtifacts; - private Set lesserPriorityArtifacts; private Set localProjectArtifacts; private Map> excludedResources; private Collection capabilitiesContracts; @@ -50,9 +47,6 @@ public MutableJarApplicationModel(String baseName, Map dependencies.add(new SerializedDep(i, paths, i.getFlags())); } localProjectArtifacts = new HashSet<>(appModel.getReloadableWorkspaceDependencies()); - parentFirstArtifacts = new HashSet<>(appModel.getParentFirst()); - runnerParentFirstArtifacts = new HashSet<>(appModel.getRunnerParentFirst()); - lesserPriorityArtifacts = new HashSet<>(appModel.getLowerPriorityArtifacts()); excludedResources = new HashMap<>(appModel.getRemovedResources()); capabilitiesContracts = new ArrayList<>(appModel.getExtensionCapabilities()); this.platformImports = appModel.getPlatforms(); @@ -64,19 +58,10 @@ public String getUserProvidersDirectory() { public ApplicationModel getAppModel(Path root) { final ApplicationModelBuilder model = new ApplicationModelBuilder(); - model.setAppArtifact(appArtifact.getDep(root)); + model.setAppArtifact(appArtifact.getDep(root).build()); for (SerializedDep i : dependencies) { model.addDependency(i.getDep(root)); } - for (ArtifactKey i : parentFirstArtifacts) { - model.addParentFirstArtifact(i); - } - for (ArtifactKey i : runnerParentFirstArtifacts) { - model.addRunnerParentFirstArtifact(i); - } - for (ArtifactKey i : lesserPriorityArtifacts) { - model.addLesserPriorityArtifact(i); - } model.addReloadableWorkspaceModules(localProjectArtifacts); for (Map.Entry> i : excludedResources.entrySet()) { model.addRemovedResources(i.getKey(), i.getValue()); @@ -109,20 +94,18 @@ public SerializedDep(ResolvedDependency dependency, Map builder.addLesserPriorityArtifact( - new AppArtifactKey(k.getGroupId(), k.getArtifactId(), k.getClassifier(), k.getType()))); - appModel.getParentFirst().forEach(k -> builder - .addParentFirstArtifact(new AppArtifactKey(k.getGroupId(), k.getArtifactId(), k.getClassifier(), k.getType()))); - appModel.getRunnerParentFirst().forEach(k -> builder.addRunnerParentFirstArtifact( - new AppArtifactKey(k.getGroupId(), k.getArtifactId(), k.getClassifier(), k.getType()))); - appModel.getReloadableWorkspaceDependencies().forEach(k -> builder.addLocalProjectArtifact( new AppArtifactKey(k.getGroupId(), k.getArtifactId(), k.getClassifier(), k.getType()))); diff --git a/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/maven/dependency/ArtifactDependencyBuilder.java b/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/maven/dependency/ArtifactDependencyBuilder.java index 2ed15e46cffcf..87ea57e10e187 100644 --- a/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/maven/dependency/ArtifactDependencyBuilder.java +++ b/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/maven/dependency/ArtifactDependencyBuilder.java @@ -4,7 +4,7 @@ abstract class AbstractDependencyBuilder 0; } diff --git a/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/maven/dependency/DependencyFlags.java b/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/maven/dependency/DependencyFlags.java index f3629c6265610..a6b37da58205e 100644 --- a/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/maven/dependency/DependencyFlags.java +++ b/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/maven/dependency/DependencyFlags.java @@ -3,17 +3,20 @@ public interface DependencyFlags { /* @formatter:off */ - public static final int OPTIONAL = 0b00000001; - public static final int DIRECT = 0b00000010; - public static final int RUNTIME_CP = 0b00000100; - public static final int DEPLOYMENT_CP = 0b00001000; - public static final int RUNTIME_EXTENSION_ARTIFACT = 0b00010000; - public static final int WORKSPACE_MODULE = 0b00100000; - public static final int RELOADABLE = 0b01000000; + public static final int OPTIONAL = 0b00000000001; + public static final int DIRECT = 0b00000000010; + public static final int RUNTIME_CP = 0b00000000100; + public static final int DEPLOYMENT_CP = 0b00000001000; + public static final int RUNTIME_EXTENSION_ARTIFACT = 0b00000010000; + public static final int WORKSPACE_MODULE = 0b00000100000; + public static final int RELOADABLE = 0b00001000000; // A top-level runtime extension artifact is either a direct // dependency or a first extension dependency on the branch // navigating from the root to leaves - public static final int TOP_LEVEL_RUNTIME_EXTENSION_ARTIFACT = 0b10000000; + public static final int TOP_LEVEL_RUNTIME_EXTENSION_ARTIFACT = 0b00010000000; + public static final int CLASSLOADER_PARENT_FIRST = 0b00100000000; + public static final int CLASSLOADER_RUNNER_PARENT_FIRST = 0b01000000000; + public static final int CLASSLOADER_LESSER_PRIORITY = 0b10000000000; /* @formatter:on */ } diff --git a/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/app/ConfiguredClassLoading.java b/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/app/ConfiguredClassLoading.java index 610de0a6e58a3..723b6ed72887f 100644 --- a/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/app/ConfiguredClassLoading.java +++ b/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/app/ConfiguredClassLoading.java @@ -88,7 +88,11 @@ public ConfiguredClassLoading build() { } if (appModel != null) { - parentFirstArtifacts.addAll(appModel.getParentFirst()); + appModel.getDependencies().forEach(d -> { + if (d.isClassLoaderParentFirst()) { + parentFirstArtifacts.add(d.getKey()); + } + }); if (mode == Mode.TEST) { final WorkspaceModule module = appModel.getApplicationModule(); diff --git a/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/app/CuratedApplication.java b/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/app/CuratedApplication.java index 7f60c010d39fd..8236688afac1b 100644 --- a/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/app/CuratedApplication.java +++ b/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/app/CuratedApplication.java @@ -9,6 +9,7 @@ import io.quarkus.bootstrap.model.ApplicationModel; import io.quarkus.bootstrap.util.BootstrapUtils; import io.quarkus.maven.dependency.ArtifactKey; +import io.quarkus.maven.dependency.DependencyFlags; import io.quarkus.maven.dependency.ResolvedDependency; import io.quarkus.paths.OpenPathTree; import io.quarkus.paths.PathTree; @@ -190,7 +191,7 @@ private void addCpElement(QuarkusClassLoader.Builder builder, ResolvedDependency //we always load this from the parent if it is available, as this acts as a bridge between the running //app and the dev mode code builder.addParentFirstElement(element); - } else if (appModel.getLowerPriorityArtifacts().contains(key)) { + } else if (dep.isFlagSet(DependencyFlags.CLASSLOADER_LESSER_PRIORITY)) { builder.addLesserPriorityElement(element); } builder.addElement(element); diff --git a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/ApplicationDependencyTreeResolver.java b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/ApplicationDependencyTreeResolver.java index 6a5121dee0ed6..3b7bd27df81f3 100644 --- a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/ApplicationDependencyTreeResolver.java +++ b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/ApplicationDependencyTreeResolver.java @@ -30,7 +30,6 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; -import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Objects; @@ -92,7 +91,6 @@ public static Artifact getRuntimeArtifact(DependencyNode dep) { private final Deque> exclusionStack = new ArrayDeque<>(); private final Map> artifactDeps = new HashMap<>(); - private final Map appDeps = new LinkedHashMap<>(); private MavenArtifactResolver resolver; private List managedDeps; @@ -206,21 +204,21 @@ public void resolve(CollectRequest collectRtDepsRequest) throws AppModelResolver root = normalize(originalSession, root); - final BuildDependencyGraphVisitor buildDepsVisitor = new BuildDependencyGraphVisitor(originalResolver, appDeps, + final BuildDependencyGraphVisitor buildDepsVisitor = new BuildDependencyGraphVisitor(originalResolver, appBuilder, buildTreeConsumer); buildDepsVisitor.visit(root); if (!CONVERGED_TREE_ONLY && collectReloadableModules) { final Set visited = new HashSet<>(); - for (ResolvedDependencyBuilder db : appDeps.values()) { + for (ResolvedDependencyBuilder db : appBuilder.getDependencies()) { if (!db.isFlagSet(DependencyFlags.RELOADABLE)) { clearReloadableFlag(db, visited); } } } - for (ResolvedDependencyBuilder db : appDeps.values()) { - appBuilder.addDependency(db.build()); + for (ResolvedDependencyBuilder db : appBuilder.getDependencies()) { + appBuilder.addDependency(db); } collectPlatformProperties(); @@ -252,7 +250,7 @@ private void clearReloadableFlag(ResolvedDependencyBuilder db, Set return; } for (ArtifactKey key : deps) { - final ResolvedDependencyBuilder dep = appDeps.get(key); + final ResolvedDependencyBuilder dep = appBuilder.getDependency(key); if (dep == null || !visited.add(key)) { continue; } @@ -323,7 +321,7 @@ private void walk(DependencyNode node, Set visited) { } private boolean isRuntimeArtifact(ArtifactKey key) { - final ResolvedDependencyBuilder dep = appDeps.get(key); + final ResolvedDependencyBuilder dep = appBuilder.getDependency(key); return dep != null && dep.isFlagSet(DependencyFlags.RUNTIME_CP); } @@ -345,7 +343,7 @@ private void visitRuntimeDependency(DependencyNode node) { Artifact artifact = node.getArtifact(); final ArtifactKey key = getKey(artifact); - ResolvedDependencyBuilder dep = appDeps.get(key); + ResolvedDependencyBuilder dep = appBuilder.getDependency(key); if (dep == null) { artifact = resolve(artifact); } @@ -379,7 +377,7 @@ private void visitRuntimeDependency(DependencyNode node) { clearWalkingFlag(COLLECT_RELOADABLE_MODULES); } } - appDeps.put(key, dep); + appBuilder.addDependency(dep); } clearWalkingFlag(COLLECT_DIRECT_DEPS); @@ -528,7 +526,7 @@ private void clearReloadable(DependencyNode node) { for (DependencyNode child : node.getChildren()) { clearReloadable(child); } - final ResolvedDependencyBuilder dep = appDeps.get(getKey(node.getArtifact())); + final ResolvedDependencyBuilder dep = appBuilder.getDependency(getKey(node.getArtifact())); if (dep != null) { dep.clearFlag(DependencyFlags.RELOADABLE); } 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 8afcad82abcb7..4cb0251ac4971 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 @@ -3,14 +3,13 @@ */ package io.quarkus.bootstrap.resolver.maven; +import io.quarkus.bootstrap.model.ApplicationModelBuilder; import io.quarkus.bootstrap.util.DependencyUtils; import io.quarkus.bootstrap.workspace.WorkspaceModule; import io.quarkus.maven.dependency.ArtifactKey; import io.quarkus.maven.dependency.DependencyFlags; -import io.quarkus.maven.dependency.ResolvedDependencyBuilder; import java.util.ArrayList; import java.util.List; -import java.util.Map; import java.util.function.Consumer; import org.eclipse.aether.artifact.Artifact; import org.eclipse.aether.graph.Dependency; @@ -19,7 +18,7 @@ public class BuildDependencyGraphVisitor { private final MavenArtifactResolver resolver; - private final Map appDeps; + private final ApplicationModelBuilder appBuilder; private final StringBuilder buf; private final Consumer buildTreeConsumer; private final List depth; @@ -28,10 +27,10 @@ public class BuildDependencyGraphVisitor { private DependencyNode currentRuntime; private Artifact runtimeArtifactToFind; - public BuildDependencyGraphVisitor(MavenArtifactResolver resolver, Map appDeps, + public BuildDependencyGraphVisitor(MavenArtifactResolver resolver, ApplicationModelBuilder appBuilder, Consumer buildTreeConsumer) { this.resolver = resolver; - this.appDeps = appDeps; + this.appBuilder = appBuilder; this.buildTreeConsumer = buildTreeConsumer; if (buildTreeConsumer == null) { buf = null; @@ -133,8 +132,7 @@ private void visitLeave(DependencyNode node) throws BootstrapMavenException { if (currentDeployment == null) { return; } - ArtifactKey key; - if (currentRuntime == null && !appDeps.containsKey(key = getKey(node.getArtifact()))) { + if (currentRuntime == null && appBuilder.getDependency(getKey(node.getArtifact())) == null) { Artifact artifact = dep.getArtifact(); if (artifact.getFile() == null) { @@ -152,7 +150,7 @@ private void visitLeave(DependencyNode node) throws BootstrapMavenException { flags |= DependencyFlags.WORKSPACE_MODULE; } } - appDeps.put(key, ApplicationDependencyTreeResolver.toAppArtifact(artifact, module) + appBuilder.addDependency(ApplicationDependencyTreeResolver.toAppArtifact(artifact, module) .setScope(node.getDependency().getScope()) .setFlags(flags));