Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turn parent first, runner parent first and lesser priority artifacts into dependency flags #26672

Merged
merged 1 commit into from Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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()
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -817,8 +818,12 @@ public void accept(Path path) {
*/
private Set<ArtifactKey> getParentFirstKeys(CurateOutcomeBuildItem curateOutcomeBuildItem,
ClassLoadingConfig classLoadingConfig) {
final Set<ArtifactKey> parentFirstKeys = new HashSet<>(
curateOutcomeBuildItem.getApplicationModel().getRunnerParentFirst());
final Set<ArtifactKey> 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) {
Expand Down
Expand Up @@ -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()) {
Expand Down
Expand Up @@ -190,12 +190,12 @@ private boolean exist(List<ArtifactKey> 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) {
Expand All @@ -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());
}
}
Expand Up @@ -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;

Expand Down Expand Up @@ -113,14 +111,10 @@ public Object buildAll(String modelName, ModelParameter parameter, Project proje
.addReloadableWorkspaceModule(appArtifact.getKey())
.setPlatformImports(platformImports);

final Map<ArtifactKey, ResolvedDependencyBuilder> 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();
}

Expand Down Expand Up @@ -169,7 +163,7 @@ private static void collectDestinationDirs(Collection<SourceDir> sources, final
}

private void collectExtensionDependencies(Project project, Configuration deploymentConfiguration,
Map<ArtifactKey, ResolvedDependencyBuilder> appDependencies) {
ApplicationModelBuilder modelBuilder) {
final ResolvedConfiguration rc = deploymentConfiguration.getResolvedConfiguration();
for (ResolvedArtifact a : rc.getResolvedArtifacts()) {
if (a.getId().getComponentIdentifier() instanceof ProjectComponentIdentifier) {
Expand All @@ -178,24 +172,30 @@ 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);
}
}
}

private void collectDependencies(ResolvedConfiguration configuration,
boolean workspaceDiscovery, Project project, Map<ArtifactKey, ResolvedDependencyBuilder> appDependencies,
ApplicationModelBuilder modelBuilder, WorkspaceModule.Mutable wsModule) {
boolean workspaceDiscovery, Project project, ApplicationModelBuilder modelBuilder,
WorkspaceModule.Mutable wsModule) {

final Set<ResolvedArtifact> resolvedArtifacts = configuration.getResolvedArtifacts();
// if the number of artifacts is less than the number of files then probably
Expand All @@ -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));
Expand Down Expand Up @@ -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<ArtifactKey, ResolvedDependencyBuilder> appDependencies, Set<File> artifactFiles,
Set<ArtifactKey> processedModules, ApplicationModelBuilder modelBuilder, WorkspaceModule.Mutable parentModule,
Project project, Set<File> artifactFiles, Set<ArtifactKey> 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);
Expand Down Expand Up @@ -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());
Expand All @@ -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);
}
}
}
Expand Down
1 change: 0 additions & 1 deletion devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java
Expand Up @@ -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()) {
Expand Down
Expand Up @@ -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);
Expand Down
Expand Up @@ -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<ResolvedDependency> getDependencies();
Expand Down
Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -32,7 +31,7 @@ public class ApplicationModelBuilder {

ResolvedDependency appArtifact;

final Map<ArtifactKey, ResolvedDependency> dependencies = new LinkedHashMap<>();
final Map<ArtifactKey, ResolvedDependencyBuilder> dependencies = new LinkedHashMap<>();
final Set<ArtifactKey> parentFirstArtifacts = new HashSet<>();
final Set<ArtifactKey> runnerParentFirstArtifacts = new HashSet<>();
final Set<ArtifactKey> excludedArtifacts = new HashSet<>();
Expand All @@ -43,8 +42,6 @@ public class ApplicationModelBuilder {
PlatformImports platformImports;
final Map<WorkspaceModuleId, WorkspaceModule.Mutable> projectModules = new HashMap<>();

private Predicate<ResolvedDependency> depPredicate;

public ApplicationModelBuilder setAppArtifact(ResolvedDependency appArtifact) {
this.appArtifact = appArtifact;
return this;
Expand All @@ -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<ResolvedDependency> deps) {
public ApplicationModelBuilder addDependencies(Collection<ResolvedDependencyBuilder> deps) {
deps.forEach(d -> addDependency(d));
return this;
}

public Dependency getDependency(ArtifactKey key) {
public ResolvedDependencyBuilder getDependency(ArtifactKey key) {
return dependencies.get(key);
}

public Collection<ResolvedDependencyBuilder> getDependencies() {
return dependencies.values();
}

public ApplicationModelBuilder addParentFirstArtifact(ArtifactKey deps) {
this.parentFirstArtifacts.add(deps);
return this;
Expand Down Expand Up @@ -208,22 +209,39 @@ public void handleExtensionProperties(Properties props, String extension) {
}
}

private Predicate<ResolvedDependency> 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<ResolvedDependency> filter(Collection<ResolvedDependency> deps) {
return deps.stream().filter(dependencyPredicate()).collect(Collectors.toList());
List<ResolvedDependency> 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<ResolvedDependency> result = new ArrayList<>(dependencies.size());
for (ResolvedDependencyBuilder db : this.dependencies.values()) {
if (!isExcluded(db)) {
result.add(db.build());
}
}
return result;
}

public DefaultApplicationModel build() {
Expand Down