Search in sources :

Example 1 with ScopeFilter

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

the class AddDependencySetsTask method resolveDependencyArtifacts.

Set<Artifact> resolveDependencyArtifacts(final DependencySet dependencySet) throws InvalidAssemblerConfigurationException {
    final Set<Artifact> dependencyArtifacts = new LinkedHashSet<Artifact>();
    if (resolvedArtifacts != null) {
        dependencyArtifacts.addAll(resolvedArtifacts);
    }
    if (dependencySet.isUseProjectArtifact()) {
        final Artifact projectArtifact = project.getArtifact();
        if ((projectArtifact != null) && (projectArtifact.getFile() != null)) {
            dependencyArtifacts.add(projectArtifact);
        } else {
            logger.warn("Cannot include project artifact: " + projectArtifact + "; it doesn't have an associated file or directory.");
        }
    }
    if (dependencySet.isUseProjectAttachments()) {
        final List<Artifact> attachments = project.getAttachedArtifacts();
        if (attachments != null) {
            for (final Artifact attachment : attachments) {
                if (attachment.getFile() != null) {
                    dependencyArtifacts.add(attachment);
                } else {
                    logger.warn("Cannot include attached artifact: " + project.getId() + " for project: " + project.getId() + "; it doesn't have an associated file or directory.");
                }
            }
        }
    }
    if (dependencySet.isUseTransitiveFiltering()) {
        logger.debug("Filtering dependency artifacts USING transitive dependency path information.");
    } else {
        logger.debug("Filtering dependency artifacts WITHOUT transitive dependency path information.");
    }
    final ScopeFilter scopeFilter = FilterUtils.newScopeFilter(dependencySet.getScope());
    final ArtifactFilter filter = new ArtifactIncludeFilterTransformer().transform(scopeFilter);
    FilterUtils.filterArtifacts(dependencyArtifacts, dependencySet.getIncludes(), dependencySet.getExcludes(), dependencySet.isUseStrictFiltering(), dependencySet.isUseTransitiveFiltering(), logger, filter);
    return dependencyArtifacts;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ArtifactFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) ScopeFilter(org.apache.maven.shared.artifact.filter.resolve.ScopeFilter) ArtifactIncludeFilterTransformer(org.apache.maven.shared.artifact.filter.resolve.transform.ArtifactIncludeFilterTransformer) Artifact(org.apache.maven.artifact.Artifact)

Example 2 with ScopeFilter

use of org.apache.maven.shared.artifact.filter.resolve.ScopeFilter 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 {
                ProjectBuildingRequest pbr = new DefaultProjectBuildingRequest(buildingRequest);
                pbr.setRemoteRepositories(project.getRemoteArtifactRepositories());
                Iterable<ArtifactResult> artifactResults = dependencyResolver.resolveDependencies(pbr, 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 : ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest) 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) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest) ArtifactResult(org.apache.maven.shared.artifact.resolve.ArtifactResult)

Aggregations

Artifact (org.apache.maven.artifact.Artifact)2 ScopeFilter (org.apache.maven.shared.artifact.filter.resolve.ScopeFilter)2 LinkedHashSet (java.util.LinkedHashSet)1 ArtifactFilter (org.apache.maven.artifact.resolver.filter.ArtifactFilter)1 DefaultProjectBuildingRequest (org.apache.maven.project.DefaultProjectBuildingRequest)1 MavenProject (org.apache.maven.project.MavenProject)1 ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)1 ArtifactIncludeFilterTransformer (org.apache.maven.shared.artifact.filter.resolve.transform.ArtifactIncludeFilterTransformer)1 ArtifactResult (org.apache.maven.shared.artifact.resolve.ArtifactResult)1 DependencyResolverException (org.apache.maven.shared.dependencies.resolve.DependencyResolverException)1