Author: bodewig
Date: Thu Feb 18 13:21:37 2010
New Revision: 911387
URL: http://svn.apache.org/viewvc?rev=911387&view=rev
Log:
support different formats and block sizes in CPIO
Modified:
ant/antlibs/compress/trunk/docs/archive.html
ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Cpio.java
ant/antlibs/compress/trunk/src/tests/antunit/uncpio-test.xml
Modified: ant/antlibs/compress/trunk/docs/archive.html
URL:
http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/docs/archive.html?rev=911387&r1=911386&r2=911387&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/docs/archive.html (original)
+++ ant/antlibs/compress/trunk/docs/archive.html Thu Feb 18 13:21:37 2010
@@ -232,6 +232,29 @@
<p>An <a href="#archive">archiving task</a> creating archives of the
CPIO format.</p>
+ <p>This task supports the following additional attributes:</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">CPIO format for the archive to create. One of
+ "binary", "old-ascii", "new-ascii"<!-- or "crc"-->. "odc" can be
+ used as a synonym for "old-ascii".</td>
+ <td valign="top" align="center">No, default is "binary"</td>
+ </tr>
+ <tr>
+ <td valign="top">blocksize</td>
+ <td valign="top">Block size for the archive. Must be a
+ positive number.</td>
+ <td valign="top" align="center">No, default is 512.</td>
+ </tr>
+ </table>
+
<h3><a name="tar">Tar</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/Cpio.java
URL:
http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Cpio.java?rev=911387&r1=911386&r2=911387&view=diff
==============================================================================
---
ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Cpio.java
(original)
+++
ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Cpio.java
Thu Feb 18 13:21:37 2010
@@ -18,25 +18,43 @@
package org.apache.ant.compress.taskdefs;
+import java.io.IOException;
+import java.io.OutputStream;
import org.apache.ant.compress.util.CpioStreamFactory;
import org.apache.ant.compress.resources.CpioFileSet;
import org.apache.commons.compress.archivers.ArchiveEntry;
+import org.apache.commons.compress.archivers.ArchiveOutputStream;
import org.apache.commons.compress.archivers.cpio.CpioArchiveEntry;
+import org.apache.commons.compress.archivers.cpio.CpioArchiveOutputStream;
+import org.apache.commons.compress.archivers.cpio.CpioConstants;
+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;
/**
* Creates cpio archives.
*/
public class Cpio extends ArchiveBase {
+ private Format format = Format.BINARY;
+ private int blockSize = CpioConstants.BLOCK_SIZE;
+
public Cpio() {
- setFactory(new CpioStreamFactory());
+ setFactory(new CpioStreamFactory() {
+ public ArchiveOutputStream getArchiveStream(OutputStream
stream,
+ String encoding)
+ throws IOException {
+ return new CpioArchiveOutputStream(stream,
+ format.getFormat(),
+ blockSize);
+ }
+ });
setEntryBuilder(
new ArchiveBase.EntryBuilder() {
public ArchiveEntry buildEntry(ArchiveBase.ResourceWithFlags
r) {
boolean isDir = r.getResource().isDirectory();
CpioArchiveEntry ent =
- new CpioArchiveEntry(r.getName(),
+ new CpioArchiveEntry(format.getFormat(), r.getName(),
isDir
? 0 : r.getResource().getSize());
ent.setTime(round(r.getResource().getLastModified(), 1000)
@@ -80,4 +98,72 @@
});
}
+ /**
+ * The format to use.
+ * <p>Default is binary</b>
+ */
+ public void setFormat(Format f) {
+ format = f;
+ }
+
+ /**
+ * The blocksize to use.
+ * <p>Default is 512 bytes.</p>
+ */
+ public void setBlockSize(int size) {
+ if (size <= 0) {
+ throw new BuildException("Block size must be a positive number");
+ }
+ blockSize = size;
+ }
+
+ /**
+ * The supported cpio formats.
+ */
+ public static class Format extends EnumeratedAttribute {
+ private static final String BINARY_NAME = "binary";
+ private static final String OLD_ASCII_NAME = "old-ascii";
+ private static final String ODC_NAME = "odc";
+ private static final String NEW_ASCII_NAME = "new-ascii";
+ private static final String CRC_NAME = "crc";
+
+ public static final Format BINARY = new Format(BINARY_NAME);
+ public static final Format OLD_ASCII = new Format(OLD_ASCII_NAME);
+ public static final Format ODC = new Format(ODC_NAME);
+ public static final Format NEW_ASCII = new Format(NEW_ASCII_NAME);
+ //public static final Format CRC = new Format(CRC_NAME);
+
+ public Format(String v) {
+ setValue(v);
+ }
+
+ public Format() {
+ setValue(BINARY_NAME);
+ }
+
+ public String[] getValues() {
+ return new String[] {
+ BINARY_NAME, OLD_ASCII_NAME, ODC_NAME, NEW_ASCII_NAME,
//CRC_NAME
+ };
+ }
+
+ public short getFormat() {
+ String v = getValue();
+ if (v.equals(OLD_ASCII_NAME) || v.equals(ODC_NAME)) {
+ return CpioConstants.FORMAT_OLD_ASCII;
+ }
+ if (v.equals(NEW_ASCII_NAME)) {
+ return CpioConstants.FORMAT_NEW;
+ }
+ if (v.equals(CRC_NAME)) {
+ return CpioConstants.FORMAT_NEW_CRC;
+ }
+ return CpioConstants.FORMAT_OLD_BINARY;
+ }
+
+ public boolean equals(Object other) {
+ return other instanceof Format
+ && ((Format) other).getFormat() == getFormat();
+ }
+ }
}
\ No newline at end of file
Modified: ant/antlibs/compress/trunk/src/tests/antunit/uncpio-test.xml
URL:
http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/tests/antunit/uncpio-test.xml?rev=911387&r1=911386&r2=911387&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/src/tests/antunit/uncpio-test.xml (original)
+++ ant/antlibs/compress/trunk/src/tests/antunit/uncpio-test.xml Thu Feb 18
13:21:37 2010
@@ -26,7 +26,7 @@
<mkdir dir="${input}"/>
</target>
- <target name="testAgainstAntlibCpioTask" depends="setUp">
+ <target name="testAgainstAntlibCpioTaskBinary" depends="setUp">
<cmp:cpio destfile="${input}/test.cpio">
<fileset dir="."/>
</cmp:cpio>
@@ -38,6 +38,42 @@
/>
</target>
+ <target name="testAgainstAntlibCpioTaskOldAscii" depends="setUp">
+ <cmp:cpio destfile="${input}/test.cpio" format="odc">
+ <fileset dir="."/>
+ </cmp:cpio>
+ <cmp:uncpio src="${input}/test.cpio" dest="${output}"/>
+ <au:assertFileExists file="${output}/uncpio-test.xml"/>
+ <au:assertFilesMatch
+ actual="${output}/uncpio-test.xml"
+ expected="uncpio-test.xml"
+ />
+ </target>
+
+ <target name="testAgainstAntlibCpioTaskNewAscii" depends="setUp">
+ <cmp:cpio destfile="${input}/test.cpio" format="new-ascii">
+ <fileset dir="."/>
+ </cmp:cpio>
+ <cmp:uncpio src="${input}/test.cpio" dest="${output}"/>
+ <au:assertFileExists file="${output}/uncpio-test.xml"/>
+ <au:assertFilesMatch
+ actual="${output}/uncpio-test.xml"
+ expected="uncpio-test.xml"
+ />
+ </target>
+
+ <!--target name="testAgainstAntlibCpioTaskCRC" depends="setUp">
+ <cmp:cpio destfile="${input}/test.cpio" format="crc">
+ <fileset dir="."/>
+ </cmp:cpio>
+ <cmp:uncpio src="${input}/test.cpio" dest="${output}"/>
+ <au:assertFileExists file="${output}/uncpio-test.xml"/>
+ <au:assertFilesMatch
+ actual="${output}/uncpio-test.xml"
+ expected="uncpio-test.xml"
+ />
+ </target-->
+
<target name="testAgainstNativeCpio" depends="setUp">
<cmp:uncpio src="../resources/asf-logo.gif.cpio" dest="${output}" />
<au:assertFileExists file="${output}/asf-logo.gif"/>