use of org.apache.maven.artifact.handler.ArtifactHandler in project maven-plugins by apache.
the class AbstractFromConfigurationMojo method getArtifact.
/**
* Resolves the Artifact from the remote repository if necessary. If no version is specified, it will be retrieved
* from the dependency list or from the DependencyManagement section of the pom.
*
* @param artifactItem containing information about artifact from plugin configuration.
* @return Artifact object representing the specified file.
* @throws MojoExecutionException with a message if the version can't be found in DependencyManagement.
*/
protected Artifact getArtifact(ArtifactItem artifactItem) throws MojoExecutionException {
Artifact artifact;
try {
// mdep-50 - rolledback for now because it's breaking some functionality.
/*
* List listeners = new ArrayList(); Set theSet = new HashSet(); theSet.add( artifact );
* ArtifactResolutionResult artifactResolutionResult = artifactCollector.collect( theSet, project
* .getArtifact(), managedVersions, this.local, project.getRemoteArtifactRepositories(),
* artifactMetadataSource, null, listeners ); Iterator iter =
* artifactResolutionResult.getArtifactResolutionNodes().iterator(); while ( iter.hasNext() ) {
* ResolutionNode node = (ResolutionNode) iter.next(); artifact = node.getArtifact(); }
*/
ProjectBuildingRequest buildingRequest = newResolveArtifactProjectBuildingRequest();
if (localRepositoryDirectory != null) {
buildingRequest = repositoryManager.setLocalRepositoryBasedir(buildingRequest, localRepositoryDirectory);
}
// Map dependency to artifact coordinate
DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate();
coordinate.setGroupId(artifactItem.getGroupId());
coordinate.setArtifactId(artifactItem.getArtifactId());
coordinate.setVersion(artifactItem.getVersion());
coordinate.setClassifier(artifactItem.getClassifier());
final String extension;
ArtifactHandler artifactHandler = artifactHandlerManager.getArtifactHandler(artifactItem.getType());
if (artifactHandler != null) {
extension = artifactHandler.getExtension();
} else {
extension = artifactItem.getType();
}
coordinate.setExtension(extension);
artifact = artifactResolver.resolveArtifact(buildingRequest, coordinate).getArtifact();
} catch (ArtifactResolverException e) {
throw new MojoExecutionException("Unable to find/resolve artifact.", e);
}
return artifact;
}
use of org.apache.maven.artifact.handler.ArtifactHandler in project maven-plugins by apache.
the class GetMojo method toArtifactCoordinate.
private ArtifactCoordinate toArtifactCoordinate(DependableCoordinate dependableCoordinate) {
ArtifactHandler artifactHandler = artifactHandlerManager.getArtifactHandler(dependableCoordinate.getType());
DefaultArtifactCoordinate artifactCoordinate = new DefaultArtifactCoordinate();
artifactCoordinate.setGroupId(dependableCoordinate.getGroupId());
artifactCoordinate.setArtifactId(dependableCoordinate.getArtifactId());
artifactCoordinate.setVersion(dependableCoordinate.getVersion());
artifactCoordinate.setClassifier(dependableCoordinate.getClassifier());
artifactCoordinate.setExtension(artifactHandler.getExtension());
return artifactCoordinate;
}
use of org.apache.maven.artifact.handler.ArtifactHandler in project maven-plugins by apache.
the class CompilerMojoTestCase method getTestCompilerMojo.
private TestCompilerMojo getTestCompilerMojo(CompilerMojo compilerMojo, String pomXml) throws Exception {
File testPom = new File(getBasedir(), pomXml);
TestCompilerMojo mojo = (TestCompilerMojo) lookupMojo("testCompile", testPom);
setVariableValueToObject(mojo, "log", new DebugEnabledLog());
File buildDir = (File) getVariableValueFromObject(compilerMojo, "buildDirectory");
File testClassesDir = new File(buildDir, "test-classes");
setVariableValueToObject(mojo, "outputDirectory", testClassesDir);
List<String> testClasspathList = new ArrayList<String>();
Artifact junitArtifact = mock(Artifact.class);
ArtifactHandler handler = mock(ArtifactHandler.class);
when(handler.isAddedToClasspath()).thenReturn(true);
when(junitArtifact.getArtifactHandler()).thenReturn(handler);
File artifactFile;
String localRepository = System.getProperty("localRepository");
if (localRepository != null) {
artifactFile = new File(localRepository, "junit/junit/3.8.1/junit-3.8.1.jar");
} else {
// for IDE
String junitURI = org.junit.Test.class.getResource("Test.class").toURI().toString();
junitURI = junitURI.substring("jar:".length(), junitURI.indexOf('!'));
artifactFile = new File(URI.create(junitURI));
}
when(junitArtifact.getFile()).thenReturn(artifactFile);
testClasspathList.add(artifactFile.getAbsolutePath());
testClasspathList.add(compilerMojo.getOutputDirectory().getPath());
String testSourceRoot = testPom.getParent() + "/src/test/java";
setVariableValueToObject(mojo, "compileSourceRoots", Collections.singletonList(testSourceRoot));
MavenProject project = getMockMavenProject();
project.setArtifacts(Collections.singleton(junitArtifact));
project.getBuild().setOutputDirectory(new File(buildDir, "classes").getAbsolutePath());
setVariableValueToObject(mojo, "project", project);
setVariableValueToObject(mojo, "compilePath", Collections.EMPTY_LIST);
setVariableValueToObject(mojo, "testPath", testClasspathList);
setVariableValueToObject(mojo, "session", getMockMavenSession());
setVariableValueToObject(mojo, "mojoExecution", getMockMojoExecution());
setVariableValueToObject(mojo, "source", source);
setVariableValueToObject(mojo, "target", target);
return mojo;
}
use of org.apache.maven.artifact.handler.ArtifactHandler in project maven-plugins by apache.
the class TestAbstractFileNameMapping method test.
@Test
public void test() {
ArtifactHandler handler = mock(ArtifactHandler.class);
when(handler.getExtension()).thenReturn("jar");
Artifact artifact = mock(Artifact.class);
when(artifact.getArtifactHandler()).thenReturn(handler);
when(artifact.getArtifactId()).thenReturn("mear149");
when(artifact.getVersion()).thenReturn("1.0-SNAPSHOT");
when(artifact.getBaseVersion()).thenReturn("1.0-20130423.042904");
// default behavior: use -SNAPSHOT
assertEquals("mear149-1.0-SNAPSHOT.jar", abstractFileNameMapping.generateFileName(artifact, true));
abstractFileNameMapping.setUseBaseVersion(true);
assertEquals("mear149-1.0-20130423.042904.jar", abstractFileNameMapping.generateFileName(artifact, true));
abstractFileNameMapping.setUseBaseVersion(false);
assertEquals("mear149-1.0-SNAPSHOT.jar", abstractFileNameMapping.generateFileName(artifact, true));
}
use of org.apache.maven.artifact.handler.ArtifactHandler in project maven-plugins by apache.
the class DependencyProjectStub method getArtifact.
public Artifact getArtifact() {
if (artifact == null) {
ArtifactHandler ah = new DefaultArtifactHandlerStub("jar", null);
VersionRange vr = VersionRange.createFromVersion("1.0");
Artifact art = new DefaultArtifact("group", "artifact", vr, Artifact.SCOPE_COMPILE, "jar", null, ah, false);
setArtifact(art);
}
return artifact;
}
Aggregations