Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   package org.apache.maven.plugin.ant;
   
   /*
    * Licensed to the Apache Software Foundation (ASF) under one
    * or more contributor license agreements.  See the NOTICE file
    * distributed with this work for additional information
    * regarding copyright ownership.  The ASF licenses this file
    * to you 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 java.io.File;
  import java.util.List;
  import java.util.Map;
  
Write Ant build files from Maven Project for Ant 1.6.2 or above:
  • build.xml
  • maven-build.xml
  • maven-build.properties

Author(s):
Brett Porter
Vincent Siveton
Version:
$Id: AntBuildWriter.java 528821 2007-04-14 15:36:28Z carlos $
  
  public class AntBuildWriter
  {
    
The default line indenter
  
      protected static final int DEFAULT_INDENTATION_SIZE = 2;

    
The default build file name (build.xml)
  
      protected static final String DEFAULT_BUILD_FILENAME = .;

    
The default generated build file name
  
      protected static final String DEFAULT_MAVEN_BUILD_FILENAME = "maven-build.xml";

    
The default build properties file name
  
      protected static final String DEFAULT_MAVEN_PROPERTIES_FILENAME = "maven-build.properties";
  
      private MavenProject project;
  
  
      private File localRepository;
  
      private Settings settings;
  
      private boolean overwrite;

    

Parameters:
project
artifactResolverWrapper
settings
overwrite
  
      public AntBuildWriterMavenProject projectArtifactResolverWrapper artifactResolverWrapperSettings settings,
                            boolean overwrite )
      {
          this. = project;
          this. = artifactResolverWrapper;
          this. = new FileartifactResolverWrapper.getLocalRepository().getBasedir() );
         this. = settings;
         this. = overwrite;
     }

    
Generate Ant build XML files

 
     protected void writeBuildXmls()
         throws IOException
     {
         writeGeneratedBuildXml();
         writeBuildXml();
     }

    
Generate maven-build.properties only for a non-POM project

 
     protected void writeBuildProperties()
         throws IOException
     {
         if ( AntBuildWriterUtil.isPomPackaging ) )
         {
             return;
         }
 
         Properties properties = new Properties();
 
         // ----------------------------------------------------------------------
         // Build properties
         // ----------------------------------------------------------------------
 
         addPropertyproperties"maven.build.finalName", PathUtils.toRelative.getBasedir(), 
             .getBuild().getFinalName() ) );
 
         // target
         addPropertyproperties"maven.build.dir", PathUtils.toRelative.getBasedir(), .getBuild()
             .getDirectory() ) );
         addPropertyproperties"project.build.directory""${maven.build.dir}" );
 
         // ${maven.build.dir}/classes
         addPropertyproperties"maven.build.outputDir""${maven.build.dir}/"
             + PathUtils.toRelativenew File.getBasedir(), properties.getProperty"maven.build.dir" ) ),
                                     .getBuild().getOutputDirectory() ) );
         addPropertyproperties"project.build.outputDirectory""${maven.build.outputDir}" );
 
         // src/main/java
         if ( !.getCompileSourceRoots().isEmpty() )
         {
             String[] compileSourceRoots = (String[]) .getCompileSourceRoots().toArraynew String[0] );
             for ( int i = 0; i < compileSourceRoots.lengthi++ )
             {
                 addPropertyproperties"maven.build.srcDir." + i, PathUtils.toRelative.getBasedir(),
                                                                                           compileSourceRoots[i] ) );
             }
         }
         // src/main/resources
         if ( .getBuild().getResources() != null )
         {
             Resource[] array = (Resource[]) .getBuild().getResources().toArraynew Resource[0] );
             for ( int i = 0; i < array.lengthi++ )
             {
                 addPropertyproperties"maven.build.resourceDir." + i, PathUtils.toRelative.getBasedir(),
                                                                                                array[i].getDirectory() ) );
             }
         }
 
         // ${maven.build.dir}/test-classes
         addPropertyproperties"maven.build.testOutputDir""${maven.build.dir}/"
             + PathUtils.toRelativenew File.getBasedir(), properties.getProperty"maven.build.dir" ) ),
                                     .getBuild().getTestOutputDirectory() ) );
         // src/test/java
         if ( !.getTestCompileSourceRoots().isEmpty() )
         {
             String[] compileSourceRoots = (String[]) .getTestCompileSourceRoots().toArraynew String[0] );
             for ( int i = 0; i < compileSourceRoots.lengthi++ )
             {
                 addPropertyproperties"maven.build.testDir." + i, PathUtils.toRelative.getBasedir(),
                                                                                            compileSourceRoots[i] ) );
             }
         }
         // src/test/resources
         if ( .getBuild().getTestResources() != null )
         {
             Resource[] array = (Resource[]) .getBuild().getTestResources().toArraynew Resource[0] );
             for ( int i = 0; i < array.lengthi++ )
             {
                 addPropertyproperties"maven.build.testResourceDir." + i, PathUtils
                     .toRelative.getBasedir(), array[i].getDirectory() ) );
             }
         }
 
         addPropertyproperties"maven.test.reports""${maven.build.dir}/test-reports" );
 
         addPropertyproperties"maven.reporting.outputDirectory""${maven.build.dir}/site" );
 
         // ----------------------------------------------------------------------
         // Settings properties
         // ----------------------------------------------------------------------
 
         addPropertyproperties"maven.settings.offline", String.valueOf.isOffline() ) );
         addPropertyproperties"maven.settings.interactiveMode", String.valueOf.isInteractiveMode() ) );
         addPropertyproperties"maven.repo.local".getAbsolutePath() );
 
         // ----------------------------------------------------------------------
         // Project properties
         // ----------------------------------------------------------------------
 
         if ( .getProperties() != null )
         {
             for ( Iterator it = .getProperties().entrySet().iterator(); it.hasNext(); )
             {
                 Map.Entry property = (Map.Entryit.next();
                 addPropertypropertiesproperty.getKey().toString(), property.getValue().toString() );
             }
         }
 
         properties.storeos"Generated by Maven Ant Plugin - DO NOT EDIT THIS FILE!" );
     }

    
Generate an maven-build.xml

 
     private void writeGeneratedBuildXml()
         throws IOException
     {
         // TODO: parameter
         FileWriter w = new FileWriternew File.getBasedir(),  ) );
 
         XMLWriter writer = new PrettyPrintXMLWriterw, StringUtils.repeat" " ), "UTF-8",
                                                      null );
 
         // ----------------------------------------------------------------------
         // <!-- comments -->
         // ----------------------------------------------------------------------
 
         AntBuildWriterUtil.writeHeaderwriter );
 
         // ----------------------------------------------------------------------
         // <project/>
         // ----------------------------------------------------------------------
 
         writer.startElement"project" );
         writer.addAttribute"name".getArtifactId() + "-from-maven" );
         writer.addAttribute"default""package" );
         writer.addAttribute"basedir""." );
 
         AntBuildWriterUtil.writeLineBreakwriter );
 
         // ----------------------------------------------------------------------
         // <property/>
         // ----------------------------------------------------------------------
 
         writePropertieswriter );
 
         // ----------------------------------------------------------------------
         // <path/>
         // ----------------------------------------------------------------------
 
         writeBuildPathDefinitionwriter );
 
         // ----------------------------------------------------------------------
         // <target name="clean" />
         // ----------------------------------------------------------------------
 
         writeCleanTargetwriter );
 
         // ----------------------------------------------------------------------
         // <target name="compile" />
         // ----------------------------------------------------------------------
 
         List compileSourceRoots = AntBuildWriterUtil.removeEmptyCompileSourceRoots.getCompileSourceRoots() );
         writeCompileTargetwritercompileSourceRoots );
 
         // ----------------------------------------------------------------------
         // <target name="compile-tests" />
         // ----------------------------------------------------------------------
 
         List testCompileSourceRoots = AntBuildWriterUtil.removeEmptyCompileSourceRoots
             .getTestCompileSourceRoots() );
         writeCompileTestsTargetwritertestCompileSourceRoots );
 
         // ----------------------------------------------------------------------
         // <target name="test" />
         // ----------------------------------------------------------------------
 
         writeTestTargetswritertestCompileSourceRoots );
 
         // ----------------------------------------------------------------------
         // <target name="javadoc" />
         // ----------------------------------------------------------------------
         writeJavadocTargetwriter );
 
         // ----------------------------------------------------------------------
         // <target name="package" />
         // ----------------------------------------------------------------------
         writePackageTargetwriter );
 
         // ----------------------------------------------------------------------
         // <target name="get-deps" />
         // ----------------------------------------------------------------------
         writeGetDepsTargetwriter );
 
         writer.endElement(); // project
 
         IOUtil.closew );
     }

    
Generate an generic build.xml if not already exist

 
     private void writeBuildXml()
         throws IOException
     {
         if ( new File.getBasedir(),  ).exists() && ! )
         {
             return;
         }
 
         FileWriter w = new FileWriternew File.getBasedir(),  ) );
 
         XMLWriter writer = new PrettyPrintXMLWriterw, StringUtils.repeat" " ), "UTF-8",
                                                      null );
 
         // ----------------------------------------------------------------------
         // <!-- comments -->
         // ----------------------------------------------------------------------
 
         AntBuildWriterUtil.writeAntVersionHeaderwriter );
 
         // ----------------------------------------------------------------------
         // <project/>
         // ----------------------------------------------------------------------
 
         writer.startElement"project" );
         writer.addAttribute"name".getArtifactId() );
         writer.addAttribute"default""package" );
         writer.addAttribute"basedir""." );
 
         AntBuildWriterUtil.writeLineBreakwriter );
 
         AntBuildWriterUtil.writeCommentTextwriter"Import " + 
             + " into the current project", 1 );
 
         writer.startElement"import" );
         writer.addAttribute"file" );
         writer.endElement(); // import
 
         AntBuildWriterUtil.writeLineBreakwriter, 1, 1 );
 
         AntBuildWriterUtil.writeCommentTextwriter"Help target", 1 );
 
         writer.startElement"target" );
         writer.addAttribute"name""help" );
 
         writer.startElement"echo" );
         writer.addAttribute"message""Please run: $ant -projecthelp" );
         writer.endElement(); // echo
 
         writer.endElement(); // target
 
         AntBuildWriterUtil.writeLineBreakwriter );
 
         writer.endElement(); // project
 
         IOUtil.closew );
     }

    
Write properties in the writer only for a non-POM project.

Parameters:
writer
 
     private void writePropertiesXMLWriter writer )
     {
         if ( AntBuildWriterUtil.isPomPackaging ) )
         {
             return;
         }
 
         // TODO: optional in m1
         // TODO: USD properties
         AntBuildWriterUtil.writeCommentTextwriter"Build environnement properties", 1 );
 
         // ----------------------------------------------------------------------
         // File properties to override local properties
         // ----------------------------------------------------------------------
 
         writer.startElement"property" );
         writer.addAttribute"file""${user.home}/.m2/maven.properties" );
         writer.endElement(); // property
 
         writer.startElement"property" );
         writer.addAttribute"file" );
         writer.endElement(); // property
 
         // ----------------------------------------------------------------------
         // Build properties
         // ----------------------------------------------------------------------
 
         AntBuildWriterUtil.writeLineBreakwriter, 2, 1 );
 
         writer.startElement"property" );
         writer.addAttribute"name""maven.build.finalName" );
         writer.addAttribute"value".getBuild().getFinalName() );
         writer.endElement(); // property
 
         writer.startElement"property" );
         writer.addAttribute"name""maven.build.dir" );
         writer.addAttribute"value", PathUtils.toRelative.getBasedir(), .getBuild().getDirectory() ) );
         writer.endElement(); // property
 
         writer.startElement"property" );
         writer.addAttribute"name""maven.build.outputDir" );
         writer.addAttribute"value""${maven.build.dir}/"
             + PathUtils.toRelativenew File.getBuild().getDirectory() ), .getBuild()
                 .getOutputDirectory() ) );
         writer.endElement(); // property
 
         if ( !.getCompileSourceRoots().isEmpty() )
         {
             String[] compileSourceRoots = (String[]) .getCompileSourceRoots().toArraynew String[0] );
             for ( int i = 0; i < compileSourceRoots.lengthi++ )
             {
                 writer.startElement"property" );
                 writer.addAttribute"name""maven.build.srcDir." + i );
                 writer.addAttribute"value", PathUtils.toRelative.getBasedir(), compileSourceRoots[i] ) );
                 writer.endElement(); // property
             }
         }
 
         if ( .getBuild().getResources() != null )
         {
             Resource[] array = (Resource[]) .getBuild().getResources().toArraynew Resource[0] );
             for ( int i = 0; i < array.lengthi++ )
             {
                 writer.startElement"property" );
                 writer.addAttribute"name""maven.build.resourceDir." + i );
                 writer.addAttribute"value", PathUtils.toRelative.getBasedir(), array[i].getDirectory() ) );
                 writer.endElement(); // property
             }
         }
 
         writer.startElement"property" );
         writer.addAttribute"name""maven.build.testOutputDir" );
         writer.addAttribute"value""${maven.build.dir}/"
             + PathUtils.toRelativenew File.getBuild().getDirectory() ), .getBuild()
                 .getTestOutputDirectory() ) );
         writer.endElement(); // property
 
         if ( !.getTestCompileSourceRoots().isEmpty() )
         {
             String[] compileSourceRoots = (String[]) .getTestCompileSourceRoots().toArraynew String[0] );
             for ( int i = 0; i < compileSourceRoots.lengthi++ )
             {
                 writer.startElement"property" );
                 writer.addAttribute"name""maven.build.testDir." + i );
                 writer.addAttribute"value", PathUtils.toRelative.getBasedir(), compileSourceRoots[i] ) );
                 writer.endElement(); // property
             }
         }
 
         if ( .getBuild().getResources() != null )
         {
             Resource[] array = (Resource[]) .getBuild().getResources().toArraynew Resource[0] );
             for ( int i = 0; i < array.lengthi++ )
             {
                 writer.startElement"property" );
                 writer.addAttribute"name""maven.build.testResourceDir." + i );
                 writer.addAttribute"value", PathUtils.toRelative.getBasedir(), array[i].getDirectory() ) );
                 writer.endElement(); // property
             }
         }
 
         writer.startElement"property" );
         writer.addAttribute"name""maven.test.reports" );
         writer.addAttribute"value""${maven.build.dir}/test-reports" );
         writer.endElement(); // property
 
         writer.startElement"property" );
         writer.addAttribute"name""maven.reporting.outputDirectory" );
         writer.addAttribute"value""${maven.build.dir}/site" );
         writer.endElement(); // property
 
         // ----------------------------------------------------------------------
         // Setting properties
         // ----------------------------------------------------------------------
 
         AntBuildWriterUtil.writeLineBreakwriter, 2, 1 );
 
         writer.startElement"property" );
         writer.addAttribute"name""maven.repo.local" );
         writer.addAttribute"value".getAbsolutePath() );
         writer.endElement(); // property
 
         writer.startElement"property" );
         writer.addAttribute"name""maven.settings.offline" );
         writer.addAttribute"value", String.valueOf.isOffline() ) );
         writer.endElement(); // property
 
         writer.startElement"property" );
         writer.addAttribute"name""maven.settings.interactiveMode" );
         writer.addAttribute"value", String.valueOf.isInteractiveMode() ) );
         writer.endElement(); // property
 
         AntBuildWriterUtil.writeLineBreakwriter );
     }

    
Write path definition in the writer only for a non-POM project.

Parameters:
writer
 
     private void writeBuildPathDefinitionXMLWriter writer )
     {
         if ( AntBuildWriterUtil.isPomPackaging ) )
         {
             return;
         }
 
         AntBuildWriterUtil.writeCommentTextwriter"Defining classpaths", 1 );
 
         writer.startElement"path" );
         writer.addAttribute"id""build.classpath" );
         writer.startElement"fileset" );
         writer.addAttribute"dir""${maven.repo.local}" );
         if ( !.getCompileArtifacts().isEmpty() )
         {
             for ( Iterator i = .getCompileArtifacts().iterator(); i.hasNext(); )
             {
                 Artifact artifact = (Artifacti.next();
                 writer.startElement"include" );
                 writer.addAttribute"name", PathUtils.toRelativeartifact.getFile().getPath() ) );
                 writer.endElement(); // include
             }
         }
         else
         {
             writer.startElement"include" );
             writer.addAttribute"name""*.jar" );
             writer.endElement(); // include
         }
         writer.endElement(); // fileset
         writer.endElement(); // path
 
         writer.startElement"path" );
         writer.addAttribute"id""build.test.classpath" );
         writer.startElement"fileset" );
         writer.addAttribute"dir""${maven.repo.local}" );
         if ( !.getTestArtifacts().isEmpty() )
         {
             for ( Iterator i = .getTestArtifacts().iterator(); i.hasNext(); )
             {
                 Artifact artifact = (Artifacti.next();
                 writer.startElement"include" );
                 writer.addAttribute"name", PathUtils.toRelativeartifact.getFile().getPath() ) );
                 writer.endElement(); // include
             }
         }
         else
         {
             writer.startElement"include" );
             writer.addAttribute"name""*.jar" );
             writer.endElement(); // include
         }
         writer.endElement(); // fileset
         writer.endElement(); // path
 
         AntBuildWriterUtil.writeLineBreakwriter );
     }

    
Write clean target in the writer depending the packaging of the project.

Parameters:
writer
 
     private void writeCleanTargetXMLWriter writer )
     {
         AntBuildWriterUtil.writeCommentTextwriter"Cleaning up target", 1 );
 
         writer.startElement"target" );
         writer.addAttribute"name""clean" );
         writer.addAttribute"description""Clean the output directory" );
 
         if ( AntBuildWriterUtil.isPomPackaging ) )
         {
             if ( .getModules() != null )
             {
                 for ( Iterator it = .getModules().iterator(); it.hasNext(); )
                 {
                     String moduleSubPath = (Stringit.next();
                     AntBuildWriterUtil.writeAntTaskwritermoduleSubPath"clean" );
                 }
             }
         }
         else
         {
             writer.startElement"delete" );
             writer.addAttribute"dir""${maven.build.dir}" );
             writer.endElement(); // delete
         }
 
         writer.endElement(); // target
 
         AntBuildWriterUtil.writeLineBreakwriter );
     }

    
Write compile target in the writer depending the packaging of the project.

Parameters:
writer
compileSourceRoots
Throws:
java.io.IOException if any
 
     private void writeCompileTargetXMLWriter writerList compileSourceRoots )
         throws IOException
     {
         AntBuildWriterUtil.writeCommentTextwriter"Compilation target", 1 );
 
         if ( AntBuildWriterUtil.isPomPackaging ) )
         {
             writer.startElement"target" );
             writer.addAttribute"name""compile" );
             writer.addAttribute"description""Compile the code" );
             if ( .getModules() != null )
             {
                 for ( Iterator it = .getModules().iterator(); it.hasNext(); )
                 {
                     String moduleSubPath = (Stringit.next();
                     AntBuildWriterUtil.writeAntTaskwritermoduleSubPath"compile" );
                 }
             }
             writer.endElement(); // target
         }
         else
         {
             writer.startElement"target" );
             writer.addAttribute"name""compile" );
             writer.addAttribute"depends""get-deps" );
             writer.addAttribute"description""Compile the code" );
 
             writeCompileTaskswriter.getBasedir(), "${maven.build.outputDir}"compileSourceRoots
                 .getBuild().getResources(), nullfalse );
 
             writer.endElement(); // target
         }
 
         AntBuildWriterUtil.writeLineBreakwriter );
     }

    
Write compile-test target in the writer depending the packaging of the project.

Parameters:
writer
testCompileSourceRoots
Throws:
java.io.IOException if any
 
     private void writeCompileTestsTargetXMLWriter writerList testCompileSourceRoots )
         throws IOException
     {
         AntBuildWriterUtil.writeCommentTextwriter"Test-compilation target", 1 );
 
         if ( AntBuildWriterUtil.isPomPackaging ) )
         {
             writer.startElement"target" );
             writer.addAttribute"name""compile-tests" );
             writer.addAttribute"description""Compile the test code" );
             if ( .getModules() != null )
             {
                 for ( Iterator it = .getModules().iterator(); it.hasNext(); )
                 {
                     String moduleSubPath = (Stringit.next();
                     AntBuildWriterUtil.writeAntTaskwritermoduleSubPath"compile-tests" );
                 }
             }
             writer.endElement(); // target
         }
         else
         {
             writer.startElement"target" );
             writer.addAttribute"name""compile-tests" );
             AntBuildWriterUtil.addWrapAttributewriter"target""depends""junit-present, compile", 2 );
             AntBuildWriterUtil.addWrapAttributewriter"target""description""Compile the test code", 2 );
             AntBuildWriterUtil.addWrapAttributewriter"target""if""junit.present", 2 );
 
             writeCompileTaskswriter.getBasedir(), "${maven.build.testOutputDir}"testCompileSourceRoots,
                                .getBuild().getTestResources(), "${maven.build.outputDir}"true );
 
             writer.endElement(); // target
         }
 
         AntBuildWriterUtil.writeLineBreakwriter );
     }

    
Write test target in the writer depending the packaging of the project.

Parameters:
writer
testCompileSourceRoots
 
     private void writeTestTargetsXMLWriter writerList testCompileSourceRoots )
     {
         AntBuildWriterUtil.writeCommentTextwriter"Run all tests", 1 );
 
         if ( AntBuildWriterUtil.isPomPackaging ) )
         {
             writer.startElement"target" );
             writer.addAttribute"name""test" );
             writer.addAttribute"description""Run the test cases" );
             if ( .getModules() != null )
             {
                 for ( Iterator it = .getModules().iterator(); it.hasNext(); )
                 {
                     String moduleSubPath = (Stringit.next();
                     AntBuildWriterUtil.writeAntTaskwritermoduleSubPath"test" );
                 }
             }
             writer.endElement(); // target
         }
         else
         {
             writer.startElement"target" );
             writer.addAttribute"name""test" );
             AntBuildWriterUtil.addWrapAttributewriter"target""depends""junit-present, compile-tests", 2 );
             AntBuildWriterUtil.addWrapAttributewriter"target""if""junit.present", 2 );
             AntBuildWriterUtil.addWrapAttributewriter"target""description""Run the test cases", 2 );
 
             if ( !testCompileSourceRoots.isEmpty() )
             {
                 writer.startElement"mkdir" );
                 writer.addAttribute"dir""${maven.test.reports}" );
                 writer.endElement(); //mkdir
 
                 writer.startElement"junit" );
                 writer.addAttribute"printSummary""yes" );
                 writer.addAttribute"haltonerror""true" );
                 writer.addAttribute"haltonfailure""true" );
                 writer.addAttribute"fork""true" );
                 writer.addAttribute"dir""." );
 
                 writer.startElement"sysproperty" );
                 writer.addAttribute"key""basedir" );
                 writer.addAttribute"value""." );
                 writer.endElement(); // sysproperty
 
                 writer.startElement"formatter" );
                 writer.addAttribute"type""xml" );
                 writer.endElement(); // formatter
 
                 writer.startElement"formatter" );
                 writer.addAttribute"type""plain" );
                 writer.addAttribute"usefile""false" );
                 writer.endElement(); // formatter
 
                 writer.startElement"classpath" );
                 writer.startElement"path" );
                 writer.addAttribute"refid""build.test.classpath" );
                 writer.endElement(); // path
                 writer.startElement"pathelement" );
                 writer.addAttribute"location""${maven.build.outputDir}" );
                 writer.endElement(); // pathelement
                 writer.startElement"pathelement" );
                 writer.addAttribute"location""${maven.build.testOutputDir}" );
                 writer.endElement(); // pathelement
                 writer.endElement(); // classpath
 
                 writer.startElement"batchtest" );
                 writer.addAttribute"todir""${maven.test.reports}" );
 
                 String[] compileSourceRoots = (String[]) testCompileSourceRoots.toArraynew String[0] );
                 for ( int i = 0; i < compileSourceRoots.lengthi++ )
                 {
                     writer.startElement"fileset" );
                     writer.addAttribute"dir""${maven.build.testDir." + i + "}" );
                     /* TODO: need to get these from the test plugin somehow?
                      UnitTest unitTest = project.getBuild().getUnitTest();
                      writeIncludesExcludes( writer, unitTest.getIncludes(), unitTest.getExcludes() );
                      // TODO: m1 allows additional test exclusions via maven.ant.excludeTests
                      */
                     AntBuildWriterUtil.writeIncludesExcludeswriter, Collections.singletonList"**/*Test.java" ),
                                                               Collections.singletonList"**/*Abstract*Test.java" ) );
                     writer.endElement(); // fileset
                 }
                 writer.endElement(); // batchtest
 
                 writer.endElement(); // junit
             }
             writer.endElement(); // target
 
             AntBuildWriterUtil.writeLineBreakwriter, 2, 1 );
 
             writer.startElement"target" );
             writer.addAttribute"name""test-junit-present" );
 
             writer.startElement"available" );
             writer.addAttribute"classname""junit.framework.Test" );
             writer.addAttribute"property""junit.present" );
             writer.endElement(); // available
 
             writer.endElement(); // target
 
             AntBuildWriterUtil.writeLineBreakwriter, 2, 1 );
 
             writer.startElement"target" );
             writer.addAttribute"name""junit-present" );
             AntBuildWriterUtil.addWrapAttributewriter"target""depends""test-junit-present", 2 );
             AntBuildWriterUtil.addWrapAttributewriter"target""unless""junit.present", 2 );
 
             writer.startElement"echo" );
             writer.writeText( StringUtils.repeat"=", 35 ) + " WARNING " + StringUtils.repeat"=", 35 ) );
             writer.endElement(); // echo
 
             writer.startElement"echo" );
             writer.writeText" Junit isn't present in your $ANT_HOME/lib directory. Tests not executed. " );
             writer.endElement(); // echo
 
             writer.startElement"echo" );
             writer.writeText( StringUtils.repeat"=", 79 ) );
             writer.endElement(); // echo
 
             writer.endElement(); // target
         }
 
         AntBuildWriterUtil.writeLineBreakwriter );
     }

    
Write javadoc target in the writer depending the packaging of the project.

Parameters:
writer
Throws:
java.io.IOException if any
 
     private void writeJavadocTargetXMLWriter writer )
         throws IOException
     {
         AntBuildWriterUtil.writeCommentTextwriter"Javadoc target", 1 );
 
         writer.startElement"target" );
         writer.addAttribute"name""javadoc" );
         writer.addAttribute"description""Generates the Javadoc of the application" );
 
         if ( AntBuildWriterUtil.isPomPackaging ) )
         {
             if ( .getModules() != null )
             {
                 for ( Iterator it = .getModules().iterator(); it.hasNext(); )
                 {
                     String moduleSubPath = (Stringit.next();
                     AntBuildWriterUtil.writeAntTaskwritermoduleSubPath"javadoc" );
                 }
             }
         }
         else
         {
             AntBuildWriterUtil.writeJavadocTaskwriter );
         }
 
         writer.endElement(); // target
 
         AntBuildWriterUtil.writeLineBreakwriter );
     }

    
Write package target in the writer depending the packaging of the project.

Parameters:
writer
Throws:
java.io.IOException if any
 
     private void writePackageTargetXMLWriter writer )
         throws IOException
     {
         String synonym = null// type of the package we are creating (for example jar)
         AntBuildWriterUtil.writeCommentTextwriter"Package target", 1 );
 
         writer.startElement"target" );
         writer.addAttribute"name""package" );
 
         if ( !AntBuildWriterUtil.isPomPackaging ) )
         {
             writer.addAttribute"depends""compile,test" );
         }
         writer.addAttribute"description""Package the application" );
 
         if ( AntBuildWriterUtil.isPomPackaging ) )
         {
             if ( .getModules() != null )
             {
                 for ( Iterator it = .getModules().iterator(); it.hasNext(); )
                 {
                     String moduleSubPath = (Stringit.next();
                     AntBuildWriterUtil.writeAntTaskwritermoduleSubPath"package" );
                 }
             }
         }
         else
         {
             if ( AntBuildWriterUtil.isJarPackaging ) )
             {
                 AntBuildWriterUtil.writeJarTaskwriter );
                 synonym = "jar";
             }
             else if ( AntBuildWriterUtil.isEarPackaging ) )
             {
                 AntBuildWriterUtil.writeEarTaskwriter );
                 synonym = "ear";
             }
             else if ( AntBuildWriterUtil.isWarPackaging ) )
             {
                 AntBuildWriterUtil.writeWarTaskwriter );
                 synonym = "war";
             }
             else
             {
                 writer.startElement"echo" );
                 writer.addAttribute"message""No Ant task exists for the packaging '" + .getPackaging()
                     + "'. " + "You could overrided the Ant package target in your build.xml." );
                 writer.endElement(); // echo
             }
         }
 
         writer.endElement(); // target
 
         AntBuildWriterUtil.writeLineBreakwriter );
 
         if ( synonym != null )
         {
             AntBuildWriterUtil.writeCommentTextwriter,
                                                  "A dummy target for the package named after the type it creates", 1 );
             writer.startElement"target" );
             writer.addAttribute"name"synonym );
             writer.addAttribute"depends""package" );
             writer.addAttribute"description""Builds the " + synonym + " for the application" );
             writer.endElement(); //target
 
             AntBuildWriterUtil.writeLineBreakwriter );
         }
     }
 
     private void writeCompileTasksXMLWriter writerFile basedirString outputDirectoryList compileSourceRoots,
                                    List resourcesString additionalClassesDirectoryboolean isTest )
         throws IOException
     {
         writer.startElement"mkdir" );
         writer.addAttribute"dir"outputDirectory );
         writer.endElement(); // mkdir
 
         if ( !compileSourceRoots.isEmpty() )
         {
             writer.startElement"javac" );
             writer.addAttribute"destdir"outputDirectory );
             Map[] includes = AntBuildWriterUtil.getMavenCompilerPluginOptions"includes"null );
             AntBuildWriterUtil.addWrapAttributewriter"javac""includes"getCommaSeparatedListincludes,
                                                                                                      "include" ), 3 );
             Map[] excludes = AntBuildWriterUtil.getMavenCompilerPluginOptions"excludes"null );
             AntBuildWriterUtil.addWrapAttributewriter"javac""excludes"getCommaSeparatedListexcludes,
                                                                                                      "exclude" ), 3 );
             AntBuildWriterUtil.addWrapAttributewriter"javac""encoding", AntBuildWriterUtil
                 .getMavenCompilerPluginBasicOption"encoding"null ), 3 );
             AntBuildWriterUtil.addWrapAttributewriter"javac""nowarn", AntBuildWriterUtil
                 .getMavenCompilerPluginBasicOption"showWarnings""false" ), 3 );
             AntBuildWriterUtil.addWrapAttributewriter"javac""debug", AntBuildWriterUtil
                 .getMavenCompilerPluginBasicOption"debug""true" ), 3 );
             AntBuildWriterUtil.addWrapAttributewriter"javac""optimize", AntBuildWriterUtil
                 .getMavenCompilerPluginBasicOption"optimize""false" ), 3 );
             AntBuildWriterUtil.addWrapAttributewriter"javac""deprecation", AntBuildWriterUtil
                 .getMavenCompilerPluginBasicOption"showDeprecation""true" ), 3 );
             AntBuildWriterUtil.addWrapAttributewriter"javac""target", AntBuildWriterUtil
                 .getMavenCompilerPluginBasicOption"target"null ), 3 );
             AntBuildWriterUtil.addWrapAttributewriter"javac""verbose", AntBuildWriterUtil
                 .getMavenCompilerPluginBasicOption"verbose""false" ), 3 );
             AntBuildWriterUtil.addWrapAttributewriter"javac""fork", AntBuildWriterUtil
                 .getMavenCompilerPluginBasicOption"fork""false" ), 3 );
             AntBuildWriterUtil.addWrapAttributewriter"javac""memoryMaximumSize", AntBuildWriterUtil
                 .getMavenCompilerPluginBasicOption"meminitial"null ), 3 );
             AntBuildWriterUtil.addWrapAttributewriter"javac""memoryInitialSize", AntBuildWriterUtil
                 .getMavenCompilerPluginBasicOption"maxmem"null ), 3 );
             AntBuildWriterUtil.addWrapAttributewriter"javac""source", AntBuildWriterUtil
                 .getMavenCompilerPluginBasicOption"source"null ), 3 );
 
             String[] compileSourceRootsArray = (String[]) compileSourceRoots.toArraynew String[0] );
             for ( int i = 0; i < compileSourceRootsArray.lengthi++ )
             {
                 writer.startElement"src" );
                 writer.startElement"pathelement" );
                 if ( isTest )
                 {
                     writer.addAttribute"location""${maven.build.testDir." + i + "}" );
                 }
                 else
                {
                    writer.addAttribute"location""${maven.build.srcDir." + i + "}" );
                }
                writer.endElement(); // pathelement
                writer.endElement(); // src
            }
            if ( additionalClassesDirectory == null )
            {
                writer.startElement"classpath" );
                if ( isTest )
                {
                    writer.addAttribute"refid""build.test.classpath" );
                }
                else
                {
                    writer.addAttribute"refid""build.classpath" );
                }
                writer.endElement(); // classpath
            }
            else
            {
                writer.startElement"classpath" );
                writer.startElement"path" );
                if ( isTest )
                {
                    writer.addAttribute"refid""build.test.classpath" );
                }
                else
                {
                    writer.addAttribute"refid""build.classpath" );
                }
                writer.endElement(); // path
                writer.startElement"pathelement" );
                writer.addAttribute"location"additionalClassesDirectory );
                writer.endElement(); // pathelement
                writer.endElement(); // classpath
            }
            writer.endElement(); // javac
        }
        Resource[] array = (Resource[]) resources.toArraynew Resource[0] );
        for ( int i = 0; i < array.lengthi++ )
        {
            Resource resource = array[i];
            if ( new Fileresource.getDirectory() ).exists() )
            {
                String outputDir = outputDirectory;
                if ( resource.getTargetPath() != null && resource.getTargetPath().length() > 0 )
                {
                    outputDir = outputDir + "/" + resource.getTargetPath();
                    writer.startElement"mkdir" );
                    writer.addAttribute"dir"outputDir );
                    writer.endElement(); // mkdir
                }
                writer.startElement"copy" );
                writer.addAttribute"todir"outputDir );
                writer.startElement"fileset" );
                if ( isTest )
                {
                    writer.addAttribute"dir""${maven.build.testResourceDir." + i + "}" );
                }
                else
                {
                    writer.addAttribute"dir""${maven.build.resourceDir." + i + "}" );
                }
                AntBuildWriterUtil.writeIncludesExcludeswriterresource.getIncludes(), resource.getExcludes() );
                writer.endElement(); // fileset
                writer.endElement(); // copy
            }
        }
    }

    
Write get-deps target in the writer only for a non-POM project

Parameters:
writer
    private void writeGetDepsTargetXMLWriter writer )
    {
        if ( AntBuildWriterUtil.isPomPackaging ) )
        {
            return;
        }
        AntBuildWriterUtil.writeCommentTextwriter"Download dependencies target", 1 );
        writer.startElement"target" );
        writer.addAttribute"name""test-offline" );
        writer.startElement"condition" );
        writer.addAttribute"property""maven.mode.offline" );
        writer.startElement"equals" );
        writer.addAttribute"arg1""${maven.settings.offline}" );
        writer.addAttribute"arg2""true" );
        writer.endElement(); // equals
        writer.endElement(); // condition
        writer.endElement(); // target
        AntBuildWriterUtil.writeLineBreakwriter, 2, 1 );