Search in sources :

Example 6 with ArtifactHandler

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;
}
Also used : ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) ArtifactResolverException(org.apache.maven.shared.artifact.resolve.ArtifactResolverException) ArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DefaultArtifactCoordinate(org.apache.maven.shared.artifact.DefaultArtifactCoordinate) Artifact(org.apache.maven.artifact.Artifact)

Example 7 with ArtifactHandler

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;
}
Also used : ArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) DefaultArtifactCoordinate(org.apache.maven.shared.artifact.DefaultArtifactCoordinate)

Example 8 with ArtifactHandler

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;
}
Also used : DebugEnabledLog(org.apache.maven.plugin.compiler.stubs.DebugEnabledLog) ArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) MavenProject(org.apache.maven.project.MavenProject) ArrayList(java.util.ArrayList) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Example 9 with ArtifactHandler

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));
}
Also used : ArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) Artifact(org.apache.maven.artifact.Artifact) Test(org.junit.Test)

Example 10 with ArtifactHandler

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;
}
Also used : ArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) DefaultArtifactHandlerStub(org.apache.maven.plugin.testing.stubs.DefaultArtifactHandlerStub) VersionRange(org.apache.maven.artifact.versioning.VersionRange) Artifact(org.apache.maven.artifact.Artifact) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact)

Aggregations

ArtifactHandler (org.apache.maven.artifact.handler.ArtifactHandler)35 File (java.io.File)17 Artifact (org.apache.maven.artifact.Artifact)14 DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)12 JarArtifactStub (org.apache.maven.plugins.war.stub.JarArtifactStub)10 ArtifactStub (org.apache.maven.plugin.testing.stubs.ArtifactStub)9 VersionRange (org.apache.maven.artifact.versioning.VersionRange)7 MavenProjectArtifactsStub (org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub)6 DefaultArtifactHandlerStub (org.apache.maven.plugin.testing.stubs.DefaultArtifactHandlerStub)5 AarArtifactStub (org.apache.maven.plugins.war.stub.AarArtifactStub)5 EJBArtifactStub (org.apache.maven.plugins.war.stub.EJBArtifactStub)5 EJBClientArtifactStub (org.apache.maven.plugins.war.stub.EJBClientArtifactStub)5 IncludeExcludeWarArtifactStub (org.apache.maven.plugins.war.stub.IncludeExcludeWarArtifactStub)5 MarArtifactStub (org.apache.maven.plugins.war.stub.MarArtifactStub)5 PARArtifactStub (org.apache.maven.plugins.war.stub.PARArtifactStub)5 TLDArtifactStub (org.apache.maven.plugins.war.stub.TLDArtifactStub)5 WarArtifactStub (org.apache.maven.plugins.war.stub.WarArtifactStub)5 XarArtifactStub (org.apache.maven.plugins.war.stub.XarArtifactStub)5 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)4 MavenProject (org.apache.maven.project.MavenProject)4