Example usage for org.apache.maven.artifact.resolver.filter ExcludesArtifactFilter ExcludesArtifactFilter

List of usage examples for org.apache.maven.artifact.resolver.filter ExcludesArtifactFilter ExcludesArtifactFilter

Introduction

In this page you can find the example usage for org.apache.maven.artifact.resolver.filter ExcludesArtifactFilter ExcludesArtifactFilter.

Prototype

public ExcludesArtifactFilter(List<String> patterns) 

Source Link

Usage

From source file:com.alibaba.citrus.maven.eclipse.base.ide.AbstractIdeSupportMojo.java

License:Apache License

/**
 * Apply exclusion filters to direct AND transitive dependencies.
 *
 * @param artifact//from  ww  w  .  ja va  2 s .  com
 * @param dependency
 */
private void handleExclusions(Artifact artifact, Dependency dependency) {

    List exclusions = new ArrayList();
    for (Iterator j = dependency.getExclusions().iterator(); j.hasNext();) {
        Exclusion e = (Exclusion) j.next();
        exclusions.add(e.getGroupId() + ":" + e.getArtifactId()); //$NON-NLS-1$
    }

    ArtifactFilter newFilter = new ExcludesArtifactFilter(exclusions);

    artifact.setDependencyFilter(newFilter);
}

From source file:com.github.maven_nar.NarIntegrationTestMojo.java

License:Apache License

private ArtifactResolutionResult resolveArtifact(final Artifact filteredArtifact,
        final Artifact providerArtifact) throws ArtifactResolutionException, ArtifactNotFoundException {
    ArtifactFilter filter = null;/*from w  w w  .  j a v a  2 s.c  o m*/
    if (filteredArtifact != null) {
        filter = new ExcludesArtifactFilter(Collections
                .singletonList(filteredArtifact.getGroupId() + ":" + filteredArtifact.getArtifactId()));
    }

    final Artifact originatingArtifact = this.artifactFactory.createBuildArtifact("dummy", "dummy", "1.0",
            "jar");

    // DUNS, use access method rather than "localRepository" field.
    return this.artifactResolver.resolveTransitively(Collections.singleton(providerArtifact),
            originatingArtifact, getLocalRepository(), getRemoteRepositories(), this.metadataSource, filter);
}

From source file:com.github.zhve.ideaplugin.ArtifactDependencyResolver.java

License:Apache License

/**
 * Convert Dependency to Artifact//  w ww .ja  v  a2  s. com
 *
 * @param artifactFactory standard Maven's factory to create artifacts
 * @param dependency      dependency
 * @return artifact
 * @throws InvalidVersionSpecificationException if VersionRange is invalid
 */
private Artifact toDependencyArtifact(ArtifactFactory artifactFactory, Dependency dependency)
        throws InvalidVersionSpecificationException {
    // instantiate
    Artifact dependencyArtifact = artifactFactory.createDependencyArtifact(dependency.getGroupId(),
            dependency.getArtifactId(), VersionRange.createFromVersionSpec(dependency.getVersion()),
            dependency.getType(), dependency.getClassifier(),
            dependency.getScope() == null ? Artifact.SCOPE_COMPILE : dependency.getScope(), null,
            dependency.isOptional());

    // apply exclusions is needed
    if (!dependency.getExclusions().isEmpty()) {
        List<String> exclusions = new ArrayList<String>();
        for (Exclusion exclusion : dependency.getExclusions())
            exclusions.add(exclusion.getGroupId() + ":" + exclusion.getArtifactId());
        dependencyArtifact.setDependencyFilter(new ExcludesArtifactFilter(exclusions));
    }

    // additional
    if (Artifact.SCOPE_SYSTEM.equalsIgnoreCase(dependency.getScope()))
        dependencyArtifact.setFile(new File(dependency.getSystemPath()));

    return dependencyArtifact;
}

From source file:com.google.code.sbt.compiler.plugin.AbstractSBTCompileMojo.java

License:Apache License

private List<File> getCompilerDependencies(Artifact scalaCompilerArtifact, Artifact scalaLibraryArtifact)
        throws ArtifactNotFoundException, ArtifactResolutionException {
    ArtifactFilter scalaLibraryFilter = new ExcludesArtifactFilter(Collections
            .singletonList(scalaLibraryArtifact.getGroupId() + ":" + scalaLibraryArtifact.getArtifactId()));
    List<File> d = new ArrayList<File>();
    for (Artifact artifact : getAllDependencies(scalaCompilerArtifact, scalaLibraryFilter)) {
        if (!scalaCompilerArtifact.getGroupId().equals(artifact.getGroupId())
                || !scalaCompilerArtifact.getArtifactId().equals(artifact.getArtifactId())) {
            d.add(artifact.getFile()); // don't add scalaCompilerArtifact file
        }//from w w w.j  av a  2s  .c  o m
    }
    return d;
}

From source file:com.ning.maven.plugins.dependencyversionscheck.AbstractDependencyVersionsMojo.java

License:Apache License

/**
 * Resolve all transitive dependencies relative to a given dependency, based off the artifact given. A scope filter can be added which limits the
 * results to the scopes present in that filter.
 *//*from w w w.j a v a 2  s  .c  o  m*/
private List resolveTransitiveVersions(final Dependency dependency, final Artifact artifact,
        final String artifactName, final ArtifactFilter scopeFilter) throws InvalidDependencyVersionException,
        ArtifactResolutionException, ArtifactNotFoundException, ProjectBuildingException {
    ArtifactFilter exclusionFilter = null;

    if (!CollectionUtils.isEmpty(dependency.getExclusions())) {
        final List exclusions = new ArrayList();
        for (Iterator j = dependency.getExclusions().iterator(); j.hasNext();) {
            final Exclusion e = (Exclusion) j.next();
            exclusions.add(e.getGroupId() + ":" + e.getArtifactId());
        }

        exclusionFilter = new ExcludesArtifactFilter(exclusions);
        LOG.debug("Built Exclusion Filter: {}", exclusions);
    }

    final ArtifactFilter filter;
    if (exclusionFilter != null) {
        AndArtifactFilter andFilter = new AndArtifactFilter();
        andFilter.add(exclusionFilter);
        andFilter.add(scopeFilter);
        filter = andFilter;
    } else {
        filter = scopeFilter;
    }

    final Collection dependenciesToCheck = resolveDependenciesInItsOwnScope(artifact, filter);

    return resolveTransitiveVersions(dependency, dependenciesToCheck, artifactName, scopeFilter);
}

From source file:org.apache.camel.guice.maven.RunMojo.java

License:Apache License

private Collection<Artifact> getAllDependencies() throws MojoExecutionException {
    List<Artifact> artifacts = new ArrayList<Artifact>();

    for (Iterator<?> dependencies = project.getDependencies().iterator(); dependencies.hasNext();) {
        Dependency dependency = (Dependency) dependencies.next();

        String groupId = dependency.getGroupId();
        String artifactId = dependency.getArtifactId();

        VersionRange versionRange;/*  w  w  w .  jav a2  s.  c  o m*/
        try {
            versionRange = VersionRange.createFromVersionSpec(dependency.getVersion());
        } catch (InvalidVersionSpecificationException e) {
            throw new MojoExecutionException("unable to parse version", e);
        }

        String type = dependency.getType();
        if (type == null) {
            type = "jar";
        }
        String classifier = dependency.getClassifier();
        boolean optional = dependency.isOptional();
        String scope = dependency.getScope();
        if (scope == null) {
            scope = Artifact.SCOPE_COMPILE;
        }

        Artifact art = this.artifactFactory.createDependencyArtifact(groupId, artifactId, versionRange, type,
                classifier, scope, null, optional);

        if (scope.equalsIgnoreCase(Artifact.SCOPE_SYSTEM)) {
            art.setFile(new File(dependency.getSystemPath()));
        }

        List<String> exclusions = new ArrayList<String>();
        for (Iterator<?> j = dependency.getExclusions().iterator(); j.hasNext();) {
            Exclusion e = (Exclusion) j.next();
            exclusions.add(e.getGroupId() + ":" + e.getArtifactId());
        }

        ArtifactFilter newFilter = new ExcludesArtifactFilter(exclusions);

        art.setDependencyFilter(newFilter);

        artifacts.add(art);
    }

    return artifacts;
}

From source file:org.apache.tuscany.maven.plugin.eclipse.AbstractIdeSupportMojo.java

License:Apache License

/**
 * Returns the list of project artifacts. Also artifacts generated from referenced projects will be added, but with
 * the <code>resolved</code> property set to true.
 *
 * @return list of projects artifacts//from   www  . j  ava  2 s  .c om
 * @throws MojoExecutionException if unable to parse dependency versions
 */
private Set getProjectArtifacts() throws MojoExecutionException {
    // keep it sorted, this should avoid random classpath order in tests
    Set artifacts = new TreeSet();

    for (Iterator dependencies = getProject().getDependencies().iterator(); dependencies.hasNext();) {
        Dependency dependency = (Dependency) dependencies.next();

        String groupId = dependency.getGroupId();
        String artifactId = dependency.getArtifactId();
        VersionRange versionRange;
        try {
            versionRange = VersionRange.createFromVersionSpec(dependency.getVersion());
        } catch (InvalidVersionSpecificationException e) {
            throw new MojoExecutionException(Messages.getString("AbstractIdeSupportMojo.unabletoparseversion", //$NON-NLS-1$
                    new Object[] { dependency.getArtifactId(), dependency.getVersion(), dependency.getManagementKey(),
                            e.getMessage() }),
                    e);
        }

        String type = dependency.getType();
        if (type == null) {
            type = Constants.PROJECT_PACKAGING_JAR;
        }
        String classifier = dependency.getClassifier();
        boolean optional = dependency.isOptional();
        String scope = dependency.getScope();
        if (scope == null) {
            scope = Artifact.SCOPE_COMPILE;
        }

        Artifact art = getArtifactFactory().createDependencyArtifact(groupId, artifactId, versionRange, type,
                classifier, scope, optional);

        if (scope.equalsIgnoreCase(Artifact.SCOPE_SYSTEM)) {
            art.setFile(new File(dependency.getSystemPath()));
        }

        List exclusions = new ArrayList();
        for (Iterator j = dependency.getExclusions().iterator(); j.hasNext();) {
            Exclusion e = (Exclusion) j.next();
            exclusions.add(e.getGroupId() + ":" + e.getArtifactId()); //$NON-NLS-1$
        }

        ArtifactFilter newFilter = new ExcludesArtifactFilter(exclusions);

        art.setDependencyFilter(newFilter);

        artifacts.add(art);
    }

    return artifacts;
}

From source file:org.apache.tuscany.maven.plugin.surefire.OSGiSurefirePlugin.java

License:Apache License

private ArtifactResolutionResult resolveArtifact(Artifact filteredArtifact, Artifact providerArtifact)
        throws ArtifactResolutionException, ArtifactNotFoundException {
    ArtifactFilter filter = null;//www  .  j  a  v  a 2s  .c  o m
    if (filteredArtifact != null) {
        filter = new ExcludesArtifactFilter(Collections
                .singletonList(filteredArtifact.getGroupId() + ":" + filteredArtifact.getArtifactId()));
    }

    Artifact originatingArtifact = artifactFactory.createBuildArtifact("dummy", "dummy", "1.0", "jar");

    return artifactResolver.resolveTransitively(Collections.singleton(providerArtifact), originatingArtifact,
            localRepository, remoteRepositories, metadataSource, filter);
}

From source file:org.codehaus.mojo.appassembler.CreateRepositoryMojo.java

License:Open Source License

private void installBooterArtifacts(ArtifactRepository artifactRepository) throws MojoExecutionException {
    Artifact artifact = artifactFactory.createDependencyArtifact("org.codehaus.mojo.appassembler",
            "appassembler-booter", VersionRange.createFromVersion(pluginVersion), "jar", null,
            Artifact.SCOPE_RUNTIME);/*from w  w w . j a v a2 s.c om*/
    try {
        Artifact p = artifactFactory.createBuildArtifact("org.codehaus.mojo.appassembler",
                "appassembler-maven-plugin", pluginVersion, "jar");

        ArtifactFilter filter = new ExcludesArtifactFilter(Collections.singletonList("junit:junit"));
        ArtifactResolutionResult result = artifactResolver.resolveTransitively(Collections.singleton(artifact),
                p, localRepository, Collections.EMPTY_LIST, metadataSource, filter);
        for (Iterator i = result.getArtifacts().iterator(); i.hasNext();) {
            Artifact a = (Artifact) i.next();
            installArtifact(a, artifactRepository, this.useTimestampInSnapshotFileName);
        }
    } catch (ArtifactResolutionException e) {
        throw new MojoExecutionException("Failed to copy artifact.", e);
    } catch (ArtifactNotFoundException e) {
        throw new MojoExecutionException("Failed to copy artifact.", e);
    }
}

From source file:org.codehaus.mojo.pluginsupport.MojoSupport.java

License:Apache License

protected Set getProjectArtifacts(final MavenProject project, final boolean resolve)
        throws MojoExecutionException {
    Set artifacts = new HashSet();

    Iterator dependencies = project.getDependencies().iterator();
    while (dependencies.hasNext()) {
        Dependency dep = (Dependency) dependencies.next();

        String groupId = dep.getGroupId();
        String artifactId = dep.getArtifactId();
        VersionRange versionRange = VersionRange.createFromVersion(dep.getVersion());
        String type = dep.getType();
        if (type == null) {
            type = "jar";
        }// ww w.j a v  a 2  s  .com

        String classifier = dep.getClassifier();
        boolean optional = dep.isOptional();
        String scope = dep.getScope();
        if (scope == null) {
            scope = Artifact.SCOPE_COMPILE;
        }

        Artifact artifact = getArtifactFactory().createDependencyArtifact(groupId, artifactId, versionRange,
                type, classifier, scope, optional);

        if (scope.equalsIgnoreCase(Artifact.SCOPE_SYSTEM)) {
            artifact.setFile(new File(dep.getSystemPath()));
        }

        List exclusions = new ArrayList();
        for (Iterator j = dep.getExclusions().iterator(); j.hasNext();) {
            Exclusion e = (Exclusion) j.next();
            exclusions.add(e.getGroupId() + ":" + e.getArtifactId());
        }

        ArtifactFilter newFilter = new ExcludesArtifactFilter(exclusions);
        artifact.setDependencyFilter(newFilter);

        if (resolve && !artifact.isResolved()) {
            log.debug("Resolving artifact: " + artifact);
            artifact = resolveArtifact(artifact);
        }

        artifacts.add(artifact);
    }

    return artifacts;
}