mirror of https://github.com/apache/maven.git
Moved execution code to abstract base class, so other ant-enabled plugins
may use this more easily. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@232501 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
59128be85b
commit
f14a81d454
|
@ -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 <a href="mailto:kenney@apache.org">Kenney Westerhof</a>
|
||||||
|
*/
|
||||||
|
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 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -41,7 +41,7 @@ import org.apache.tools.ant.Target;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class AntRunMojo
|
public class AntRunMojo
|
||||||
extends AbstractMojo
|
extends AbstractAntMojo
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @parameter expression="${project}"
|
* @parameter expression="${project}"
|
||||||
|
@ -60,30 +60,6 @@ public class AntRunMojo
|
||||||
public void execute()
|
public void execute()
|
||||||
throws MojoExecutionException
|
throws MojoExecutionException
|
||||||
{
|
{
|
||||||
try
|
executeTasks( tasks, project );
|
||||||
{
|
|
||||||
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 );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,8 @@ package org.apache.maven.plugin.antrun.components;
|
||||||
|
|
||||||
import org.apache.tools.ant.ComponentHelper;
|
import org.apache.tools.ant.ComponentHelper;
|
||||||
import org.apache.tools.ant.Project;
|
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.RuntimeConfigurable;
|
||||||
import org.apache.tools.ant.Target;
|
import org.apache.tools.ant.Target;
|
||||||
import org.apache.tools.ant.UnknownElement;
|
import org.apache.tools.ant.UnknownElement;
|
||||||
|
@ -112,9 +114,14 @@ public class AntTargetConverter
|
||||||
task.setProject( project );
|
task.setProject( project );
|
||||||
task.setNamespace( "" );
|
task.setNamespace( "" );
|
||||||
task.setQName( childConfiguration.getName() );
|
task.setQName( childConfiguration.getName() );
|
||||||
task.setTaskType( childConfiguration.getName() );
|
task.setTaskType(
|
||||||
|
ProjectHelper.genComponentName(
|
||||||
|
task.getNamespace(), childConfiguration.getName()
|
||||||
|
)
|
||||||
|
);
|
||||||
task.setTaskName( childConfiguration.getName() );
|
task.setTaskName( childConfiguration.getName() );
|
||||||
task.setOwningTarget( target );
|
task.setOwningTarget( target );
|
||||||
|
task.init();
|
||||||
|
|
||||||
if ( parent != null )
|
if ( parent != null )
|
||||||
{
|
{
|
||||||
|
@ -186,7 +193,6 @@ public class AntTargetConverter
|
||||||
wrapper, project, target,
|
wrapper, project, target,
|
||||||
childConfiguration, expressionEvaluator
|
childConfiguration, expressionEvaluator
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue