Example usage for org.apache.maven.artifact ArtifactUtils artifactMapByVersionlessId

List of usage examples for org.apache.maven.artifact ArtifactUtils artifactMapByVersionlessId

Introduction

In this page you can find the example usage for org.apache.maven.artifact ArtifactUtils artifactMapByVersionlessId.

Prototype

public static Map<String, Artifact> artifactMapByVersionlessId(Collection<Artifact> artifacts) 

Source Link

Usage

From source file:com.github.lukaszkusek.maven.cobertura.project.ProjectHandler.java

License:Open Source License

private Artifact getCoberturaArtifact() throws MojoExecutionException {
    Map<String, Artifact> pluginArtifacts = ArtifactUtils.artifactMapByVersionlessId(this.pluginArtifacts);
    Artifact coberturaArtifact = pluginArtifacts.get(COBERTURA_ARTIFACT_ID);

    if (coberturaArtifact == null) {
        throw new MojoExecutionException(
                "Couldn't find '" + COBERTURA_ARTIFACT_ID + "' artifact in plugin dependencies.");
    }//from   ww  w .  j  a  v  a 2s  . c  om
    return coberturaArtifact;
}

From source file:org.codehaus.mojo.cobertura.CoberturaInstrumentMojo.java

License:Apache License

/**
 * We need to tweak our test classpath for cobertura.
 *
 * @throws MojoExecutionException/*ww  w.  j av a 2s . c o m*/
 */
private void addCoberturaDependenciesToTestClasspath() throws MojoExecutionException {
    Map<String, Artifact> pluginArtifactMap = ArtifactUtils.artifactMapByVersionlessId(pluginClasspathList);
    Artifact coberturaArtifact = pluginArtifactMap.get("net.sourceforge.cobertura:cobertura-runtime");

    if (coberturaArtifact == null) {
        getLog().error("pluginArtifactMap: " + pluginArtifactMap);

        throw new MojoExecutionException("Couldn't find 'cobertura' artifact in plugin dependencies");
    }

    coberturaArtifact = artifactScopeToProvided(coberturaArtifact);

    if (this.getProject().getDependencyArtifacts() != null) {
        Set<Artifact> set = new LinkedHashSet<Artifact>(this.getProject().getDependencyArtifacts());
        set.add(coberturaArtifact);
        this.getProject().setDependencyArtifacts(set);
    }
}

From source file:org.codehaus.mojo.emma.EmmaInstrumentMojo.java

License:Open Source License

/**
 * Add EMMA dependency to project test classpath. When tests are executed, EMMA runtime dependency is required.
 * //from   w w  w  .ja  v  a2  s.c  o  m
 * @throws MojoExecutionException if EMMA dependency could not be added
 */
private void addEmmaDependenciesToTestClasspath() throws MojoExecutionException {
    // look for EMMA dependency in this plugin classpath
    final Map pluginArtifactMap = ArtifactUtils.artifactMapByVersionlessId(pluginClasspath);
    Artifact emmaArtifact = (Artifact) pluginArtifactMap.get("emma:emma");

    if (emmaArtifact == null) {
        // this should not happen
        throw new MojoExecutionException("Failed to find 'emma' artifact in plugin dependencies");
    }

    // set EMMA dependency scope to test
    emmaArtifact = artifactScopeToTest(emmaArtifact);

    // add EMMA to project dependencies
    final Set deps = new HashSet();
    if (project.getDependencyArtifacts() != null) {
        deps.addAll(project.getDependencyArtifacts());
    }
    deps.add(emmaArtifact);
    project.setDependencyArtifacts(deps);
}

From source file:org.codehaus.mojo.snapshots.PinSnapshotsMojo.java

License:Apache License

public void execute() throws MojoExecutionException {
    Model pom = readPom();//from   ww w .  j a v a  2  s  .c o  m

    Map artifactsByVersionlessId = ArtifactUtils.artifactMapByVersionlessId(artifacts);

    getLog().info("Pinning POM Dependencies.");
    int changed = pin(pom.getDependencies(), artifactsByVersionlessId);

    DependencyManagement depMgmt = pom.getDependencyManagement();
    if (depMgmt != null) {
        getLog().info("Pinning DependencyManagement (where possible).");
        changed += pin(depMgmt.getDependencies(), artifactsByVersionlessId);
    }

    if (changed == 0) {
        getLog().info(
                "No dependency versions could be pinned. You may need to clean out your local repository and try again.");
    } else {
        write(pom);
    }
}

From source file:org.jboss.maven.shared.release.phase.MapVersionRangesPhase.java

License:Open Source License

private void checkProject(final MavenProject project, final Map<String, String> originalVersions,
        final ReleaseDescriptor releaseDescriptor) throws ReleaseExecutionException {
    Map<String, Artifact> artifactMap = ArtifactUtils.artifactMapByVersionlessId(project.getArtifacts());
    try {// w ww . j  av  a 2 s. c  om
        Set<Artifact> dependencyArtifacts = project.createArtifacts(artifactFactory, null, null);
        checkDependencies(project, originalVersions, releaseDescriptor, artifactMap, dependencyArtifacts);
    } catch (InvalidDependencyVersionException e) {
        throw new ReleaseExecutionException("Failed to create dependency artifacts", e);
    }
}

From source file:org.sonatype.maven.plugin.cobertura4it.InstrumentMojo.java

License:Open Source License

/**
 * Add cobertura dependency to project test classpath. When tests are executed, cobertura runtime dependency is
 * required.//from  w ww  . j a  v a2s .c  o  m
 * 
 * @throws MojoExecutionException if cobertura dependency could not be added
 */
@SuppressWarnings("unchecked")
private void addCoberturaDependenciesToTestClasspath() throws MojoExecutionException {
    // look for cobertura dependency in this plugin classpath
    final Map<String, Artifact> pluginArtifactMap = ArtifactUtils.artifactMapByVersionlessId(pluginClasspath);
    Artifact coberturaArtifact = pluginArtifactMap.get("net.sourceforge.cobertura:cobertura");

    if (coberturaArtifact == null) {
        // this should not happen
        throw new MojoExecutionException("Failed to find 'cobertura' artifact in plugin dependencies");
    }

    // set cobertura dependency scope to test
    coberturaArtifact = artifactScopeToTest(coberturaArtifact);

    // add cobertura to project dependencies
    final Set<Artifact> deps = new LinkedHashSet<Artifact>();
    if (project.getDependencyArtifacts() != null) {
        deps.addAll(project.getDependencyArtifacts());
    }
    deps.add(coberturaArtifact);
    project.setDependencyArtifacts(deps);
}

From source file:org.sonatype.maven.plugin.emma.EmmaInstrumentMojo.java

License:Open Source License

/**
 * Add EMMA dependency to project test classpath. When tests are executed, EMMA runtime dependency is required.
 *
 * @throws MojoExecutionException if EMMA dependency could not be added
 *//*www  .  ja va  2  s  .  c  om*/
private void addEmmaDependenciesToTestClasspath() throws MojoExecutionException {
    // look for EMMA dependency in this plugin classpath
    final Map pluginArtifactMap = ArtifactUtils.artifactMapByVersionlessId(pluginClasspath);
    Artifact emmaArtifact = (Artifact) pluginArtifactMap.get("emma:emma");

    if (emmaArtifact == null) {
        // this should not happen
        throw new MojoExecutionException("Failed to find 'emma' artifact in plugin dependencies");
    }

    // set EMMA dependency scope to test
    emmaArtifact = artifactScopeToTest(emmaArtifact);

    // add EMMA to project dependencies
    final Set deps = new LinkedHashSet();
    if (project.getDependencyArtifacts() != null) {
        deps.addAll(project.getDependencyArtifacts());
    }
    deps.add(emmaArtifact);
    project.setDependencyArtifacts(deps);
}