diff --git a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java index 9f1061ec84..7505dece5a 100644 --- a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java +++ b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java @@ -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() ) { diff --git a/maven-core/src/main/java/org/apache/maven/execution/ReactorManager.java b/maven-core/src/main/java/org/apache/maven/execution/ReactorManager.java index ea2b8f9cb3..c524dfbaf1 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/ReactorManager.java +++ b/maven-core/src/main/java/org/apache/maven/execution/ReactorManager.java @@ -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 ); } diff --git a/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java b/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java index b661319de1..91e46332cf 100644 --- a/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java +++ b/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java @@ -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, ".", diff --git a/maven-project/src/main/java/org/apache/maven/project/DuplicateProjectException.java b/maven-project/src/main/java/org/apache/maven/project/DuplicateProjectException.java new file mode 100644 index 0000000000..5691d8c2db --- /dev/null +++ b/maven-project/src/main/java/org/apache/maven/project/DuplicateProjectException.java @@ -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 Brett Porter + * @version $Id$ + */ +public class DuplicateProjectException + extends Exception +{ + public DuplicateProjectException( String message ) + { + super( message ); + } + + public DuplicateProjectException( String message, Exception e ) + { + super( message, e ); + } +} diff --git a/maven-project/src/main/java/org/apache/maven/project/ProjectSorter.java b/maven-project/src/main/java/org/apache/maven/project/ProjectSorter.java index 2d27aa6c12..11c31ba6ff 100644 --- a/maven-project/src/main/java/org/apache/maven/project/ProjectSorter.java +++ b/maven-project/src/main/java/org/apache/maven/project/ProjectSorter.java @@ -56,9 +56,10 @@ public class ProjectSorter * we are trying to build. we assume a closed set. *
  • do a topo sort on the graph that remains.
  • * + * @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 ); diff --git a/maven-project/src/test/java/org/apache/maven/project/ProjectSorterTest.java b/maven-project/src/test/java/org/apache/maven/project/ProjectSorterTest.java index c4a9eed5bf..5f8e02940f 100644 --- a/maven-project/src/test/java/org/apache/maven/project/ProjectSorterTest.java +++ b/maven-project/src/test/java/org/apache/maven/project/ProjectSorterTest.java @@ -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();