use of org.apache.maven.artifact.DefaultArtifact in project maven-plugins by apache.
the class ResourceResolver method createResourceArtifact.
private Artifact createResourceArtifact(final Artifact artifact, final String classifier, final SourceResolverConfig config) {
final DefaultArtifact a = (DefaultArtifact) artifactFactory.createArtifactWithClassifier(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), "jar", classifier);
a.setRepository(artifact.getRepository());
return a;
}
use of org.apache.maven.artifact.DefaultArtifact in project asterixdb by apache.
the class SourcePointerResolver method ensureCDDLSourcesPointer.
private void ensureCDDLSourcesPointer(Collection<Project> projects, ArtifactRepository central, ArtifactResolutionRequest request) throws ProjectBuildingException, IOException {
for (Project p : projects) {
if (p.getSourcePointer() != null) {
continue;
}
mojo.getLog().debug("finding sources for artifact: " + p);
Artifact sourcesArtifact = new DefaultArtifact(p.getGroupId(), p.getArtifactId(), p.getVersion(), Artifact.SCOPE_COMPILE, "jar", "sources", null);
MavenProject mavenProject = mojo.resolveDependency(sourcesArtifact);
sourcesArtifact.setArtifactHandler(mavenProject.getArtifact().getArtifactHandler());
final ArtifactRepository localRepo = mojo.getSession().getLocalRepository();
final File marker = new File(localRepo.getBasedir(), localRepo.pathOf(sourcesArtifact) + ".oncentral");
final File antimarker = new File(localRepo.getBasedir(), localRepo.pathOf(sourcesArtifact) + ".nocentral");
boolean onCentral;
if (marker.exists() || antimarker.exists()) {
onCentral = marker.exists();
} else {
request.setArtifact(sourcesArtifact);
ArtifactResolutionResult result = mojo.getArtifactResolver().resolve(request);
mojo.getLog().debug("result: " + result);
onCentral = result.isSuccess();
if (onCentral) {
FileUtils.touch(marker);
} else {
FileUtils.touch(antimarker);
}
}
StringBuilder noticeBuilder = new StringBuilder("You may obtain ");
noticeBuilder.append(p.getName()).append(" in Source Code form code here:\n");
if (onCentral) {
noticeBuilder.append(central.getUrl()).append("/").append(central.pathOf(sourcesArtifact));
} else {
mojo.getLog().warn("Unable to find sources in 'central' for " + p + ", falling back to project url: " + p.getUrl());
noticeBuilder.append(p.getUrl() != null ? p.getUrl() : "MISSING SOURCE POINTER");
}
p.setSourcePointer(noticeBuilder.toString());
}
}
use of org.apache.maven.artifact.DefaultArtifact in project sling by apache.
the class ModelUtils method getArtifact.
/**
* Get a resolved Artifact from the coordinates provided
*
* @return the artifact, which has been resolved.
* @throws MojoExecutionException
*/
public static Artifact getArtifact(final MavenProject project, final MavenSession session, final ArtifactHandlerManager artifactHandlerManager, final ArtifactResolver resolver, final String groupId, final String artifactId, final String version, final String type, final String classifier) throws MojoExecutionException {
final Set<Artifact> artifacts = project.getDependencyArtifacts();
for (final Artifact artifact : artifacts) {
if (artifact.getGroupId().equals(groupId) && artifact.getArtifactId().equals(artifactId) && artifact.getVersion().equals(version) && artifact.getType().equals(type) && ((classifier == null && artifact.getClassifier() == null) || (classifier != null && classifier.equals(artifact.getClassifier())))) {
return artifact;
}
}
final Artifact prjArtifact = new DefaultArtifact(groupId, artifactId, VersionRange.createFromVersion(version), Artifact.SCOPE_PROVIDED, type, classifier, artifactHandlerManager.getArtifactHandler(type));
try {
resolver.resolve(prjArtifact, project.getRemoteArtifactRepositories(), session.getLocalRepository());
} catch (final ArtifactResolutionException e) {
throw new MojoExecutionException("Unable to get artifact for " + groupId + ":" + artifactId + ":" + version, e);
} catch (final ArtifactNotFoundException e) {
throw new MojoExecutionException("Unable to get artifact for " + groupId + ":" + artifactId + ":" + version, e);
}
return prjArtifact;
}
use of org.apache.maven.artifact.DefaultArtifact in project bnd by bndtools.
the class IndexerMojo method attach.
private void attach(File file, String type, String extension) {
DefaultArtifactHandler handler = new DefaultArtifactHandler(type);
handler.setExtension(extension);
DefaultArtifact artifact = new DefaultArtifact(project.getGroupId(), project.getArtifactId(), project.getVersion(), null, type, null, handler);
artifact.setFile(file);
project.addAttachedArtifact(artifact);
}
use of org.apache.maven.artifact.DefaultArtifact in project sling by apache.
the class PreparePackageMojoTest method getMavenArtifact.
private org.apache.maven.artifact.Artifact getMavenArtifact(File repoRoot, ArtifactHandler ah, String gid, String aid, String ver, String classifier) {
DefaultArtifact art = new DefaultArtifact(gid, aid, ver, "compile", "jar", classifier, ah);
art.setFile(getMavenArtifactFile(repoRoot, gid, aid, ver));
return art;
}
Aggregations