Search in sources :

Example 1 with ResolvedDependencyBuilder

use of io.quarkus.maven.dependency.ResolvedDependencyBuilder in project quarkus by quarkusio.

the class GradleApplicationModelBuilder method collectExtensionDependencies.

private void collectExtensionDependencies(Project project, Configuration deploymentConfiguration, Map<ArtifactKey, ResolvedDependencyBuilder> appDependencies) {
    final ResolvedConfiguration rc = deploymentConfiguration.getResolvedConfiguration();
    for (ResolvedArtifact a : rc.getResolvedArtifacts()) {
        if (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);
            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));
            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));
            dep.setDeploymentCp();
            dep.clearFlag(DependencyFlags.RELOADABLE);
        }
    }
}
Also used : ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier) DefaultSourceDir(io.quarkus.bootstrap.workspace.DefaultSourceDir) ModelParameter(io.quarkus.bootstrap.model.gradle.ModelParameter) ApplicationDeploymentClasspathBuilder(io.quarkus.gradle.dependency.ApplicationDeploymentClasspathBuilder) DefaultArtifactSources(io.quarkus.bootstrap.workspace.DefaultArtifactSources) FileTree(org.gradle.api.file.FileTree) ArtifactSources(io.quarkus.bootstrap.workspace.ArtifactSources) SourceDir(io.quarkus.bootstrap.workspace.SourceDir) Map(java.util.Map) ArtifactCoords(io.quarkus.maven.dependency.ArtifactCoords) AbstractCompile(org.gradle.api.tasks.compile.AbstractCompile) Path(java.nio.file.Path) WorkspaceModule(io.quarkus.bootstrap.workspace.WorkspaceModule) Project(org.gradle.api.Project) ZipUtils(io.quarkus.fs.util.ZipUtils) AppModelResolverException(io.quarkus.bootstrap.resolver.AppModelResolverException) Collection(java.util.Collection) Set(java.util.Set) BootstrapConstants(io.quarkus.bootstrap.BootstrapConstants) FileSystem(java.nio.file.FileSystem) PlatformImportsImpl(io.quarkus.bootstrap.model.PlatformImportsImpl) UncheckedIOException(java.io.UncheckedIOException) ApplicationModelBuilder(io.quarkus.bootstrap.model.ApplicationModelBuilder) List(java.util.List) ApplicationModel(io.quarkus.bootstrap.model.ApplicationModel) ParameterizedToolingModelBuilder(org.gradle.tooling.provider.model.ParameterizedToolingModelBuilder) DefaultWorkspaceModule(io.quarkus.bootstrap.workspace.DefaultWorkspaceModule) GACT(io.quarkus.maven.dependency.GACT) ResolvedDependency(io.quarkus.maven.dependency.ResolvedDependency) HashUtil(io.quarkus.runtime.util.HashUtil) IncludedBuild(org.gradle.api.initialization.IncludedBuild) ProcessResources(org.gradle.language.jvm.tasks.ProcessResources) PathList(io.quarkus.paths.PathList) LaunchMode(io.quarkus.runtime.LaunchMode) FileCollection(org.gradle.api.file.FileCollection) ArrayList(java.util.ArrayList) SourceSet(org.gradle.api.tasks.SourceSet) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) DefaultDependencyArtifact(org.gradle.api.internal.artifacts.dependencies.DefaultDependencyArtifact) Configuration(org.gradle.api.artifacts.Configuration) DependencyFlags(io.quarkus.maven.dependency.DependencyFlags) ModelParameterImpl(io.quarkus.bootstrap.model.gradle.impl.ModelParameterImpl) ArtifactKey(io.quarkus.maven.dependency.ArtifactKey) ArtifactDependency(io.quarkus.maven.dependency.ArtifactDependency) Dependency(io.quarkus.maven.dependency.Dependency) ResolvedConfiguration(org.gradle.api.artifacts.ResolvedConfiguration) PlatformImports(io.quarkus.bootstrap.model.PlatformImports) GACTV(io.quarkus.maven.dependency.GACTV) CapabilityContract(io.quarkus.bootstrap.model.CapabilityContract) Properties(java.util.Properties) Files(java.nio.file.Files) JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) ResolvedArtifact(org.gradle.api.artifacts.ResolvedArtifact) GAV(io.quarkus.maven.dependency.GAV) DefaultExternalModuleDependency(org.gradle.api.internal.artifacts.dependencies.DefaultExternalModuleDependency) ResolvedDependencyBuilder(io.quarkus.maven.dependency.ResolvedDependencyBuilder) IOException(java.io.IOException) File(java.io.File) GradleException(org.gradle.api.GradleException) PathCollection(io.quarkus.paths.PathCollection) BufferedReader(java.io.BufferedReader) Collections(java.util.Collections) ResolvedConfiguration(org.gradle.api.artifacts.ResolvedConfiguration) Project(org.gradle.api.Project) SourceSet(org.gradle.api.tasks.SourceSet) ResolvedArtifact(org.gradle.api.artifacts.ResolvedArtifact) JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier) ResolvedDependencyBuilder(io.quarkus.maven.dependency.ResolvedDependencyBuilder)

Example 2 with ResolvedDependencyBuilder

use of io.quarkus.maven.dependency.ResolvedDependencyBuilder in project quarkus by quarkusio.

the class GradleApplicationModelBuilder method collectDependencies.

private void collectDependencies(ResolvedConfiguration configuration, LaunchMode mode, Project project, Map<ArtifactKey, ResolvedDependencyBuilder> appDependencies, 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
    // the project includes direct file dependencies
    final Set<File> artifactFiles = resolvedArtifacts.size() < configuration.getFiles().size() ? new HashSet<>(resolvedArtifacts.size()) : null;
    configuration.getFirstLevelModuleDependencies().forEach(d -> {
        collectDependencies(d, mode, project, appDependencies, artifactFiles, new HashSet<>(), modelBuilder, wsModule, (byte) (COLLECT_TOP_EXTENSION_RUNTIME_NODES | COLLECT_DIRECT_DEPS | COLLECT_RELOADABLE_MODULES));
    });
    if (artifactFiles != null) {
        // detect FS paths that aren't provided by the resolved artifacts
        for (File f : configuration.getFiles()) {
            if (artifactFiles.contains(f) || !f.exists()) {
                continue;
            }
            // here we are trying to represent a direct FS path dependency
            // as an artifact dependency
            // SHA1 hash is used to avoid long file names in the lib dir
            final String parentPath = f.getParent();
            final String group = HashUtil.sha1(parentPath == null ? f.getName() : parentPath);
            String name = f.getName();
            String type = ArtifactCoords.TYPE_JAR;
            if (!f.isDirectory()) {
                final int dot = f.getName().lastIndexOf('.');
                if (dot > 0) {
                    name = f.getName().substring(0, dot);
                    type = f.getName().substring(dot + 1);
                }
            }
            // hash could be a better way to represent the version
            final String version = String.valueOf(f.lastModified());
            final ResolvedDependencyBuilder artifactBuilder = ResolvedDependencyBuilder.newInstance().setGroupId(group).setArtifactId(name).setType(type).setVersion(version).setResolvedPath(f.toPath()).setDirect(true).setRuntimeCp();
            processQuarkusDependency(artifactBuilder, modelBuilder);
            appDependencies.put(artifactBuilder.getKey(), artifactBuilder);
        }
    }
}
Also used : ResolvedArtifact(org.gradle.api.artifacts.ResolvedArtifact) File(java.io.File) ResolvedDependencyBuilder(io.quarkus.maven.dependency.ResolvedDependencyBuilder)

Example 3 with ResolvedDependencyBuilder

use of io.quarkus.maven.dependency.ResolvedDependencyBuilder 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 4 with ResolvedDependencyBuilder

use of io.quarkus.maven.dependency.ResolvedDependencyBuilder in project quarkus by quarkusio.

the class GradleApplicationModelBuilder method getProjectArtifact.

public static ResolvedDependency getProjectArtifact(Project project, LaunchMode mode) {
    final ResolvedDependencyBuilder appArtifact = ResolvedDependencyBuilder.newInstance().setGroupId(project.getGroup().toString()).setArtifactId(project.getName()).setVersion(project.getVersion().toString());
    final JavaPluginConvention javaConvention = project.getConvention().findPlugin(JavaPluginConvention.class);
    if (javaConvention == null) {
        throw new GradleException("Failed to locate Java plugin extension in " + project.getPath());
    }
    final WorkspaceModule.Mutable mainModule = WorkspaceModule.builder().setModuleId(new GAV(appArtifact.getGroupId(), appArtifact.getArtifactId(), appArtifact.getVersion())).setModuleDir(project.getProjectDir().toPath()).setBuildDir(project.getBuildDir().toPath()).setBuildFile(project.getBuildFile().toPath());
    initProjectModule(project, mainModule, javaConvention.getSourceSets().findByName(SourceSet.MAIN_SOURCE_SET_NAME), SourceSet.MAIN_SOURCE_SET_NAME, ArtifactSources.MAIN);
    if (mode.equals(LaunchMode.TEST) || mode.equals(LaunchMode.DEVELOPMENT)) {
        initProjectModule(project, mainModule, javaConvention.getSourceSets().findByName(SourceSet.TEST_SOURCE_SET_NAME), SourceSet.TEST_SOURCE_SET_NAME, ArtifactSources.TEST);
    }
    final PathList.Builder paths = PathList.builder();
    collectDestinationDirs(mainModule.getMainSources().getSourceDirs(), paths);
    collectDestinationDirs(mainModule.getMainSources().getResourceDirs(), paths);
    return appArtifact.setWorkspaceModule(mainModule).setResolvedPaths(paths.build()).build();
}
Also used : JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) GradleException(org.gradle.api.GradleException) PathList(io.quarkus.paths.PathList) WorkspaceModule(io.quarkus.bootstrap.workspace.WorkspaceModule) DefaultWorkspaceModule(io.quarkus.bootstrap.workspace.DefaultWorkspaceModule) ResolvedDependencyBuilder(io.quarkus.maven.dependency.ResolvedDependencyBuilder) GAV(io.quarkus.maven.dependency.GAV)

Example 5 with ResolvedDependencyBuilder

use of io.quarkus.maven.dependency.ResolvedDependencyBuilder 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)

Aggregations

ResolvedDependencyBuilder (io.quarkus.maven.dependency.ResolvedDependencyBuilder)6 WorkspaceModule (io.quarkus.bootstrap.workspace.WorkspaceModule)4 ApplicationModelBuilder (io.quarkus.bootstrap.model.ApplicationModelBuilder)3 DefaultWorkspaceModule (io.quarkus.bootstrap.workspace.DefaultWorkspaceModule)3 ApplicationDeploymentClasspathBuilder (io.quarkus.gradle.dependency.ApplicationDeploymentClasspathBuilder)3 ArtifactDependency (io.quarkus.maven.dependency.ArtifactDependency)3 ArtifactKey (io.quarkus.maven.dependency.ArtifactKey)3 GACT (io.quarkus.maven.dependency.GACT)3 PathList (io.quarkus.paths.PathList)3 ResolvedArtifact (org.gradle.api.artifacts.ResolvedArtifact)3 JavaPluginConvention (org.gradle.api.plugins.JavaPluginConvention)3 PlatformImports (io.quarkus.bootstrap.model.PlatformImports)2 AppModelResolverException (io.quarkus.bootstrap.resolver.AppModelResolverException)2 ArtifactCoords (io.quarkus.maven.dependency.ArtifactCoords)2 Dependency (io.quarkus.maven.dependency.Dependency)2 GAV (io.quarkus.maven.dependency.GAV)2 ResolvedDependency (io.quarkus.maven.dependency.ResolvedDependency)2 PathCollection (io.quarkus.paths.PathCollection)2 LaunchMode (io.quarkus.runtime.LaunchMode)2 File (java.io.File)2