Search in sources :

Example 21 with ArtifactHandler

use of org.apache.maven.artifact.handler.ArtifactHandler 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);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArrayList(java.util.ArrayList) Artifact(org.apache.maven.artifact.Artifact) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact) NoSuchCompilerException(org.codehaus.plexus.compiler.manager.NoSuchCompilerException) CompilerException(org.codehaus.plexus.compiler.CompilerException) InclusionScanException(org.codehaus.plexus.compiler.util.scan.InclusionScanException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) CompilerNotImplementedException(org.codehaus.plexus.compiler.CompilerNotImplementedException) ArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) ArtifactResolutionRequest(org.apache.maven.artifact.resolver.ArtifactResolutionRequest) ArtifactResolutionResult(org.apache.maven.artifact.resolver.ArtifactResolutionResult) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact)

Example 22 with ArtifactHandler

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

Example 23 with ArtifactHandler

use of org.apache.maven.artifact.handler.ArtifactHandler 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());
}
Also used : ArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) Random(java.util.Random) DefaultArtifactHandlerStub(org.apache.maven.plugin.testing.stubs.DefaultArtifactHandlerStub) VersionRange(org.apache.maven.artifact.versioning.VersionRange) File(java.io.File) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact)

Example 24 with ArtifactHandler

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

Example 25 with ArtifactHandler

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