You are viewing a plain text version of this content. The canonical link for it is here.
Posted to m2-dev@maven.apache.org by jd...@apache.org on 2004/08/08 07:11:13 UTC
cvs commit: maven-components/maven-plugin-loaders/maven-marmalade-loader/src/main/resources/META-INF/marmalade mojo.def
jdcasey 2004/08/07 22:11:13
Modified: maven-core/src/main/java/org/apache/maven/plugin
MavenPluginDescriptor.java
maven-plugin/src/main/java/org/apache/maven/plugin/descriptor
PluginDescriptor.java
Added: maven-plugin-loaders/maven-marmalade-loader/src/main/java/org/apache/maven/plugin/loader/marmalade/tags
MojoDependencyTag.java MojoParametersTag.java
DescriptionOwner.java MojoTag.java
MojoDependenciesTag.java MojoPrereqsTag.java
MojoTagLibrary.java MojoDescriptorTag.java
MojoParameterTag.java DescriptionTag.java
MojoPrereqTag.java
maven-plugin-loaders/maven-marmalade-loader/src/main/java/org/apache/maven/plugin/loader/marmalade
MarmaladePluginDiscoverer.java
maven-plugin-loaders/maven-marmalade-loader/src/test/java/org/apache/maven/plugin/loader/marmalade
MarmaladePluginDiscovererTest.java
maven-plugin-loaders/maven-marmalade-loader/src/main/resources/META-INF/marmalade
mojo.def
Log:
o Added marmalade scripted mojo discoverer and tests.
o Minimal modifications to the MavenPluginDescriptor to allow building of instances without privileged field access.
o Still need to add a pom.xml for the marmalade-plugin-loader (or whatever we should call it).
Revision Changes Path
1.1 maven-components/maven-plugin-loaders/maven-marmalade-loader/src/main/java/org/apache/maven/plugin/loader/marmalade/tags/MojoDependencyTag.java
Index: MojoDependencyTag.java
===================================================================
/* Created on Aug 7, 2004 */
package org.apache.maven.plugin.loader.marmalade.tags;
import org.apache.maven.plugin.descriptor.Dependency;
import org.codehaus.marmalade.model.AbstractMarmaladeTag;
import org.codehaus.marmalade.runtime.MarmaladeExecutionContext;
import org.codehaus.marmalade.runtime.MarmaladeExecutionException;
public class MojoDependencyTag extends AbstractMarmaladeTag
{
public static final String GROUP_ID_ATTRIBUTE = "groupId";
public static final String ARTIFACT_ID_ATTRIBUTE = "artifactId";
public static final String VERSION_ATTRIBUTE = "version";
public static final String TYPE_ATTRIBUTE = "type";
protected void doExecute( MarmaladeExecutionContext context )
throws MarmaladeExecutionException
{
String groupId = (String)requireTagAttribute(GROUP_ID_ATTRIBUTE, String.class, context);
String artifactId = (String)requireTagAttribute(ARTIFACT_ID_ATTRIBUTE, String.class, context);
String version = (String)requireTagAttribute(VERSION_ATTRIBUTE, String.class, context);
String type = (String)getAttributes().getValue(TYPE_ATTRIBUTE, String.class, context);
MojoDependenciesTag parent = (MojoDependenciesTag)requireParent(MojoDependenciesTag.class);
Dependency dep = new Dependency();
dep.setGroupId(groupId);
dep.setArtifactId(artifactId);
dep.setVersion(version);
if(type != null) {
dep.setType(type);
}
parent.addDependency(dep);
}
protected boolean alwaysProcessChildren() {
// never process children...shouldn't even have any!
return false;
}
}
1.1 maven-components/maven-plugin-loaders/maven-marmalade-loader/src/main/java/org/apache/maven/plugin/loader/marmalade/tags/MojoParametersTag.java
Index: MojoParametersTag.java
===================================================================
/* Created on Aug 7, 2004 */
package org.apache.maven.plugin.loader.marmalade.tags;
import java.util.LinkedList;
import java.util.List;
import org.apache.maven.plugin.descriptor.Parameter;
import org.codehaus.marmalade.model.AbstractMarmaladeTag;
import org.codehaus.marmalade.runtime.MarmaladeExecutionContext;
import org.codehaus.marmalade.runtime.MarmaladeExecutionException;
/**
* @author jdcasey
*/
public class MojoParametersTag extends AbstractMarmaladeTag {
private List parameters = new LinkedList();
protected void doExecute(MarmaladeExecutionContext context)
throws MarmaladeExecutionException {
processChildren(context);
MojoDescriptorTag parent = (MojoDescriptorTag)requireParent(MojoDescriptorTag.class);
parent.setParameters(parameters);
}
public void addParameter(Parameter param) {
parameters.add(param);
}
}
1.1 maven-components/maven-plugin-loaders/maven-marmalade-loader/src/main/java/org/apache/maven/plugin/loader/marmalade/tags/DescriptionOwner.java
Index: DescriptionOwner.java
===================================================================
/* Created on Aug 7, 2004 */
package org.apache.maven.plugin.loader.marmalade.tags;
/**
* @author jdcasey
*/
public interface DescriptionOwner {
public void setDescription(String description);
}
1.1 maven-components/maven-plugin-loaders/maven-marmalade-loader/src/main/java/org/apache/maven/plugin/loader/marmalade/tags/MojoTag.java
Index: MojoTag.java
===================================================================
/* Created on Aug 7, 2004 */
package org.apache.maven.plugin.loader.marmalade.tags;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.codehaus.marmalade.model.AbstractMarmaladeTag;
import org.codehaus.marmalade.model.MarmaladeTag;
import org.codehaus.marmalade.runtime.MarmaladeExecutionContext;
import org.codehaus.marmalade.runtime.MarmaladeExecutionException;
/**
* @author jdcasey
*/
public class MojoTag extends AbstractMarmaladeTag
{
private boolean describeOnly = false;
private List dependencies;
private MojoDescriptor descriptor;
protected boolean alwaysProcessChildren( )
{
return false;
}
protected void doExecute( MarmaladeExecutionContext context )
throws MarmaladeExecutionException
{
boolean describeOnly = describeOnly();
for (Iterator it = children().iterator(); it.hasNext();) {
MarmaladeTag child = (MarmaladeTag) it.next();
if(describeOnly && (child instanceof MojoDescriptorTag)) {
MojoDescriptorTag headerTag = (MojoDescriptorTag)child;
child.execute(context);
this.descriptor = headerTag.getMojoDescriptor();
this.dependencies = headerTag.getDependencies();
// we're done with the description phase.
break;
}
else if(!describeOnly) {
child.execute(context);
}
}
}
public MojoDescriptor getMojoDescriptor() {
return descriptor;
}
public List addDependencies(List accumulatedDependencies) {
accumulatedDependencies.addAll(dependencies);
return accumulatedDependencies;
}
public void describeOnly(boolean describeOnly) {
this.describeOnly = describeOnly;
}
public boolean describeOnly() {
return describeOnly;
}
}
1.1 maven-components/maven-plugin-loaders/maven-marmalade-loader/src/main/java/org/apache/maven/plugin/loader/marmalade/tags/MojoDependenciesTag.java
Index: MojoDependenciesTag.java
===================================================================
/* Created on Aug 7, 2004 */
package org.apache.maven.plugin.loader.marmalade.tags;
import java.util.LinkedList;
import java.util.List;
import org.apache.maven.plugin.descriptor.Dependency;
import org.codehaus.marmalade.model.AbstractMarmaladeTag;
import org.codehaus.marmalade.runtime.MarmaladeExecutionContext;
import org.codehaus.marmalade.runtime.MarmaladeExecutionException;
/**
* @author jdcasey
*/
public class MojoDependenciesTag extends AbstractMarmaladeTag {
private List dependencies = new LinkedList();
protected void doExecute(MarmaladeExecutionContext context)
throws MarmaladeExecutionException {
processChildren(context);
MojoDescriptorTag parent = (MojoDescriptorTag)requireParent(MojoDescriptorTag.class);
parent.setDependencies(dependencies);
}
public void addDependency(Dependency dependency) {
dependencies.add(dependency);
}
}
1.1 maven-components/maven-plugin-loaders/maven-marmalade-loader/src/main/java/org/apache/maven/plugin/loader/marmalade/tags/MojoPrereqsTag.java
Index: MojoPrereqsTag.java
===================================================================
/* Created on Aug 7, 2004 */
package org.apache.maven.plugin.loader.marmalade.tags;
import java.util.LinkedList;
import java.util.List;
import org.codehaus.marmalade.model.AbstractMarmaladeTag;
import org.codehaus.marmalade.runtime.MarmaladeExecutionContext;
import org.codehaus.marmalade.runtime.MarmaladeExecutionException;
/**
* @author jdcasey
*/
public class MojoPrereqsTag extends AbstractMarmaladeTag {
private List prereqs = new LinkedList();
protected void doExecute(MarmaladeExecutionContext context)
throws MarmaladeExecutionException {
processChildren(context);
MojoDescriptorTag parent = (MojoDescriptorTag)requireParent(MojoDescriptorTag.class);
parent.setPrereqs(prereqs);
}
public void addPrereq(String prereq) {
prereqs.add(prereq);
}
}
1.1 maven-components/maven-plugin-loaders/maven-marmalade-loader/src/main/java/org/apache/maven/plugin/loader/marmalade/tags/MojoTagLibrary.java
Index: MojoTagLibrary.java
===================================================================
/* Created on Aug 7, 2004 */
package org.apache.maven.plugin.loader.marmalade.tags;
import org.codehaus.marmalade.model.AbstractMarmaladeTagLibrary;
public class MojoTagLibrary extends AbstractMarmaladeTagLibrary {
public static final String MOJO_TAG = "mojo";
public static final String DESCRIPTOR_TAG = "descriptor";
public static final String PREREQS_TAG = "prereqs";
public static final String PREREQ_TAG = "prereq";
public static final String PARAMETERS_TAG = "parameters";
public static final String PARAMETER_TAG = "parameter";
public static final String DESCRIPTION_TAG = "description";
public static final String DEPENDENCIES_TAG = "dependencies";
public static final String DEPENDENCY_TAG = "dependency";
public MojoTagLibrary() {
registerTag(MOJO_TAG, MojoTag.class);
registerTag(DESCRIPTOR_TAG, MojoDescriptorTag.class);
registerTag(PREREQS_TAG, MojoPrereqsTag.class);
registerTag(PREREQ_TAG, MojoPrereqTag.class);
registerTag(PARAMETERS_TAG, MojoParametersTag.class);
registerTag(PARAMETER_TAG, MojoParameterTag.class);
registerTag(DESCRIPTION_TAG, DescriptionTag.class);
registerTag(DEPENDENCIES_TAG, MojoDependenciesTag.class);
registerTag(DEPENDENCY_TAG, MojoDependencyTag.class);
}
}
1.1 maven-components/maven-plugin-loaders/maven-marmalade-loader/src/main/java/org/apache/maven/plugin/loader/marmalade/tags/MojoDescriptorTag.java
Index: MojoDescriptorTag.java
===================================================================
/* Created on Aug 7, 2004 */
package org.apache.maven.plugin.loader.marmalade.tags;
import org.apache.maven.model.Dependency;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.Parameter;
import org.codehaus.marmalade.model.AbstractMarmaladeTag;
import org.codehaus.marmalade.model.MarmaladeAttributes;
import org.codehaus.marmalade.runtime.MarmaladeExecutionContext;
import org.codehaus.marmalade.runtime.MarmaladeExecutionException;
import java.util.LinkedList;
import java.util.List;
/**
* @author jdcasey
*/
public class MojoDescriptorTag extends AbstractMarmaladeTag
implements DescriptionOwner
{
public static final String ID_ATTRIBUTE = "id";
public static final String INSTANTIATION_STRATEGY_ATTRIBUTE = "instantiation-strategy";
public static final String EXECUTION_STRATEGY_ATTRIBUTE = "execution-strategy";
public static final String GOAL_ATTRIBUTE = "goal";
private String id;
private String instantiationStrategy;
private String executionStrategy;
private String goal;
private String description;
private List prereqs = new LinkedList( );
private List dependencies = new LinkedList( );
private List parameters = new LinkedList();
protected void doExecute( MarmaladeExecutionContext context )
throws MarmaladeExecutionException
{
this.id = ( String ) requireTagAttribute( ID_ATTRIBUTE, String.class,
context );
MarmaladeAttributes attributes = getAttributes();
this.instantiationStrategy = ( String ) attributes.getValue( INSTANTIATION_STRATEGY_ATTRIBUTE,
String.class, context );
this.executionStrategy = ( String ) attributes.getValue( EXECUTION_STRATEGY_ATTRIBUTE,
String.class, context );
this.goal = (String)attributes.getValue(GOAL_ATTRIBUTE, String.class, context);
}
public List getDependencies( )
{
return dependencies;
}
public MojoDescriptor getMojoDescriptor( )
{
MojoDescriptor descriptor = new MojoDescriptor( );
descriptor.setId( id );
if(instantiationStrategy != null) {
descriptor.setInstantiationStrategy( instantiationStrategy );
}
if(executionStrategy != null) {
descriptor.setExecutionStrategy( executionStrategy );
}
if(goal != null) {
descriptor.setGoal(goal);
}
descriptor.setPrereqs(prereqs);
descriptor.setParameters(parameters);
return descriptor;
}
public void setPrereqs( List prereqs )
{
this.prereqs = prereqs;
}
public void setDependencies( List dependencies)
{
this.dependencies = dependencies;
}
public void setDescription( String description )
{
this.description = description;
}
public void setParameters(List parameters) {
this.parameters = parameters;
}
}
1.1 maven-components/maven-plugin-loaders/maven-marmalade-loader/src/main/java/org/apache/maven/plugin/loader/marmalade/tags/MojoParameterTag.java
Index: MojoParameterTag.java
===================================================================
/* Created on Aug 7, 2004 */
package org.apache.maven.plugin.loader.marmalade.tags;
import org.apache.maven.plugin.descriptor.Parameter;
import org.codehaus.marmalade.model.AbstractMarmaladeTag;
import org.codehaus.marmalade.model.MarmaladeAttribute;
import org.codehaus.marmalade.model.MarmaladeAttributes;
import org.codehaus.marmalade.runtime.MarmaladeExecutionContext;
import org.codehaus.marmalade.runtime.MarmaladeExecutionException;
public class MojoParameterTag extends AbstractMarmaladeTag
implements DescriptionOwner
{
public static final String NAME_ATTRIBUTE = "name";
public static final String TYPE_ATTRIBUTE = "type";
public static final String REQUIRED_ATTRIBUTE = "required";
public static final String VALIDATOR_ATTRIBUTE = "validator";
public static final String EXPRESSION_ATTRIBUTE = "expression";
private Parameter param = new Parameter( );
protected void doExecute( MarmaladeExecutionContext context )
throws MarmaladeExecutionException
{
MarmaladeAttributes attributes = getAttributes( );
param.setName( ( String ) requireTagAttribute( NAME_ATTRIBUTE,
String.class, context ) );
param.setRequired( ( ( Boolean ) requireTagAttribute(
REQUIRED_ATTRIBUTE, Boolean.class, context ) ).booleanValue( ) );
param.setType( ( String ) requireTagAttribute( TYPE_ATTRIBUTE,
String.class, context ) );
param.setValidator( ( String ) requireTagAttribute(
VALIDATOR_ATTRIBUTE, String.class, context ) );
param.setExpression( String.valueOf(requireTagAttribute(
EXPRESSION_ATTRIBUTE, context ) ) );
processChildren( context );
if ( param.getDescription( ) == null )
{
throw new MarmaladeExecutionException(
"mojo parameters require a description" );
}
MojoParametersTag parent = ( MojoParametersTag ) requireParent( MojoParametersTag.class );
parent.addParameter( param );
}
public void setDescription( String description )
{
param.setDescription( description );
}
}
1.1 maven-components/maven-plugin-loaders/maven-marmalade-loader/src/main/java/org/apache/maven/plugin/loader/marmalade/tags/DescriptionTag.java
Index: DescriptionTag.java
===================================================================
/* Created on Aug 7, 2004 */
package org.apache.maven.plugin.loader.marmalade.tags;
import org.codehaus.marmalade.el.ExpressionEvaluationException;
import org.codehaus.marmalade.model.AbstractMarmaladeTag;
import org.codehaus.marmalade.runtime.MarmaladeExecutionContext;
import org.codehaus.marmalade.runtime.MarmaladeExecutionException;
public class DescriptionTag extends AbstractMarmaladeTag
{
protected void doExecute( MarmaladeExecutionContext context )
throws MarmaladeExecutionException
{
String description = (String)getBody(context, String.class);
DescriptionOwner parent = (DescriptionOwner)requireParent(DescriptionOwner.class);
parent.setDescription(description);
}
protected boolean preserveBodyWhitespace( MarmaladeExecutionContext arg0 )
throws ExpressionEvaluationException
{
return false;
}
}
1.1 maven-components/maven-plugin-loaders/maven-marmalade-loader/src/main/java/org/apache/maven/plugin/loader/marmalade/tags/MojoPrereqTag.java
Index: MojoPrereqTag.java
===================================================================
/* Created on Aug 7, 2004 */
package org.apache.maven.plugin.loader.marmalade.tags;
import org.codehaus.marmalade.el.ExpressionEvaluationException;
import org.codehaus.marmalade.model.AbstractMarmaladeTag;
import org.codehaus.marmalade.runtime.MarmaladeExecutionContext;
import org.codehaus.marmalade.runtime.MarmaladeExecutionException;
public class MojoPrereqTag extends AbstractMarmaladeTag {
private static final String NAME_ATTRIBUTE = "name";
protected boolean alwaysProcessChildren() {
// shouldn't even have children...
return false;
}
protected void doExecute(MarmaladeExecutionContext context)
throws MarmaladeExecutionException {
String prereq = (String)requireTagAttribute(NAME_ATTRIBUTE, String.class, context);
MojoPrereqsTag parent = (MojoPrereqsTag)requireParent(MojoPrereqsTag.class);
parent.addPrereq(prereq);
}
}
1.5 +10 -14 maven-components/maven-core/src/main/java/org/apache/maven/plugin/MavenPluginDescriptor.java
Index: MavenPluginDescriptor.java
===================================================================
RCS file: /home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/plugin/MavenPluginDescriptor.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- MavenPluginDescriptor.java 27 Jun 2004 07:39:08 -0000 1.4
+++ MavenPluginDescriptor.java 8 Aug 2004 05:11:13 -0000 1.5
@@ -1,5 +1,8 @@
package org.apache.maven.plugin;
+import org.apache.maven.plugin.descriptor.PluginDescriptor;
+import org.codehaus.plexus.component.repository.ComponentSetDescriptor;
+
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
@@ -15,19 +18,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
import java.util.List;
-import org.apache.maven.plugin.descriptor.PluginDescriptor;
-
-import org.codehaus.plexus.component.repository.ComponentSetDescriptor;
-
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
-public class MavenPluginDescriptor
- extends ComponentSetDescriptor
+public class MavenPluginDescriptor extends ComponentSetDescriptor
{
/** */
private PluginDescriptor pluginDescriptor;
@@ -40,22 +37,21 @@
this.pluginDescriptor = pluginDescriptor;
}
- public String getPluginId()
+ public String getPluginId( )
{
- return pluginDescriptor.getId();
+ return pluginDescriptor.getId( );
}
// ----------------------------------------------------------------------
// Accessors
// ----------------------------------------------------------------------
-
- public PluginDescriptor getPluginDescriptor()
+ public PluginDescriptor getPluginDescriptor( )
{
return pluginDescriptor;
}
- public List getMavenMojoDescriptors()
+ public List getMavenMojoDescriptors( )
{
- return super.getComponents();
+ return super.getComponents( );
}
}
1.7 +11 -1 maven-components/maven-plugin/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java
Index: PluginDescriptor.java
===================================================================
RCS file: /home/cvs/maven-components/maven-plugin/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- PluginDescriptor.java 27 Jun 2004 07:39:08 -0000 1.6
+++ PluginDescriptor.java 8 Aug 2004 05:11:13 -0000 1.7
@@ -38,6 +38,11 @@
{
return mojos;
}
+
+ public void setMojos(List mojos)
+ {
+ this.mojos = mojos;
+ }
public String getId()
{
@@ -56,5 +61,10 @@
public List getDependencies()
{
return dependencies;
+ }
+
+ public void setDependencies(List dependencies)
+ {
+ this.dependencies = dependencies;
}
}
1.1 maven-components/maven-plugin-loaders/maven-marmalade-loader/src/main/java/org/apache/maven/plugin/loader/marmalade/MarmaladePluginDiscoverer.java
Index: MarmaladePluginDiscoverer.java
===================================================================
/* Created on Aug 7, 2004 */
package org.apache.maven.plugin.loader.marmalade;
import org.apache.maven.plugin.MavenMojoDescriptor;
import org.apache.maven.plugin.MavenPluginDependency;
import org.apache.maven.plugin.MavenPluginDescriptor;
import org.apache.maven.plugin.descriptor.Dependency;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.loader.marmalade.tags.MojoTag;
import org.codehaus.classworlds.ClassRealm;
import org.codehaus.marmalade.el.ognl.OgnlExpressionEvaluator;
import org.codehaus.marmalade.metamodel.MarmaladeTaglibResolver;
import org.codehaus.marmalade.model.MarmaladeScript;
import org.codehaus.marmalade.model.MarmaladeTag;
import org.codehaus.marmalade.parsetime.CachingScriptParser;
import org.codehaus.marmalade.parsetime.DefaultParsingContext;
import org.codehaus.marmalade.parsetime.MarmaladeModelBuilderException;
import org.codehaus.marmalade.parsetime.MarmaladeParsetimeException;
import org.codehaus.marmalade.parsetime.MarmaladeParsingContext;
import org.codehaus.marmalade.parsetime.ScriptBuilder;
import org.codehaus.marmalade.parsetime.ScriptParser;
import org.codehaus.marmalade.runtime.DefaultContext;
import org.codehaus.marmalade.runtime.MarmaladeExecutionContext;
import org.codehaus.marmalade.runtime.MarmaladeExecutionException;
import org.codehaus.marmalade.util.RecordingReader;
import org.codehaus.plexus.component.discovery.AbstractComponentDiscoverer;
import org.codehaus.plexus.component.factory.ComponentInstantiationException;
import org.codehaus.plexus.component.repository.ComponentDescriptor;
import org.codehaus.plexus.component.repository.ComponentSetDescriptor;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.jar.JarEntry;
import java.util.jar.JarInputStream;
/**
* @author jdcasey
*/
public class MarmaladePluginDiscoverer extends AbstractComponentDiscoverer
{
private static final String FILE_PROTO = "file";
private static final String MARMALADE_MOJO_PATH_PATTERN = ".*\\.mmld";
private static final String MARMALADE_COMPONENT_FACTORY = "marmalade";
protected String getComponentDescriptorLocation( )
{
return null;
}
protected ComponentSetDescriptor createComponentDescriptors(
Reader reader, String source )
throws Exception
{
return null;
}
public List findComponents( ClassRealm classRealm )
{
URL[] candidateLocations = classRealm.getConstituents( );
List componentSetDescriptors = new LinkedList( );
for ( int i = 0; i < candidateLocations.length; i++ )
{
URL url = candidateLocations[i];
String urlProto = url.getProtocol( );
try
{
PluginDescriptor pluginDescriptor = null;
if ( FILE_PROTO.equals( urlProto ) )
{
// scan as directory...
pluginDescriptor = scanAsDirectory( url.getPath( ),
classRealm );
}
else
{
// Skip this one...not sure what to do with it.
}
if ( pluginDescriptor != null )
{
MavenPluginDescriptor descriptor = new MavenPluginDescriptor( pluginDescriptor );
// Add the dependencies
List dependencies = new ArrayList();
for ( Iterator it = pluginDescriptor.getDependencies().iterator(); it.hasNext() ; )
{
Dependency dependency = (Dependency)it.next();
dependencies.add( new MavenPluginDependency( dependency ) );
}
descriptor.setDependencies( dependencies );
List mojoDescriptors = pluginDescriptor.getMojos( );
List componentDescriptors = new LinkedList( );
for ( Iterator it = mojoDescriptors.iterator( );
it.hasNext( ); )
{
MojoDescriptor mojoDescriptor = ( MojoDescriptor ) it
.next( );
mojoDescriptor.setImplementation(url.getPath());
ComponentDescriptor mmDesc = new MavenMojoDescriptor( mojoDescriptor );
mmDesc.setComponentFactory( MARMALADE_COMPONENT_FACTORY );
componentDescriptors.add( mmDesc );
}
descriptor.setComponents( componentDescriptors );
componentSetDescriptors.add( descriptor );
}
}
catch ( Exception e )
{
// TODO Log and what...skip???
e.printStackTrace( );
}
}
return componentSetDescriptors;
}
private PluginDescriptor scanAsJar( String path, ClassRealm classRealm )
throws Exception
{
String jarPart = path;
int bangIdx = jarPart.indexOf( "!" );
if ( bangIdx > -1 )
{
jarPart = jarPart.substring( 0, bangIdx );
}
File file = new File(path);
JarInputStream jis = new JarInputStream( new FileInputStream( file ) );
List mojoDescriptors = new LinkedList( );
List dependencies = new LinkedList( );
JarEntry je = null;
while ( ( je = jis.getNextJarEntry( ) ) != null )
{
String entryName = je.getName( );
if ( entryName.matches( MARMALADE_MOJO_PATH_PATTERN ) )
{
mojoDescriptors.add( loadMojoDescriptor( entryName,
dependencies, classRealm ) );
}
}
PluginDescriptor descriptor = null;
if ( !mojoDescriptors.isEmpty( ) )
{
descriptor = new PluginDescriptor( );
descriptor.setMojos( mojoDescriptors );
descriptor.setDependencies( dependencies );
}
return descriptor;
}
private PluginDescriptor scanAsDirectory( String path, ClassRealm classRealm )
throws Exception
{
List dependencies = new LinkedList( );
File file = new File(path);
PluginDescriptor descriptor = null;
if(!file.isDirectory() && path.endsWith(".jar")) {
// try to scan it as a jar...
descriptor = scanAsJar(path, classRealm);
}
else {
List mojoDescriptors = scanDir( path, file,
new LinkedList( ), dependencies, classRealm );
if ( !mojoDescriptors.isEmpty( ) )
{
descriptor = new PluginDescriptor( );
descriptor.setMojos( mojoDescriptors );
descriptor.setDependencies( dependencies );
}
}
return descriptor;
}
private List scanDir( String basePath, File parent, List results,
List dependencies, ClassRealm classRealm )
throws Exception
{
if ( parent.isDirectory( ) )
{
String[] subPaths = parent.list( );
for ( int i = 0; i < subPaths.length; i++ )
{
File file = new File( parent, subPaths[i] );
if ( file.isDirectory( ) )
{
results = scanDir( basePath, file, results, dependencies,
classRealm );
}
else if ( file.getPath( ).matches( MARMALADE_MOJO_PATH_PATTERN ) )
{
String scriptResource = file.getAbsolutePath( ).substring( basePath
.length( ) );
results.add( loadMojoDescriptor( scriptResource,
dependencies, classRealm ) );
}
}
}
return results;
}
private MojoDescriptor loadMojoDescriptor( String entryName,
List dependencies, ClassRealm classRealm )
throws Exception
{
MarmaladeParsingContext context = buildParsingContext( entryName,
classRealm );
MarmaladeScript script = getScriptInstance( context );
MojoDescriptor desc = getDescriptor( script, dependencies );
return desc;
}
private MojoDescriptor getDescriptor( MarmaladeScript script,
List dependencies ) throws ComponentInstantiationException
{
MojoTag root = ( MojoTag ) script.getRoot( );
root.describeOnly( true );
MarmaladeExecutionContext execCtx = new DefaultContext( );
try
{
script.execute( execCtx );
}
catch ( MarmaladeExecutionException e )
{
throw new ComponentInstantiationException(
"failed to execute component script: " + script.getLocation( ),
e );
}
MojoDescriptor descriptor = root.getMojoDescriptor( );
dependencies = root.addDependencies( dependencies );
return descriptor;
}
private MarmaladeScript getScriptInstance(
MarmaladeParsingContext parsingContext )
throws Exception
{
ScriptBuilder builder = null;
try
{
builder = new ScriptParser().parse( parsingContext );
}
catch ( MarmaladeParsetimeException e )
{
throw new Exception( "failed to parse component script: "
+ parsingContext.getInputLocation( ), e );
}
catch ( MarmaladeModelBuilderException e )
{
throw new Exception( "failed to parse component script: "
+ parsingContext.getInputLocation( ), e );
}
MarmaladeScript script = null;
try
{
script = builder.build( );
}
catch ( MarmaladeModelBuilderException e )
{
throw new Exception( "failed to build component script: "
+ parsingContext.getInputLocation( ), e );
}
MarmaladeTag root = script.getRoot( );
if ( !( root instanceof MojoTag ) )
{
throw new Exception(
"marmalade script does not contain a mojo header" );
}
return script;
}
private MarmaladeParsingContext buildParsingContext( String scriptName,
ClassRealm classRealm )
throws Exception
{
InputStream scriptResource = classRealm.getResourceAsStream( scriptName );
if ( scriptResource == null )
{
throw new Exception( "can't get script from classpath: "
+ scriptName );
}
RecordingReader scriptIn = new RecordingReader( new InputStreamReader(
scriptResource ) );
MarmaladeTaglibResolver resolver = new MarmaladeTaglibResolver( MarmaladeTaglibResolver.DEFAULT_STRATEGY_CHAIN );
OgnlExpressionEvaluator el = new OgnlExpressionEvaluator( );
MarmaladeParsingContext context = new DefaultParsingContext( );
context.setDefaultExpressionEvaluator( el );
context.setInput( scriptIn );
context.setInputLocation( scriptName );
context.setTaglibResolver( resolver );
return context;
}
}
1.1 maven-components/maven-plugin-loaders/maven-marmalade-loader/src/test/java/org/apache/maven/plugin/loader/marmalade/MarmaladePluginDiscovererTest.java
Index: MarmaladePluginDiscovererTest.java
===================================================================
/* Created on Aug 7, 2004 */
package org.apache.maven.plugin.loader.marmalade;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.net.URL;
import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
import org.apache.maven.plugin.MavenMojoDescriptor;
import org.apache.maven.plugin.MavenPluginDescriptor;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.Parameter;
import org.codehaus.classworlds.ClassRealm;
import org.codehaus.classworlds.ClassWorld;
import org.codehaus.classworlds.DefaultClassRealm;
import org.codehaus.plexus.component.repository.ComponentDependency;
import org.codehaus.plexus.component.repository.ComponentDescriptor;
import org.codehaus.plexus.component.repository.ComponentSetDescriptor;
import junit.framework.TestCase;
/**
* @author jdcasey
*/
public class MarmaladePluginDiscovererTest extends TestCase {
private static final String TEST_MOJO_SCRIPT = "<?xml version=\"1.0\"?>" +
"<mojo xmlns=\"marmalade:mojo\">" +
"<descriptor id=\"test\" goal=\"myTest\" instantiation-strategy=\"singleton\" execution-strategy=\"always\">" +
"<description>This is a test mojo script.</description>" +
"<prereqs><prereq name=\"test-prereq\"/></prereqs>" +
"<parameters>" +
"<parameter name=\"param\" type=\"String\" required=\"true\" validator=\"something\" expression=\"false\">" +
"<description>Parameter to test</description>" +
"</parameter>" +
"</parameters>" +
"<dependencies>" +
"<dependency groupId=\"marmalade\" artifactId=\"marmalade-core\" version=\"0.2\"/>" +
"</dependencies>" +
"</descriptor>" +
"<c:set xmlns:c=\"marmalade:jstl-core\" var=\"testVar\" value=\"testValue\"/>" +
"</mojo>";
public void testShouldFindPluginWithOneMojoFromClassDirectory() throws IOException {
File directory = new File("test-dir");
File scriptFile = new File(directory, "test.mmld");
try {
if (!directory.exists()) {
directory.mkdirs();
}
BufferedWriter writer = new BufferedWriter(new FileWriter(
scriptFile));
writer.write(TEST_MOJO_SCRIPT);
writer.flush();
writer.close();
ClassRealm realm = new DefaultClassRealm(new ClassWorld(), "root");
realm.addConstituent(directory.toURL());
MarmaladePluginDiscoverer discoverer = new MarmaladePluginDiscoverer();
List componentSets = discoverer.findComponents(realm);
verifyComponentSets(componentSets);
}
finally {
if(scriptFile.exists()) {
scriptFile.delete();
}
if(directory.exists()) {
directory.delete();
}
}
}
public void testShouldFindPluginWithOneMojoFromJar() throws IOException {
File jar = new File("test-plugin.jar");
try {
JarOutputStream jarOut = new JarOutputStream(new FileOutputStream(jar));
jarOut.putNextEntry(new JarEntry("test.mmld"));
jarOut.write(TEST_MOJO_SCRIPT.getBytes());
jarOut.flush();
jarOut.closeEntry();
jarOut.close();
ClassRealm realm = new DefaultClassRealm(new ClassWorld(), "root");
realm.addConstituent(new URL("jar:" + jar.toURL().toExternalForm() + "!/"));
MarmaladePluginDiscoverer discoverer = new MarmaladePluginDiscoverer();
List componentSets = discoverer.findComponents(realm);
verifyComponentSets(componentSets);
}
finally {
if(jar.exists()) {
jar.delete();
}
}
}
private void verifyComponentSets(List componentSets) {
assertNotNull(componentSets);
assertEquals(1, componentSets.size());
ComponentSetDescriptor setDescriptor = (ComponentSetDescriptor) componentSets
.get(0);
List components = setDescriptor.getComponents();
assertNotNull(components);
assertEquals(1, components.size());
ComponentDescriptor descriptor = (ComponentDescriptor) components
.get(0);
assertEquals("marmalade", descriptor.getComponentFactory());
MavenMojoDescriptor mojoDesc = (MavenMojoDescriptor) descriptor;
MojoDescriptor mojo = mojoDesc.getMojoDescriptor();
assertEquals("test", mojo.getId());
assertEquals("myTest", mojo.getGoal());
assertEquals("singleton", mojo.getInstantiationStrategy());
assertEquals("always", mojo.getExecutionStrategy());
List prereqs = mojoDesc.getPrereqs();
assertEquals(1, prereqs.size());
assertEquals("test-prereq", prereqs.get(0));
List dependencies = setDescriptor.getDependencies();
assertEquals(1, dependencies.size());
ComponentDependency dep = (ComponentDependency)dependencies.get(0);
assertEquals("marmalade", dep.getGroupId());
assertEquals("marmalade-core", dep.getArtifactId());
assertEquals("0.2", dep.getVersion());
List parameters = mojo.getParameters();
assertEquals(1, parameters.size());
Parameter param = (Parameter)parameters.get(0);
assertEquals("param", param.getName());
assertEquals("String", param.getType());
assertEquals(true, param.isRequired());
assertEquals("something", param.getValidator());
assertEquals("false", param.getExpression());
}
}
1.1 maven-components/maven-plugin-loaders/maven-marmalade-loader/src/main/resources/META-INF/marmalade/mojo.def
Index: mojo.def
===================================================================
org.apache.maven.plugin.loader.marmalade.tags.MojoTagLibrary