use of io.quarkus.bootstrap.model.ApplicationModelBuilder in project quarkus by quarkusio.
the class GradleApplicationModelBuilder method buildAll.
@Override
public Object buildAll(String modelName, ModelParameter parameter, Project project) {
final LaunchMode mode = LaunchMode.valueOf(parameter.getMode());
final List<org.gradle.api.artifacts.Dependency> enforcedPlatforms = ToolingUtils.getEnforcedPlatforms(project);
final PlatformImports platformImports = resolvePlatformImports(project, enforcedPlatforms);
final ResolvedDependency appArtifact = getProjectArtifact(project, mode);
final ApplicationModelBuilder modelBuilder = new ApplicationModelBuilder().setAppArtifact(appArtifact).addReloadableWorkspaceModule(appArtifact.getKey()).setPlatformImports(platformImports);
final ApplicationDeploymentClasspathBuilder classpathBuilder = new ApplicationDeploymentClasspathBuilder(project, mode, enforcedPlatforms);
final Configuration classpathConfig = classpathBuilder.getRuntimeConfiguration();
final Configuration deploymentConfig = classpathBuilder.getDeploymentConfiguration();
final Map<ArtifactKey, ResolvedDependencyBuilder> appDependencies = new LinkedHashMap<>();
collectDependencies(classpathConfig.getResolvedConfiguration(), mode, project, appDependencies, modelBuilder, appArtifact.getWorkspaceModule().mutable());
collectExtensionDependencies(project, deploymentConfig, appDependencies);
for (ResolvedDependencyBuilder d : appDependencies.values()) {
modelBuilder.addDependency(d.build());
}
return modelBuilder.build();
}
use of io.quarkus.bootstrap.model.ApplicationModelBuilder in project quarkus by quarkusio.
the class GradleApplicationModelBuilder method collectDependencies.
private void collectDependencies(org.gradle.api.artifacts.ResolvedDependency resolvedDep, LaunchMode mode, Project project, Map<ArtifactKey, ResolvedDependencyBuilder> appDependencies, 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)) {
continue;
}
final ArtifactCoords depCoords = toArtifactCoords(a);
final ResolvedDependencyBuilder depBuilder = ResolvedDependencyBuilder.newInstance().setCoords(depCoords).setRuntimeCp();
if (isFlagOn(flags, COLLECT_DIRECT_DEPS)) {
depBuilder.setDirect(true);
flags = clearFlag(flags, COLLECT_DIRECT_DEPS);
}
if (parentModule != null) {
parentModule.addDependency(new ArtifactDependency(depCoords));
}
PathCollection paths = null;
if ((LaunchMode.DEVELOPMENT.equals(mode) || LaunchMode.TEST.equals(mode)) && a.getId().getComponentIdentifier() instanceof ProjectComponentIdentifier) {
final Project projectDep = project.getRootProject().findProject(((ProjectComponentIdentifier) a.getId().getComponentIdentifier()).getProjectPath());
final JavaPluginConvention javaExtension = projectDep == null ? null : projectDep.getConvention().findPlugin(JavaPluginConvention.class);
final String classifier = a.getClassifier();
if (classifier == null || classifier.isEmpty()) {
final IncludedBuild includedBuild = ToolingUtils.includedBuild(project.getRootProject(), a.getName());
if (includedBuild != null) {
final PathList.Builder pathBuilder = PathList.builder();
addSubstitutedProject(pathBuilder, includedBuild.getProjectDir());
paths = pathBuilder.build();
} else if (javaExtension != null) {
final PathList.Builder pathBuilder = PathList.builder();
projectModule = initProjectModuleAndBuildPaths(projectDep, a, modelBuilder, depBuilder, javaExtension, pathBuilder, SourceSet.MAIN_SOURCE_SET_NAME, false);
paths = pathBuilder.build();
}
} else if (javaExtension != null) {
if ("test".equals(classifier)) {
final PathList.Builder pathBuilder = PathList.builder();
projectModule = initProjectModuleAndBuildPaths(projectDep, a, modelBuilder, depBuilder, javaExtension, pathBuilder, SourceSet.TEST_SOURCE_SET_NAME, true);
paths = pathBuilder.build();
} else if ("test-fixtures".equals(classifier)) {
final PathList.Builder pathBuilder = PathList.builder();
projectModule = initProjectModuleAndBuildPaths(projectDep, a, modelBuilder, depBuilder, javaExtension, pathBuilder, "testFixtures", true);
paths = pathBuilder.build();
}
}
}
depBuilder.setResolvedPaths(paths == null ? PathList.of(a.getFile().toPath()) : paths).setWorkspaceModule(projectModule);
if (processQuarkusDependency(depBuilder, modelBuilder)) {
if (isFlagOn(flags, COLLECT_TOP_EXTENSION_RUNTIME_NODES)) {
depBuilder.setFlags(DependencyFlags.TOP_LEVEL_RUNTIME_EXTENSION_ARTIFACT);
flags = clearFlag(flags, COLLECT_TOP_EXTENSION_RUNTIME_NODES);
}
flags = clearFlag(flags, COLLECT_RELOADABLE_MODULES);
}
if (!isFlagOn(flags, COLLECT_RELOADABLE_MODULES)) {
depBuilder.clearFlag(DependencyFlags.RELOADABLE);
}
appDependencies.put(depBuilder.getKey(), depBuilder);
if (artifactFiles != null) {
artifactFiles.add(a.getFile());
}
}
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, mode, project, appDependencies, artifactFiles, processedModules, modelBuilder, projectModule, flags);
}
}
}
use of io.quarkus.bootstrap.model.ApplicationModelBuilder in project quarkus by quarkusio.
the class BootstrapAppModelResolver method buildAppModel.
private ApplicationModel buildAppModel(ResolvedDependency appArtifact, DependencyNode resolvedDeps, Set<ArtifactKey> reloadableModules, List<Dependency> managedDeps, final List<RemoteRepository> repos) throws AppModelResolverException, BootstrapMavenException {
final ApplicationModelBuilder appBuilder = new ApplicationModelBuilder().setAppArtifact(appArtifact);
if (appArtifact.getWorkspaceModule() != null) {
appBuilder.addReloadableWorkspaceModule(appArtifact.getKey());
}
if (!reloadableModules.isEmpty()) {
appBuilder.addReloadableWorkspaceModules(reloadableModules);
}
final DeploymentInjectingDependencyVisitor deploymentInjector;
try {
deploymentInjector = new DeploymentInjectingDependencyVisitor(mvn, managedDeps, repos, appBuilder, collectReloadableDeps && reloadableModules.isEmpty());
deploymentInjector.injectDeploymentDependencies(resolvedDeps);
} catch (BootstrapDependencyProcessingException e) {
throw new AppModelResolverException("Failed to inject extension deployment dependencies for " + resolvedDeps.getArtifact(), e);
}
if (deploymentInjector.isInjectedDeps()) {
final DependencyGraphTransformationContext context = new SimpleDependencyGraphTransformationContext(mvn.getSession());
try {
// add conflict IDs to the added deployments
resolvedDeps = new ConflictMarker().transformGraph(resolvedDeps, context);
// resolves version conflicts
resolvedDeps = new ConflictIdSorter().transformGraph(resolvedDeps, context);
resolvedDeps = mvn.getSession().getDependencyGraphTransformer().transformGraph(resolvedDeps, context);
} catch (RepositoryException e) {
throw new AppModelResolverException("Failed to normalize the dependency graph", e);
}
final BuildDependencyGraphVisitor buildDepsVisitor = new BuildDependencyGraphVisitor(deploymentInjector.allRuntimeDeps, buildTreeConsumer);
buildDepsVisitor.visit(resolvedDeps);
final List<ArtifactRequest> requests = buildDepsVisitor.getArtifactRequests();
if (!requests.isEmpty()) {
final List<ArtifactResult> results = mvn.resolve(requests);
// update the artifacts in the graph
for (ArtifactResult result : results) {
final Artifact artifact = result.getArtifact();
if (artifact != null) {
result.getRequest().getDependencyNode().setArtifact(artifact);
}
}
final List<DependencyNode> deploymentDepNodes = buildDepsVisitor.getDeploymentNodes();
for (DependencyNode dep : deploymentDepNodes) {
int flags = DependencyFlags.DEPLOYMENT_CP;
if (dep.getDependency().isOptional()) {
flags |= DependencyFlags.OPTIONAL;
}
WorkspaceModule module = null;
if (mvn.getProjectModuleResolver() != null) {
module = mvn.getProjectModuleResolver().getProjectModule(dep.getArtifact().getGroupId(), dep.getArtifact().getArtifactId());
if (module != null) {
flags |= DependencyFlags.WORKSPACE_MODULE;
}
}
appBuilder.addDependency(toAppArtifact(dep.getArtifact(), module).setScope(dep.getDependency().getScope()).setFlags(flags).build());
}
}
}
collectPlatformProperties(appBuilder, managedDeps);
return appBuilder.build();
}
Aggregations