Search in sources :

Example 1 with AndArtifactFilter

use of org.apache.maven.artifact.resolver.filter.AndArtifactFilter in project wso2-synapse by wso2.

the class AbstractXarMojo method addDependencies.

private void addDependencies(Archiver archiver) throws ArchiverException, MojoExecutionException {
    Log log = getLog();
    AndArtifactFilter filter = new AndArtifactFilter();
    filter.add(new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME));
    filter.add(new ArtifactFilter() {

        public boolean include(Artifact artifact) {
            return !artifact.isOptional();
        }
    });
    filter.add(new TypeArtifactFilter("jar"));
    filter.add(buildSynapseRuntimeArtifactFilter());
    for (Artifact artifact : filterArtifacts((Set<Artifact>) project.getArtifacts(), filter)) {
        String targetFileName = artifact.getArtifactId() + "-" + artifact.getVersion() + "." + artifact.getArtifactHandler().getExtension();
        log.info("Adding " + targetFileName + " (scope " + artifact.getScope() + ")");
        archiver.addFile(artifact.getFile(), "lib/" + targetFileName);
    }
}
Also used : AndArtifactFilter(org.apache.maven.artifact.resolver.filter.AndArtifactFilter) ArtifactFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) TypeArtifactFilter(org.apache.maven.artifact.resolver.filter.TypeArtifactFilter) ScopeArtifactFilter(org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter) TypeArtifactFilter(org.apache.maven.artifact.resolver.filter.TypeArtifactFilter) ScopeArtifactFilter(org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter) Log(org.apache.maven.plugin.logging.Log) AndArtifactFilter(org.apache.maven.artifact.resolver.filter.AndArtifactFilter) Artifact(org.apache.maven.artifact.Artifact)

Example 2 with AndArtifactFilter

use of org.apache.maven.artifact.resolver.filter.AndArtifactFilter in project abstools by abstools.

the class AbstractABSMojo method resolveDependencyArtifacts.

/**
 * This method resolves the dependency artifacts from the project.
 *
 * @param theProject
 *            The POM.
 * @return resolved set of dependency artifacts.
 *
 * @throws ArtifactResolutionException
 * @throws ArtifactNotFoundException
 * @throws InvalidDependencyVersionException
 */
@SuppressWarnings("unchecked")
protected Set<Artifact> resolveDependencyArtifacts(MavenProject theProject) throws Exception {
    AndArtifactFilter filter = new AndArtifactFilter();
    filter.add(new ScopeArtifactFilter(Artifact.SCOPE_TEST));
    filter.add(new ArtifactFilter() {

        public boolean include(Artifact artifact) {
            return !artifact.isOptional();
        }
    });
    // TODO follow the dependenciesManagement and override rules
    Set<Artifact> artifacts = theProject.createArtifacts(factory, Artifact.SCOPE_RUNTIME, filter);
    for (Artifact artifact : artifacts) {
        resolver.resolve(artifact, remoteRepos, localRepo);
    }
    return artifacts;
}
Also used : AndArtifactFilter(org.apache.maven.artifact.resolver.filter.AndArtifactFilter) ArtifactFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) ScopeArtifactFilter(org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter) ScopeArtifactFilter(org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter) AndArtifactFilter(org.apache.maven.artifact.resolver.filter.AndArtifactFilter) Artifact(org.apache.maven.artifact.Artifact) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact)

Example 3 with AndArtifactFilter

use of org.apache.maven.artifact.resolver.filter.AndArtifactFilter in project xwiki-platform by xwiki.

the class PackageMojo method resolveTransitively.

private Set<Artifact> resolveTransitively(Set<Artifact> artifacts) throws MojoExecutionException {
    AndArtifactFilter filter = new AndArtifactFilter(Arrays.asList(new ScopeArtifactFilter("runtime"), // for JSX. See https://jira.xwiki.org/browse/XWIKI-6151 for more details.
    new ExcludesArtifactFilter(Arrays.asList("org.apache.xmlgraphic:batik-js", "commons-logging:commons-logging", "commons-logging:commons-logging-api", "log4j:log4j"))));
    ArtifactResolutionRequest request = new ArtifactResolutionRequest().setArtifact(this.project.getArtifact()).setArtifactDependencies(artifacts).setCollectionFilter(filter).setRemoteRepositories(this.remoteRepositories).setLocalRepository(this.localRepository).setManagedVersionMap(getManagedVersionMap()).setResolveRoot(false);
    ArtifactResolutionResult resolutionResult = this.repositorySystem.resolve(request);
    if (resolutionResult.hasExceptions()) {
        throw new MojoExecutionException(String.format("Failed to resolve artifacts [%s]", artifacts, resolutionResult.getExceptions().get(0)));
    }
    return resolutionResult.getArtifacts();
}
Also used : ScopeArtifactFilter(org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ExcludesArtifactFilter(org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter) ArtifactResolutionRequest(org.apache.maven.artifact.resolver.ArtifactResolutionRequest) ArtifactResolutionResult(org.apache.maven.artifact.resolver.ArtifactResolutionResult) AndArtifactFilter(org.apache.maven.artifact.resolver.filter.AndArtifactFilter)

Example 4 with AndArtifactFilter

use of org.apache.maven.artifact.resolver.filter.AndArtifactFilter in project scala-maven-plugin by davidB.

the class ScalaMojoSupport method resolveArtifactDependencies.

/**
 * This method resolves all transitive dependencies of an artifact.
 *
 * @param artifact the {@link Artifact} used to retrieve dependencies.
 *
 * @return resolved {@link Set} of dependencies.
 *
 * @throws {@link Exception} when various artifact resolution mechanisms fail.
 */
protected final Set<Artifact> resolveArtifactDependencies(final Artifact artifact) throws Exception {
    final AndArtifactFilter filter = new AndArtifactFilter();
    filter.add(new ScopeArtifactFilter(Artifact.SCOPE_TEST));
    filter.add(new ArtifactFilter() {

        public boolean include(Artifact artifact) {
            return !artifact.isOptional();
        }
    });
    // Use the collection filter as the resolution filter.
    return resolveDependencyArtifacts(artifact, filter, filter);
}
Also used : AndArtifactFilter(org.apache.maven.artifact.resolver.filter.AndArtifactFilter) ArtifactFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) ScopeArtifactFilter(org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter) ScalaDistroArtifactFilter(scala_maven_dependency.ScalaDistroArtifactFilter) ScopeArtifactFilter(org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter) AndArtifactFilter(org.apache.maven.artifact.resolver.filter.AndArtifactFilter) Artifact(org.apache.maven.artifact.Artifact)

Example 5 with AndArtifactFilter

use of org.apache.maven.artifact.resolver.filter.AndArtifactFilter in project maven-plugins by apache.

the class DependencyFilesetsTask method filterArtifacts.

/**
 * Filter a set of artifacts using the scopes and type filters.
 *
 * @param artifacts {@link Artifact} set.
 * @return The set of filtered artifacts.
 */
public Set<Artifact> filterArtifacts(Set<Artifact> artifacts) {
    if (scopes == null) {
        scopes = "";
    }
    if (types == null) {
        types = "";
    }
    if (scopes.equals("") && types.equals("")) {
        return artifacts;
    }
    AndArtifactFilter filter = new AndArtifactFilter();
    if (!scopes.equals("")) {
        filter.add(new SpecificScopesArtifactFilter(getScopes()));
    }
    if (!types.equals("")) {
        filter.add(new TypesArtifactFilter(getTypes()));
    }
    Set<Artifact> artifactsResult = new LinkedHashSet<Artifact>();
    for (Artifact artifact : artifacts) {
        if (filter.include(artifact)) {
            artifactsResult.add(artifact);
        }
    }
    return artifactsResult;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) TypesArtifactFilter(org.apache.maven.ant.tasks.support.TypesArtifactFilter) SpecificScopesArtifactFilter(org.apache.maven.ant.tasks.support.SpecificScopesArtifactFilter) AndArtifactFilter(org.apache.maven.artifact.resolver.filter.AndArtifactFilter) Artifact(org.apache.maven.artifact.Artifact)

Aggregations

AndArtifactFilter (org.apache.maven.artifact.resolver.filter.AndArtifactFilter)9 Artifact (org.apache.maven.artifact.Artifact)8 ArtifactFilter (org.apache.maven.artifact.resolver.filter.ArtifactFilter)6 ScopeArtifactFilter (org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter)4 ArrayList (java.util.ArrayList)3 LinkedHashSet (java.util.LinkedHashSet)3 PatternExcludesArtifactFilter (org.apache.maven.shared.artifact.filter.PatternExcludesArtifactFilter)3 PatternIncludesArtifactFilter (org.apache.maven.shared.artifact.filter.PatternIncludesArtifactFilter)3 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 Attrs (aQute.bnd.header.Attrs)1 Map (java.util.Map)1 SpecificScopesArtifactFilter (org.apache.maven.ant.tasks.support.SpecificScopesArtifactFilter)1 TypesArtifactFilter (org.apache.maven.ant.tasks.support.TypesArtifactFilter)1 DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)1 ArtifactResolutionRequest (org.apache.maven.artifact.resolver.ArtifactResolutionRequest)1 ArtifactResolutionResult (org.apache.maven.artifact.resolver.ArtifactResolutionResult)1 ExcludesArtifactFilter (org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter)1 TypeArtifactFilter (org.apache.maven.artifact.resolver.filter.TypeArtifactFilter)1 Log (org.apache.maven.plugin.logging.Log)1 InvalidAssemblerConfigurationException (org.apache.maven.plugins.assembly.InvalidAssemblerConfigurationException)1