Skip to content

Commit

Permalink
An option to resolve only the runtime part of the ApplicationModel
Browse files Browse the repository at this point in the history
  • Loading branch information
aloubyansky committed Oct 28, 2024
1 parent 123ea8e commit e04ebf3
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package io.quarkus.bootstrap.resolver.test;

import io.quarkus.bootstrap.resolver.BootstrapAppModelResolver;
import io.quarkus.bootstrap.resolver.CollectDependenciesBase;
import io.quarkus.bootstrap.resolver.TsArtifact;
import io.quarkus.bootstrap.resolver.TsQuarkusExt;
import io.quarkus.bootstrap.resolver.maven.workspace.LocalProject;
import io.quarkus.maven.dependency.DependencyFlags;

public class RuntimeOnlyApplicationModelTestCase extends CollectDependenciesBase {

private static final boolean runtimeOnly = true;

@Override
protected BootstrapAppModelResolver newAppModelResolver(LocalProject currentProject) throws Exception {
var resolver = super.newAppModelResolver(currentProject);
resolver.setIncubatingModelResolver(false);
resolver.setRuntimeModelOnly(runtimeOnly);
return resolver;
}

@Override
protected void setupDependencies() {

final TsQuarkusExt extA = new TsQuarkusExt("ext-a");
install(extA, false);
if (!runtimeOnly) {
addCollectedDeploymentDep(extA.getDeployment());
}

installAsDep(extA.getRuntime(),
DependencyFlags.DIRECT
| DependencyFlags.RUNTIME_EXTENSION_ARTIFACT
| DependencyFlags.TOP_LEVEL_RUNTIME_EXTENSION_ARTIFACT);

final TsQuarkusExt extB = new TsQuarkusExt("ext-b");
install(extB, false);

final TsQuarkusExt extC = new TsQuarkusExt("ext-c");
extC.setDependencyCondition(extB);
install(extC, false);

final TsQuarkusExt extD = new TsQuarkusExt("ext-d");
install(extD, false);
installAsDep(extD.getRuntime(),
DependencyFlags.DIRECT
| DependencyFlags.RUNTIME_EXTENSION_ARTIFACT
| DependencyFlags.TOP_LEVEL_RUNTIME_EXTENSION_ARTIFACT);
if (!runtimeOnly) {
addCollectedDeploymentDep(extD.getDeployment());
}

final TsArtifact libE = TsArtifact.jar("lib-e");
install(libE, true);
final TsArtifact libEBuildTIme = TsArtifact.jar("lib-e-build-time");
install(libEBuildTIme);
if (!runtimeOnly) {
addCollectedDeploymentDep(libEBuildTIme);
}

final TsQuarkusExt extE = new TsQuarkusExt("ext-e");
extE.setDependencyCondition(extD);
extE.getRuntime().addDependency(libE);
extE.getDeployment().addDependency(libEBuildTIme);
install(extE, false);
addCollectedDep(extE.getRuntime(), DependencyFlags.RUNTIME_EXTENSION_ARTIFACT);
if (!runtimeOnly) {
addCollectedDeploymentDep(extE.getDeployment());
}

final TsQuarkusExt extF = new TsQuarkusExt("ext-f");
extF.setConditionalDeps(extC, extE);
install(extF, false);
installAsDep(extF.getRuntime(),
DependencyFlags.DIRECT
| DependencyFlags.RUNTIME_EXTENSION_ARTIFACT
| DependencyFlags.TOP_LEVEL_RUNTIME_EXTENSION_ARTIFACT);
if (!runtimeOnly) {
addCollectedDeploymentDep(extF.getDeployment());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class BootstrapAppModelResolver implements AppModelResolver {
protected boolean test;
private boolean collectReloadableDeps = true;
private boolean incubatingModelResolver;
private boolean runtimeModelOnly;

public BootstrapAppModelResolver(MavenArtifactResolver mvn) {
this.mvn = mvn;
Expand Down Expand Up @@ -110,6 +111,11 @@ public BootstrapAppModelResolver setCollectReloadableDependencies(boolean collec
return this;
}

public BootstrapAppModelResolver setRuntimeModelOnly(boolean runtimeModelOnly) {
this.runtimeModelOnly = runtimeModelOnly;
return this;
}

public void addRemoteRepositories(List<RemoteRepository> repos) {
mvn.addRemoteRepositories(repos);
}
Expand Down Expand Up @@ -371,6 +377,7 @@ private ApplicationModel buildAppModel(ResolvedDependencyBuilder appArtifact,
.setCollectReloadableModules(collectReloadableDeps && reloadableModules.isEmpty())
.setCollectCompileOnly(filteredProvidedDeps)
.setDependencyLogging(depLogConfig)
.setRuntimeModelOnly(runtimeModelOnly)
.resolve(collectRtDepsRequest);
} else {
ApplicationDependencyTreeResolver.newInstance()
Expand All @@ -379,6 +386,7 @@ private ApplicationModel buildAppModel(ResolvedDependencyBuilder appArtifact,
.setCollectReloadableModules(collectReloadableDeps && reloadableModules.isEmpty())
.setCollectCompileOnly(filteredProvidedDeps)
.setBuildTreeConsumer(depLogConfig == null ? null : depLogConfig.getMessageConsumer())
.setRuntimeModelOnly(runtimeModelOnly)
.resolve(collectRtDepsRequest);
}
if (logTime) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public static Artifact getRuntimeArtifact(DependencyNode dep) {
private boolean collectReloadableModules;
private Consumer<String> buildTreeConsumer;
private List<Dependency> collectCompileOnly;
private boolean runtimeModelOnly;

public ApplicationDependencyTreeResolver setArtifactResolver(MavenArtifactResolver resolver) {
this.resolver = resolver;
Expand Down Expand Up @@ -139,6 +140,11 @@ public ApplicationDependencyTreeResolver setCollectCompileOnly(List<Dependency>
return this;
}

public ApplicationDependencyTreeResolver setRuntimeModelOnly(boolean runtimeModelOnly) {
this.runtimeModelOnly = runtimeModelOnly;
return this;
}

public void resolve(CollectRequest collectRtDepsRequest) throws AppModelResolverException {

this.managedDeps = collectRtDepsRequest.getManagedDependencies();
Expand Down Expand Up @@ -202,13 +208,15 @@ public void resolve(CollectRequest collectRtDepsRequest) throws AppModelResolver
}
}

for (ExtensionDependency extDep : topExtensionDeps) {
injectDeploymentDependencies(extDep);
}
if (!runtimeModelOnly) {
for (ExtensionDependency extDep : topExtensionDeps) {
injectDeploymentDependencies(extDep);
}

if (!activatedConditionalDeps.isEmpty()) {
for (ConditionalDependency cd : activatedConditionalDeps) {
injectDeploymentDependencies(cd.getExtensionDependency());
if (!activatedConditionalDeps.isEmpty()) {
for (ConditionalDependency cd : activatedConditionalDeps) {
injectDeploymentDependencies(cd.getExtensionDependency());
}
}
}

Expand All @@ -231,7 +239,9 @@ public void resolve(CollectRequest collectRtDepsRequest) throws AppModelResolver
}

collectPlatformProperties();
collectCompileOnly(collectRtDepsRequest, root);
if (!runtimeModelOnly) {
collectCompileOnly(collectRtDepsRequest, root);
}
}

/**
Expand Down Expand Up @@ -886,7 +896,7 @@ void activate() {
return;
}
activated = true;
clearWalkingFlag(COLLECT_TOP_EXTENSION_RUNTIME_NODES);
clearWalkingFlag((byte) (COLLECT_DIRECT_DEPS | COLLECT_TOP_EXTENSION_RUNTIME_NODES));
final ExtensionDependency extDep = getExtensionDependency();
final DependencyNode originalNode = collectDependencies(info.runtimeArtifact, extDep.exclusions,
extDep.runtimeNode.getRepositories());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ public static IncubatingApplicationModelResolver newInstance() {
private boolean collectReloadableModules;
private DependencyLoggingConfig depLogging;
private List<Dependency> collectCompileOnly;
private boolean runtimeModelOnly;

public IncubatingApplicationModelResolver setArtifactResolver(MavenArtifactResolver resolver) {
this.resolver = resolver;
Expand Down Expand Up @@ -172,6 +173,11 @@ public IncubatingApplicationModelResolver setCollectCompileOnly(List<Dependency>
return this;
}

public IncubatingApplicationModelResolver setRuntimeModelOnly(boolean runtimeModelOnly) {
this.runtimeModelOnly = runtimeModelOnly;
return this;
}

public void resolve(CollectRequest collectRtDepsRequest) throws AppModelResolverException {
this.managedDeps = collectRtDepsRequest.getManagedDependencies();
// managed dependencies will be a bit augmented with every added extension, so let's load the properties early
Expand All @@ -182,10 +188,14 @@ public void resolve(CollectRequest collectRtDepsRequest) throws AppModelResolver
processRuntimeDeps(root);
final List<ConditionalDependency> activatedConditionalDeps = activateConditionalDeps();

// resolve and inject deployment dependency branches for the top (first met) runtime extension nodes
injectDeployment(activatedConditionalDeps);
root = normalize(resolver.getSession(), root);
processDeploymentDeps(root);
if (runtimeModelOnly) {
root = normalize(resolver.getSession(), root);
} else {
// resolve and inject deployment dependency branches for the top (first met) runtime extension nodes
injectDeployment(activatedConditionalDeps);
root = normalize(resolver.getSession(), root);
processDeploymentDeps(root);
}

for (var d : appBuilder.getDependencies()) {
if (!d.isFlagSet(DependencyFlags.RELOADABLE) && !d.isFlagSet(DependencyFlags.VISITED)) {
Expand All @@ -201,7 +211,9 @@ public void resolve(CollectRequest collectRtDepsRequest) throws AppModelResolver
appBuilder.addDependency(d);
}

collectCompileOnly(collectRtDepsRequest, root);
if (!runtimeModelOnly) {
collectCompileOnly(collectRtDepsRequest, root);
}
}

private List<ConditionalDependency> activateConditionalDeps() {
Expand Down Expand Up @@ -1053,7 +1065,6 @@ void activate() {
} else {
currentChildren.addAll(originalNode.getChildren());
}
conditionalDep.walkingFlags = COLLECT_DIRECT_DEPS;
if (collectReloadableModules) {
conditionalDep.walkingFlags |= COLLECT_RELOADABLE_MODULES;
}
Expand Down

0 comments on commit e04ebf3

Please sign in to comment.