Class AntRunMojo

  • All Implemented Interfaces:
    org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo

    @Mojo(name="run",
          threadSafe=true,
          requiresDependencyResolution=TEST)
    public class AntRunMojo
    extends org.apache.maven.plugin.AbstractMojo
    Maven AntRun Mojo.
    This plugin provides the capability of calling Ant tasks from a POM by running the nested Ant tasks inside the <tasks/> parameter. It is encouraged to move the actual tasks to a separate build.xml file and call that file with an <ant/> task.
    Version:
    $Id: AntRunMojo.java 1645339 2014-12-13 17:56:59Z khmarbaise $
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String ANTLIB
      The path to The XML file containing the definition of the Maven tasks.
      private java.lang.String antTargetName
      The name used for the Ant target
      private java.lang.String customTaskPrefix
      The xml tag prefix to use for the built in Ant tasks.
      static java.lang.String DEFAULT_ANT_TARGET_NAME
      The default target name.
      static java.lang.String DEFAULT_MAVEN_PROJECT_HELPER_REFID
      The refid used to store the Maven project object in the Ant build.
      static java.lang.String DEFAULT_MAVEN_PROJECT_REFID
      The refid used to store the Maven project object in the Ant build.
      static java.lang.String DEPENDENCY_PREFIX
      Deprecated.
      This should only be used for generating the old property format.
      private boolean exportAntProperties
      Specifies whether the Ant properties should be propagated to the Maven properties.
      private boolean failOnError
      Specifies whether a failure in the Ant build leads to a failure of the Maven build.
      protected org.apache.maven.artifact.repository.ArtifactRepository localRepository
      The local Maven repository
      private java.util.List<org.apache.maven.artifact.Artifact> pluginArtifacts
      The plugin dependencies.
      private org.apache.maven.project.MavenProject project
      The Maven project object
      private org.apache.maven.project.MavenProjectHelper projectHelper
      The Maven project helper object
      private java.lang.String propertyPrefix
      String to prepend to project and dependency property names.
      private boolean skip
      Specifies whether the Antrun execution should be skipped.
      private java.io.File sourceRoot
      Deprecated.
      Use the build-helper-maven-plugin to bind source directories
      private org.codehaus.plexus.configuration.PlexusConfiguration target
      The XML for the Ant target.
      static java.lang.String TASK_URI
      The URI which defines the built in Ant tasks
      private org.codehaus.plexus.configuration.PlexusConfiguration tasks
      Deprecated.
      Use target instead
      private java.io.File testSourceRoot
      Deprecated.
      Use the build-helper-maven-plugin to bind test source directories
      static java.lang.String UTF_8
      The default encoding to use for the generated Ant build.
      private java.lang.String versionsPropertyName
      The name of a property containing the list of all dependency versions.
      • Fields inherited from interface org.apache.maven.plugin.Mojo

        ROLE
    • Constructor Summary

      Constructors 
      Constructor Description
      AntRunMojo()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      java.lang.String checkTargetName​(org.codehaus.plexus.configuration.PlexusConfiguration antTargetConfig)  
      void copyProperties​(org.apache.maven.project.MavenProject mavenProject, org.apache.tools.ant.Project antProject)
      Copy properties from the Maven project to the Ant project.
      void copyProperties​(org.apache.tools.ant.Project antProject, org.apache.maven.project.MavenProject mavenProject)
      Copy properties from the Ant project to the Maven project.
      void execute()
      private java.lang.String findFragment​(org.apache.tools.ant.BuildException buildException)  
      static java.lang.String getDependencyArtifactPropertyName​(org.apache.maven.artifact.Artifact artifact)
      Deprecated.
      The dependency conflict ID should be used as the property name.
      org.apache.maven.project.MavenProject getMavenProject()
      Get the current Maven project
      org.apache.tools.ant.types.Path getPathFromArtifacts​(java.util.Collection<org.apache.maven.artifact.Artifact> artifacts, org.apache.tools.ant.Project antProject)  
      void initMavenTasks​(org.apache.tools.ant.Project antProject)  
      void stringReplace​(java.lang.StringBuilder text, java.lang.String match, java.lang.String with)
      Replace text in a StringBuilder.
      private java.io.File writeTargetToProjectFile()
      Write the Ant target and surrounding tags to a temporary file
      • Methods inherited from class org.apache.maven.plugin.AbstractMojo

        getLog, getPluginContext, setLog, setPluginContext
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DEFAULT_MAVEN_PROJECT_REFID

        public static final java.lang.String DEFAULT_MAVEN_PROJECT_REFID
        The refid used to store the Maven project object in the Ant build.
        See Also:
        Constant Field Values
      • DEFAULT_MAVEN_PROJECT_HELPER_REFID

        public static final java.lang.String DEFAULT_MAVEN_PROJECT_HELPER_REFID
        The refid used to store the Maven project object in the Ant build.
        See Also:
        Constant Field Values
      • DEFAULT_ANT_TARGET_NAME

        public static final java.lang.String DEFAULT_ANT_TARGET_NAME
        The default target name.
        See Also:
        Constant Field Values
      • UTF_8

        public static final java.lang.String UTF_8
        The default encoding to use for the generated Ant build.
        See Also:
        Constant Field Values
      • antTargetName

        private java.lang.String antTargetName
        The name used for the Ant target
      • ANTLIB

        public static final java.lang.String ANTLIB
        The path to The XML file containing the definition of the Maven tasks.
        See Also:
        Constant Field Values
      • TASK_URI

        public static final java.lang.String TASK_URI
        The URI which defines the built in Ant tasks
        See Also:
        Constant Field Values
      • project

        @Parameter(defaultValue="${project}",
                   readonly=true,
                   required=true)
        private org.apache.maven.project.MavenProject project
        The Maven project object
      • projectHelper

        @Component
        private org.apache.maven.project.MavenProjectHelper projectHelper
        The Maven project helper object
      • pluginArtifacts

        @Parameter(property="plugin.artifacts",
                   required=true,
                   readonly=true)
        private java.util.List<org.apache.maven.artifact.Artifact> pluginArtifacts
        The plugin dependencies.
      • localRepository

        @Parameter(property="localRepository",
                   readonly=true)
        protected org.apache.maven.artifact.repository.ArtifactRepository localRepository
        The local Maven repository
      • propertyPrefix

        @Parameter(defaultValue="")
        private java.lang.String propertyPrefix
        String to prepend to project and dependency property names.
        Since:
        1.4
      • customTaskPrefix

        @Parameter(defaultValue="")
        private java.lang.String customTaskPrefix
        The xml tag prefix to use for the built in Ant tasks. This prefix needs to be prepended to each task referenced in the antrun target config. For example, a prefix of "mvn" means that the attachartifact task is referenced by "<mvn:attachartifact>" The default value of an empty string means that no prefix is used for the tasks.
        Since:
        1.5
      • versionsPropertyName

        @Parameter(defaultValue="maven.project.dependencies.versions")
        private java.lang.String versionsPropertyName
        The name of a property containing the list of all dependency versions. This is used for the removing the versions from the filenames.
      • tasks

        @Parameter
        private org.codehaus.plexus.configuration.PlexusConfiguration tasks
        Deprecated.
        Use target instead
        The XML for the Ant task. You can add anything you can add between <target> and </target> in a build.xml.
      • target

        @Parameter
        private org.codehaus.plexus.configuration.PlexusConfiguration target
        The XML for the Ant target. You can add anything you can add between <target> and </target> in a build.xml.
        Since:
        1.5
      • sourceRoot

        @Parameter(property="sourceRoot")
        private java.io.File sourceRoot
        Deprecated.
        Use the build-helper-maven-plugin to bind source directories
        This folder is added to the list of those folders containing source to be compiled. Use this if your Ant script generates source code.
      • testSourceRoot

        @Parameter(property="testSourceRoot")
        private java.io.File testSourceRoot
        Deprecated.
        Use the build-helper-maven-plugin to bind test source directories
        This folder is added to the list of those folders containing source to be compiled for testing. Use this if your Ant script generates test source code.
      • skip

        @Parameter(property="maven.antrun.skip",
                   defaultValue="false")
        private boolean skip
        Specifies whether the Antrun execution should be skipped.
        Since:
        1.7
      • exportAntProperties

        @Parameter(defaultValue="false")
        private boolean exportAntProperties
        Specifies whether the Ant properties should be propagated to the Maven properties.
        Since:
        1.7
      • failOnError

        @Parameter(defaultValue="true")
        private boolean failOnError
        Specifies whether a failure in the Ant build leads to a failure of the Maven build. If this value is false, the Maven build will proceed even if the Ant build fails. If it is true, then the Maven build fails if the Ant build fails.
        Since:
        1.7
      • DEPENDENCY_PREFIX

        public static final java.lang.String DEPENDENCY_PREFIX
        Deprecated.
        This should only be used for generating the old property format.
        Prefix for legacy property format.
        See Also:
        Constant Field Values
    • Constructor Detail

      • AntRunMojo

        public AntRunMojo()
    • Method Detail

      • execute

        public void execute()
                     throws org.apache.maven.plugin.MojoExecutionException
        Throws:
        org.apache.maven.plugin.MojoExecutionException
      • getPathFromArtifacts

        public org.apache.tools.ant.types.Path getPathFromArtifacts​(java.util.Collection<org.apache.maven.artifact.Artifact> artifacts,
                                                                    org.apache.tools.ant.Project antProject)
                                                             throws org.apache.maven.artifact.DependencyResolutionRequiredException
        Parameters:
        artifacts - Artifact collection.
        antProject - Project
        Returns:
        Path
        Throws:
        org.apache.maven.artifact.DependencyResolutionRequiredException - In case of a failure.
      • copyProperties

        public void copyProperties​(org.apache.maven.project.MavenProject mavenProject,
                                   org.apache.tools.ant.Project antProject)
        Copy properties from the Maven project to the Ant project.
        Parameters:
        mavenProject - MavenProject
        antProject - Project
      • copyProperties

        public void copyProperties​(org.apache.tools.ant.Project antProject,
                                   org.apache.maven.project.MavenProject mavenProject)
        Copy properties from the Ant project to the Maven project.
        Parameters:
        antProject - not null
        mavenProject - not null
        Since:
        1.7
      • getDependencyArtifactPropertyName

        public static java.lang.String getDependencyArtifactPropertyName​(org.apache.maven.artifact.Artifact artifact)
        Deprecated.
        The dependency conflict ID should be used as the property name.
        Returns a property name for a dependency artifact. The name is in the format maven.dependency.groupId.artifactId[.classifier].type.path
        Parameters:
        artifact - Artifact
        Returns:
        property name
      • getMavenProject

        public org.apache.maven.project.MavenProject getMavenProject()
        Get the current Maven project
        Returns:
        current Maven project
      • initMavenTasks

        public void initMavenTasks​(org.apache.tools.ant.Project antProject)
        Parameters:
        antProject - Project
      • writeTargetToProjectFile

        private java.io.File writeTargetToProjectFile()
                                               throws java.io.IOException,
                                                      org.codehaus.plexus.configuration.PlexusConfigurationException
        Write the Ant target and surrounding tags to a temporary file
        Throws:
        org.codehaus.plexus.configuration.PlexusConfigurationException
        java.io.IOException
      • stringReplace

        public void stringReplace​(java.lang.StringBuilder text,
                                  java.lang.String match,
                                  java.lang.String with)
        Replace text in a StringBuilder. If the match text is not found, the StringBuilder is returned unchanged.
        Parameters:
        text - The string buffer containing the text
        match - The string to match and remove
        with - The string to insert
      • checkTargetName

        public java.lang.String checkTargetName​(org.codehaus.plexus.configuration.PlexusConfiguration antTargetConfig)
                                         throws org.codehaus.plexus.configuration.PlexusConfigurationException
        Parameters:
        antTargetConfig - PlexusConfiguration
        Returns:
        The target name.
        Throws:
        org.codehaus.plexus.configuration.PlexusConfigurationException - in case of not existing attribute.
      • findFragment

        private java.lang.String findFragment​(org.apache.tools.ant.BuildException buildException)
        Parameters:
        buildException - not null
        Returns:
        the fragment XML part where the buildException occurs.
        Since:
        1.7