From 24964c3232d4684d7a0c346a141a2048ef75ebc0 Mon Sep 17 00:00:00 2001
From: Stefan Bodewig
Date: Fri, 4 Aug 2000 06:53:13 +0000
Subject: [PATCH] Removed JDK 1.2+ dependency from task. Submitted by:
Roger Vaughn
git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@267883 13f79535-47bb-0310-9956-ffa450edef68
---
build.xml | 1 -
docs/index.html | 63 ++++++++++++++++++-
.../tools/ant/taskdefs/optional/Cab.java | 40 ++++++++++--
3 files changed, 95 insertions(+), 9 deletions(-)
diff --git a/build.xml b/build.xml
index 91a274564..79fb8ddc2 100644
--- a/build.xml
+++ b/build.xml
@@ -83,7 +83,6 @@
-
diff --git a/docs/index.html b/docs/index.html
index eb4a62bce..c0e88e7e2 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -3356,11 +3356,68 @@ directory.
the cabarc tool. should not normally be necessary.
No |
+
+ includes |
+ comma separated list of patterns of files that
+ must be included. All files are included when omitted. |
+ No |
+
+
+ includesfile |
+ the name of a file. Each line of this file is
+ taken to be an include pattern |
+ No |
+
+
+ excludes |
+ comma separated list of patterns of files that
+ must be excluded. No files (except default excludes) are excluded
+ when omitted. |
+ No |
+
+
+ excludesfile |
+ the name of a file. Each line of this file is
+ taken to be an exclude pattern |
+ No |
+
+
+ defaultexcludes |
+ indicates whether default excludes should be used
+ or not ("yes"/"no"). Default excludes are used when omitted. |
+ No |
+
Examples
-
- None yet available
-
+
+<cab cabfile="${dist}/manual.cab"
+ basedir="htdocs/manual"
+ />
+
+cabs all files in the htdocs/manual directory in a file called
+manual.cab in the ${dist} directory.
+
+<cab cabfile="${dist}/manual.cab"
+ basedir="htdocs/manual"
+ excludes="mydocs/**, **/todo.html"
+ />
+
+cabs all files in the htdocs/manual directory in a file called
+manual.cab in the ${dist} directory. Files in the directory mydocs,
+or files with the name todo.html are excluded.
+
+<cab cabfile="${dist}/manual.cab"
+ basedir="htdocs/manual"
+ includes="api/**/*.html"
+ excludes="**/todo.html"
+ verbose="yes"
+ />
+
+cab all files in the htdocs/manual directory in a file called
+manual.cab in the ${dist} directory. Only html files under the
+directory api are archived, and files with the name todo.html are
+excluded. Output from the cabarc tool is displayed in the build
+output.
Description:
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 1d6ded673..908323774 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/Cab.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/Cab.java
@@ -62,6 +62,8 @@ import java.io.*;
import java.util.Enumeration;
import java.util.StringTokenizer;
import java.util.Vector;
+import java.util.Random;
+import java.text.DecimalFormat;
/**
* Create a CAB archive.
@@ -93,7 +95,7 @@ public class Cab extends MatchingTask {
* create the .cab file.
*/
public void setCabfile(File cabFile) {
- cabFile = cabFile;
+ this.cabFile = cabFile;
}
/**
@@ -215,6 +217,27 @@ public class Cab extends MatchingTask {
return command;
}
+ private static int counter = new Random().nextInt() % 100000;
+ protected File createTempFile(String prefix, String suffix)
+ {
+ if (suffix == null)
+ {
+ suffix = ".tmp";
+ }
+
+ String name = prefix +
+ new DecimalFormat("#####").format(new Integer(counter++)) +
+ suffix;
+
+ String tmpdir = System.getProperty("java.io.tmpdir");
+
+ // java.io.tmpdir is not present in 1.1
+ if (tmpdir == null)
+ return new File(name);
+ else
+ return new File(tmpdir, name);
+ }
+
/**
* Creates a list file. This temporary file contains a list of all files
* to be included in the cab, one file per line.
@@ -222,8 +245,8 @@ public class Cab extends MatchingTask {
protected File createListFile(Vector files)
throws IOException
{
- File listFile = File.createTempFile("ant", null);
- listFile.deleteOnExit();
+ File listFile = createTempFile("ant", null);
+
PrintWriter writer = new PrintWriter(new FileOutputStream(listFile));
for (int i = 0; i < files.size(); i++)
@@ -327,6 +350,7 @@ public class Cab extends MatchingTask {
try {
File listFile = createListFile(files);
ExecTask exec = createExec();
+ File outFile = null;
// die if cabarc fails
exec.setFailonerror(true);
@@ -334,13 +358,19 @@ public class Cab extends MatchingTask {
if (!doVerbose)
{
- File outFile = File.createTempFile("ant", null);
- outFile.deleteOnExit();
+ 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);