use of org.apache.maven.shared.artifact.ArtifactCoordinate in project maven-plugins by apache.
the class TestClassifierTypeTranslator method doTestNullEmptyClassifier.
public void doTestNullEmptyClassifier(String classifier) {
String type = "zip";
ArtifactTranslator at = new ClassifierTypeTranslator(artifactHandlerManager, classifier, type);
Set<ArtifactCoordinate> results = at.translate(artifacts, log);
for (Artifact artifact : artifacts) {
Iterator<ArtifactCoordinate> resultIter = results.iterator();
boolean found = false;
while (resultIter.hasNext()) {
ArtifactCoordinate translatedArtifact = resultIter.next();
if (artifact.getArtifactId().equals(translatedArtifact.getArtifactId()) && artifact.getGroupId().equals(translatedArtifact.getGroupId())) /*&& artifact.getScope().equals(translatedArtifact.getScope())*/
{
// classifier is null, should be the same as the artifact
assertEquals(artifact.getClassifier(), translatedArtifact.getClassifier());
assertEquals(type, translatedArtifact.getExtension());
found = true;
break;
}
}
assertTrue(found);
}
}
use of org.apache.maven.shared.artifact.ArtifactCoordinate in project maven-plugins by apache.
the class AbstractHelpMojo method getMavenProject.
/**
* Retrieves the Maven Project associated with the given artifact String, in the form of
* <code>groupId:artifactId[:version]</code>. This resolves the POM artifact at those coordinates and then builds
* the Maven project from it.
*
* @param artifactString Coordinates of the Maven project to get.
* @return New Maven project.
* @throws MojoExecutionException If there was an error while getting the Maven project.
*/
protected MavenProject getMavenProject(String artifactString) throws MojoExecutionException {
ArtifactCoordinate coordinate = getArtifactCoordinate(artifactString, "pom");
try {
ProjectBuildingRequest pbr = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
pbr.setRemoteRepositories(remoteRepositories);
pbr.setProject(null);
pbr.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
pbr.setResolveDependencies(true);
Artifact artifact = artifactResolver.resolveArtifact(pbr, coordinate).getArtifact();
return projectBuilder.build(artifact.getFile(), pbr).getProject();
} catch (Exception e) {
throw new MojoExecutionException("Unable to get the POM for the artifact '" + artifactString + "'. Verify the artifact parameter.", e);
}
}
use of org.apache.maven.shared.artifact.ArtifactCoordinate 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;
}
use of org.apache.maven.shared.artifact.ArtifactCoordinate in project maven-plugins by apache.
the class ClassifierTypeTranslator method translate.
/*
* (non-Javadoc)
*
* @see org.apache.mojo.dependency.utils.translators.ArtifactTranslator#translate(java.util.Set,
* org.apache.maven.plugin.logging.Log)
*/
@Override
public Set<ArtifactCoordinate> translate(Set<Artifact> artifacts, Log log) {
Set<ArtifactCoordinate> results;
log.debug("Translating Artifacts using Classifier: " + this.classifier + " and Type: " + this.type);
results = new LinkedHashSet<ArtifactCoordinate>();
for (Artifact artifact : artifacts) {
// this translator must pass both type and classifier here so we
// will use the
// base artifact value if null comes in
final String useType;
if (StringUtils.isNotEmpty(this.type)) {
useType = this.type;
} else {
useType = artifact.getType();
}
ArtifactHandler artifactHandler = artifactHandlerManager.getArtifactHandler(useType);
final String extension;
if (artifactHandler != null) {
extension = artifactHandler.getExtension();
} else {
extension = this.type;
}
String useClassifier;
if (StringUtils.isNotEmpty(this.classifier)) {
useClassifier = this.classifier;
} else {
useClassifier = artifact.getClassifier();
}
DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate();
coordinate.setGroupId(artifact.getGroupId());
coordinate.setArtifactId(artifact.getArtifactId());
coordinate.setVersion(artifact.getVersion());
coordinate.setClassifier(useClassifier);
coordinate.setExtension(extension);
// // Create a new artifact
// Artifact newArtifact = factory.createArtifactWithClassifier( artifact.getGroupId(), artifact
// .getArtifactId(), artifact.getVersion(), useType, useClassifier );
//
// // note the new artifacts will always have the scope set to null. We
// // should
// // reset it here so that it will pass other filters if needed
// newArtifact.setScope( artifact.getScope() );
//
// if ( Artifact.SCOPE_SYSTEM.equals( newArtifact.getScope() ) )
// {
// File baseDir = repositoryManager.getLocalRepositoryBasedir( buildingRequest );
// String path = repositoryManager.getPathForLocalArtifact( buildingRequest, newArtifact );
// newArtifact.setFile( new File( baseDir, path ) );
// }
results.add(coordinate);
}
return results;
}
use of org.apache.maven.shared.artifact.ArtifactCoordinate in project maven-plugins by apache.
the class TestClassifierTypeTranslator method doTestNullEmptyType.
public void doTestNullEmptyType(String type) {
String classifier = "jdk5";
ArtifactTranslator at = new ClassifierTypeTranslator(artifactHandlerManager, classifier, type);
Set<ArtifactCoordinate> results = at.translate(artifacts, log);
for (Artifact artifact : artifacts) {
Iterator<ArtifactCoordinate> resultIter = results.iterator();
boolean found = false;
while (!found && resultIter.hasNext()) {
ArtifactCoordinate translatedArtifact = resultIter.next();
if (artifact.getArtifactId() == translatedArtifact.getArtifactId() && artifact.getGroupId() == translatedArtifact.getGroupId()) /*&& artifact.getScope() == translatedArtifact.getScope()*/
{
// classifier is null, should be the same as the artifact
assertEquals(classifier, translatedArtifact.getClassifier());
assertEquals(artifact.getType(), translatedArtifact.getExtension());
found = true;
break;
}
}
assertTrue(found);
}
}
Aggregations