Sorry. I found another bug in cab task (introduced in rev. 1.10) which broke it for both windows and non-windows platforms. The change from:
``if(!isWindows) {''
to:
``if(Os.isFamily("windows")) {''
reversed the meaning of the condition. This new patch should incorporate the fix for this problem as well.


Sorry for not catching the second problem earlier.
--
Ilya

P.S.:
Quesion to ``bodewig'': may anything else be broken because of this?

Ilya A. Kriveshko wrote:

Wait! Please, don't apply this patch yet. I'll send a new one in a few minutes.
---
Ilya


Ilya A. Kriveshko wrote:

Could someone qualified to make changes to CVS please apply the attached patch?


Index: Cab.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/Cab.java,v
retrieving revision 1.11
diff -u -r1.11 Cab.java
--- Cab.java    2001/11/02 16:36:49     1.11
+++ Cab.java    2001/11/15 19:45:57
@@ -64,11 +64,14 @@
 import org.apache.tools.ant.types.Commandline;
 import org.apache.tools.ant.util.FileUtils;
 
+import java.io.BufferedReader;
 import java.io.File;
-import java.io.IOException;
-import java.io.PrintWriter;
 import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
 import java.io.OutputStream;
+import java.io.PrintWriter;
 import java.util.Enumeration;
 
 import java.util.Vector;
@@ -289,8 +292,8 @@
 
         log("Building "+ archiveType +": "+ cabFile.getAbsolutePath());
 
-        // we must be on Windows to continue
-        if (Os.isFamily("windows")) {
+        // Use libcabinet on non-windows platforms
+        if (!Os.isFamily("windows")) {
             log("Using listcab/libcabinet", Project.MSG_VERBOSE);
             
             StringBuffer sb = new StringBuffer();
@@ -303,15 +306,48 @@
             sb.append("\n").append(cabFile.getAbsolutePath()).append("\n");
             
             try {
-                Process p = Runtime.getRuntime().exec("listcab");
+                Process p = Runtime.getRuntime().exec("listcab", null, 
baseDir);
                 OutputStream out = p.getOutputStream();
-                out.write(sb.toString().getBytes());
+               out.write(sb.toString().getBytes());
                 out.flush();
                 out.close();
+               AsyncStreamGobbler stdout = new 
AsyncStreamGobbler(p.getInputStream());
+               AsyncStreamGobbler stderr = new 
AsyncStreamGobbler(p.getErrorStream()); 
+               stdout.startGobbling();
+               stderr.startGobbling();
+               int result = -99;
+
+                // Wait for the end of output and error streams
+               try {
+                   result = p.waitFor();
+                   while(!stdout.isDone()) {
+                       Thread.currentThread().sleep(200);
+                   }
+                    while(!stderr.isDone()) {
+                       Thread.currentThread().sleep(200);
+                   }
+               } catch(InterruptedException ie) {
+                   log(ie.toString());
+               }
+
+                // Handle errors in listcab
+               if(result != 0) {
+                   log("Error executing listcab.");
+                   log("Error code: " + result);
+                   String output = stdout.getResult();
+                   String errors = stderr.getResult();
+                   if(output.length() > 0) {
+                       log("Output: \n" + output);
+                   }
+                   if(errors.length() > 0) {
+                       log("Errors: \n" + errors);
+                   }
+               }
+               
             } catch (IOException ex) {
                 String msg = "Problem creating " + cabFile + " " + 
ex.getMessage();
                 throw new BuildException(msg);
-            }
+           }
         } else {
             try {
                 File listFile = createListFile(files);
@@ -341,4 +377,41 @@
             }
         }
     }
+
+    private static class AsyncStreamGobbler implements Runnable {
+       public AsyncStreamGobbler(InputStream in) {
+           _in = in;
+       }
+       public void startGobbling() {
+           new Thread(this).start();
+       }
+       public synchronized String getResult() {
+           return _result.toString();
+       }
+       public void run() {
+           try {
+               _reader = new BufferedReader(new InputStreamReader(_in));
+               String line;
+               while((line = _reader.readLine()) != null) {
+                   synchronized(this) {
+                       _result.append(line + "\n");
+                   }
+               }
+               synchronized(this) {
+                   _done = true;
+               }
+           } catch(IOException e) {
+               _result.append("AsyncStreamGobbler exception: " + e);
+           }
+       }
+       public synchronized boolean isDone() {
+           return _done;
+       }
+
+       StringBuffer   _result = new StringBuffer();
+       BufferedReader _reader;
+       InputStream    _in;
+       boolean        _done = false;
+    }
+
 }

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to