You are viewing a plain text version of this content. The canonical link for it is here.
Posted to m2-dev@maven.apache.org by jd...@apache.org on 2004/07/19 02:58:15 UTC
cvs commit: maven-components/maven-core/src/test/resources maven.xml
jdcasey 2004/07/18 17:58:14
Modified: maven-core/src/main/java/org/apache/maven/decoration
GoalDecorationParser.java GoalDecorator.java
DefaultGoalDecorator.java
GoalDecoratorBindings.java
maven-plugin/src/main/java/org/apache/maven/plugin/descriptor
MojoDescriptor.java
maven-core-it integration-tests.txt
maven-plugin/src/main/java/org/apache/maven/plugin/generator
AbstractGenerator.java
maven-core/src/main/java/org/apache/maven/lifecycle
MavenLifecycleContext.java
maven-core/src/main/java/org/apache/maven/lifecycle/phase
GoalResolutionPhase.java GoalDecorationPhase.java
Added: maven-core/src/test/java/org/apache/maven/decoration
GoalDecorationParserTest.java
DefaultGoalDecoratorTest.java
GoalDecoratorBindingsTest.java
maven-core/src/test/java/org/apache/maven/lifecycle/phase
GoalDecorationPhaseTest.java
GoalResolutionPhaseTest.java
maven-core/src/test/java/org/apache/maven/plugin
GoalDecorationAndResolutionTestPlugin.java
maven-core-it/it0006 .cvsignore pom.xml expected-results.txt
goals.txt decorators.xml
maven-core/src/test/resources/META-INF/maven plugin.xml
maven-core-it/it0006/src/test/java/org/apache/maven/it0000
PersonTest.java
maven-core-it/it0006/src/main/java/org/apache/maven/it0000
Person.java
Removed: maven-core/src/test/resources maven.xml
Log:
o Added unit tests for goal decoration/resolution.
o Added integration test featuring a decorated goal.
Revision Changes Path
1.1 maven-components/maven-core/src/test/java/org/apache/maven/decoration/GoalDecorationParserTest.java
Index: GoalDecorationParserTest.java
===================================================================
/* Created on Jul 14, 2004 */
package org.apache.maven.decoration;
/*
* Copyright 2001-2004 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.
*/
import java.io.IOException;
import java.io.StringReader;
import org.xmlpull.v1.XmlPullParserException;
import junit.framework.TestCase;
/**
* @author jdcasey
*/
public class GoalDecorationParserTest extends TestCase {
private static final String SCRIPT_WITH_ONE_PREGOAL_NO_DEFAULT_GOAL =
"<decorators>" +
"<preGoal name=\"compiler:compile\" attain=\"compiler:init\"/>" +
"</decorators>";
private static final String SCRIPT_WITH_ONE_POSTGOAL_NO_DEFAULT_GOAL =
"<decorators>" +
"<postGoal name=\"compiler:compile\" attain=\"compiler:init\"/>" +
"</decorators>";
private static final String SCRIPT_WITH_DEFAULT_GOAL_NO_DECORATORS =
"<decorators defaultGoal=\"jar:jar\"/>";
private static final String SCRIPT_WITH_ONE_POSTGOAL_ONE_PREGOAL_AND_DEFAULT_GOAL =
"<decorators defaultGoal=\"jar:jar\">" +
"<preGoal name=\"compiler:compile\" attain=\"compiler:init\"/>" +
"<postGoal name=\"compiler:compile\" attain=\"jar:initFS\"/>" +
"</decorators>";
public void testShouldConstructWithNoArgs() {
new GoalDecorationParser();
}
public void testShouldParseOnePreGoalNoPostGoalsNoDefaultGoal() throws XmlPullParserException, IOException {
GoalDecoratorBindings bindings = parse(SCRIPT_WITH_ONE_POSTGOAL_ONE_PREGOAL_AND_DEFAULT_GOAL);
assertEquals(1, bindings.getPreGoals("compiler:compile").size());
}
public void testShouldParseNoPreGoalsOnePostGoalNoDefaultGoal() throws XmlPullParserException, IOException {
GoalDecoratorBindings bindings = parse(SCRIPT_WITH_ONE_POSTGOAL_ONE_PREGOAL_AND_DEFAULT_GOAL);
assertEquals(1, bindings.getPostGoals("compiler:compile").size());
}
public void testShouldParseNoPreGoalsNoPostGoalsWithDefaultGoal() throws XmlPullParserException, IOException {
GoalDecoratorBindings bindings = parse(SCRIPT_WITH_ONE_POSTGOAL_ONE_PREGOAL_AND_DEFAULT_GOAL);
assertEquals("jar:jar", bindings.getDefaultGoal());
}
public void testShouldParseOnePreGoalOnePostGoalWithDefaultGoal() throws XmlPullParserException, IOException {
GoalDecoratorBindings bindings = parse(SCRIPT_WITH_ONE_POSTGOAL_ONE_PREGOAL_AND_DEFAULT_GOAL);
assertEquals("jar:jar", bindings.getDefaultGoal());
assertEquals(1, bindings.getPreGoals("compiler:compile").size());
assertEquals(1, bindings.getPostGoals("compiler:compile").size());
}
private GoalDecoratorBindings parse(String inputString) throws XmlPullParserException, IOException {
GoalDecorationParser parser = new GoalDecorationParser();
StringReader reader = new StringReader(inputString);
return parser.parse(reader);
}
}
1.1 maven-components/maven-core/src/test/java/org/apache/maven/decoration/DefaultGoalDecoratorTest.java
Index: DefaultGoalDecoratorTest.java
===================================================================
/* Created on Jul 14, 2004 */
package org.apache.maven.decoration;
/*
* Copyright 2001-2004 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.
*/
import junit.framework.TestCase;
/**
* @author jdcasey
*/
public class DefaultGoalDecoratorTest extends TestCase {
public void testShouldConstructWithTargetGoalAndDecoratorGoal() {
new DefaultGoalDecorator("compiler:compile", "compiler:init");
}
public void testShouldRetrieveTargetGoal() {
DefaultGoalDecorator decorator = new DefaultGoalDecorator("compiler:compile", "compiler:init");
assertEquals("compiler:compile", decorator.getGoalToDecorate());
}
public void testShouldRetrieveDecoratorGoal() {
DefaultGoalDecorator decorator = new DefaultGoalDecorator("compiler:compile", "compiler:init");
assertEquals("compiler:init", decorator.getDecoratorGoal());
}
}
1.1 maven-components/maven-core/src/test/java/org/apache/maven/decoration/GoalDecoratorBindingsTest.java
Index: GoalDecoratorBindingsTest.java
===================================================================
/* Created on Jul 14, 2004 */
package org.apache.maven.decoration;
/*
* Copyright 2001-2004 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.
*/
import junit.framework.TestCase;
/**
* @author jdcasey
*/
public class GoalDecoratorBindingsTest extends TestCase {
public void testShouldConstructWithNoArguments() {
new GoalDecoratorBindings();
}
public void testShouldAddOnePreGoalAndRetrievePreGoalsListOfSizeOne() {
String targetGoal = "compiler:compile";
DefaultGoalDecorator decorator = new DefaultGoalDecorator(targetGoal, "compiler:init");
GoalDecoratorBindings bindings = new GoalDecoratorBindings();
bindings.addPreGoal(decorator);
assertEquals(1, bindings.getPreGoals(targetGoal).size());
}
public void testShouldAddOnePostGoalAndRetrievePostGoalsListOfSizeOne() {
String targetGoal = "compiler:compile";
DefaultGoalDecorator decorator = new DefaultGoalDecorator(targetGoal, "compiler:init");
GoalDecoratorBindings bindings = new GoalDecoratorBindings();
bindings.addPostGoal(decorator);
assertEquals(1, bindings.getPostGoals(targetGoal).size());
}
public void testShouldAddTwoPreGoalsAndRetrievePreGoalsListOfSizeTwo() {
String targetGoal = "compiler:compile";
DefaultGoalDecorator decorator = new DefaultGoalDecorator(targetGoal, "compiler:init");
DefaultGoalDecorator decorator2 = new DefaultGoalDecorator(targetGoal, "compiler:clean");
GoalDecoratorBindings bindings = new GoalDecoratorBindings();
bindings.addPreGoal(decorator);
bindings.addPreGoal(decorator2);
assertEquals(2, bindings.getPreGoals(targetGoal).size());
}
public void testShouldAddTwoPostGoalsAndRetrievePostGoalsListOfSizeTwo() {
String targetGoal = "compiler:compile";
DefaultGoalDecorator decorator = new DefaultGoalDecorator(targetGoal, "compiler:init");
DefaultGoalDecorator decorator2 = new DefaultGoalDecorator(targetGoal, "compiler:clean");
GoalDecoratorBindings bindings = new GoalDecoratorBindings();
bindings.addPostGoal(decorator);
bindings.addPostGoal(decorator2);
assertEquals(2, bindings.getPostGoals(targetGoal).size());
}
public void testShouldSetAndRetrieveDefaultGoal() {
GoalDecoratorBindings bindings = new GoalDecoratorBindings();
bindings.setDefaultGoal("jar:jar");
assertEquals("jar:jar", bindings.getDefaultGoal());
}
public void testShouldGetDefaultGoalOfCompiler_CompileWhenNotExplicitlySet() {
GoalDecoratorBindings bindings = new GoalDecoratorBindings();
assertEquals("compiler:compile", bindings.getDefaultGoal());
}
}
1.4 +83 -41 maven-components/maven-core/src/test/java/org/apache/maven/lifecycle/phase/GoalDecorationPhaseTest.java
1.1 maven-components/maven-core/src/test/java/org/apache/maven/lifecycle/phase/GoalResolutionPhaseTest.java
Index: GoalResolutionPhaseTest.java
===================================================================
/* Created on Jul 14, 2004 */
package org.apache.maven.lifecycle.phase;
import junit.framework.TestCase;
import org.apache.maven.decoration.DefaultGoalDecorator;
import org.apache.maven.decoration.GoalDecoratorBindings;
import org.apache.maven.lifecycle.MavenLifecycleContext;
import org.apache.maven.model.Model;
import org.apache.maven.plugin.MavenMojoDescriptor;
import org.apache.maven.plugin.MavenPluginDescriptor;
import org.apache.maven.plugin.PluginManager;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.embed.Embedder;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
/**
* @author jdcasey
*/
public class GoalResolutionPhaseTest extends TestCase
{
/*
<!-- Test main with preGoal and postGoal -->
<mojo>
<id>t1:preGoal</id>
<implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin</implementation>
<instantiationStrategy>singleton</instantiationStrategy>
</mojo>
<mojo>
<id>t1:main</id>
<implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin</implementation>
<instantiationStrategy>singleton</instantiationStrategy>
</mojo>
<mojo>
<id>t1:postGoal</id>
<implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin</implementation>
<instantiationStrategy>singleton</instantiationStrategy>
</mojo>
<!-- End of test -->
*/
public void testT1_ShouldFind_PreGoal_MainGoal_PostGoal( )
throws Exception
{
String mainGoal = "t1:main";
String preGoal = "t1:preGoal";
String postGoal = "t1:postGoal";
GoalDecoratorBindings bindings = new GoalDecoratorBindings( );
bindings.addPreGoal( new DefaultGoalDecorator( mainGoal, preGoal ) );
bindings.addPostGoal( new DefaultGoalDecorator( mainGoal, postGoal ) );
Map messages = new TreeMap( );
messages.put( mainGoal, "Main goal is missing." );
messages.put( preGoal, "preGoal is missing" );
messages.put( postGoal, "postGoal is missing" );
List order = new ArrayList( );
order.add( preGoal );
order.add( mainGoal );
order.add( postGoal );
runTest( mainGoal, bindings, order, messages );
}
/*
<!-- Test main with prereq -->
<mojo>
<id>t2:prereq</id>
<implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin</implementation>
<instantiationStrategy>singleton</instantiationStrategy>
</mojo>
<mojo>
<id>t2:main</id>
<implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin</implementation>
<instantiationStrategy>singleton</instantiationStrategy>
<prereqs>
<prereq>t2:prereq</prereq>
</prereqs>
</mojo>
<!-- End of test -->
*/
public void testT2_ShouldFind_Prereq_MainGoal( )
throws Exception
{
String mainGoal = "t2:main";
String prereq = "t2:prereq";
GoalDecoratorBindings bindings = new GoalDecoratorBindings( );
Map messages = new TreeMap( );
messages.put( mainGoal, "Main goal is missing." );
messages.put( prereq, "prereq is missing" );
List order = new ArrayList( );
order.add( prereq );
order.add( mainGoal );
runTest( mainGoal, bindings, order, messages );
}
/*
<!-- Test main with prereq, preGoal and postGoal -->
<mojo>
<id>t3:preGoal</id>
<implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin</implementation>
<instantiationStrategy>singleton</instantiationStrategy>
</mojo>
<mojo>
<id>t3:prereq</id>
<implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin</implementation>
<instantiationStrategy>singleton</instantiationStrategy>
</mojo>
<mojo>
<id>t3:main</id>
<implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin</implementation>
<instantiationStrategy>singleton</instantiationStrategy>
<prereqs>
<prereq>t3:prereq</prereq>
</prereqs>
</mojo>
<mojo>
<id>t3:postGoal</id>
<implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin</implementation>
<instantiationStrategy>singleton</instantiationStrategy>
</mojo>
<!-- End of test -->
*/
public void testT3_ShouldFind_PreGoal_Prereq_MainGoal_PostGoal( )
throws Exception
{
String mainGoal = "t3:main";
String prereq = "t3:prereq";
String preGoal = "t3:preGoal";
String postGoal = "t3:postGoal";
GoalDecoratorBindings bindings = new GoalDecoratorBindings( );
bindings.addPreGoal( new DefaultGoalDecorator( mainGoal, preGoal ) );
bindings.addPostGoal( new DefaultGoalDecorator( mainGoal, postGoal ) );
Map messages = new TreeMap( );
messages.put( mainGoal, "Main goal is missing." );
messages.put( prereq, "prereq is missing" );
messages.put( preGoal, "preGoal is missing" );
messages.put( postGoal, "postGoal is missing" );
List order = new ArrayList( );
order.add( preGoal );
order.add( prereq );
order.add( mainGoal );
order.add( postGoal );
runTest( mainGoal, bindings, order, messages );
}
/*
<!-- Test main with prereq which has preGoal and postGoal -->
<mojo>
<id>t4:prereq-preGoal</id>
<implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin</implementation>
<instantiationStrategy>singleton</instantiationStrategy>
</mojo>
<mojo>
<id>t4:prereq</id>
<implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin</implementation>
<instantiationStrategy>singleton</instantiationStrategy>
</mojo>
<mojo>
<id>t4:main</id>
<implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin</implementation>
<instantiationStrategy>singleton</instantiationStrategy>
<prereqs>
<prereq>t4:prereq</prereq>
</prereqs>
</mojo>
<mojo>
<id>t4:prereq-postGoal</id>
<implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin</implementation>
<instantiationStrategy>singleton</instantiationStrategy>
</mojo>
<!-- End of test -->
*/
public void testT4_ShouldFind_PreGoal_Prereq_PostGoal_MainGoal( )
throws Exception
{
String mainGoal = "t4:main";
String prereq = "t4:prereq";
String preGoal = "t4:prereq-preGoal";
String postGoal = "t4:prereq-postGoal";
GoalDecoratorBindings bindings = new GoalDecoratorBindings( );
bindings.addPreGoal( new DefaultGoalDecorator( prereq, preGoal ) );
bindings.addPostGoal( new DefaultGoalDecorator( prereq, postGoal ) );
Map messages = new TreeMap( );
messages.put( mainGoal, "Main goal is missing." );
messages.put( prereq, "prereq is missing" );
messages.put( preGoal, "preGoal is missing" );
messages.put( postGoal, "postGoal is missing" );
List order = new ArrayList( );
order.add( preGoal );
order.add( prereq );
order.add( postGoal );
order.add( mainGoal );
runTest( mainGoal, bindings, order, messages );
}
/*
<!-- Test main with prereq and preGoal which has the same prereq -->
<mojo>
<id>t5:prereq</id>
<implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin</implementation>
<instantiationStrategy>singleton</instantiationStrategy>
</mojo>
<mojo>
<id>t5:preGoal</id>
<implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin</implementation>
<instantiationStrategy>singleton</instantiationStrategy>
<prereqs>
<prereq>t5:prereq</prereq>
</prereqs>
</mojo>
<mojo>
<id>t5:main</id>
<implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin</implementation>
<instantiationStrategy>singleton</instantiationStrategy>
<prereqs>
<prereq>t5:prereq</prereq>
</prereqs>
</mojo>
<!-- End of test -->
*/
public void testT5_ShouldFind_Prereq_PreGoal_MainGoal( )
throws Exception
{
String mainGoal = "t5:main";
String prereq = "t5:prereq";
String preGoal = "t5:preGoal";
GoalDecoratorBindings bindings = new GoalDecoratorBindings( );
bindings.addPreGoal( new DefaultGoalDecorator( mainGoal, preGoal ) );
Map messages = new TreeMap( );
messages.put( mainGoal, "Main goal is missing." );
messages.put( prereq, "prereq is missing" );
messages.put( preGoal, "preGoal is missing" );
List order = new ArrayList( );
order.add( prereq );
order.add( preGoal );
order.add( mainGoal );
runTest( mainGoal, bindings, order, messages );
}
private void runTest( String mainGoal, GoalDecoratorBindings bindings,
List expectedOrder, Map messages )
throws Exception
{
MavenProject project = new MavenProject( new Model( ) );
project.setFile( new File( new File( "./resolution-test" ),
"project.xml" ) );
Embedder embedder = new Embedder( );
embedder.start( );
PluginManager pluginManager = ( PluginManager ) embedder.lookup( PluginManager.ROLE );
MojoDescriptor descriptor = pluginManager.getMojoDescriptor( mainGoal );
MavenLifecycleContext context = new MavenLifecycleContext( embedder
.getContainer( ), project, descriptor );
context.setGoalDecoratorBindings( bindings );
GoalResolutionPhase phase = new GoalResolutionPhase( );
phase.execute( context );
List goals = context.getResolvedGoals( );
System.out.println( "Resolved goals: " + goals );
assertNotNull( goals );
assertEquals( expectedOrder.size( ), goals.size( ) );
int index = 0;
for ( Iterator it = expectedOrder.iterator( ); it.hasNext( ); )
{
String goal = ( String ) it.next( );
String failureMessage = ( String ) messages.get( goal );
String resolvedGoal = ( String ) goals.get( index++ );
assertEquals( failureMessage, goal, resolvedGoal );
}
}
}
1.2 +2 -2 maven-components/maven-core/src/main/java/org/apache/maven/decoration/GoalDecorationParser.java
Index: GoalDecorationParser.java
===================================================================
RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/decoration/GoalDecorationParser.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- GoalDecorationParser.java 14 Jul 2004 04:27:25 -0000 1.1
+++ GoalDecorationParser.java 19 Jul 2004 00:58:14 -0000 1.2
@@ -13,8 +13,8 @@
*/
public class GoalDecorationParser {
- public static final String ROOT_TAG = "project";
- public static final String DEFAULT_GOAL_ATTRIBUTE = "default";
+ public static final String ROOT_TAG = "decorators";
+ public static final String DEFAULT_GOAL_ATTRIBUTE = "defaultGoal";
public static final String PREGOAL_TAG = "preGoal";
public static final String POSTGOAL_TAG = "postGoal";
1.2 +0 -4 maven-components/maven-core/src/main/java/org/apache/maven/decoration/GoalDecorator.java
Index: GoalDecorator.java
===================================================================
RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/decoration/GoalDecorator.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- GoalDecorator.java 14 Jul 2004 04:27:25 -0000 1.1
+++ GoalDecorator.java 19 Jul 2004 00:58:14 -0000 1.2
@@ -21,8 +21,4 @@
*/
String getDecoratorGoal();
- /** Whether to force the execution of the decorator goal. The default action is NOT to force
- * decorator-goal execution...in other words, fire each goal once-and-only-once.
- */
- boolean forceExecute();
}
1.2 +1 -11 maven-components/maven-core/src/main/java/org/apache/maven/decoration/DefaultGoalDecorator.java
Index: DefaultGoalDecorator.java
===================================================================
RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/decoration/DefaultGoalDecorator.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DefaultGoalDecorator.java 14 Jul 2004 04:27:25 -0000 1.1
+++ DefaultGoalDecorator.java 19 Jul 2004 00:58:14 -0000 1.2
@@ -16,7 +16,6 @@
private String goal;
private String decoratorGoal;
- private boolean forceExecution = false;
public DefaultGoalDecorator( String goal, String decoratorGoal )
{
@@ -34,19 +33,10 @@
return decoratorGoal;
}
- public void forceExecute( boolean forceExecution ) {
- this.forceExecution = forceExecution;
- }
-
- public boolean forceExecute() {
- return forceExecution;
- }
-
public String toString()
{
return "DefaultGoalDecorator[decorate: " + goal +
- " with: " + decoratorGoal + " and force? " +
- forceExecution + "]";
+ " with: " + decoratorGoal + "]";
}
}
1.2 +2 -6 maven-components/maven-core/src/main/java/org/apache/maven/decoration/GoalDecoratorBindings.java
Index: GoalDecoratorBindings.java
===================================================================
RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/decoration/GoalDecoratorBindings.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- GoalDecoratorBindings.java 14 Jul 2004 04:27:25 -0000 1.1
+++ GoalDecoratorBindings.java 19 Jul 2004 00:58:14 -0000 1.2
@@ -13,14 +13,10 @@
public class GoalDecoratorBindings
{
- public static final String PARSE_CTX_KEY = "maven-script";
-
private Map preGoals = new HashMap();
private Map postGoals = new HashMap();
- private String defaultGoal = "jar";
+ private String defaultGoal = "compiler:compile";
- /**
- */
public GoalDecoratorBindings()
{
}
@@ -60,7 +56,7 @@
private void addGoalDecorator( GoalDecorator decorator, Map decoratorMap )
{
String goal = decorator.getGoalToDecorate();
-
+
List decorators = (List) decoratorMap.get( goal );
if ( decorators == null )
{
1.4 +6 -2 maven-components/maven-plugin/src/main/java/org/apache/maven/plugin/descriptor/MojoDescriptor.java
Index: MojoDescriptor.java
===================================================================
RCS file: /home/cvs/maven-components/maven-plugin/src/main/java/org/apache/maven/plugin/descriptor/MojoDescriptor.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- MojoDescriptor.java 14 Jul 2004 04:27:25 -0000 1.3
+++ MojoDescriptor.java 19 Jul 2004 00:58:14 -0000 1.4
@@ -25,8 +25,8 @@
public class MojoDescriptor
{
- public static final String SINGLE_PASS_EXEC_STRATEGY = "single-pass";
- public static final String MULTI_PASS_EXEC_STRATEGY = "multi-pass";
+ public static final String SINGLE_PASS_EXEC_STRATEGY = "once-per-session";
+ public static final String MULTI_PASS_EXEC_STRATEGY = "always";
private String implementation;
@@ -186,6 +186,10 @@
this.goal = goal;
}
+ public boolean alwaysExecute() {
+ return MULTI_PASS_EXEC_STRATEGY.equals(executionStrategy);
+ }
+
public String getExecutionStrategy() {
return executionStrategy;
}
1.1 maven-components/maven-core/src/test/java/org/apache/maven/plugin/GoalDecorationAndResolutionTestPlugin.java
Index: GoalDecorationAndResolutionTestPlugin.java
===================================================================
/* Created on Jul 18, 2004 */
package org.apache.maven.plugin;
/**
* @author jdcasey
*/
public class GoalDecorationAndResolutionTestPlugin implements Plugin
{
private boolean executed = false;
public void execute(PluginExecutionRequest request, PluginExecutionResponse response) throws Exception {
this.executed = true;
}
public boolean executed() {
return executed;
}
}
1.5 +1 -0 maven-components/maven-core-it/integration-tests.txt
Index: integration-tests.txt
===================================================================
RCS file: /home/cvs/maven-components/maven-core-it/integration-tests.txt,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- integration-tests.txt 5 Jul 2004 16:53:15 -0000 1.4
+++ integration-tests.txt 19 Jul 2004 00:58:14 -0000 1.5
@@ -4,3 +4,4 @@
it0003
it0004
it0005
+it0006
1.1 maven-components/maven-core-it/it0006/.cvsignore
Index: .cvsignore
===================================================================
*~
*.log
target
*.ipr
*.iws
dist
target
.classpath
.project
1.1 maven-components/maven-core-it/it0006/pom.xml
Index: pom.xml
===================================================================
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>maven</groupId>
<artifactId>maven-core-it0006</artifactId>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<type>test</type>
</dependency>
</dependencies>
</project>
1.1 maven-components/maven-core-it/it0006/expected-results.txt
<<Binary file>>
1.1 maven-components/maven-core-it/it0006/goals.txt
Index: goals.txt
===================================================================
jar:jar
1.1 maven-components/maven-core-it/it0006/decorators.xml
Index: decorators.xml
===================================================================
<!--
/*
* Copyright 2001-2004 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.
*/
-->
<decorators>
<preGoal name="compiler:compile" attain="clean:clean"/>
<postGoal name="compiler:compile" attain="jar:install"/>
</decorators>
1.1 maven-components/maven-core/src/test/resources/META-INF/maven/plugin.xml
Index: plugin.xml
===================================================================
<plugin>
<id>decorTest</id>
<mojos>
<!-- Test main with preGoal and postGoal -->
<mojo>
<id>t1:preGoal</id>
<implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin</implementation>
<instantiationStrategy>singleton</instantiationStrategy>
</mojo>
<mojo>
<id>t1:main</id>
<implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin</implementation>
<instantiationStrategy>singleton</instantiationStrategy>
</mojo>
<mojo>
<id>t1:postGoal</id>
<implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin</implementation>
<instantiationStrategy>singleton</instantiationStrategy>
</mojo>
<!-- End of test -->
<!-- Test main with prereq -->
<mojo>
<id>t2:prereq</id>
<implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin</implementation>
<instantiationStrategy>singleton</instantiationStrategy>
</mojo>
<mojo>
<id>t2:main</id>
<implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin</implementation>
<instantiationStrategy>singleton</instantiationStrategy>
<prereqs>
<prereq>t2:prereq</prereq>
</prereqs>
</mojo>
<!-- End of test -->
<!-- Test main with prereq, preGoal and postGoal -->
<mojo>
<id>t3:preGoal</id>
<implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin</implementation>
<instantiationStrategy>singleton</instantiationStrategy>
</mojo>
<mojo>
<id>t3:prereq</id>
<implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin</implementation>
<instantiationStrategy>singleton</instantiationStrategy>
</mojo>
<mojo>
<id>t3:main</id>
<implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin</implementation>
<instantiationStrategy>singleton</instantiationStrategy>
<prereqs>
<prereq>t3:prereq</prereq>
</prereqs>
</mojo>
<mojo>
<id>t3:postGoal</id>
<implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin</implementation>
<instantiationStrategy>singleton</instantiationStrategy>
</mojo>
<!-- End of test -->
<!-- Test main with prereq which has preGoal and postGoal -->
<mojo>
<id>t4:prereq-preGoal</id>
<implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin</implementation>
<instantiationStrategy>singleton</instantiationStrategy>
</mojo>
<mojo>
<id>t4:prereq</id>
<implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin</implementation>
<instantiationStrategy>singleton</instantiationStrategy>
</mojo>
<mojo>
<id>t4:main</id>
<implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin</implementation>
<instantiationStrategy>singleton</instantiationStrategy>
<prereqs>
<prereq>t4:prereq</prereq>
</prereqs>
</mojo>
<mojo>
<id>t4:prereq-postGoal</id>
<implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin</implementation>
<instantiationStrategy>singleton</instantiationStrategy>
</mojo>
<!-- End of test -->
<!-- Test main with prereq and preGoal which has the same prereq -->
<mojo>
<id>t5:prereq</id>
<implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin</implementation>
<instantiationStrategy>singleton</instantiationStrategy>
</mojo>
<mojo>
<id>t5:preGoal</id>
<implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin</implementation>
<instantiationStrategy>singleton</instantiationStrategy>
<prereqs>
<prereq>t5:prereq</prereq>
</prereqs>
</mojo>
<mojo>
<id>t5:main</id>
<implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin</implementation>
<instantiationStrategy>singleton</instantiationStrategy>
<prereqs>
<prereq>t5:prereq</prereq>
</prereqs>
</mojo>
<!-- End of test -->
</mojos>
<dependencies/>
</plugin>
1.1 maven-components/maven-core-it/it0006/src/test/java/org/apache/maven/it0000/PersonTest.java
Index: PersonTest.java
===================================================================
package org.apache.maven.it0000;
import junit.framework.TestCase;
public class PersonTest
extends TestCase
{
public void testPerson()
{
Person person = new Person();
person.setName( "foo" );
assertEquals( "foo", person.getName() );
}
}
1.19 +4 -4 maven-components/maven-plugin/src/main/java/org/apache/maven/plugin/generator/AbstractGenerator.java
Index: AbstractGenerator.java
===================================================================
RCS file: /home/cvs/maven-components/maven-plugin/src/main/java/org/apache/maven/plugin/generator/AbstractGenerator.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- AbstractGenerator.java 14 Jul 2004 04:27:24 -0000 1.18
+++ AbstractGenerator.java 19 Jul 2004 00:58:14 -0000 1.19
@@ -56,7 +56,7 @@
public static final String GOAL_REQUIRES_DEPENDENCY_RESOLUTION = "requiresDependencyResolution";
- public static final String GOAL_SINGLE_EXECUTION_STRATEGY = "singleExecution";
+ public static final String GOAL_MULTI_EXECUTION_STRATEGY = "attainAlways";
protected abstract void processPluginDescriptors( MojoDescriptor[] pluginDescriptors, String destinationDirectory, Xpp3Dom pomDom )
throws Exception;
@@ -197,15 +197,15 @@
mojoDescriptor.setInstantiationStrategy( tag.getValue() );
}
- tag = javaClass.getTagByName( GOAL_SINGLE_EXECUTION_STRATEGY );
+ tag = javaClass.getTagByName( GOAL_MULTI_EXECUTION_STRATEGY );
if ( tag != null )
{
- mojoDescriptor.setExecutionStrategy( MojoDescriptor.SINGLE_PASS_EXEC_STRATEGY );
+ mojoDescriptor.setExecutionStrategy( MojoDescriptor.MULTI_PASS_EXEC_STRATEGY );
}
else
{
- mojoDescriptor.setExecutionStrategy( MojoDescriptor.MULTI_PASS_EXEC_STRATEGY );
+ mojoDescriptor.setExecutionStrategy( MojoDescriptor.SINGLE_PASS_EXEC_STRATEGY );
}
// ----------------------------------------------------------------------
1.12 +2 -2 maven-components/maven-core/src/main/java/org/apache/maven/lifecycle/MavenLifecycleContext.java
Index: MavenLifecycleContext.java
===================================================================
RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/lifecycle/MavenLifecycleContext.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- MavenLifecycleContext.java 14 Jul 2004 04:27:25 -0000 1.11
+++ MavenLifecycleContext.java 19 Jul 2004 00:58:14 -0000 1.12
@@ -60,7 +60,7 @@
pluginDependencies = new HashSet( );
}
-
+
// ----------------------------------------------------------------------
// Provide an easy way to lookup plexus components
// ----------------------------------------------------------------------
1.9 +49 -89 maven-components/maven-core/src/main/java/org/apache/maven/lifecycle/phase/GoalResolutionPhase.java
Index: GoalResolutionPhase.java
===================================================================
RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/lifecycle/phase/GoalResolutionPhase.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- GoalResolutionPhase.java 14 Jul 2004 04:27:25 -0000 1.8
+++ GoalResolutionPhase.java 19 Jul 2004 00:58:14 -0000 1.9
@@ -24,10 +24,14 @@
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.LinkedList;
import java.util.List;
import java.util.Set;
+import java.util.Stack;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
@@ -43,40 +47,12 @@
try
{
pluginManager = ( PluginManager ) context.getContainer( ).lookup( PluginManager.ROLE );
-
+
// First, start by retrieving the currently-requested goal.
- String goal = context.getMojoDescriptor( ).getId( );
-
- // Initialize the set we'll use to track goals which have already
- // been included.
- Set includedGoals = new HashSet( );
+ String goal = context.getMojoDescriptor( ).getId();
- // Retrieve the preGoals implied by this goal, with this goal appended
- // to the end of the list.
- List originalGoals = pluginManager.getGoals( goal );
+ List resolvedGoals = resolveTopLevel(goal, new HashSet(), new LinkedList(), context, pluginManager);
- // Initialize the results list.
- List resolvedGoals = new ArrayList( );
-
- // Iterate over each goal (original and those implied by prereq's)
- for ( Iterator it = originalGoals.iterator( ); it.hasNext( ); )
- {
- String preReq = ( String ) it.next( );
-
- MojoDescriptor descriptor = context.getMojoDescriptor( preReq );
-
- // If the mojo's execution strategy allows multiple execution,
- // or if we haven't seen this mojo yet, "resolve" its goal
- // decorators.
- if ( MojoDescriptor.MULTI_PASS_EXEC_STRATEGY.equals(
- descriptor.getExecutionStrategy( ) )
- || !includedGoals.contains( descriptor ) )
- {
- resolvedGoals.addAll( resolve( descriptor, context,
- includedGoals ) );
- }
- }
-
context.setResolvedGoals( resolvedGoals );
}
finally
@@ -85,68 +61,52 @@
}
}
- private List resolve( MojoDescriptor descriptor,
- MavenLifecycleContext context, Set includedGoals )
- {
- // Initialize results for this resolve call
- List result = new ArrayList( );
-
- String goal = descriptor.getId( );
- GoalDecoratorBindings decorators = context.getGoalDecoratorBindings( );
-
- // If the decorator bindings are null, don't bother
- if ( decorators != null )
- {
- // Otherwise, repeat the process for all pre-goals, with the added
- // ability to specify force-execute inside the preGoal descriptor.
- result.addAll( resolveAllAsDecorators( decorators.getPreGoals( goal ),
- context, includedGoals ) );
- }
-
- // The actual goal execution gets sandwiched between pre- and post-goals
- result.add( goal );
- includedGoals.add(goal);
-
- // If the decorator bindings are null, don't bother
- if ( decorators != null )
- {
- // Otherwise, repeat the process for all post-goals, with the added
- // ability to specify force-execute inside the postGoal descriptor.
- result.addAll( resolveAllAsDecorators( decorators.getPostGoals(
- goal ), context, includedGoals ) );
- }
-
- // Return all the goals, in order, that we resolved for the specified
- // input goal.
- return result;
+ private List resolveTopLevel(String goal, Set includedGoals, List results, MavenLifecycleContext context, PluginManager pluginManager) {
+
+ // Retrieve the prereqs-driven execution path for this goal, using the DAG.
+ List work = pluginManager.getGoals( goal );
+
+ // Reverse the original goals list to preserve encapsulation while decorating.
+ Collections.reverse(work);
+
+ return resolveWithPrereqs(work, includedGoals, results, context, pluginManager);
}
- private List resolveAllAsDecorators( List goals,
- MavenLifecycleContext context, Set includedGoals )
- {
- // Initialize the results for this call
- List result = new ArrayList( );
-
- // Iterate over each decorator, and if it qualifies, resolve it to the
- // results list.
- for ( Iterator it = goals.iterator( ); it.hasNext( ); )
- {
- GoalDecorator decorator = ( GoalDecorator ) it.next( );
- String preGoal = ( String ) decorator.getGoalToDecorate( );
-
- MojoDescriptor descriptor = context.getMojoDescriptor( preGoal );
+ private List resolveWithPrereqs(List work, Set includedGoals, List results, MavenLifecycleContext context, PluginManager pluginManager) {
+ if(!work.isEmpty()) {
+ String goal = (String)work.remove(0);
+
+ MojoDescriptor descriptor = context.getMojoDescriptor( goal );
- // NOTE: This adds a check to account for the ability to force
- // execution via the pre- or post-goal specification.
- if ( decorator.forceExecute( )
- || MojoDescriptor.MULTI_PASS_EXEC_STRATEGY.equals(
- descriptor.getExecutionStrategy( ) )
- || !includedGoals.contains( descriptor ) )
- {
- result.addAll( resolve( descriptor, context, includedGoals ) );
+ if(descriptor.alwaysExecute() || !includedGoals.contains(goal)) {
+ GoalDecoratorBindings bindings = context.getGoalDecoratorBindings();
+ if(bindings != null) {
+ List preGoals = bindings.getPreGoals(goal);
+
+ results = resolveGoalDecorators(preGoals, includedGoals, results, context, pluginManager);
+ }
+
+ results = resolveWithPrereqs(work, includedGoals, results, context, pluginManager);
+ includedGoals.add(goal);
+ results.add(goal);
+
+ if(bindings != null) {
+ List postGoals = bindings.getPostGoals(goal);
+ results = resolveGoalDecorators(postGoals, includedGoals, results, context, pluginManager);
+ }
}
}
+ return results;
+ }
- return result;
+ private List resolveGoalDecorators(List preGoals, Set includedGoals, List results, MavenLifecycleContext context, PluginManager pluginManager) {
+ for (Iterator it = preGoals.iterator(); it.hasNext();) {
+ GoalDecorator decorator = (GoalDecorator)it.next();
+ String goal = decorator.getDecoratorGoal();
+ resolveTopLevel(goal, includedGoals, results, context, pluginManager);
+ }
+
+ return results;
}
+
}
1.4 +2 -2 maven-components/maven-core/src/main/java/org/apache/maven/lifecycle/phase/GoalDecorationPhase.java
Index: GoalDecorationPhase.java
===================================================================
RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/lifecycle/phase/GoalDecorationPhase.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- GoalDecorationPhase.java 14 Jul 2004 04:27:25 -0000 1.3
+++ GoalDecorationPhase.java 19 Jul 2004 00:58:14 -0000 1.4
@@ -43,7 +43,7 @@
public class GoalDecorationPhase extends AbstractMavenLifecyclePhase
{
public static final String MAVEN_XML_DEFAULT_NAMESPACE = "mavenxml";
- public static final String MAVEN_SCRIPT = "maven.xml";
+ public static final String MAVEN_SCRIPT = "decorators.xml";
private GoalDecoratorBindings decorators;
private boolean decoratorsInitialized = false;
1.1 maven-components/maven-core-it/it0006/src/main/java/org/apache/maven/it0000/Person.java
Index: Person.java
===================================================================
package org.apache.maven.it0000;
public class Person
{
private String name;
public void setName( String name )
{
this.name = name;
}
public String getName()
{
return name;
}
}