Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id F3503200D4B for ; Mon, 13 Nov 2017 03:45:10 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id F1EE2160C0A; Mon, 13 Nov 2017 02:45:10 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 4421E160C06 for ; Mon, 13 Nov 2017 03:45:10 +0100 (CET) Received: (qmail 99889 invoked by uid 500); 13 Nov 2017 02:45:09 -0000 Mailing-List: contact commits-help@groovy.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@groovy.apache.org Delivered-To: mailing list commits@groovy.apache.org Received: (qmail 99820 invoked by uid 99); 13 Nov 2017 02:45:09 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 13 Nov 2017 02:45:09 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 05DC0DFE46; Mon, 13 Nov 2017 02:45:09 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: paulk@apache.org To: commits@groovy.apache.org Date: Mon, 13 Nov 2017 02:45:10 -0000 Message-Id: <664f1d6921ae42228ce33bdb3c6a258a@git.apache.org> In-Reply-To: <2fbf0801a2094d3087f55d905952916c@git.apache.org> References: <2fbf0801a2094d3087f55d905952916c@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [3/5] groovy git commit: GROOVY-8295: Groovyc ant task can overflow Windows command line if classpath is large (closes #629) archived-at: Mon, 13 Nov 2017 02:45:11 -0000 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/a072f0ec Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/a072f0ec Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/a072f0ec Branch: refs/heads/GROOVY_2_5_X Commit: a072f0ec83041df5b0f422ad4d26b022a1fbc8b3 Parents: f7f7f23 Author: paulk Authored: Tue Nov 7 12:30:10 2017 +1000 Committer: paulk Committed: Mon Nov 13 12:44:54 2017 +1000 ---------------------------------------------------------------------- .../java/org/codehaus/groovy/ant/Groovyc.java | 58 ++++++++++---------- 1 file changed, 30 insertions(+), 28 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/groovy/blob/a072f0ec/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 d69dcb4..cf6408c 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.DefaultParser; @@ -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. *

@@ -1029,7 +1028,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("")) { @@ -1057,6 +1056,15 @@ 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. * @@ -1066,7 +1074,7 @@ public class Groovyc extends MatchingTask { */ private void doNormalCommandLineList(List commandLineList, List jointOptions, Path classpath) { commandLineList.add("--classpath"); - commandLineList.add(classpath.toString()); + commandLineList.add(getClasspathRelative(classpath)); if (jointCompilation) { commandLineList.add("-j"); commandLineList.addAll(jointOptions); @@ -1133,18 +1141,12 @@ public class Groovyc extends MatchingTask { } private String[] makeCommandLine(List 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);