mirror of https://github.com/apache/maven.git
PR: MNG-1223
error out if there are duplicate modules in the reactor git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@327763 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3177575ca9
commit
772bf37124
|
@ -16,6 +16,7 @@ package org.apache.maven;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
import org.apache.maven.artifact.manager.WagonManager;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||
|
@ -32,6 +33,7 @@ import org.apache.maven.monitor.event.EventDispatcher;
|
|||
import org.apache.maven.monitor.event.MavenEvents;
|
||||
import org.apache.maven.profiles.ProfileManager;
|
||||
import org.apache.maven.profiles.activation.ProfileActivationException;
|
||||
import org.apache.maven.project.DuplicateProjectException;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.project.MavenProjectBuilder;
|
||||
import org.apache.maven.project.ProjectBuildingException;
|
||||
|
@ -294,9 +296,13 @@ public class DefaultMaven
|
|||
}
|
||||
catch ( CycleDetectedException e )
|
||||
{
|
||||
throw new MavenExecutionException(
|
||||
throw new BuildFailureException(
|
||||
"The projects in the reactor contain a cyclic reference: " + e.getMessage(), e );
|
||||
}
|
||||
catch ( DuplicateProjectException e )
|
||||
{
|
||||
throw new BuildFailureException( e.getMessage(), e );
|
||||
}
|
||||
|
||||
if ( rm.hasMultipleProjects() )
|
||||
{
|
||||
|
|
|
@ -16,8 +16,10 @@ package org.apache.maven.execution;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
import org.apache.maven.artifact.ArtifactUtils;
|
||||
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||
import org.apache.maven.project.DuplicateProjectException;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.project.ProjectSorter;
|
||||
import org.codehaus.plexus.util.dag.CycleDetectedException;
|
||||
|
@ -49,7 +51,7 @@ public class ReactorManager
|
|||
private Map buildSuccessesByProject = new HashMap();
|
||||
|
||||
public ReactorManager( List projects )
|
||||
throws CycleDetectedException
|
||||
throws CycleDetectedException, DuplicateProjectException
|
||||
{
|
||||
this.sorter = new ProjectSorter( projects );
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ package org.apache.maven.plugin;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.factory.ArtifactFactory;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
|
@ -28,6 +29,7 @@ import org.apache.maven.model.Model;
|
|||
import org.apache.maven.monitor.event.DefaultEventDispatcher;
|
||||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||
import org.apache.maven.project.DuplicateProjectException;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.settings.Settings;
|
||||
import org.codehaus.plexus.PlexusContainer;
|
||||
|
@ -141,7 +143,7 @@ public class PluginParameterExpressionEvaluatorTest
|
|||
}
|
||||
|
||||
private static MavenSession createSession( PlexusContainer container, ArtifactRepository repo )
|
||||
throws CycleDetectedException
|
||||
throws CycleDetectedException, DuplicateProjectException
|
||||
{
|
||||
return new MavenSession( container, new Settings(), repo, new DefaultEventDispatcher(),
|
||||
new ReactorManager( Collections.EMPTY_LIST ), Collections.EMPTY_LIST, ".",
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
package org.apache.maven.project;
|
||||
|
||||
|
||||
/*
|
||||
* Copyright 2001-2005 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Exception that occurs when the project list contains duplicate projects instead of ignoring one.
|
||||
*
|
||||
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
|
||||
* @version $Id$
|
||||
*/
|
||||
public class DuplicateProjectException
|
||||
extends Exception
|
||||
{
|
||||
public DuplicateProjectException( String message )
|
||||
{
|
||||
super( message );
|
||||
}
|
||||
|
||||
public DuplicateProjectException( String message, Exception e )
|
||||
{
|
||||
super( message, e );
|
||||
}
|
||||
}
|
|
@ -56,9 +56,10 @@ public class ProjectSorter
|
|||
* we are trying to build. we assume a closed set.</li>
|
||||
* <li>do a topo sort on the graph that remains.</li>
|
||||
* </ul>
|
||||
* @throws DuplicateProjectException if any projects are duplicated by id
|
||||
*/
|
||||
public ProjectSorter( List projects )
|
||||
throws CycleDetectedException
|
||||
throws CycleDetectedException, DuplicateProjectException
|
||||
{
|
||||
dag = new DAG();
|
||||
|
||||
|
@ -70,6 +71,11 @@ public class ProjectSorter
|
|||
|
||||
String id = ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() );
|
||||
|
||||
if ( dag.getVertex( id ) != null )
|
||||
{
|
||||
throw new DuplicateProjectException( "Project '" + id + "' is duplicated in the reactor" );
|
||||
}
|
||||
|
||||
dag.addVertex( id );
|
||||
|
||||
projectMap.put( id, project );
|
||||
|
|
|
@ -34,7 +34,7 @@ public class ProjectSorterTest
|
|||
extends TestCase
|
||||
{
|
||||
public void testMatchingArtifactIdsDifferentGroupIds()
|
||||
throws CycleDetectedException
|
||||
throws CycleDetectedException, DuplicateProjectException
|
||||
{
|
||||
List projects = new ArrayList();
|
||||
MavenProject project1 = createProject( "groupId1", "artifactId", "1.0" );
|
||||
|
@ -50,7 +50,7 @@ public class ProjectSorterTest
|
|||
}
|
||||
|
||||
public void testMatchingGroupIdsDifferentArtifactIds()
|
||||
throws CycleDetectedException
|
||||
throws CycleDetectedException, DuplicateProjectException
|
||||
{
|
||||
List projects = new ArrayList();
|
||||
MavenProject project1 = createProject( "groupId", "artifactId1", "1.0" );
|
||||
|
@ -65,6 +65,48 @@ public class ProjectSorterTest
|
|||
assertEquals( project1, projects.get( 1 ) );
|
||||
}
|
||||
|
||||
public void testMatchingIdsAndVersions()
|
||||
throws CycleDetectedException
|
||||
{
|
||||
List projects = new ArrayList();
|
||||
MavenProject project1 = createProject( "groupId", "artifactId", "1.0" );
|
||||
projects.add( project1 );
|
||||
MavenProject project2 = createProject( "groupId", "artifactId", "1.0" );
|
||||
projects.add( project2 );
|
||||
|
||||
try
|
||||
{
|
||||
projects = new ProjectSorter( projects ).getSortedProjects();
|
||||
fail( "Duplicate projects should fail" );
|
||||
}
|
||||
catch ( DuplicateProjectException e )
|
||||
{
|
||||
// expected
|
||||
assertTrue( true );
|
||||
}
|
||||
}
|
||||
|
||||
public void testMatchingIdsAndDifferentVersions()
|
||||
throws CycleDetectedException
|
||||
{
|
||||
List projects = new ArrayList();
|
||||
MavenProject project1 = createProject( "groupId", "artifactId", "1.0" );
|
||||
projects.add( project1 );
|
||||
MavenProject project2 = createProject( "groupId", "artifactId", "2.0" );
|
||||
projects.add( project2 );
|
||||
|
||||
try
|
||||
{
|
||||
projects = new ProjectSorter( projects ).getSortedProjects();
|
||||
fail( "Duplicate projects should fail" );
|
||||
}
|
||||
catch ( DuplicateProjectException e )
|
||||
{
|
||||
// expected
|
||||
assertTrue( true );
|
||||
}
|
||||
}
|
||||
|
||||
private Dependency createDependency( MavenProject project )
|
||||
{
|
||||
Dependency depdendency = new Dependency();
|
||||
|
|
Loading…
Reference in New Issue