o Added <pluginManagement/>

o Removed goal decoration.


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163468 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2005-03-07 19:03:19 +00:00
parent e2588cf933
commit 2513cb25aa
41 changed files with 676 additions and 2419 deletions

View File

@ -24,9 +24,8 @@ import org.apache.maven.execution.MavenExecutionResponse;
import org.apache.maven.execution.MavenProjectExecutionRequest;
import org.apache.maven.execution.MavenReactorExecutionRequest;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.GoalNotFoundException;
import org.apache.maven.lifecycle.LifecycleExecutor;
import org.apache.maven.lifecycle.goal.GoalNotFoundException;
import org.apache.maven.lifecycle.session.MavenSessionPhaseManager;
import org.apache.maven.monitor.event.EventDispatcher;
import org.apache.maven.monitor.event.MavenEvents;
import org.apache.maven.plugin.PluginManager;
@ -52,7 +51,7 @@ import java.util.Iterator;
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 DefaultMaven
@ -69,8 +68,6 @@ public class DefaultMaven
protected PluginManager pluginManager;
protected MavenSessionPhaseManager sessionPhaseManager;
protected LifecycleExecutor lifecycleExecutor;
protected PlexusContainer container;
@ -79,8 +76,7 @@ public class DefaultMaven
// Project execution
// ----------------------------------------------------------------------
public MavenExecutionResponse execute( MavenExecutionRequest request )
throws GoalNotFoundException, Exception
public MavenExecutionResponse execute( MavenExecutionRequest request ) throws GoalNotFoundException, Exception
{
// TODO: not happy about this:
if ( request instanceof MavenReactorExecutionRequest )
@ -94,8 +90,7 @@ public class DefaultMaven
}
// TODO: don't throw generic exception
public MavenExecutionResponse handleProject( MavenExecutionRequest request )
throws Exception
public MavenExecutionResponse handleProject( MavenExecutionRequest request ) throws Exception
{
MavenSession session = createSession( request );
@ -109,18 +104,18 @@ public class DefaultMaven
// Event monitoring.
EventDispatcher dispatcher = request.getEventDispatcher();
String event = MavenEvents.PROJECT_EXECUTION;
dispatcher.dispatchStart( event, project.getId() );
MavenExecutionResponse response = null;
try
{
// Actual meat of the code.
response = lifecycleExecutor.execute( request.getGoals(), session );
dispatcher.dispatchEnd( event, project.getId() );
}
catch(Exception e)
catch ( Exception e )
{
dispatcher.dispatchError( event, project.getId(), e );
}
@ -131,8 +126,10 @@ public class DefaultMaven
{
if ( response.getException() != null )
{
// TODO: this should be a "FATAL" exception, reported to the developers - however currently a LOT of
// "user" errors fall through the cracks (like invalid POMs, as one example)
// TODO: this should be a "FATAL" exception, reported to the
// developers - however currently a LOT of
// "user" errors fall through the cracks (like invalid POMs, as
// one example)
logError( response );
}
else
@ -151,12 +148,11 @@ public class DefaultMaven
// Reactor
// ----------------------------------------------------------------------
public MavenExecutionResponse handleReactor( MavenReactorExecutionRequest request )
throws ReactorException
public MavenExecutionResponse handleReactor( MavenReactorExecutionRequest request ) throws ReactorException
{
EventDispatcher dispatcher = request.getEventDispatcher();
String event = MavenEvents.REACTOR_EXECUTION;
dispatcher.dispatchStart( event, request.getBaseDirectory().getPath() );
try
{
@ -231,7 +227,7 @@ public class DefaultMaven
}
}
dispatcher.dispatchEnd( event, request.getBaseDirectory().getPath() );
// TODO: not really satisfactory
@ -240,13 +236,12 @@ public class DefaultMaven
catch ( ReactorException e )
{
dispatcher.dispatchError( event, request.getBaseDirectory().getPath(), e );
throw e;
}
}
public MavenProject getProject( File pom, ArtifactRepository localRepository )
throws ProjectBuildingException
public MavenProject getProject( File pom, ArtifactRepository localRepository ) throws ProjectBuildingException
{
if ( pom.exists() )
{
@ -263,20 +258,26 @@ public class DefaultMaven
// Methods used by all execution request handlers
// ----------------------------------------------------------------------
//!! We should probably have the execution request handler create the session as
//!! We should probably have the execution request handler create the
// session as
// the session type would be specific to the request i.e. having a project
// or not.
protected MavenSession createSession( MavenExecutionRequest request )
{
return new MavenSession( container, pluginManager, request.getLocalRepository(), request.getEventDispatcher(), request.getLog(), request.getGoals() );
return new MavenSession( container,
pluginManager,
request.getLocalRepository(),
request.getEventDispatcher(),
request.getLog(),
request.getGoals() );
}
/**
* @todo [BP] this might not be required if there is a better way to pass them in. It doesn't feel quite right.
* @todo [BP] this might not be required if there is a better way to pass
* them in. It doesn't feel quite right.
*/
private void resolveParameters( MavenExecutionRequest request )
throws ComponentLookupException
private void resolveParameters( MavenExecutionRequest request ) throws ComponentLookupException
{
WagonManager wagonManager = (WagonManager) container.lookup( WagonManager.ROLE );
@ -295,7 +296,9 @@ public class DefaultMaven
getLogger().warn( "maven.proxy.http.port was not valid" );
}
}
wagonManager.setProxy( "http", request.getParameter( "maven.proxy.http.host" ), port,
wagonManager.setProxy( "http",
request.getParameter( "maven.proxy.http.host" ),
port,
request.getParameter( "maven.proxy.http.username" ),
request.getParameter( "maven.proxy.http.password" ),
request.getParameter( "maven.proxy.http.nonProxyHosts" ) );
@ -380,7 +383,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" );
}
protected void line()
@ -414,10 +418,9 @@ public class DefaultMaven
// Reactor
// ----------------------------------------------------------------------
public List getSortedProjects( List projects )
throws CycleDetectedException
public List getSortedProjects( List projects ) throws CycleDetectedException
{
return projectBuilder.getSortedProjects( projects );
}
}
}

View File

@ -18,16 +18,15 @@ package org.apache.maven;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResponse;
import org.apache.maven.lifecycle.goal.GoalNotFoundException;
import org.apache.maven.lifecycle.GoalNotFoundException;
/**
* @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 interface Maven
{
static String ROLE = Maven.class.getName();
MavenExecutionResponse execute( MavenExecutionRequest request )
throws GoalNotFoundException, Exception;
}
MavenExecutionResponse execute( MavenExecutionRequest request ) throws GoalNotFoundException, Exception;
}

View File

@ -18,8 +18,6 @@ package org.apache.maven.execution;
*/
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.PostGoal;
import org.apache.maven.model.PreGoal;
import org.apache.maven.monitor.event.EventDispatcher;
import org.apache.maven.monitor.logging.Log;
import org.apache.maven.plugin.PluginManager;
@ -32,12 +30,9 @@ import org.codehaus.plexus.util.dag.DAG;
import org.codehaus.plexus.util.dag.TopologicalSorter;
import org.codehaus.plexus.util.dag.Vertex;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
@ -67,12 +62,8 @@ public class MavenSession
private Log log;
public MavenSession( PlexusContainer container,
PluginManager pluginManager,
ArtifactRepository localRepository,
EventDispatcher eventDispatcher,
Log log,
List goals )
public MavenSession( PlexusContainer container, PluginManager pluginManager, ArtifactRepository localRepository,
EventDispatcher eventDispatcher, Log log, List goals )
{
this.container = container;
@ -81,7 +72,7 @@ public class MavenSession
this.localRepository = localRepository;
this.eventDispatcher = eventDispatcher;
this.log = log;
this.dag = new DAG();
@ -107,16 +98,6 @@ public class MavenSession
public void setProject( MavenProject project )
{
this.project = project;
// ----------------------------------------------------------------------
// We only need these things to be done when we have a project.
// ----------------------------------------------------------------------
this.preGoalMappings = new TreeMap();
this.postGoalMappings = new TreeMap();
initGoalDecoratorMappings();
}
public ArtifactRepository getLocalRepository()
@ -143,14 +124,12 @@ public class MavenSession
//
// ----------------------------------------------------------------------
public Object lookup( String role )
throws ComponentLookupException
public Object lookup( String role ) throws ComponentLookupException
{
return container.lookup( role );
}
public Object lookup( String role, String roleHint )
throws ComponentLookupException
public Object lookup( String role, String roleHint ) throws ComponentLookupException
{
return container.lookup( role, roleHint );
}
@ -170,89 +149,22 @@ public class MavenSession
}
}
}
public EventDispatcher getEventDispatcher()
{
return eventDispatcher;
}
public Log getLog()
{
return log;
}
//!! this should probably not be done here as there are request types that
// have no project
public List getPreGoals( String goal )
{
if ( project == null )
{
return null;
}
List result = (List) preGoalMappings.get( goal );
return result;
}
public List getPostGoals( String goal )
{
if ( project == null )
{
return null;
}
List result = (List) postGoalMappings.get( goal );
return result;
}
private void initGoalDecoratorMappings()
{
List allPreGoals = project.getPreGoals();
for ( Iterator it = allPreGoals.iterator(); it.hasNext(); )
{
PreGoal preGoal = (PreGoal) it.next();
List preGoalList = (List) preGoalMappings.get( preGoal.getName() );
if ( preGoalList == null )
{
preGoalList = new LinkedList();
preGoalMappings.put( preGoal.getName(), preGoalList );
}
preGoalList.add( preGoal.getAttain() );
}
List allPostGoals = project.getPostGoals();
for ( Iterator it = allPostGoals.iterator(); it.hasNext(); )
{
PostGoal postGoal = (PostGoal) it.next();
List postGoalList = (List) postGoalMappings.get( postGoal.getName() );
if ( postGoalList == null )
{
postGoalList = new LinkedList();
postGoalMappings.put( postGoal.getName(), postGoalList );
}
postGoalList.add( postGoal.getAttain() );
}
}
public void addImpliedExecution( String goal, String implied )
throws CycleDetectedException
public void addImpliedExecution( String goal, String implied ) throws CycleDetectedException
{
dag.addEdge( goal, implied );
}
public void addSingleExecution( String goal )
{
dag.addVertex( goal );
@ -261,13 +173,13 @@ public class MavenSession
public List getExecutionChain( String goal )
{
Vertex vertex = dag.getVertex( goal );
List sorted = TopologicalSorter.sort( vertex );
int goalIndex = sorted.indexOf( goal );
List chainToHere = sorted.subList( 0, goalIndex + 1 );
return chainToHere;
}

View File

@ -22,7 +22,6 @@ import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.execution.MavenExecutionResponse;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.goal.GoalExecutionException;
import org.apache.maven.model.Plugin;
import org.apache.maven.monitor.event.EventDispatcher;
import org.apache.maven.monitor.event.MavenEvents;
@ -41,8 +40,9 @@ import java.util.List;
import java.util.Map;
/**
* @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: DefaultLifecycleExecutor.java,v 1.16 2005/03/04 09:04:25
* jdcasey Exp $
*/
public class DefaultLifecycleExecutor
implements LifecycleExecutor, Initializable
@ -68,9 +68,9 @@ public class DefaultLifecycleExecutor
// ----------------------------------------------------------------------
/**
* Execute a list of tasks. Each task may be a phase in the lifecycle
* or the execution of a mojo.
*
* Execute a list of tasks. Each task may be a phase in the lifecycle or the
* execution of a mojo.
*
* @param tasks
* @param session
*/
@ -82,12 +82,14 @@ public class DefaultLifecycleExecutor
try
{
// TODO: should enrich this with the type handler, but for now just use "type" as is
// TODO: should enrich this with the type handler, but for now just
// use "type" as is
ArtifactHandler handler = artifactHandlerManager.getArtifactHandler( session.getProject().getType() );
if ( handler != null )
{
// TODO: perhaps each type should define their own lifecycle completely, using the base as a default?
// TODO: perhaps each type should define their own lifecycle
// completely, using the base as a default?
// If so, remove both of these goals from type handler
if ( handler.packageGoal() != null )
{
@ -139,15 +141,15 @@ public class DefaultLifecycleExecutor
}
// TODO: don't throw Exception
private void processPluginConfiguration( MavenProject project, MavenSession mavenSession )
throws Exception
private void processPluginConfiguration( MavenProject project, MavenSession mavenSession ) throws Exception
{
for ( Iterator i = project.getPlugins().iterator(); i.hasNext(); )
{
Plugin plugin = (Plugin) i.next();
// TODO: should this flag be used in verifyPlugin, completely disabling the plugin?
if ( !plugin.isDisabled() )
// TODO: should this flag be used in verifyPlugin, completely
// disabling the plugin?
if ( Boolean.TRUE != plugin.isDisabled() )
{
String pluginId = plugin.getId();
processPluginPhases( pluginId, mavenSession );
@ -156,8 +158,7 @@ public class DefaultLifecycleExecutor
}
// TODO: don't throw Exception
private void processPluginPhases( String pluginId, MavenSession mavenSession )
throws Exception
private void processPluginPhases( String pluginId, MavenSession mavenSession ) throws Exception
{
pluginManager.verifyPlugin( pluginId, mavenSession );
PluginDescriptor pluginDescriptor = pluginManager.getPluginDescriptor( pluginId );
@ -165,7 +166,8 @@ public class DefaultLifecycleExecutor
{
MojoDescriptor mojoDescriptor = (MojoDescriptor) j.next();
// TODO: check if the goal exists in the configuration and is disabled
// TODO: check if the goal exists in the configuration and is
// disabled
if ( mojoDescriptor.getPhase() != null )
{
Phase phase = (Phase) phaseMap.get( mojoDescriptor.getPhase() );
@ -175,8 +177,7 @@ public class DefaultLifecycleExecutor
}
private void processGoalChain( String task, MavenSession session )
throws Exception
private void processGoalChain( String task, MavenSession session ) throws Exception
{
if ( phaseMap.containsKey( task ) )
{
@ -204,8 +205,7 @@ public class DefaultLifecycleExecutor
}
}
private void verifyMojoPhase( String task, MavenSession session )
throws Exception
private void verifyMojoPhase( String task, MavenSession session ) throws Exception
{
MojoDescriptor mojoDescriptor = pluginManager.getMojoDescriptor( task );
if ( mojoDescriptor == null )
@ -232,11 +232,11 @@ public class DefaultLifecycleExecutor
int index = phases.indexOf( phaseMap.get( phase ) );
EventDispatcher dispatcher = session.getEventDispatcher();
for ( int j = 0; j <= index; j++ )
{
Phase p = (Phase) phases.get( j );
String event = MavenEvents.PHASE_EXECUTION;
// !! This is ripe for refactoring to an aspect.
@ -259,21 +259,20 @@ public class DefaultLifecycleExecutor
}
}
}
dispatcher.dispatchEnd( event, p.getId() );
}
catch ( LifecycleExecutionException e )
{
dispatcher.dispatchError( event, p.getId(), e );
throw e;
}
// End event monitoring.
}
}
protected PluginExecutionResponse executeMojo( String id, MavenSession session )
throws LifecycleExecutionException
protected PluginExecutionResponse executeMojo( String id, MavenSession session ) throws LifecycleExecutionException
{
// ----------------------------------------------------------------------
// We have something of the form <pluginId>:<mojoId>, so this might be
@ -312,8 +311,7 @@ public class DefaultLifecycleExecutor
// Lifecylce Management
// ----------------------------------------------------------------------
public void initialize()
throws Exception
public void initialize() throws Exception
{
phaseMap = new HashMap();
@ -324,4 +322,4 @@ public class DefaultLifecycleExecutor
phaseMap.put( p.getId(), p );
}
}
}
}

View File

@ -1,4 +1,4 @@
package org.apache.maven.lifecycle.goal;
package org.apache.maven.lifecycle;
/* ====================================================================
* Copyright 2001-2004 The Apache Software Foundation.
@ -18,8 +18,9 @@ package org.apache.maven.lifecycle.goal;
*/
/**
* @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: GoalExecutionException.java,v 1.3 2004/12/25 16:26:24 jvanzyl
* Exp $
*/
public class GoalExecutionException
extends Exception
@ -38,4 +39,4 @@ public class GoalExecutionException
{
super( message, cause );
}
}
}

View File

@ -0,0 +1,32 @@
package org.apache.maven.lifecycle;
/*
* ====================================================================
* 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.
* ====================================================================
*/
public class GoalNotFoundException
extends GoalExecutionException
{
private String goalName;
public GoalNotFoundException( String goal )
{
super( "Unknown goal \"" + goal + "\"" );
this.goalName = goal;
}
public String getGoalName()
{
return this.goalName;
}
}

View File

@ -1,32 +0,0 @@
package org.apache.maven.lifecycle.goal;
/* ====================================================================
* 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.codehaus.plexus.logging.AbstractLogEnabled;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public abstract class AbstractMavenGoalPhase
extends AbstractLogEnabled
implements MavenGoalPhase
{
public abstract void execute( MavenGoalExecutionContext context )
throws GoalExecutionException;
}

View File

@ -1,57 +0,0 @@
package org.apache.maven.lifecycle.goal;
/* ====================================================================
* 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.codehaus.plexus.logging.AbstractLogEnabled;
import java.util.Iterator;
import java.util.List;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public class DefaultMavenGoalPhaseManager
extends AbstractLogEnabled
implements MavenGoalPhaseManager
{
private List lifecyclePhases;
public List getLifecyclePhases()
{
return lifecyclePhases;
}
public void execute( MavenGoalExecutionContext context )
throws GoalExecutionException
{
for ( Iterator iterator = lifecyclePhases.iterator(); iterator.hasNext(); )
{
MavenGoalPhase phase = (MavenGoalPhase) iterator.next();
phase.enableLogging( getLogger() );
phase.execute( context );
if ( context.isExecutionFailure() )
{
break;
}
}
}
}

View File

@ -1,37 +0,0 @@
package org.apache.maven.lifecycle.goal;
/* ====================================================================
* 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.
* ====================================================================
*/
public class GoalNotFoundException
extends GoalExecutionException
{
private String goalName;
public GoalNotFoundException( String goal )
{
super( "Unknown goal \"" + goal + "\"" );
this.goalName = goal;
}
public String getGoalName()
{
return this.goalName;
}
}

View File

@ -1,171 +0,0 @@
package org.apache.maven.lifecycle.goal;
/* ====================================================================
* 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;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.FailureResponse;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import java.util.List;
import java.util.Set;
/**
* @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
{
private MavenSession session;
private String failedGoal;
private FailureResponse failureResponse;
private List resolvedGoals;
private String goalName;
private boolean requiresDependencies;
public MavenGoalExecutionContext( MavenSession session, String goalName )
{
this.session = session;
this.goalName = goalName;
}
public MavenSession getSession()
{
return session;
}
// ----------------------------------------------------------------------
// Delegation to the session
// ----------------------------------------------------------------------
public MavenProject getProject()
{
return session.getProject();
}
public ArtifactRepository getLocalRepository()
{
return session.getLocalRepository();
}
public Set getRemoteRepositories()
{
return session.getRemoteRepositories();
}
public Object lookup( String role )
throws ComponentLookupException
{
return session.lookup( role );
}
public Object lookup( String role, String hint )
throws ComponentLookupException
{
return session.lookup( role, hint );
}
// TODO: can remove when phases are gone
public void release( Object component )
{
session.release( component );
}
// ----------------------------------------------------------------------
public List getResolvedGoals()
{
return resolvedGoals;
}
public void setResolvedGoals( List resolvedGoals )
{
this.resolvedGoals = resolvedGoals;
}
public MojoDescriptor getMojoDescriptor( String mojoDescriptorName )
{
return session.getPluginManager().getMojoDescriptor( mojoDescriptorName );
}
public String getPluginId( MojoDescriptor mojoDescriptor )
{
return mojoDescriptor.getId();
}
public void setExecutionFailure( String failedGoal, FailureResponse response )
{
this.failedGoal = failedGoal;
this.failureResponse = response;
}
public boolean isExecutionFailure()
{
return ( failedGoal != null );
}
public String getFailedGoal()
{
return failedGoal;
}
public void setFailedGoal( String failedGoal )
{
this.failedGoal = failedGoal;
}
public FailureResponse getFailureResponse()
{
return failureResponse;
}
public void setFailureResponse( FailureResponse failureResponse )
{
this.failureResponse = failureResponse;
}
public String getGoalName()
{
return goalName;
}
public void setGoalName( String goalName )
{
this.goalName = goalName;
}
public void requiresDependencies( boolean requiresDependencies )
{
this.requiresDependencies = requiresDependencies;
}
public boolean requiresDependencies()
{
return requiresDependencies;
}
}

View File

@ -1,35 +0,0 @@
package org.apache.maven.lifecycle.goal;
/* ====================================================================
* 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.codehaus.plexus.logging.Logger;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public interface MavenGoalPhase
{
String ROLE = MavenGoalPhase.class.getName();
void execute( MavenGoalExecutionContext context )
throws GoalExecutionException;
void enableLogging( Logger logger );
}

View File

@ -1,34 +0,0 @@
package org.apache.maven.lifecycle.goal;
/* ====================================================================
* 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.util.List;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public interface MavenGoalPhaseManager
{
String ROLE = MavenGoalPhaseManager.class.getName();
void execute( MavenGoalExecutionContext context )
throws GoalExecutionException;
List getLifecyclePhases();
}

View File

@ -1,73 +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.artifact.Artifact;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.lifecycle.goal.AbstractMavenGoalPhase;
import org.apache.maven.lifecycle.goal.GoalExecutionException;
import org.apache.maven.lifecycle.goal.MavenGoalExecutionContext;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import java.util.Iterator;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public class DependencyDownloadPhase
extends AbstractMavenGoalPhase
{
public void execute( MavenGoalExecutionContext context )
throws GoalExecutionException
{
if ( context.requiresDependencies() )
{
ArtifactResolver artifactResolver = null;
try
{
// Once this is a property component there will be an assembly phase for
// this and we won't have to do this.
artifactResolver = (ArtifactResolver) context.lookup( ArtifactResolver.ROLE );
for ( Iterator it = context.getProject().getArtifacts().iterator(); it.hasNext(); )
{
Artifact artifact = (Artifact) it.next();
artifactResolver.resolve( artifact,
context.getRemoteRepositories(),
context.getLocalRepository() );
}
}
catch ( ComponentLookupException e )
{
throw new GoalExecutionException( "Can't lookup artifact resolver: ", e );
}
catch ( ArtifactResolutionException e )
{
throw new GoalExecutionException( "Can't resolve artifact: ", e );
}
finally
{
context.release( artifactResolver );
}
}
}
}

View File

@ -1,102 +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.artifact.MavenMetadataSource;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.lifecycle.goal.AbstractMavenGoalPhase;
import org.apache.maven.lifecycle.goal.GoalExecutionException;
import org.apache.maven.lifecycle.goal.MavenGoalExecutionContext;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import java.util.Iterator;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public class DependencyResolutionPhase
extends AbstractMavenGoalPhase
{
public void execute( MavenGoalExecutionContext context )
throws GoalExecutionException
{
boolean requiresDependencies = false;
for ( Iterator iterator = context.getResolvedGoals().iterator(); iterator.hasNext(); )
{
String goalName = (String) iterator.next();
MojoDescriptor mojoDescriptor = context.getMojoDescriptor( goalName );
if ( mojoDescriptor.requiresDependencyResolution() )
{
requiresDependencies = true;
try
{
resolveTransitiveDependencies( context );
}
catch ( Exception e )
{
throw new GoalExecutionException( "Can't resolve transitive dependencies: ", e );
}
break;
}
}
context.requiresDependencies( requiresDependencies );
}
private void resolveTransitiveDependencies( MavenGoalExecutionContext context )
throws Exception
{
ArtifactResolver artifactResolver = null;
MavenProjectBuilder projectBuilder = null;
try
{
MavenProject project = context.getProject();
artifactResolver = (ArtifactResolver) context.lookup( ArtifactResolver.ROLE );
projectBuilder = (MavenProjectBuilder) context.lookup( MavenProjectBuilder.ROLE );
MavenMetadataSource sourceReader = new MavenMetadataSource( artifactResolver,
projectBuilder );
ArtifactResolutionResult result = artifactResolver.resolveTransitively( project.getArtifacts(),
context.getRemoteRepositories(),
context.getLocalRepository(),
sourceReader );
project.getArtifacts().addAll( result.getArtifacts().values() );
}
finally
{
context.release( artifactResolver );
context.release( projectBuilder );
}
}
}

View File

@ -1,54 +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.PluginExecutionResponse;
import java.util.Iterator;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public class GoalAttainmentPhase
extends AbstractMavenGoalPhase
{
public void execute( MavenGoalExecutionContext context )
throws GoalExecutionException
{
PluginExecutionResponse response;
// TODO: remove - most likely empty as there are no prereqs and I don't think the pre/postGoals are being walked
for ( Iterator it = context.getResolvedGoals().iterator(); it.hasNext(); )
{
String goalName = (String) it.next();
response = context.getSession().getPluginManager().executeMojo( context.getSession(), goalName );
if ( response.isExecutionFailure() )
{
context.setExecutionFailure( goalName, response.getFailureResponse() );
break;
}
}
}
}

View File

@ -1,103 +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.execution.MavenSession;
import org.apache.maven.plugin.PluginManager;
import org.apache.maven.util.AbstractGoalVisitor;
import org.apache.maven.util.GoalWalker;
import org.apache.maven.util.GraphTraversalException;
import org.apache.maven.execution.MavenSession;
import org.codehaus.plexus.util.dag.CycleDetectedException;
import java.util.HashSet;
import java.util.Set;
/**
* @author jdcasey
*/
public class GoalMappingPhase
extends AbstractMavenGoalPhase
{
public void execute( MavenGoalExecutionContext context )
throws GoalExecutionException
{
GoalMappingVisitor visitor = new GoalMappingVisitor();
try
{
GoalWalker.walk( context.getGoalName(), context.getSession(), visitor );
}
catch ( GraphTraversalException e )
{
throw new GoalExecutionException( "Cannot resolve plugins required for goal execution chain", e );
}
}
public static final class GoalMappingVisitor
extends AbstractGoalVisitor
{
private Set visited = new HashSet();
public void visitPrereq( String goal, String prereq, MavenSession session )
throws GraphTraversalException
{
GoalWalker.walk( prereq, session, this );
try
{
session.addImpliedExecution( goal, prereq );
visited.add( prereq );
}
catch ( CycleDetectedException e )
{
throw new GraphTraversalException( "Goal prereq causes goal-graph cycle", e );
}
}
public void visitPostGoal( String goal, String postGoal, MavenSession session )
throws GraphTraversalException
{
GoalWalker.walk( postGoal, session, this );
}
public void visitPreGoal( String goal, String preGoal, MavenSession session )
throws GraphTraversalException
{
GoalWalker.walk( preGoal, session, this );
}
public void visitGoal( String goal, MavenSession session )
{
session.addSingleExecution( goal );
visited.add( goal );
}
public boolean shouldVisit( String goal, MavenSession session )
{
return !visited.contains( goal );
}
}
}

View File

@ -1,114 +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.execution.MavenSession;
import org.apache.maven.plugin.PluginManager;
import org.apache.maven.util.AbstractGoalVisitor;
import org.apache.maven.util.GoalWalker;
import org.apache.maven.util.GraphTraversalException;
import org.apache.maven.execution.MavenSession;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
* @version $Id$
*/
public class GoalResolutionPhase
extends AbstractMavenGoalPhase
{
public void execute( MavenGoalExecutionContext context ) throws GoalExecutionException
{
GoalResolutionVisitor visitor = new GoalResolutionVisitor( context.getSession().getPluginManager() );
try
{
GoalWalker.walk( context.getGoalName(), context.getSession(), visitor );
}
catch ( GraphTraversalException e )
{
throw new GoalExecutionException("Cannot calculate goal execution chain", e);
}
context.setResolvedGoals(visitor.getExecutionChain());
}
public static final class GoalResolutionVisitor
extends AbstractGoalVisitor
{
private PluginManager pluginManager;
private List executionChain = new LinkedList();
private Map prereqChains = new TreeMap();
GoalResolutionVisitor( PluginManager pluginManager )
{
this.pluginManager = pluginManager;
}
public boolean shouldVisit( String goal, MavenSession session )
{
boolean result = !executionChain.contains( goal );
return result;
}
public void visitGoal( String goal, MavenSession session )
{
executionChain.add( goal );
}
public void visitPostGoal( String goal, String postGoal, MavenSession session )
throws GraphTraversalException
{
List chain = session.getExecutionChain( postGoal );
executionChain.addAll( chain );
}
public void visitPreGoal( String goal, String preGoal, MavenSession session )
throws GraphTraversalException
{
List chain = session.getExecutionChain( preGoal );
executionChain.addAll( chain );
}
public void visitPrereq( String goal, String prereq, MavenSession session)
throws GraphTraversalException
{
GoalWalker.walk( prereq, session, this );
}
public List getExecutionChain()
{
return executionChain;
}
}
}

View File

@ -1,106 +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.execution.MavenSession;
import org.apache.maven.plugin.PluginManager;
import org.apache.maven.util.AbstractGoalVisitor;
import org.apache.maven.util.GoalWalker;
import org.apache.maven.util.GraphTraversalException;
import org.apache.maven.execution.MavenSession;
import java.util.HashSet;
import java.util.Set;
/**
* @author jdcasey
*/
public class PluginResolutionPhase
extends AbstractMavenGoalPhase
{
public void execute( MavenGoalExecutionContext context )
throws GoalExecutionException
{
PluginResolutionVisitor visitor = new PluginResolutionVisitor( context.getSession().getPluginManager() );
try
{
GoalWalker.walk( context.getGoalName(), context.getSession(), visitor );
}
catch ( GraphTraversalException e )
{
throw new GoalExecutionException( "Cannot resolve plugins required for goal execution chain", e );
}
}
public static final class PluginResolutionVisitor
extends AbstractGoalVisitor
{
private PluginManager pluginManager;
private Set resolved = new HashSet();
PluginResolutionVisitor( PluginManager pluginManager )
{
this.pluginManager = pluginManager;
}
public void preVisit( String goal, MavenSession session )
throws GraphTraversalException
{
try
{
pluginManager.verifyPluginForGoal( goal, session );
}
catch ( Exception e )
{
throw new GraphTraversalException( "Cannot resolve plugin for goal", e );
}
finally
{
resolved.add( goal );
}
}
public boolean shouldVisit( String goal, MavenSession session )
{
return !resolved.contains( goal );
}
public void visitPostGoal( String goal, String postGoal, MavenSession session )
throws GraphTraversalException
{
GoalWalker.walk( postGoal, session, this );
}
public void visitPreGoal( String goal, String preGoal, MavenSession session )
throws GraphTraversalException
{
GoalWalker.walk( preGoal, session, this );
}
public void visitPrereq( String goal, String prereq, MavenSession session )
throws GraphTraversalException
{
GoalWalker.walk( prereq, session, this );
}
}
}

View File

@ -1,30 +0,0 @@
package org.apache.maven.lifecycle.session;
/* ====================================================================
* 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.codehaus.plexus.logging.AbstractLogEnabled;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public abstract class AbstractMavenSessionPhase
extends AbstractLogEnabled
implements MavenSessionPhase
{
}

View File

@ -1,61 +0,0 @@
package org.apache.maven.lifecycle.session;
/* ====================================================================
* 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.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResponse;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import java.util.Iterator;
import java.util.List;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public class DefaultMavenSessionPhaseManager
extends AbstractLogEnabled
implements MavenSessionPhaseManager
{
private List lifecyclePhases;
public List getLifecyclePhases()
{
return lifecyclePhases;
}
public void execute( MavenExecutionRequest request, MavenExecutionResponse response )
throws Exception
{
// TODO: no longer executed. Remove this, components, etc.
for ( Iterator iterator = lifecyclePhases.iterator(); iterator.hasNext(); )
{
MavenSessionPhase phase = (MavenSessionPhase) iterator.next();
phase.enableLogging( getLogger() );
phase.execute( request, response );
if ( response.isExecutionFailure() )
{
return;
}
}
}
}

View File

@ -1,36 +0,0 @@
package org.apache.maven.lifecycle.session;
/* ====================================================================
* 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.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResponse;
import org.codehaus.plexus.logging.Logger;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public interface MavenSessionPhase
{
String ROLE = MavenSessionPhase.class.getName();
void execute( MavenExecutionRequest request, MavenExecutionResponse response )
throws Exception;
void enableLogging( Logger logger );
}

View File

@ -1,37 +0,0 @@
package org.apache.maven.lifecycle.session;
/* ====================================================================
* 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.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResponse;
import java.util.List;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public interface MavenSessionPhaseManager
{
String ROLE = MavenSessionPhaseManager.class.getName();
void execute( MavenExecutionRequest request, MavenExecutionResponse response )
throws Exception;
List getLifecyclePhases();
}

View File

@ -1,63 +0,0 @@
package org.apache.maven.lifecycle.session.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.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResponse;
import org.apache.maven.lifecycle.goal.MavenGoalExecutionContext;
import org.apache.maven.lifecycle.goal.MavenGoalPhaseManager;
import org.apache.maven.lifecycle.session.AbstractMavenSessionPhase;
import org.apache.maven.execution.MavenSession;
import java.util.Iterator;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
* @version $Id$
*/
public class GoalExecutionPhase
extends AbstractMavenSessionPhase
{
public void execute( MavenExecutionRequest request, MavenExecutionResponse response )
throws Exception
{
MavenSession session = request.getSession();
MavenGoalPhaseManager lifecycleManager = (MavenGoalPhaseManager) session.lookup( MavenGoalPhaseManager.ROLE );
for ( Iterator iterator = session.getGoals().iterator(); iterator.hasNext(); )
{
String goal = (String) iterator.next();
MavenGoalExecutionContext context;
context = new MavenGoalExecutionContext( session, goal );
context.setGoalName( goal );
lifecycleManager.execute( context );
if ( context.isExecutionFailure() )
{
response.setExecutionFailure( context.getGoalName(), context.getFailureResponse() );
break;
}
}
}
}

View File

@ -1,19 +1,15 @@
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.
* ====================================================================
*/
@ -28,7 +24,7 @@ import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.artifact.resolver.filter.ExclusionSetFilter;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.goal.GoalExecutionException;
import org.apache.maven.lifecycle.GoalExecutionException;
import org.apache.maven.monitor.event.EventDispatcher;
import org.apache.maven.monitor.event.MavenEvents;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
@ -103,9 +99,9 @@ public class DefaultPluginManager
/**
* Mojo descriptors are looked up using their id which is of the form
* <pluginId>:<mojoId>. So this might be archetype:create for example which
* <pluginId>: <mojoId>. So this might be archetype:create for example which
* is the create mojo that resides in the archetype plugin.
*
*
* @param name
* @return
*/
@ -125,8 +121,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() ) )
{
@ -157,7 +152,7 @@ public class DefaultPluginManager
{
ComponentSetDescriptor componentSetDescriptor = event.getComponentSetDescriptor();
if ( !( componentSetDescriptor instanceof MavenPluginDescriptor ) )
if ( !(componentSetDescriptor instanceof MavenPluginDescriptor) )
{
return;
}
@ -194,8 +189,7 @@ public class DefaultPluginManager
}
// TODO: don't throw Exception
public void verifyPluginForGoal( String goalName, MavenSession session )
throws Exception
public void verifyPluginForGoal( String goalName, MavenSession session ) throws Exception
{
String pluginId = getPluginId( goalName );
@ -203,8 +197,7 @@ public class DefaultPluginManager
}
// TODO: don't throw Exception
public void verifyPlugin( String pluginId, MavenSession session )
throws Exception
public void verifyPlugin( String pluginId, MavenSession session ) throws Exception
{
if ( !isPluginInstalled( pluginId ) )
{
@ -223,8 +216,7 @@ public class DefaultPluginManager
}
// TODO: don't throw Exception
protected void addPlugin( Artifact pluginArtifact, MavenSession session )
throws Exception
protected void addPlugin( Artifact pluginArtifact, MavenSession session ) throws Exception
{
// TODO: these should be configured, not instantiated here
@ -234,17 +226,19 @@ public class DefaultPluginManager
MavenMetadataSource metadataSource = new MavenMetadataSource( artifactResolver, mavenProjectBuilder );
( (ArtifactEnabledContainer) container ).addComponent( pluginArtifact, artifactResolver,
remotePluginRepositories, session.getLocalRepository(),
metadataSource, artifactFilter );
((ArtifactEnabledContainer) container).addComponent( pluginArtifact,
artifactResolver,
remotePluginRepositories,
session.getLocalRepository(),
metadataSource,
artifactFilter );
}
// ----------------------------------------------------------------------
// Plugin execution
// ----------------------------------------------------------------------
public PluginExecutionResponse executeMojo( MavenSession session, String goalName )
throws GoalExecutionException
public PluginExecutionResponse executeMojo( MavenSession session, String goalName ) throws GoalExecutionException
{
try
{
@ -281,7 +275,7 @@ public class DefaultPluginManager
try
{
// getLogger().info( "[" + mojoDescriptor.getId() + "]" );
// getLogger().info( "[" + mojoDescriptor.getId() + "]" );
request = new PluginExecutionRequest( DefaultPluginManager.createParameters( mojoDescriptor, session ) );
@ -299,7 +293,7 @@ public class DefaultPluginManager
try
{
plugin = (Plugin) container.lookup( Plugin.ROLE, goalName );
// !! This is ripe for refactoring to an aspect.
// Event monitoring.
String event = MavenEvents.MOJO_EXECUTION;
@ -309,10 +303,10 @@ public class DefaultPluginManager
try
{
plugin.execute( request, response );
dispatcher.dispatchEnd( event, goalName );
}
catch(Exception e)
catch ( Exception e )
{
session.getEventDispatcher().dispatchError( event, goalName, e );
throw e;
@ -336,8 +330,7 @@ public class DefaultPluginManager
}
// TODO: don't throw Exception
private void releaseComponents( MojoDescriptor goal, PluginExecutionRequest request )
throws Exception
private void releaseComponents( MojoDescriptor goal, PluginExecutionRequest request ) throws Exception
{
if ( request != null && request.getParameters() != null )
{
@ -363,8 +356,7 @@ public class DefaultPluginManager
// Mojo Parameter Handling
// ----------------------------------------------------------------------
public static Map createParameters( MojoDescriptor goal, MavenSession session )
throws PluginConfigurationException
public static Map createParameters( MojoDescriptor goal, MavenSession session ) throws PluginConfigurationException
{
Map map = null;
@ -412,7 +404,8 @@ public class DefaultPluginManager
// ----------------------------------------------------------------------
// We will perform a basic check here for parameters values that are
// required. Required parameters can't be null so we throw an
// Exception in the case where they are. We probably want some pluggable
// Exception in the case where they are. We probably want some
// pluggable
// mechanism here but this will catch the most obvious of
// misconfigurations.
// ----------------------------------------------------------------------
@ -456,8 +449,10 @@ public class DefaultPluginManager
{
StringBuffer message = new StringBuffer();
message.append( "The '" + parameter.getName() ).append( "' parameter is required for the execution of the " ).append(
mojo.getId() ).append( " mojo and cannot be null." );
message.append( "The '" + parameter.getName() )
.append( "' parameter is required for the execution of the " )
.append( mojo.getId() )
.append( " mojo and cannot be null." );
return message.toString();
}
@ -466,9 +461,7 @@ public class DefaultPluginManager
// Lifecycle
// ----------------------------------------------------------------------
public void contextualize( Context context )
throws ContextException
public void contextualize( Context context ) throws ContextException
{
container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
}
@ -476,10 +469,17 @@ public class DefaultPluginManager
public void initialize()
{
// TODO: configure this from bootstrap or scan lib
artifactFilter = new ExclusionSetFilter( new String[]{"maven-core", "maven-artifact", "maven-model",
"maven-monitor", "maven-plugin", "plexus-container-api",
"plexus-container-default", "plexus-artifact-container",
"wagon-provider-api", "classworlds"} );
artifactFilter = new ExclusionSetFilter( new String[] {
"maven-core",
"maven-artifact",
"maven-model",
"maven-monitor",
"maven-plugin",
"plexus-container-api",
"plexus-container-default",
"plexus-artifact-container",
"wagon-provider-api",
"classworlds" } );
// TODO: move this to be configurable from the Maven component
remotePluginRepositories = new HashSet();
@ -492,8 +492,7 @@ public class DefaultPluginManager
// Artifact resolution
// ----------------------------------------------------------------------
private void resolveTransitiveDependencies( MavenSession context )
throws ArtifactResolutionException
private void resolveTransitiveDependencies( MavenSession context ) throws ArtifactResolutionException
{
MavenProject project = context.getProject();
@ -511,8 +510,7 @@ public class DefaultPluginManager
// Artifact downloading
// ----------------------------------------------------------------------
private void downloadDependencies( MavenSession context )
throws GoalExecutionException
private void downloadDependencies( MavenSession context ) throws GoalExecutionException
{
try
{

View File

@ -18,30 +18,27 @@ package org.apache.maven.plugin;
*/
import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.goal.GoalExecutionException;
import org.apache.maven.lifecycle.GoalExecutionException;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
/**
* @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 interface PluginManager
{
String ROLE = PluginManager.class.getName();
PluginExecutionResponse executeMojo( MavenSession session, String goalName )
throws GoalExecutionException;
PluginExecutionResponse executeMojo( MavenSession session, String goalName ) throws GoalExecutionException;
MojoDescriptor getMojoDescriptor( String goalId );
// TODO: don't throw Exception
void verifyPluginForGoal( String goalName, MavenSession session )
throws Exception;
void verifyPluginForGoal( String goalName, MavenSession session ) throws Exception;
// TODO: don't throw Exception
void verifyPlugin( String pluginId, MavenSession session )
throws Exception;
void verifyPlugin( String pluginId, MavenSession session ) throws Exception;
PluginDescriptor getPluginDescriptor( String pluginId );
}
}

View File

@ -39,15 +39,13 @@ import java.util.List;
import java.util.Set;
/**
* The concern of the project is provide runtime values based on the model.
* <p/>
* The values in the model remain untouched but during the process of building
* a project notions like inheritance and interpolation can be added. This allows
* to have an entity which is useful in a runtime while preserving the model so that
* it can be marshalled and unmarshalled without being tainted by runtime
* requirements.
* <p/>
* We need to leave the model intact because we don't want the following:
* The concern of the project is provide runtime values based on the model. <p/>
* The values in the model remain untouched but during the process of building a
* project notions like inheritance and interpolation can be added. This allows
* to have an entity which is useful in a runtime while preserving the model so
* that it can be marshalled and unmarshalled without being tainted by runtime
* requirements. <p/>We need to leave the model intact because we don't want
* the following:
* <ol>
* <li>We don't want interpolated values being written back into the model.
* <li>We don't want inherited values being written back into the model.
@ -67,6 +65,7 @@ public class MavenProject
{
this.model = model;
}
// ----------------------------------------------------------------------
// Accessors
// ----------------------------------------------------------------------
@ -116,7 +115,7 @@ public class MavenProject
{
return model.getDependencies();
}
public DependencyManagement getDependencyManagement()
{
return model.getDependencyManagement();
@ -126,7 +125,8 @@ public class MavenProject
// Test and compile sourceroots.
// ----------------------------------------------------------------------
//!!! Refactor, collect the list of compile source roots and create a path1:path2
//!!! Refactor, collect the list of compile source roots and create a
// path1:path2
// type construct from the list instead of the other way around. jvz.
private String compileSourceRoots = "";
@ -239,7 +239,8 @@ public class MavenProject
if ( isAddedToClasspath( a ) )
{
// TODO: let the scope handler deal with this
if ( a.getScope() == null || "test".equals( a.getScope() ) || "compile".equals( a.getScope() ) || "runtime".equals( a.getScope() ) )
if ( a.getScope() == null || "test".equals( a.getScope() ) || "compile".equals( a.getScope() )
|| "runtime".equals( a.getScope() ) )
{
list.add( a.getPath() );
}
@ -327,7 +328,7 @@ public class MavenProject
public void setType( String type )
{
model.setType( type );
model.setType( type );
}
public void setInceptionYear( String inceptionYear )
@ -540,24 +541,10 @@ public class MavenProject
return model.getRepositories();
}
// ----------------------------------------------------------------------
// Decorators
// ----------------------------------------------------------------------
public List getPreGoals()
{
return model.getPreGoals();
}
public List getPostGoals()
{
return model.getPostGoals();
}
// ----------------------------------------------------------------------
// Plugins
// ----------------------------------------------------------------------
public List getPlugins()
{
return model.getPlugins();

View File

@ -17,20 +17,22 @@ package org.apache.maven.project.inheritance;
* ====================================================================
*/
import org.apache.maven.model.Build;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.DependencyManagement;
import org.apache.maven.model.Goal;
import org.apache.maven.model.Model;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.PostGoal;
import org.apache.maven.model.PreGoal;
import org.apache.maven.model.PluginManagement;
import org.apache.maven.model.Repository;
import org.apache.maven.model.Scm;
import org.apache.maven.model.UnitTest;
import org.codehaus.plexus.util.StringUtils;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;
/**
@ -127,6 +129,275 @@ public class DefaultModelInheritanceAssembler
}
// Scm
assembleScmInheritance( child, parent );
// ciManagement
if ( child.getCiManagement() == null )
{
child.setCiManagement( parent.getCiManagement() );
}
// developers
if ( child.getDevelopers().size() == 0 )
{
child.setDevelopers( parent.getDevelopers() );
}
// developers
if ( child.getContributors().size() == 0 )
{
child.setContributors( parent.getContributors() );
}
// mailingLists
if ( child.getMailingLists().size() == 0 )
{
child.setMailingLists( parent.getMailingLists() );
}
// reports
if ( child.getReports().size() == 0 )
{
child.setReports( parent.getReports() );
}
// Build
assembleBuildInheritance( child, parent );
// Dependencies :: aggregate
List dependencies = parent.getDependencies();
for ( Iterator iterator = dependencies.iterator(); iterator.hasNext(); )
{
Dependency dependency = (Dependency) iterator.next();
child.addDependency( dependency );
}
// Repositories :: aggregate
List parentRepositories = parent.getRepositories();
List childRepositories = child.getRepositories();
for ( Iterator iterator = parentRepositories.iterator(); iterator.hasNext(); )
{
Repository repository = (Repository) iterator.next();
if ( !childRepositories.contains( repository ) )
{
child.addRepository( repository );
}
}
// Plugins :: aggregate
List parentPlugins = parent.getPlugins();
List childPlugins = child.getPlugins();
for ( Iterator iterator = parentPlugins.iterator(); iterator.hasNext(); )
{
Plugin plugin = (Plugin) iterator.next();
if ( !childPlugins.contains( plugin ) )
{
child.addPlugin( plugin );
}
}
assembleDependencyManagementInheritance( child, parent );
assemblePluginManagementInheritance( child, parent );
}
private void assemblePluginManagementInheritance( Model child, Model parent )
{
PluginManagement parentPluginMgmt = parent.getPluginManagement();
PluginManagement childPluginMgmt = child.getPluginManagement();
if ( parentPluginMgmt != null )
{
if ( childPluginMgmt == null )
{
child.setPluginManagement( parentPluginMgmt );
}
else
{
List childPlugins = childPluginMgmt.getPlugins();
Map mappedChildPlugins = new TreeMap();
for ( Iterator it = childPlugins.iterator(); it.hasNext(); )
{
Plugin plugin = (Plugin) it.next();
mappedChildPlugins.put( plugin.getId(), plugin );
}
for ( Iterator it = parentPluginMgmt.getPlugins().iterator(); it.hasNext(); )
{
Plugin plugin = (Plugin) it.next();
if ( !mappedChildPlugins.containsKey( plugin.getId() ) )
{
childPluginMgmt.addPlugin( plugin );
}
else
{
Plugin childPlugin = (Plugin) mappedChildPlugins.get( plugin.getId() );
Map mappedChildGoals = new TreeMap();
for ( Iterator itGoals = childPlugin.getGoals().iterator(); itGoals.hasNext(); )
{
Goal goal = (Goal) itGoals.next();
mappedChildGoals.put( goal.getId(), goal );
}
for ( Iterator itGoals = plugin.getGoals().iterator(); itGoals.hasNext(); )
{
Goal parentGoal = (Goal) itGoals.next();
Goal childGoal = (Goal) mappedChildGoals.get( parentGoal.getId() );
if ( childGoal == null )
{
childPlugin.addGoal( parentGoal );
}
else
{
Boolean disabled = childGoal.isDisabled();
if ( disabled == null )
{
childGoal.setDisabled( parentGoal.isDisabled() );
Properties conf = new Properties( childGoal.getConfiguration() );
conf.putAll( parentGoal.getConfiguration() );
childGoal.setConfiguration( conf );
}
}
}
}
}
}
}
}
private void assembleDependencyManagementInheritance( Model child, Model parent )
{
DependencyManagement parentDepMgmt = parent.getDependencyManagement();
DependencyManagement childDepMgmt = child.getDependencyManagement();
if ( parentDepMgmt != null )
{
if ( childDepMgmt == null )
{
child.setDependencyManagement( parentDepMgmt );
}
else
{
List childDeps = childDepMgmt.getDependencies();
Map mappedChildDeps = new TreeMap();
for ( Iterator it = childDeps.iterator(); it.hasNext(); )
{
Dependency dep = (Dependency) it.next();
mappedChildDeps.put( dep.getManagementKey(), dep );
}
for ( Iterator it = parentDepMgmt.getDependencies().iterator(); it.hasNext(); )
{
Dependency dep = (Dependency) it.next();
if ( !mappedChildDeps.containsKey( dep.getManagementKey() ) )
{
childDepMgmt.addDependency( dep );
}
}
}
}
}
private void assembleBuildInheritance( Model child, Model parent )
{
Build childBuild = child.getBuild();
Build parentBuild = parent.getBuild();
if ( childBuild == null )
{
child.setBuild( parentBuild );
}
else
{
// The build has been set but we want to step in here and fill in
// values
// that have not been set by the child.
if ( childBuild.getDirectory() == null )
{
childBuild.setDirectory( parentBuild.getDirectory() );
}
if ( childBuild.getSourceDirectory() == null )
{
childBuild.setSourceDirectory( parentBuild.getSourceDirectory() );
}
if ( childBuild.getUnitTestSourceDirectory() == null )
{
childBuild.setUnitTestSourceDirectory( parentBuild.getUnitTestSourceDirectory() );
}
if ( childBuild.getOutput() == null )
{
childBuild.setOutput( parentBuild.getOutput() );
}
if ( childBuild.getTestOutput() == null )
{
childBuild.setTestOutput( parentBuild.getTestOutput() );
}
if ( childBuild.getFinalName() == null )
{
childBuild.setFinalName( parentBuild.getFinalName() );
}
List resources = childBuild.getResources();
if ( resources == null || resources.isEmpty() )
{
childBuild.setResources( parentBuild.getResources() );
}
UnitTest childUnitTest = childBuild.getUnitTest();
UnitTest parentUnitTest = parentBuild.getUnitTest();
if ( childUnitTest == null )
{
childBuild.setUnitTest( parentUnitTest );
}
else
{
if ( childUnitTest.getIncludes().size() == 0 )
{
childUnitTest.setIncludes( parentUnitTest.getIncludes() );
}
if ( childUnitTest.getExcludes().size() == 0 )
{
childUnitTest.setExcludes( parentUnitTest.getExcludes() );
}
List testResources = childUnitTest.getResources();
if ( testResources == null || testResources.isEmpty() )
{
childUnitTest.setResources( parentUnitTest.getResources() );
}
}
}
}
private void assembleScmInheritance( Model child, Model parent )
{
if ( parent.getScm() != null )
{
Scm parentScm = parent.getScm();
@ -161,204 +432,6 @@ public class DefaultModelInheritanceAssembler
childScm.getBranches().addAll( parentScm.getBranches() );
}
}
// ciManagement
if ( child.getCiManagement() == null )
{
child.setCiManagement( parent.getCiManagement() );
}
// developers
if ( child.getDevelopers().size() == 0 )
{
child.setDevelopers( parent.getDevelopers() );
}
// developers
if ( child.getContributors().size() == 0 )
{
child.setContributors( parent.getContributors() );
}
// mailingLists
if ( child.getMailingLists().size() == 0 )
{
child.setMailingLists( parent.getMailingLists() );
}
// reports
if ( child.getReports().size() == 0 )
{
child.setReports( parent.getReports() );
}
// Build
if ( child.getBuild() == null )
{
child.setBuild( parent.getBuild() );
}
else
{
// The build has been set but we want to step in here and fill in
// values
// that have not been set by the child.
if ( child.getBuild().getDirectory() == null )
{
child.getBuild().setDirectory( parent.getBuild().getDirectory() );
}
if ( child.getBuild().getSourceDirectory() == null )
{
child.getBuild().setSourceDirectory( parent.getBuild().getSourceDirectory() );
}
if ( child.getBuild().getUnitTestSourceDirectory() == null )
{
child.getBuild().setUnitTestSourceDirectory( parent.getBuild().getUnitTestSourceDirectory() );
}
if ( child.getBuild().getOutput() == null )
{
child.getBuild().setOutput( parent.getBuild().getOutput() );
}
if ( child.getBuild().getTestOutput() == null )
{
child.getBuild().setTestOutput( parent.getBuild().getTestOutput() );
}
if ( child.getBuild().getFinalName() == null )
{
child.getBuild().setFinalName( parent.getBuild().getFinalName() );
}
List resources = child.getBuild().getResources();
if ( resources == null || resources.isEmpty() )
{
child.getBuild().setResources( parent.getBuild().getResources() );
}
if ( child.getBuild().getUnitTest() == null )
{
child.getBuild().setUnitTest( parent.getBuild().getUnitTest() );
}
else
{
if ( child.getBuild().getUnitTest().getIncludes().size() == 0 )
{
child.getBuild().getUnitTest().setIncludes( parent.getBuild().getUnitTest().getIncludes() );
}
if ( child.getBuild().getUnitTest().getExcludes().size() == 0 )
{
child.getBuild().getUnitTest().setExcludes( parent.getBuild().getUnitTest().getExcludes() );
}
List testResources = child.getBuild().getUnitTest().getResources();
if ( testResources == null || testResources.isEmpty() )
{
child.getBuild().getUnitTest().setResources( parent.getBuild().getUnitTest().getResources() );
}
}
}
// Dependencies :: aggregate
List dependencies = parent.getDependencies();
for ( Iterator iterator = dependencies.iterator(); iterator.hasNext(); )
{
Dependency dependency = (Dependency) iterator.next();
child.addDependency( dependency );
}
// PreGoals :: aggregate
List preGoals = parent.getPreGoals();
for ( Iterator iterator = preGoals.iterator(); iterator.hasNext(); )
{
PreGoal preGoal = (PreGoal) iterator.next();
child.addPreGoal( preGoal );
}
// PostGoals :: aggregate
List postGoals = parent.getPostGoals();
for ( Iterator iterator = postGoals.iterator(); iterator.hasNext(); )
{
PostGoal postGoal = (PostGoal) iterator.next();
child.addPostGoal( postGoal );
}
// Repositories :: aggregate
List parentRepositories = parent.getRepositories();
List childRepositories = child.getRepositories();
for ( Iterator iterator = parentRepositories.iterator(); iterator.hasNext(); )
{
Repository repository = (Repository) iterator.next();
if ( !childRepositories.contains( repository ) )
{
child.addRepository( repository );
}
}
// Plugins :: aggregate
List parentPlugins = parent.getPlugins();
List childPlugins = child.getPlugins();
for ( Iterator iterator = parentPlugins.iterator(); iterator.hasNext(); )
{
Plugin plugin = (Plugin) iterator.next();
if ( !childPlugins.contains( plugin ) )
{
child.addPlugin( plugin );
}
}
DependencyManagement parentDepMgmt = parent.getDependencyManagement();
DependencyManagement childDepMgmt = child.getDependencyManagement();
if ( parentDepMgmt != null )
{
if ( childDepMgmt == null )
{
child.setDependencyManagement( parentDepMgmt );
}
else
{
List parentDeps = parentDepMgmt.getDependencies();
Map mappedParentDeps = new TreeMap();
for ( Iterator it = parentDeps.iterator(); it.hasNext(); )
{
Dependency dep = (Dependency) it.next();
mappedParentDeps.put( dep.getManagementKey(), dep );
}
List deps = new ArrayList( parentDeps );
for ( Iterator it = childDepMgmt.getDependencies().iterator(); it.hasNext(); )
{
Dependency dep = (Dependency) it.next();
if ( !mappedParentDeps.containsKey( dep.getManagementKey() ) )
{
deps.add( dep );
}
}
childDepMgmt.setDependencies( deps );
}
}
}
}

View File

@ -18,8 +18,12 @@ package org.apache.maven.project.injection;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.DependencyManagement;
import org.apache.maven.model.Goal;
import org.apache.maven.model.Model;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginManagement;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@ -36,11 +40,99 @@ public class DefaultModelDefaultsInjector
public void injectDefaults( Model model )
{
injectDependencyDefaults( model.getDependencies(), model.getDependencyManagement() );
injectPluginDefaults( model.getPlugins(), model.getPluginManagement() );
}
private void injectPluginDefaults( List plugins, PluginManagement pluginManagement )
{
if ( pluginManagement != null )
{
// a given project's plugins should be smaller than the
// group-defined defaults set...
// in other words, the project's plugins will probably be a subset
// of
// those specified in defaults.
Map pluginMap = new TreeMap();
for ( Iterator it = plugins.iterator(); it.hasNext(); )
{
Plugin plugin = (Plugin) it.next();
pluginMap.put( plugin.getId(), plugin );
}
List managedPlugins = pluginManagement.getPlugins();
for ( Iterator it = managedPlugins.iterator(); it.hasNext(); )
{
Plugin def = (Plugin) it.next();
String key = def.getId();
Plugin plugin = (Plugin) pluginMap.get( key );
if ( plugin != null )
{
mergePluginWithDefaults( plugin, def );
}
}
}
}
private void mergePluginWithDefaults( Plugin plugin, Plugin def )
{
if ( plugin.getVersion() == null && def.getVersion() != null )
{
plugin.setVersion( def.getVersion() );
}
Boolean disabled = plugin.isDisabled();
if ( disabled == null )
{
plugin.setDisabled( def.isDisabled() );
}
Map goalMap = new TreeMap();
List pluginGoals = plugin.getGoals();
if ( pluginGoals != null )
{
for ( Iterator it = pluginGoals.iterator(); it.hasNext(); )
{
Goal goal = (Goal) it.next();
goalMap.put( goal.getId(), goal );
}
}
List defGoals = def.getGoals();
if ( defGoals != null )
{
for ( Iterator it = defGoals.iterator(); it.hasNext(); )
{
Goal defaultGoal = (Goal) it.next();
Goal localGoal = (Goal) goalMap.get( defaultGoal.getId() );
if ( localGoal == null )
{
goalMap.put( defaultGoal.getId(), defaultGoal );
}
else
{
Properties conf = defaultGoal.getConfiguration();
conf.putAll( localGoal.getConfiguration() );
localGoal.setConfiguration( conf );
}
}
}
plugin.setGoals( new ArrayList( goalMap.values() ) );
Properties props = new Properties( def.getConfiguration() );
props.putAll( plugin.getConfiguration() );
plugin.setConfiguration( props );
}
/**
* Added: Feb 1, 2005 by jdcasey
*/
private void injectDependencyDefaults( List dependencies, DependencyManagement dependencyManagement )
{
if ( dependencyManagement != null )
@ -56,9 +148,9 @@ public class DefaultModelDefaultsInjector
depsMap.put( dep.getManagementKey(), dep );
}
List dependencyDefaults = dependencyManagement.getDependencies();
List managedDependencies = dependencyManagement.getDependencies();
for ( Iterator it = dependencyDefaults.iterator(); it.hasNext(); )
for ( Iterator it = managedDependencies.iterator(); it.hasNext(); )
{
Dependency def = (Dependency) it.next();
String key = def.getManagementKey();
@ -66,16 +158,13 @@ public class DefaultModelDefaultsInjector
Dependency dep = (Dependency) depsMap.get( key );
if ( dep != null )
{
mergeWithDefaults( dep, def );
mergeDependencyWithDefaults( dep, def );
}
}
}
}
/**
* Added: Feb 1, 2005 by jdcasey
*/
private void mergeWithDefaults( Dependency dep, Dependency def )
private void mergeDependencyWithDefaults( Dependency dep, Dependency def )
{
if ( dep.getScope() == null && def.getScope() != null )
{
@ -92,4 +181,4 @@ public class DefaultModelDefaultsInjector
dep.setProperties( props );
}
}
}

View File

@ -1,75 +0,0 @@
package org.apache.maven.util;
/* ====================================================================
* 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.execution.MavenSession;
import org.apache.maven.execution.MavenSession;
/**
* @author jdcasey
*/
public abstract class AbstractGoalVisitor
implements GoalVisitor
{
protected AbstractGoalVisitor()
{
}
public boolean shouldVisit( String goal, MavenSession session )
throws GraphTraversalException
{
// visit all by default
return true;
}
public void visitGoal( String goal, MavenSession session )
throws GraphTraversalException
{
// do nothing by default
}
public void visitPostGoal( String goal, String postGoal, MavenSession session )
throws GraphTraversalException
{
// do nothing by default
}
public void visitPreGoal( String goal, String preGoal, MavenSession session )
throws GraphTraversalException
{
// do nothing by default
}
public void visitPrereq( String goal, String prereq, MavenSession session )
throws GraphTraversalException
{
// do nothing by default
}
public void preVisit( String goal, MavenSession session )
throws GraphTraversalException
{
// do nothing by default
}
public void postVisit( String goal, MavenSession session )
throws GraphTraversalException
{
// do nothing by default
}
}

View File

@ -1,47 +0,0 @@
package org.apache.maven.util;
/* ====================================================================
* 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.execution.MavenSession;
/**
* @author jdcasey
*/
public interface GoalVisitor
{
boolean shouldVisit( String goal, MavenSession session )
throws GraphTraversalException;
void preVisit( String goal, MavenSession session )
throws GraphTraversalException;
void visitGoal( String goal, MavenSession session )
throws GraphTraversalException;
void visitPreGoal( String goal, String preGoal, MavenSession session )
throws GraphTraversalException;
void visitPrereq( String goal, String prereq, MavenSession session )
throws GraphTraversalException;
void visitPostGoal( String goal, String postGoal, MavenSession session )
throws GraphTraversalException;
void postVisit( String goal, MavenSession session )
throws GraphTraversalException;
}

View File

@ -1,87 +0,0 @@
package org.apache.maven.util;
/* ====================================================================
* 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.execution.MavenSession;
import org.apache.maven.plugin.PluginManager;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import java.util.Iterator;
import java.util.List;
/**
* @author jdcasey
*/
public final class GoalWalker
{
public static void walk( String goal, MavenSession session, GoalVisitor visitor )
throws GraphTraversalException
{
if ( visitor.shouldVisit( goal, session ) )
{
visitor.preVisit( goal, session );
List preGoals = session.getPreGoals( goal );
if ( preGoals != null )
{
for ( Iterator it = preGoals.iterator(); it.hasNext(); )
{
String preGoal = (String) it.next();
visitor.visitPreGoal( goal, preGoal, session );
}
}
PluginManager pluginManager = session.getPluginManager();
MojoDescriptor mojoDescriptor = pluginManager.getMojoDescriptor( goal );
if ( mojoDescriptor != null )
{
List prereqs = mojoDescriptor.getPrereqs();
if ( prereqs != null )
{
for ( Iterator it = prereqs.iterator(); it.hasNext(); )
{
String prereq = (String) it.next();
visitor.visitPrereq( goal, prereq, session );
}
}
}
visitor.visitGoal( goal, session );
List postGoals = session.getPostGoals( goal );
if ( postGoals != null )
{
for ( Iterator it = postGoals.iterator(); it.hasNext(); )
{
String postGoal = (String) it.next();
visitor.visitPostGoal( goal, postGoal, session );
}
}
visitor.postVisit( goal, session );
}
}
}

View File

@ -1,37 +0,0 @@
package org.apache.maven.util;
/* ====================================================================
* 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.
* ====================================================================
*/
/**
* @author jdcasey
*/
public class GraphTraversalException
extends Exception
{
public GraphTraversalException( Throwable cause )
{
super( cause );
}
public GraphTraversalException( String message, Throwable cause )
{
super( message, cause );
}
}

View File

@ -27,11 +27,11 @@ import java.util.StringTokenizer;
/**
* Using simple dotted expressions extract the values from a MavenProject
* instance, For example we might want to extract a value like:
*
* project.build.sourceDirectory
*
* @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: ReflectionValueExtractor.java,v 1.2 2005/03/01 07:05:33 brett
* Exp $
*/
public class ReflectionValueExtractor
{
@ -48,8 +48,7 @@ public class ReflectionValueExtractor
}
// TODO: don't throw Exception
public static Object evaluate( String expression, Object root )
throws Exception
public static Object evaluate( String expression, Object root ) throws Exception
{
// ----------------------------------------------------------------------
// Remove the leading "project" token
@ -66,12 +65,12 @@ public class ReflectionValueExtractor
StringTokenizer parser = new StringTokenizer( expression, "." );
while( parser.hasMoreTokens() )
while ( parser.hasMoreTokens() )
{
classMap = getClassMap( value.getClass() );
String token = parser.nextToken();
classMap = getClassMap( value.getClass() );
String methodName = "get" + StringUtils.capitalizeFirstLetter( token );
Method method = classMap.findMethod( methodName, args );
@ -86,7 +85,7 @@ public class ReflectionValueExtractor
{
classMap = (ClassMap) classMaps.get( clazz );
if( classMap == null )
if ( classMap == null )
{
classMap = new ClassMap( clazz );
}

View File

@ -18,9 +18,6 @@
<requirement>
<role>org.apache.maven.project.MavenProjectBuilder</role>
</requirement>
<requirement>
<role>org.apache.maven.lifecycle.session.MavenSessionPhaseManager</role>
</requirement>
<requirement>
<role>org.apache.maven.lifecycle.LifecycleExecutor</role>
</requirement>
@ -38,39 +35,6 @@
<default-bundle-name>org.apache.maven.messages.messages</default-bundle-name>
</configuration>
</component>
<!--
|
|
|
-->
<component>
<role>org.apache.maven.lifecycle.session.MavenSessionPhaseManager</role>
<implementation>org.apache.maven.lifecycle.session.DefaultMavenSessionPhaseManager</implementation>
<configuration>
<lifecycle-phases>
<lifecycle-phase implementation="org.apache.maven.lifecycle.session.phase.GoalExecutionPhase"/>
</lifecycle-phases>
</configuration>
</component>
<!--
|
|
|
-->
<component>
<role>org.apache.maven.lifecycle.goal.MavenGoalPhaseManager</role>
<implementation>org.apache.maven.lifecycle.goal.DefaultMavenGoalPhaseManager</implementation>
<configuration>
<lifecycle-phases>
<lifecycle-phase implementation="org.apache.maven.lifecycle.goal.phase.PluginResolutionPhase"/>
<lifecycle-phase implementation="org.apache.maven.lifecycle.goal.phase.GoalMappingPhase"/>
<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-phases>
</configuration>
</component>
<!--
|
|

View File

@ -16,23 +16,14 @@ package org.apache.maven;
* limitations under the License.
*/
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.lifecycle.goal.MavenGoalExecutionContext;
import org.apache.maven.monitor.event.DefaultEventDispatcher;
import org.apache.maven.monitor.logging.DefaultLog;
import org.apache.maven.monitor.logging.Log;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.PluginManager;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.execution.MavenSession;
import org.codehaus.plexus.ArtifactEnabledPlexusTestCase;
import java.io.File;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
* @version $Id$
@ -86,61 +77,4 @@ public class MavenTestCase
return projectBuilder.build( pom, getLocalRepository() );
}
// ----------------------------------------------------------------------
// Execution context
// ----------------------------------------------------------------------
protected MavenGoalExecutionContext createGoalExecutionContext()
throws Exception
{
return createGoalExecutionContext( null, null );
}
protected MavenGoalExecutionContext createGoalExecutionContext( File pom )
throws Exception
{
return createGoalExecutionContext( pom, null );
}
protected MavenGoalExecutionContext createGoalExecutionContext( String goal )
throws Exception
{
return createGoalExecutionContext( null, goal );
}
protected MavenGoalExecutionContext createGoalExecutionContext( File pom, String goal )
throws Exception
{
MavenProject project;
if ( pom != null )
{
project = getProject( pom );
}
else
{
File f = getTestFile( "target/test-classes/pom.xml" );
project = getProject( f );
}
return createGoalExecutionContext( project, getLocalRepository(), goal );
}
protected MavenGoalExecutionContext createGoalExecutionContext( MavenProject project,
ArtifactRepository localRepository,
String goal )
{
List goals = new ArrayList();
Log log = new DefaultLog(getContainer().getLogger());
MavenSession session = new MavenSession( getContainer(), pluginManager, localRepository, new DefaultEventDispatcher(), log, goals );
session.setProject( project );
MavenGoalExecutionContext context = new MavenGoalExecutionContext( session, goal );
return context;
}
}

View File

@ -1,24 +0,0 @@
package org.apache.maven.lifecycle;
import org.apache.maven.MavenTestCase;
import org.apache.maven.lifecycle.goal.MavenGoalPhaseManager;
import java.util.List;
/**
* @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
{
MavenGoalPhaseManager mlm = (MavenGoalPhaseManager) lookup( MavenGoalPhaseManager.ROLE );
List lifecyclePhases = mlm.getLifecyclePhases();
assertEquals( 6, lifecyclePhases.size() );
}
}

View File

@ -1,324 +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 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;
import org.apache.maven.MavenTestCase;
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;
/** The point of this test class is to check out the functioning of the
* plugin resolution, goal mapping, and goal resolution phases. These are
* intertwined here to make testing easier, but should be separated into their
* own unit tests.
*
* @author jdcasey
*/
public class GoalAssemblySubProcessTest
extends MavenTestCase
{
/*
* <!-- 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 = "resolveTest:t1-main";
String preGoal = "resolveTest:t1-preGoal";
String postGoal = "resolveTest:t1-postGoal";
PreGoal pg = new PreGoal();
pg.setAttain( preGoal );
pg.setName( mainGoal );
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();
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, preGoals, postGoals, order, messages );
}
/*
* <!-- 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 = "resolveTest:t2-main";
String prereq = "resolveTest:t2-prereq";
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, Collections.EMPTY_LIST, Collections.EMPTY_LIST, order, messages );
}
/*
* <!-- 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 = "resolveTest:t3-main";
String prereq = "resolveTest:t3-prereq";
String preGoal = "resolveTest:t3-preGoal";
String postGoal = "resolveTest:t3-postGoal";
PreGoal pg = new PreGoal();
pg.setAttain( preGoal );
pg.setName( mainGoal );
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();
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, preGoals, postGoals, order, messages );
}
/*
* <!-- 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 = "resolveTest:t4-main";
String prereq = "resolveTest:t4-prereq";
String preGoal = "resolveTest:t4-prereq-preGoal";
String postGoal = "resolveTest:t4-prereq-postGoal";
PreGoal pg = new PreGoal();
pg.setAttain( preGoal );
pg.setName( prereq );
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();
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, preGoals, postGoals, order, messages );
}
/*
* <!-- 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 = "resolveTest:t5-main";
String prereq = "resolveTest:t5-prereq";
String preGoal = "resolveTest:t5-preGoal";
PreGoal pg = new PreGoal();
pg.setAttain( preGoal );
pg.setName( mainGoal );
List preGoals = new LinkedList();
preGoals.add( pg );
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, preGoals, Collections.EMPTY_LIST, order, messages );
}
private void runTest( String mainGoal, List preGoals, List postGoals, List expectedOrder, Map messages )
throws Exception
{
Model model = new Model();
model.setPreGoals( preGoals );
model.setPostGoals( postGoals );
MavenProject project = new MavenProject( model );
MavenGoalExecutionContext context = createGoalExecutionContext( project, getLocalRepository(), mainGoal );
context.setGoalName( mainGoal );
PluginResolutionPhase pluginPhase = new PluginResolutionPhase();
GoalMappingPhase mappingPhase = new GoalMappingPhase();
GoalResolutionPhase goalPhase = new GoalResolutionPhase();
pluginPhase.execute( context );
mappingPhase.execute( context );
goalPhase.execute( context );
List goals = context.getResolvedGoals();
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 );
}
}
}

View File

@ -2,11 +2,16 @@ package org.apache.maven.plugin;
import org.apache.maven.MavenTestCase;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.lifecycle.goal.MavenGoalExecutionContext;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Build;
import org.apache.maven.model.Model;
import org.apache.maven.monitor.event.DefaultEventDispatcher;
import org.apache.maven.monitor.logging.DefaultLog;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.codehaus.plexus.PlexusContainer;
import java.io.File;
import java.util.Collections;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
@ -17,8 +22,6 @@ public class PluginParameterExpressionEvaluatorTest
{
private MavenProject project;
private MavenGoalExecutionContext context;
protected void setUp()
throws Exception
{
@ -27,18 +30,36 @@ public class PluginParameterExpressionEvaluatorTest
File f = getTestFile( "src/test/resources/pom.xml" );
project = getProject( f );
context = createGoalExecutionContext();
}
public void testValueExtractionWithAPomValueContainingAPath()
throws Exception
{
Object value = PluginParameterExpressionEvaluator.evaluate( "#project.build.directory/classes", context.getSession() );
String expected = getTestFile( "target/test-classes/target/classes" ).getCanonicalPath();
ArtifactRepository repo = new ArtifactRepository("local", "here");
PluginManager mgr = (PluginManager)lookup(PluginManager.ROLE);
PlexusContainer container = getContainer();
MavenSession session = new MavenSession(container, mgr, repo, new DefaultEventDispatcher(), new DefaultLog(container.getLogger()), Collections.EMPTY_LIST);
Build build = new Build();
build.setDirectory(expected.substring(0, expected.length() - "/classes".length()));
Model model = new Model();
model.setBuild(build);
MavenProject project = new MavenProject(model);
project.setFile(new File("pom.xml").getCanonicalFile());
session.setProject(project);
Object value = PluginParameterExpressionEvaluator.evaluate( "#project.build.directory/classes", session );
String actual = new File( value.toString() ).getCanonicalPath();
System.out.println("Expected value: " + expected);
System.out.println("Resolved value: " + actual);
assertEquals( expected, actual );
}
@ -48,7 +69,12 @@ public class PluginParameterExpressionEvaluatorTest
{
String role = "#component.org.apache.maven.project.MavenProjectBuilder";
Object value = PluginParameterExpressionEvaluator.evaluate( role, context.getSession() );
ArtifactRepository repo = new ArtifactRepository();
PluginManager mgr = (PluginManager)lookup(PluginManager.ROLE);
PlexusContainer container = getContainer();
MavenSession session = new MavenSession(container, mgr, repo, new DefaultEventDispatcher(), new DefaultLog(container.getLogger()), Collections.EMPTY_LIST);
Object value = PluginParameterExpressionEvaluator.evaluate( role, session );
assertNotNull( value );
}
@ -56,7 +82,13 @@ public class PluginParameterExpressionEvaluatorTest
public void testLocalRepositoryExtraction()
throws Exception
{
Object value = PluginParameterExpressionEvaluator.evaluate( "#localRepository", context.getSession() );
ArtifactRepository repo = new ArtifactRepository("local", "target/repo");
PluginManager mgr = (PluginManager)lookup(PluginManager.ROLE);
PlexusContainer container = getContainer();
MavenSession session = new MavenSession(container, mgr, repo, new DefaultEventDispatcher(), new DefaultLog(container.getLogger()), Collections.EMPTY_LIST);
Object value = PluginParameterExpressionEvaluator.evaluate( "#localRepository", session );
assertEquals( "local", ((ArtifactRepository)value).getId() );
}

View File

@ -19,8 +19,6 @@ package org.apache.maven.project.inheritance;
import junit.framework.TestCase;
import org.apache.maven.model.Build;
import org.apache.maven.model.Model;
import org.apache.maven.model.PostGoal;
import org.apache.maven.model.PreGoal;
import org.apache.maven.model.Resource;
import org.apache.maven.model.Scm;
import org.apache.maven.model.UnitTest;
@ -69,19 +67,6 @@ public class DefaultModelInheritanceAssemblerTest
parentBuild.setUnitTest( parentUT );
parent.setBuild( parentBuild );
PreGoal preGoal1 = new PreGoal();
preGoal1.setName("compiler:compile");
preGoal1.setAttain("clean:clean");
parent.addPreGoal(preGoal1);
// hehe...try getting anything done with this one in place!
PostGoal postGoal1 = new PostGoal();
postGoal1.setName("jar:jar");
postGoal1.setAttain("clean:clean");
parent.addPostGoal(postGoal1);
Model child = new Model();
child.setType( "plugin" );
@ -95,12 +80,6 @@ public class DefaultModelInheritanceAssemblerTest
childBuild.setUnitTest( childUT );
child.setBuild( childBuild );
PreGoal preGoal2 = new PreGoal();
preGoal2.setName("compiler:compile");
preGoal2.setAttain("qdox:generate");
child.addPreGoal(preGoal2);
assembler.assembleModelInheritance( child, parent );
assertEquals( "source directory should be from parent", "src/main/java", child.getBuild().getSourceDirectory() );
@ -128,12 +107,6 @@ public class DefaultModelInheritanceAssemblerTest
assertEquals( "plugin", child.getType() );
assertEquals( "jar", parent.getType() );
assertEquals("merged child should have 2 preGoals", 2, child.getPreGoals().size());
assertTrue("preGoal should be inherited from parent", child.getPreGoals().contains(preGoal1));
assertTrue("preGoal should be preserved from child", child.getPreGoals().contains(preGoal2));
assertEquals("1 postGoal should be inherited from parent", 1, child.getPostGoals().size());
}
/**

View File

@ -20,6 +20,7 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
@ -146,9 +147,29 @@ public class MBoot
public static void main( String[] args ) throws Exception
{
MBoot mboot = new MBoot();
try
{
MBoot mboot = new MBoot();
mboot.run( args );
mboot.run( args );
}
catch ( InvocationTargetException e )
{
Throwable target = e.getTargetException();
if(target instanceof RuntimeException)
{
throw (RuntimeException)target;
}
else if(target instanceof Exception)
{
throw (Exception)target;
}
else
{
throw new RuntimeException(target);
}
}
}
public void run( String[] args ) throws Exception

View File

@ -407,6 +407,17 @@
<type>DependencyManagement</type>
</association>
</field>
<!-- [ jdcasey:06-Mar-2005 ] Added to handle version management, etc. for
| plugins to be used in sub-projects. -->
<field>
<name>pluginManagement</name>
<version>4.0.0</version>
<required>false</required>
<description><![CDATA[Default plugin information for grouped projects inheriting from this one.]]></description>
<association>
<type>PluginManagement</type>
</association>
</field>
<!-- @todo long run 4.0.0 may not need properties, with the parameters being specified
for the plugin directly -->
<field>
@ -422,24 +433,6 @@
<multiplicity>*</multiplicity>
</association>
</field>
<field>
<name>preGoals</name>
<version>4.0.0</version>
<description><![CDATA[Set of decorator(s) injected before the target goal(s).]]></description>
<association>
<type>PreGoal</type>
<multiplicity>*</multiplicity>
</association>
</field>
<field>
<name>postGoals</name>
<version>4.0.0</version>
<description><![CDATA[Set of decorator(s) injected after the target goal(s).]]></description>
<association>
<type>PostGoal</type>
<multiplicity>*</multiplicity>
</association>
</field>
<!-- @todo is this for javadoc only? maybe make it a plugin property? -->
<field xml.tagName="package">
<name>packageName</name>
@ -1546,38 +1539,6 @@
</field>
</fields>
</class>
<class>
<name>GoalDecorator</name>
<version>4.0.0</version>
<fields>
<field>
<name>name</name>
<version>4.0.0</version>
<description><![CDATA[The target goal which should be decorated.]]></description>
<type>String</type>
</field>
<field>
<name>attain</name>
<version>4.0.0</version>
<description><![CDATA[
The goal which should be injected into the execution chain.
]]></description>
<type>String</type>
</field>
</fields>
</class>
<class>
<superClass>GoalDecorator</superClass>
<name>PreGoal</name>
<version>4.0.0</version>
<fields></fields>
</class>
<class>
<superClass>GoalDecorator</superClass>
<name>PostGoal</name>
<version>4.0.0</version>
<fields></fields>
</class>
<!--
@ -1631,8 +1592,8 @@
<field>
<name>disabled</name>
<version>4.0.0</version>
<type>boolean</type>
<defaultValue>false</defaultValue>
<type>Boolean</type>
<!-- defaultValue>false</defaultValue -->
</field>
<field>
<name>configuration</name>
@ -1664,8 +1625,8 @@
<field>
<name>disabled</name>
<version>4.0.0</version>
<type>boolean</type>
<defaultValue>false</defaultValue>
<type>Boolean</type>
<!-- defaultValue>false</defaultValue -->
</field>
<field>
<name>configuration</name>
@ -1700,6 +1661,29 @@
</field>
</fields>
</class>
<class>
<name>PluginManagement</name>
<version>4.0.0</version>
<description>
Section for management of default plugin information for use in a group of POMs.
</description>
<fields>
<field>
<name>plugins</name>
<version>4.0.0</version>
<description>
The dependencies specified here are not validated until they
are referenced in a POM within the group. This allows the
specification of a "standard" version for a particular
dependency.
</description>
<association>
<type>Plugin</type>
<multiplicity>*</multiplicity>
</association>
</field>
</fields>
</class>
</classes>
</model>