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 22:43:19 UTC
cvs commit: maven-components/maven-core/src/test/org/apache/maven/plugin PluginDescriptorBuilderTest.java
jvanzyl 2004/02/15 13:43:19
Modified: maven-core project.xml
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
DefaultPluginManagerManager.java
PluginDescriptor.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
PluginDescriptorBuilder.java
maven-core/src/java/org/apache/maven/plugin/plexus
PluginConfigurationException.java
PluginConfigurator.java
maven-core/src/test/org/apache/maven/plugin
PluginDescriptorBuilderTest.java
Removed: maven-core/src/java/org/apache/maven/plugin
ParameterCollectionException.java
Log:
o simplified the configuration mechanism for plugins.
Revision Changes Path
1.4 +0 -17 maven-components/maven-core/project.xml
Index: project.xml
===================================================================
RCS file: /home/cvs/maven-components/maven-core/project.xml,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- project.xml 14 Feb 2004 17:08:31 -0000 1.3
+++ project.xml 15 Feb 2004 21:43:18 -0000 1.4
@@ -143,27 +143,10 @@
</build>
<reports>
- <!--
- <report>maven-checkstyle-plugin</report>
- <report>maven-junit-report-plugin</report>
- <report>maven-simian-plugin</report>
- -->
<report>maven-jxr-plugin</report>
<report>maven-javadoc-plugin</report>
<report>maven-changes-plugin</report>
<report>maven-changelog-plugin</report>
- <!--
- <report>maven-faq-plugin</report> will run by itself but won't register
- <report>maven-file-activity-plugin</report> can't parse jelly script
- <report>maven-developer-activity-plugin</report>
- <report>maven-tasklist-plugin</report> not quite right the report comes out empty @tag problem?
- <report>maven-jdepend-plugin</report> works itself but not with site, also it uses maven-classpath which is really just maven_home/lib
- <report>maven-jellydoc-plugin</report> ${genDocs} not available in jelly.plugin
- <report>maven-pmd-plugin</report> classpath is borked because of getDependencyPath("foo:foo")
-
- We have different uses everywhere which is a result of no documenation.
-
- -->
</reports>
</project>
1.3 +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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- MavenConstants.java 15 Feb 2004 01:16:44 -0000 1.2
+++ MavenConstants.java 15 Feb 2004 21:43:18 -0000 1.3
@@ -143,8 +143,8 @@
/** MavenSession POM context tag **/
public static final String MAVEN_POM = "pom";
- /** MavenSession goalMap context tag **/
- public static final String MAVEN_GOALS = "maven.goalMap";
+ /** MavenSession goalDescriptorsKeyedByName context tag **/
+ public static final String MAVEN_GOALS = "maven.goalDescriptorsKeyedByName";
/** MavenSession project verifier context tag **/
public static final String MAVEN_PROJECT_VERIFIER = "maven.project.verifier";
1.3 +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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- CLIManager.java 15 Feb 2004 01:16:44 -0000 1.2
+++ CLIManager.java 15 Feb 2004 21:43:19 -0000 1.3
@@ -131,8 +131,8 @@
.create( 'f' ) );
options.addOption( OptionBuilder
- .withLongOpt( "goalMap" )
- .withDescription( "Display available goalMap" )
+ .withLongOpt( "goalDescriptorsKeyedByName" )
+ .withDescription( "Display available goalDescriptorsKeyedByName" )
.create( 'g' ) );
options.addOption( OptionBuilder
1.8 +28 -86 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.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- DefaultPluginManagerManager.java 15 Feb 2004 01:53:33 -0000 1.7
+++ DefaultPluginManagerManager.java 15 Feb 2004 21:43:19 -0000 1.8
@@ -57,6 +57,7 @@
*/
import org.apache.maven.GoalException;
+import org.apache.maven.plugin.plexus.PluginConfigurator;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.verifier.DependencyVerifier;
@@ -73,18 +74,10 @@
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
+import java.util.HashMap;
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
@@ -110,39 +103,32 @@
protected DAG dag = new DAG();
- protected XStream xstream;
-
- protected Map goalMap;
+ protected Map goalDescriptorsKeyedByName;
protected Map goalToPluginMap;
- public DefaultPluginManagerManager()
- {
- xstream = new XStream( new JavaReflectionObjectFactory(),
- new DefaultClassMapper(),
- new DefaultElementMapper(),
- new Xpp3DomXMLReaderDriver() );
+ protected Map pluginDescriptors;
- xstream.alias( "plugin", PluginDescriptor.class );
+ protected PluginDescriptorBuilder pluginDescriptorBuilder;
- xstream.alias( "goal", PluginDescriptor.Goal.class );
-
- xstream.alias( "parameter", PluginDescriptor.Parameter.class );
+ public DefaultPluginManagerManager()
+ {
+ goalDescriptorsKeyedByName = new HashMap();
- xstream.alias( "prereq", String.class );
+ goalToPluginMap = new HashMap();
- goalMap = new HashMap();
+ pluginDescriptors = new HashMap();
- goalToPluginMap = new HashMap();
+ pluginDescriptorBuilder = new PluginDescriptorBuilder();
}
public void attainGoals( MavenProject project, List goalNames )
throws GoalException, Exception
{
- // We have to look at each of the goalMap and find out which plugin manager
+ // We have to look at each of the goalDescriptorsKeyedByName and find out which plugin manager
// is responsible for a particular goal.
- // Track attained goalMap and optionally turn them on or off
+ // Track attained goalDescriptorsKeyedByName and optionally turn them on or off
// Need a clean goal
@@ -160,7 +146,7 @@
int goalIndex = goals.indexOf( goal );
- // execute all goalMap starting from the beginning of the chain
+ // execute all goalDescriptorsKeyedByName starting from the beginning of the chain
// up to the goal specified.
for ( int j = 0; j <= goalIndex; j++ )
@@ -169,11 +155,18 @@
String g = (String) goals.get( j );
- pluginManager.attainGoal( (String) goalToPluginMap.get( g ), collectParameters( g, project ) );
+ System.out.println( "[" + g + "]" );
+
+ pluginManager.attainGoal( (String) goalToPluginMap.get( g ), getGoalDescriptor( g ), project );
}
}
}
+ private PluginDescriptor.GoalDescriptor getGoalDescriptor( String name )
+ {
+ return (PluginDescriptor.GoalDescriptor) goalDescriptorsKeyedByName.get( name );
+ }
+
public void contextualize( Context context )
throws Exception
{
@@ -204,7 +197,7 @@
for ( Iterator j = goals.iterator(); j.hasNext(); )
{
- PluginDescriptor.Goal g = (PluginDescriptor.Goal) j.next();
+ PluginDescriptor.GoalDescriptor g = (PluginDescriptor.GoalDescriptor) j.next();
if ( g.getPrereqs() != null )
{
@@ -214,7 +207,7 @@
}
}
- goalMap.put( g.getName(), g );
+ goalDescriptorsKeyedByName.put( g.getName(), g );
goalToPluginMap.put( g.getName(), pd.getId() );
}
@@ -228,7 +221,7 @@
classLoader = Thread.currentThread().getContextClassLoader();
}
- List componentDescriptors = new ArrayList();
+ List pluginDescriptors = new ArrayList();
try
{
@@ -258,9 +251,9 @@
String configuration = os.toString();
- PluginDescriptor pd = (PluginDescriptor) xstream.fromXML( configuration );
+ PluginDescriptor pd = pluginDescriptorBuilder.build( configuration );
- componentDescriptors.add( pd );
+ pluginDescriptors.add( pd );
}
}
catch ( Exception e )
@@ -268,57 +261,6 @@
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;
+ return pluginDescriptors;
}
}
1.5 +7 -5 maven-components/maven-core/src/java/org/apache/maven/plugin/PluginDescriptor.java
Index: PluginDescriptor.java
===================================================================
RCS file: /home/cvs/maven-components/maven-core/src/java/org/apache/maven/plugin/PluginDescriptor.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- PluginDescriptor.java 15 Feb 2004 18:26:00 -0000 1.4
+++ PluginDescriptor.java 15 Feb 2004 21:43:19 -0000 1.5
@@ -1,5 +1,7 @@
package org.apache.maven.plugin;
+import com.thoughtworks.xstream.xml.xpp3.Xpp3Dom;
+
import java.util.List;
/**
@@ -25,11 +27,11 @@
return id;
}
- public static class Goal
+ public static class GoalDescriptor
{
private String name;
- private List parameters;
+ private Xpp3Dom configuration;
private List prereqs;
@@ -40,9 +42,9 @@
return name;
}
- public List getParameters()
+ public Xpp3Dom getConfiguration()
{
- return parameters;
+ return configuration;
}
public List getPrereqs()
1.5 +2 -3 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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- PluginManager.java 15 Feb 2004 01:42:30 -0000 1.4
+++ PluginManager.java 15 Feb 2004 21:43:19 -0000 1.5
@@ -5,7 +5,6 @@
import org.codehaus.classworlds.ClassRealm;
import java.util.List;
-import java.util.Map;
/**
*
@@ -18,7 +17,7 @@
{
static String ROLE = PluginManager.class.getName();
- void attainGoal( String pluginId, Map parameters )
+ void attainGoal( String pluginId, PluginDescriptor.GoalDescriptor gd, MavenProject project )
throws GoalException, Exception;
List getGoals();
1.1 maven-components/maven-core/src/java/org/apache/maven/plugin/PluginDescriptorBuilder.java
Index: PluginDescriptorBuilder.java
===================================================================
package org.apache.maven.plugin;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.ConverterLookup;
import com.thoughtworks.xstream.xml.xpp3.Xpp3DomXMLReaderDriver;
import com.thoughtworks.xstream.xml.xpp3.Xpp3Dom;
import com.thoughtworks.xstream.xml.xpp3.Xpp3DomXMLReader;
import com.thoughtworks.xstream.xml.XMLWriter;
import com.thoughtworks.xstream.xml.XMLReader;
import com.thoughtworks.xstream.alias.DefaultClassMapper;
import com.thoughtworks.xstream.alias.DefaultElementMapper;
import com.thoughtworks.xstream.objecttree.reflection.JavaReflectionObjectFactory;
import com.thoughtworks.xstream.objecttree.ObjectTree;
/**
*
*
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
*
* @version $Id: PluginDescriptorBuilder.java,v 1.1 2004/02/15 21:43:19 jvanzyl Exp $
*/
public class PluginDescriptorBuilder
{
private XStream xstream;
public PluginDescriptorBuilder()
{
xstream = new XStream( new JavaReflectionObjectFactory(),
new DefaultClassMapper(),
new DefaultElementMapper(),
new Xpp3DomXMLReaderDriver() );
xstream.alias( "plugin", PluginDescriptor.class );
xstream.alias( "goal", PluginDescriptor.GoalDescriptor.class );
xstream.alias( "prereq", String.class );
xstream.registerConverter( new Xpp3DomConverter() );
}
public PluginDescriptor build( String xml )
{
return (PluginDescriptor) xstream.fromXML( xml );
}
public class Xpp3DomConverter
implements Converter
{
public boolean canConvert( Class type )
{
return Xpp3Dom.class.isAssignableFrom( type );
}
public void toXML( ObjectTree objectGraph, XMLWriter xmlWriter, ConverterLookup converterLookup )
{
}
public void fromXML( ObjectTree objectGraph, XMLReader xmlReader, ConverterLookup converterLookup, Class requiredType )
{
Xpp3DomXMLReader reader = (Xpp3DomXMLReader) xmlReader;
Xpp3Dom xpp3Dom = (Xpp3Dom) reader.peek();
while ( xmlReader.nextChild() )
{
xmlReader.pop();
}
objectGraph.set( xpp3Dom );
}
}
}
1.10 +11 -4 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.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- PlexusPluginManager.java 15 Feb 2004 02:03:07 -0000 1.9
+++ PlexusPluginManager.java 15 Feb 2004 21:43:19 -0000 1.10
@@ -1,7 +1,9 @@
package org.apache.maven.plugin.plexus;
import org.apache.maven.GoalException;
+import org.apache.maven.project.MavenProject;
import org.apache.maven.plugin.AbstractPluginManager;
+import org.apache.maven.plugin.PluginDescriptor;
import java.lang.reflect.Method;
import java.util.Map;
@@ -18,18 +20,23 @@
{
private Map plugins;
+ private PluginConfigurator pluginConfigurator;
+
public PlexusPluginManager()
{
+ pluginConfigurator = new PluginConfigurator();
}
- public void attainGoal( String pluginId, Map parameters )
+ public void attainGoal( String pluginId, PluginDescriptor.GoalDescriptor gd, MavenProject project )
throws GoalException, Exception
{
Object plugin = plugins.get( pluginId );
- Method m = plugin.getClass().getMethod( "execute", new Class[]{ Map.class } );
+ plugin = pluginConfigurator.configure( plugin, gd.getConfiguration(), project );
+
+ Method m = plugin.getClass().getMethod( "execute", new Class[0] );
- m.invoke( plugin, new Object[]{ parameters } );
+ m.invoke( plugin, new Object[0] );
}
public void loadPlugin( String name )
1.1 maven-components/maven-core/src/java/org/apache/maven/plugin/plexus/PluginConfigurationException.java
Index: PluginConfigurationException.java
===================================================================
package org.apache.maven.plugin.plexus;
/**
*
*
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
*
* @version $Id: PluginConfigurationException.java,v 1.1 2004/02/15 21:43:19 jvanzyl Exp $
*/
public class PluginConfigurationException
extends Exception
{
public PluginConfigurationException( String message )
{
super( message );
}
public PluginConfigurationException( String message, Throwable cause )
{
super( message, cause );
}
}
1.1 maven-components/maven-core/src/java/org/apache/maven/plugin/plexus/PluginConfigurator.java
Index: PluginConfigurator.java
===================================================================
package org.apache.maven.plugin.plexus;
import com.thoughtworks.xstream.xml.xpp3.Xpp3Dom;
import ognl.Ognl;
import ognl.OgnlException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.plugin.plexus.PluginConfigurationException;
import java.lang.reflect.Field;
/**
*
*
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
*
* @version $Id: PluginConfigurator.java,v 1.1 2004/02/15 21:43:19 jvanzyl Exp $
*/
public class PluginConfigurator
{
public Object configure( Object plugin, Xpp3Dom configuration, MavenProject project )
throws PluginConfigurationException
{
Class pluginClass = plugin.getClass();
int size = configuration.getChildCount();
for ( int i = 0; i < size; i++ )
{
Xpp3Dom c = configuration.getChild( i );
String fieldName = c.getName();
String expression = c.getValue();
Object value;
if ( expression.startsWith( "#" ) )
{
try
{
value = Ognl.getValue( expression.substring( 1 ), project );
}
catch ( OgnlException e )
{
throw new PluginConfigurationException(
"Error trying to evaluate expression " + expression + " for the field " + fieldName, e );
}
}
else if ( expression.equals( "project" ) )
{
value = project;
}
else
{
value = project.getProperty( expression );
}
if ( value == null )
{
value = expression;
}
try
{
Field field = pluginClass.getDeclaredField( fieldName );
field.setAccessible( true );
field.set( plugin, value );
}
catch ( Exception e )
{
throw new PluginConfigurationException(
"Error setting value of field " + fieldName + " with " + value + ".", e );
}
}
return plugin;
}
}
1.3 +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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- WerkzProject.java 15 Feb 2004 01:16:44 -0000 1.2
+++ WerkzProject.java 15 Feb 2004 21:43:19 -0000 1.3
@@ -155,7 +155,7 @@
*
* @param name The name of the goal.
*
- * @return The array of goalMap in the execution chain, terminating
+ * @return The array of goalDescriptorsKeyedByName 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 goalMap.
+ * @param session The context in which to attain goalDescriptorsKeyedByName.
*
* @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 goalMap.
+ * @param session The context in which to percolate goalDescriptorsKeyedByName.
*
* @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: goalMap=" + this.goals + ";]";
+ return "[Werkz: goalDescriptorsKeyedByName=" + this.goals + ";]";
}
}
1.1 maven-components/maven-core/src/test/org/apache/maven/plugin/PluginDescriptorBuilderTest.java
Index: PluginDescriptorBuilderTest.java
===================================================================
package org.apache.maven.plugin;
import junit.framework.TestCase;
import java.util.List;
import com.thoughtworks.xstream.xml.xpp3.Xpp3Dom;
/**
*
*
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
*
* @version $Id: PluginDescriptorBuilderTest.java,v 1.1 2004/02/15 21:43:19 jvanzyl Exp $
*/
public class PluginDescriptorBuilderTest
extends TestCase
{
public void testPluginDescriptorBuilder()
{
String xml =
"<plugin>" +
" <id>compiler</id>" +
" <goals>" +
" <goal>" +
" <name>compile</name>" +
" <configuration>" +
" <sourceDirectory>#build.sourceDirectory</sourceDirectory>" +
" <outputDirectory>maven.build.dest</outputDirectory>" +
" <classpathElements>#classpathElements</classpathElements>" +
" <compiler>javac</compiler>" +
" </configuration>" +
" </goal>" +
" </goals>" +
"</plugin>";
PluginDescriptorBuilder pluginDescriptorBuilder = new PluginDescriptorBuilder();
PluginDescriptor pd = pluginDescriptorBuilder.build( xml );
assertEquals( "compiler", pd.getId() );
List goals = pd.getGoals();
assertEquals( 1, goals.size() );
PluginDescriptor.GoalDescriptor goal = (PluginDescriptor.GoalDescriptor) goals.get( 0 );
assertEquals( "compile", goal.getName() );
Xpp3Dom configuration = goal.getConfiguration();
assertNotNull( configuration );
assertEquals( "#build.sourceDirectory", configuration.getChild( "sourceDirectory" ).getValue() );
assertEquals( "maven.build.dest", configuration.getChild( "outputDirectory" ).getValue() );
assertEquals( "#classpathElements", configuration.getChild( "classpathElements" ).getValue() );
assertEquals( "javac", configuration.getChild( "compiler" ).getValue() );
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org