diff --git a/maven-plugins/maven-antrun-plugin/pom.xml b/maven-plugins/maven-antrun-plugin/pom.xml new file mode 100644 index 0000000000..a5414ffd61 --- /dev/null +++ b/maven-plugins/maven-antrun-plugin/pom.xml @@ -0,0 +1,54 @@ + + 4.0.0 + + maven-plugin-parent + org.apache.maven.plugins + 2.0-beta-1-SNAPSHOT + + maven-antrun-plugin + maven-plugin + 1.0-alpha-1-SNAPSHOT + + Maven AntRun Plugin + Runs ant scripts embedded in the POM + + + + kenney + Kenney Westerhof + kenney@apache.org + + + + + + org.apache.maven + maven-project + + + + plexus + plexus-container-default + + + + ant + ant + 1.6.5 + + + + + ant + ant-launcher + 1.6.5 + runtime + + + + + diff --git a/maven-plugins/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AntPropertyHelper.java b/maven-plugins/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AntPropertyHelper.java new file mode 100644 index 0000000000..02abfde158 --- /dev/null +++ b/maven-plugins/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AntPropertyHelper.java @@ -0,0 +1,77 @@ +package org.apache.maven.plugin.antrun; + +/* + * Copyright 2004-2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.project.MavenProject; +import org.apache.tools.ant.PropertyHelper; +import org.codehaus.plexus.util.introspection.ReflectionValueExtractor; + +/** + * Makes the ${expressions} used in Maven available to Ant as properties. + * + * @author Kenney Westerhof + */ +public class AntPropertyHelper + extends PropertyHelper +{ + private Log log; + private MavenProject mavenProject; + + public AntPropertyHelper( MavenProject project, Log l ) + { + mavenProject = project; + log = l; + } + + public synchronized Object getPropertyHook( String ns, String name, + boolean user + ) + { + log.debug( "getProperty(ns="+ns+", name="+name+", user="+user+")" ); + + try + { + if ( name.startsWith( "project." ) || name.equals( "basedir" ) ) + { + Object val = ReflectionValueExtractor.evaluate( + name.substring( "project.".length() ), + mavenProject + ); + + if ( val != null ) + { + return val; + } + } + } + catch ( Exception e ) + { + log.warn( "Error evaluating expression '" + name + "'", e ); + e.printStackTrace(); + } + + Object val = super.getPropertyHook( ns, name, user ); + + if ( val == null ) + { + val = System.getProperty( name.toString() ); + } + + return val; + } +} diff --git a/maven-plugins/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AntRunMojo.java b/maven-plugins/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AntRunMojo.java new file mode 100644 index 0000000000..7cba53817b --- /dev/null +++ b/maven-plugins/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AntRunMojo.java @@ -0,0 +1,89 @@ +package org.apache.maven.plugin.antrun; + +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.project.MavenProject; +import org.apache.tools.ant.DefaultLogger; +import org.apache.tools.ant.PropertyHelper; +import org.apache.tools.ant.Target; + +/** + * Maven AntRun Mojo. + * + * This plugin provides the capability of calling ant tasks + * from a POM. It is encouraged to move the actual tasks to + * a separate build.xml file and call that file with an + * <ant/> task. + * + * @author Kenney Westerhof + * + * @configurator override + * + * @goal run + * + * @description Runs the nested ant tasks + * + */ +public class AntRunMojo + extends AbstractMojo +{ + /** + * @parameter expression="${project}" + * @required + * @readonly + */ + private MavenProject project; + + /** + * @parameter expression="${tasks}" + */ + private Target tasks; + + /** + */ + public void execute() + throws MojoExecutionException + { + try + { + PropertyHelper propertyHelper = PropertyHelper.getPropertyHelper( + tasks.getProject() + ); + + propertyHelper.setNext( + new AntPropertyHelper( project, getLog() ) + ); + + DefaultLogger antLogger = new DefaultLogger(); + antLogger.setOutputPrintStream( System.out ); + antLogger.setErrorPrintStream( System.err ); + tasks.getProject().addBuildListener( antLogger ); + + getLog().info( "Executing tasks" ); + + tasks.execute(); + + getLog().info( "Executed tasks" ); + } + catch ( Exception e ) + { + throw new MojoExecutionException( "Error executing ant tasks", e ); + } + } +} diff --git a/maven-plugins/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/components/AntTargetConverter.java b/maven-plugins/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/components/AntTargetConverter.java new file mode 100644 index 0000000000..850f9542a2 --- /dev/null +++ b/maven-plugins/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/components/AntTargetConverter.java @@ -0,0 +1,202 @@ +package org.apache.maven.plugin.antrun.components; + +/* + * Copyright 2004-2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.apache.tools.ant.ComponentHelper; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.RuntimeConfigurable; +import org.apache.tools.ant.Target; +import org.apache.tools.ant.UnknownElement; + +import org.codehaus.plexus.component.configurator.ComponentConfigurationException; +import org.codehaus.plexus.component.configurator.converters.AbstractConfigurationConverter; +import org.codehaus.plexus.component.configurator.converters.ConfigurationConverter; +import org.codehaus.plexus.component.configurator.converters.lookup.ConverterLookup; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; +import org.codehaus.plexus.configuration.PlexusConfiguration; +import org.codehaus.plexus.configuration.PlexusConfigurationException; + +/** + * Plexus ConfigurationConverter to set up Ant Target component fields. + * + * @author Kenney Westerhof + */ +public class AntTargetConverter + extends AbstractConfigurationConverter +{ + public static final String ROLE = ConfigurationConverter.class.getName(); + + public boolean canConvert( Class type ) + { + return Target.class.isAssignableFrom( type ); + } + + public Object fromConfiguration( + ConverterLookup converterLookup, PlexusConfiguration configuration, + Class type, Class baseType, ClassLoader classLoader, + ExpressionEvaluator expressionEvaluator + ) + throws ComponentConfigurationException + { + Object retValue = fromExpression( configuration, expressionEvaluator, type ); + if ( retValue != null ) + { + return retValue; + } + + Class implementation = getClassForImplementationHint( type, configuration, classLoader ); + + retValue = instantiateObject( implementation ); + + processConfiguration( + (Target) retValue, classLoader, configuration, expressionEvaluator + ); + + return retValue; + } + + + private void processConfiguration( + Target target, ClassLoader classLoader, + PlexusConfiguration configuration, + ExpressionEvaluator expressionEvaluator + ) + throws ComponentConfigurationException + { + Project project = new Project(); + project.setName( "DummyProject" ); + + target.setName( "" ); + target.setProject( project ); + project.addTarget( target ); + + initDefinitions( project, target ); + + processConfiguration( + null, project, target, configuration, expressionEvaluator + ); + } + + + private void processConfiguration( + RuntimeConfigurable parentWrapper, Project project, Target target, + PlexusConfiguration configuration, ExpressionEvaluator expressionEvaluator + ) + throws ComponentConfigurationException + { + int items = configuration.getChildCount(); + + Object parent = parentWrapper == null ? null : parentWrapper.getProxy(); + + for ( int i = 0; i < items; i++ ) + { + PlexusConfiguration childConfiguration = configuration.getChild( i ); + UnknownElement task = new UnknownElement( + childConfiguration.getName() + ); + task.setProject( project ); + task.setNamespace( "" ); + task.setQName( childConfiguration.getName() ); + task.setTaskType( childConfiguration.getName() ); + task.setTaskName( childConfiguration.getName() ); + task.setOwningTarget( target ); + + if ( parent != null ) + { + ( (UnknownElement) parent ).addChild( task ); + } + else + { + target.addTask( task ); + } + + RuntimeConfigurable wrapper = new RuntimeConfigurable( + task, task.getTaskName() + ); + + try + { + if ( childConfiguration.getValue() != null ) + { + wrapper.addText( childConfiguration.getValue() ); + } + } + catch ( PlexusConfigurationException e ) + { + throw new ComponentConfigurationException( + "Error reading text value from element '" + + childConfiguration.getName() + "'", e + ); + } + + String [] attrNames = childConfiguration.getAttributeNames(); + + for ( int a = 0; a < attrNames.length; a++ ) + { + try + { + String v = childConfiguration.getAttribute( attrNames[a] ); + + try + { + Object evaluatedExpr = expressionEvaluator.evaluate( v ); + v = evaluatedExpr == null ? v : evaluatedExpr.toString(); + } + catch ( ExpressionEvaluationException e ) + { + throw new ComponentConfigurationException + ( + "Error evaluating value '" + v + "' of attribute '" + attrNames[a] + + "' of tag '" + childConfiguration.getName() + "'", e + ); + } + + wrapper.setAttribute( attrNames[a], v ); + } + catch ( PlexusConfigurationException e ) + { + throw new ComponentConfigurationException( + "Error getting attribute '" + attrNames[a] + + "' of tag '" + childConfiguration.getName() + "'", e + ); + } + } + + if ( parentWrapper != null ) + { + parentWrapper.addChild( wrapper ); + } + + processConfiguration( + wrapper, project, target, + childConfiguration, expressionEvaluator + ); + + } + } + + + protected void initDefinitions( Project project, Target target ) + { + ComponentHelper componentHelper = ComponentHelper.getComponentHelper( + project + ); + + componentHelper.initDefaultDefinitions(); + } +} diff --git a/maven-plugins/maven-antrun-plugin/src/main/resources/META-INF/plexus/components.xml b/maven-plugins/maven-antrun-plugin/src/main/resources/META-INF/plexus/components.xml new file mode 100644 index 0000000000..5aee9d07c1 --- /dev/null +++ b/maven-plugins/maven-antrun-plugin/src/main/resources/META-INF/plexus/components.xml @@ -0,0 +1,37 @@ + + + + + + org.codehaus.plexus.component.configurator.ComponentConfigurator + override + org.codehaus.plexus.component.configurator.BasicComponentConfigurator + + + org.codehaus.plexus.component.configurator.converters.lookup.ConverterLookup + override + + + + + + org.codehaus.plexus.component.configurator.converters.lookup.ConverterLookup + override + org.codehaus.plexus.component.configurator.converters.lookup.DefaultConverterLookup + + + org.codehaus.plexus.component.configurator.converters.ConfigurationConverter + AntTarget + customConverters + + + + + + org.codehaus.plexus.component.configurator.converters.ConfigurationConverter + AntTarget + org.apache.maven.plugin.antrun.components.AntTargetConverter + + + + diff --git a/maven-plugins/maven-antrun-plugin/src/site/site.xml b/maven-plugins/maven-antrun-plugin/src/site/site.xml new file mode 100644 index 0000000000..320c015a6e --- /dev/null +++ b/maven-plugins/maven-antrun-plugin/src/site/site.xml @@ -0,0 +1,42 @@ + + + + + + + Maven AntRun Plugin + http://maven.apache.org/images/apache-maven-project.png + http://maven.apache.org/maven2/ + + + http://maven.apache.org/images/maven-small.gif + + + + + + + + + + + + + ${reports} + + diff --git a/maven-plugins/maven-antrun-plugin/src/site/xdoc/introduction.xml b/maven-plugins/maven-antrun-plugin/src/site/xdoc/introduction.xml new file mode 100644 index 0000000000..5434221560 --- /dev/null +++ b/maven-plugins/maven-antrun-plugin/src/site/xdoc/introduction.xml @@ -0,0 +1,39 @@ + + + + + Kenney Westerhof + Introduction + + + +
+

+ This plugin provides the ability to run Ant tasks from + within Maven2. You can even embed your ant scripts in the POM! +

+ +

+ It is not the intention of this plugin to provide a means + of polluting the POM, so it's encouraged to move all your + Ant tasks to a build.xml file and just call it from the POM + using Ant's <ant/> task. +

+ +

+ One of the main goals of this plugin is to ease the migration from + Ant based projects to Maven 2. A lot of projects are currently unable + to migrate simply because they depend on some custom build functionality + that Maven2 doesn't provide yet. +

+ +

+ Even with plugins widely available there will always be simple, small + tasks that can be done using one or two lines of Ant script (like + deploying an EAR), until ofcourse a plugin comes available that does + the job. +

+ +
+ +
diff --git a/maven-plugins/maven-antrun-plugin/src/site/xdoc/usage.xml b/maven-plugins/maven-antrun-plugin/src/site/xdoc/usage.xml new file mode 100644 index 0000000000..7c930dcb3c --- /dev/null +++ b/maven-plugins/maven-antrun-plugin/src/site/xdoc/usage.xml @@ -0,0 +1,65 @@ + + + + + Kenney Westerhof + Introduction + + + +
+

+ For those of you unfamiliar with configuring a plugin see the example + below: + + + + 4.0.0 + my-test-app + my-test-group + 1.0-SNAPSHOT + + + + + + maven-antrun-plugin + + + generate-sources + + + + + + + + + run + + + + + + + + +]]> + +

+ +

+ The example above illustrates how to bind an ant script to a + lifecycle phase. You can add a script to each lifecycle phase, + by duplicating the ]]> section and specifying + a new phase. +

+
+ + +
diff --git a/maven-plugins/pom.xml b/maven-plugins/pom.xml index 14dff19349..fb1116d17e 100644 --- a/maven-plugins/pom.xml +++ b/maven-plugins/pom.xml @@ -52,6 +52,15 @@ Java Developer + + kenney + Kenney Westerhof + kenney@apache.org + Neonics + + Java Developer + + @@ -108,6 +117,11 @@ + + org.apache.maven + maven-project + 2.0-beta-1-SNAPSHOT + plexus plexus-container-default @@ -122,6 +136,7 @@ maven-ant-plugin + maven-antrun-plugin maven-assembly-plugin maven-checkstyle-plugin maven-clean-plugin