mirror of https://github.com/apache/maven.git
MNG-5552 made classifier part of MavenProject.artifactMap key
Signed-off-by: Igor Fedorenko <ifedorenko@apache.org>
This commit is contained in:
parent
b99658c943
commit
f35698c790
|
@ -68,10 +68,15 @@ public static String toSnapshotVersion( String version )
|
||||||
|
|
||||||
public static String versionlessKey( Artifact artifact )
|
public static String versionlessKey( Artifact artifact )
|
||||||
{
|
{
|
||||||
return versionlessKey( artifact.getGroupId(), artifact.getArtifactId() );
|
return versionlessKey( artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String versionlessKey( String groupId, String artifactId )
|
public static String versionlessKey( String groupId, String artifactId )
|
||||||
|
{
|
||||||
|
return versionlessKey( groupId, artifactId, null );
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String versionlessKey( String groupId, String artifactId, String classifier )
|
||||||
{
|
{
|
||||||
if ( groupId == null )
|
if ( groupId == null )
|
||||||
{
|
{
|
||||||
|
@ -81,7 +86,13 @@ public static String versionlessKey( String groupId, String artifactId )
|
||||||
{
|
{
|
||||||
throw new NullPointerException( "artifactId is null" );
|
throw new NullPointerException( "artifactId is null" );
|
||||||
}
|
}
|
||||||
return groupId + ":" + artifactId;
|
StringBuilder key = new StringBuilder();
|
||||||
|
key.append( groupId ).append( ':' ).append( artifactId );
|
||||||
|
if ( classifier != null && !"".equals( classifier.trim() ) )
|
||||||
|
{
|
||||||
|
key.append( ':' ).append( classifier );
|
||||||
|
}
|
||||||
|
return key.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String key( Artifact artifact )
|
public static String key( Artifact artifact )
|
||||||
|
|
|
@ -22,9 +22,11 @@
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.maven.AbstractCoreMavenComponentTestCase;
|
import org.apache.maven.AbstractCoreMavenComponentTestCase;
|
||||||
import org.apache.maven.artifact.Artifact;
|
import org.apache.maven.artifact.Artifact;
|
||||||
|
@ -380,6 +382,28 @@ public void testShouldExtractPluginArtifacts()
|
||||||
assertEquals( "testGroup", result.getGroupId() );
|
assertEquals( "testGroup", result.getGroupId() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testProjectArtifactMap()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
Model model = new Model();
|
||||||
|
MavenProject project = new MavenProject( model );
|
||||||
|
Set<Artifact> artifacts = new HashSet<Artifact>();
|
||||||
|
artifacts.add( createArtifact( "testGroup", "testArtifact", "1.0" ) );
|
||||||
|
artifacts.add( createArtifact( "testGroup", "testArtifact", "1.0", "testClassifier" ) );
|
||||||
|
project.setArtifacts( artifacts );
|
||||||
|
ExpressionEvaluator ee = createExpressionEvaluator( project, null, new Properties() );
|
||||||
|
|
||||||
|
@SuppressWarnings( "unchecked" )
|
||||||
|
Map<String, Artifact> depResults = (Map<String, Artifact>) ee.evaluate( "${project.artifactMap}" );
|
||||||
|
assertEquals( 2, depResults.size() );
|
||||||
|
assertNotNull( depResults.get( "testGroup:testArtifact" ) );
|
||||||
|
assertNotNull( depResults.get( "testGroup:testArtifact:testClassifier" ) );
|
||||||
|
|
||||||
|
assertNull( ( (Artifact) ee.evaluate( "${project.artifactMap(testGroup:testArtifact)}" ) ).getClassifier() );
|
||||||
|
assertEquals( "testClassifier",
|
||||||
|
( (Artifact) ee.evaluate( "${project.artifactMap(testGroup:testArtifact:testClassifier)}" ) ).getClassifier() );
|
||||||
|
}
|
||||||
|
|
||||||
private MavenProject createDefaultProject()
|
private MavenProject createDefaultProject()
|
||||||
{
|
{
|
||||||
return new MavenProject( new Model() );
|
return new MavenProject( new Model() );
|
||||||
|
@ -416,6 +440,20 @@ protected Artifact createArtifact( String groupId, String artifactId, String ver
|
||||||
return factory.createDependencyArtifact( dependency );
|
return factory.createDependencyArtifact( dependency );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected Artifact createArtifact( String groupId, String artifactId, String version, String classifier )
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
Dependency dependency = new Dependency();
|
||||||
|
dependency.setGroupId( groupId );
|
||||||
|
dependency.setArtifactId( artifactId );
|
||||||
|
dependency.setVersion( version );
|
||||||
|
dependency.setClassifier( classifier );
|
||||||
|
dependency.setType( "jar" );
|
||||||
|
dependency.setScope( "compile" );
|
||||||
|
|
||||||
|
return factory.createDependencyArtifact( dependency );
|
||||||
|
}
|
||||||
|
|
||||||
private MojoExecution newMojoExecution()
|
private MojoExecution newMojoExecution()
|
||||||
{
|
{
|
||||||
PluginDescriptor pd = new PluginDescriptor();
|
PluginDescriptor pd = new PluginDescriptor();
|
||||||
|
|
Loading…
Reference in New Issue