Example usage for org.apache.maven.artifact.handler.manager ArtifactHandlerManager getArtifactHandler

List of usage examples for org.apache.maven.artifact.handler.manager ArtifactHandlerManager getArtifactHandler

Introduction

In this page you can find the example usage for org.apache.maven.artifact.handler.manager ArtifactHandlerManager getArtifactHandler.

Prototype

ArtifactHandler getArtifactHandler(String type);

Source Link

Usage

From source file:hudson.gridmaven.reporters.MavenArtifact.java

License:Open Source License

/**
 * Creates a Maven {@link Artifact} back from the persisted data.
 *//* w w  w .  j a v a2s .c o  m*/
public Artifact toArtifact(ArtifactHandlerManager handlerManager, ArtifactFactory factory, MavenBuild build)
        throws IOException {
    // Hack: presence of custom ArtifactHandler during builds could influence the file extension
    // in the repository during deployment. So simulate that behavior if that's necessary.
    final String canonicalExtension = canonicalName.substring(canonicalName.lastIndexOf('.') + 1);
    ArtifactHandler ah = handlerManager.getArtifactHandler(type);
    Map<String, ArtifactHandler> handlers = Maps.newHashMap();

    handlers.put(type, new DefaultArtifactHandler(type) {
        public String getExtension() {
            return canonicalExtension;
        }
    });
    // Fix for HUDSON-3814 - changed from comparing against canonical extension to canonicalName.endsWith.
    if (!canonicalName.endsWith(ah.getExtension())) {
        handlerManager.addHandlers(handlers);
    }

    Artifact a = factory.createArtifactWithClassifier(groupId, artifactId, version, type, classifier);
    a.setFile(getFile(build));

    return a;
}

From source file:org.apache.sling.maven.slingstart.ModelUtils.java

License:Apache License

/**
 * Get a resolved Artifact from the coordinates provided
 *
 * @return the artifact, which has been resolved.
 * @throws MojoExecutionException//from  ww  w.  ja  v  a2 s .c om
 */
public static Artifact getArtifact(final MavenProject project, final MavenSession session,
        final ArtifactHandlerManager artifactHandlerManager, final ArtifactResolver resolver,
        final String groupId, final String artifactId, final String version, final String type,
        final String classifier) throws MojoExecutionException {
    final Set<Artifact> artifacts = project.getDependencyArtifacts();
    for (final Artifact artifact : artifacts) {
        if (artifact.getGroupId().equals(groupId) && artifact.getArtifactId().equals(artifactId)
                && artifact.getVersion().equals(version) && artifact.getType().equals(type)
                && ((classifier == null && artifact.getClassifier() == null)
                        || (classifier != null && classifier.equals(artifact.getClassifier())))) {
            return artifact;
        }
    }
    final Artifact prjArtifact = new DefaultArtifact(groupId, artifactId,
            VersionRange.createFromVersion(version), Artifact.SCOPE_PROVIDED, type, classifier,
            artifactHandlerManager.getArtifactHandler(type));
    try {
        resolver.resolve(prjArtifact, project.getRemoteArtifactRepositories(), session.getLocalRepository());
    } catch (final ArtifactResolutionException e) {
        throw new MojoExecutionException(
                "Unable to get artifact for " + groupId + ":" + artifactId + ":" + version, e);
    } catch (final ArtifactNotFoundException e) {
        throw new MojoExecutionException(
                "Unable to get artifact for " + groupId + ":" + artifactId + ":" + version, e);
    }
    return prjArtifact;
}