o Removed GoalDecorationPhase, since goal decoration is now a part of the model

o Removed PluginDownloadPhase, since plugin resolution/download has to be a part of the prereq and pre/postGoal resolution, too
o Changed DefaultMaven to execute the session lifecycle, and the component wiring to likewise wire the DefaultMaven with a session lifecycle manager
o Removed the org.apache.maven.decoration package and its contents, since this is all in the model now
o Fixed the GoalResolutionPhase to verify each goal's plugin in turn as it resolves prereqs, preGoals and postGoals
o Fixed the GoalResolutionPhaseTest to work with the new resolution model
o Added a new createGoalExecutionContext to the MavenTestCase base class, to allow me to inject a MavenProject directly rather than a pom file
o Fixed the MavenLifecycleManagerTest to only expect 4 lifecycle phases, now than the plugin resolution and goal decoration phases are obsoleted
o All builds on local machine, but will depend on plexus-0.17.jar/pom and plexus-artifact-container-1.0-alpha-1.jar/pom to build on beaver
o I uploaded plexus-artifact-container-1.0-alpha-1.jar to ${plexus.home}/dist, but cannot upload POMs due to priveleges problem in poms dir.


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163007 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2004-08-26 04:40:02 +00:00
parent 24ce8263d9
commit a949eb66de
25 changed files with 399 additions and 1020 deletions

View File

@ -25,23 +25,22 @@ import java.util.Set;
*/
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
* @version $Id: DefaultArtifactHandlerManager.java,v 1.1.1.1 2004/08/09
* 18:37:32 jvanzyl Exp $
*/
public class DefaultArtifactHandlerManager
implements ArtifactHandlerManager
{
private Map artifactHandlers;
public ArtifactHandler getArtifactHandler( String type )
throws ArtifactHandlerNotFoundException
public ArtifactHandler getArtifactHandler( String type ) throws ArtifactHandlerNotFoundException
{
ArtifactHandler handler = (ArtifactHandler) artifactHandlers.get( type );
if ( handler == null )
{
throw new ArtifactHandlerNotFoundException(
"Artifact handler for type '" + type + "' cannot be found." );
throw new ArtifactHandlerNotFoundException( "Artifact handler for type '" + type + "' cannot be found." );
}
return handler;
@ -82,18 +81,12 @@ public class DefaultArtifactHandlerManager
{
ArtifactHandler handler = (ArtifactHandler) artifactHandlers.get( artifact.getType() );
return interpolateLayout( artifact.getGroupId(),
artifact.getArtifactId(),
artifact.getVersion(),
handler.directory(),
handler.extension() );
return interpolateLayout( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), handler
.directory(), handler.extension() );
}
private String interpolateLayout( String groupId,
String artifactId,
String version,
String directory,
String extension )
private String interpolateLayout( String groupId, String artifactId, String version, String directory,
String extension )
{
String layout = getLayout();
@ -109,4 +102,4 @@ public class DefaultArtifactHandlerManager
return layout;
}
}
}

View File

@ -1,23 +0,0 @@
<!--
/*
* 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>

View File

@ -1 +1 @@
jar:jar
compiler:compile

View File

@ -11,4 +11,18 @@
<type>test</type>
</dependency>
</dependencies>
<preGoals>
<preGoal>
<name>compiler:compile</name>
<attain>clean:clean</attain>
</preGoal>
</preGoals>
<postGoals>
<postGoal>
<name>compiler:compile</name>
<attain>jar:jar</attain>
</postGoal>
</postGoals>
</project>

View File

@ -52,17 +52,6 @@
<artifactId>ognl</artifactId>
<version>2.5.1</version>
</dependency>
<!-- Used to support maven.xml script and goal decorating in general. -->
<dependency>
<groupId>marmalade</groupId>
<artifactId>marmalade-core</artifactId>
<version>0.1</version>
</dependency>
<dependency>
<groupId>marmalade</groupId>
<artifactId>marmalade-el-ognl</artifactId>
<version>0.1</version>
</dependency>
<!-- Wagon -->
<dependency>
<groupId>maven</groupId>

View File

@ -1,19 +1,14 @@
package org.apache.maven;
/*
* 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.
* 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 org.apache.maven.artifact.repository.ArtifactRepository;
@ -23,6 +18,7 @@ import org.apache.maven.lifecycle.goal.MavenGoalExecutionContext;
import org.apache.maven.lifecycle.goal.MavenGoalPhaseManager;
import org.apache.maven.lifecycle.goal.GoalNotFoundException;
import org.apache.maven.lifecycle.session.MavenSession;
import org.apache.maven.lifecycle.session.MavenSessionPhaseManager;
import org.apache.maven.plugin.PluginManager;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.project.MavenProject;
@ -65,7 +61,7 @@ public class DefaultMaven
private PluginManager pluginManager;
private MavenGoalPhaseManager lifecycleManager;
private MavenSessionPhaseManager lifecycleManager;
private MavenProjectBuilder projectBuilder;
@ -75,20 +71,18 @@ public class DefaultMaven
// Project execution
// ----------------------------------------------------------------------
public ExecutionResponse execute( List goals )
throws GoalNotFoundException
public ExecutionResponse execute( List goals ) throws GoalNotFoundException
{
return execute( (MavenProject) null, goals );
}
public ExecutionResponse execute( File projectFile, List goals )
throws ProjectBuildingException, GoalNotFoundException
public ExecutionResponse execute( File projectFile, List goals ) throws ProjectBuildingException,
GoalNotFoundException
{
return execute( getProject( projectFile ), goals );
}
public ExecutionResponse execute( MavenProject project, List goals )
throws GoalNotFoundException
public ExecutionResponse execute( MavenProject project, List goals ) throws GoalNotFoundException
{
Date fullStop;
@ -96,57 +90,35 @@ public class DefaultMaven
ExecutionResponse response = new ExecutionResponse();
MavenSession session = new MavenSession( container,
pluginManager,
project,
getLocalRepository(),
goals );
MavenSession session = new MavenSession( container, pluginManager, project, getLocalRepository(), goals );
for ( Iterator iterator = goals.iterator(); iterator.hasNext(); )
try
{
String goal = (String) iterator.next();
lifecycleManager.execute( session );
}
catch ( Exception e )
{
response.setException( e );
MavenGoalExecutionContext context;
try
if ( logResults )
{
context = new MavenGoalExecutionContext( session, getMojoDescriptor( goal ) );
line();
context.setGoalName( goal );
getLogger().error( "BUILD ERROR" );
lifecycleManager.execute( context );
line();
if ( context.isExecutionFailure() )
{
response.setExecutionFailure( context.getMojoDescriptor().getId(), context.getFailureResponse() );
getLogger().error( "Cause: ", e );
break;
}
line();
stats( fullStart, new Date() );
line();
}
catch ( Exception e )
{
response.setException( e );
if ( logResults )
{
line();
getLogger().error( "BUILD ERROR" );
line();
getLogger().error( "Cause: ", e );
line();
stats( fullStart, new Date() );
line();
}
// An exception is a failure
return response;
}
// An exception is a failure
return response;
}
fullStop = new Date();
@ -204,7 +176,8 @@ public class DefaultMaven
Runtime r = Runtime.getRuntime();
getLogger().info( "Final Memory: " + ( ( r.totalMemory() - r.freeMemory() ) / mb ) + "M/" + ( r.totalMemory() / mb ) + "M" );
getLogger().info(
"Final Memory: " + ((r.totalMemory() - r.freeMemory()) / mb) + "M/" + (r.totalMemory() / mb) + "M" );
}
@ -217,8 +190,8 @@ public class DefaultMaven
// Reactor execution
// ----------------------------------------------------------------------
public ExecutionResponse executeReactor( String goals, String includes, String excludes )
throws ReactorException, GoalNotFoundException
public ExecutionResponse executeReactor( String goals, String includes, String excludes ) throws ReactorException,
GoalNotFoundException
{
List projects = new ArrayList();
@ -298,8 +271,7 @@ public class DefaultMaven
// Project building
// ----------------------------------------------------------------------
public MavenProject getProject( File project )
throws ProjectBuildingException
public MavenProject getProject( File project ) throws ProjectBuildingException
{
if ( project.exists() )
{
@ -316,8 +288,7 @@ public class DefaultMaven
// Reactor
// ----------------------------------------------------------------------
public List getSortedProjects( List projects )
throws Exception
public List getSortedProjects( List projects ) throws Exception
{
return projectBuilder.getSortedProjects( projects );
}
@ -361,8 +332,7 @@ public class DefaultMaven
// Lifecylce Management
// ----------------------------------------------------------------------
public void contextualize( Context context )
throws ContextException
public void contextualize( Context context ) throws ContextException
{
container = (ArtifactEnabledContainer) context.get( PlexusConstants.PLEXUS_KEY );
}
@ -393,9 +363,8 @@ public class DefaultMaven
//
// ----------------------------------------------------------------------
public void booty()
throws Exception
public void booty() throws Exception
{
pluginManager.setLocalRepository( getLocalRepository() );
}
}
}

View File

@ -1,39 +0,0 @@
/* Created on Apr 6, 2004 */
package org.apache.maven.decoration;
/**
* Default implementation of a goal decorator.
*
* @author <a href="mailto:jdcasey@commonjava.org">John Casey</a>
*/
public class DefaultGoalDecorator implements GoalDecorator
{
private String goal;
private String decoratorGoal;
public DefaultGoalDecorator( String goal, String decoratorGoal )
{
this.goal = goal;
this.decoratorGoal = decoratorGoal;
}
public String getGoalToDecorate()
{
return goal;
}
public String getDecoratorGoal()
{
return decoratorGoal;
}
public String toString()
{
return "DefaultGoalDecorator[decorate: " + goal +
" with: " + decoratorGoal + "]";
}
}

View File

@ -1,74 +0,0 @@
/* Created on Jul 2, 2004 */
package org.apache.maven.decoration;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
import java.io.IOException;
import java.io.Reader;
/**
* @author jdcasey
*/
public class GoalDecorationParser {
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";
public static final String NAME_ATTRIBUTE = "name";
public static final String ATTAIN_ATTRIBUTE = "attain";
public GoalDecorationParser() {
}
public GoalDecoratorBindings parse(Reader reader) throws XmlPullParserException, IOException {
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
XmlPullParser parser = factory.newPullParser();
parser.setInput(reader);
GoalDecoratorBindings bindings = null;
int eventType = parser.getEventType();
while(eventType != XmlPullParser.END_DOCUMENT) {
if(eventType == XmlPullParser.START_TAG) {
String tagName = parser.getName();
if(ROOT_TAG.equals(tagName)) {
bindings = new GoalDecoratorBindings();
String defaultGoal = parser.getAttributeValue("", DEFAULT_GOAL_ATTRIBUTE);
if(defaultGoal != null && defaultGoal.length() > 0) {
bindings.setDefaultGoal(defaultGoal);
}
}
else if(PREGOAL_TAG.equals(tagName)) {
String name = parser.getAttributeValue("", NAME_ATTRIBUTE);
String attain = parser.getAttributeValue("", ATTAIN_ATTRIBUTE);
DefaultGoalDecorator decorator = new DefaultGoalDecorator(name, attain);
bindings.addPreGoal(decorator);
}
else if(POSTGOAL_TAG.equals(tagName)) {
String name = parser.getAttributeValue("", NAME_ATTRIBUTE);
String attain = parser.getAttributeValue("", ATTAIN_ATTRIBUTE);
DefaultGoalDecorator decorator = new DefaultGoalDecorator(name, attain);
bindings.addPostGoal(decorator);
}
else {
throw new IllegalArgumentException(tagName + " is not allowed.");
}
}
eventType = parser.next();
}
return bindings;
}
}

View File

@ -1,23 +0,0 @@
/* Created on Apr 5, 2004 */
package org.apache.maven.decoration;
/**
* Represents a decorator which executes around the main execution of a goal, but which
* fits outside the DAG, since it (a) cannot have prereqs, and (b) should decorate the execution
* of all prereqs of the goal, to encapsulate the entire process.
*
* @author <a href="mailto:jdcasey@commonjava.org">John Casey</a>
*/
public interface GoalDecorator
{
/** The goal to which this decorator is bound. */
String getGoalToDecorate();
/** The goal to execute when this decorator is triggered by execution of the bound goal target.
*/
String getDecoratorGoal();
}

View File

@ -1,83 +0,0 @@
/* Created on Apr 9, 2004 */
package org.apache.maven.decoration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author jdcasey
*/
public class GoalDecoratorBindings
{
private Map preGoals = new HashMap();
private Map postGoals = new HashMap();
private String defaultGoal = "compiler:compile";
public GoalDecoratorBindings()
{
}
public void addPreGoal( GoalDecorator decorator )
{
addGoalDecorator( decorator, preGoals );
}
public void addPostGoal( GoalDecorator decorator )
{
addGoalDecorator( decorator, postGoals );
}
public List getPreGoals( String goal )
{
List result = (List) preGoals.get( goal );
if ( result == null )
{
result = Collections.EMPTY_LIST;
}
return Collections.unmodifiableList( result );
}
public List getPostGoals( String goal )
{
List result = (List) postGoals.get( goal );
if ( result == null )
{
result = Collections.EMPTY_LIST;
}
return Collections.unmodifiableList( result );
}
private void addGoalDecorator( GoalDecorator decorator, Map decoratorMap )
{
String goal = decorator.getGoalToDecorate();
List decorators = (List) decoratorMap.get( goal );
if ( decorators == null )
{
decorators = new ArrayList();
decoratorMap.put( goal, decorators );
}
decorators.add( decorator );
}
/**
* @param defGoal
*/
public void setDefaultGoal( String defGoal )
{
this.defaultGoal = defGoal;
}
public String getDefaultGoal()
{
return defaultGoal;
}
}

View File

@ -1,7 +1,6 @@
package org.apache.maven.lifecycle.goal;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.decoration.GoalDecoratorBindings;
import org.apache.maven.lifecycle.session.MavenSession;
import org.apache.maven.plugin.FailureResponse;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
@ -12,8 +11,9 @@ import java.util.List;
import java.util.Set;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
* @version $Id: MavenGoalExecutionContext.java,v 1.1 2004/08/15 15:01:50
* jvanzyl Exp $
*/
public class MavenGoalExecutionContext
{
@ -27,13 +27,13 @@ public class MavenGoalExecutionContext
private List resolvedGoals;
private GoalDecoratorBindings goalDecoratorBindings;
// private GoalDecoratorBindings goalDecoratorBindings;
private String goalName;
public MavenGoalExecutionContext( MavenSession session, MojoDescriptor goal )
{
this.session = session;
this.session = session;
this.mojoDescriptor = goal;
}
@ -62,14 +62,12 @@ public class MavenGoalExecutionContext
return session.getRemoteRepositories();
}
public Object lookup( String role )
throws ComponentLookupException
public Object lookup( String role ) throws ComponentLookupException
{
return session.lookup( role );
}
public Object lookup( String role, String hint )
throws ComponentLookupException
public Object lookup( String role, String hint ) throws ComponentLookupException
{
return session.lookup( role, hint );
}
@ -125,7 +123,7 @@ public class MavenGoalExecutionContext
public boolean isExecutionFailure()
{
return ( failedGoal != null );
return (failedGoal != null);
}
public String getFailedGoal()
@ -148,16 +146,6 @@ public class MavenGoalExecutionContext
this.failureResponse = failureResponse;
}
public GoalDecoratorBindings getGoalDecoratorBindings()
{
return goalDecoratorBindings;
}
public void setGoalDecoratorBindings( GoalDecoratorBindings goalDecoratorBindings )
{
this.goalDecoratorBindings = goalDecoratorBindings;
}
public String getGoalName()
{
return goalName;
@ -167,4 +155,4 @@ public class MavenGoalExecutionContext
{
this.goalName = goalName;
}
}
}

View File

@ -1,46 +0,0 @@
package org.apache.maven.lifecycle.goal.phase;
/*
* 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 org.apache.maven.decoration.GoalDecorationParser;
import org.apache.maven.decoration.GoalDecoratorBindings;
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.project.MavenProject;
import org.xmlpull.v1.XmlPullParserException;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @author <a href="mailto:jdcasey@commonjava.org">John Casey</a>
* @version $Id$
*/
public class GoalDecorationPhase extends AbstractMavenGoalPhase
{
public void execute( MavenGoalExecutionContext context )
throws GoalExecutionException
{
}
}

View File

@ -1,6 +1,5 @@
package org.apache.maven.lifecycle.goal.phase;
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
@ -18,12 +17,13 @@ package org.apache.maven.lifecycle.goal.phase;
*/
import org.apache.maven.lifecycle.goal.GoalNotFoundException;
import org.apache.maven.decoration.GoalDecorator;
import org.apache.maven.decoration.GoalDecoratorBindings;
import org.apache.maven.lifecycle.goal.AbstractMavenGoalPhase;
import org.apache.maven.lifecycle.goal.MavenGoalExecutionContext;
import org.apache.maven.lifecycle.goal.MavenGoalExecutionContext;
import org.apache.maven.lifecycle.goal.GoalExecutionException;
import org.apache.maven.model.GoalDecorator;
import org.apache.maven.model.PostGoal;
import org.apache.maven.model.PreGoal;
import org.apache.maven.plugin.PluginManager;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
@ -35,31 +35,37 @@ import java.util.List;
import java.util.Set;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
* @version $Id$
*/
public class GoalResolutionPhase extends AbstractMavenGoalPhase
public class GoalResolutionPhase
extends AbstractMavenGoalPhase
{
public void execute( MavenGoalExecutionContext context )
throws GoalExecutionException
public void execute( MavenGoalExecutionContext context ) throws GoalExecutionException
{
PluginManager pluginManager = context.getSession().getPluginManager();
try
{
// First, start by retrieving the currently-requested goal.
MojoDescriptor goalDescriptor = context.getMojoDescriptor();
if ( goalDescriptor == null )
{
throw new GoalNotFoundException( context.getGoalName() );
}
String goal = goalDescriptor.getId();
String goal = context.getGoalName();
List resolvedGoals = resolveTopLevel( goal, new HashSet(), new LinkedList(), context, pluginManager );
context.setResolvedGoals( resolvedGoals );
if ( goal.indexOf( ":" ) < 0 )
{
goal = context.getProject().getType() + ":" + goal;
}
MojoDescriptor md = pluginManager.getMojoDescriptor( goal );
context.setMojoDescriptor( md );
}
catch ( Exception e )
{
throw new GoalExecutionException( "Error resolving goals: ", e );
}
finally
{
@ -67,19 +73,26 @@ public class GoalResolutionPhase extends AbstractMavenGoalPhase
}
}
private List resolveTopLevel( String goal, Set includedGoals, List results, MavenGoalExecutionContext context, PluginManager pluginManager )
private List resolveTopLevel( String goal, Set includedGoals, List results, MavenGoalExecutionContext context,
PluginManager pluginManager ) throws Exception
{
// Retrieve the prereqs-driven execution path for this goal, using the DAG.
// Ensure that the plugin for this goal is installed.
pluginManager.verifyPluginForGoal( goal );
// 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.
// Reverse the original goals list to preserve encapsulation while
// decorating.
Collections.reverse( work );
return resolveWithPrereqs( work, includedGoals, results, context, pluginManager );
}
private List resolveWithPrereqs( List work, Set includedGoals, List results, MavenGoalExecutionContext context, PluginManager pluginManager )
private List resolveWithPrereqs( List work, Set includedGoals, List results, MavenGoalExecutionContext context,
PluginManager pluginManager ) throws Exception
{
if ( !work.isEmpty() )
{
@ -89,38 +102,53 @@ public class GoalResolutionPhase extends AbstractMavenGoalPhase
if ( descriptor.alwaysExecute() || !includedGoals.contains( goal ) )
{
GoalDecoratorBindings bindings = context.getGoalDecoratorBindings();
if ( bindings != null )
List preGoals = new LinkedList();
List allPreGoals = context.getProject().getModel().getPreGoals();
for ( Iterator it = allPreGoals.iterator(); it.hasNext(); )
{
List preGoals = bindings.getPreGoals( goal );
results = resolveGoalDecorators( preGoals, includedGoals, results, context, pluginManager );
PreGoal preGoal = (PreGoal) it.next();
if ( goal.equals( preGoal.getName() ) )
{
preGoals.add( preGoal.getAttain() );
}
}
results = resolveGoalDecorators( goal, true, 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 );
}
results = resolveGoalDecorators( goal, false, includedGoals, results, context, pluginManager );
}
}
return results;
}
private List resolveGoalDecorators( List preGoals, Set includedGoals, List results, MavenGoalExecutionContext context, PluginManager pluginManager )
private List resolveGoalDecorators( String baseGoal, boolean usePreGoals, Set includedGoals, List results,
MavenGoalExecutionContext context, PluginManager pluginManager ) throws Exception
{
for ( Iterator it = preGoals.iterator(); it.hasNext(); )
List decorators = null;
if ( usePreGoals )
{
decorators = context.getProject().getModel().getPreGoals();
}
else
{
decorators = context.getProject().getModel().getPostGoals();
}
for ( Iterator it = decorators.iterator(); it.hasNext(); )
{
GoalDecorator decorator = (GoalDecorator) it.next();
String goal = decorator.getDecoratorGoal();
resolveTopLevel( goal, includedGoals, results, context, pluginManager );
if ( baseGoal.equals( decorator.getName() ) )
{
String goal = decorator.getAttain();
resolveTopLevel( goal, includedGoals, results, context, pluginManager );
}
}
return results;
}
}
}

View File

@ -1,82 +0,0 @@
package org.apache.maven.lifecycle.goal.phase;
/*
* 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 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.PluginManager;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
/**
* From the name of the goal we can determine the plugin that houses the
* goal. The goal will be in the form pluginId:goalName so we take the pluginId
* portion of the name and with that we can determine if the plugin is installed
* or not. If the plugin is not installed then we can use the pluginId to retrieve
* the plugin and install it for use.
*
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public class PluginDownloadPhase
extends AbstractMavenGoalPhase
{
public void execute( MavenGoalExecutionContext context )
throws GoalExecutionException
{
PluginManager pluginManager = null;
try
{
pluginManager = (PluginManager) context.lookup( PluginManager.ROLE );
}
catch ( ComponentLookupException e )
{
throw new GoalExecutionException( "Error looking up plugin manager: ", e );
}
String goalName = context.getGoalName();
// m2 install
// install the install plugin
// if this is a dispatcher goal then turn install in to type:install
// then the appropriate prereqs will be called
// would be good to let the plugin manager deal with all of this
try
{
pluginManager.verifyPluginForGoal( goalName );
}
catch ( Exception e )
{
throw new GoalExecutionException( "Error verifying plugin: ", e );
}
if ( goalName.indexOf( ":" ) < 0 )
{
goalName = context.getProject().getType() + ":" + goalName;
}
MojoDescriptor md = pluginManager.getMojoDescriptor( goalName );
context.setMojoDescriptor( md );
}
}

View File

@ -25,14 +25,13 @@ import org.apache.maven.lifecycle.session.MavenSession;
import java.util.Iterator;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
* @version $Id$
*/
public class GoalExecutionPhase
extends AbstractMavenSessionPhase
{
public void execute( MavenSession session )
throws Exception
public void execute( MavenSession session ) throws Exception
{
MavenGoalPhaseManager lifecycleManager = (MavenGoalPhaseManager) session.lookup( MavenGoalPhaseManager.ROLE );
@ -58,4 +57,4 @@ public class GoalExecutionPhase
}
}
}
}
}

View File

@ -1,19 +1,14 @@
package org.apache.maven.plugin;
/*
* 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.
* 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 org.apache.maven.artifact.Artifact;
@ -111,8 +106,7 @@ public class DefaultPluginManager
private Set pluginsInProcess = new HashSet();
public void processPluginDescriptor( MavenPluginDescriptor mavenPluginDescriptor )
throws CycleDetectedException
public void processPluginDescriptor( MavenPluginDescriptor mavenPluginDescriptor ) throws CycleDetectedException
{
if ( pluginsInProcess.contains( mavenPluginDescriptor.getPluginId() ) )
{
@ -152,8 +146,7 @@ public class DefaultPluginManager
}
}
private boolean processEdge( String mojoId, String prereq )
throws CycleDetectedException
private boolean processEdge( String mojoId, String prereq ) throws CycleDetectedException
{
dag.addEdge( mojoId, prereq );
@ -191,7 +184,7 @@ public class DefaultPluginManager
{
ComponentSetDescriptor componentSetDescriptor = event.getComponentSetDescriptor();
if ( !( componentSetDescriptor instanceof MavenPluginDescriptor ) )
if ( !(componentSetDescriptor instanceof MavenPluginDescriptor) )
{
return;
}
@ -214,7 +207,7 @@ public class DefaultPluginManager
public boolean isPluginInstalled( String pluginId )
{
return ( pluginDescriptors.get( pluginId ) != null );
return (pluginDescriptors.get( pluginId ) != null);
}
private String getPluginId( String goalName )
@ -227,14 +220,14 @@ public class DefaultPluginManager
return goalName;
}
public void verifyPluginForGoal( String goalName )
throws Exception
public void verifyPluginForGoal( String goalName ) throws Exception
{
String pluginId = getPluginId( goalName );
if ( !isPluginInstalled( pluginId ) )
{
//!! This is entirely crappy. We need a better naming for plugin artifact ids and
//!! This is entirely crappy. We need a better naming for plugin
// artifact ids and
// we definitely need better version extraction support.
String artifactId = "maven-" + pluginId + "-plugin";
@ -244,47 +237,43 @@ public class DefaultPluginManager
Artifact pluginArtifact = new DefaultArtifact( "maven", artifactId, version, "plugin", "jar" );
addPlugin( pluginArtifact );
// Now, we need to resolve the plugins for this goal's prereqs.
MojoDescriptor mojoDescriptor = getMojoDescriptor( goalName );
List prereqs = mojoDescriptor.getPrereqs();
if ( prereqs != null )
{
for ( Iterator it = prereqs.iterator(); it.hasNext(); )
{
String prereq = (String) it.next();
verifyPluginForGoal( prereq );
}
}
}
}
public void addPlugin( Artifact pluginArtifact )
throws Exception
public void addPlugin( Artifact pluginArtifact ) throws Exception
{
artifactResolver = (ArtifactResolver) container.lookup( ArtifactResolver.ROLE );
MavenMetadataSource sr = new MavenMetadataSource( remotePluginRepositories,
localRepository,
artifactResolver );
MavenMetadataSource sr = new MavenMetadataSource( remotePluginRepositories, localRepository, artifactResolver );
String[] excludes = new String[]
{
"maven-core",
"maven-artifact",
"maven-model",
"maven-plugin",
"plexus",
"xstream",
"xpp3",
"classworlds",
"ognl"
};
String[] excludes = new String[] { "maven-core", "maven-artifact", "maven-model", "maven-plugin", "plexus",
"xstream", "xpp3", "classworlds", "ognl" };
container.addComponent( pluginArtifact,
artifactResolver,
remotePluginRepositories,
localRepository,
sr,
excludes );
container.addComponent( pluginArtifact, artifactResolver, remotePluginRepositories, localRepository, sr,
excludes );
}
public void contextualize( Context context )
throws ContextException
public void contextualize( Context context ) throws ContextException
{
container = (ArtifactEnabledContainer) context.get( PlexusConstants.PLEXUS_KEY );
}
public void initialize()
throws Exception
public void initialize() throws Exception
{
//!! move this to be configurable from the Maven component
remotePluginRepositories = new HashSet();
@ -303,4 +292,3 @@ public class DefaultPluginManager
}
}

View File

@ -14,7 +14,7 @@
<role>org.codehaus.plexus.i18n.I18N</role>
</requirement>
<requirement>
<role>org.apache.maven.lifecycle.goal.MavenGoalPhaseManager</role>
<role>org.apache.maven.lifecycle.session.MavenSessionPhaseManager</role>
</requirement>
</requirements>
</component>
@ -30,12 +30,7 @@
<implementation>org.apache.maven.lifecycle.session.DefaultMavenSessionPhaseManager</implementation>
<configuration>
<lifecycle-phases>
<lifecycle-phase implementation="org.apache.maven.lifecycle.goal.phase.PluginDownloadPhase"/>
<lifecycle-phase implementation="org.apache.maven.lifecycle.goal.phase.GoalDecorationPhase"/>
<lifecycle-phase implementation="org.apache.maven.lifecycle.goal.phase.GoalResolutionPhase"/>
<lifecycle-phase implementation="org.apache.maven.lifecycle.goal.phase.DependencyResolutionPhase"/>
<lifecycle-phase implementation="org.apache.maven.lifecycle.goal.phase.DependencyDownloadPhase"/>
<lifecycle-phase implementation="org.apache.maven.lifecycle.goal.phase.GoalAttainmentPhase"/>
<lifecycle-phase implementation="org.apache.maven.lifecycle.session.phase.GoalExecutionPhase"/>
</lifecycle-phases>
</configuration>
</component>
@ -44,8 +39,6 @@
<implementation>org.apache.maven.lifecycle.goal.DefaultMavenGoalPhaseManager</implementation>
<configuration>
<lifecycle-phases>
<lifecycle-phase implementation="org.apache.maven.lifecycle.goal.phase.PluginDownloadPhase"/>
<lifecycle-phase implementation="org.apache.maven.lifecycle.goal.phase.GoalDecorationPhase"/>
<lifecycle-phase implementation="org.apache.maven.lifecycle.goal.phase.GoalResolutionPhase"/>
<lifecycle-phase implementation="org.apache.maven.lifecycle.goal.phase.DependencyResolutionPhase"/>
<lifecycle-phase implementation="org.apache.maven.lifecycle.goal.phase.DependencyDownloadPhase"/>

View File

@ -33,7 +33,7 @@ import java.util.ArrayList;
import java.util.List;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
* @version $Id$
*/
public class MavenTestCase
@ -43,18 +43,32 @@ public class MavenTestCase
protected MavenProjectBuilder projectBuilder;
protected void setUp()
throws Exception
protected String testRepoUrl;
protected void setUp() throws Exception
{
super.setUp();
File testRepoLocation = new File( "target/repo" );
if ( !testRepoLocation.exists() )
{
testRepoLocation.mkdirs();
}
testRepoUrl = testRepoLocation.toURL().toExternalForm();
testRepoUrl = testRepoUrl.substring( 0, testRepoUrl.length() - 1 );
pluginManager = (PluginManager) lookup( PluginManager.ROLE );
projectBuilder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE );
}
protected void customizeContext()
throws Exception
protected String getTestRepoURL()
{
return testRepoUrl;
}
protected void customizeContext() throws Exception
{
ClassWorld classWorld = new ClassWorld();
@ -64,31 +78,28 @@ public class MavenTestCase
getContainer().addContextValue( "maven.home", new File( getBasedir(), "target/maven.home" ).getPath() );
getContainer().addContextValue( "maven.home.local", new File( getBasedir(), "target/maven.home.local" ).getPath() );
getContainer().addContextValue( "maven.home.local",
new File( getBasedir(), "target/maven.home.local" ).getPath() );
}
protected MavenGoalExecutionContext createGoalExecutionContext()
throws Exception
protected MavenGoalExecutionContext createGoalExecutionContext() throws Exception
{
return createGoalExecutionContext( null, null );
}
protected MavenGoalExecutionContext createGoalExecutionContext( File pom )
throws Exception
protected MavenGoalExecutionContext createGoalExecutionContext( File pom ) throws Exception
{
return createGoalExecutionContext( pom, null );
}
protected MavenGoalExecutionContext createGoalExecutionContext( String goal )
throws Exception
protected MavenGoalExecutionContext createGoalExecutionContext( String goal ) throws Exception
{
return createGoalExecutionContext( null, goal );
}
protected MavenGoalExecutionContext createGoalExecutionContext( File pom, String goal )
throws Exception
protected MavenGoalExecutionContext createGoalExecutionContext( File pom, String goal ) throws Exception
{
ArtifactRepository localRepository = new ArtifactRepository( "local", "file://" );
ArtifactRepository localRepository = new ArtifactRepository( "local", testRepoUrl );
MavenProject project;
@ -103,12 +114,20 @@ public class MavenTestCase
project = projectBuilder.build( f, localRepository );
}
return createGoalExecutionContext( project, localRepository, goal );
}
protected MavenGoalExecutionContext createGoalExecutionContext( MavenProject project,
ArtifactRepository localRepository, String goal )
{
project.setProperty( "foo", "bar" );
List goals = new ArrayList();
MavenSession session = new MavenSession( getContainer(), pluginManager, project, localRepository, goals );
pluginManager.setLocalRepository( localRepository );
MojoDescriptor descriptor;
if ( goal != null )
@ -124,4 +143,4 @@ public class MavenTestCase
return context;
}
}
}

View File

@ -1,43 +0,0 @@
/* 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());
}
}

View File

@ -1,88 +0,0 @@
/* 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);
}
}

View File

@ -1,92 +0,0 @@
/* 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());
}
}

View File

@ -6,19 +6,19 @@ import org.apache.maven.lifecycle.goal.MavenGoalPhaseManager;
import java.util.List;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
* @version $Id: MavenLifecycleManagerTest.java,v 1.2 2004/08/15 15:01:51
* jvanzyl Exp $
*/
public class MavenLifecycleManagerTest
extends MavenTestCase
{
public void testMavenLifecycleManager()
throws Exception
public void testMavenLifecycleManager() throws Exception
{
MavenGoalPhaseManager mlm = (MavenGoalPhaseManager) lookup( MavenGoalPhaseManager.ROLE );
List lifecyclePhases = mlm.getLifecyclePhases();
assertEquals( 6, lifecyclePhases.size() );
assertEquals( 4, lifecyclePhases.size() );
}
}
}

View File

@ -1,13 +1,19 @@
/* Created on Jul 14, 2004 */
package org.apache.maven.lifecycle.goal.phase;
import org.apache.maven.decoration.DefaultGoalDecorator;
import org.apache.maven.decoration.GoalDecoratorBindings;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.lifecycle.goal.MavenGoalExecutionContext;
import org.apache.maven.model.Model;
import org.apache.maven.model.PostGoal;
import org.apache.maven.model.PreGoal;
import org.apache.maven.project.MavenProject;
import org.apache.maven.MavenTestCase;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
@ -19,35 +25,37 @@ public class GoalResolutionPhaseTest
extends MavenTestCase
{
/*
<!-- 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
* <!-- Test main with preGoal and postGoal --> <mojo>
* <id>resolveTest:t1-preGoal </id>
* <implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin
* </implementation> <instantiationStrategy>singleton
* </instantiationStrategy> </mojo> <mojo> <id>resolveTest:t1-main </id>
* <implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin
* </implementation> <instantiationStrategy>singleton
* </instantiationStrategy> </mojo> <mojo> <id>resolveTest: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";
String mainGoal = "resolveTest:t1-main";
String preGoal = "resolveTest:t1-preGoal";
String postGoal = "resolveTest:t1-postGoal";
GoalDecoratorBindings bindings = new GoalDecoratorBindings();
PreGoal pg = new PreGoal();
pg.setAttain( preGoal );
pg.setName( mainGoal );
bindings.addPreGoal( new DefaultGoalDecorator( mainGoal, preGoal ) );
bindings.addPostGoal( new DefaultGoalDecorator( mainGoal, postGoal ) );
List preGoals = new LinkedList();
preGoals.add( pg );
PostGoal pog = new PostGoal();
pog.setAttain( postGoal );
pog.setName( mainGoal );
List postGoals = new LinkedList();
postGoals.add( pog );
Map messages = new TreeMap();
@ -61,33 +69,23 @@ public class GoalResolutionPhaseTest
order.add( mainGoal );
order.add( postGoal );
runTest( mainGoal, bindings, order, messages );
runTest( mainGoal, preGoals, postGoals, 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
* <!-- Test main with prereq --> <mojo> <id>resolveTest:t2-prereq </id>
* <implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin
* </implementation> <instantiationStrategy>singleton
* </instantiationStrategy> </mojo> <mojo> <id>resolveTest:t2-main </id>
* <implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin
* </implementation> <instantiationStrategy>singleton
* </instantiationStrategy> <prereqs> <prereq>resolveTest: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();
String mainGoal = "resolveTest:t2-main";
String prereq = "resolveTest:t2-prereq";
Map messages = new TreeMap();
@ -99,48 +97,46 @@ public class GoalResolutionPhaseTest
order.add( prereq );
order.add( mainGoal );
runTest( mainGoal, bindings, order, messages );
runTest( mainGoal, Collections.EMPTY_LIST, Collections.EMPTY_LIST, 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
* <!-- Test main with prereq, preGoal and postGoal --> <mojo>
* <id>resolveTest:t3-preGoal </id>
* <implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin
* </implementation> <instantiationStrategy>singleton
* </instantiationStrategy> </mojo> <mojo> <id>resolveTest:t3-prereq </id>
* <implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin
* </implementation> <instantiationStrategy>singleton
* </instantiationStrategy> </mojo> <mojo> <id>resolveTest:t3-main </id>
* <implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin
* </implementation> <instantiationStrategy>singleton
* </instantiationStrategy> <prereqs> <prereq>resolveTest:t3-prereq
* </prereq> </prereqs> </mojo> <mojo> <id>resolveTest: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";
String mainGoal = "resolveTest:t3-main";
String prereq = "resolveTest:t3-prereq";
String preGoal = "resolveTest:t3-preGoal";
String postGoal = "resolveTest:t3-postGoal";
GoalDecoratorBindings bindings = new GoalDecoratorBindings();
PreGoal pg = new PreGoal();
pg.setAttain( preGoal );
pg.setName( mainGoal );
bindings.addPreGoal( new DefaultGoalDecorator( mainGoal, preGoal ) );
bindings.addPostGoal( new DefaultGoalDecorator( mainGoal, postGoal ) );
List preGoals = new LinkedList();
preGoals.add( pg );
PostGoal pog = new PostGoal();
pog.setAttain( postGoal );
pog.setName( mainGoal );
List postGoals = new LinkedList();
postGoals.add( pog );
Map messages = new TreeMap();
@ -156,48 +152,47 @@ public class GoalResolutionPhaseTest
order.add( mainGoal );
order.add( postGoal );
runTest( mainGoal, bindings, order, messages );
runTest( mainGoal, preGoals, postGoals, 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
* <!-- Test main with prereq which has preGoal and postGoal --> <mojo>
* <id>resolveTest:t4-prereq-preGoal </id>
* <implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin
* </implementation> <instantiationStrategy>singleton
* </instantiationStrategy> </mojo> <mojo> <id>resolveTest:t4-prereq </id>
* <implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin
* </implementation> <instantiationStrategy>singleton
* </instantiationStrategy> </mojo> <mojo> <id>resolveTest:t4-main </id>
* <implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin
* </implementation> <instantiationStrategy>singleton
* </instantiationStrategy> <prereqs> <prereq>resolveTest:t4-prereq
* </prereq> </prereqs> </mojo> <mojo> <id>resolveTest: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";
String mainGoal = "resolveTest:t4-main";
String prereq = "resolveTest:t4-prereq";
String preGoal = "resolveTest:t4-prereq-preGoal";
String postGoal = "resolveTest:t4-prereq-postGoal";
GoalDecoratorBindings bindings = new GoalDecoratorBindings();
PreGoal pg = new PreGoal();
pg.setAttain( preGoal );
pg.setName( prereq );
bindings.addPreGoal( new DefaultGoalDecorator( prereq, preGoal ) );
bindings.addPostGoal( new DefaultGoalDecorator( prereq, postGoal ) );
List preGoals = new LinkedList();
preGoals.add( pg );
PostGoal pog = new PostGoal();
pog.setAttain( postGoal );
pog.setName( prereq );
List postGoals = new LinkedList();
postGoals.add( pog );
Map messages = new TreeMap();
@ -213,44 +208,36 @@ public class GoalResolutionPhaseTest
order.add( postGoal );
order.add( mainGoal );
runTest( mainGoal, bindings, order, messages );
runTest( mainGoal, preGoals, postGoals, 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
* <!-- Test main with prereq and preGoal which has the same prereq -->
* <mojo> <id>resolveTest:t5-prereq </id>
* <implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin
* </implementation> <instantiationStrategy>singleton
* </instantiationStrategy> </mojo> <mojo> <id>resolveTest:t5-preGoal </id>
* <implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin
* </implementation> <instantiationStrategy>singleton
* </instantiationStrategy> <prereqs> <prereq>resolveTest:t5-prereq
* </prereq> </prereqs> </mojo> <mojo> <id>resolveTest:t5-main </id>
* <implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin
* </implementation> <instantiationStrategy>singleton
* </instantiationStrategy> <prereqs> <prereq>resolveTest: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";
String mainGoal = "resolveTest:t5-main";
String prereq = "resolveTest:t5-prereq";
String preGoal = "resolveTest:t5-preGoal";
GoalDecoratorBindings bindings = new GoalDecoratorBindings();
PreGoal pg = new PreGoal();
pg.setAttain( preGoal );
pg.setName( mainGoal );
bindings.addPreGoal( new DefaultGoalDecorator( mainGoal, preGoal ) );
List preGoals = new LinkedList();
preGoals.add( pg );
Map messages = new TreeMap();
@ -264,16 +251,23 @@ public class GoalResolutionPhaseTest
order.add( preGoal );
order.add( mainGoal );
runTest( mainGoal, bindings, order, messages );
runTest( mainGoal, preGoals, Collections.EMPTY_LIST, order, messages );
}
private void runTest( String mainGoal, GoalDecoratorBindings bindings,
List expectedOrder, Map messages )
private void runTest( String mainGoal, List preGoals, List postGoals, List expectedOrder, Map messages )
throws Exception
{
MavenGoalExecutionContext context = createGoalExecutionContext( mainGoal );
ArtifactRepository localRepository = new ArtifactRepository( "local", getTestRepoURL() );
context.setGoalDecoratorBindings( bindings );
Model model = new Model();
model.setPreGoals( preGoals );
model.setPostGoals( postGoals );
MavenProject project = new MavenProject( model );
project.setProperties( new TreeMap() );
MavenGoalExecutionContext context = createGoalExecutionContext( project, localRepository, mainGoal );
context.setGoalName( mainGoal );
GoalResolutionPhase phase = new GoalResolutionPhase();
@ -281,8 +275,6 @@ public class GoalResolutionPhaseTest
List goals = context.getResolvedGoals();
System.out.println( "Resolved goals: " + goals );
assertNotNull( goals );
assertEquals( expectedOrder.size(), goals.size() );
@ -300,4 +292,4 @@ public class GoalResolutionPhaseTest
assertEquals( failureMessage, goal, resolvedGoal );
}
}
}
}

View File

@ -1,19 +1,19 @@
<plugin>
<id>decorTest</id>
<id>resolveTest</id>
<mojos>
<!-- Test main with preGoal and postGoal -->
<mojo>
<id>t1:preGoal</id>
<id>resolveTest:t1-preGoal</id>
<implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin</implementation>
<instantiationStrategy>singleton</instantiationStrategy>
</mojo>
<mojo>
<id>t1:main</id>
<id>resolveTest:t1-main</id>
<implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin</implementation>
<instantiationStrategy>singleton</instantiationStrategy>
</mojo>
<mojo>
<id>t1:postGoal</id>
<id>resolveTest:t1-postGoal</id>
<implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin</implementation>
<instantiationStrategy>singleton</instantiationStrategy>
</mojo>
@ -21,41 +21,41 @@
<!-- Test main with prereq -->
<mojo>
<id>t2:prereq</id>
<id>resolveTest:t2-prereq</id>
<implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin</implementation>
<instantiationStrategy>singleton</instantiationStrategy>
</mojo>
<mojo>
<id>t2:main</id>
<id>resolveTest:t2-main</id>
<implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin</implementation>
<instantiationStrategy>singleton</instantiationStrategy>
<prereqs>
<prereq>t2:prereq</prereq>
<prereq>resolveTest:t2-prereq</prereq>
</prereqs>
</mojo>
<!-- End of test -->
<!-- Test main with prereq, preGoal and postGoal -->
<mojo>
<id>t3:preGoal</id>
<id>resolveTest:t3-preGoal</id>
<implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin</implementation>
<instantiationStrategy>singleton</instantiationStrategy>
</mojo>
<mojo>
<id>t3:prereq</id>
<id>resolveTest:t3-prereq</id>
<implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin</implementation>
<instantiationStrategy>singleton</instantiationStrategy>
</mojo>
<mojo>
<id>t3:main</id>
<id>resolveTest:t3-main</id>
<implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin</implementation>
<instantiationStrategy>singleton</instantiationStrategy>
<prereqs>
<prereq>t3:prereq</prereq>
<prereq>resolveTest:t3-prereq</prereq>
</prereqs>
</mojo>
<mojo>
<id>t3:postGoal</id>
<id>resolveTest:t3-postGoal</id>
<implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin</implementation>
<instantiationStrategy>singleton</instantiationStrategy>
</mojo>
@ -63,25 +63,25 @@
<!-- Test main with prereq which has preGoal and postGoal -->
<mojo>
<id>t4:prereq-preGoal</id>
<id>resolveTest:t4-prereq-preGoal</id>
<implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin</implementation>
<instantiationStrategy>singleton</instantiationStrategy>
</mojo>
<mojo>
<id>t4:prereq</id>
<id>resolveTest:t4-prereq</id>
<implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin</implementation>
<instantiationStrategy>singleton</instantiationStrategy>
</mojo>
<mojo>
<id>t4:main</id>
<id>resolveTest:t4-main</id>
<implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin</implementation>
<instantiationStrategy>singleton</instantiationStrategy>
<prereqs>
<prereq>t4:prereq</prereq>
<prereq>resolveTest:t4-prereq</prereq>
</prereqs>
</mojo>
<mojo>
<id>t4:prereq-postGoal</id>
<id>resolveTest:t4-prereq-postGoal</id>
<implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin</implementation>
<instantiationStrategy>singleton</instantiationStrategy>
</mojo>
@ -90,24 +90,24 @@
<!-- Test main with prereq and preGoal which has the same prereq -->
<mojo>
<id>t5:prereq</id>
<id>resolveTest:t5-prereq</id>
<implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin</implementation>
<instantiationStrategy>singleton</instantiationStrategy>
</mojo>
<mojo>
<id>t5:preGoal</id>
<id>resolveTest:t5-preGoal</id>
<implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin</implementation>
<instantiationStrategy>singleton</instantiationStrategy>
<prereqs>
<prereq>t5:prereq</prereq>
<prereq>resolveTest:t5-prereq</prereq>
</prereqs>
</mojo>
<mojo>
<id>t5:main</id>
<id>resolveTest:t5-main</id>
<implementation>org.apache.maven.plugin.GoalDecorationAndResolutionTestPlugin</implementation>
<instantiationStrategy>singleton</instantiationStrategy>
<prereqs>
<prereq>t5:prereq</prereq>
<prereq>resolveTest:t5-prereq</prereq>
</prereqs>
</mojo>
<!-- End of test -->

BIN
mboot.jar

Binary file not shown.