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/02/15 02:16:44 UTC
cvs commit: maven-components/maven-core/src/java/org/apache/maven/werkz WerkzProject.java
jvanzyl 2004/02/14 17:16:44
Modified: maven-core/src/java/org/apache/maven MavenConstants.java
maven-core/src/java/org/apache/maven/cli CLIManager.java
maven-core/src/java/org/apache/maven/plugin
AbstractPluginManager.java
DefaultPluginManagerManager.java PluginManager.java
maven-core/src/java/org/apache/maven/plugin/plexus
PlexusPluginManager.java
maven-core/src/java/org/apache/maven/werkz WerkzProject.java
Added: maven-core/src/java/org/apache/maven/plugin
PluginDescriptor.java
Log:
o add support for sucking in plugin.xml descriptors
Revision Changes Path
1.2 +3 -3 maven-components/maven-core/src/java/org/apache/maven/MavenConstants.java
Index: MavenConstants.java
===================================================================
RCS file: /home/cvs/maven-components/maven-core/src/java/org/apache/maven/MavenConstants.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- MavenConstants.java 6 Feb 2004 23:27:42 -0000 1.1
+++ MavenConstants.java 15 Feb 2004 01:16:44 -0000 1.2
@@ -143,8 +143,8 @@
/** MavenSession POM context tag **/
public static final String MAVEN_POM = "pom";
- /** MavenSession goals context tag **/
- public static final String MAVEN_GOALS = "maven.goals";
+ /** MavenSession goalMap context tag **/
+ public static final String MAVEN_GOALS = "maven.goalMap";
/** MavenSession project verifier context tag **/
public static final String MAVEN_PROJECT_VERIFIER = "maven.project.verifier";
1.2 +2 -2 maven-components/maven-core/src/java/org/apache/maven/cli/CLIManager.java
Index: CLIManager.java
===================================================================
RCS file: /home/cvs/maven-components/maven-core/src/java/org/apache/maven/cli/CLIManager.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- CLIManager.java 6 Feb 2004 23:27:43 -0000 1.1
+++ CLIManager.java 15 Feb 2004 01:16:44 -0000 1.2
@@ -131,8 +131,8 @@
.create( 'f' ) );
options.addOption( OptionBuilder
- .withLongOpt( "goals" )
- .withDescription( "Display available goals" )
+ .withLongOpt( "goalMap" )
+ .withDescription( "Display available goalMap" )
.create( 'g' ) );
options.addOption( OptionBuilder
1.3 +4 -5 maven-components/maven-core/src/java/org/apache/maven/plugin/AbstractPluginManager.java
Index: AbstractPluginManager.java
===================================================================
RCS file: /home/cvs/maven-components/maven-core/src/java/org/apache/maven/plugin/AbstractPluginManager.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AbstractPluginManager.java 12 Feb 2004 19:28:53 -0000 1.2
+++ AbstractPluginManager.java 15 Feb 2004 01:16:44 -0000 1.3
@@ -1,17 +1,16 @@
package org.apache.maven.plugin;
-import org.codehaus.plexus.util.Expand;
-import org.codehaus.classworlds.ClassRealm;
import org.apache.maven.MavenException;
-import org.apache.maven.model.Dependency;
import org.apache.maven.artifact.MavenArtifact;
+import org.apache.maven.model.Dependency;
import org.apache.maven.project.MavenProject;
+import org.codehaus.classworlds.ClassRealm;
+import org.codehaus.plexus.util.Expand;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.Iterator;
-import java.util.StringTokenizer;
import java.util.List;
/**
1.4 +157 -5 maven-components/maven-core/src/java/org/apache/maven/plugin/DefaultPluginManagerManager.java
Index: DefaultPluginManagerManager.java
===================================================================
RCS file: /home/cvs/maven-components/maven-core/src/java/org/apache/maven/plugin/DefaultPluginManagerManager.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DefaultPluginManagerManager.java 14 Feb 2004 21:33:00 -0000 1.3
+++ DefaultPluginManagerManager.java 15 Feb 2004 01:16:44 -0000 1.4
@@ -68,9 +68,23 @@
import org.codehaus.plexus.util.dag.DAG;
import org.codehaus.plexus.util.dag.TopologicalSorter;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.HashMap;
+
+import com.thoughtworks.xstream.XStream;
+import com.thoughtworks.xstream.alias.DefaultClassMapper;
+import com.thoughtworks.xstream.alias.DefaultElementMapper;
+import com.thoughtworks.xstream.xml.xpp3.Xpp3DomXMLReaderDriver;
+import com.thoughtworks.xstream.objecttree.reflection.JavaReflectionObjectFactory;
+import ognl.Ognl;
+import ognl.OgnlException;
public class DefaultPluginManagerManager
extends AbstractLogEnabled
@@ -94,8 +108,25 @@
DAG dag = new DAG();
+ protected XStream xstream;
+
+ protected Map goalMap;
+
public DefaultPluginManagerManager()
{
+ xstream = new XStream( new JavaReflectionObjectFactory(),
+ new DefaultClassMapper(),
+ new DefaultElementMapper(),
+ new Xpp3DomXMLReaderDriver() );
+
+ xstream.alias( "plugin", PluginDescriptor.class );
+
+ xstream.alias( "goal", PluginDescriptor.Goal.class );
+
+ xstream.alias( "parameter", PluginDescriptor.Parameter.class );
+
+ goalMap = new HashMap();
+
// compile, test, test:compile
dag.addEdge( "jar", "test" );
@@ -107,10 +138,10 @@
public void attainGoals( MavenProject project, List goalNames )
throws GoalException, Exception
{
- // We have to look at each of the goals and find out which plugin manager
+ // We have to look at each of the goalMap and find out which plugin manager
// is responsible for a particular goal.
- // Track attained goals and optionally turn them on or off
+ // Track attained goalMap and optionally turn them on or off
// Need a clean goal
@@ -128,7 +159,7 @@
int goalIndex = goals.indexOf( goal );
- // execute all goals starting from the beginning of the chain
+ // execute all goalMap starting from the beginning of the chain
// up to the goal specified.
for ( int j = 0; j <= goalIndex; j++ )
@@ -137,7 +168,7 @@
String g = (String) goals.get( j );
- pluginManager.attainGoal( project, g );
+ pluginManager.attainGoal( g, collectParameters( g, project ) );
}
}
}
@@ -159,5 +190,126 @@
pluginManager.initializePlugins( mavenHome, mavenLocalHome, rootClassRealm );
}
+
+ // Now lets go hunting for plugin descriptors
+
+ List pds = findPlugins( null );
+
+ for ( Iterator i = pds.iterator(); i.hasNext(); )
+ {
+ PluginDescriptor pd = (PluginDescriptor) i.next();
+
+ List goals = pd.getGoals();
+
+ for ( Iterator j = goals.iterator(); j.hasNext(); )
+ {
+ PluginDescriptor.Goal g = (PluginDescriptor.Goal) j.next();
+
+ goalMap.put( g.getName(), g );
+ }
+ }
+ }
+
+ static String PLUGIN_RESOURCES = "META-INF/plexus/plugin.xml";
+
+ public List findPlugins( ClassLoader classLoader )
+ {
+ if ( classLoader == null )
+ {
+ classLoader = Thread.currentThread().getContextClassLoader();
+ }
+
+ List componentDescriptors = new ArrayList();
+
+ try
+ {
+ for ( Enumeration e = classLoader.getResources( PLUGIN_RESOURCES ); e.hasMoreElements(); )
+ {
+ URL url = (URL) e.nextElement();
+
+ InputStream is = url.openStream();
+
+ byte[] buffer = new byte[1024];
+
+ int read = 0;
+
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+
+ while( is.available() > 0 )
+ {
+ read = is.read( buffer, 0, buffer.length );
+
+ if ( read < 0 )
+ {
+ break;
+ }
+
+ os.write( buffer, 0, read );
+ }
+
+ String configuration = os.toString();
+
+ PluginDescriptor pd = (PluginDescriptor) xstream.fromXML( configuration );
+
+ componentDescriptors.add( pd );
+ }
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
+ }
+
+ return componentDescriptors;
+ }
+
+ private Map collectParameters( String goal, MavenProject project )
+ throws ParameterCollectionException
+ {
+ List goalParameters = ((PluginDescriptor.Goal) goalMap.get( goal )).getParameters();
+
+ Map parameters = new HashMap();
+
+ for ( Iterator i = goalParameters.iterator(); i.hasNext(); )
+ {
+ PluginDescriptor.Parameter parameter = (PluginDescriptor.Parameter) i.next();
+
+ String key = parameter.getKey();
+
+ String keyValue = parameter.getValue();
+
+ System.out.println( "keyValue = " + keyValue );
+
+ Object value;
+
+ if ( keyValue.startsWith( "#" ) )
+ {
+ try
+ {
+ value = Ognl.getValue( keyValue.substring( 1 ), project );
+ }
+ catch ( OgnlException e )
+ {
+ throw new ParameterCollectionException(
+ "Error trying to extract parameter from the project using: " + key, e );
+ }
+ }
+ else if ( keyValue.equals( "project" ) )
+ {
+ value = project;
+ }
+ else
+ {
+ value = project.getProperty( keyValue );
+ }
+
+ if ( value == null )
+ {
+ value = keyValue;
+ }
+
+ parameters.put( key, value );
+ }
+
+ return parameters;
}
-}
+}
\ No newline at end of file
1.3 +3 -2 maven-components/maven-core/src/java/org/apache/maven/plugin/PluginManager.java
Index: PluginManager.java
===================================================================
RCS file: /home/cvs/maven-components/maven-core/src/java/org/apache/maven/plugin/PluginManager.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- PluginManager.java 12 Feb 2004 01:59:00 -0000 1.2
+++ PluginManager.java 15 Feb 2004 01:16:44 -0000 1.3
@@ -5,6 +5,7 @@
import org.codehaus.classworlds.ClassRealm;
import java.util.List;
+import java.util.Map;
/**
*
@@ -17,7 +18,7 @@
{
static String ROLE = PluginManager.class.getName();
- void attainGoal( MavenProject project, String goal )
+ void attainGoal( String goal, Map parameters )
throws GoalException, Exception;
List getGoals();
1.1 maven-components/maven-core/src/java/org/apache/maven/plugin/PluginDescriptor.java
Index: PluginDescriptor.java
===================================================================
package org.apache.maven.plugin;
import java.util.List;
/**
*
*
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
*
* @version $Id: PluginDescriptor.java,v 1.1 2004/02/15 01:16:44 jvanzyl Exp $
*/
public class PluginDescriptor
{
private List goals;
public List getGoals()
{
return goals;
}
public static class Goal
{
private String name;
private List parameters;
public String getName()
{
return name;
}
public List getParameters()
{
return parameters;
}
}
public static class Parameter
{
private String key;
private String value;
public String getKey()
{
return key;
}
public String getValue()
{
return value;
}
}
}
1.7 +2 -132 maven-components/maven-core/src/java/org/apache/maven/plugin/plexus/PlexusPluginManager.java
Index: PlexusPluginManager.java
===================================================================
RCS file: /home/cvs/maven-components/maven-core/src/java/org/apache/maven/plugin/plexus/PlexusPluginManager.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- PlexusPluginManager.java 14 Feb 2004 21:33:00 -0000 1.6
+++ PlexusPluginManager.java 15 Feb 2004 01:16:44 -0000 1.7
@@ -1,15 +1,10 @@
package org.apache.maven.plugin.plexus;
-import ognl.Ognl;
-import ognl.OgnlException;
import org.apache.maven.GoalException;
import org.apache.maven.plugin.AbstractPluginManager;
-import org.apache.maven.plugin.ParameterCollectionException;
-import org.apache.maven.project.MavenProject;
import java.lang.reflect.Method;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.Map;
/**
@@ -26,8 +21,6 @@
private Map goalToPluginMap;
- private Map goalParameterMap;
-
// parameters can be extracted from the MavenProject itself
// or from properties or good old hard coded values.
@@ -43,151 +36,28 @@
{
goalToPluginMap = new HashMap();
- goalParameterMap = new HashMap();
-
- // --------------------------------------------------------------------------
- // Compile
- // --------------------------------------------------------------------------
- // sourceDirectory = project.build.sourceDirectory
- // outputDirectory = project.build.testOutputDirectory
- // compiler =
- // options
-
- Map compile = new HashMap();
-
- compile.put( "sourceDirectory", "#build.sourceDirectory" );
- compile.put( "outputDirectory", "maven.build.dest" );
- compile.put( "classpathElements", "#classpathElements" );
- compile.put( "compiler", "jikes" );
-
- goalParameterMap.put( "compile", compile );
-
goalToPluginMap.put( "compile", "compiler" );
- // --------------------------------------------------------------------------
- // Test Compile
- // --------------------------------------------------------------------------
- // sourceDirectory = project.build.testSourceDirectory
- // targetDirectory = project.build.testOutputDirectory
- // compiler =
- // options
-
- Map testCompile = new HashMap();
-
- testCompile.put( "sourceDirectory", "#build.unitTestSourceDirectory" );
- testCompile.put( "outputDirectory", "maven.test.dest" );
- testCompile.put( "classpathElements", "#classpathElements" );
- testCompile.put( "compiler", "jikes" );
-
- goalParameterMap.put( "test:compile", testCompile );
-
goalToPluginMap.put( "test:compile", "compiler" );
- // --------------------------------------------------------------------------
- // Jar
- // --------------------------------------------------------------------------
- // jarName
- // basedir
-
- Map jar = new HashMap();
-
- jar.put( "jarName", "maven.final.name" );
- jar.put( "outputDirectory", "maven.build.dir" );
- jar.put( "basedir", "maven.build.dest" );
- jar.put( "project", "project" );
-
- goalParameterMap.put( "jar", jar );
-
goalToPluginMap.put( "jar", "jar" );
- // --------------------------------------------------------------------------
- // Test
- // --------------------------------------------------------------------------
- // mavenRepoLocal
- // basedir
- // includes
- // excludes
-
- Map surefire = new HashMap();
-
- surefire.put( "mavenRepoLocal", "maven.repo.local" );
- surefire.put( "basedir", "basedir" );
- surefire.put( "includes", "#build.unitTest.includes" );
- surefire.put( "excludes", "#build.unitTest.excludes" );
- surefire.put( "classpathElements", "#classpathElements" );
-
- goalParameterMap.put( "test", surefire );
-
goalToPluginMap.put( "test", "surefire" );
}
- public void attainGoal( MavenProject project, String goal )
+ public void attainGoal( String goal, Map parameters )
throws GoalException, Exception
{
String roleHint = (String) goalToPluginMap.get( goal );
Object plugin = plugins.get( roleHint );
- // Now this brings up the question of where do the parameters come from?
-
- Map parameters = collectParameters( goal, project );
-
System.out.println( "parameters = " + parameters );
Method m = plugin.getClass().getMethod( "execute", new Class[]{ Map.class } );
m.invoke( plugin, new Object[]{ parameters } );
}
-
- private Map collectParameters( String goal, MavenProject project )
- throws ParameterCollectionException
- {
- Map goalParameters = (Map) goalParameterMap.get( goal );
-
- Map parameters = new HashMap();
-
- for ( Iterator i = goalParameters.keySet().iterator(); i.hasNext(); )
- {
- String key = (String) i.next();
-
- String keyValue = (String) goalParameters.get( key );
-
- System.out.println( "keyValue = " + keyValue );
-
- Object value;
-
- if ( keyValue.startsWith( "#" ) )
- {
- try
- {
- value = Ognl.getValue( keyValue.substring( 1 ), project );
- }
- catch ( OgnlException e )
- {
- throw new ParameterCollectionException(
- "Error trying to extract parameter from the project using: " + key, e );
- }
- }
- else if ( keyValue.equals( "project" ) )
- {
- value = project;
- }
- else
- {
- value = project.getProperty( keyValue );
- }
-
- if ( value == null )
- {
- value = keyValue;
- }
-
- parameters.put( key, value );
- }
-
- return parameters;
- }
-
public void loadPlugin( String name )
throws Exception
1.2 +4 -4 maven-components/maven-core/src/java/org/apache/maven/werkz/WerkzProject.java
Index: WerkzProject.java
===================================================================
RCS file: /home/cvs/maven-components/maven-core/src/java/org/apache/maven/werkz/WerkzProject.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- WerkzProject.java 6 Feb 2004 23:27:46 -0000 1.1
+++ WerkzProject.java 15 Feb 2004 01:16:44 -0000 1.2
@@ -155,7 +155,7 @@
*
* @param name The name of the goal.
*
- * @return The array of goals in the execution chain, terminating
+ * @return The array of goalMap 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 goals.
+ * @param session The context in which to attain goalMap.
*
* @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 goals.
+ * @param session The context in which to percolate goalMap.
*
* @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: goals=" + this.goals + ";]";
+ return "[Werkz: goalMap=" + this.goals + ";]";
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org