Author: bodewig
Date: Mon Aug 8 13:34:46 2011
New Revision: 1154959
URL: http://svn.apache.org/viewvc?rev=1154959&view=rev
Log:
support for the BSD dialect of AR
Modified:
ant/antlibs/compress/trunk/changes.xml
ant/antlibs/compress/trunk/docs/archive.html
ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Ar.java
ant/antlibs/compress/trunk/src/tests/antunit/ar-test.xml
Modified: ant/antlibs/compress/trunk/changes.xml
URL:
http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/changes.xml?rev=1154959&r1=1154958&r2=1154959&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/changes.xml (original)
+++ ant/antlibs/compress/trunk/changes.xml Mon Aug 8 13:34:46 2011
@@ -42,6 +42,11 @@
The Apache Compress Antlib now requires Apache Commons
Compress 1.3 which in turn requires Java5 at runtime.
</action>
+ <action type="update">
+ The <ar> task now optionally suppports writing entries
+ with names longer than 16 characters using the BSD variant of
+ AR archives.
+ </action>
<action type="add">
The unarchiving tasks and fileset types share a new attribute
skipUnreadableEntries that can be used to ignore archive
Modified: ant/antlibs/compress/trunk/docs/archive.html
URL:
http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/docs/archive.html?rev=1154959&r1=1154958&r2=1154959&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/docs/archive.html (original)
+++ ant/antlibs/compress/trunk/docs/archive.html Mon Aug 8 13:34:46 2011
@@ -222,11 +222,27 @@
<p>An <a href="#archive">archiving task</a> creating archives of the
AR format.</p>
- <p>The AR format is pretty limited, it can only store file names up
+ <p>The AR format is pretty limited, by default it can only store file names
up
to 16 characters and not store directories at all. It is not
possible to set the <code>filesonly</code> attribute to true for
the <code>ar</code> task.</p>
+ <table border="1" cellpadding="2" cellspacing="0">
+ <tr>
+ <td valign="top"><b>Attribute</b></td>
+ <td valign="top"><b>Description</b></td>
+ <td align="center" valign="top"><b>Required</b></td>
+ </tr>
+ <tr>
+ <td valign="top">format</td>
+ <td valign="top">Ar format for entries with names longer than
+ 16 characters. Supported values are "ar" which doesn't
+ support entries of that length and results in a build failure
+ and "bsd".</td>
+ <td valign="top" align="center">No, default is "ar"</td>
+ </tr>
+ </table>
+
<h3><a name="cpio">Cpio</a></h3>
<p>An <a href="#archive">archiving task</a> creating archives of the
Modified:
ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Ar.java
URL:
http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Ar.java?rev=1154959&r1=1154958&r2=1154959&view=diff
==============================================================================
---
ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Ar.java
(original)
+++
ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Ar.java
Mon Aug 8 13:34:46 2011
@@ -18,12 +18,17 @@
package org.apache.ant.compress.taskdefs;
-import org.apache.ant.compress.util.ArStreamFactory;
+import java.io.IOException;
+import java.io.OutputStream;
import org.apache.ant.compress.resources.ArFileSet;
+import org.apache.ant.compress.util.ArStreamFactory;
import org.apache.commons.compress.archivers.ArchiveEntry;
+import org.apache.commons.compress.archivers.ArchiveOutputStream;
import org.apache.commons.compress.archivers.ar.ArArchiveEntry;
+import org.apache.commons.compress.archivers.ar.ArArchiveOutputStream;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.types.ArchiveFileSet;
+import org.apache.tools.ant.types.EnumeratedAttribute;
import org.apache.tools.ant.types.Resource;
/**
@@ -34,8 +39,22 @@ public class Ar extends ArchiveBase {
private static final String NO_DIRS_MESSAGE = "ar archives cannot store"
+ " directory entries";
+ private Format format = Format.AR;
+
public Ar() {
- setFactory(new ArStreamFactory());
+ setFactory(new ArStreamFactory() {
+ public ArchiveOutputStream getArchiveStream(OutputStream
stream,
+ String encoding)
+ throws IOException {
+ ArArchiveOutputStream o =
+ (ArArchiveOutputStream) super.getArchiveStream(stream,
+
encoding);
+ if (format.equals(Format.BSD)) {
+ o.setLongFileMode(ArArchiveOutputStream.LONGFILE_BSD);
+ }
+ return o;
+ }
+ });
setEntryBuilder(
new ArchiveBase.EntryBuilder() {
public ArchiveEntry buildEntry(ArchiveBase.ResourceWithFlags
r) {
@@ -85,4 +104,43 @@ public class Ar extends ArchiveBase {
throw new BuildException(NO_DIRS_MESSAGE);
}
}
+
+ /**
+ * The format for entries with filenames longer than 16 characters
+ * or containign spaces - any other entry will always use "ar".
+ *
+ * @since Apache Compress Antlib 1.1
+ */
+ public void setFormat(Format f) {
+ format = f;
+ }
+
+ /**
+ * The supported tar formats for entries with long file names.
+ */
+ public final static class Format extends EnumeratedAttribute {
+ private static final String AR_NAME = "ar";
+ private static final String BSD_NAME = "bsd";
+
+ public static final Format AR = new Format(AR_NAME);
+ public static final Format BSD = new Format(BSD_NAME);
+
+ public Format(String v) {
+ setValue(v);
+ }
+
+ public Format() {
+ setValue(AR_NAME);
+ }
+
+ public String[] getValues() {
+ return new String[] {AR_NAME, BSD_NAME};
+ }
+
+ public boolean equals(Object other) {
+ return other instanceof Format
+ && ((Format) other).getValue().equals(getValue());
+ }
+ }
+
}
\ No newline at end of file
Modified: ant/antlibs/compress/trunk/src/tests/antunit/ar-test.xml
URL:
http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/tests/antunit/ar-test.xml?rev=1154959&r1=1154958&r2=1154959&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/src/tests/antunit/ar-test.xml (original)
+++ ant/antlibs/compress/trunk/src/tests/antunit/ar-test.xml Mon Aug 8
13:34:46 2011
@@ -539,4 +539,26 @@
</cond:islastmodified>
</au:assertFalse>
</target>
+
+ <target name="testLongNameException" depends="setUp">
+ <touch file="${input}/this-is-a-long-name-for-ar.txt"/>
+ <au:expectfailure>
+ <cmp:ar dest="${dest}">
+ <fileset dir="${input}"/>
+ </cmp:ar>
+ </au:expectfailure>
+ </target>
+
+
+ <target name="testLongNameBSD" depends="setUp">
+ <touch file="${input}/this-is-a-long-name-for-ar.txt"/>
+ <cmp:ar dest="${dest}" format="bsd">
+ <fileset dir="${input}"/>
+ </cmp:ar>
+ <assertResourceExists>
+ <cmp:arentry name="this-is-a-long-name-for-ar.txt">
+ <file file="${dest}"/>
+ </cmp:arentry>
+ </assertResourceExists>
+ </target>
</project>