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.Date;
  import java.util.HashMap;
  import java.util.List;
  import java.util.Locale;
  import java.util.Map;
  
  
  import org.w3c.dom.Node;
Utility class for the AntBuildWriter class.

Author(s):
Vincent Siveton
Version:
$Id: AntBuildWriterUtil.java 510478 2007-02-22 12:29:45Z vsiveton $
  
  public class AntBuildWriterUtil
  {
    

Parameters:
compileSourceRoots
Returns:
not null list
  
      public static List removeEmptyCompileSourceRootsList compileSourceRoots )
      {
          List newCompileSourceRootsList = new ArrayList();
          if ( compileSourceRoots != null )
          {
              // copy as I may be modifying it
              for ( Iterator i = compileSourceRoots.iterator(); i.hasNext(); )
              {
                  String srcDir = (Stringi.next();
                  if ( new FilesrcDir ).exists() )
                  {
                      newCompileSourceRootsList.addsrcDir );
                  }
              }
          }
  
          return newCompileSourceRootsList;
      }

    
Convenience method to write <include/> and <exclude/>

Parameters:
writer not null
includes
excludes
  
      public static void writeIncludesExcludesXMLWriter writerList includesList excludes )
      {
          if ( includes != null )
          {
              for ( Iterator i = includes.iterator(); i.hasNext(); )
              {
                  String include = (Stringi.next();
                  writer.startElement"include" );
                  writer.addAttribute"name"include );
                  writer.endElement(); // include
              }
          }
         if ( excludes != null )
         {
             for ( Iterator i = excludes.iterator(); i.hasNext(); )
             {
                 String exclude = (Stringi.next();
                 writer.startElement"exclude" );
                 writer.addAttribute"name"exclude );
                 writer.endElement(); // exclude
             }
         }
     }

    
Write comments in the Ant build file header

Parameters:
writer
 
     public static void writeHeaderXMLWriter writer )
     {
         writeAntVersionHeaderwriter );
 
         writeCommentLineBreakwriter );
         writeCommentwriter, StringUtils.repeat"=", 21 ) + " - DO NOT EDIT THIS FILE! - "
             + StringUtils.repeat"=", 21 ) );
         writeCommentLineBreakwriter );
         writeCommentwriter" " );
         writeCommentwriter"Any modifications will be overwritten." );
         writeCommentwriter" " );
         DateFormat dateFormat = DateFormat.getDateTimeInstance... );
         writeCommentwriter"Generated by Maven Ant Plugin on "
             + dateFormat.formatnew Date( System.currentTimeMillis() ) ) );
         writeCommentwriter"See: http://maven.apache.org/plugins/maven-ant-plugin/" );
         writeCommentwriter" " );
         writeCommentLineBreakwriter );
 
         writeLineBreakwriter );
     }

    
Write comment for the Ant supported version

Parameters:
writer
 
     public static void writeAntVersionHeaderXMLWriter writer )
     {
         writeCommentTextwriter"Ant build file (http://ant.apache.org/) for Ant 1.6.2 or above.", 0 );
     }

    
Convenience method to write one CRLF

Parameters:
writer not null writer
 
     public static void writeLineBreakXMLWriter writer )
     {
         writeLineBreakwriter, 1 );
     }

    
Convenience method to repeat CRLF

Parameters:
writer not null
repeat
 
     public static void writeLineBreakXMLWriter writerint repeat )
     {
         for ( int i = 0; i < repeati++ )
         {
             writer.writeMarkup"\n" );
         }
     }

    
Convenience method to repeat CRLF and to indent the writer

Parameters:
writer not null
repeat
indent postive number
 
     public static void writeLineBreakXMLWriter writerint repeatint indent )
     {
         writeLineBreakwriterrepeat );
 
         if ( indent < 0 )
         {
             indent = 0;
         }
 
         writer.writeText( StringUtils.repeat" "indent * . ) );
     }

    
Convenience method to write XML comment line break. Its size is 80.

Parameters:
writer not null
 
     public static void writeCommentLineBreakXMLWriter writer )
     {
         writer.writeMarkup"<!-- " + StringUtils.repeat"=", 70 ) + " -->\n" );
     }

    
Convenience method to write XML comment line. The comment is splitted to have a size of 80.

Parameters:
writer not null
comment
 
     public static void writeCommentXMLWriter writerString comment )
     {
         if ( comment == null )
         {
             comment = "null";
         }
 
         String[] words = StringUtils.splitcomment" " );
 
         StringBuffer line = new StringBuffer"<!-- " );
         for ( int i = 0; i < words.lengthi++ )
         {
             String[] sentences = StringUtils.splitwords[i], "\n" );
             if ( sentences.length > 1 )
             {
                 for ( int j = 0; j < sentences.length - 1; j++ )
                 {
                     line.appendsentences[j] ).append' ' );
                     line.append( StringUtils.repeat" ", 76 - line.length() ) ).append"-->" ).append'\n' );
                     writer.writeMarkupline.toString() );
                     line = new StringBuffer"<!-- " );
                 }
                 line.appendsentences[sentences.length - 1] ).append' ' );
             }
             else
             {
                 StringBuffer sentenceTmp = new StringBufferline.toString() );
                 sentenceTmp.appendwords[i] ).append' ' );
                 if ( sentenceTmp.length() > 76 )
                 {
                     line.append( StringUtils.repeat" ", 76 - line.length() ) ).append"-->" ).append'\n' );
                     writer.writeMarkupline.toString() );
                     line = new StringBuffer"<!-- " );
                     line.appendwords[i] ).append' ' );
                 }
                 else
                 {
                     line.appendwords[i] ).append' ' );
                 }
             }
         }
         if ( line.length() <= 76 )
         {
             line.append( StringUtils.repeat" ", 76 - line.length() ) ).append"-->" ).append'\n' );
         }
         writer.writeMarkupline.toString() );
     }

    
Convenience method to write XML comment between two comment line break. The XML comment block is also indented.

Parameters:
writer not null
comment
indent
 
     public static void writeCommentTextXMLWriter writerString commentint indent )
     {
         if ( indent < 0 )
         {
             indent = 0;
         }
 
         writeLineBreakwriter, 1 );
 
         writer.writeMarkup( StringUtils.repeat" "indent * . ) );
         writeCommentLineBreakwriter );
 
         writer.writeMarkup( StringUtils.repeat" "indent * . ) );
         writeCommentwritercomment );
 
         writer.writeMarkup( StringUtils.repeat" "indent * . ) );
         writeCommentLineBreakwriter );
 
         writeLineBreakwriter, 1, indent );
     }

    
Convenience method to write XML ant task

Parameters:
writer not null
project not null
moduleSubPath not null
tasks not null
 
     public static void writeAntTaskXMLWriter writerMavenProject projectString moduleSubPathString tasks )
     {
         writer.startElement"ant" );
         writer.addAttribute"antfile""build.xml" );
         writer.addAttribute"dir", PathUtils.toRelativeproject.getBasedir(), moduleSubPath ) );
         writer.addAttribute"target"tasks );
         writer.endElement(); // ant
     }

    
Convenience method to write XML Ant javadoc task

Parameters:
writer not null
project not null
wrapper not null
Throws:
java.io.IOException if any
 
     public static void writeJavadocTaskXMLWriter writerMavenProject projectArtifactResolverWrapper wrapper )
         throws IOException
     {
         List sources = new ArrayList();
         for ( Iterator it = project.getCompileSourceRoots().iterator(); it.hasNext(); )
         {
             String source = (Stringit.next();
 
             if ( new Filesource ).exists() )
             {
                 sources.addsource );
             }
         }
 
         // No sources
         if ( sources.size() == 0 )
         {
             return;
         }
 
         writer.startElement"javadoc" );
         String sourcepath = getMavenJavadocPluginBasicOptionproject"sourcepath"null );
         if ( sourcepath == null )
         {
             StringBuffer sb = new StringBuffer();
             String[] compileSourceRoots = (String[]) sources.toArraynew String[0] );
             for ( int i = 0; i < compileSourceRoots.lengthi++ )
             {
                 sb.append"${maven.build.srcDir." ).appendi ).append"}" );
 
                 if ( i < ( compileSourceRoots.length - 1 ) )
                 {
                     sb.append. );
                 }
             }
             writer.addAttribute"sourcepath"sb.toString() );
             addWrapAttributewriter"javadoc""packagenames""*", 3 );
         }
         else
         {
             writer.addAttribute"sourcepath"sourcepath );
         }
         addWrapAttributewriter"javadoc""destdir",
                           getMavenJavadocPluginBasicOptionproject"destdir",
                                                             "${maven.reporting.outputDirectory}/apidocs" ), 3 );
         addWrapAttributewriter"javadoc""extdirs"getMavenJavadocPluginBasicOptionproject"extdirs"null ), 3 );
 
         addWrapAttributewriter"javadoc""overview"getMavenJavadocPluginBasicOptionproject"overview"null ),
                           3 );
         addWrapAttributewriter"javadoc""access",
                           getMavenJavadocPluginBasicOptionproject"show""protected" ), 3 );
         addWrapAttributewriter"javadoc""old"getMavenJavadocPluginBasicOptionproject"old""false" ), 3 );
         addWrapAttributewriter"javadoc""verbose",
                           getMavenJavadocPluginBasicOptionproject"verbose""false" ), 3 );
         addWrapAttributewriter"javadoc""locale"getMavenJavadocPluginBasicOptionproject"locale"null ), 3 );
         addWrapAttributewriter"javadoc""encoding"getMavenJavadocPluginBasicOptionproject"encoding"null ),
                           3 );
         addWrapAttributewriter"javadoc""version"getMavenJavadocPluginBasicOptionproject"version""true" ),
                           3 );
         addWrapAttributewriter"javadoc""use"getMavenJavadocPluginBasicOptionproject"use""true" ), 3 );
         addWrapAttributewriter"javadoc""author"getMavenJavadocPluginBasicOptionproject"author""true" ), 3 );
         addWrapAttributewriter"javadoc""splitindex"getMavenJavadocPluginBasicOptionproject"splitindex",
                                                                                              "false" ), 3 );
         addWrapAttributewriter"javadoc""windowtitle"getMavenJavadocPluginBasicOptionproject"windowtitle",
                                                                                               null ), 3 );
         addWrapAttributewriter"javadoc""nodeprecated"getMavenJavadocPluginBasicOptionproject"nodeprecated",
                                                                                                "false" ), 3 );
         addWrapAttributewriter"javadoc""nodeprecatedlist"getMavenJavadocPluginBasicOptionproject,
                                                                                                    "nodeprecatedlist",
                                                                                                    "false" ), 3 );
         addWrapAttributewriter"javadoc""notree"getMavenJavadocPluginBasicOptionproject"notree""false" ),
                           3 );
         addWrapAttributewriter"javadoc""noindex",
                           getMavenJavadocPluginBasicOptionproject"noindex""false" ), 3 );
         addWrapAttributewriter"javadoc""nohelp"getMavenJavadocPluginBasicOptionproject"nohelp""false" ),
                           3 );
         addWrapAttributewriter"javadoc""nonavbar",
                           getMavenJavadocPluginBasicOptionproject"nonavbar""false" ), 3 );
         addWrapAttributewriter"javadoc""serialwarn"getMavenJavadocPluginBasicOptionproject"serialwarn",
                                                                                              "false" ), 3 );
         addWrapAttributewriter"javadoc""helpfile"getMavenJavadocPluginBasicOptionproject"helpfile"null ),
                           3 );
         addWrapAttributewriter"javadoc""stylesheetfile",
                           getMavenJavadocPluginBasicOptionproject"stylesheetfile"null ), 3 );
         addWrapAttributewriter"javadoc""charset"getMavenJavadocPluginBasicOptionproject"charset",
                                                                                           "ISO-8859-1" ), 3 );
         addWrapAttributewriter"javadoc""docencoding"getMavenJavadocPluginBasicOptionproject"docencoding",
                                                                                               null ), 3 );
         addWrapAttributewriter"javadoc""excludepackagenames",
                           getMavenJavadocPluginBasicOptionproject"excludepackagenames"null ), 3 );
         addWrapAttributewriter"javadoc""source"getMavenJavadocPluginBasicOptionproject"source"null ), 3 );
         addWrapAttributewriter"javadoc""linksource"getMavenJavadocPluginBasicOptionproject"linksource",
                                                                                              "false" ), 3 );
         addWrapAttributewriter"javadoc""breakiterator"getMavenJavadocPluginBasicOptionproject,
                                                                                                 "breakiterator",
                                                                                                 "false" ), 3 );
         addWrapAttributewriter"javadoc""noqualifier"getMavenJavadocPluginBasicOptionproject"noqualifier",
                                                                                               null ), 3 );
         // miscellaneous
         addWrapAttributewriter"javadoc""maxmemory",
                           getMavenJavadocPluginBasicOptionproject"maxmemory"null ), 3 );
         addWrapAttributewriter"javadoc""additionalparam"getMavenJavadocPluginBasicOptionproject,
                                                                                                   "additionalparam",
                                                                                                   null ), 3 );
 
         // Nested arg
         String doctitle = getMavenJavadocPluginBasicOptionproject"doctitle"null );
         if ( doctitle != null )
         {
             writer.startElement"doctitle" );
             writer.writeText"<![CDATA[" + doctitle + "]]>" );
             writer.endElement(); // doctitle
         }
         String header = getMavenJavadocPluginBasicOptionproject"header"null );
         if ( header != null )
         {
             writer.startElement"header" );
             writer.writeText"<![CDATA[" + header + "]]>" );
             writer.endElement(); // header
         }
         String footer = getMavenJavadocPluginBasicOptionproject"footer"null );
         if ( footer != null )
         {
             writer.startElement"footer" );
             writer.writeText"<![CDATA[" + footer + "]]>" );
             writer.endElement(); // footer
         }
         String bottom = getMavenJavadocPluginBasicOptionproject"bottom"null );
         if ( bottom != null )
         {
             writer.startElement"bottom" );
             writer.writeText"<![CDATA[" + bottom + "]]>" );
             writer.endElement(); // bottom
         }
 
         Map[] links = getMavenJavadocPluginOptionsproject"links"null );
         if ( links != null )
         {
             for ( int i = 0; i < links.lengthi++ )
             {
                 writer.startElement"link" );
                 writer.addAttribute"href", (Stringlinks[i].get"link" ) );
                 writer.endElement(); // link
             }
         }
 
         Map[] offlineLinks = getMavenJavadocPluginOptionsproject"offlineLinks"null );
         if ( offlineLinks != null )
         {
             for ( int i = 0; i < offlineLinks.lengthi++ )
             {
                 writer.startElement"link" );
                 writer.addAttribute"href", (StringofflineLinks[i].get"url" ) );
                 addWrapAttributewriter"javadoc""offline""true", 4 );
                 writer.endElement(); // link
             }
         }
 
         Map[] groups = getMavenJavadocPluginOptionsproject"groups"null );
         if ( groups != null )
         {
             for ( int i = 0; i < groups.lengthi++ )
             {
                 writer.startElement"group" );
                 writer.addAttribute"title", (Stringgroups[i].get"title" ) );
                 addWrapAttributewriter"javadoc""package", (Stringgroups[i].get"package" ), 4 );
                 writer.endElement(); // group
             }
         }
 
         // TODO Handle docletArtifacts
         String doclet = getMavenJavadocPluginBasicOptionproject"doclet"null );
         if ( doclet != null )
         {
             String docletpath = getMavenJavadocPluginBasicOptionproject"docletpath"null );
             if ( StringUtils.isNotEmptydocletpath ) )
             {
                 writer.startElement"doclet" );
                 writer.addAttribute"name"doclet );
                 addWrapAttributewriter"javadoc""path"docletpath, 4 );
                 writer.endElement(); // doclet
             }
             else
             {
                 Map docletArtifact = getMavenJavadocPluginOptionproject"docletArtifact"null );
                 String path = wrapper.getArtifactAbsolutePath( (StringdocletArtifact.get"groupId" ),
                                                                (StringdocletArtifact.get"artifactId" ),
                                                                (StringdocletArtifact.get"version" ) );
                 path = StringUtils.replacepathwrapper.getLocalRepository().getBasedir(), "${maven.repo.local}" );
 
                 writer.startElement"doclet" );
                 writer.addAttribute"name"doclet );
                 addWrapAttributewriter"javadoc""path"path, 4 );
                 writer.endElement(); // doclet
             }
         }
 
         // TODO Handle taglets
         String taglet = getMavenJavadocPluginBasicOptionproject"taglet"null );
         if ( taglet != null )
         {
             String tagletpath = getMavenJavadocPluginBasicOptionproject"tagletpath"null );
             if ( StringUtils.isNotEmptytagletpath ) )
             {
                 writer.startElement"taglet" );
                 writer.addAttribute"name"taglet );
                 addWrapAttributewriter"javadoc""path"tagletpath, 4 );
                 writer.endElement(); // taglet
             }
             else
             {
                 Map tagletArtifact = getMavenJavadocPluginOptionproject"tagletArtifact"null );
                 String path = wrapper.getArtifactAbsolutePath( (StringtagletArtifact.get"groupId" ),
                                                                (StringtagletArtifact.get"artifactId" ),
                                                                (StringtagletArtifact.get"version" ) );
                 path = StringUtils.replacepathwrapper.getLocalRepository().getBasedir(), "${maven.repo.local}" );
 
                 writer.startElement"taglet" );
                 writer.addAttribute"name"taglet );
                 addWrapAttributewriter"javadoc""path"path, 4 );
                 writer.endElement(); // taglet
             }
         }
 
         Map[] tags = getMavenJavadocPluginOptionsproject"tags"null );
         if ( tags != null )
         {
             for ( int i = 0; i < tags.lengthi++ )
             {
                 writer.startElement"tag" );
                 writer.addAttribute"name", (Stringtags[i].get"name" ) );
                 addWrapAttributewriter"javadoc""scope", (Stringtags[i].get"placement" ), 4 );
                 addWrapAttributewriter"javadoc""description", (Stringtags[i].get"head" ), 4 );
                 writer.endElement(); // tag
             }
         }
 
         writer.endElement(); // javadoc
     }

    
Convenience method to write XML Ant jar task

Parameters:
writer not null
project not null
Throws:
java.io.IOException if any
 
     public static void writeJarTaskXMLWriter writerMavenProject project )
         throws IOException
     {
         writer.startElement"jar" );
         writer.addAttribute"jarfile""${maven.build.dir}/${maven.build.finalName}.jar" );
         addWrapAttributewriter"jar""compress",
                           getMavenJarPluginBasicOptionproject"archive//compress""true" ), 3 );
         addWrapAttributewriter"jar""index"getMavenJarPluginBasicOptionproject"archive//index""false" ), 3 );
         if ( getMavenJarPluginBasicOptionproject"archive//manifestFile"null ) != null )
         {
             addWrapAttributewriter"jar""manifest"getMavenJarPluginBasicOptionproject,
                                                                                        "archive//manifestFile"null ),
                               3 );
         }
         addWrapAttributewriter"jar""basedir""${maven.build.outputDir}", 3 );
         addWrapAttributewriter"jar""excludes""**/package.html", 3 );
         if ( getMavenJarPluginBasicOptionproject"archive//manifest"null ) != null )
         {
             writer.startElement"manifest" );
             writer.startElement"attribute" );
             writer.addAttribute"name""Main-Class" );
             addWrapAttributewriter"attribute""value",
                               getMavenJarPluginBasicOptionproject"archive//manifest//mainClass"null ), 5 );
             writer.endElement(); // attribute
             writer.endElement(); // manifest
         }
         writer.endElement(); // jar
     }

    
Convenience method to write XML Ant ear task

Parameters:
writer not null
project not null
Throws:
java.io.IOException if any
 
     public static void writeEarTaskXMLWriter writerMavenProject project )
         throws IOException
     {
         writeCopyLibwriterproject"${maven.build.dir}/${maven.build.finalName}" );
 
         writer.startElement"ear" );
         writer.addAttribute"destfile""${maven.build.dir}/${maven.build.finalName}.ear" );
         addWrapAttributewriter"ear""basedir""${maven.build.dir}/${maven.build.finalName}", 3 );
         addWrapAttributewriter"ear""compress",
                           getMavenEarPluginBasicOptionproject"archive//compress""true" ), 3 );
         addWrapAttributewriter"ear""includes "getMavenEarPluginBasicOptionproject"includes"null ), 3 );
         addWrapAttributewriter"ear""excludes"getMavenEarPluginBasicOptionproject"excludes"null ), 3 );
         if ( getMavenEarPluginBasicOptionproject"applicationXml"null ) != null )
         {
             addWrapAttributewriter"ear""appxml"getMavenEarPluginBasicOptionproject"applicationXml"null ),
                               3 );
         }
         else
         {
             // Generated appxml
             addWrapAttributewriter"ear""appxml""${maven.build.dir}/application.xml", 3 );
         }
         if ( getMavenEarPluginBasicOptionproject"manifestFile"null ) != null )
         {
             addWrapAttributewriter"ear""manifest"getMavenEarPluginBasicOptionproject"manifestFile"null ),
                               3 );
         }
         writer.endElement(); // ear
     }

    
Convenience method to write XML Ant war task

Parameters:
writer not null
project not null
localRepository not null
Throws:
java.io.IOException if any
 
     public static void writeWarTaskXMLWriter writerMavenProject projectFile localRepository )
         throws IOException
     {
         writeCopyLibwriterproject"${maven.build.dir}/${maven.build.finalName}/WEB-INF/lib" );
 
         writer.startElement"war" );
         writer.addAttribute"destfile""${maven.build.dir}/${maven.build.finalName}.war" );
         addWrapAttributewriter"war""basedir""${maven.build.outputDir}", 3 );
         addWrapAttributewriter"war""compress",
                           getMavenWarPluginBasicOptionproject"archive//compress""true" ), 3 );
         if ( getMavenWarPluginBasicOptionproject"webXml"null ) != null )
         {
             addWrapAttributewriter"war""webxml"getMavenWarPluginBasicOptionproject"webXml"null ), 3 );
         }
         else
         {
             // Default
             addWrapAttributewriter"war""webxml""${basedir}/src/main/webapp/WEB-INF/web.xml", 3 );
         }
         if ( getMavenWarPluginBasicOptionproject"manifestFile"null ) != null )
         {
             addWrapAttributewriter"war""manifest"getMavenWarPluginBasicOptionproject"manifestFile"null ),
                               3 );
         }
         writer.startElement"lib" );
         writer.addAttribute"dir""${maven.build.dir}/${maven.build.finalName}/WEB-INF/lib" );
         writer.endElement(); // lib
         writer.startElement"classes" );
         writer.addAttribute"dir""${maven.build.outputDir}" );
         writer.endElement(); // classes
         writer.startElement"webinf" );
         writer.addAttribute"dir""${basedir}/src/main/webapp/WEB-INF" );
         addWrapAttributewriter"webinf""excludes""web.xml", 4 );
         writer.endElement(); // webinf
         writer.startElement"fileset" );
         writer.addAttribute"dir""${basedir}/src/main/webapp" );
         writer.endElement(); // fileset
         writer.endElement(); // war
     }

    
Convenience method to wrap long element tags for a given attribute.

Parameters:
writer not null
tag not null
name not null
value not null
indent positive value
 
     public static void addWrapAttributeXMLWriter writerString tagString nameString valueint indent )
     {
         if ( StringUtils.isEmptyvalue ) )
         {
             return;
         }
 
         if ( indent < 0 )
         {
             writer.addAttributenamevalue );
         }
         else
         {
             writer.addAttribute"\n"
                 + StringUtils.repeat" ", ( StringUtils.isEmptytag ) ? 0 : tag.length() ) + indent
                     * . ) + namevalue );
         }
     }

    

Parameters:
mavenProject not null
Returns:
true if project packaging equals pom
 
     public static boolean isPomPackagingMavenProject mavenProject )
     {
         return mavenProject.getPackaging().toLowerCase().equals"pom" );
     }

    

Parameters:
mavenProject not null
Returns:
true if project packaging equals jar or maven-plugin
 
     public static boolean isJarPackagingMavenProject mavenProject )
     {
         return mavenProject.getPackaging().toLowerCase().equals"jar" )
             || mavenProject.getPackaging().toLowerCase().equals"ejb" )
             || mavenProject.getPackaging().toLowerCase().equals"maven-plugin" );
     }

    

Parameters:
mavenProject
Returns:
true if project packaging equals ear
 
     public static boolean isEarPackagingMavenProject mavenProject )
     {
         return mavenProject.getPackaging().toLowerCase().equals"ear" );
     }

    

Parameters:
mavenProject not null
Returns:
true if project packaging equals war
 
     public static boolean isWarPackagingMavenProject mavenProject )
     {
         return mavenProject.getPackaging().toLowerCase().equals"war" );
     }

    
Return the optionName value defined in a project for the "maven-compiler-plugin" plugin.

Parameters:
project not null
optionName the option name wanted
defaultValue a default value
Returns:
the value for the option name or the default value. Could be null if not found.
Throws:
java.io.IOException if any
 
     public static String getMavenCompilerPluginBasicOptionMavenProject projectString optionNameString defaultValue )
         throws IOException
     {
         return getMavenPluginBasicOptionproject"maven-compiler-plugin"optionNamedefaultValue );
     }

    
Return the map of optionName value defined in a project for the "maven-compiler-plugin" plugin.

Parameters:
project not null
optionName the option name wanted
defaultValue a default value
Returns:
the map for the option name or the default value. Could be null if not found.
Throws:
java.io.IOException if any
 
     public static Map getMavenCompilerPluginOptionMavenProject projectString optionNameString defaultValue )
         throws IOException
     {
         return getMavenPluginOptionproject"maven-compiler-plugin"optionNamedefaultValue );
     }

    
Return an array of map of optionName value defined in a project for the "maven-compiler-plugin" plugin.

Parameters:
project not null
optionName the option name wanted
defaultValue a default value
Returns:
the array of option name or the default value. Could be null if not found.
Throws:
java.io.IOException if any
 
     public static Map[] getMavenCompilerPluginOptionsMavenProject projectString optionNameString defaultValue )
         throws IOException
     {
         return getMavenPluginOptionsproject"maven-compiler-plugin"optionNamedefaultValue );
     }

    
Return the optionName value defined in a project for the "maven-javadoc-plugin" plugin.

Parameters:
project not null
optionName the option name wanted
defaultValue a default value
Returns:
the value for the option name or the default value. Could be null if not found.
Throws:
java.io.IOException if any
 
     public static String getMavenJavadocPluginBasicOptionMavenProject projectString optionNameString defaultValue )
         throws IOException
     {
         return getMavenPluginBasicOptionproject"maven-javadoc-plugin"optionNamedefaultValue );
     }

    
Return a map of optionName value defined in a project for the "maven-javadoc-plugin" plugin.

Parameters:
project not null
optionName the option name wanted
defaultValue a default value
Returns:
the map for the option name or the default value. Could be null if not found.
Throws:
java.io.IOException if any
 
     public static Map getMavenJavadocPluginOptionMavenProject projectString optionNameString defaultValue )
         throws IOException
     {
         return getMavenPluginOptionproject"maven-javadoc-plugin"optionNamedefaultValue );
     }

    
Return an array of map of optionName value defined in a project for the "maven-javadoc-plugin" plugin.

Parameters:
project not null
optionName the option name wanted
defaultValue a default value
Returns:
an array of option name. Could be null if not found.
Throws:
java.io.IOException if any
 
     public static Map[] getMavenJavadocPluginOptionsMavenProject projectString optionNameString defaultValue )
         throws IOException
     {
         return getMavenPluginOptionsproject"maven-javadoc-plugin"optionNamedefaultValue );
     }

    
Return the optionName value defined in a project for the "maven-jar-plugin" plugin.

Parameters:
project not null
optionName the option name wanted
defaultValue a default value
Returns:
the value for the option name or the default value. Could be null if not found.
Throws:
java.io.IOException if any
 
     public static String getMavenJarPluginBasicOptionMavenProject projectString optionNameString defaultValue )
         throws IOException
     {
         return getMavenPluginBasicOptionproject"maven-jar-plugin"optionNamedefaultValue );
     }

    
Return the optionName value defined in a project for the "maven-ear-plugin" plugin.

Parameters:
project not null
optionName the option name wanted
defaultValue a default value
Returns:
the value for the option name or the default value. Could be null if not found.
Throws:
java.io.IOException if any
 
     public static String getMavenEarPluginBasicOptionMavenProject projectString optionNameString defaultValue )
         throws IOException
     {
         return getMavenPluginBasicOptionproject"maven-ear-plugin"optionNamedefaultValue );
     }

    
Return the optionName value defined in a project for the "maven-war-plugin" plugin.

Parameters:
project not null
optionName the option name wanted
defaultValue a default value
Returns:
the value for the option name or the default value. Could be null if not found.
Throws:
java.io.IOException if any
 
     public static String getMavenWarPluginBasicOptionMavenProject projectString optionNameString defaultValue )
         throws IOException
     {
         return getMavenPluginBasicOptionproject"maven-war-plugin"optionNamedefaultValue );
     }
 
     // ----------------------------------------------------------------------
     // Convenience methods
     // ----------------------------------------------------------------------
 
    
Return the value for the option optionName defined in a project with the given artifactId plugin.
Example:
ConfigurationResult
<option>value</option>
value

Parameters:
project not null
pluginArtifactId not null
optionName an Xpath expression from the plugin <configuration/>
defaultValue could be null
Returns:
the value for the option name or null if not found
Throws:
java.io.IOException if any
 
     private static String getMavenPluginBasicOptionMavenProject projectString pluginArtifactIdString optionName,
                                                     String defaultValue )
         throws IOException
     {
         return (StringgetMavenPluginConfigurationsImplprojectpluginArtifactIdoptionNamedefaultValue )
             .getoptionName );
     }

    
Return a Map for the option optionName defined in a project with the given artifactId plugin.
Example:
ConfigurationResult
 <option>
  <param1>value1</param1>
  <param2>value2</param2>
 </option>
 
{param1=value1, param2=value2}

Parameters:
project not null
pluginArtifactId not null
optionName an Xpath expression from the plugin <configuration/>
defaultValue could be null
Returns:
the value for the option name or null if not found
Throws:
java.io.IOException if any
 
     private static Map getMavenPluginOptionMavenProject projectString pluginArtifactIdString optionName,
                                             String defaultValue )
         throws IOException
     {
         return (MapgetMavenPluginConfigurationsImplprojectpluginArtifactIdoptionNamedefaultValue )
             .getoptionName );
     }

    
Return an array of Map for the option optionName defined in a project with the given artifactId plugin.
Example:
ConfigurationResult
 <options>
   <option>
    <param1>value1</param1>
    <param2>value2</param2>
   </option>
   <option>
    <param1>value1</param1>
    <param2>value2</param2>
   </option>
 </options>
 
[{option=[{param1=value1, param2=value2}]}, {option=[{param1=value1, param2=value2}]

Parameters:
project not null
pluginArtifactId not null
optionName an Xpath expression from the plugin <configuration/>
defaultValue could be null
Returns:
the value for the option name or null if not found
Throws:
java.io.IOException if any
 
     private static Map[] getMavenPluginOptionsMavenProject projectString pluginArtifactIdString optionName,
                                                String defaultValue )
         throws IOException
     {
         return (Map[]) getMavenPluginConfigurationsImplprojectpluginArtifactIdoptionNamedefaultValue )
             .getoptionName );
     }

    
Return a Map for the option optionName defined in a project with the given artifactId plugin.
Example:
ConfigurationResult
<option>value</option>
{option=value}
 <option>
  <param1>value1</param1>
  <param2>value2</param2>
 </option>
 
{option={param1=value1, param2=value2}}
 <options>
   <option>
    <param1>value1</param1>
    <param2>value2</param2>
   </option>
   <option>
    <param1>value1</param1>
    <param2>value2</param2>
   </option>
 </options>
 
{options=[{option=[{param1=value1, param2=value2}]}, {option=[{param1=value1, param2=value2}]}]

Parameters:
project not null
pluginArtifactId not null
optionName an Xpath expression from the plugin <configuration/>
defaultValue could be null
Returns:
a map with the options found
Throws:
java.io.IOException if any
    private static Map getMavenPluginConfigurationsImplMavenProject projectString pluginArtifactId,
                                                        String optionNameString defaultValue )
        throws IOException
    {
        List plugins = new ArrayList();
        for ( Iterator it = project.getModel().getReporting().getPlugins().iterator(); it.hasNext(); )
        {
            plugins.addit.next() );
        }
        for ( Iterator it = project.getModel().getBuild().getPlugins().iterator(); it.hasNext(); )
        {
            plugins.addit.next() );
        }
        for ( Iterator it = plugins.iterator(); it.hasNext(); )
        {
            Object next = it.next();
            Xpp3Dom pluginConf = null;
            if ( next instanceof Plugin )
            {
                Plugin plugin = (Pluginnext;
                // using out-of-box Maven plugins
                if ( !( ( plugin.getGroupId().equals"org.apache.maven.plugins" ) ) && ( plugin.getArtifactId()
                    .equalspluginArtifactId ) ) ) )
                {
                    continue;
                }
                pluginConf = (Xpp3Domplugin.getConfiguration();
            }
            if ( next instanceof ReportPlugin )
            {
                ReportPlugin reportPlugin = (ReportPluginnext;
                // using out-of-box Maven plugins
                if ( !( ( reportPlugin.getGroupId().equals"org.apache.maven.plugins" ) ) && ( reportPlugin
                    .getArtifactId().equalspluginArtifactId ) ) ) )
                {
                    continue;
                }
                pluginConf = (Xpp3DomreportPlugin.getConfiguration();
            }
            if ( pluginConf == null )
            {
                continue;
            }
            try
            {
                Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder()
                    .parsenew StringInputStreampluginConf.toString() ) );
                XObject obj = XPathAPI.evaldoc"//configuration/" + optionName );
                NodeList nodeList = obj.nodelist();
                if ( isListnodeList.item( 0 ) ) )
                {
                    /*
                     * <optionNames>
                     *   <optionName>
                     *    <param1>value1</param1>
                     *    <param2>value2</param2>
                     *   </optionName>
                     * </optionNames>
                     */
                    Map options = new HashMap();
                    List optionNames = new ArrayList();
                    NodeList childs = nodeList.item( 0 ).getChildNodes();
                    for ( int i = 0; i < childs.getLength(); i++ )
                    {
                        if ( childs.itemi ).getNodeType() == . )
                        {
                            Map option = new HashMap();
                            obj = XPathAPI.evaldoc"//configuration/" + childs.itemi ).getNodeName() );
                            if ( StringUtils.isNotEmptyobj.toString() ) )
                            {
                                Map properties = new HashMap();
                                NodeList childs2 = childs.itemi ).getChildNodes();
                                if ( childs2.getLength() > 0 )
                                {
                                    for ( int j = 0; j < childs2.getLength(); j++ )
                                    {
                                        if ( childs2.itemj ).getNodeType() == . )
                                        {
                                            properties.putchilds2.itemj ).getNodeName(), childs2.itemj )
                                                .getFirstChild().getNodeValue() );
                                        }
                                    }
                                    option.putchilds.itemi ).getNodeName(), properties );
                                }
                            }
                            else
                            {
                                option.putchilds.itemi ).getNodeName(), childs.itemi ).getFirstChild()
                                    .getNodeValue() );
                            }
                            optionNames.addoption );
                        }
                    }
                    options.putoptionNameoptionNames.toArraynew Map[0] ) );
                    return options;
                }
                /*
                 * <optionName>
                 *  <param1>value1</param1>
                 *  <param2>value2</param2>
                 * </optionName>
                 */
                if ( StringUtils.isNotEmptyobj.toString() ) )
                {
                    Map option = new HashMap();
                    NodeList childs = nodeList.item( 0 ).getChildNodes();
                    if ( childs.getLength() > 1 )
                    {
                        Map parameters = new HashMap();
                        for ( int i = 0; i < childs.getLength(); i++ )
                        {
                            if ( childs.itemi ).getNodeType() == . )
                            {
                                parameters.putchilds.itemi ).getNodeName(), childs.itemi ).getFirstChild()
                                    .getNodeValue() );
                            }
                        }
                        option.putoptionNameparameters );
                    }
                    else
                    {
                        /*
                         * <optionName>value1</optionName>
                         */
                        option.putoptionNameobj.toString() );
                    }
                    return option;
                }
            }
            catch ( Exception e )
            {
                throw new IOException"Exception occured: " + e.getMessage() );
            }
        }
        Map properties = new HashMap();
        properties.putoptionNamedefaultValue );
        return properties;
    }

    
Write copy tasks in an outputDir for EAR and WAR targets for project depencies without provided or test as scope

Parameters:
writer not null
project not null
outputDir not null
    private static void writeCopyLibXMLWriter writerMavenProject projectString outputDir )
    {
        writer.startElement"mkdir" );
        writer.addAttribute"dir"outputDir );
        writer.endElement(); // mkdir
        if ( !project.getDependencyArtifacts().isEmpty() )
        {
            for ( Iterator i = project.getDependencyArtifacts().iterator(); i.hasNext(); )
            {
                Artifact artifact = (Artifacti.next();
                if ( !artifact.getScope().equals. )
                    && !artifact.getScope().equals. ) )
                {
                    writer.startElement"copy" );
                    writer.addAttribute"file"artifact.getFile().getPath() );
                    addWrapAttributewriter"copy""todir"outputDir, 3 );
                    writer.endElement(); // copy
                }
            }
        }
    }

    
Check if a given node is a list of nodes or not.
For instance, the node options is a list of option in the following case:
 <options>
   <option>
    <param1>value1</param1>
    <param2>value2</param2>
   </option>
   <option>
    <param1>value1</param1>
    <param2>value2</param2>
   </option>
 </options>
 

Parameters:
node a given node
Returns:
true if the node is a list, false otherwise.
    private static boolean isListNode node )
    {
        if ( node == null )
        {
            return false;
        }
        NodeList childs = node.getChildNodes();
        boolean isList = false;
        String lastNodeName = null;
        for ( int i = 0; i < childs.getLength(); i++ )
        {
            if ( childs.itemi ).getNodeType() == . )
            {
                if ( i != 0 )
                {
                    isList = isList || ( childs.itemi ).getNodeName().equalslastNodeName ) );
                }
                lastNodeName = childs.itemi ).getNodeName();
            }
        }
        return isList;
    }