PR: MNG-753

correct ordering of repositories in POM (also fixed problem of not correctly overriding "central" - properly this time!)
took note of a simpler way to ensure this is correct in future

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@240204 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-08-26 11:24:11 +00:00
parent c945c27bff
commit d466205274
1 changed files with 84 additions and 62 deletions

View File

@ -144,7 +144,8 @@ public class DefaultMavenProjectBuilder
/** /**
* @todo move to metadatasource itself? * @todo move to metadatasource itself?
*/ */
public MavenProject buildWithDependencies( File projectDescriptor, ArtifactRepository localRepository, ProfileManager profileManager ) public MavenProject buildWithDependencies( File projectDescriptor, ArtifactRepository localRepository,
ProfileManager profileManager )
throws ProjectBuildingException, ArtifactResolutionException throws ProjectBuildingException, ArtifactResolutionException
{ {
MavenProject project = buildFromSourceFile( projectDescriptor, localRepository, profileManager ); MavenProject project = buildFromSourceFile( projectDescriptor, localRepository, profileManager );
@ -258,13 +259,15 @@ public class DefaultMavenProjectBuilder
return buildFromSourceFile( projectDescriptor, localRepository, profileManager ); return buildFromSourceFile( projectDescriptor, localRepository, profileManager );
} }
public MavenProject build( File projectDescriptor, ArtifactRepository localRepository, ProfileManager profileManager ) public MavenProject build( File projectDescriptor, ArtifactRepository localRepository,
ProfileManager profileManager )
throws ProjectBuildingException throws ProjectBuildingException
{ {
return buildFromSourceFile( projectDescriptor, localRepository, profileManager ); return buildFromSourceFile( projectDescriptor, localRepository, profileManager );
} }
private MavenProject buildFromSourceFile( File projectDescriptor, ArtifactRepository localRepository, ProfileManager profileManager ) private MavenProject buildFromSourceFile( File projectDescriptor, ArtifactRepository localRepository,
ProfileManager profileManager )
throws ProjectBuildingException throws ProjectBuildingException
{ {
Model model = readModel( projectDescriptor ); Model model = readModel( projectDescriptor );
@ -273,7 +276,8 @@ public class DefaultMavenProjectBuilder
modelCache.put( createCacheKey( model.getGroupId(), model.getArtifactId(), model.getVersion() ), model ); modelCache.put( createCacheKey( model.getGroupId(), model.getArtifactId(), model.getVersion() ), model );
MavenProject project = build( projectDescriptor.getAbsolutePath(), model, localRepository, MavenProject project = build( projectDescriptor.getAbsolutePath(), model, localRepository,
Collections.EMPTY_LIST, projectDescriptor.getAbsoluteFile().getParentFile(), profileManager ); Collections.EMPTY_LIST, projectDescriptor.getAbsoluteFile().getParentFile(),
profileManager );
if ( project.getDistributionManagement() != null && project.getDistributionManagement().getStatus() != null ) if ( project.getDistributionManagement() != null && project.getDistributionManagement().getStatus() != null )
{ {
@ -308,8 +312,8 @@ public class DefaultMavenProjectBuilder
Model model = findModelFromRepository( artifact, remoteArtifactRepositories, localRepository ); Model model = findModelFromRepository( artifact, remoteArtifactRepositories, localRepository );
return build( "Artifact [" + artifact.getId() + "]", model, localRepository, remoteArtifactRepositories, return build( "Artifact [" + artifact.getId() + "]", model, localRepository, remoteArtifactRepositories, null,
null, null ); null );
} }
private Model findModelFromRepository( Artifact artifact, List remoteArtifactRepositories, private Model findModelFromRepository( Artifact artifact, List remoteArtifactRepositories,
@ -443,12 +447,11 @@ public class DefaultMavenProjectBuilder
//noinspection CollectionDeclaredAsConcreteClass //noinspection CollectionDeclaredAsConcreteClass
LinkedList lineage = new LinkedList(); LinkedList lineage = new LinkedList();
// TODO: the aRWR can get out of sync with project.model.repositories. We should do all the processing of
// profiles, etc on the models then recreate the aggregated sets at the end from the project repositories (they
// must still be created along the way so that parent poms can be discovered, however)
Set aggregatedRemoteWagonRepositories = new HashSet(); Set aggregatedRemoteWagonRepositories = new HashSet();
aggregatedRemoteWagonRepositories.addAll( ProjectUtils.buildArtifactRepositories( superModel.getRepositories(),
artifactRepositoryFactory,
container ) );
List activeExternalProfiles; List activeExternalProfiles;
try try
{ {
@ -503,9 +506,22 @@ public class DefaultMavenProjectBuilder
previous = current; previous = current;
} }
// only add the super repository if it wasn't overridden by a profile or project
List repositories = new ArrayList( aggregatedRemoteWagonRepositories );
List superRepositories = ProjectUtils.buildArtifactRepositories( superModel.getRepositories(),
artifactRepositoryFactory, container );
for ( Iterator i = superRepositories.iterator(); i.hasNext(); )
{
ArtifactRepository repository = (ArtifactRepository) i.next();
if ( !repositories.contains( repository ) )
{
repositories.add( repository );
}
}
try try
{ {
project = processProjectLogic( pomLocation, project, new ArrayList( aggregatedRemoteWagonRepositories ), profileManager ); project = processProjectLogic( pomLocation, project, repositories, profileManager );
} }
catch ( ModelInterpolationException e ) catch ( ModelInterpolationException e )
{ {
@ -524,7 +540,8 @@ public class DefaultMavenProjectBuilder
* the resolved source roots, etc for the parent - that occurs for the parent when it is constructed independently * the resolved source roots, etc for the parent - that occurs for the parent when it is constructed independently
* and projects are not cached or reused * and projects are not cached or reused
*/ */
private MavenProject processProjectLogic( String pomLocation, MavenProject project, List remoteRepositories, ProfileManager profileMgr ) private MavenProject processProjectLogic( String pomLocation, MavenProject project, List remoteRepositories,
ProfileManager profileMgr )
throws ProjectBuildingException, ModelInterpolationException throws ProjectBuildingException, ModelInterpolationException
{ {
Model model = project.getModel(); Model model = project.getModel();
@ -584,9 +601,11 @@ public class DefaultMavenProjectBuilder
if ( projectArtifact.isSnapshot() ) if ( projectArtifact.isSnapshot() )
{ {
project.setSnapshotDeploymentVersion( transformationManager.getSnapshotDeploymentVersion( projectArtifact ) ); project.setSnapshotDeploymentVersion(
transformationManager.getSnapshotDeploymentVersion( projectArtifact ) );
project.setSnapshotDeploymentBuildNumber( transformationManager.getSnapshotDeploymentBuildNumber( projectArtifact ) ); project.setSnapshotDeploymentBuildNumber(
transformationManager.getSnapshotDeploymentBuildNumber( projectArtifact ) );
} }
project.setPluginArtifactRepositories( ProjectUtils.buildArtifactRepositories( model.getPluginRepositories(), project.setPluginArtifactRepositories( ProjectUtils.buildArtifactRepositories( model.getPluginRepositories(),
@ -779,8 +798,8 @@ public class DefaultMavenProjectBuilder
model = findModelFromRepository( parentArtifact, remoteRepositories, localRepository ); model = findModelFromRepository( parentArtifact, remoteRepositories, localRepository );
} }
MavenProject parent = assembleLineage( model, lineage, localRepository, parentProjectDir, parentSearchRepositories, MavenProject parent = assembleLineage( model, lineage, localRepository, parentProjectDir,
aggregatedRemoteWagonRepositories ); parentSearchRepositories, aggregatedRemoteWagonRepositories );
project.setParent( parent ); project.setParent( parent );
@ -844,11 +863,13 @@ public class DefaultMavenProjectBuilder
} }
catch ( IOException e ) catch ( IOException e )
{ {
throw new ProfileActivationException( "Cannot read profiles.xml resource from directory: " + projectDir, e ); throw new ProfileActivationException( "Cannot read profiles.xml resource from directory: " + projectDir,
e );
} }
catch ( XmlPullParserException e ) catch ( XmlPullParserException e )
{ {
throw new ProfileActivationException( "Cannot parse profiles.xml resource from directory: " + projectDir, e ); throw new ProfileActivationException(
"Cannot parse profiles.xml resource from directory: " + projectDir, e );
} }
} }
} }
@ -882,7 +903,8 @@ public class DefaultMavenProjectBuilder
} }
} }
private Model readModel( Reader reader ) throws IOException, XmlPullParserException, InvalidModelException private Model readModel( Reader reader )
throws IOException, XmlPullParserException, InvalidModelException
{ {
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();