Search in sources :

Example 6 with ArtifactResult

use of org.apache.maven.shared.artifact.resolve.ArtifactResult in project maven-plugins by apache.

the class DefaultDependencyResolver method updateDependencySetResolutionRequirements.

void updateDependencySetResolutionRequirements(final DependencySet set, final ResolutionManagementInfo requirements, AssemblyId assemblyId, ProjectBuildingRequest buildingRequest, final MavenProject... projects) throws DependencyResolutionException {
    requirements.setResolutionRequired(true);
    requirements.setResolvedTransitively(set.isUseTransitiveDependencies());
    ScopeFilter scopeFilter = FilterUtils.newScopeFilter(set.getScope());
    requirements.setScopeFilter(scopeFilter);
    for (final MavenProject project : projects) {
        if (project == null) {
            continue;
        }
        Set<Artifact> dependencyArtifacts = project.getDependencyArtifacts();
        if (dependencyArtifacts == null) {
            try {
                Iterable<ArtifactResult> artifactResults = dependencyResolver.resolveDependencies(buildingRequest, project.getModel(), scopeFilter);
                dependencyArtifacts = new HashSet<Artifact>();
                for (ArtifactResult artifactResult : artifactResults) {
                    dependencyArtifacts.add(artifactResult.getArtifact());
                }
                project.setDependencyArtifacts(dependencyArtifacts);
            } catch (final DependencyResolverException e) {
                throw new DependencyResolutionException("Failed to create dependency artifacts for resolution. Assembly: " + assemblyId, e);
            }
        }
        requirements.addArtifacts(dependencyArtifacts);
        getLogger().debug("Dependencies for project: " + project.getId() + " are:\n" + StringUtils.join(dependencyArtifacts.iterator(), "\n"));
    }
}
Also used : ScopeFilter(org.apache.maven.shared.artifact.filter.resolve.ScopeFilter) MavenProject(org.apache.maven.project.MavenProject) DependencyResolverException(org.apache.maven.shared.dependencies.resolve.DependencyResolverException) Artifact(org.apache.maven.artifact.Artifact) ArtifactResult(org.apache.maven.shared.artifact.resolve.ArtifactResult)

Example 7 with ArtifactResult

use of org.apache.maven.shared.artifact.resolve.ArtifactResult in project maven-plugins by apache.

the class DefaultRepositoryAssembler method buildRemoteRepository.

public void buildRemoteRepository(File repositoryDirectory, RepositoryInfo repository, RepositoryBuilderConfigSource configSource) throws RepositoryAssemblyException {
    MavenProject project = configSource.getProject();
    ProjectBuildingRequest buildingRequest = configSource.getProjectBuildingRequest();
    Iterable<ArtifactResult> result = null;
    Collection<Dependency> dependencies = project.getDependencies();
    if (dependencies == null) {
        Logger logger = getLogger();
        if (logger.isDebugEnabled()) {
            logger.debug("dependency-artifact set for project: " + project.getId() + " is null. Skipping repository processing.");
        }
        return;
    }
    Collection<Dependency> managedDependencies = null;
    if (project.getDependencyManagement() != null) {
        managedDependencies = project.getDependencyManagement().getDependencies();
    }
    // Older Aether versions use an cache which can't be cleared. So can't delete repoDir and use it again.
    // Instead create a temporary repository, delete it at end (should be in a finally-block)
    File tempRepo = new File(repositoryDirectory.getParentFile(), repositoryDirectory.getName() + "_tmp");
    buildingRequest = repositoryManager.setLocalRepositoryBasedir(buildingRequest, tempRepo);
    try {
        result = dependencyResolver.resolveDependencies(buildingRequest, dependencies, managedDependencies, null);
    } catch (DependencyResolverException e) {
        throw new RepositoryAssemblyException("Error resolving artifacts: " + e.getMessage(), e);
    }
    ArtifactFilter filter = buildRepositoryFilter(repository, project);
    buildingRequest = repositoryManager.setLocalRepositoryBasedir(buildingRequest, repositoryDirectory);
    Map<String, GroupVersionAlignment> groupVersionAlignments = createGroupVersionAlignments(repository.getGroupVersionAlignments());
    assembleRepositoryArtifacts(buildingRequest, result, filter, groupVersionAlignments);
    if (repository.isIncludeMetadata()) {
    //            assembleRepositoryMetadata( result, filter, centralRepository, targetRepository );
    }
    try {
        FileUtils.deleteDirectory(tempRepo);
    } catch (IOException e) {
    // noop
    }
}
Also used : DependencyResolverException(org.apache.maven.shared.dependencies.resolve.DependencyResolverException) Dependency(org.apache.maven.model.Dependency) IOException(java.io.IOException) Logger(org.codehaus.plexus.logging.Logger) ArtifactResult(org.apache.maven.shared.artifact.resolve.ArtifactResult) ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) ScopeArtifactFilter(org.apache.maven.shared.artifact.filter.ScopeArtifactFilter) PatternExcludesArtifactFilter(org.apache.maven.shared.artifact.filter.PatternExcludesArtifactFilter) AndArtifactFilter(org.apache.maven.artifact.resolver.filter.AndArtifactFilter) ArtifactFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) PatternIncludesArtifactFilter(org.apache.maven.shared.artifact.filter.PatternIncludesArtifactFilter) MavenProject(org.apache.maven.project.MavenProject) GroupVersionAlignment(org.apache.maven.plugins.assembly.repository.model.GroupVersionAlignment) File(java.io.File)

Aggregations

ArtifactResult (org.apache.maven.shared.artifact.resolve.ArtifactResult)7 Artifact (org.apache.maven.artifact.Artifact)6 DependencyResolverException (org.apache.maven.shared.dependencies.resolve.DependencyResolverException)4 File (java.io.File)3 MavenProject (org.apache.maven.project.MavenProject)3 ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)3 ArtifactResolverException (org.apache.maven.shared.artifact.resolve.ArtifactResolverException)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 LinkedHashSet (java.util.LinkedHashSet)2 ArtifactFilter (org.apache.maven.artifact.resolver.filter.ArtifactFilter)2 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 List (java.util.List)1 DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)1 ArtifactHandler (org.apache.maven.artifact.handler.ArtifactHandler)1 AndArtifactFilter (org.apache.maven.artifact.resolver.filter.AndArtifactFilter)1 MavenSession (org.apache.maven.execution.MavenSession)1 Dependency (org.apache.maven.model.Dependency)1 BootclasspathArtifact (org.apache.maven.plugin.javadoc.options.BootclasspathArtifact)1