mirror of https://github.com/apache/maven.git
Resolving: MNG-482
To use the new artifact map for either the project or the current plugin from your mojo, simply use one of the following expressions: ${plugin.artifactMap} ${project.artifactMap} The artifacts in these maps are keyed using org.apache.maven.artifact.ArtifactUtils.versionlessKey( String groupId, String artifactId ) (found in the maven-artifact project). git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@219234 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
872214ca25
commit
2c80da6ba4
|
@ -0,0 +1,40 @@
|
|||
package org.apache.maven.artifact;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public final class ArtifactUtils
|
||||
{
|
||||
|
||||
private ArtifactUtils()
|
||||
{
|
||||
}
|
||||
|
||||
public static String versionlessKey( Artifact artifact )
|
||||
{
|
||||
return versionlessKey( artifact.getGroupId(), artifact.getArtifactId() );
|
||||
}
|
||||
|
||||
public static String versionlessKey( String groupId, String artifactId )
|
||||
{
|
||||
return groupId + ":" + artifactId;
|
||||
}
|
||||
|
||||
public static Map artifactMap( Collection artifacts )
|
||||
{
|
||||
Map artifactMap = new HashMap();
|
||||
|
||||
for ( Iterator it = artifacts.iterator(); it.hasNext(); )
|
||||
{
|
||||
Artifact artifact = (Artifact) it.next();
|
||||
|
||||
artifactMap.put( versionlessKey( artifact ), artifact );
|
||||
}
|
||||
|
||||
return artifactMap;
|
||||
}
|
||||
|
||||
}
|
|
@ -38,7 +38,7 @@ import java.util.TreeMap;
|
|||
public class MBoot
|
||||
{
|
||||
String[] builds = new String[]{"maven-model", "maven-settings", "maven-monitor", "maven-plugin-api",
|
||||
"maven-plugin-descriptor", "maven-artifact", "maven-artifact-manager", "maven-artifact-test",
|
||||
"maven-artifact", "maven-plugin-descriptor", "maven-artifact-manager", "maven-artifact-test",
|
||||
"maven-plugin-mapping",
|
||||
"maven-script/maven-script-beanshell", "maven-script/maven-script-marmalade", "maven-project", "maven-profile",
|
||||
"maven-plugin-registry", "maven-reporting/maven-reporting-api", "maven-core", "maven-archiver",
|
||||
|
|
|
@ -15,6 +15,11 @@
|
|||
<artifactId>maven-plugin-api</artifactId>
|
||||
<version>2.0-beta-1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-artifact</artifactId>
|
||||
<version>2.0-beta-1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>plexus</groupId>
|
||||
<artifactId>plexus-container-default</artifactId>
|
||||
|
|
|
@ -20,6 +20,8 @@ import org.codehaus.plexus.component.repository.ComponentSetDescriptor;
|
|||
import org.codehaus.plexus.util.IOUtil;
|
||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||
import org.codehaus.classworlds.ClassRealm;
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.ArtifactUtils;
|
||||
import org.apache.maven.plugin.lifecycle.LifecycleConfiguration;
|
||||
import org.apache.maven.plugin.lifecycle.Lifecycle;
|
||||
import org.apache.maven.plugin.lifecycle.io.xpp3.LifecycleMappingsXpp3Reader;
|
||||
|
@ -60,6 +62,9 @@ public class PluginDescriptor
|
|||
|
||||
private ClassRealm classRealm;
|
||||
|
||||
// calculated on-demand.
|
||||
private Map artifactMap;
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
//
|
||||
// ----------------------------------------------------------------------
|
||||
|
@ -216,6 +221,19 @@ public class PluginDescriptor
|
|||
public void setArtifacts( List artifacts )
|
||||
{
|
||||
this.artifacts = artifacts;
|
||||
|
||||
// clear the calculated artifactMap
|
||||
artifactMap = null;
|
||||
}
|
||||
|
||||
public Map getArtifactMap()
|
||||
{
|
||||
if ( artifactMap == null )
|
||||
{
|
||||
artifactMap = ArtifactUtils.artifactMap( getArtifacts() );
|
||||
}
|
||||
|
||||
return artifactMap;
|
||||
}
|
||||
|
||||
public boolean equals( Object object )
|
||||
|
|
|
@ -17,6 +17,7 @@ package org.apache.maven.project;
|
|||
*/
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.ArtifactUtils;
|
||||
import org.apache.maven.artifact.DependencyResolutionRequiredException;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.model.Build;
|
||||
|
@ -49,6 +50,7 @@ import java.util.ArrayList;
|
|||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -105,6 +107,9 @@ public class MavenProject
|
|||
|
||||
private Artifact artifact;
|
||||
|
||||
// calculated.
|
||||
private Map artifactMap;
|
||||
|
||||
public MavenProject( Model model )
|
||||
{
|
||||
this.model = model;
|
||||
|
@ -782,6 +787,9 @@ public class MavenProject
|
|||
public void setArtifacts( Set artifacts )
|
||||
{
|
||||
this.artifacts = artifacts;
|
||||
|
||||
// flush the calculated artifactMap
|
||||
artifactMap = null;
|
||||
}
|
||||
|
||||
public Set getArtifacts()
|
||||
|
@ -789,6 +797,16 @@ public class MavenProject
|
|||
return artifacts;
|
||||
}
|
||||
|
||||
public Map getArtifactMap()
|
||||
{
|
||||
if ( artifactMap == null )
|
||||
{
|
||||
artifactMap = ArtifactUtils.artifactMap( getArtifacts() );
|
||||
}
|
||||
|
||||
return artifactMap;
|
||||
}
|
||||
|
||||
public void setPluginArtifacts( Set pluginArtifacts )
|
||||
{
|
||||
this.pluginArtifacts = pluginArtifacts;
|
||||
|
|
Loading…
Reference in New Issue