groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject [groovy] 01/02: Ant: add support for more joint compilation options
Date Fri, 15 Nov 2019 10:57:46 GMT
This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 15dc98c9a499231931a8b98f5031569adb6a0b89
Author: Eric Milles <eric.milles@thomsonreuters.com>
AuthorDate: Wed Nov 13 13:58:02 2019 -0600

    Ant: add support for more joint compilation options
    
    <groovyc>
      <javac _attribute_ />
    </groovyc>
    - bootclasspath
    - bootclasspathref
    - deprecation
    - modulepath
    - modulepathref
    - modulesourcepath
    - modulesourcepathref
    - nativeheaderdir
    - nowarn
    - release
    - upgrademodulepath
    - upgrademodulepathref
    
    <groovyc>
      <javac>
        <compilerarg value="-proc:_option_" />
      </javac>
    </groovyc>
    
    <groovyc previewFeatures="true">
      <javac><!-- receives "--enable-preview" argument -->
    </groovyc>
---
 .../codehaus/groovy/tools/FileSystemCompiler.java  | 53 ++++++++++---------
 .../main/java/org/codehaus/groovy/ant/Groovyc.java | 59 ++++++++++++++++------
 2 files changed, 71 insertions(+), 41 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/tools/FileSystemCompiler.java b/src/main/java/org/codehaus/groovy/tools/FileSystemCompiler.java
index 39e103f..8b16882 100644
--- a/src/main/java/org/codehaus/groovy/tools/FileSystemCompiler.java
+++ b/src/main/java/org/codehaus/groovy/tools/FileSystemCompiler.java
@@ -84,7 +84,7 @@ public class FileSystemCompiler {
      *
      * @since 2.5
      */
-    public static void displayHelp(final PrintWriter writer) {
+    public static void displayHelp(PrintWriter writer) {
         configureParser(new CompilationOptions()).usage(writer);
     }
 
@@ -102,7 +102,7 @@ public class FileSystemCompiler {
      *
      * @since 2.5
      */
-    public static void displayVersion(final PrintWriter writer) {
+    public static void displayVersion(PrintWriter writer) {
         for (String line : new VersionProvider().getVersion()) {
             writer.println(line);
         }
@@ -115,10 +115,10 @@ public class FileSystemCompiler {
             File file = new File(filename);
             if (!file.exists()) {
                 System.err.println("error: file not found: " + file);
-                ++errors;
+                errors += 1;
             } else if (!file.canRead()) {
                 System.err.println("error: file not readable: " + file);
-                ++errors;
+                errors += 1;
             }
         }
 
@@ -419,15 +419,15 @@ public class FileSystemCompiler {
 
             // joint compilation parameters
             if (jointCompilation) {
-                Map<String, Object> compilerOptions = new HashMap<String, Object>();
-                compilerOptions.put("namedValues", javacOptionsList());
-                compilerOptions.put("flags", flagsWithParameterMetaData());
+                Map<String, Object> compilerOptions = new HashMap<>();
+                compilerOptions.put("flags", javacFlags());
+                compilerOptions.put("namedValues", javacNamedValues());
                 configuration.setJointCompilationOptions(compilerOptions);
             }
 
             if (indy) {
-                configuration.getOptimizationOptions().put("int", false);
-                configuration.getOptimizationOptions().put("indy", true);
+                configuration.getOptimizationOptions().put("int", Boolean.FALSE);
+                configuration.getOptimizationOptions().put("indy", Boolean.TRUE);
             }
 
             final List<String> transformations = new ArrayList<>();
@@ -443,12 +443,12 @@ public class FileSystemCompiler {
 
             String configScripts = System.getProperty("groovy.starter.configscripts", null);
             if (configScript != null || (configScripts != null && !configScripts.isEmpty()))
{
-                List<String> scripts = new ArrayList<String>();
+                List<String> scripts = new ArrayList<>();
                 if (configScript != null) {
                     scripts.add(configScript);
                 }
                 if (configScripts != null) {
-                    scripts.addAll(StringGroovyMethods.tokenize((CharSequence) configScripts,
','));
+                    scripts.addAll(StringGroovyMethods.tokenize(configScripts, ','));
                 }
                 processConfigScripts(scripts, configuration);
             }
@@ -460,26 +460,29 @@ public class FileSystemCompiler {
             return generateFileNamesFromOptions(files);
         }
 
-        String[] javacOptionsList() {
-            if (javacOptionsMap == null) {
-                return null;
-            }
-            List<String> result = new ArrayList<String>();
-            for (Map.Entry<String, String> entry : javacOptionsMap.entrySet()) {
-                result.add(entry.getKey());
-                result.add(entry.getValue());
+        private String[] javacNamedValues() {
+            List<String> result = new ArrayList<>();
+            if (javacOptionsMap != null) {
+                for (Map.Entry<String, String> entry : javacOptionsMap.entrySet())
{
+                    result.add(entry.getKey());
+                    result.add(entry.getValue());
+                }
             }
-            return result.toArray(new String[0]);
+            return result.isEmpty() ? null : result.toArray(new String[0]);
         }
 
-        String[] flagsWithParameterMetaData() {
-            if (flags == null) {
-                return null;
+        private String[] javacFlags() {
+            List<String> result = new ArrayList<>();
+            if (flags != null) {
+                result.addAll(flags);
             }
             if (parameterMetadata) {
-                flags.add("parameters");
+                result.add("parameters");
+            }
+            if (previewFeatures) {
+                result.add("-enable-preview");
             }
-            return flags.toArray(new String[0]);
+            return result.isEmpty() ? null : result.toArray(new String[0]);
         }
     }
 }
diff --git a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java
index a255703..a72af08 100644
--- a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java
+++ b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java
@@ -988,6 +988,16 @@ public class Groovyc extends MatchingTask {
             jointOptions.add("-Fg:none");
         }
 
+        // map "deprecation" to "-Fdeprecation"
+        if (javac.getDeprecation()) {
+            jointOptions.add("-Fdeprecation");
+        }
+
+        // map "nowarn" to "-Fnowarn"
+        if (javac.getNowarn()) {
+            jointOptions.add("-Fnowarn");
+        }
+
         // map "verbose" to "-Fverbose"
         if (javac.getVerbose()) {
             jointOptions.add("-Fverbose");
@@ -997,25 +1007,45 @@ public class Groovyc extends MatchingTask {
 
         for (Map.Entry<String, Object> e : rc.getAttributeMap().entrySet()) {
             String key = e.getKey();
-            if (key.contains("encoding")
-                    || key.contains("extdirs")
-                    || key.contains("depend")
-                    || key.contains("source")
-                    || key.contains("target")) {
-                // map "encoding", etc. to "-Jkey=val"
+            if (key.equals("depend")
+                    || key.equals("encoding")
+                    || key.equals("extdirs")
+                    || key.equals("nativeheaderdir")
+                    || key.equals("release")
+                    || key.equals("source")
+                    || key.equals("target")) {
+                switch (key) {
+                case "nativeheaderdir":
+                    key = "h"; break;
+                case "release":
+                    key = "-" + key; // to get "--" when passed to javac
+                }
+                // map "depend", "encoding", etc. to "-Jkey=val"
                 jointOptions.add("-J" + key + "=" + getProject().replaceProperties(e.getValue().toString()));
 
             } else if (key.contains("classpath")) {
                 if (key.startsWith("boot")) {
-                    // TODO: javac.getBootclasspath()
+                    // map "bootclasspath" or "bootclasspathref" to "-Jbootclasspath="
+                    jointOptions.add("-Jbootclasspath=" + javac.getBootclasspath());
                 } else {
+                    // map "classpath" or "classpathref" to "--classpath"
                     classpath.add(javac.getClasspath());
                 }
-            } else if (!key.contains("debug") && !key.contains("verbose")) {
+            } else if (key.contains("module") && key.contains("path")) {
+                if (key.startsWith("upgrade")) {
+                    // map "upgrademodulepath" or "upgrademodulepathref" to "-J-upgrade-module-path="
+                    jointOptions.add("-J-upgrade-module-path=" + javac.getUpgrademodulepath());
+                } else if (key.contains("source")) {
+                    // map "modulesourcepath" or "modulesourcepathref" to "-J-module-source-path="
+                    jointOptions.add("-J-module-source-path=" + javac.getModulesourcepath());
+                } else {
+                    // map "modulepath" or "modulepathref" to "-J-module-path="
+                    jointOptions.add("-J-module-path=" + javac.getModulepath());
+                }
+            } else if (!key.contains("debug") && !key.equals("deprecation") &&
!key.equals("nowarn") && !key.equals("verbose")) {
                 log.warn("The option " + key + " cannot be set on the contained <javac>
element. The option will be ignored.");
             }
-            // TODO: modulepath, modulepathref, modulesourcepath, modulesourcepathref, upgrademodulepath,
upgrademodulepathref
-            // TODO: release, deprecation, failonerror, nowarn, tempdir, nativeheaderdir,
includes(file)? excludes(file)?
+            // TODO: defaultexcludes, excludes(file)?, includes(file)?, includeDestClasses,
tempdir
         }
 
         // Ant's <javac> supports nested <compilerarg value=""> elements (there
@@ -1028,12 +1058,9 @@ public class Groovyc extends MatchingTask {
                         String value = getProject().replaceProperties(e.getValue().toString());
                         StringTokenizer st = new StringTokenizer(value, " ");
                         while (st.hasMoreTokens()) {
-                            String optionStr = st.nextToken();
-                            String replaced = optionStr.replace("-X", "-FX");
-                            if (optionStr.equals(replaced)) {
-                                replaced = optionStr.replace("-W", "-FW"); // GROOVY-5063
-                            }
-                            jointOptions.add(replaced);
+                            String option = st.nextToken();
+                            // GROOVY-5063: map "-Werror", etc. to "-FWerror"
+                            jointOptions.add(option.replaceFirst("^-(W|X|proc:)", "-F$1"));
                         }
                     }
                 }


Mime
View raw message