diff --git a/maven-core-it/it0015/src/main/scripts/org/apache/maven/it0015/it0015.mmld b/maven-core-it/it0015/src/main/scripts/org/apache/maven/it0015/it0015.mmld index 7bdf326a2e..d4a6b9bde8 100644 --- a/maven-core-it/it0015/src/main/scripts/org/apache/maven/it0015/it0015.mmld +++ b/maven-core-it/it0015/src/main/scripts/org/apache/maven/it0015/it0015.mmld @@ -5,8 +5,8 @@ outDir + java.lang.String ${project.build.directory} - target Output directory for files. diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java index 93371babb5..69c43ec7a5 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java @@ -654,10 +654,10 @@ else if ( mergedConfiguration.getChild( key, false ) != null ) Object value = expressionEvaluator.evaluate( expression ); - getLogger().debug( "Evaluated mojo parameter expression: \'" + expression + "\' to: " + value ); + getLogger().debug( "Evaluated mojo parameter expression: \'" + expression + "\' to: " + value + " for parameter: \'" + key + "\'" ); // TODO: remove. If there is a default value, required should have been removed by the descriptor generator - if ( value == null ) + if ( value == null && !"map-oriented".equals( goal.getComponentConfigurator() ) ) { Object defaultValue; try diff --git a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/MojoDescriptor.java b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/MojoDescriptor.java index e87cb8bc1d..9fbb95be60 100755 --- a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/MojoDescriptor.java +++ b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/MojoDescriptor.java @@ -154,7 +154,7 @@ public void setRequiresProject( boolean requiresProject ) this.requiresProject = requiresProject; } - public boolean isRequiresProject() + public boolean getRequiresProject() { return requiresProject; } diff --git a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java index 02189811ee..80f66bd0df 100755 --- a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java +++ b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java @@ -100,6 +100,13 @@ public MojoDescriptor buildComponentDescriptor( PlexusConfiguration c, PluginDes mojo.setComponentConfigurator( configuratorConfig.getValue() ); } + PlexusConfiguration composerConfig = c.getChild( "composer" ); + + if ( composerConfig != null ) + { + mojo.setComponentComposer( composerConfig.getValue() ); + } + String phase = c.getChild( "phase" ).getValue(); if ( phase != null ) @@ -125,6 +132,20 @@ public MojoDescriptor buildComponentDescriptor( PlexusConfiguration c, PluginDes mojo.setRequiresDependencyResolution( dependencyResolution ); } + String requiresProject = c.getChild( "requiresProject" ).getValue(); + + if ( requiresProject != null ) + { + mojo.setRequiresProject( "true".equals( requiresProject ) ); + } + + String requiresOnline = c.getChild( "requiresOnline" ).getValue(); + + if ( requiresOnline != null ) + { + mojo.setRequiresOnline( "true".equals( requiresOnline ) ); + } + // ---------------------------------------------------------------------- // Parameters // ---------------------------------------------------------------------- @@ -163,12 +184,8 @@ public MojoDescriptor buildComponentDescriptor( PlexusConfiguration c, PluginDes parameter.setDescription( d.getChild( "description" ).getValue() ); - // TODO: remove parameter.setExpression( d.getChild( "expression" ).getValue() ); - // TODO: remove - parameter.setDefaultValue( d.getChild( "default" ).getValue() ); - parameter.setDeprecated( d.getChild( "deprecated" ).getValue() ); parameters.add( parameter ); diff --git a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java index 38bd713b20..124be80826 100644 --- a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java +++ b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java @@ -71,9 +71,7 @@ public void execute( String destinationDirectory, Set mavenMojoDescriptors, Mave element( w, "goalPrefix", goalPrefix ); - element( w, "isolatedRealm", "true" ); - - w.startElement( "mojos" ); + w.startElement( "mojos" ); for ( Iterator it = mavenMojoDescriptors.iterator(); it.hasNext(); ) { @@ -122,6 +120,18 @@ protected void processPluginDescriptor( MojoDescriptor mojoDescriptor, XMLWriter // // ---------------------------------------------------------------------- + element( w, "requiresProject", "" + mojoDescriptor.getRequiresProject() ); + + // ---------------------------------------------------------------------- + // + // ---------------------------------------------------------------------- + + element( w, "requiresOnline", "" + mojoDescriptor.requiresOnline() ); + + // ---------------------------------------------------------------------- + // + // ---------------------------------------------------------------------- + if ( mojoDescriptor.getPhase() != null ) { element( w, "phase", mojoDescriptor.getPhase() ); @@ -173,6 +183,19 @@ protected void processPluginDescriptor( MojoDescriptor mojoDescriptor, XMLWriter // // ---------------------------------------------------------------------- + if ( mojoDescriptor.getComponentComposer() != null ) + { + w.startElement( "composer" ); + + w.writeText( mojoDescriptor.getComponentComposer() ); + + w.endElement(); + } + + // ---------------------------------------------------------------------- + // + // ---------------------------------------------------------------------- + w.startElement( "instantiationStrategy" ); w.writeText( mojoDescriptor.getInstantiationStrategy() ); @@ -205,8 +228,7 @@ protected void processPluginDescriptor( MojoDescriptor mojoDescriptor, XMLWriter String expression = parameter.getExpression(); - if ( StringUtils.isNotEmpty( expression ) && - ( expression.startsWith( "${component." ) || expression.startsWith( "#component." ) ) ) + if ( StringUtils.isNotEmpty( expression ) && expression.startsWith( "${component." ) ) { // treat it as a component...a requirement, in other words. @@ -241,11 +263,6 @@ protected void processPluginDescriptor( MojoDescriptor mojoDescriptor, XMLWriter element( w, "description", parameter.getDescription() ); - if ( StringUtils.isEmpty( expression ) ) - { - expression = parameter.getDefaultValue(); - } - if ( expression != null && expression.length() > 0 ) { configuration.put( parameter, expression ); @@ -300,17 +317,10 @@ protected void processPluginDescriptor( MojoDescriptor mojoDescriptor, XMLWriter w.startElement( "requirement" ); - String role; // remove "component." plus expression delimiters String expression = requirement.getExpression(); - if ( expression.startsWith( "${" ) ) - { - role = expression.substring( "${component.".length(), expression.length() - 1 ); - } - else - { - role = expression.substring( "#component.".length() ); - } + String role = expression.substring( "${component.".length(), expression.length() - 1 ); + element( w, "role", role ); element( w, "field-name", requirement.getName() ); diff --git a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/util/PluginUtils.java b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/util/PluginUtils.java index 48ec622fd9..e03761c9b8 100644 --- a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/util/PluginUtils.java +++ b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/util/PluginUtils.java @@ -16,6 +16,7 @@ * limitations under the License. */ +import org.apache.maven.artifact.Artifact; import org.apache.maven.model.Dependency; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.util.DirectoryScanner; @@ -67,17 +68,21 @@ public static void writeDependencies( XMLWriter w, MavenProject project ) for ( Iterator it = project.getDependencies().iterator(); it.hasNext(); ) { Dependency dep = (Dependency) it.next(); - w.startElement( "dependency" ); + + if ( !Artifact.SCOPE_TEST.equals( dep.getScope() ) ) + { + w.startElement( "dependency" ); - PluginUtils.element( w, "groupId", dep.getGroupId() ); + PluginUtils.element( w, "groupId", dep.getGroupId() ); - PluginUtils.element( w, "artifactId", dep.getArtifactId() ); + PluginUtils.element( w, "artifactId", dep.getArtifactId() ); - PluginUtils.element( w, "type", dep.getType() ); + PluginUtils.element( w, "type", dep.getType() ); - PluginUtils.element( w, "version", dep.getVersion() ); + PluginUtils.element( w, "version", dep.getVersion() ); - w.endElement(); + w.endElement(); + } } w.endElement(); diff --git a/maven-plugin-tools/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractor.java b/maven-plugin-tools/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractor.java index f5b954743a..9a88d17198 100644 --- a/maven-plugin-tools/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractor.java +++ b/maven-plugin-tools/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractor.java @@ -50,13 +50,7 @@ public class JavaMojoDescriptorExtractor extends AbstractLogEnabled implements MojoDescriptorExtractor { - public static final String MAVEN_PLUGIN_ID = "maven.plugin.id"; - - public static final String MAVEN_PLUGIN_DESCRIPTION = "maven.plugin.description"; - - public static final String MAVEN_PLUGIN_INSTANTIATION = "maven.plugin.instantiation"; - - public static final String MAVEN_PLUGIN_MODE = "maven.plugin.mode"; + public static final String MAVEN_PLUGIN_INSTANTIATION = "instantiationStrategy"; public static final String PARAMETER = "parameter"; @@ -78,6 +72,10 @@ public class JavaMojoDescriptorExtractor public static final String GOAL_REQUIRES_DEPENDENCY_RESOLUTION = "requiresDependencyResolution"; + public static final String GOAL_REQUIRES_PROJECT = "requiresProject"; + + public static final String GOAL_REQUIRES_ONLINE = "requiresOnline"; + public static final String GOAL_MULTI_EXECUTION_STRATEGY = "attainAlways"; protected void validateParameter( Parameter parameter, int i ) @@ -123,16 +121,9 @@ private MojoDescriptor createMojoDescriptor( JavaSource javaSource, PluginDescri mojoDescriptor.setImplementation( javaClass.getFullyQualifiedName() ); - DocletTag tag; + mojoDescriptor.setDescription( javaClass.getComment() ); - tag = findInClassHierarchy( javaClass, MAVEN_PLUGIN_DESCRIPTION ); - - if ( tag != null ) - { - mojoDescriptor.setDescription( tag.getValue() ); - } - - tag = findInClassHierarchy( javaClass, MAVEN_PLUGIN_INSTANTIATION ); + DocletTag tag = findInClassHierarchy( javaClass, MAVEN_PLUGIN_INSTANTIATION ); if ( tag != null ) { @@ -199,6 +190,28 @@ private MojoDescriptor createMojoDescriptor( JavaSource javaSource, PluginDescri mojoDescriptor.setRequiresDependencyResolution( value ); } + // ---------------------------------------------------------------------- + // Project flag + // ---------------------------------------------------------------------- + + DocletTag requiresProject = findInClassHierarchy( javaClass, GOAL_REQUIRES_PROJECT ); + + if ( requiresProject != null ) + { + mojoDescriptor.setRequiresProject( true ); + } + + // ---------------------------------------------------------------------- + // Online flag + // ---------------------------------------------------------------------- + + DocletTag requiresOnline = findInClassHierarchy( javaClass, GOAL_REQUIRES_ONLINE ); + + if ( requiresOnline != null ) + { + mojoDescriptor.setRequiresOnline( true ); + } + extractParameters( mojoDescriptor, javaClass ); return mojoDescriptor; diff --git a/maven-script/maven-script-marmalade/src/main/java/org/apache/maven/script/marmalade/tags/AbstractStringValuedBodyTag.java b/maven-script/maven-script-marmalade/src/main/java/org/apache/maven/script/marmalade/tags/AbstractStringValuedBodyTag.java index 713df27bf5..d203f412da 100644 --- a/maven-script/maven-script-marmalade/src/main/java/org/apache/maven/script/marmalade/tags/AbstractStringValuedBodyTag.java +++ b/maven-script/maven-script-marmalade/src/main/java/org/apache/maven/script/marmalade/tags/AbstractStringValuedBodyTag.java @@ -34,7 +34,7 @@ protected boolean alwaysProcessChildren() protected void doExecute( MarmaladeExecutionContext context ) throws MarmaladeExecutionException { - String bodyValue = (String) getBody( context, String.class ); + String bodyValue = getRawBody( context ); setValue( bodyValue ); } diff --git a/maven-site/src/site/xdoc/developing-plugins-with-marmalade.xml b/maven-site/src/site/xdoc/developers/developing-plugins-with-marmalade.xml similarity index 100% rename from maven-site/src/site/xdoc/developing-plugins-with-marmalade.xml rename to maven-site/src/site/xdoc/developers/developing-plugins-with-marmalade.xml diff --git a/maven-site/src/site/xdoc/developers/mojo-api-specification.xml b/maven-site/src/site/xdoc/developers/mojo-api-specification.xml new file mode 100644 index 0000000000..ed9b75b709 --- /dev/null +++ b/maven-site/src/site/xdoc/developers/mojo-api-specification.xml @@ -0,0 +1,459 @@ + + + + + + Maven 2.0 - Mojo API Specification + John Casey + + +
+

Starting with Maven 2.0, plugins can be written in Java or any of a + number of scripting languages (currently just marmalade - we are + working to implement others). Additionally, Maven tries to stay out of + the way of the programmer with its new Mojo API. This opens up the + opportunity for many Mojos to be reused outside of Maven, or bridged + into Maven from external systems like Ant.

+

NOTE: For now, we will limit the discussion to Java-based mojos, since + each scripting language will present these same basic requirements with + various forms of implementation.

+

Although the requirements on Mojos are minimal by design, there are + still a very few requirements that Mojo developers must keep in mind. Basically, these Mojo requirements are embodied by the + org.apache.maven.plugin.Mojo interface, which the Mojo + must implement (or else extend its abstract base class counterpart + org.apache.maven.plugin.AbstractMojo). This interface + guarantees the correct execution contract for the mojo: no parameters, + void return type, and a throws clause that allows only + org.apache.maven.plugin.MojoExecutionException and its + derivatives. It also guarantees that the Mojo will have access to the + standard Maven user-feedback mechanism, + org.apache.maven.monitor.logging.Log, so the Mojo can + communicate important events to the console or other log sink.

+

As mentioned before, each Plugin - or packaged set of Mojos - must + provide a descriptor called plugin.xml under the path + META-INF/maven inside the Plugin jar file. Fortunately, + Maven also provides a set of javadoc annotations and tools to generate + this descriptor, so developers don't have to worry about directly + authoring or maintaining a separate XML metadata file.

+

To serve as a quick reference for the developer, the rest of this page + will document these features (the API, along with the annotations) + which are considered the best practice for developing Mojos.

+
+
+ +

This interface forms the contract required for Mojos to interact + with the Maven infrastructure. It features an execute() + method, which trigger's the Mojo's build-process behavior, and can + throw a MojoExecutionException if an error condition + occurs. See below for a discussion on proper use of this + Exception class. Also included is the + setLog(..) method, which simply allows Maven to inject a + logging mechanism which will allow the Mojo to communicate to the + outside world through standard Maven channels.

+

+

    + + Method Summary: + +
  • + + void setLog( org.apache.maven.monitor.logging.Log ) + +

    Inject a standard Maven logging mechanism to allow this Mojo + to communicate events and feedback to the user.

    +
  • +
  • + + void execute() throws org.apache.maven.plugin.MojoExecutionException + +

    Perform whatever build-process behavior this Mojo implements. + This is the main trigger for the Mojo inside the Maven system, + and allows the Mojo to communicate fatal errors by throwing an + instance of MojoExecutionException.

    +

    The MojoExecutionException (and all error + conditions inside the Mojo) should be handled very carefully. + The simple wrapping of lower-level exceptions without providing + any indication of a user-friendly probable cause is strictly + discouraged. In fact, a much better course of action is to + provide error handling code (try/catch stanzas) for each + coherent step within the Mojo's execution. Developers are then + in a much better position to diagnose the cause of any error, + and provide user-friendly feedback in the message of the + MojoExecutionException.

    +
  • +
+

+
+ +

Currently, this abstract base class simply takes care of managing + the Maven log for concrete derivations. In keeping with this, it + provides a protected method, getLog():Log, + to furnish Log access to these concrete implementations.

+

+

    + + Method Summary: + +
  • + + public void setLog( org.apache.maven.monitor.logging.Log ) + +

    + [IMPLEMENTED] +

    +

    Inject a standard Maven logging mechanism to allow this Mojo + to communicate events and feedback to the user.

    +
  • +
  • + protected Log getLog() +

    + [IMPLEMENTED] +

    +

    Furnish access to the standard Maven logging mechanism which + is managed in this base class.

    +
  • +
  • + + void execute() throws org.apache.maven.plugin.MojoExecutionException + +

    + [ABSTRACT] +

    +

    Perform whatever build-process behavior this Mojo implements. + See the documentation for Mojo above for more + information.

    +
  • +
+

+
+ +

This interface supplies the API for providing feedback to the user + from the Mojo, using standard Maven channels. There should be no big + surprises here, although you may notice that the methods accept + java.lang.CharSequence rather than + java.lang.String. This is provided mainly as a + convenience, to enable developers to pass things like + StringBuffer directly into the logger, rather than + formatting first by calling toString().

+

+

    + + Method Summary: + +
  • + void debug( java.lang.CharSequence ) +

    Send a message to the user in the debug error level.

    +
  • +
  • + + void debug( java.lang.CharSequence, java.lang.Throwable ) + +

    Send a message (and accompanying exception) to the user in the + debug error level. The error's stacktrace will be output + when this error level is enabled.

    +
  • +
  • + void debug( java.lang.Throwable ) +

    Send an exception to the user in the debug error level. + The stack trace for this exception will be output when this + error level is enabled.

    +
  • +
  • + void info( java.lang.CharSequence ) +

    Send a message to the user in the info error level.

    +
  • +
  • + + void info( java.lang.CharSequence, java.lang.Throwable ) + +

    Send a message (and accompanying exception) to the user in the + info error level. The error's stacktrace will be output + when this error level is enabled.

    +
  • +
  • + void info( java.lang.CharSequence ) +

    Send an exception to the user in the info error level. + The stack trace for this exception will be output when this + error level is enabled.

    +
  • +
  • + void warn( java.lang.CharSequence ) +

    Send a message to the user in the warn error level.

    +
  • +
  • + + void warn( java.lang.CharSequence, java.lang.Throwable ) + +

    Send a message (and accompanying exception) to the user in the + warn error level. The error's stacktrace will be output + when this error level is enabled.

    +
  • +
  • + void warn( java.lang.CharSequence ) +

    Send an exception to the user in the warn error level. + The stack trace for this exception will be output when this + error level is enabled.

    +
  • +
  • + void error( java.lang.CharSequence ) +

    Send a message to the user in the error error level.

    +
  • +
  • + + void error( java.lang.CharSequence, java.lang.Throwable ) + +

    Send a message (and accompanying exception) to the user in the + error error level. The error's stacktrace will be output + when this error level is enabled.

    +
  • +
  • + void error( java.lang.CharSequence ) +

    Send an exception to the user in the error error level. + The stack trace for this exception will be output when this + error level is enabled.

    +
  • +
+

+
+
+
+

In addition to the normal Java requirements in terms of interfaces + and/or abstract base classes which need to be implemented, a plugin + descriptor must accompany these classes inside the plugin jar. This + descriptor file is used to provide metadata about the parameters and + other component requirements for a set of Mojos so that Maven can + initialize the Mojo and validate it's configuration before executing + it. As such, the plugin descriptor has a certain set of information + that is required for each Mojo specification to be valid, as well as + requirements for the overall plugin descriptor itself.

+

NOTE: In the following discussion, bolded items are the descriptor's + element name along with a javadoc annotation (if applicable) supporting + that piece of the plugin descriptor. A couple of examples are: + someElement + (@annotation parameterName="parameterValue") or + someOtherElement (@annotation <rawAnnotationValue>).

+

The plugin descriptor must be provided in a jar resource with the + path: META-INF/maven/plugin.xml, and it must contain the + following:

+

+

+

+

Each Mojo specified inside a plugin descriptor must provide the + following:

+

+

+

+

Each Mojo specifies the parameters that it expects to be able to work + with. These parameters are the Mojo's link to the outside world, and + will be satisfied through a combination of POM/project values, plugin + configurations (from the POM and configuration defaults), and System + properties.

+

NOTE[1]: For this discussion on Mojo parameters, a single + annotation may span multiple elements in the descriptor's specification + for that parameter. Duplicate annotation declarations in this section + will be used to detail each parameter of an annotation separately.

+

NOTE[2]: In many cases, simply annotating a Mojo field with + @parameter will be enough to allow injection of a value for that + parameter using POM configuration elements. The discussion below + shows advanced usage for this annotation, along with others.

+

Each parameter for a Mojo must be specified in the + plugin descriptor as follows:

+

+

+

+

The final component of a plugin descriptor is the dependencies. This + enables the plugin to function independently of it's POM (or at least + to declare the libraries it needs to run). Dependencies are taken from + the runtime scope of the plugin's calculated dependencies (from + the POM). Dependencies are specified in exactly the same manner as in + the POM, except for the <scope> element (all dependencies in the + plugin descriptor are assumed to be runtime, because this is a + runtime profile for the plugin).

+
+
+

By now, we've mentioned the plugin tools several times without telling + you what they are or how to use them. instead of writing (and + maintaining) this metadata file by hand, Maven 2.0 ships with some + tools to aid developers in this task. In fact, the only thing a plugin + developer needs to do is declare his project to be a plugin from within + the POM. Once this is done, Maven will call the appropriate descriptor + generators, etc. to produce an artifact that is ready for use within + Maven builds. The section below describes the changes to the POM + which are necessary to create plugin artifacts.

+
+
+

From the POM, Maven plugin projects look quite similar to any other + project. For pure java plugins, the differences are even smaller than + for script-based plugins. The following details the POM elements + which are necessary to build a Maven plugin artifact.

+

+

+

+

After making the changes above, the developer can simply call m2 + install to install the plugin to the local repository. (Any of + the other standard lifecycle targets like package, deploy, etc. are + also available in like fashion.)

+
+
+
+ +
\ No newline at end of file diff --git a/maven-site/src/site/xdoc/index.xml b/maven-site/src/site/xdoc/index.xml index 3ef0984678..69470300d7 100644 --- a/maven-site/src/site/xdoc/index.xml +++ b/maven-site/src/site/xdoc/index.xml @@ -141,7 +141,7 @@ -->
  • - Developing Plugins with Marmalade + Developing Plugins with Marmalade
  • diff --git a/maven-site/src/site/xdoc/navigation.xml b/maven-site/src/site/xdoc/navigation.xml index 4c35885aab..ba63073135 100644 --- a/maven-site/src/site/xdoc/navigation.xml +++ b/maven-site/src/site/xdoc/navigation.xml @@ -17,7 +17,7 @@ - +