Search in sources :

Example 1 with ApplicationModelBuilder

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();
}
Also used : ApplicationDeploymentClasspathBuilder(io.quarkus.gradle.dependency.ApplicationDeploymentClasspathBuilder) ArtifactKey(io.quarkus.maven.dependency.ArtifactKey) Configuration(org.gradle.api.artifacts.Configuration) ResolvedConfiguration(org.gradle.api.artifacts.ResolvedConfiguration) ApplicationModelBuilder(io.quarkus.bootstrap.model.ApplicationModelBuilder) PlatformImports(io.quarkus.bootstrap.model.PlatformImports) ResolvedDependency(io.quarkus.maven.dependency.ResolvedDependency) ResolvedDependency(io.quarkus.maven.dependency.ResolvedDependency) ArtifactDependency(io.quarkus.maven.dependency.ArtifactDependency) Dependency(io.quarkus.maven.dependency.Dependency) DefaultExternalModuleDependency(org.gradle.api.internal.artifacts.dependencies.DefaultExternalModuleDependency) ResolvedDependencyBuilder(io.quarkus.maven.dependency.ResolvedDependencyBuilder) LinkedHashMap(java.util.LinkedHashMap) LaunchMode(io.quarkus.runtime.LaunchMode)

Example 2 with ApplicationModelBuilder

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);
        }
    }
}
Also used : PathCollection(io.quarkus.paths.PathCollection) ResolvedArtifact(org.gradle.api.artifacts.ResolvedArtifact) ArtifactCoords(io.quarkus.maven.dependency.ArtifactCoords) ArtifactKey(io.quarkus.maven.dependency.ArtifactKey) ArtifactDependency(io.quarkus.maven.dependency.ArtifactDependency) ApplicationDeploymentClasspathBuilder(io.quarkus.gradle.dependency.ApplicationDeploymentClasspathBuilder) ApplicationModelBuilder(io.quarkus.bootstrap.model.ApplicationModelBuilder) ParameterizedToolingModelBuilder(org.gradle.tooling.provider.model.ParameterizedToolingModelBuilder) ResolvedDependencyBuilder(io.quarkus.maven.dependency.ResolvedDependencyBuilder) PathList(io.quarkus.paths.PathList) GACT(io.quarkus.maven.dependency.GACT) ResolvedDependencyBuilder(io.quarkus.maven.dependency.ResolvedDependencyBuilder) Project(org.gradle.api.Project) JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) WorkspaceModule(io.quarkus.bootstrap.workspace.WorkspaceModule) DefaultWorkspaceModule(io.quarkus.bootstrap.workspace.DefaultWorkspaceModule) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier) IncludedBuild(org.gradle.api.initialization.IncludedBuild)

Example 3 with ApplicationModelBuilder

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();
}
Also used : DeploymentInjectingDependencyVisitor(io.quarkus.bootstrap.resolver.maven.DeploymentInjectingDependencyVisitor) SimpleDependencyGraphTransformationContext(io.quarkus.bootstrap.resolver.maven.SimpleDependencyGraphTransformationContext) DependencyGraphTransformationContext(org.eclipse.aether.collection.DependencyGraphTransformationContext) ApplicationModelBuilder(io.quarkus.bootstrap.model.ApplicationModelBuilder) BootstrapDependencyProcessingException(io.quarkus.bootstrap.BootstrapDependencyProcessingException) ConflictIdSorter(org.eclipse.aether.util.graph.transformer.ConflictIdSorter) RepositoryException(org.eclipse.aether.RepositoryException) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) SimpleDependencyGraphTransformationContext(io.quarkus.bootstrap.resolver.maven.SimpleDependencyGraphTransformationContext) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) BuildDependencyGraphVisitor(io.quarkus.bootstrap.resolver.maven.BuildDependencyGraphVisitor) DependencyNode(org.eclipse.aether.graph.DependencyNode) ConflictMarker(org.eclipse.aether.util.graph.transformer.ConflictMarker) WorkspaceModule(io.quarkus.bootstrap.workspace.WorkspaceModule)

Aggregations

ApplicationModelBuilder (io.quarkus.bootstrap.model.ApplicationModelBuilder)3 WorkspaceModule (io.quarkus.bootstrap.workspace.WorkspaceModule)2 ApplicationDeploymentClasspathBuilder (io.quarkus.gradle.dependency.ApplicationDeploymentClasspathBuilder)2 ArtifactDependency (io.quarkus.maven.dependency.ArtifactDependency)2 ArtifactKey (io.quarkus.maven.dependency.ArtifactKey)2 ResolvedDependencyBuilder (io.quarkus.maven.dependency.ResolvedDependencyBuilder)2 BootstrapDependencyProcessingException (io.quarkus.bootstrap.BootstrapDependencyProcessingException)1 PlatformImports (io.quarkus.bootstrap.model.PlatformImports)1 BuildDependencyGraphVisitor (io.quarkus.bootstrap.resolver.maven.BuildDependencyGraphVisitor)1 DeploymentInjectingDependencyVisitor (io.quarkus.bootstrap.resolver.maven.DeploymentInjectingDependencyVisitor)1 SimpleDependencyGraphTransformationContext (io.quarkus.bootstrap.resolver.maven.SimpleDependencyGraphTransformationContext)1 DefaultWorkspaceModule (io.quarkus.bootstrap.workspace.DefaultWorkspaceModule)1 ArtifactCoords (io.quarkus.maven.dependency.ArtifactCoords)1 Dependency (io.quarkus.maven.dependency.Dependency)1 GACT (io.quarkus.maven.dependency.GACT)1 ResolvedDependency (io.quarkus.maven.dependency.ResolvedDependency)1 PathCollection (io.quarkus.paths.PathCollection)1 PathList (io.quarkus.paths.PathList)1 LaunchMode (io.quarkus.runtime.LaunchMode)1 LinkedHashMap (java.util.LinkedHashMap)1