PR: MNG-1355

Submitted By: Edwin Punzalan
Reviewed By: John Casey

Applied patch, with small logical fix (used getArtifactId() where getGroupId() was the intention).

This patch will guard against overwriting cached models in the project builder (check for pre-existing model in cache before adding), and will validate that a POM's parent has a different groupId:artifactId than the current POM.



git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@354473 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2005-12-06 16:50:22 +00:00
parent eeb14425c6
commit 8e85652193
2 changed files with 25 additions and 1 deletions

View File

@ -290,7 +290,14 @@ public class DefaultMavenProjectBuilder
// Always cache files in the source tree over those in the repository
MavenProject p = new MavenProject( model );
p.setFile( projectDescriptor );
modelCache.put( createCacheKey( model.getGroupId(), model.getArtifactId(), model.getVersion() ), p );
String modelKey = createCacheKey( model.getGroupId(), model.getArtifactId(), model.getVersion() );
if ( modelCache.containsKey( modelKey ) )
{
throw new ProjectBuildingException( model.getGroupId() + ":" + model.getArtifactId(),
"Duplicate project ID found in " + projectDescriptor.getAbsolutePath() );
}
modelCache.put( modelKey, p );
MavenProject project = build( projectDescriptor.getAbsolutePath(), model, localRepository,
buildArtifactRepositories( getSuperModel() ),
@ -852,6 +859,12 @@ public class DefaultMavenProjectBuilder
{
throw new ProjectBuildingException( projectId, "Missing artifactId element from parent element" );
}
else if ( parentModel.getGroupId().equals( model.getGroupId() ) &&
parentModel.getArtifactId().equals( model.getArtifactId() ) )
{
throw new ProjectBuildingException( projectId, "Parent element is a duplicate of " +
"the current project " );
}
else if ( StringUtils.isEmpty( parentModel.getVersion() ) )
{
throw new ProjectBuildingException( projectId, "Missing version element from parent element" );

View File

@ -21,6 +21,7 @@ import org.apache.maven.model.Build;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.DependencyManagement;
import org.apache.maven.model.Model;
import org.apache.maven.model.Parent;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.ReportPlugin;
import org.apache.maven.model.Reporting;
@ -60,6 +61,16 @@ public class DefaultModelValidator
result.addMessage( "Packaging '" + model.getPackaging() + "' is invalid. Aggregator projects " +
"require 'pom' as packaging." );
}
Parent parent = model.getParent();
if ( parent != null )
{
if ( parent.getGroupId().equals( model.getGroupId() ) &&
parent.getArtifactId().equals( model.getArtifactId() ) )
{
result.addMessage( "The parent element cannot have the same ID as the project." );
}
}
validateStringNotEmpty( "version", result, model.getVersion() );