groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject [3/4] groovy git commit: GROOVY-8295: Groovyc ant task can overflow Windows command line if classpath is large (closes #629)
Date Mon, 13 Nov 2017 02:50:51 GMT
GROOVY-8295: Groovyc ant task can overflow Windows command line if classpath is large (closes
#629)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/a8390968
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/a8390968
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/a8390968

Branch: refs/heads/GROOVY_2_4_X
Commit: a83909683bbdc6dba253fbb9ca9f8e52e3d6461c
Parents: da310b6
Author: paulk <paulk@asert.com.au>
Authored: Tue Nov 7 12:30:10 2017 +1000
Committer: paulk <paulk@asert.com.au>
Committed: Mon Nov 13 12:50:33 2017 +1000

----------------------------------------------------------------------
 .../java/org/codehaus/groovy/ant/Groovyc.java   | 65 +++++++++++---------
 1 file changed, 37 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/a8390968/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java
----------------------------------------------------------------------
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 594dd40..8942f90 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
@@ -20,23 +20,6 @@ package org.codehaus.groovy.ant;
 
 import groovy.lang.GroovyClassLoader;
 import groovy.lang.GroovyResourceLoader;
-
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.nio.charset.Charset;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.StringTokenizer;
-
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.CommandLineParser;
 import org.apache.commons.cli.GroovyInternalPosixParser;
@@ -62,6 +45,22 @@ import org.codehaus.groovy.tools.FileSystemCompiler;
 import org.codehaus.groovy.tools.RootLoader;
 import org.codehaus.groovy.tools.javac.JavaAwareCompilationUnit;
 
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.StringTokenizer;
+
 /**
  * Compiles Groovy source files using Ant.
  * <p>
@@ -1006,7 +1005,7 @@ public class Groovyc extends MatchingTask {
             commandLineList.add(javaHome + separator + "bin" + separator + "java");
         }
         commandLineList.add("-classpath");
-        commandLineList.add(classpath.toString());
+        commandLineList.add(getClasspathRelative(classpath));
 
         final String fileEncodingProp = System.getProperty("file.encoding");
         if ((fileEncodingProp != null) && !fileEncodingProp.equals("")) {
@@ -1034,9 +1033,25 @@ public class Groovyc extends MatchingTask {
         }
     }
 
+    private String getClasspathRelative(Path classpath) {
+        String raw = classpath.toString();
+        String baseDir = getProject().getBaseDir().getAbsolutePath();
+        if (!raw.startsWith(baseDir)) {
+            return raw;
+        }
+        return "." + raw.substring(baseDir.length());
+    }
+
+    /**
+     * Add "groovyc" parameters to the commandLineList, based on the ant configuration.
+     *
+     * @param commandLineList
+     * @param jointOptions
+     * @param classpath
+     */
     private void doNormalCommandLineList(List<String> commandLineList, List<String>
jointOptions, Path classpath) {
         commandLineList.add("--classpath");
-        commandLineList.add(classpath.toString());
+        commandLineList.add(getClasspathRelative(classpath));
         if (jointCompilation) {
             commandLineList.add("-j");
             commandLineList.addAll(jointOptions);
@@ -1100,18 +1115,12 @@ public class Groovyc extends MatchingTask {
     }
 
     private String[] makeCommandLine(List<String> commandLineList) {
-        final String[] commandLine = new String[commandLineList.size()];
-        for (int i = 0; i < commandLine.length; ++i) {
-            commandLine[i] = commandLineList.get(i);
-        }
-        log.verbose("Compilation arguments:");
-        log.verbose(DefaultGroovyMethods.join(commandLine, "\n"));
-        return commandLine;
+        log.verbose("Compilation arguments:\n" + DefaultGroovyMethods.join(commandLineList,
"\n"));
+        return commandLineList.toArray(new String[commandLineList.size()]);
     }
 
     private void runForked(String[] commandLine) {
-        // use the main method in FileSystemCompiler
-        final Execute executor = new Execute(); // new LogStreamHandler ( attributes , Project.MSG_INFO
, Project.MSG_WARN ) ) ;
+        final Execute executor = new Execute();
         executor.setAntRun(getProject());
         executor.setWorkingDirectory(getProject().getBaseDir());
         executor.setCommandline(commandLine);


Mime
View raw message