PR: MNG-649

add classifier to dependency. it becomes part of the dependency key along with type when not null

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@225524 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-07-27 14:17:41 +00:00
parent 3fb0852fdf
commit eedd050414
10 changed files with 133 additions and 103 deletions

View File

@ -42,10 +42,10 @@ Artifact createArtifactWithClassifier( String groupId, String artifactId, String
String classifier );
Artifact createDependencyArtifact( String groupId, String artifactId, VersionRange versionRange, String type,
String scope );
String classifier, String scope );
Artifact createDependencyArtifact( String groupId, String artifactId, VersionRange versionRange, String type,
String scope, String inheritedScope );
String classifier, String scope, String inheritedScope );
Artifact createBuildArtifact( String groupId, String artifactId, String version, String packaging );

View File

@ -50,15 +50,15 @@ public Artifact createArtifactWithClassifier( String groupId, String artifactId,
}
public Artifact createDependencyArtifact( String groupId, String artifactId, VersionRange versionRange, String type,
String scope )
String classifier, String scope )
{
return createArtifact( groupId, artifactId, versionRange, null, type, null, null );
return createArtifact( groupId, artifactId, versionRange, null, type, classifier, null );
}
public Artifact createDependencyArtifact( String groupId, String artifactId, VersionRange versionRange, String type,
String scope, String inheritedScope )
String classifier, String scope, String inheritedScope )
{
return createArtifact( groupId, artifactId, versionRange, scope, type, null, inheritedScope );
return createArtifact( groupId, artifactId, versionRange, scope, type, classifier, inheritedScope );
}
public Artifact createBuildArtifact( String groupId, String artifactId, String version, String packaging )

View File

@ -419,8 +419,10 @@ public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepo
ArtifactSpec a = (ArtifactSpec) artifacts.get( key );
try
{
return new ResolutionGroup( artifact, createArtifacts( artifactFactory, a.dependencies, artifact.getScope(),
artifact.getDependencyFilter() ), Collections.EMPTY_LIST );
return new ResolutionGroup( artifact, createArtifacts( artifactFactory, a.dependencies,
artifact.getScope(),
artifact.getDependencyFilter() ),
Collections.EMPTY_LIST );
}
catch ( InvalidVersionSpecificationException e )
{
@ -445,7 +447,8 @@ private Set createArtifacts( ArtifactFactory artifactFactory, Set dependencies,
VersionRange versionRange = VersionRange.createFromVersionSpec( d.getVersion() );
Artifact artifact = artifactFactory.createDependencyArtifact( d.getGroupId(), d.getArtifactId(),
versionRange, d.getType(), d.getScope(),
versionRange, d.getType(),
d.getClassifier(), d.getScope(),
inheritedScope );
if ( artifact != null && ( dependencyFilter == null || dependencyFilter.include( artifact ) ) )

View File

@ -1210,6 +1210,16 @@
<type>String</type>
<defaultValue>jar</defaultValue>
</field>
<field>
<name>classifier</name>
<version>4.0.0</version>
<description>
The classifier of the dependency. This allows distinguishing two artifacts that belong to the same POM but
were built differently, and is appended to the filename after the version.
</description>
<type>String</type>
<required>false</required>
</field>
<field>
<name>properties</name>
<version>3.0.0</version>
@ -1266,14 +1276,9 @@
<codeSegment>
<version>4.0.0</version>
<code><![CDATA[
public String getId()
{
return groupId + ":" + artifactId + ":" + type + ":" + version;
}
public String getManagementKey()
{
return groupId + ":" + artifactId + ":" + type;
return groupId + ":" + artifactId + ":" + type + classifier != null ? ":" + classifier : "";
}
]]></code>
</codeSegment>

View File

@ -138,7 +138,8 @@ protected void executeTask()
checkInSnapshotVersionPom();
}
private void generateReleasePropertiesFile() throws MojoExecutionException
private void generateReleasePropertiesFile()
throws MojoExecutionException
{
try
{
@ -365,7 +366,8 @@ private void transformPomToReleaseVersionPom()
{
Dependency dep = (Dependency) i.next();
String conflictId = ArtifactUtils.artifactId( dep.getGroupId(), dep.getArtifactId(), dep.getType(), dep.getVersion() );
String conflictId = ArtifactUtils.artifactId( dep.getGroupId(), dep.getArtifactId(), dep.getType(),
dep.getClassifier(), dep.getVersion() );
Artifact artifact = (Artifact) artifactMap.get( conflictId );
@ -392,7 +394,8 @@ private void transformPomToReleaseVersionPom()
}
}
private void generateReleasePom() throws MojoExecutionException
private void generateReleasePom()
throws MojoExecutionException
{
MavenProject releaseProject = new MavenProject( project );
Model releaseModel = releaseProject.getModel();
@ -424,6 +427,7 @@ private void generateReleasePom() throws MojoExecutionException
newdep.setVersion( artifact.getVersion() );
newdep.setType( artifact.getType() );
newdep.setScope( artifact.getScope() );
newdep.setClassifier( artifact.getClassifier() );
newdeps.add( newdep );
}

View File

@ -83,6 +83,8 @@ else if ( selectDependenciesNodesXPathExpression().equals( node.getPath() ) )
Node type = node.selectSingleNode( "type" );
Node classifier = node.selectSingleNode( "classifier" );
String typeText = "jar";
if ( type != null )
@ -91,7 +93,8 @@ else if ( selectDependenciesNodesXPathExpression().equals( node.getPath() ) )
}
Node version = node.selectSingleNode( "version" );
String versionText = getDependency( groupId.getText(), artifactId.getText(), typeText ).getVersion();
String versionText = getDependency( groupId.getText(), artifactId.getText(), typeText,
classifier.getText() ).getVersion();
if ( version != null )
{
version.setText( versionText );
@ -183,14 +186,16 @@ else if ( selectPluginsNodesXPathExpression().equals( node.getPath() ) )
}
}
private Dependency getDependency( String groupId, String artifactId, String type )
private Dependency getDependency( String groupId, String artifactId, String type, String classifier )
{
// TODO: equals() in Dependency would be better
for ( Iterator i = getUpdatedModel().getDependencies().iterator(); i.hasNext(); )
{
Dependency dependency = (Dependency) i.next();
if ( dependency.getGroupId().equals( groupId ) && dependency.getArtifactId().equals( artifactId ) &&
dependency.getType().equals( type ) )
dependency.getType().equals( type ) && dependency.getClassifier() != null
? dependency.getClassifier().equals( classifier ) : classifier == null )
{
return dependency;
}

View File

@ -151,7 +151,8 @@ public MavenProject buildWithDependencies( File projectDescriptor, ArtifactRepos
try
{
project.setDependencyArtifacts( MavenProject.createArtifacts( artifactFactory, project.getDependencies() ) );
project.setDependencyArtifacts(
MavenProject.createArtifacts( artifactFactory, project.getDependencies() ) );
}
catch ( InvalidVersionSpecificationException e )
{
@ -199,7 +200,7 @@ private Map createManagedVersionMap( DependencyManagement dependencyManagement )
VersionRange versionRange = VersionRange.createFromVersionSpec( d.getVersion() );
Artifact artifact = artifactFactory.createDependencyArtifact( d.getGroupId(), d.getArtifactId(),
versionRange, d.getType(),
d.getScope() );
d.getClassifier(), d.getScope() );
map.put( d.getManagementKey(), artifact );
}
catch ( InvalidVersionSpecificationException e )
@ -231,7 +232,8 @@ private MavenProject buildFromSourceFile( File projectDescriptor, ArtifactReposi
modelCache.put( createCacheKey( model.getGroupId(), model.getArtifactId(), model.getVersion() ), model );
MavenProject project = build( projectDescriptor.getAbsolutePath(), model, localRepository,
Collections.EMPTY_LIST, externalProfiles, projectDescriptor.getAbsoluteFile().getParentFile() );
Collections.EMPTY_LIST, externalProfiles,
projectDescriptor.getAbsoluteFile().getParentFile() );
// Only translate the base directory for files in the source tree
pathTranslator.alignToBaseDirectory( project.getModel(), projectDescriptor );
@ -348,7 +350,8 @@ private MavenProject build( String pomLocation, Model model, ArtifactRepository
List repositories = new ArrayList( aggregatedRemoteWagonRepositories );
MavenProject project = assembleLineage( model, lineage, repositories, localRepository, externalProfiles, projectDir );
MavenProject project = assembleLineage( model, lineage, repositories, localRepository, externalProfiles,
projectDir );
project.setOriginalModel( originalModel );
@ -479,7 +482,9 @@ private MavenProject processProjectLogic( String pomLocation, MavenProject proje
return project;
}
/** @noinspection CollectionDeclaredAsConcreteClass*/
/**
* @noinspection CollectionDeclaredAsConcreteClass
*/
private MavenProject assembleLineage( Model model, LinkedList lineage, List aggregatedRemoteWagonRepositories,
ArtifactRepository localRepository, List externalProfiles, File projectDir )
throws ProjectBuildingException
@ -550,21 +555,24 @@ else if ( StringUtils.isEmpty( parentModel.getVersion() ) )
Model candidateParent = readModel( parentDescriptor );
// this works because parent-version is still required...
if ( parentModel.getGroupId().equals( candidateParent.getGroupId() )
&& parentModel.getArtifactId().equals( candidateParent.getArtifactId() )
&& ( parentModel.getVersion().equals( candidateParent.getVersion() )
|| ( candidateParent.getParent() != null
&& parentModel.getVersion().equals(candidateParent.getParent().getVersion() ) ) ) )
if ( parentModel.getGroupId().equals( candidateParent.getGroupId() ) &&
parentModel.getArtifactId().equals( candidateParent.getArtifactId() ) && (
parentModel.getVersion().equals( candidateParent.getVersion() ) || (
candidateParent.getParent() != null &&
parentModel.getVersion().equals( candidateParent.getParent().getVersion() ) ) ) )
{
model = candidateParent;
parentProjectDir = parentDescriptor.getParentFile();
getLogger().debug( "Using parent-POM from the project hierarchy at: \'" + parentModel.getRelativePath() + "\' for project: " + project.getId() );
getLogger().debug( "Using parent-POM from the project hierarchy at: \'" +
parentModel.getRelativePath() + "\' for project: " + project.getId() );
}
else
{
getLogger().debug("Invalid parent-POM referenced by relative path: \'" + parentModel.getRelativePath() + "\'. It did not match parent specification in " + project.getId() );
getLogger().debug( "Invalid parent-POM referenced by relative path: \'" +
parentModel.getRelativePath() + "\'. It did not match parent specification in " +
project.getId() );
}
}
}
@ -590,7 +598,8 @@ else if ( StringUtils.isEmpty( parentModel.getVersion() ) )
model = findModelFromRepository( parentArtifact, aggregatedRemoteWagonRepositories, localRepository );
}
MavenProject parent = assembleLineage( model, lineage, aggregatedRemoteWagonRepositories, localRepository, externalProfiles, parentProjectDir );
MavenProject parent = assembleLineage( model, lineage, aggregatedRemoteWagonRepositories, localRepository,
externalProfiles, parentProjectDir );
project.setParent( parent );

View File

@ -19,9 +19,9 @@
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.model.Build;
import org.apache.maven.model.CiManagement;
import org.apache.maven.model.Contributor;
@ -387,6 +387,7 @@ public List getCompileDependencies()
dependency.setVersion( a.getVersion() );
dependency.setScope( a.getScope() );
dependency.setType( a.getType() );
dependency.setClassifier( a.getClassifier() );
list.add( dependency );
}
@ -471,6 +472,7 @@ public List getTestDependencies()
dependency.setVersion( a.getVersion() );
dependency.setScope( a.getScope() );
dependency.setType( a.getType() );
dependency.setClassifier( a.getClassifier() );
list.add( dependency );
}
@ -552,6 +554,7 @@ public List getRuntimeDependencies()
dependency.setVersion( a.getVersion() );
dependency.setScope( a.getScope() );
dependency.setType( a.getType() );
dependency.setClassifier( a.getClassifier() );
list.add( dependency );
}

View File

@ -150,8 +150,8 @@ public static Set createArtifacts( ArtifactFactory artifactFactory, List depende
VersionRange versionRange = VersionRange.createFromVersionSpec( d.getVersion() );
Artifact artifact = artifactFactory.createDependencyArtifact( d.getGroupId(), d.getArtifactId(),
versionRange, d.getType(), d.getScope(),
inheritedScope );
versionRange, d.getType(), d.getClassifier(),
d.getScope(), inheritedScope );
if ( artifact != null && ( dependencyFilter == null || dependencyFilter.include( artifact ) ) )
{

View File

@ -146,7 +146,8 @@ protected Set createArtifacts( List dependencies, String inheritedScope )
VersionRange versionRange = VersionRange.createFromVersionSpec( d.getVersion() );
Artifact artifact = artifactFactory.createDependencyArtifact( d.getGroupId(), d.getArtifactId(),
versionRange, d.getType(), d.getScope(),
versionRange, d.getType(),
d.getClassifier(), d.getScope(),
inheritedScope );
if ( artifact != null )
{