You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by jv...@apache.org on 2004/03/21 00:20:17 UTC
cvs commit: maven-components/maven-core/src/main/java/org/apache/maven/werkz WerkzProject.java
jvanzyl 2004/03/20 15:20:17
Modified: maven-core/src/main/java/org/apache/maven DefaultMaven.java
Maven.java MavenConstants.java
UnknownGoalException.java
maven-core/src/main/java/org/apache/maven/cli
CLIManager.java
maven-core/src/main/java/org/apache/maven/plugin
PluginExecutionRequest.java
PluginExecutionResponse.java
maven-core/src/main/java/org/apache/maven/plugin/manager
DefaultPluginManagerManager.java PluginManager.java
PluginManagerManager.java
maven-core/src/main/java/org/apache/maven/plugin/plexus
PlexusPluginManager.java
maven-core/src/main/java/org/apache/maven/werkz
WerkzProject.java
Log:
o making better use of the plugin request/response, creating them in the
PluginMM, capturing all errors that can occur in the response and passing
it back up to the Maven component to deal with.
Revision Changes Path
1.3 +30 -33 maven-components/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
Index: DefaultMaven.java
===================================================================
RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/DefaultMaven.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DefaultMaven.java 20 Mar 2004 20:21:07 -0000 1.2
+++ DefaultMaven.java 20 Mar 2004 23:20:16 -0000 1.3
@@ -60,7 +60,7 @@
// cleanup attainGoal make is singular
// use i18n
-import org.apache.maven.plugin.manager.PluginManager;
+import org.apache.maven.plugin.PluginExecutionResponse;
import org.apache.maven.plugin.manager.PluginManagerManager;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
@@ -142,62 +142,59 @@
//return getPluginManager().getGoalDescription( goalName );
}
- public void attainGoals( File project, List goalNames )
- throws GoalException, Exception
+ public void attainGoals( File projectFile, List goals )
+ throws Exception
{
- if ( project.exists() )
+ if ( projectFile.exists() )
{
- if ( project.length() == 0 )
+ if ( projectFile.length() == 0 )
{
- throw new Exception( getMessage( "empty.descriptor.error", project.getName() ) );
+ throw new Exception( getMessage( "empty.descriptor.error", projectFile.getName() ) );
}
}
- MavenProject mproject = null;
+ MavenProject project = null;
try
{
- mproject = getProject( project );
+ project = getProject( projectFile );
}
- catch (Exception e)
+ catch ( Exception e )
{
- mproject = null;
+ project = null;
}
-
- pluginMM.attainGoals( mproject, goalNames );
- }
- public void attainGoals( File project, String goalNamesList )
- throws GoalException, Exception
- {
- attainGoals( project, list( goalNamesList ) );
+ attainGoals( project, goals );
}
- public void attainGoals( MavenProject project, String goalNamesList )
- throws GoalException, Exception
+ public void attainGoal( File projectFile, String goal )
+ throws Exception
{
- pluginMM.attainGoals( project, list( goalNamesList ) );
+ MavenProject project = getProject( projectFile );
+
+ attainGoal( project, goal );
}
- private List list( String goalNamesList )
+ public void attainGoals( MavenProject project, List goals )
+ throws Exception
{
- String[] goalNames = StringUtils.split( goalNamesList, "," );
-
- List list = new ArrayList();
-
- for ( int i = 0; i < goalNames.length; i++ )
+ for ( Iterator i = goals.iterator(); i.hasNext(); )
{
- list.add( goalNames[i] );
- }
+ String goal = (String) i.next();
- return list;
+ attainGoal( project, goal );
+ }
}
-
- public void attainGoals( MavenProject project, List goalNames )
- throws GoalException, Exception
+ public void attainGoal( MavenProject project, String goal )
+ throws Exception
{
- pluginMM.attainGoals( project, goalNames );
+ PluginExecutionResponse response = pluginMM.attainGoal( project, goal );
+
+ if ( response.exceptionOccurred() )
+ {
+ response.getException().printStackTrace();
+ }
}
// ----------------------------------------------------------------------
1.2 +5 -2 maven-components/maven-core/src/main/java/org/apache/maven/Maven.java
Index: Maven.java
===================================================================
RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/Maven.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Maven.java 19 Mar 2004 04:13:19 -0000 1.1
+++ Maven.java 20 Mar 2004 23:20:16 -0000 1.2
@@ -15,6 +15,9 @@
{
static String ROLE = Maven.class.getName();
+ void attainGoal( File project, String goal )
+ throws Exception;
+
void attainGoals( File project, List goals )
- throws GoalException, Exception;
+ throws Exception;
}
1.2 +3 -3 maven-components/maven-core/src/main/java/org/apache/maven/MavenConstants.java
Index: MavenConstants.java
===================================================================
RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/MavenConstants.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- MavenConstants.java 19 Mar 2004 04:13:19 -0000 1.1
+++ MavenConstants.java 20 Mar 2004 23:20:16 -0000 1.2
@@ -143,8 +143,8 @@
/** MavenSession POM context tag **/
public static final String MAVEN_POM = "pom";
- /** MavenSession goalDescriptorsKeyedByName context tag **/
- public static final String MAVEN_GOALS = "maven.goalDescriptorsKeyedByName";
+ /** MavenSession goalDescriptors context tag **/
+ public static final String MAVEN_GOALS = "maven.goalDescriptors";
/** MavenSession project verifier context tag **/
public static final String MAVEN_PROJECT_VERIFIER = "maven.project.verifier";
1.2 +5 -18 maven-components/maven-core/src/main/java/org/apache/maven/UnknownGoalException.java
Index: UnknownGoalException.java
===================================================================
RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/UnknownGoalException.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- UnknownGoalException.java 19 Mar 2004 04:13:19 -0000 1.1
+++ UnknownGoalException.java 20 Mar 2004 23:20:16 -0000 1.2
@@ -56,31 +56,18 @@
* ====================================================================
*/
-/** Indicates an attempt to access an unknown werkz goal.
- *
- * @author <a href="mailto:bob@eng.werken.com">bob mcwhirter</a>
- * @version $Id$
- */
public class UnknownGoalException
- extends GoalException
+ extends Exception
{
- /** Name of unknown goal. */
private String goalName;
- /** Construct with an unknown goal name.
- *
- * @param goalName The name of the unknown goal.
- */
- public UnknownGoalException( String goalName )
+ public UnknownGoalException( String goal )
{
- super( "Unknown goal \"" + goalName + "\"" );
- this.goalName = goalName;
+ super( "Unknown goal \"" + goal + "\"" );
+
+ this.goalName = goal;
}
- /** Retrieve the unknown goal name.
- *
- * @return The name of the unknown goal.
- */
public String getGoalName()
{
return this.goalName;
1.2 +2 -2 maven-components/maven-core/src/main/java/org/apache/maven/cli/CLIManager.java
Index: CLIManager.java
===================================================================
RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/cli/CLIManager.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- CLIManager.java 19 Mar 2004 04:13:20 -0000 1.1
+++ CLIManager.java 20 Mar 2004 23:20:17 -0000 1.2
@@ -131,8 +131,8 @@
.create( 'f' ) );
options.addOption( OptionBuilder
- .withLongOpt( "goalDescriptorsKeyedByName" )
- .withDescription( "Display available goalDescriptorsKeyedByName" )
+ .withLongOpt( "goalDescriptors" )
+ .withDescription( "Display available goalDescriptors" )
.create( 'g' ) );
options.addOption( OptionBuilder
1.3 +7 -8 maven-components/maven-core/src/main/java/org/apache/maven/plugin/PluginExecutionRequest.java
Index: PluginExecutionRequest.java
===================================================================
RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/plugin/PluginExecutionRequest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- PluginExecutionRequest.java 20 Mar 2004 20:21:07 -0000 1.2
+++ PluginExecutionRequest.java 20 Mar 2004 23:20:17 -0000 1.3
@@ -25,21 +25,15 @@
private Object plugin;
- public PluginExecutionRequest( Object plugin,
- PluginDescriptor pluginDescriptor,
+ public PluginExecutionRequest( PluginDescriptor pluginDescriptor,
GoalDescriptor goalDescriptor,
- MavenProject project,
- Map parameters )
+ MavenProject project )
{
- this.plugin = plugin;
-
this.pluginDescriptor = pluginDescriptor;
this.goalDescriptor = goalDescriptor;
this.project = project;
-
- this.parameters = parameters;
}
public Map getParameters()
@@ -70,6 +64,11 @@
public MavenProject getProject()
{
return project;
+ }
+
+ public void setPlugin( Object plugin )
+ {
+ this.plugin = plugin;
}
public Object getPlugin()
1.3 +7 -2 maven-components/maven-core/src/main/java/org/apache/maven/plugin/PluginExecutionResponse.java
Index: PluginExecutionResponse.java
===================================================================
RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/plugin/PluginExecutionResponse.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- PluginExecutionResponse.java 20 Mar 2004 20:21:07 -0000 1.2
+++ PluginExecutionResponse.java 20 Mar 2004 23:20:17 -0000 1.3
@@ -2,7 +2,7 @@
/**
*
- *
+ *
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
*
* @version $Id$
@@ -19,5 +19,10 @@
public void setException( Throwable exception )
{
this.exception = exception;
+ }
+
+ public boolean exceptionOccurred()
+ {
+ return ( exception != null );
}
}
1.3 +34 -27 maven-components/maven-core/src/main/java/org/apache/maven/plugin/manager/DefaultPluginManagerManager.java
Index: DefaultPluginManagerManager.java
===================================================================
RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/plugin/manager/DefaultPluginManagerManager.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DefaultPluginManagerManager.java 20 Mar 2004 20:21:07 -0000 1.2
+++ DefaultPluginManagerManager.java 20 Mar 2004 23:20:17 -0000 1.3
@@ -56,13 +56,14 @@
* ====================================================================
*/
-import org.apache.maven.GoalException;
import org.apache.maven.plugin.descriptor.GoalDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptorBuilder;
import org.apache.maven.plugin.PluginExecutionResponse;
+import org.apache.maven.plugin.PluginExecutionRequest;
import org.apache.maven.project.MavenProject;
import org.apache.maven.verifier.DependencyVerifier;
+import org.apache.maven.UnknownGoalException;
import org.codehaus.classworlds.ClassRealm;
import org.codehaus.plexus.component.discovery.ComponentDiscoveryEvent;
import org.codehaus.plexus.component.discovery.ComponentDiscoveryListener;
@@ -77,6 +78,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Set;
public class DefaultPluginManagerManager
extends AbstractLogEnabled
@@ -100,7 +102,7 @@
protected DAG dag = new DAG();
- protected Map goalDescriptorsKeyedByName;
+ protected Map goalDescriptors;
protected Map goalToPluginMap;
@@ -110,7 +112,7 @@
public DefaultPluginManagerManager()
{
- goalDescriptorsKeyedByName = new HashMap();
+ goalDescriptors = new HashMap();
goalToPluginMap = new HashMap();
@@ -119,44 +121,49 @@
pluginDescriptorBuilder = new PluginDescriptorBuilder();
}
- public void attainGoals( MavenProject project, List goalNames )
+ public PluginExecutionResponse attainGoal( MavenProject project, String goal )
throws Exception
{
PluginManager pluginManager = (PluginManager) pluginManagers.get( "plexus" );
- PluginExecutionResponse response;
+ PluginExecutionResponse response = new PluginExecutionResponse();
- for ( Iterator i = goalNames.iterator(); i.hasNext(); )
+ if ( !goalDescriptors.containsKey( goal ) )
{
- String goal = (String) i.next();
+ response.setException( new UnknownGoalException( goal ) );
- if ( dag.getChildLabels( goal ).size() == 0 && dag.getParentLabels( goal ).size() == 0 )
- {
- System.out.println( "[" + goal + "]" );
+ return response;
+ }
- response = pluginManager.attainGoal( getPluginDescriptor( goal ), getGoalDescriptor( goal ), project );
- }
- else
- {
- List goals = TopologicalSorter.sort( dag );
+ GoalDescriptor goalDescriptor = getGoalDescriptor( goal );
- int goalIndex = goals.indexOf( goal );
+ PluginDescriptor pluginDescriptor = getPluginDescriptor( goal );
- // execute all goalDescriptorsKeyedByName starting from the beginning of the chain
- // up to the goal specified.
+ PluginExecutionRequest request = new PluginExecutionRequest( pluginDescriptor, goalDescriptor, project );
- for ( int j = 0; j <= goalIndex; j++ )
- {
- // Now dealing with whether the goal as been attained.
+ if ( dag.getChildLabels( goal ).size() == 0 && dag.getParentLabels( goal ).size() == 0 )
+ {
+ System.out.println( "[" + goal + "]" );
- String goalName = (String) goals.get( j );
+ pluginManager.attainGoal( request, response );
+ }
+ else
+ {
+ List goals = TopologicalSorter.sort( dag );
- System.out.println( "[" + goalName + "]" );
+ int goalIndex = goals.indexOf( goal );
- response = pluginManager.attainGoal( getPluginDescriptor( goalName ), getGoalDescriptor( goalName ), project );
- }
+ for ( int j = 0; j <= goalIndex; j++ )
+ {
+ String goalName = (String) goals.get( j );
+
+ System.out.println( "[" + goalName + "]" );
+
+ pluginManager.attainGoal( request, response );
}
}
+
+ return response;
}
private PluginDescriptor getPluginDescriptor( String goalName )
@@ -166,7 +173,7 @@
private GoalDescriptor getGoalDescriptor( String name )
{
- return (GoalDescriptor) goalDescriptorsKeyedByName.get( name );
+ return (GoalDescriptor) goalDescriptors.get( name );
}
public void contextualize( Context context )
@@ -208,7 +215,7 @@
dag.addVertex( goalDescriptor.getName() );
}
- goalDescriptorsKeyedByName.put( goalDescriptor.getName(), goalDescriptor );
+ goalDescriptors.put( goalDescriptor.getName(), goalDescriptor );
goalToPluginMap.put( goalDescriptor.getName(), pluginDescriptor );
}
1.3 +3 -3 maven-components/maven-core/src/main/java/org/apache/maven/plugin/manager/PluginManager.java
Index: PluginManager.java
===================================================================
RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/plugin/manager/PluginManager.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- PluginManager.java 20 Mar 2004 20:21:07 -0000 1.2
+++ PluginManager.java 20 Mar 2004 23:20:17 -0000 1.3
@@ -1,9 +1,9 @@
package org.apache.maven.plugin.manager;
-import org.apache.maven.GoalException;
import org.apache.maven.plugin.descriptor.GoalDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.PluginExecutionResponse;
+import org.apache.maven.plugin.PluginExecutionRequest;
import org.apache.maven.project.MavenProject;
import org.codehaus.classworlds.ClassRealm;
@@ -20,7 +20,7 @@
{
static String ROLE = PluginManager.class.getName();
- PluginExecutionResponse attainGoal( PluginDescriptor pd, GoalDescriptor gd, MavenProject project )
+ void attainGoal( PluginExecutionRequest request, PluginExecutionResponse response )
throws Exception;
List getGoals();
1.3 +3 -2 maven-components/maven-core/src/main/java/org/apache/maven/plugin/manager/PluginManagerManager.java
Index: PluginManagerManager.java
===================================================================
RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/plugin/manager/PluginManagerManager.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- PluginManagerManager.java 20 Mar 2004 20:21:07 -0000 1.2
+++ PluginManagerManager.java 20 Mar 2004 23:20:17 -0000 1.3
@@ -1,6 +1,7 @@
package org.apache.maven.plugin.manager;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
+import org.apache.maven.plugin.PluginExecutionResponse;
import org.apache.maven.project.MavenProject;
import java.util.List;
@@ -16,7 +17,7 @@
{
String ROLE = PluginManagerManager.class.getName();
- void attainGoals( MavenProject project, List goalNames )
+ PluginExecutionResponse attainGoal( MavenProject project, String goal )
throws Exception;
void processPluginDescriptor( PluginDescriptor pluginDescriptor );
1.4 +6 -13 maven-components/maven-core/src/main/java/org/apache/maven/plugin/plexus/PlexusPluginManager.java
Index: PlexusPluginManager.java
===================================================================
RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/plugin/plexus/PlexusPluginManager.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- PlexusPluginManager.java 20 Mar 2004 20:21:07 -0000 1.3
+++ PlexusPluginManager.java 20 Mar 2004 23:20:17 -0000 1.4
@@ -3,11 +3,8 @@
import org.apache.maven.plugin.Plugin;
import org.apache.maven.plugin.PluginExecutionRequest;
import org.apache.maven.plugin.PluginExecutionResponse;
-import org.apache.maven.plugin.descriptor.GoalDescriptor;
-import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.manager.AbstractPluginManager;
import org.apache.maven.plugin.plexus.executor.PluginExecutor;
-import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.context.Context;
@@ -37,24 +34,20 @@
return "plexus";
}
- public PluginExecutionResponse attainGoal( PluginDescriptor pd, GoalDescriptor gd, MavenProject project )
+ public void attainGoal( PluginExecutionRequest request, PluginExecutionResponse response )
throws Exception
{
- Object plugin = container.lookup( Plugin.ROLE, pd.getId() );
+ String id = request.getPluginDescriptor().getId();
- PluginExecutionRequest request = new PluginExecutionRequest( plugin, pd, gd, project, null );
+ Object plugin = container.lookup( Plugin.ROLE, id );
- PluginExecutionResponse response = new PluginExecutionResponse();
+ request.setPlugin( plugin );
- // I could make a factory and use polymorphism here but there are only
- // 4 flavours here and hopefully people will opt for the integrated
- // form. So we'll use the good old if/else if for now.
+ String mode = request.getPluginDescriptor().getMode();
- PluginExecutor pluginExecutor = (PluginExecutor) container.lookup( PluginExecutor.ROLE, pd.getMode() );
+ PluginExecutor pluginExecutor = (PluginExecutor) container.lookup( PluginExecutor.ROLE, mode );
pluginExecutor.execute( request, response );
-
- return response;
}
// ----------------------------------------------------------------------
1.2 +4 -4 maven-components/maven-core/src/main/java/org/apache/maven/werkz/WerkzProject.java
Index: WerkzProject.java
===================================================================
RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/werkz/WerkzProject.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- WerkzProject.java 19 Mar 2004 04:13:23 -0000 1.1
+++ WerkzProject.java 20 Mar 2004 23:20:17 -0000 1.2
@@ -155,7 +155,7 @@
*
* @param name The name of the goal.
*
- * @return The array of goalDescriptorsKeyedByName in the execution chain, terminating
+ * @return The array of goalDescriptors in the execution chain, terminating
* with the requested goal as the last member.
*
* @throws NoSuchGoalException if the <code>name</code> refers to no known goal.
@@ -204,7 +204,7 @@
/** Attempt to attain the specified goal.
*
* @param name The name of the goal to attain.
- * @param session The context in which to attain goalDescriptorsKeyedByName.
+ * @param session The context in which to attain goalDescriptors.
*
* @throws NoSuchGoalException if the <code>name</code> refers to no known goal.
* @throws UnattainableGoalException if a precursor or the goal itself had an error.
@@ -226,7 +226,7 @@
/** Attempt to percolate the specified goal.
*
* @param name The name of the goal to percolate.
- * @param session The context in which to percolate goalDescriptorsKeyedByName.
+ * @param session The context in which to percolate goalDescriptors.
*
* @throws NoSuchGoalException if the <code>name</code> refers to no known goal.
* @throws UnattainableGoalException if a postcursor or the goal itself had an error.
@@ -368,6 +368,6 @@
*/
public String toString()
{
- return "[Werkz: goalDescriptorsKeyedByName=" + this.goals + ";]";
+ return "[Werkz: goalDescriptors=" + this.goals + ";]";
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org