Search in sources :

Example 1 with DependencyStatusSets

use of org.apache.maven.plugins.dependency.utils.DependencyStatusSets in project maven-plugins by apache.

the class UnpackDependenciesMojo method doExecute.

/**
     * Main entry into mojo. This method gets the dependencies and iterates
     * through each one passing it to DependencyUtil.unpackFile().
     *
     * @throws MojoExecutionException with a message if an error occurs.
     * @see #getDependencySets(boolean)
     * @see #unpack(Artifact, File, String)
     */
@Override
protected void doExecute() throws MojoExecutionException {
    DependencyStatusSets dss = getDependencySets(this.failOnMissingClassifierArtifact);
    for (Artifact artifact : dss.getResolvedDependencies()) {
        File destDir;
        destDir = DependencyUtil.getFormattedOutputDirectory(useSubDirectoryPerScope, useSubDirectoryPerType, useSubDirectoryPerArtifact, useRepositoryLayout, stripVersion, outputDirectory, artifact);
        unpack(artifact, destDir, getIncludes(), getExcludes(), getEncoding());
        DefaultFileMarkerHandler handler = new DefaultFileMarkerHandler(artifact, this.markersDirectory);
        handler.setMarker();
    }
    for (Artifact artifact : dss.getSkippedDependencies()) {
        getLog().info(artifact.getId() + " already exists in destination.");
    }
}
Also used : DependencyStatusSets(org.apache.maven.plugins.dependency.utils.DependencyStatusSets) DefaultFileMarkerHandler(org.apache.maven.plugins.dependency.utils.markers.DefaultFileMarkerHandler) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Example 2 with DependencyStatusSets

use of org.apache.maven.plugins.dependency.utils.DependencyStatusSets 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 3 with DependencyStatusSets

use of org.apache.maven.plugins.dependency.utils.DependencyStatusSets in project maven-plugins by apache.

the class CopyDependenciesMojo method doExecute.

/**
     * Main entry into mojo. Gets the list of dependencies and iterates through
     * calling copyArtifact.
     *
     * @throws MojoExecutionException with a message if an error occurs.
     * @see #getDependencySets(boolean, boolean)
     * @see #copyArtifact(Artifact, boolean, boolean, boolean, boolean)
     */
@Override
protected void doExecute() throws MojoExecutionException {
    DependencyStatusSets dss = getDependencySets(this.failOnMissingClassifierArtifact, addParentPoms);
    Set<Artifact> artifacts = dss.getResolvedDependencies();
    if (!useRepositoryLayout) {
        for (Artifact artifact : artifacts) {
            copyArtifact(artifact, isStripVersion(), this.prependGroupId, this.useBaseVersion, this.stripClassifier);
        }
    } else {
        ProjectBuildingRequest buildingRequest = getRepositoryManager().setLocalRepositoryBasedir(session.getProjectBuildingRequest(), outputDirectory);
        for (Artifact artifact : artifacts) {
            installArtifact(artifact, buildingRequest);
        }
    }
    Set<Artifact> skippedArtifacts = dss.getSkippedDependencies();
    for (Artifact artifact : skippedArtifacts) {
        getLog().info(artifact.getId() + " already exists in destination.");
    }
    if (isCopyPom() && !useRepositoryLayout) {
        copyPoms(getOutputDirectory(), artifacts, this.stripVersion);
        copyPoms(getOutputDirectory(), skippedArtifacts, this.stripVersion, // Artifacts that already exist may not yet have poms
        this.stripClassifier);
    }
}
Also used : ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) DependencyStatusSets(org.apache.maven.plugins.dependency.utils.DependencyStatusSets) Artifact(org.apache.maven.artifact.Artifact)

Example 4 with DependencyStatusSets

use of org.apache.maven.plugins.dependency.utils.DependencyStatusSets in project maven-plugins by apache.

the class TestCollectMojo method testCollectTestEnvironment.

/**
     * tests the proper discovery and configuration of the mojo
     * 
     * @throws Exception if a problem occurs
     */
public void testCollectTestEnvironment() throws Exception {
    File testPom = new File(getBasedir(), "target/test-classes/unit/collect-test/plugin-config.xml");
    CollectDependenciesMojo mojo = (CollectDependenciesMojo) lookupMojo("collect", testPom);
    assertNotNull(mojo);
    assertNotNull(mojo.getProject());
    MavenProject project = mojo.getProject();
    mojo.setSilent(true);
    Set<Artifact> artifacts = this.stubFactory.getScopedArtifacts();
    Set<Artifact> directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts();
    artifacts.addAll(directArtifacts);
    project.setArtifacts(artifacts);
    project.setDependencyArtifacts(directArtifacts);
    mojo.execute();
    DependencyStatusSets results = mojo.getResults();
    assertNotNull(results);
    assertEquals(artifacts.size(), results.getResolvedDependencies().size());
}
Also used : CollectDependenciesMojo(org.apache.maven.plugins.dependency.resolvers.CollectDependenciesMojo) MavenProject(org.apache.maven.project.MavenProject) DependencyStatusSets(org.apache.maven.plugins.dependency.utils.DependencyStatusSets) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Example 5 with DependencyStatusSets

use of org.apache.maven.plugins.dependency.utils.DependencyStatusSets in project maven-plugins by apache.

the class AbstractDependencyFilterMojo method getClassifierTranslatedDependencies.

/**
     * Transform artifacts
     *
     * @param artifacts
     * @param stopOnFailure
     * @return DependencyStatusSets - Bean of TreeSets that contains information
     *         on the projects dependencies
     * @throws MojoExecutionException
     */
protected DependencyStatusSets getClassifierTranslatedDependencies(Set<Artifact> artifacts, boolean stopOnFailure) throws MojoExecutionException {
    Set<Artifact> unResolvedArtifacts = new LinkedHashSet<Artifact>();
    Set<Artifact> resolvedArtifacts = artifacts;
    DependencyStatusSets status = new DependencyStatusSets();
    // if this did something, we need to resolve the new artifacts
    if (StringUtils.isNotEmpty(classifier)) {
        ArtifactTranslator translator = new ClassifierTypeTranslator(artifactHandlerManager, this.classifier, this.type);
        Collection<ArtifactCoordinate> coordinates = translator.translate(artifacts, getLog());
        status = filterMarkedDependencies(artifacts);
        // the unskipped artifacts are in the resolved set.
        artifacts = status.getResolvedDependencies();
        // resolve the rest of the artifacts
        resolvedArtifacts = resolve(new LinkedHashSet<ArtifactCoordinate>(coordinates), stopOnFailure);
        // calculate the artifacts not resolved.
        unResolvedArtifacts.addAll(artifacts);
        unResolvedArtifacts.removeAll(resolvedArtifacts);
    }
    // return a bean of all 3 sets.
    status.setResolvedDependencies(resolvedArtifacts);
    status.setUnResolvedDependencies(unResolvedArtifacts);
    return status;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ArtifactTranslator(org.apache.maven.plugins.dependency.utils.translators.ArtifactTranslator) ArtifactCoordinate(org.apache.maven.shared.artifact.ArtifactCoordinate) ClassifierTypeTranslator(org.apache.maven.plugins.dependency.utils.translators.ClassifierTypeTranslator) DependencyStatusSets(org.apache.maven.plugins.dependency.utils.DependencyStatusSets) Artifact(org.apache.maven.artifact.Artifact)

Aggregations

Artifact (org.apache.maven.artifact.Artifact)8 DependencyStatusSets (org.apache.maven.plugins.dependency.utils.DependencyStatusSets)8 File (java.io.File)4 MavenProject (org.apache.maven.project.MavenProject)3 LinkedHashSet (java.util.LinkedHashSet)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 CollectDependenciesMojo (org.apache.maven.plugins.dependency.resolvers.CollectDependenciesMojo)2 ArtifactFilterException (org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException)2 FilterArtifacts (org.apache.maven.shared.artifact.filter.collection.FilterArtifacts)2 ArrayList (java.util.ArrayList)1 ResolveDependenciesMojo (org.apache.maven.plugins.dependency.resolvers.ResolveDependenciesMojo)1 DefaultFileMarkerHandler (org.apache.maven.plugins.dependency.utils.markers.DefaultFileMarkerHandler)1 ArtifactTranslator (org.apache.maven.plugins.dependency.utils.translators.ArtifactTranslator)1 ClassifierTypeTranslator (org.apache.maven.plugins.dependency.utils.translators.ClassifierTypeTranslator)1 ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)1 ArtifactCoordinate (org.apache.maven.shared.artifact.ArtifactCoordinate)1 ArtifactIdFilter (org.apache.maven.shared.artifact.filter.collection.ArtifactIdFilter)1 ClassifierFilter (org.apache.maven.shared.artifact.filter.collection.ClassifierFilter)1 GroupIdFilter (org.apache.maven.shared.artifact.filter.collection.GroupIdFilter)1 ProjectTransitivityFilter (org.apache.maven.shared.artifact.filter.collection.ProjectTransitivityFilter)1