use of org.apache.maven.artifact.DefaultArtifact in project maven-plugins by apache.
the class AbstractCompilerMojo method resolveProcessorPathEntries.
private List<String> resolveProcessorPathEntries() throws MojoExecutionException {
if (annotationProcessorPaths == null || annotationProcessorPaths.isEmpty()) {
return null;
}
try {
Set<Artifact> requiredArtifacts = new LinkedHashSet<Artifact>();
for (DependencyCoordinate coord : annotationProcessorPaths) {
ArtifactHandler handler = artifactHandlerManager.getArtifactHandler(coord.getType());
Artifact artifact = new DefaultArtifact(coord.getGroupId(), coord.getArtifactId(), VersionRange.createFromVersionSpec(coord.getVersion()), Artifact.SCOPE_RUNTIME, coord.getType(), coord.getClassifier(), handler, false);
requiredArtifacts.add(artifact);
}
ArtifactResolutionRequest request = new ArtifactResolutionRequest().setArtifact(requiredArtifacts.iterator().next()).setResolveRoot(true).setResolveTransitively(true).setArtifactDependencies(requiredArtifacts).setLocalRepository(session.getLocalRepository()).setRemoteRepositories(project.getRemoteArtifactRepositories());
ArtifactResolutionResult resolutionResult = repositorySystem.resolve(request);
resolutionErrorHandler.throwErrors(request, resolutionResult);
List<String> elements = new ArrayList<String>(resolutionResult.getArtifacts().size());
for (Object resolved : resolutionResult.getArtifacts()) {
elements.add(((Artifact) resolved).getFile().getAbsolutePath());
}
return elements;
} catch (Exception e) {
throw new MojoExecutionException("Resolution of annotationProcessorPath dependencies failed: " + e.getLocalizedMessage(), e);
}
}
use of org.apache.maven.artifact.DefaultArtifact in project maven-plugins by apache.
the class TestSourcesMarkerFileHandler method setUp.
protected void setUp() throws Exception {
super.setUp();
ArtifactHandler ah = new DefaultArtifactHandler();
VersionRange vr = VersionRange.createFromVersion("1.1");
Artifact artifact = new DefaultArtifact("test", "1", vr, Artifact.SCOPE_COMPILE, "jar", "", ah, false);
artifacts.add(artifact);
artifact = new DefaultArtifact("test", "2", vr, Artifact.SCOPE_PROVIDED, "war", "", ah, false);
artifacts.add(artifact);
artifact = new DefaultArtifact("test", "3", vr, Artifact.SCOPE_TEST, "sources", "", ah, false);
artifacts.add(artifact);
artifact = new DefaultArtifact("test", "4", vr, Artifact.SCOPE_RUNTIME, "zip", "", ah, false);
artifacts.add(artifact);
// pick random output location
Random a = new Random();
outputFolder = new File("target/markers" + a.nextLong() + "/");
outputFolder.delete();
assertFalse(outputFolder.exists());
}
use of org.apache.maven.artifact.DefaultArtifact in project maven-plugins by apache.
the class TestDependencyUtil method testFileNameClassifierWithFile.
public void testFileNameClassifierWithFile() throws MojoExecutionException {
// specifically testing the default operation that getFormattedFileName
// returns
// the actual name of the file if available unless remove version is
// set.
ArtifactHandler ah = new DefaultArtifactHandlerStub("war", "sources");
VersionRange vr = VersionRange.createFromVersion("1.1-SNAPSHOT");
Artifact artifact = new DefaultArtifact("test", "two", vr, Artifact.SCOPE_PROVIDED, "war", "sources", ah, false);
File file = new File("/target", "test-file-name.jar");
artifact.setFile(file);
String name = DependencyUtil.getFormattedFileName(artifact, false);
String expectedResult = "two-1.1-SNAPSHOT-sources.war";
assertEquals(expectedResult, name);
name = DependencyUtil.getFormattedFileName(artifact, false, false, false, true);
expectedResult = "two-1.1-SNAPSHOT.war";
assertEquals(expectedResult, name);
name = DependencyUtil.getFormattedFileName(artifact, true);
expectedResult = "two-sources.war";
assertEquals(expectedResult, name);
artifact = new DefaultArtifact("test", "two", vr, Artifact.SCOPE_PROVIDED, "war", "", ah, false);
name = DependencyUtil.getFormattedFileName(artifact, true);
expectedResult = "two.war";
assertEquals(expectedResult, name);
// test that we pickup the correct extension in the file name if set.
ah = new DefaultArtifactHandlerStub("jar", null);
artifact = new DefaultArtifact("test", "two", vr, Artifact.SCOPE_PROVIDED, "war", "", ah, false);
name = DependencyUtil.getFormattedFileName(artifact, true);
expectedResult = "two.jar";
assertEquals(expectedResult, name);
}
use of org.apache.maven.artifact.DefaultArtifact in project maven-plugins by apache.
the class TestDependencyUtil method setUp.
protected void setUp() throws Exception {
super.setUp();
ArtifactHandler ah = new DefaultArtifactHandlerStub("jar", null);
VersionRange vr = VersionRange.createFromVersion("1.1");
release = new DefaultArtifact("test", "one", vr, Artifact.SCOPE_COMPILE, "jar", "sources", ah, false);
artifacts.add(release);
ah = new DefaultArtifactHandlerStub("war", null);
vr = VersionRange.createFromVersion("1.1-SNAPSHOT");
snap = new DefaultArtifact("test", "two", vr, Artifact.SCOPE_PROVIDED, "war", null, ah, false);
artifacts.add(snap);
ah = new DefaultArtifactHandlerStub("war", null);
vr = VersionRange.createFromVersion("1.1-SNAPSHOT");
snapResolvedVersion = new DefaultArtifact("test", "three", vr, Artifact.SCOPE_PROVIDED, "war", null, ah, false);
snapResolvedVersion.setResolvedVersion("1.1-20121003.035531-117");
artifacts.add(snapResolvedVersion);
ah = new DefaultArtifactHandlerStub("war", null);
vr = VersionRange.createFromVersion("1.1-SNAPSHOT");
sources = new DefaultArtifact("test", "two", vr, Artifact.SCOPE_PROVIDED, "sources", "sources", ah, false);
// pick random output location
Random a = new Random();
outputFolder = new File("target/copy" + a.nextLong() + "/");
outputFolder.delete();
assertFalse(outputFolder.exists());
}
use of org.apache.maven.artifact.DefaultArtifact in project maven-plugins by apache.
the class TestDependencyUtil method testTestJar.
public void testTestJar() {
ArtifactHandler ah = new DefaultArtifactHandlerStub("test-jar", null);
VersionRange vr = VersionRange.createFromVersion("1.1-SNAPSHOT");
Artifact artifact = new DefaultArtifact("test", "two", vr, Artifact.SCOPE_PROVIDED, "test-jar", null, ah, false);
String name = DependencyUtil.getFormattedFileName(artifact, false);
String expectedResult = "two-1.1-SNAPSHOT.jar";
assertEquals(expectedResult, name);
}
Aggregations