Search in sources :

Example 6 with DefaultArtifactCoordinate

use of org.apache.maven.shared.artifact.DefaultArtifactCoordinate in project maven-plugins by apache.

the class AbstractJavadocMojo method createAndResolveArtifact.

/**
     * creates an {@link Artifact} representing the configured {@link JavadocPathArtifact} and resolves it.
     *
     * @param javadocArtifact the {@link JavadocPathArtifact} to resolve
     * @return a resolved {@link Artifact}
     * @throws ArtifactResolverException
     */
private Artifact createAndResolveArtifact(JavadocPathArtifact javadocArtifact) throws ArtifactResolverException {
    DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate();
    coordinate.setGroupId(javadocArtifact.getGroupId());
    coordinate.setArtifactId(javadocArtifact.getArtifactId());
    coordinate.setVersion(javadocArtifact.getVersion());
    return artifactResolver.resolveArtifact(session.getProjectBuildingRequest(), coordinate).getArtifact();
}
Also used : DefaultArtifactCoordinate(org.apache.maven.shared.artifact.DefaultArtifactCoordinate)

Example 7 with DefaultArtifactCoordinate

use of org.apache.maven.shared.artifact.DefaultArtifactCoordinate in project maven-plugins by apache.

the class CopyDependenciesMojo method getResolvedPomArtifact.

protected Artifact getResolvedPomArtifact(Artifact artifact) {
    DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate();
    coordinate.setGroupId(artifact.getGroupId());
    coordinate.setArtifactId(artifact.getArtifactId());
    coordinate.setVersion(artifact.getVersion());
    coordinate.setExtension("pom");
    Artifact pomArtifact = null;
    // Resolve the pom artifact using repos
    try {
        ProjectBuildingRequest buildingRequest = newResolveArtifactProjectBuildingRequest();
        pomArtifact = getArtifactResolver().resolveArtifact(buildingRequest, coordinate).getArtifact();
    } catch (ArtifactResolverException e) {
        getLog().info(e.getMessage());
    }
    return pomArtifact;
}
Also used : ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) ArtifactResolverException(org.apache.maven.shared.artifact.resolve.ArtifactResolverException) DefaultArtifactCoordinate(org.apache.maven.shared.artifact.DefaultArtifactCoordinate) Artifact(org.apache.maven.artifact.Artifact)

Example 8 with DefaultArtifactCoordinate

use of org.apache.maven.shared.artifact.DefaultArtifactCoordinate 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 9 with DefaultArtifactCoordinate

use of org.apache.maven.shared.artifact.DefaultArtifactCoordinate in project maven-plugins by apache.

the class DeployFileMojo method getLocalRepoFile.

/**
     * Gets the path of the artifact constructed from the supplied groupId, artifactId, version, classifier and
     * packaging within the local repository. Note that the returned path need not exist (yet).
     * 
     * @return The absolute path to the artifact when installed, never <code>null</code>.
     */
private File getLocalRepoFile() {
    DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate();
    coordinate.setGroupId(groupId);
    coordinate.setArtifactId(artifactId);
    coordinate.setVersion(version);
    coordinate.setClassifier(classifier);
    coordinate.setExtension(packaging);
    String path = repoManager.getPathForLocalArtifact(getSession().getProjectBuildingRequest(), coordinate);
    return new File(repoManager.getLocalRepositoryBasedir(getSession().getProjectBuildingRequest()), path);
}
Also used : DefaultArtifactCoordinate(org.apache.maven.shared.artifact.DefaultArtifactCoordinate) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 10 with DefaultArtifactCoordinate

use of org.apache.maven.shared.artifact.DefaultArtifactCoordinate in project maven-plugins by apache.

the class ShadeMojo method resolveArtifactSources.

private File resolveArtifactSources(Artifact artifact) {
    DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate();
    coordinate.setGroupId(artifact.getGroupId());
    coordinate.setArtifactId(artifact.getArtifactId());
    coordinate.setVersion(artifact.getVersion());
    coordinate.setExtension("jar");
    coordinate.setClassifier("sources");
    Artifact resolvedArtifact;
    try {
        resolvedArtifact = artifactResolver.resolveArtifact(session.getProjectBuildingRequest(), coordinate).getArtifact();
    } catch (ArtifactResolverException e) {
        getLog().warn("Could not get sources for " + artifact);
        return null;
    }
    if (resolvedArtifact.isResolved()) {
        return resolvedArtifact.getFile();
    }
    return null;
}
Also used : ArtifactResolverException(org.apache.maven.shared.artifact.resolve.ArtifactResolverException) DefaultArtifactCoordinate(org.apache.maven.shared.artifact.DefaultArtifactCoordinate) Artifact(org.apache.maven.artifact.Artifact)

Aggregations

DefaultArtifactCoordinate (org.apache.maven.shared.artifact.DefaultArtifactCoordinate)10 ArtifactResolverException (org.apache.maven.shared.artifact.resolve.ArtifactResolverException)5 Artifact (org.apache.maven.artifact.Artifact)4 ArtifactHandler (org.apache.maven.artifact.handler.ArtifactHandler)3 ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)3 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 File (java.io.File)1 JarFile (java.util.jar.JarFile)1 Skin (org.apache.maven.doxia.site.decoration.Skin)1 DefaultProjectBuildingRequest (org.apache.maven.project.DefaultProjectBuildingRequest)1 MavenReportException (org.apache.maven.reporting.MavenReportException)1 ArtifactCoordinate (org.apache.maven.shared.artifact.ArtifactCoordinate)1