Browse Source

Make ZipFileSet resolve srcfile relative to project's basedir.

Submitted by:	Jesse Glick <Jesse.Glick@netbeans.com>


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268541 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 24 years ago
parent
commit
4fd9a820a0
4 changed files with 18 additions and 40 deletions
  1. +2
    -2
      src/main/org/apache/tools/ant/taskdefs/Zip.java
  2. +1
    -1
      src/main/org/apache/tools/ant/types/FileSet.java
  3. +12
    -34
      src/main/org/apache/tools/ant/types/ZipFileSet.java
  4. +3
    -3
      src/main/org/apache/tools/ant/types/ZipScanner.java

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

@@ -267,10 +267,10 @@ public class Zip extends MatchingTask {
throws IOException throws IOException
{ {
ZipScanner zipScanner = (ZipScanner) ds; ZipScanner zipScanner = (ZipScanner) ds;
String zipSrc = fs.getSrc();
File zipSrc = fs.getSrc();


ZipEntry entry; ZipEntry entry;
ZipInputStream in = new ZipInputStream(new FileInputStream(new File(zipSrc)));
ZipInputStream in = new ZipInputStream(new FileInputStream(zipSrc));
while ((entry = in.getNextEntry()) != null) { while ((entry = in.getNextEntry()) != null) {
String vPath = entry.getName(); String vPath = entry.getName();
if (zipScanner.match(vPath)) { if (zipScanner.match(vPath)) {


+ 1
- 1
src/main/org/apache/tools/ant/types/FileSet.java View File

@@ -260,7 +260,7 @@ public class FileSet extends DataType {
* Performs the check for circular references and returns the * Performs the check for circular references and returns the
* referenced FileSet. * referenced FileSet.
*/ */
private FileSet getRef(Project p) {
protected FileSet getRef(Project p) {
if (!checked) { if (!checked) {
Stack stk = new Stack(); Stack stk = new Stack();
stk.push(this); stk.push(this);


+ 12
- 34
src/main/org/apache/tools/ant/types/ZipFileSet.java View File

@@ -79,7 +79,7 @@ import org.apache.tools.ant.Project;
*/ */
public class ZipFileSet extends FileSet { public class ZipFileSet extends FileSet {


private String srcFileName = null;
private File srcFile = null;
private String prefix = ""; private String prefix = "";
private String fullpath = ""; private String fullpath = "";
private boolean hasDir = false; private boolean hasDir = false;
@@ -89,7 +89,7 @@ public class ZipFileSet extends FileSet {
* from being specified. * from being specified.
*/ */
public void setDir(File dir) throws BuildException { public void setDir(File dir) throws BuildException {
if (srcFileName != null) {
if (srcFile != null) {
throw new BuildException("Cannot set both dir and src attributes"); throw new BuildException("Cannot set both dir and src attributes");
} else { } else {
super.setDir(dir); super.setDir(dir);
@@ -98,16 +98,16 @@ public class ZipFileSet extends FileSet {
} }


/** /**
* Set the source Zip file for the zipfileset. Prevents both "dir" and "src"
* from being specified.
* Set the source Zip file for the zipfileset. Prevents both
* "dir" and "src" from being specified.
* *
* @param srcFileName The zip file from which to extract entries.
* @param srcFile The zip file from which to extract entries.
*/ */
public void setSrc(String srcFileName) {
public void setSrc(File srcFile) {
if (hasDir) { if (hasDir) {
throw new BuildException("Cannot set both dir and src attributes"); throw new BuildException("Cannot set both dir and src attributes");
} }
this.srcFileName = srcFileName;
this.srcFile = srcFile;
} }


/** /**
@@ -115,8 +115,8 @@ public class ZipFileSet extends FileSet {
* References are not followed, since it is not possible * References are not followed, since it is not possible
* to have a reference to a ZipFileSet, only to a FileSet. * to have a reference to a ZipFileSet, only to a FileSet.
*/ */
public String getSrc() {
return srcFileName;
public File getSrc() {
return srcFile;
} }


/** /**
@@ -162,12 +162,10 @@ public class ZipFileSet extends FileSet {
if (isReference()) { if (isReference()) {
return getRef(p).getDirectoryScanner(p); return getRef(p).getDirectoryScanner(p);
} }
if (srcFileName != null) {
if (srcFile != null) {
ZipScanner zs = new ZipScanner(); ZipScanner zs = new ZipScanner();
zs.setSrc(srcFileName);
if (getDir(p) == null) {
super.setDir(new File("."));
}
zs.setSrc(srcFile);
super.setDir(new File("."));
setupDirectoryScanner(zs, p); setupDirectoryScanner(zs, p);
zs.init(); zs.init();
return zs; return zs;
@@ -176,24 +174,4 @@ public class ZipFileSet extends FileSet {
} }
} }
/**
* Performs the check for circular references and returns the
* referenced FileSet.
*/
private FileSet getRef(Project p) {
if (!checked) {
Stack stk = new Stack();
stk.push(this);
dieOnCircularReference(stk, p);
}
Object o = ref.getReferencedObject(p);
if (!(o instanceof FileSet)) {
String msg = ref.getRefId()+" doesn\'t denote a fileset";
throw new BuildException(msg);
} else {
return (FileSet) o;
}
}
} }

+ 3
- 3
src/main/org/apache/tools/ant/types/ZipScanner.java View File

@@ -74,7 +74,7 @@ public class ZipScanner extends DirectoryScanner {
/** /**
* The zip file which should be scanned. * The zip file which should be scanned.
*/ */
protected String srcFile;
protected File srcFile;


/** /**
* Sets the srcFile for scanning. This is the jar or zip file that is scanned * Sets the srcFile for scanning. This is the jar or zip file that is scanned
@@ -82,7 +82,7 @@ public class ZipScanner extends DirectoryScanner {
* *
* @param srcFile the (non-null) zip file name for scanning * @param srcFile the (non-null) zip file name for scanning
*/ */
public void setSrc(String srcFile) {
public void setSrc(File srcFile) {
this.srcFile = srcFile; this.srcFile = srcFile;
} }


@@ -95,7 +95,7 @@ public class ZipScanner extends DirectoryScanner {
*/ */
public String[] getIncludedFiles() { public String[] getIncludedFiles() {
String[] result = new String[1]; String[] result = new String[1];
result[0] = srcFile;
result[0] = srcFile.getAbsolutePath();
return result; return result;
} }




Loading…
Cancel
Save