Search in sources :

Example 1 with ArtifactFilterException

use of org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException in project maven-plugins by apache.

the class AbstractDependencyFilterMojo method filterMarkedDependencies.

/**
     * Filter the marked dependencies
     *
     * @param artifacts
     * @return status set
     * @throws MojoExecutionException
     */
protected DependencyStatusSets filterMarkedDependencies(Set<Artifact> artifacts) throws MojoExecutionException {
    // remove files that have markers already
    FilterArtifacts filter = new FilterArtifacts();
    filter.clearFilters();
    filter.addFilter(getMarkedArtifactFilter());
    Set<Artifact> unMarkedArtifacts;
    try {
        unMarkedArtifacts = filter.filter(artifacts);
    } catch (ArtifactFilterException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
    // calculate the skipped artifacts
    Set<Artifact> skippedArtifacts = new LinkedHashSet<Artifact>();
    skippedArtifacts.addAll(artifacts);
    skippedArtifacts.removeAll(unMarkedArtifacts);
    return new DependencyStatusSets(unMarkedArtifacts, null, skippedArtifacts);
}
Also used : ArtifactFilterException(org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException) LinkedHashSet(java.util.LinkedHashSet) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) FilterArtifacts(org.apache.maven.shared.artifact.filter.collection.FilterArtifacts) DependencyStatusSets(org.apache.maven.plugins.dependency.utils.DependencyStatusSets) Artifact(org.apache.maven.artifact.Artifact)

Example 2 with ArtifactFilterException

use of org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException in project maven-plugins by apache.

the class MarkerFileFilter method isArtifactIncluded.

@Override
public boolean isArtifactIncluded(ArtifactItem item) throws ArtifactFilterException {
    Artifact artifact = item.getArtifact();
    boolean overWrite = (artifact.isSnapshot() && this.overWriteSnapshots) || (!artifact.isSnapshot() && this.overWriteReleases);
    handler.setArtifact(artifact);
    try {
        return overWrite || !handler.isMarkerSet() || (overWriteIfNewer && handler.isMarkerOlder(artifact));
    } catch (MojoExecutionException e) {
        throw new ArtifactFilterException(e.getMessage(), e);
    }
}
Also used : ArtifactFilterException(org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Artifact(org.apache.maven.artifact.Artifact)

Example 3 with ArtifactFilterException

use of org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException in project spring-boot by spring-projects.

the class AbstractDependencyFilterMojo method filterDependencies.

protected Set<Artifact> filterDependencies(Set<Artifact> dependencies, FilterArtifacts filters) throws MojoExecutionException {
    try {
        Set<Artifact> filtered = new LinkedHashSet<>(dependencies);
        filtered.retainAll(filters.filter(dependencies));
        return filtered;
    } catch (ArtifactFilterException ex) {
        throw new MojoExecutionException(ex.getMessage(), ex);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ArtifactFilterException(org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Artifact(org.apache.maven.artifact.Artifact)

Example 4 with ArtifactFilterException

use of org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException in project maven-plugins by apache.

the class ProcessRemoteResourcesMojo method getProjects.

@SuppressWarnings("unchecked")
protected List<MavenProject> getProjects() throws MojoExecutionException {
    List<MavenProject> projects = new ArrayList<MavenProject>();
    // add filters in well known order, least specific to most specific
    FilterArtifacts filter = new FilterArtifacts();
    Set<Artifact> artifacts = resolveProjectArtifacts();
    if (this.excludeTransitive) {
        Set<Artifact> depArtifacts;
        if (runOnlyAtExecutionRoot) {
            depArtifacts = aggregateProjectDependencyArtifacts();
        } else {
            depArtifacts = project.getDependencyArtifacts();
        }
        filter.addFilter(new ProjectTransitivityFilter(depArtifacts, true));
    }
    filter.addFilter(new ScopeFilter(this.includeScope, this.excludeScope));
    filter.addFilter(new GroupIdFilter(this.includeGroupIds, this.excludeGroupIds));
    filter.addFilter(new ArtifactIdFilter(this.includeArtifactIds, this.excludeArtifactIds));
    // perform filtering
    try {
        artifacts = filter.filter(artifacts);
    } catch (ArtifactFilterException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
    for (Artifact artifact : artifacts) {
        try {
            List<ArtifactRepository> remoteRepo = remoteArtifactRepositories;
            if (artifact.isSnapshot()) {
                VersionRange rng = VersionRange.createFromVersion(artifact.getBaseVersion());
                artifact = artifactFactory.createDependencyArtifact(artifact.getGroupId(), artifact.getArtifactId(), rng, artifact.getType(), artifact.getClassifier(), artifact.getScope(), null, artifact.isOptional());
            }
            getLog().debug("Building project for " + artifact);
            MavenProject p;
            try {
                p = mavenProjectBuilder.buildFromRepository(artifact, remoteRepo, localRepository);
            } catch (InvalidProjectModelException e) {
                getLog().warn("Invalid project model for artifact [" + artifact.getArtifactId() + ":" + artifact.getGroupId() + ":" + artifact.getVersion() + "]. " + "It will be ignored by the remote resources Mojo.");
                continue;
            }
            String supplementKey = generateSupplementMapKey(p.getModel().getGroupId(), p.getModel().getArtifactId());
            if (supplementModels.containsKey(supplementKey)) {
                Model mergedModel = mergeModels(p.getModel(), supplementModels.get(supplementKey));
                MavenProject mergedProject = new MavenProject(mergedModel);
                projects.add(mergedProject);
                mergedProject.setArtifact(artifact);
                mergedProject.setVersion(artifact.getVersion());
                getLog().debug("Adding project with groupId [" + mergedProject.getGroupId() + "] (supplemented)");
            } else {
                projects.add(p);
                getLog().debug("Adding project with groupId [" + p.getGroupId() + "]");
            }
        } catch (ProjectBuildingException e) {
            throw new MojoExecutionException(e.getMessage(), e);
        }
    }
    Collections.sort(projects, new ProjectComparator());
    return projects;
}
Also used : InvalidProjectModelException(org.apache.maven.project.InvalidProjectModelException) ArtifactIdFilter(org.apache.maven.shared.artifact.filter.collection.ArtifactIdFilter) ProjectBuildingException(org.apache.maven.project.ProjectBuildingException) ProjectTransitivityFilter(org.apache.maven.shared.artifact.filter.collection.ProjectTransitivityFilter) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArrayList(java.util.ArrayList) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) VersionRange(org.apache.maven.artifact.versioning.VersionRange) Artifact(org.apache.maven.artifact.Artifact) ArtifactFilterException(org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException) ScopeFilter(org.apache.maven.shared.artifact.filter.collection.ScopeFilter) MavenProject(org.apache.maven.project.MavenProject) FilterArtifacts(org.apache.maven.shared.artifact.filter.collection.FilterArtifacts) Model(org.apache.maven.model.Model) GroupIdFilter(org.apache.maven.shared.artifact.filter.collection.GroupIdFilter)

Example 5 with ArtifactFilterException

use of org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException in project maven-plugins by apache.

the class AbstractFromConfigurationMojo method getProcessedArtifactItems.

/**
     * Preprocesses the list of ArtifactItems. This method defaults the outputDirectory if not set and creates the
     * output Directory if it doesn't exist.
     *
     * @param processArtifactItemsRequest preprocessing instructions
     * @return An ArrayList of preprocessed ArtifactItems
     * @throws MojoExecutionException with a message if an error occurs.
     * @see ArtifactItem
     */
protected List<ArtifactItem> getProcessedArtifactItems(ProcessArtifactItemsRequest processArtifactItemsRequest) throws MojoExecutionException {
    boolean removeVersion = processArtifactItemsRequest.isRemoveVersion(), prependGroupId = processArtifactItemsRequest.isPrependGroupId(), useBaseVersion = processArtifactItemsRequest.isUseBaseVersion();
    boolean removeClassifier = processArtifactItemsRequest.isRemoveClassifier();
    if (artifactItems == null || artifactItems.size() < 1) {
        throw new MojoExecutionException("There are no artifactItems configured.");
    }
    for (ArtifactItem artifactItem : artifactItems) {
        this.getLog().info("Configured Artifact: " + artifactItem.toString());
        if (artifactItem.getOutputDirectory() == null) {
            artifactItem.setOutputDirectory(this.outputDirectory);
        }
        artifactItem.getOutputDirectory().mkdirs();
        // make sure we have a version.
        if (StringUtils.isEmpty(artifactItem.getVersion())) {
            fillMissingArtifactVersion(artifactItem);
        }
        artifactItem.setArtifact(this.getArtifact(artifactItem));
        if (StringUtils.isEmpty(artifactItem.getDestFileName())) {
            artifactItem.setDestFileName(DependencyUtil.getFormattedFileName(artifactItem.getArtifact(), removeVersion, prependGroupId, useBaseVersion, removeClassifier));
        }
        try {
            artifactItem.setNeedsProcessing(checkIfProcessingNeeded(artifactItem));
        } catch (ArtifactFilterException e) {
            throw new MojoExecutionException(e.getMessage(), e);
        }
    }
    return artifactItems;
}
Also used : ArtifactFilterException(org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException)

Aggregations

MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)7 ArtifactFilterException (org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException)7 Artifact (org.apache.maven.artifact.Artifact)6 FilterArtifacts (org.apache.maven.shared.artifact.filter.collection.FilterArtifacts)3 ArrayList (java.util.ArrayList)2 LinkedHashSet (java.util.LinkedHashSet)2 DependencyStatusSets (org.apache.maven.plugins.dependency.utils.DependencyStatusSets)2 ArtifactIdFilter (org.apache.maven.shared.artifact.filter.collection.ArtifactIdFilter)2 GroupIdFilter (org.apache.maven.shared.artifact.filter.collection.GroupIdFilter)2 ProjectTransitivityFilter (org.apache.maven.shared.artifact.filter.collection.ProjectTransitivityFilter)2 ScopeFilter (org.apache.maven.shared.artifact.filter.collection.ScopeFilter)2 IOException (java.io.IOException)1 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)1 VersionRange (org.apache.maven.artifact.versioning.VersionRange)1 Model (org.apache.maven.model.Model)1 InvalidProjectModelException (org.apache.maven.project.InvalidProjectModelException)1 MavenProject (org.apache.maven.project.MavenProject)1 ProjectBuildingException (org.apache.maven.project.ProjectBuildingException)1 ClassifierFilter (org.apache.maven.shared.artifact.filter.collection.ClassifierFilter)1 TypeFilter (org.apache.maven.shared.artifact.filter.collection.TypeFilter)1