conor 01/02/13 05:03:41
Modified: src/main/org/apache/tools/ant/taskdefs Tag: ANT_13_BRANCH
Tar.java
Log:
Make Tar task support OMIT option and truncate too.
Revision Changes Path
No revision
No revision
1.10.2.4 +45 -11
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Tar.java
Index: Tar.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Tar.java,v
retrieving revision 1.10.2.3
retrieving revision 1.10.2.4
diff -u -r1.10.2.3 -r1.10.2.4
--- Tar.java 2001/02/13 12:34:20 1.10.2.3
+++ Tar.java 2001/02/13 13:03:41 1.10.2.4
@@ -75,7 +75,10 @@
static public final String FAIL = "fail";
static public final String TRUNCATE = "truncate";
static public final String GNU = "gnu";
+ static public final String OMIT = "omit";
+ private String[] validModes = new String[] {WARN, FAIL, TRUNCATE, GNU,
OMIT};
+
File tarFile;
File baseDir;
@@ -83,6 +86,11 @@
Vector filesets = new Vector();
Vector fileSetFiles = new Vector();
+
+ /**
+ * Indicates whether the user has been warned about long files already.
+ */
+ private boolean longWarningGiven = false;
public TarFileSet createTarFileSet() {
TarFileSet fileset = new TarFileSet();
@@ -109,13 +117,20 @@
* Set how to handle long files.
*
* Allowable values are
- * truncate
- * fail
- * warn
- * gnu
+ * truncate - paths are truncated to the maximum length
+ * fail - patsh greater than the maximim cause a build exception
+ * warn - paths greater than the maximum cause a warning and GNU is
used
+ * gnu - GNU extensions are used for any paths greater than the
maximum.
+ * omit - paths greater than the maximum are omitted from the archive
*/
public void setLongfile(String mode) {
- this.longFileMode = mode;
+ for (int i = 0; i < validModes.length; ++i) {
+ if (mode.equalsIgnoreCase(validModes[i])) {
+ this.longFileMode = mode;
+ return;
+ }
+ }
+ throw new BuildException("The longfile value " + mode + " is not a
valid value");
}
public void execute() throws BuildException {
@@ -145,7 +160,12 @@
mainFileSet.setDefaultexcludes(useDefaultExcludes);
filesets.addElement(mainFileSet);
}
-
+
+ if (filesets.size() == 0) {
+ throw new BuildException("You must supply either a basdir
attribute or some nested filesets.",
+ location);
+ }
+
// check if tr is out of date with respect to each
// fileset
boolean upToDate = true;
@@ -171,8 +191,19 @@
try {
tOut = new TarOutputStream(new FileOutputStream(tarFile));
tOut.setDebug(true);
- tOut.setLongFileMode(TarOutputStream.LONGFILE_GNU);
+ if (longFileMode.equalsIgnoreCase(TRUNCATE)) {
+ tOut.setLongFileMode(TarOutputStream.LONGFILE_TRUNCATE);
+ }
+ else if (longFileMode.equalsIgnoreCase(FAIL) ||
+ longFileMode.equalsIgnoreCase(OMIT)) {
+ tOut.setLongFileMode(TarOutputStream.LONGFILE_ERROR);
+ }
+ else {
+ // warn or GNU
+ tOut.setLongFileMode(TarOutputStream.LONGFILE_GNU);
+ }
+ longWarningGiven = false;
for (Enumeration e = filesets.elements(); e.hasMoreElements();) {
TarFileSet fs = (TarFileSet)e.nextElement();
String[] files = fs.getFiles(project);
@@ -204,14 +235,17 @@
try {
if (vPath.length() >= TarConstants.NAMELEN) {
- if (longFileMode.equalsIgnoreCase(TRUNCATE)) {
- log("Skipping: "+ vPath, Project.MSG_INFO);
+ if (longFileMode.equalsIgnoreCase(OMIT)) {
+ log("Omitting: "+ vPath, Project.MSG_INFO);
return;
} else if (longFileMode.equalsIgnoreCase(WARN)) {
log("Entry: "+ vPath + " longer than " +
TarConstants.NAMELEN + " characters.",
Project.MSG_WARN);
- log("Resulting tar file can only be processed
successfully"
- + " by GNU compatible tar commands",
Project.MSG_WARN);
+ if (!longWarningGiven) {
+ log("Resulting tar file can only be processed
successfully"
+ + " by GNU compatible tar commands",
Project.MSG_WARN);
+ longWarningGiven = true;
+ }
} else if (longFileMode.equalsIgnoreCase(FAIL)) {
throw new BuildException(
"Entry: "+ vPath + " longer than " +