ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Rall <...@finemaltcoding.com>
Subject [PATCH] completion of fix for Bug #975
Date Fri, 13 Apr 2001 23:27:36 GMT
>From the CVS log of Property.java (revision 1.25):

Fix for Bug #975 - sometimes (for example with a default installation of cygwin) there are
environment-variables containing a new-line. We ignore anything after the first line and log
the ignored lines with warning-level.

The completion of this fix should include proper handling of parsing
chunks of data returned by the external environment listing program
(whose command is returned by getProcEnvCommand()).  UNIX environment
variables can contain text with embedded newlines.  Jon Stevens and I
came up with a solution, which I have implemented:

Index: Execute.java
===================================================================
RCS file: /home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Execute.java,v
retrieving revision 1.15
diff -u -u -r1.15 Execute.java
--- Execute.java	2001/04/11 22:44:19	1.15
+++ Execute.java	2001/04/13 23:26:19
@@ -163,10 +163,29 @@
 
             BufferedReader in = 
                 new BufferedReader(new StringReader(out.toString()));
-            String line;
+            String var = null;
+            String line, lineSep = System.getProperty("line.separator");
             while ((line = in.readLine()) != null) {
-                procEnvironment.addElement(line);
+                if (line.indexOf('=') == -1) {
+                    // Chunk part of previous env var (UNIX env vars can
+                    // contain embedded new lines).
+                    if (var == null) {
+                        var = lineSep + line;
+                    }
+                    else {
+                        var += lineSep + line;
+                    }
+                }
+                else {
+                    // New env var...append the previous one if we have it.
+                    if (var != null) {
+                        procEnvironment.addElement(var);
+                    }
+                    var = line;
+                }
             }
+            // Since we "look ahead" before adding, there's one last env var.
+            procEnvironment.addElement(var);
         } 
         catch (java.io.IOException exc) {
             exc.printStackTrace();

Mime
View raw message