mirror of https://github.com/apache/maven.git
[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:
parent
c17c9564cc
commit
d90f22f338
|
@ -187,16 +187,52 @@ public class DefaultMaven
|
||||||
|
|
||||||
List<File> files = Arrays.asList( request.getPom().getAbsoluteFile() );
|
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
|
throws MavenExecutionException, ProjectBuildingException
|
||||||
{
|
{
|
||||||
Map<String,MavenProject> projects = new LinkedHashMap<String,MavenProject>();
|
|
||||||
|
|
||||||
for ( File file : files )
|
for ( File file : files )
|
||||||
{
|
{
|
||||||
MavenProject project = projectBuilder.build( file, request.getProjectBuildingRequest() );
|
MavenProject project = projectBuilder.build( file, request.getProjectBuildingRequest() );
|
||||||
|
@ -245,15 +281,11 @@ public class DefaultMaven
|
||||||
moduleFiles.add( moduleFile );
|
moduleFiles.add( moduleFile );
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String,MavenProject> collectedProjects = collectProjects( moduleFiles, request );
|
collectProjects( projects, moduleFiles, request );
|
||||||
|
|
||||||
projects.putAll( collectedProjects );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 )
|
private void validateActivatedProfiles( List<MavenProject> projects, List<String> activeProfileIds )
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue