o Fixed goal decorator inheritance deficiency.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163137 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2004-09-22 02:58:12 +00:00
parent a793d673b4
commit 5f23120ff6
5 changed files with 55 additions and 3 deletions

View File

@ -22,6 +22,7 @@
import org.apache.maven.lifecycle.goal.AbstractMavenGoalPhase;
import org.apache.maven.lifecycle.goal.GoalExecutionException;
import org.apache.maven.lifecycle.goal.MavenGoalExecutionContext;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.project.MavenProject;
import java.util.Iterator;

View File

@ -160,7 +160,7 @@ public List getPostGoals( String goal )
private void initGoalDecoratorMappings()
{
List allPreGoals = project.getModel().getPreGoals();
List allPreGoals = project.getPreGoals();
for ( Iterator it = allPreGoals.iterator(); it.hasNext(); )
{
PreGoal preGoal = (PreGoal) it.next();
@ -175,7 +175,7 @@ private void initGoalDecoratorMappings()
preGoalList.add( preGoal.getAttain() );
}
List allPostGoals = project.getModel().getPostGoals();
List allPostGoals = project.getPostGoals();
for ( Iterator it = allPostGoals.iterator(); it.hasNext(); )
{
PostGoal postGoal = (PostGoal) it.next();

View File

@ -148,7 +148,7 @@ public MavenProject build( File projectDescriptor, boolean resolveDependencies )
superModel.getRepositories() );
Model previous = superModel;
for ( Iterator i = lineage.iterator(); i.hasNext(); )
{
Model current = ( (MavenProject) i.next() ).getModel();

View File

@ -18,6 +18,8 @@
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Model;
import org.apache.maven.model.PostGoal;
import org.apache.maven.model.PreGoal;
import org.apache.maven.model.Repository;
import java.util.Iterator;
@ -228,6 +230,28 @@ public void assembleModelInheritance( Model child, Model parent )
}
// PreGoals :: aggregate
List preGoals = parent.getPreGoals();
for ( Iterator iterator = preGoals.iterator(); iterator.hasNext(); )
{
PreGoal preGoal = (PreGoal) iterator.next();
child.addPreGoal( preGoal );
}
// PostGoals :: aggregate
List postGoals = parent.getPostGoals();
for ( Iterator iterator = postGoals.iterator(); iterator.hasNext(); )
{
PostGoal postGoal = (PostGoal) iterator.next();
child.addPostGoal( postGoal );
}
// Repositories :: aggregate
List parentRepositories = parent.getRepositories();

View File

@ -20,6 +20,8 @@
import junit.framework.TestCase;
import org.apache.maven.model.Build;
import org.apache.maven.model.Model;
import org.apache.maven.model.PostGoal;
import org.apache.maven.model.PreGoal;
import org.apache.maven.model.Resource;
import org.apache.maven.model.UnitTest;
@ -65,6 +67,19 @@ public void testShouldOverrideUnitTestExcludesOnly()
parentBuild.setUnitTest( parentUT );
parent.setBuild( parentBuild );
PreGoal preGoal1 = new PreGoal();
preGoal1.setName("compiler:compile");
preGoal1.setAttain("clean:clean");
parent.addPreGoal(preGoal1);
// hehe...try getting anything done with this one in place!
PostGoal postGoal1 = new PostGoal();
postGoal1.setName("jar:jar");
postGoal1.setAttain("clean:clean");
parent.addPostGoal(postGoal1);
Model child = new Model();
@ -78,6 +93,12 @@ public void testShouldOverrideUnitTestExcludesOnly()
childBuild.setUnitTest( childUT );
child.setBuild( childBuild );
PreGoal preGoal2 = new PreGoal();
preGoal2.setName("compiler:compile");
preGoal2.setAttain("qdox:generate");
child.addPreGoal(preGoal2);
ModelInheritanceAssembler assembler = new DefaultModelInheritanceAssembler();
@ -110,5 +131,11 @@ public void testShouldOverrideUnitTestExcludesOnly()
assertEquals( "plugin", child.getType() );
assertEquals( "jar", parent.getType() );
assertEquals("merged child should have 2 preGoals", 2, child.getPreGoals().size());
assertTrue("preGoal should be inherited from parent", child.getPreGoals().contains(preGoal1));
assertTrue("preGoal should be preserved from child", child.getPreGoals().contains(preGoal2));
assertEquals("1 postGoal should be inherited from parent", 1, child.getPostGoals().size());
}
}