Submitted by: Stefan Bodewig <stefan.bodewig@megabit.net> git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@267671 13f79535-47bb-0310-9956-ffa450edef68master
@@ -453,6 +453,7 @@ but excludes all "*.gif" files from the copy.</p> | |||
<li><a href="#expand">Expand</a></li> | |||
<li><a href="#filter">Filter</a></li> | |||
<li><a href="#get">Get</a></li> | |||
<li><a href="#gunzip">GUnzip</a></li> | |||
<li><a href="#gzip">GZip</a></li> | |||
<li><a href="#fixcrlf">FixCRLF</a></li> | |||
<li><a href="#jar">Jar</a></li> | |||
@@ -468,6 +469,7 @@ but excludes all "*.gif" files from the copy.</p> | |||
<li><a href="#tar">Tar</a></li> | |||
<li><a href="#taskdef">Taskdef</a></li> | |||
<li><a href="#tstamp">Tstamp</a></li> | |||
<li><a href="#untar">Untar</a></li> | |||
<li><a href="#zip">Zip</a></li> | |||
</ul> | |||
<hr> | |||
@@ -942,6 +944,50 @@ archive with http/ftp.</p> | |||
<h3>Examples</h3> | |||
<pre> <get src="http://jakarta.apache.org/" dest="help/index.html" /></pre> | |||
<p>gets the index page of http://jakarta.apache.org/, and stores it in the file <code>help/index.html</code>.</p> | |||
<hr> | |||
<h2><a name="gunzip">GUnzip</a></h2> | |||
<h3>Description</h3> | |||
<p>Expands a GZip file.</p> | |||
<p>If <i>dest</i> is a directory the name of the destination file is | |||
the same as <i>src</i> (with the ".gz" extension removed if | |||
present). If <i>dest</i> is ommited, the parent dir of <i>src</i> is | |||
taken. The file is only expanded if the source file is newer than the | |||
destination file, or when the destination file does not exist.</p> | |||
<h3>Parameters</h3> | |||
<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">src</td> | |||
<td valign="top">the file to expand.</td> | |||
<td align="center" valign="top">Yes</td> | |||
</tr> | |||
<tr> | |||
<td valign="top">dest</td> | |||
<td valign="top">the destination file or directory.</td> | |||
<td align="center" valign="top">No</td> | |||
</tr> | |||
</table> | |||
<h3>Examples</h3> | |||
<blockquote> | |||
<p><code><gunzip src="test.tar.gz"/></code></p> | |||
</blockquote> | |||
<p>expands <i>test.tar.gz</i> to <i>test.tar</i></p> | |||
<blockquote> | |||
<p><code><gunzip src="test.tar.gz" dest="test2.tar"/></code></p> | |||
</blockquote> | |||
<p>expands <i>test.tar.gz</i> to <i>test2.tar</i></p> | |||
<blockquote> | |||
<p><code><gunzip src="test.tar.gz" dest="subdir"/></code></p> | |||
</blockquote> | |||
<p>expands <i>test.tar.gz</i> to <i>subdir/test.tar</i> (assuming | |||
subdir is a directory).</p> | |||
<hr> | |||
<h2><a name="gzip">GZip</a></h2> | |||
<h3>Description</h3> | |||
@@ -2002,6 +2048,35 @@ initialization target.</p> | |||
<h3>Examples</h3> | |||
<pre> <tstamp/></pre> | |||
<hr> | |||
<h2><a name="untar">Untar</a></h2> | |||
<h3>Description</h3> | |||
<p>Untars a tarfile.</p> | |||
<h3>Parameters</h3> | |||
<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">src</td> | |||
<td valign="top">tarfile to expand.</td> | |||
<td align="center" valign="top">Yes</td> | |||
</tr> | |||
<tr> | |||
<td valign="top">dest</td> | |||
<td valign="top">directory where to store the expanded files.</td> | |||
<td align="center" valign="top">Yes</td> | |||
</tr> | |||
</table> | |||
<h3>Examples</h3> | |||
<blockquote> | |||
<p><code> | |||
<gunzip src="tools.tar.gz"/><br> | |||
<untar src="tools.tar" dest="${tools.home}"/> | |||
</code></p> | |||
</blockquote> | |||
<hr> | |||
<h2><a name="zip">Zip</a></h2> | |||
<h3>Description</h3> | |||
<p>Creates a zipfile.</p> | |||
@@ -0,0 +1,132 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 1999 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.tools.ant.taskdefs; | |||
import org.apache.tools.ant.*; | |||
import java.io.*; | |||
import java.util.zip.*; | |||
/** | |||
* Expands a file that has been compressed with the GZIP | |||
* algorightm. Normally used to compress non-compressed archives such | |||
* as TAR files. | |||
* | |||
* @author Stefan Bodewig <a href="mailto:stefan.bodewig@megabit.net">stefan.bodewig@megabit.net</a> | |||
*/ | |||
public class GUnzip extends Task { | |||
private File source; | |||
private File dest; | |||
public void setSrc(String src) { | |||
source = project.resolveFile(src); | |||
} | |||
public void setDest(String dest) { | |||
this.dest = project.resolveFile(dest); | |||
} | |||
public void execute() throws BuildException { | |||
if (source == null) { | |||
throw new BuildException("No source specified"); | |||
} | |||
if (!source.exists()) { | |||
throw new BuildException("source doesn't exist"); | |||
} | |||
if (source.isDirectory()) { | |||
throw new BuildException("Cannot expand a directory"); | |||
} | |||
if (dest == null) { | |||
dest = new File(source.getParent()); | |||
} | |||
if (dest.isDirectory()) { | |||
String sourceName = source.getName(); | |||
int len = sourceName.length(); | |||
if (len > 3 | |||
&& ".gz".equalsIgnoreCase(sourceName.substring(len-3))) { | |||
dest = new File(dest, sourceName.substring(0, len-3)); | |||
} else { | |||
dest = new File(dest, sourceName); | |||
} | |||
} | |||
if (source.lastModified() > dest.lastModified()) { | |||
project.log("Expanding "+ source.getAbsolutePath() + " to " | |||
+ dest.getAbsolutePath()); | |||
try { | |||
FileOutputStream out = new FileOutputStream(dest); | |||
GZIPInputStream zIn = new GZIPInputStream(new FileInputStream(source)); | |||
byte[] buffer = new byte[8 * 1024]; | |||
int count = 0; | |||
do { | |||
out.write(buffer, 0, count); | |||
count = zIn.read(buffer, 0, buffer.length); | |||
} while (count != -1); | |||
zIn.close(); | |||
out.close(); | |||
} catch (IOException ioe) { | |||
String msg = "Problem expanding gzip " + ioe.getMessage(); | |||
throw new BuildException(msg, ioe); | |||
} | |||
} | |||
} | |||
} |
@@ -0,0 +1,145 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 1999 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
* modification, are permitted provided that the following conditions | |||
* are met: | |||
* | |||
* 1. Redistributions of source code must retain the above copyright | |||
* notice, this list of conditions and the following disclaimer. | |||
* | |||
* 2. Redistributions in binary form must reproduce the above copyright | |||
* notice, this list of conditions and the following disclaimer in | |||
* the documentation and/or other materials provided with the | |||
* distribution. | |||
* | |||
* 3. The end-user documentation included with the redistribution, if | |||
* any, must include the following acknowlegement: | |||
* "This product includes software developed by the | |||
* Apache Software Foundation (http://www.apache.org/)." | |||
* Alternately, this acknowlegement may appear in the software itself, | |||
* if and wherever such third-party acknowlegements normally appear. | |||
* | |||
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software | |||
* Foundation" must not be used to endorse or promote products derived | |||
* from this software without prior written permission. For written | |||
* permission, please contact apache@apache.org. | |||
* | |||
* 5. Products derived from this software may not be called "Apache" | |||
* nor may "Apache" appear in their names without prior written | |||
* permission of the Apache Group. | |||
* | |||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
* SUCH DAMAGE. | |||
* ==================================================================== | |||
* | |||
* This software consists of voluntary contributions made by many | |||
* individuals on behalf of the Apache Software Foundation. For more | |||
* information on the Apache Software Foundation, please see | |||
* <http://www.apache.org/>. | |||
*/ | |||
package org.apache.tools.ant.taskdefs; | |||
import org.apache.tools.ant.*; | |||
import org.apache.tools.tar.*; | |||
import java.io.*; | |||
/** | |||
* Untar a file. | |||
* | |||
* Heavily based on the Expand task. | |||
* | |||
* @author Stefan Bodewig <a href="mailto:stefan.bodewig@megabit.net">stefan.bodewig@megabit.net</a> | |||
*/ | |||
public class Untar extends Task { | |||
private String dest; // req | |||
private String source; // req | |||
/** | |||
* Do the work. | |||
* | |||
* @exception BuildException Thrown in unrecoverable error. | |||
*/ | |||
public void execute() throws BuildException { | |||
try { | |||
if (source == null) { | |||
throw new BuildException("No source specified"); | |||
} | |||
File srcF=project.resolveFile(source); | |||
if (!srcF.exists()) { | |||
throw new BuildException("source doesn't exist"); | |||
} | |||
if (dest == null) { | |||
throw new BuildException("No destination specified"); | |||
} | |||
File dir=project.resolveFile(dest); | |||
project.log("Expanding: " + srcF + " into " + dir, Project.MSG_INFO); | |||
// code from WarExpand | |||
TarInputStream tis = new TarInputStream(new FileInputStream(srcF)); | |||
TarEntry te = null; | |||
while ((te = tis.getNextEntry()) != null) { | |||
try { | |||
File f = new File(dir, project.translatePath(te.getName())); | |||
project.log("expand-file " + te.getName() , "untar", Project.MSG_VERBOSE ); | |||
// create intermediary directories - sometimes tar don't add them | |||
File dirF=new File(f.getParent()); | |||
dirF.mkdirs(); | |||
if (te.isDirectory()) { | |||
f.mkdirs(); | |||
} else { | |||
byte[] buffer = new byte[1024]; | |||
int length = 0; | |||
FileOutputStream fos = new FileOutputStream(f); | |||
while ((length = tis.read(buffer)) >= 0) { | |||
fos.write(buffer, 0, length); | |||
} | |||
fos.close(); | |||
} | |||
} catch( FileNotFoundException ex ) { | |||
System.out.println("FileNotFoundException: " + te.getName() ); | |||
} | |||
} | |||
} catch (IOException ioe) { | |||
throw new BuildException(ioe); | |||
} | |||
} | |||
/** | |||
* Set the destination directory. File will be untared into the | |||
* destination directory. | |||
* | |||
* @param d Path to the directory. | |||
*/ | |||
public void setDest(String d) { | |||
this.dest=d; | |||
} | |||
/** | |||
* Set the path to tar-file. | |||
* | |||
* @param s Path to tar-file. | |||
*/ | |||
public void setSrc(String s) { | |||
this.source = s; | |||
} | |||
} |
@@ -15,6 +15,7 @@ echo=org.apache.tools.ant.taskdefs.Echo | |||
javadoc=org.apache.tools.ant.taskdefs.Javadoc | |||
zip=org.apache.tools.ant.taskdefs.Zip | |||
gzip=org.apache.tools.ant.taskdefs.GZip | |||
gunzip=org.apache.tools.ant.taskdefs.GUnzip | |||
replace=org.apache.tools.ant.taskdefs.Replace | |||
java=org.apache.tools.ant.taskdefs.Java | |||
tstamp=org.apache.tools.ant.taskdefs.Tstamp | |||
@@ -23,6 +24,7 @@ taskdef=org.apache.tools.ant.taskdefs.Taskdef | |||
ant=org.apache.tools.ant.taskdefs.Ant | |||
exec=org.apache.tools.ant.taskdefs.Exec | |||
tar=org.apache.tools.ant.taskdefs.Tar | |||
untar=org.apache.tools.ant.taskdefs.Untar | |||
available=org.apache.tools.ant.taskdefs.Available | |||
filter=org.apache.tools.ant.taskdefs.Filter | |||
fixcrlf=org.apache.tools.ant.taskdefs.FixCRLF | |||