Search in sources :

Example 1 with DefaultArtifactCoordinate

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

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

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

the class AbstractHelpMojo method getArtifactCoordinate.

protected ArtifactCoordinate getArtifactCoordinate(String groupId, String artifactId, String version, String type) {
    DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate();
    coordinate.setGroupId(groupId);
    coordinate.setArtifactId(artifactId);
    coordinate.setVersion(version);
    coordinate.setExtension(type);
    return coordinate;
}
Also used : DefaultArtifactCoordinate(org.apache.maven.shared.artifact.DefaultArtifactCoordinate)

Example 4 with DefaultArtifactCoordinate

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

the class AbstractChangesReport method getSkinArtifactFile.

private File getSkinArtifactFile() throws MojoExecutionException {
    Skin skin = Skin.getDefaultSkin();
    DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate();
    coordinate.setGroupId(skin.getGroupId());
    coordinate.setArtifactId(skin.getArtifactId());
    coordinate.setVersion(skin.getVersion());
    ProjectBuildingRequest pbr = new DefaultProjectBuildingRequest(mavenSession.getProjectBuildingRequest());
    pbr.setRemoteRepositories(project.getRemoteArtifactRepositories());
    try {
        return resolver.resolveArtifact(pbr, coordinate).getArtifact().getFile();
    } catch (ArtifactResolverException e) {
        throw new MojoExecutionException("Couldn't resolve the skin.", e);
    }
}
Also used : ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest) ArtifactResolverException(org.apache.maven.shared.artifact.resolve.ArtifactResolverException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DefaultArtifactCoordinate(org.apache.maven.shared.artifact.DefaultArtifactCoordinate) Skin(org.apache.maven.doxia.site.decoration.Skin) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest)

Example 5 with DefaultArtifactCoordinate

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

the class AbstractJavadocMojo method resolveDependency.

/**
     * @param dependency {@link Dependency}
     * @return {@link Artifact}
     * @throws MavenReportException
     */
public Artifact resolveDependency(Dependency dependency) throws MavenReportException {
    DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate();
    coordinate.setGroupId(dependency.getGroupId());
    coordinate.setArtifactId(dependency.getArtifactId());
    coordinate.setVersion(dependency.getVersion());
    coordinate.setClassifier(dependency.getClassifier());
    coordinate.setExtension(artifactHandlerManager.getArtifactHandler(dependency.getType()).getExtension());
    try {
        return artifactResolver.resolveArtifact(session.getProjectBuildingRequest(), coordinate).getArtifact();
    } catch (ArtifactResolverException e) {
        throw new MavenReportException("artifact resolver problem - " + e.getMessage(), e);
    }
}
Also used : ArtifactResolverException(org.apache.maven.shared.artifact.resolve.ArtifactResolverException) DefaultArtifactCoordinate(org.apache.maven.shared.artifact.DefaultArtifactCoordinate) MavenReportException(org.apache.maven.reporting.MavenReportException)

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