maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hbout...@apache.org
Subject [maven-ant-plugin] 30/50: MANT-17: Using Maven Compiler Plugin settings to define javac task
Date Wed, 20 Dec 2017 09:26:48 GMT
This is an automated email from the ASF dual-hosted git repository.

hboutemy pushed a commit to annotated tag maven-ant-plugin-2.0
in repository https://gitbox.apache.org/repos/asf/maven-ant-plugin.git

commit 5417ffeaeac233b17f59f43ab504a50d4830434a
Author: Vincent Siveton <vsiveton@apache.org>
AuthorDate: Mon Sep 25 11:38:16 2006 +0000

    MANT-17: Using Maven Compiler Plugin settings to define javac task
    
    o Get Maven compiler configuration and transform it in javac Ant task
    
    git-svn-id: https://svn.apache.org/repos/asf/maven/plugins/trunk/maven-ant-plugin@449656
13f79535-47bb-0310-9956-ffa450edef68
---
 .../apache/maven/plugin/ant/AntBuildWriter.java    | 35 +++++++++---
 .../maven/plugin/ant/AntBuildWriterUtil.java       | 63 ++++++++++++++++++++++
 2 files changed, 91 insertions(+), 7 deletions(-)

diff --git a/src/main/java/org/apache/maven/plugin/ant/AntBuildWriter.java b/src/main/java/org/apache/maven/plugin/ant/AntBuildWriter.java
index f0a41a2..55f7426 100644
--- a/src/main/java/org/apache/maven/plugin/ant/AntBuildWriter.java
+++ b/src/main/java/org/apache/maven/plugin/ant/AntBuildWriter.java
@@ -859,9 +859,8 @@ public class AntBuildWriter
         AntBuildWriterUtil.writeLineBreak( writer );
     }
 
-    private static void writeCompileTasks( XMLWriter writer, File basedir, String outputDirectory,
-                                          List compileSourceRoots, List resources, String
additionalClassesDirectory,
-                                          boolean isTest )
+    private void writeCompileTasks( XMLWriter writer, File basedir, String outputDirectory,
List compileSourceRoots,
+                                   List resources, String additionalClassesDirectory, boolean
isTest )
     {
         writer.startElement( "mkdir" );
         writer.addAttribute( "dir", outputDirectory );
@@ -871,10 +870,32 @@ public class AntBuildWriter
         {
             writer.startElement( "javac" );
             writer.addAttribute( "destdir", outputDirectory );
-            AntBuildWriterUtil.addWrapAttribute( writer, "javac", "excludes", "**/package.html",
3 );
-            AntBuildWriterUtil.addWrapAttribute( writer, "javac", "debug", "true", 3 ); //
TODO: use compiler setting
-            AntBuildWriterUtil.addWrapAttribute( writer, "javac", "deprecation", "true",
3 ); // TODO: use compiler setting
-            AntBuildWriterUtil.addWrapAttribute( writer, "javac", "optimize", "false", 3
); // TODO: use compiler setting
+            AntBuildWriterUtil.addWrapAttribute( writer, "javac", "includes", AntBuildWriterUtil
+                .getMavenCompilerPluginConfiguration( project, "includes", null ), 3 );
+            AntBuildWriterUtil.addWrapAttribute( writer, "javac", "excludes", AntBuildWriterUtil
+                .getMavenCompilerPluginConfiguration( project, "excludes", null ), 3 );
+            AntBuildWriterUtil.addWrapAttribute( writer, "javac", "encoding", AntBuildWriterUtil
+                .getMavenCompilerPluginConfiguration( project, "encoding", null ), 3 );
+            AntBuildWriterUtil.addWrapAttribute( writer, "javac", "nowarn", AntBuildWriterUtil
+                .getMavenCompilerPluginConfiguration( project, "showWarnings", "false" ),
3 );
+            AntBuildWriterUtil.addWrapAttribute( writer, "javac", "debug", AntBuildWriterUtil
+                .getMavenCompilerPluginConfiguration( project, "debug", "true" ), 3 );
+            AntBuildWriterUtil.addWrapAttribute( writer, "javac", "optimize", AntBuildWriterUtil
+                .getMavenCompilerPluginConfiguration( project, "optimize", "false" ), 3 );
+            AntBuildWriterUtil.addWrapAttribute( writer, "javac", "deprecation", AntBuildWriterUtil
+                .getMavenCompilerPluginConfiguration( project, "showDeprecation", "true"
), 3 );
+            AntBuildWriterUtil.addWrapAttribute( writer, "javac", "target", AntBuildWriterUtil
+                .getMavenCompilerPluginConfiguration( project, "target", null ), 3 );
+            AntBuildWriterUtil.addWrapAttribute( writer, "javac", "verbose", AntBuildWriterUtil
+                .getMavenCompilerPluginConfiguration( project, "verbose", "false" ), 3 );
+            AntBuildWriterUtil.addWrapAttribute( writer, "javac", "fork", AntBuildWriterUtil
+                .getMavenCompilerPluginConfiguration( project, "fork", "false" ), 3 );
+            AntBuildWriterUtil.addWrapAttribute( writer, "javac", "memoryMaximumSize", AntBuildWriterUtil
+                .getMavenCompilerPluginConfiguration( project, "meminitial", null ), 3 );
+            AntBuildWriterUtil.addWrapAttribute( writer, "javac", "memoryInitialSize", AntBuildWriterUtil
+                .getMavenCompilerPluginConfiguration( project, "maxmem", null ), 3 );
+            AntBuildWriterUtil.addWrapAttribute( writer, "javac", "source", AntBuildWriterUtil
+                .getMavenCompilerPluginConfiguration( project, "source", null ), 3 );
 
             String[] compileSourceRootsArray = (String[]) compileSourceRoots.toArray( new
String[0] );
             for ( int i = 0; i < compileSourceRootsArray.length; i++ )
diff --git a/src/main/java/org/apache/maven/plugin/ant/AntBuildWriterUtil.java b/src/main/java/org/apache/maven/plugin/ant/AntBuildWriterUtil.java
index 34868e8..05cc71d 100644
--- a/src/main/java/org/apache/maven/plugin/ant/AntBuildWriterUtil.java
+++ b/src/main/java/org/apache/maven/plugin/ant/AntBuildWriterUtil.java
@@ -16,8 +16,13 @@ package org.apache.maven.plugin.ant;
  * limitations under the License.
  */
 
+import java.util.Iterator;
+
+import org.apache.maven.model.Plugin;
+import org.apache.maven.project.MavenProject;
 import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.util.xml.XMLWriter;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
 
 /**
  * Utility class for the <code>AntBuildWriter</code> class.
@@ -173,6 +178,11 @@ public class AntBuildWriterUtil
      */
     public static void addWrapAttribute( XMLWriter writer, String tag, String name, String
value, int indent )
     {
+        if ( StringUtils.isEmpty( value ) )
+        {
+            return;
+        }
+
         if ( indent < 0 )
         {
             writer.addAttribute( name, value );
@@ -184,4 +194,57 @@ public class AntBuildWriterUtil
                     * AntBuildWriter.DEFAULT_INDENTATION_SIZE ) + name, value );
         }
     }
+
+    /**
+     * Return the optionName value defined in a project for a given artifactId plugin.
+     *
+     * @param project
+     * @param optionName
+     * @param defaultValue
+     * @return the value for the option name (comma separated value in the case of list)
or null if not found
+     */
+    public static String getMavenCompilerPluginConfiguration( MavenProject project, String
optionName,
+                                                String defaultValue )
+    {
+        for ( Iterator it = project.getModel().getBuild().getPlugins().iterator(); it.hasNext();
)
+        {
+            Plugin plugin = (Plugin) it.next();
+
+            if ( ( plugin.getGroupId().equals( "org.apache.maven.plugins" ) )
+                && ( plugin.getArtifactId().equals( "maven-compiler-plugin" ) ) )
+            {
+                Xpp3Dom dom = (Xpp3Dom) plugin.getConfiguration();
+
+                if ( ( dom != null ) && ( dom.getChild( optionName ) != null ) )
+                {
+                    if ( StringUtils.isNotEmpty( dom.getChild( optionName ).getValue() )
)
+                    {
+                        return dom.getChild( optionName ).getValue();
+                    }
+
+                    if ( dom.getChild( optionName ).getChildren() != null )
+                    {
+                        StringBuffer sb = new StringBuffer();
+
+                        Xpp3Dom[] children = dom.getChild( optionName ).getChildren();
+                        for ( int i = 0; i < children.length; i++ )
+                        {
+                            String value = children[i].getValue();
+                            if ( StringUtils.isNotEmpty( value ) )
+                            {
+                                sb.append( value );
+                                if ( i < children.length - 1 )
+                                {
+                                    sb.append( "," );
+                                }
+                            }
+                        }
+                        return sb.toString();
+                    }
+                }
+            }
+        }
+
+        return defaultValue;
+    }
 }

-- 
To stop receiving notification emails like this one, please contact
"commits@maven.apache.org" <commits@maven.apache.org>.

Mime
View raw message