diff --git a/maven-plugins/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AbstractAntMojo.java b/maven-plugins/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AbstractAntMojo.java new file mode 100644 index 0000000000..8c7ecfe426 --- /dev/null +++ b/maven-plugins/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AbstractAntMojo.java @@ -0,0 +1,61 @@ +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; + +/** + * @author Kenney Westerhof + */ +public abstract class AbstractAntMojo + extends AbstractMojo +{ + protected void executeTasks( Target antTasks, MavenProject mavenProject ) + throws MojoExecutionException + { + try + { + PropertyHelper propertyHelper = PropertyHelper.getPropertyHelper( + antTasks.getProject() + ); + + propertyHelper.setNext( + new AntPropertyHelper( mavenProject, getLog() ) + ); + + DefaultLogger antLogger = new DefaultLogger(); + antLogger.setOutputPrintStream( System.out ); + antLogger.setErrorPrintStream( System.err ); + antTasks.getProject().addBuildListener( antLogger ); + + getLog().info( "Executing tasks" ); + + antTasks.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/AntRunMojo.java b/maven-plugins/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AntRunMojo.java index 7cba53817b..126dfe97b1 100644 --- 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 @@ -41,7 +41,7 @@ import org.apache.tools.ant.Target; * */ public class AntRunMojo - extends AbstractMojo + extends AbstractAntMojo { /** * @parameter expression="${project}" @@ -60,30 +60,6 @@ public class AntRunMojo 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 ); - } + executeTasks( tasks, project ); } } 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 index 850f9542a2..095e63ed16 100644 --- 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 @@ -18,6 +18,8 @@ package org.apache.maven.plugin.antrun.components; import org.apache.tools.ant.ComponentHelper; import org.apache.tools.ant.Project; +import org.apache.tools.ant.ProjectHelper; +import org.apache.tools.ant.Project; import org.apache.tools.ant.RuntimeConfigurable; import org.apache.tools.ant.Target; import org.apache.tools.ant.UnknownElement; @@ -112,9 +114,14 @@ public class AntTargetConverter task.setProject( project ); task.setNamespace( "" ); task.setQName( childConfiguration.getName() ); - task.setTaskType( childConfiguration.getName() ); + task.setTaskType( + ProjectHelper.genComponentName( + task.getNamespace(), childConfiguration.getName() + ) + ); task.setTaskName( childConfiguration.getName() ); task.setOwningTarget( target ); + task.init(); if ( parent != null ) { @@ -186,7 +193,6 @@ public class AntTargetConverter wrapper, project, target, childConfiguration, expressionEvaluator ); - } }