diff --git a/WHATSNEW b/WHATSNEW index dc8eca047..d7e758105 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -19,6 +19,9 @@ Other changes: given. If the doclet does not accept the -d flag then omit the destdir attribute. +* can work on non-Windows platforms with the help of libcabinet. + See http://trill.cis.fordham.edu/~barbacha/cabinet_library/. + Fixed bugs: ----------- diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/Cab.java b/src/main/org/apache/tools/ant/taskdefs/optional/Cab.java index 8de2d301c..f5e9971b2 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/Cab.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/Cab.java @@ -295,50 +295,66 @@ public class Cab extends MatchingTask { } public void execute() throws BuildException { - // we must be on Windows to continue - if (!isWindows) - { - log("cannot run on non-Windows platforms: " + myos, - Project.MSG_VERBOSE); - return; - } - + checkConfiguration(); Vector files = getFileList(); - + // quick exit if the target is up to date if (isUpToDate(files)) return; log("Building "+ archiveType +": "+ cabFile.getAbsolutePath()); - try { - File listFile = createListFile(files); - ExecTask exec = createExec(); - File outFile = null; + // we must be on Windows to continue + if (!isWindows) { + log("Using listcab/libcabinet", Project.MSG_VERBOSE); - // die if cabarc fails - exec.setFailonerror(true); - exec.setDir(baseDir); + StringBuffer sb = new StringBuffer(); - if (!doVerbose) - { - outFile = createTempFile("ant", null); - exec.setOutput(outFile); + Enumeration fileEnum = files.elements(); + + while (fileEnum.hasMoreElements()) { + sb.append(fileEnum.nextElement()).append("\n"); } + sb.append("\n").append(cabFile.getAbsolutePath()).append("\n"); + + try { + Process p = Runtime.getRuntime().exec("listcab"); + OutputStream out = p.getOutputStream(); + out.write(sb.toString().getBytes()); + out.flush(); + out.close(); + } catch (IOException ex) { + String msg = "Problem creating " + cabFile + " " + ex.getMessage(); + throw new BuildException(msg); + } + } else { + try { + File listFile = createListFile(files); + ExecTask exec = createExec(); + File outFile = null; - exec.setCommand(createCommand(listFile)); - exec.execute(); - - if (outFile != null) - { - outFile.delete(); + // die if cabarc fails + exec.setFailonerror(true); + exec.setDir(baseDir); + + if (!doVerbose) { + outFile = createTempFile("ant", null); + exec.setOutput(outFile); + } + + exec.setCommand(createCommand(listFile)); + exec.execute(); + + if (outFile != null) { + outFile.delete(); + } + + listFile.delete(); + } catch (IOException ioe) { + String msg = "Problem creating " + cabFile + " " + ioe.getMessage(); + throw new BuildException(msg); } - - listFile.delete(); - } catch (IOException ioe) { - String msg = "Problem creating " + cabFile + " " + ioe.getMessage(); - throw new BuildException(msg); } } }