Browse Source

Make <cab> support libcabinet on non-Windows platforms.

Submitted by:	Nico Seessle <Nico.Seessle@epost.de>


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268154 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 25 years ago
parent
commit
66d9c99493
2 changed files with 50 additions and 31 deletions
  1. +3
    -0
      WHATSNEW
  2. +47
    -31
      src/main/org/apache/tools/ant/taskdefs/optional/Cab.java

+ 3
- 0
WHATSNEW View File

@@ -19,6 +19,9 @@ Other changes:
given. If the doclet does not accept the -d flag then omit the destdir
attribute.

* <cab> can work on non-Windows platforms with the help of libcabinet.
See http://trill.cis.fordham.edu/~barbacha/cabinet_library/.

Fixed bugs:
-----------



+ 47
- 31
src/main/org/apache/tools/ant/taskdefs/optional/Cab.java View File

@@ -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);
}
}
}

Loading…
Cancel
Save