Search in sources :

Example 1 with ExcludesArtifactFilter

use of org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter in project camel by apache.

the class RunMojo method getAllDependencies.

// generic method to retrieve all the transitive dependencies
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;
        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 (Exclusion exclusion : dependency.getExclusions()) {
            exclusions.add(exclusion.getGroupId() + ":" + exclusion.getArtifactId());
        }
        ArtifactFilter newFilter = new ExcludesArtifactFilter(exclusions);
        art.setDependencyFilter(newFilter);
        artifacts.add(art);
    }
    return artifacts;
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArrayList(java.util.ArrayList) VersionRange(org.apache.maven.artifact.versioning.VersionRange) Dependency(org.apache.maven.model.Dependency) ExecutableDependency(org.codehaus.mojo.exec.ExecutableDependency) Artifact(org.apache.maven.artifact.Artifact) ArtifactFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) ExcludesArtifactFilter(org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter) InvalidVersionSpecificationException(org.apache.maven.artifact.versioning.InvalidVersionSpecificationException) ExcludesArtifactFilter(org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter) Exclusion(org.apache.maven.model.Exclusion) File(java.io.File)

Example 2 with ExcludesArtifactFilter

use of org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter 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 3 with ExcludesArtifactFilter

use of org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter in project randomizedtesting by randomizedtesting.

the class JUnit4Mojo method resolveArtifact.

/**
 * Resolve a given artifact given exclusion list. (copied from surefire).
 */
@SuppressWarnings({ "deprecation" })
private ArtifactResolutionResult resolveArtifact(Artifact artifact, Artifact... filtered) {
    final ArtifactFilter filter;
    if (filtered.length > 0) {
        List<String> exclusions = new ArrayList<>(filtered.length);
        for (Artifact filteredArtifact : filtered) {
            exclusions.add(filteredArtifact.getGroupId() + ":" + filteredArtifact.getArtifactId());
        }
        filter = new ExcludesArtifactFilter(exclusions);
    } else {
        filter = null;
    }
    Artifact originatingArtifact = repositorySystem.createArtifact("dummy", "dummy", "1.0", "jar");
    try {
        return resolver.resolveTransitively(Collections.singleton(artifact), originatingArtifact, session.getLocalRepository(), project.getPluginArtifactRepositories(), metadataSource, filter);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : ExcludesArtifactFilter(org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter) ArtifactFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) PatternIncludesArtifactFilter(org.apache.maven.shared.artifact.filter.PatternIncludesArtifactFilter) ScopeArtifactFilter(org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter) ExcludesArtifactFilter(org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter) ArrayList(java.util.ArrayList) Artifact(org.apache.maven.artifact.Artifact) InvalidVersionSpecificationException(org.apache.maven.artifact.versioning.InvalidVersionSpecificationException) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 4 with ExcludesArtifactFilter

use of org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter in project camel by apache.

the class RunMojo method getAllDependencies.

// generic method to retrieve all the transitive dependencies
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;
        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 (Exclusion exclusion : dependency.getExclusions()) {
            exclusions.add(exclusion.getGroupId() + ":" + exclusion.getArtifactId());
        }
        ArtifactFilter newFilter = new ExcludesArtifactFilter(exclusions);
        art.setDependencyFilter(newFilter);
        artifacts.add(art);
    }
    return artifacts;
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArrayList(java.util.ArrayList) VersionRange(org.apache.maven.artifact.versioning.VersionRange) Dependency(org.apache.maven.model.Dependency) ExecutableDependency(org.codehaus.mojo.exec.ExecutableDependency) Artifact(org.apache.maven.artifact.Artifact) ArtifactFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) ExcludesArtifactFilter(org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter) ScopeArtifactFilter(org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter) InvalidVersionSpecificationException(org.apache.maven.artifact.versioning.InvalidVersionSpecificationException) ExcludesArtifactFilter(org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter) Exclusion(org.apache.maven.model.Exclusion) File(java.io.File)

Aggregations

ExcludesArtifactFilter (org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter)4 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)4 ArrayList (java.util.ArrayList)3 Artifact (org.apache.maven.artifact.Artifact)3 ArtifactFilter (org.apache.maven.artifact.resolver.filter.ArtifactFilter)3 ScopeArtifactFilter (org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter)3 InvalidVersionSpecificationException (org.apache.maven.artifact.versioning.InvalidVersionSpecificationException)3 File (java.io.File)2 VersionRange (org.apache.maven.artifact.versioning.VersionRange)2 Dependency (org.apache.maven.model.Dependency)2 Exclusion (org.apache.maven.model.Exclusion)2 ExecutableDependency (org.codehaus.mojo.exec.ExecutableDependency)2 IOException (java.io.IOException)1 ArtifactResolutionRequest (org.apache.maven.artifact.resolver.ArtifactResolutionRequest)1 ArtifactResolutionResult (org.apache.maven.artifact.resolver.ArtifactResolutionResult)1 AndArtifactFilter (org.apache.maven.artifact.resolver.filter.AndArtifactFilter)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1 PatternIncludesArtifactFilter (org.apache.maven.shared.artifact.filter.PatternIncludesArtifactFilter)1 BuildException (org.apache.tools.ant.BuildException)1