Skip to content

Commit

Permalink
Merge pull request #40163 from aloubyansky/app-model-deps
Browse files Browse the repository at this point in the history
Collect and expose info about dependencies of each artifact in ApplicationModel
  • Loading branch information
gsmet authored Apr 22, 2024
2 parents 1ef8ebe + 2bea0cd commit a9f0f54
Show file tree
Hide file tree
Showing 24 changed files with 466 additions and 307 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
package io.quarkus.deployment.conditionaldeps;

import static org.assertj.core.api.Assertions.assertThat;

import java.util.HashMap;

import io.quarkus.bootstrap.model.ApplicationModel;
import io.quarkus.bootstrap.resolver.TsArtifact;
import io.quarkus.bootstrap.resolver.TsQuarkusExt;
import io.quarkus.bootstrap.resolver.maven.IncubatingApplicationModelResolver;
import io.quarkus.deployment.runnerjar.BootstrapFromOriginalJarTestBase;
import io.quarkus.maven.dependency.ResolvedDependency;

public class DependencyConditionMatchesConditionalDependencyTest extends BootstrapFromOriginalJarTestBase {

Expand Down Expand Up @@ -38,6 +45,37 @@ protected TsArtifact composeApplication() {
.addDependency(extA);
}

@Override
protected void assertAppModel(ApplicationModel appModel) {
var extensions = new HashMap<String, ResolvedDependency>();
for (var d : appModel.getDependencies()) {
extensions.put(d.getArtifactId(), d);
}
assertThat(extensions).hasSize(8);

if (IncubatingApplicationModelResolver.isIncubatingEnabled(null)) {
var extA = extensions.get("ext-a");
assertThat(extA.getDependencies()).isEmpty();
var extADeployment = extensions.get("ext-a-deployment");
assertThat(extADeployment.getDependencies()).containsExactly(extA);

var extB = extensions.get("ext-b");
assertThat(extB.getDependencies()).isEmpty();
var extBDeployment = extensions.get("ext-b-deployment");
assertThat(extBDeployment.getDependencies()).containsExactly(extB);

var extD = extensions.get("ext-d");
assertThat(extD.getDependencies()).containsExactly(extB);
var extDDeployment = extensions.get("ext-d-deployment");
assertThat(extDDeployment.getDependencies()).containsExactlyInAnyOrder(extD, extBDeployment);

var extC = extensions.get("ext-c");
assertThat(extC.getDependencies()).containsExactly(extD);
var extCDeployment = extensions.get("ext-c-deployment");
assertThat(extCDeployment.getDependencies()).containsExactlyInAnyOrder(extC, extDDeployment);
}
}

@Override
protected String[] expectedExtensionDependencies() {
return new String[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public Object buildAll(String modelName, ModelParameter parameter, Project proje
}
}

final ResolvedDependency appArtifact = getProjectArtifact(project, workspaceDiscovery);
final ResolvedDependencyBuilder appArtifact = getProjectArtifact(project, workspaceDiscovery);
final ApplicationModelBuilder modelBuilder = new ApplicationModelBuilder()
.setAppArtifact(appArtifact)
.addReloadableWorkspaceModule(appArtifact.getKey())
Expand Down Expand Up @@ -159,7 +159,7 @@ private static void addCompileOnly(Project project, ApplicationDeploymentClasspa
}
}

public static ResolvedDependency getProjectArtifact(Project project, boolean workspaceDiscovery) {
public static ResolvedDependencyBuilder getProjectArtifact(Project project, boolean workspaceDiscovery) {
final ResolvedDependencyBuilder appArtifact = ResolvedDependencyBuilder.newInstance()
.setGroupId(project.getGroup().toString())
.setArtifactId(project.getName())
Expand Down Expand Up @@ -206,7 +206,7 @@ public static ResolvedDependency getProjectArtifact(Project project, boolean wor
collectDestinationDirs(mainModule.getMainSources().getSourceDirs(), paths);
collectDestinationDirs(mainModule.getMainSources().getResourceDirs(), paths);

return appArtifact.setWorkspaceModule(mainModule).setResolvedPaths(paths.build()).build();
return appArtifact.setWorkspaceModule(mainModule).setResolvedPaths(paths.build());
}

private static void collectDestinationDirs(Collection<SourceDir> sources, final PathList.Builder paths) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
import org.eclipse.aether.repository.RemoteRepository;

import io.quarkus.bootstrap.resolver.BootstrapAppModelResolver;
import io.quarkus.bootstrap.resolver.maven.ApplicationDependencyModelResolver;
import io.quarkus.bootstrap.resolver.maven.BootstrapMavenContext;
import io.quarkus.bootstrap.resolver.maven.DependencyLoggingConfig;
import io.quarkus.bootstrap.resolver.maven.IncubatingApplicationModelResolver;
import io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver;
import io.quarkus.maven.components.QuarkusWorkspaceProvider;
import io.quarkus.maven.dependency.ArtifactCoords;
Expand Down Expand Up @@ -148,7 +148,7 @@ private void logTree(final Consumer<String> log) throws MojoExecutionException {
}
}
modelResolver.setIncubatingModelResolver(
ApplicationDependencyModelResolver.isIncubatingEnabled(project.getProperties()));
IncubatingApplicationModelResolver.isIncubatingEnabled(project.getProperties()));
modelResolver.setDepLogConfig(DependencyLoggingConfig.builder()
.setMessageConsumer(log)
.setVerbose(verbose)
Expand Down
4 changes: 2 additions & 2 deletions devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@
import io.quarkus.bootstrap.model.ApplicationModel;
import io.quarkus.bootstrap.model.PathsCollection;
import io.quarkus.bootstrap.resolver.BootstrapAppModelResolver;
import io.quarkus.bootstrap.resolver.maven.ApplicationDependencyModelResolver;
import io.quarkus.bootstrap.resolver.maven.BootstrapMavenContext;
import io.quarkus.bootstrap.resolver.maven.BootstrapMavenContextConfig;
import io.quarkus.bootstrap.resolver.maven.IncubatingApplicationModelResolver;
import io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver;
import io.quarkus.bootstrap.util.BootstrapUtils;
import io.quarkus.bootstrap.workspace.ArtifactSources;
Expand Down Expand Up @@ -1361,7 +1361,7 @@ private QuarkusDevModeLauncher newLauncher(Boolean debugPortOk, String bootstrap
.setDevMode(true)
.setTest(LaunchMode.TEST.equals(getLaunchModeClasspath()))
.setCollectReloadableDependencies(!noDeps)
.setIncubatingModelResolver(ApplicationDependencyModelResolver.isIncubatingEnabled(project.getProperties()))
.setIncubatingModelResolver(IncubatingApplicationModelResolver.isIncubatingEnabled(project.getProperties()))
.resolveModel(mvnCtx.getCurrentProject().getAppArtifact());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@
import io.quarkus.bootstrap.model.ApplicationModel;
import io.quarkus.bootstrap.resolver.AppModelResolverException;
import io.quarkus.bootstrap.resolver.BootstrapAppModelResolver;
import io.quarkus.bootstrap.resolver.maven.ApplicationDependencyModelResolver;
import io.quarkus.bootstrap.resolver.maven.BootstrapMavenContext;
import io.quarkus.bootstrap.resolver.maven.BootstrapMavenException;
import io.quarkus.bootstrap.resolver.maven.IncubatingApplicationModelResolver;
import io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver;
import io.quarkus.maven.components.ManifestSection;
import io.quarkus.maven.components.QuarkusWorkspaceProvider;
import io.quarkus.maven.dependency.ArtifactCoords;
import io.quarkus.maven.dependency.ArtifactKey;
import io.quarkus.maven.dependency.Dependency;
import io.quarkus.maven.dependency.ResolvedArtifactDependency;
import io.quarkus.maven.dependency.ResolvedDependencyBuilder;
import io.quarkus.runtime.LaunchMode;
import io.smallrye.common.expression.Expression;

Expand Down Expand Up @@ -208,12 +208,12 @@ private CuratedApplication doBootstrap(QuarkusBootstrapMojo mojo, LaunchMode mod

final BootstrapAppModelResolver modelResolver = new BootstrapAppModelResolver(artifactResolver(mojo, mode))
.setIncubatingModelResolver(
ApplicationDependencyModelResolver.isIncubatingEnabled(mojo.mavenProject().getProperties()))
IncubatingApplicationModelResolver.isIncubatingEnabled(mojo.mavenProject().getProperties()))
.setDevMode(mode == LaunchMode.DEVELOPMENT)
.setTest(mode == LaunchMode.TEST)
.setCollectReloadableDependencies(mode == LaunchMode.DEVELOPMENT || mode == LaunchMode.TEST);

final ArtifactCoords appArtifact = appArtifact(mojo);
final ResolvedDependencyBuilder appArtifact = getApplicationArtifactBuilder(mojo);
Set<ArtifactKey> reloadableModules = Set.of();
if (mode == LaunchMode.NORMAL) {
// collect reloadable artifacts for remote-dev
Expand Down Expand Up @@ -367,7 +367,7 @@ protected ArtifactCoords managingProject(QuarkusBootstrapMojo mojo) {
artifact.getVersion());
}

private ArtifactCoords appArtifact(QuarkusBootstrapMojo mojo)
private ResolvedDependencyBuilder getApplicationArtifactBuilder(QuarkusBootstrapMojo mojo)
throws MojoExecutionException {
String appArtifactCoords = mojo.appArtifactCoords();
if (appArtifactCoords == null) {
Expand All @@ -388,9 +388,13 @@ private ArtifactCoords appArtifact(QuarkusBootstrapMojo mojo)
}
}
}
return new ResolvedArtifactDependency(projectArtifact.getGroupId(), projectArtifact.getArtifactId(),
projectArtifact.getClassifier(), projectArtifact.getArtifactHandler().getExtension(),
projectArtifact.getVersion(), projectFile.toPath());
return ResolvedDependencyBuilder.newInstance()
.setGroupId(projectArtifact.getGroupId())
.setArtifactId(projectArtifact.getArtifactId())
.setClassifier(projectArtifact.getClassifier())
.setType(projectArtifact.getArtifactHandler().getExtension())
.setVersion(projectArtifact.getVersion())
.setResolvedPath(projectFile.toPath());
}

final String[] coordsArr = appArtifactCoords.split(":");
Expand Down Expand Up @@ -429,7 +433,12 @@ private ArtifactCoords appArtifact(QuarkusBootstrapMojo mojo)
}
}

return ArtifactCoords.of(groupId, artifactId, classifier, type, version);
return ResolvedDependencyBuilder.newInstance()
.setGroupId(groupId)
.setArtifactId(artifactId)
.setClassifier(classifier)
.setType(type)
.setVersion(version);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[info] Quarkus application PROD mode build dependency tree:
[info] io.quarkus.bootstrap.test:app-with-conditional-deps:pom:1
[info] ├─ io.quarkus.bootstrap.test:quarkus-tomato-deployment:jar:1 (compile)
[info] │ ├─ io.quarkus.bootstrap.test:quarkus-tomato:jar:1 (compile)
[info] │ │ └─ io.quarkus.bootstrap.test:test-core-ext:jar:1 (compile)
[info] │ └─ io.quarkus.bootstrap.test:test-core-ext-deployment:jar:1 (compile)
[info] ├─ io.quarkus.bootstrap.test:quarkus-mozzarella-deployment:jar:1 (compile)
[info] │ └─ io.quarkus.bootstrap.test:quarkus-mozzarella:jar:1 (compile)
[info] ├─ io.quarkus.bootstrap.test:quarkus-basil-deployment:jar:1 (compile)
[info] │ └─ io.quarkus.bootstrap.test:quarkus-basil:jar:1 (compile)
[info] ├─ io.quarkus.bootstrap.test:quarkus-salad-deployment:jar:1 (compile)
[info] │ ├─ io.quarkus.bootstrap.test:quarkus-salad:jar:1 (compile)
[info] │ │ └─ io.quarkus.bootstrap.test:quarkus-caprese:jar:1 (compile)
[info] │ └─ io.quarkus.bootstrap.test:quarkus-caprese-deployment:jar:1 (compile)
[info] └─ io.quarkus.bootstrap.test:quarkus-oil:jar:1 (compile)
[info] ├─ io.quarkus.bootstrap.test:quarkus-tomato-deployment:1 (compile)
[info] │ ├─ io.quarkus.bootstrap.test:quarkus-tomato:1 (compile)
[info] │ │ └─ io.quarkus.bootstrap.test:test-core-ext:1 (compile)
[info] │ └─ io.quarkus.bootstrap.test:test-core-ext-deployment:1 (compile)
[info] ├─ io.quarkus.bootstrap.test:quarkus-mozzarella-deployment:1 (compile)
[info] │ └─ io.quarkus.bootstrap.test:quarkus-mozzarella:1 (compile)
[info] ├─ io.quarkus.bootstrap.test:quarkus-basil-deployment:1 (compile)
[info] │ └─ io.quarkus.bootstrap.test:quarkus-basil:1 (compile)
[info] ├─ io.quarkus.bootstrap.test:quarkus-salad-deployment:1 (compile)
[info] │ ├─ io.quarkus.bootstrap.test:quarkus-salad:1 (compile)
[info] │ │ └─ io.quarkus.bootstrap.test:quarkus-caprese:1 (compile)
[info] │ └─ io.quarkus.bootstrap.test:quarkus-caprese-deployment:1 (compile)
[info] └─ io.quarkus.bootstrap.test:quarkus-oil:1 (compile)
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
[info] Quarkus application PROD mode build dependency tree:
[info] io.quarkus.bootstrap.test:app-with-conditional-graph:pom:1
[info] ├─ io.quarkus.bootstrap.test:quarkus-basil::jar:1 (compile) [+]
[info] ├─ io.quarkus.bootstrap.test:quarkus-mozzarella::jar:1 (compile) [+]
[info] ├─ io.quarkus.bootstrap.test:quarkus-salad::jar:1 (compile) [+]
[info] ├─ io.quarkus.bootstrap.test:quarkus-tomato::jar:1 (compile) [+]
[info] ├─ io.quarkus.bootstrap.test:quarkus-tomato-deployment:jar:1 (compile)
[info] │ ├─ io.quarkus.bootstrap.test:quarkus-tomato:jar:1 (compile)
[info] │ │ └─ io.quarkus.bootstrap.test:test-core-ext:jar:1 (compile)
[info] │ └─ io.quarkus.bootstrap.test:test-core-ext-deployment:jar:1 (compile)
[info] │ └─ io.quarkus.bootstrap.test:test-core-ext::jar:1 (compile) [+]
[info] ├─ io.quarkus.bootstrap.test:quarkus-mozzarella-deployment:jar:1 (compile)
[info] │ ├─ io.quarkus.bootstrap.test:test-core-ext-deployment::jar:1 (compile) [+]
[info] │ └─ io.quarkus.bootstrap.test:quarkus-mozzarella:jar:1 (compile)
[info] │ └─ io.quarkus.bootstrap.test:test-core-ext::jar:1 (compile) [+]
[info] ├─ io.quarkus.bootstrap.test:quarkus-basil-deployment:jar:1 (compile)
[info] │ ├─ io.quarkus.bootstrap.test:test-core-ext-deployment::jar:1 (compile) [+]
[info] │ └─ io.quarkus.bootstrap.test:quarkus-basil:jar:1 (compile)
[info] │ └─ io.quarkus.bootstrap.test:test-core-ext::jar:1 (compile) [+]
[info] ├─ io.quarkus.bootstrap.test:quarkus-salad-deployment:jar:1 (compile)
[info] │ ├─ io.quarkus.bootstrap.test:test-core-ext-deployment::jar:1 (compile) [+]
[info] │ ├─ io.quarkus.bootstrap.test:quarkus-salad:jar:1 (compile)
[info] │ │ ├─ io.quarkus.bootstrap.test:test-core-ext::jar:1 (compile) [+]
[info] │ │ └─ io.quarkus.bootstrap.test:quarkus-caprese:jar:1 (compile)
[info] │ │ └─ io.quarkus.bootstrap.test:test-core-ext::jar:1 (compile) [+]
[info] │ └─ io.quarkus.bootstrap.test:quarkus-caprese-deployment:jar:1 (compile)
[info] │ ├─ io.quarkus.bootstrap.test:quarkus-caprese::jar:1 (compile) [+]
[info] │ ├─ io.quarkus.bootstrap.test:quarkus-oil::jar:1 (compile) [+]
[info] │ └─ io.quarkus.bootstrap.test:test-core-ext-deployment::jar:1 (compile) [+]
[info] └─ io.quarkus.bootstrap.test:quarkus-oil:jar:1 (compile)
[info] ├─ io.quarkus.bootstrap.test:quarkus-basil:1 (compile) [+]
[info] ├─ io.quarkus.bootstrap.test:quarkus-mozzarella:1 (compile) [+]
[info] ├─ io.quarkus.bootstrap.test:quarkus-salad:1 (compile) [+]
[info] ├─ io.quarkus.bootstrap.test:quarkus-tomato:1 (compile) [+]
[info] ├─ io.quarkus.bootstrap.test:quarkus-tomato-deployment:1 (compile)
[info] │ ├─ io.quarkus.bootstrap.test:quarkus-tomato:1 (compile)
[info] │ │ └─ io.quarkus.bootstrap.test:test-core-ext:1 (compile)
[info] │ └─ io.quarkus.bootstrap.test:test-core-ext-deployment:1 (compile)
[info] │ └─ io.quarkus.bootstrap.test:test-core-ext:1 (compile) [+]
[info] ├─ io.quarkus.bootstrap.test:quarkus-mozzarella-deployment:1 (compile)
[info] │ ├─ io.quarkus.bootstrap.test:test-core-ext-deployment:1 (compile) [+]
[info] │ └─ io.quarkus.bootstrap.test:quarkus-mozzarella:1 (compile)
[info] │ └─ io.quarkus.bootstrap.test:test-core-ext:1 (compile) [+]
[info] ├─ io.quarkus.bootstrap.test:quarkus-basil-deployment:1 (compile)
[info] │ ├─ io.quarkus.bootstrap.test:test-core-ext-deployment:1 (compile) [+]
[info] │ └─ io.quarkus.bootstrap.test:quarkus-basil:1 (compile)
[info] │ └─ io.quarkus.bootstrap.test:test-core-ext:1 (compile) [+]
[info] ├─ io.quarkus.bootstrap.test:quarkus-salad-deployment:1 (compile)
[info] │ ├─ io.quarkus.bootstrap.test:test-core-ext-deployment:1 (compile) [+]
[info] │ ├─ io.quarkus.bootstrap.test:quarkus-salad:1 (compile)
[info] │ │ ├─ io.quarkus.bootstrap.test:test-core-ext:1 (compile) [+]
[info] │ │ └─ io.quarkus.bootstrap.test:quarkus-caprese:1 (compile)
[info] │ │ └─ io.quarkus.bootstrap.test:test-core-ext:1 (compile) [+]
[info] │ └─ io.quarkus.bootstrap.test:quarkus-caprese-deployment:1 (compile)
[info] │ ├─ io.quarkus.bootstrap.test:quarkus-caprese:1 (compile) [+]
[info] │ ├─ io.quarkus.bootstrap.test:quarkus-oil:1 (compile) [+]
[info] │ └─ io.quarkus.bootstrap.test:test-core-ext-deployment:1 (compile) [+]
[info] └─ io.quarkus.bootstrap.test:quarkus-oil:1 (compile)
24 changes: 12 additions & 12 deletions devtools/maven/src/test/resources/test-app-1.jar.dev
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[info] Quarkus application DEV mode build dependency tree:
[info] io.quarkus.bootstrap.test:test-app:pom:1
[info] ├─ io.quarkus.bootstrap.test:artifact-with-classifier:jar:classifier:1 (compile)
[info] ├─ io.quarkus.bootstrap.test:test-ext2-deployment:jar:1 (compile)
[info] │ ├─ io.quarkus.bootstrap.test:test-ext2:jar:1 (compile)
[info] │ │ └─ io.quarkus.bootstrap.test:test-ext1:jar:1 (compile)
[info] │ └─ io.quarkus.bootstrap.test:test-ext1-deployment:jar:1 (compile)
[info] ├─ io.quarkus.bootstrap.test:optional:jar:1 (compile optional)
[info] ├─ io.quarkus.bootstrap.test:test-ext3-deployment:jar:1 (compile)
[info] │ ├─ io.quarkus.bootstrap.test:test-ext3:jar:1 (compile)
[info] │ │ └─ io.quarkus.bootstrap.test:test-core-ext:jar:1 (compile)
[info] │ └─ io.quarkus.bootstrap.test:test-core-ext-deployment:jar:1 (compile)
[info] ├─ io.quarkus.bootstrap.test:provided:jar:1 (provided)
[info] └─ io.quarkus.bootstrap.test:runtime:jar:1 (runtime)
[info] ├─ io.quarkus.bootstrap.test:artifact-with-classifier:classifier:1 (compile)
[info] ├─ io.quarkus.bootstrap.test:test-ext2-deployment:1 (compile)
[info] │ ├─ io.quarkus.bootstrap.test:test-ext2:1 (compile)
[info] │ │ └─ io.quarkus.bootstrap.test:test-ext1:1 (compile)
[info] │ └─ io.quarkus.bootstrap.test:test-ext1-deployment:1 (compile)
[info] ├─ io.quarkus.bootstrap.test:optional:1 (compile optional)
[info] ├─ io.quarkus.bootstrap.test:test-ext3-deployment:1 (compile)
[info] │ ├─ io.quarkus.bootstrap.test:test-ext3:1 (compile)
[info] │ │ └─ io.quarkus.bootstrap.test:test-core-ext:1 (compile)
[info] │ └─ io.quarkus.bootstrap.test:test-core-ext-deployment:1 (compile)
[info] ├─ io.quarkus.bootstrap.test:provided:1 (provided)
[info] └─ io.quarkus.bootstrap.test:runtime:1 (runtime)
Loading

0 comments on commit a9f0f54

Please sign in to comment.