[MNG-1491] Reactor should print out a message if it detects a collision of artifact ids

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@787072 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-06-21 19:26:00 +00:00
parent c17c9564cc
commit d90f22f338
2 changed files with 105 additions and 12 deletions

View File

@ -187,16 +187,52 @@ protected Map<String,MavenProject> getProjectsForMavenReactor( MavenExecutionReq
List<File> files = Arrays.asList( request.getPom().getAbsoluteFile() );
Map<String,MavenProject> projects = collectProjects( files, request );
List<MavenProject> projects = new ArrayList<MavenProject>();
return projects;
collectProjects( projects, files, request );
Map<String, MavenProject> index = new LinkedHashMap<String, MavenProject>();
Map<String, List<File>> collisions = new LinkedHashMap<String, List<File>>();
for ( MavenProject project : projects )
{
String projectId = ArtifactUtils.key( project.getGroupId(), project.getArtifactId(), project.getVersion() );
MavenProject collision = index.get( projectId );
if ( collision == null )
{
index.put( projectId, project );
}
else
{
List<File> pomFiles = collisions.get( projectId );
if ( pomFiles == null )
{
pomFiles = new ArrayList<File>( Arrays.asList( collision.getFile(), project.getFile() ) );
collisions.put( projectId, pomFiles );
}
else
{
pomFiles.add( project.getFile() );
}
}
}
if ( !collisions.isEmpty() )
{
throw new org.apache.maven.DuplicateProjectException( "Two or more projects in the reactor"
+ " have the same identifier, please make sure that <groupId>:<artifactId>:<version>"
+ " is unique for each project: " + collisions, collisions );
}
return index;
}
private Map<String,MavenProject> collectProjects( List<File> files, MavenExecutionRequest request )
private void collectProjects( List<MavenProject> projects, List<File> files, MavenExecutionRequest request )
throws MavenExecutionException, ProjectBuildingException
{
Map<String,MavenProject> projects = new LinkedHashMap<String,MavenProject>();
for ( File file : files )
{
MavenProject project = projectBuilder.build( file, request.getProjectBuildingRequest() );
@ -245,15 +281,11 @@ else if ( moduleFile.isDirectory() )
moduleFiles.add( moduleFile );
}
Map<String,MavenProject> collectedProjects = collectProjects( moduleFiles, request );
projects.putAll( collectedProjects );
collectProjects( projects, moduleFiles, request );
}
projects.put( ArtifactUtils.key( project.getGroupId(), project.getArtifactId(), project.getVersion() ), project );
}
return projects;
projects.add( project );
}
}
private void validateActivatedProfiles( List<MavenProject> projects, List<String> activeProfileIds )

View File

@ -0,0 +1,61 @@
package org.apache.maven;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import java.io.File;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* Signals a collision of two or more projects with the same g:a:v during a reactor build.
*
* @author Benjamin Bentmann
*/
public class DuplicateProjectException
extends MavenExecutionException
{
private Map<String, List<File>> collisions;
/**
* Creates a new exception with specified details.
*
* @param message The message text, may be {@code null}.
* @param collisions The POM files of the projects that collided, indexed by their g:a:v, may be {@code null}.
*/
public DuplicateProjectException( String message, Map<String, List<File>> collisions )
{
super( message, (File) null );
this.collisions = ( collisions != null ) ? collisions : new LinkedHashMap<String, List<File>>();
}
/**
* Gets the POM files of the projects that collided.
*
* @return The POM files of the projects that collided, indexed by their g:a:v, never {@code null}.
*/
public Map<String, List<File>> getCollisions()
{
return collisions;
}
}