Browse Source

Make <gunzip> really work with non-filesystem resources

master
Stefan Bodewig 9 years ago
parent
commit
7f0eeea180
3 changed files with 15 additions and 5 deletions
  1. +2
    -2
      src/main/org/apache/tools/ant/taskdefs/GUnzip.java
  2. +11
    -1
      src/main/org/apache/tools/ant/taskdefs/Unpack.java
  3. +2
    -2
      src/tests/antunit/taskdefs/gunzip-test.xml

+ 2
- 2
src/main/org/apache/tools/ant/taskdefs/GUnzip.java View File

@@ -52,8 +52,8 @@ public class GUnzip extends Unpack {
* Implement the gunzipping.
*/
protected void extract() {
if (source.lastModified() > dest.lastModified()) {
log("Expanding " + source.getAbsolutePath() + " to "
if (srcResource.getLastModified() > dest.lastModified()) {
log("Expanding " + srcResource.getName() + " to "
+ dest.getAbsolutePath());

FileOutputStream out = null;


+ 11
- 1
src/main/org/apache/tools/ant/taskdefs/Unpack.java View File

@@ -131,6 +131,10 @@ public abstract class Unpack extends Task {
}

if (dest == null) {
if (source == null) {
throw new BuildException("dest is required when using a non-filesystem source",
getLocation());
}
dest = new File(source.getParent());
}

@@ -141,7 +145,8 @@ public abstract class Unpack extends Task {
}

private void createDestFile(String defaultExtension) {
String sourceName = source.getName();
String sourceName = source == null
? getLastNamePart(srcResource) : source.getName();
int len = sourceName.length();
if (defaultExtension != null
&& len > defaultExtension.length()
@@ -192,4 +197,9 @@ public abstract class Unpack extends Task {
return false;
}

private String getLastNamePart(Resource r) {
String n = r.getName();
int idx = n.lastIndexOf("/");
return idx < 0 ? n : n.substring(idx + 1);
}
}

+ 2
- 2
src/tests/antunit/taskdefs/gunzip-test.xml View File

@@ -38,7 +38,7 @@
actual="${output}/asf-logo.gif"/>
</target>

<target name="XtestWithNonFileResourceToFile" depends="setup">
<target name="testWithNonFileResourceToFile" depends="setup">
<gunzip dest="${output}/greeting.txt">
<url url="http://ant.apache.org/webtest/gunzip/greeting.txt.gz"/>
</gunzip>
@@ -48,7 +48,7 @@
actual="${output}/greeting.txt"/>
</target>

<target name="XtestWithNonFileResourceToDir" depends="setup">
<target name="testWithNonFileResourceToDir" depends="setup">
<gunzip dest="${output}">
<url url="http://ant.apache.org/webtest/gunzip/greeting.txt.gz"/>
</gunzip>


Loading…
Cancel
Save