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.");
}
}
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);
}
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);
}
}
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());
}
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;
}
Aggregations