You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by bo...@apache.org on 2003/07/03 17:43:10 UTC
cvs commit: ant/src/main/org/apache/tools/ant/types ZipFileSet.java ZipScanner.java
bodewig 2003/07/03 08:43:09
Modified: src/main/org/apache/tools/ant/taskdefs Zip.java
src/main/org/apache/tools/ant/types ZipFileSet.java
ZipScanner.java
Log:
Base <zip> and <zipfileset> on new ZipFile code.
This happens mainly for two reasons:
* preserve stored permissions unless the user explicitly overrides them
(PR 2130). This is now fixed for stored files, but not for directories.
* deal with filename encoding of existing archives. Supposed to work
properly now.
Revision Changes Path
1.108 +14 -6 ant/src/main/org/apache/tools/ant/taskdefs/Zip.java
Index: Zip.java
===================================================================
RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Zip.java,v
retrieving revision 1.107
retrieving revision 1.108
diff -u -r1.107 -r1.108
--- Zip.java 25 Jun 2003 11:52:46 -0000 1.107
+++ Zip.java 3 Jul 2003 15:43:09 -0000 1.108
@@ -66,7 +66,6 @@
import java.util.Stack;
import java.util.Vector;
import java.util.zip.CRC32;
-import java.util.zip.ZipFile;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
@@ -85,6 +84,7 @@
import org.apache.tools.ant.util.MergingMapper;
import org.apache.tools.ant.util.ResourceUtils;
import org.apache.tools.zip.ZipEntry;
+import org.apache.tools.zip.ZipFile;
import org.apache.tools.zip.ZipOutputStream;
/**
@@ -362,6 +362,7 @@
log("Adding file " + files[j] + " to fileset",
Project.MSG_VERBOSE);
ZipFileSet zf = new ZipFileSet();
+ zf.setProject(getProject());
zf.setSrc(new File(basedir, files[j]));
filesets.addElement(zf);
filesetsFromGroupfilesets.addElement(zf);
@@ -439,6 +440,7 @@
if (doUpdate) {
addingNewFiles = false;
ZipFileSet oldFiles = new ZipFileSet();
+ oldFiles.setProject(getProject());
oldFiles.setSrc(renamedFile);
for (int i = 0; i < addedFiles.size(); i++) {
@@ -447,6 +449,7 @@
}
DirectoryScanner ds =
oldFiles.getDirectoryScanner(getProject());
+ ((ZipScanner) ds).setEncoding(encoding);
String[] f = ds.getIncludedFiles();
Resource[] r = new Resource[f.length];
for (int i = 0; i < f.length; i++) {
@@ -575,7 +578,7 @@
dealingWithFiles = true;
base = fileset.getDir(getProject());
} else {
- zf = new ZipFile(zfs.getSrc(getProject()));
+ zf = new ZipFile(zfs.getSrc(getProject()), encoding);
}
for (int i = 0; i < resources.length; i++) {
@@ -595,17 +598,18 @@
}
addParentDirs(base, name, zOut, prefix, dirMode);
-
+
if (!resources[i].isDirectory() && dealingWithFiles) {
File f = fileUtils.resolveFile(base,
resources[i].getName());
zipFile(f, zOut, prefix + name, fileMode);
} else if (!resources[i].isDirectory()) {
- java.util.zip.ZipEntry ze =
- zf.getEntry(resources[i].getName());
+ ZipEntry ze = zf.getEntry(resources[i].getName());
if (ze != null) {
zipFile(zf.getInputStream(ze), zOut, prefix + name,
- ze.getTime(), zfs.getSrc(getProject()), fileMode);
+ ze.getTime(), zfs.getSrc(getProject()),
+ zfs.hasFileModeBeenSet() ? fileMode
+ : ze.getUnixMode());
}
}
}
@@ -673,6 +677,7 @@
private synchronized ZipScanner getZipScanner() {
if (zs == null) {
zs = new ZipScanner();
+ zs.setEncoding(encoding);
zs.setSrc(zipFile);
}
return zs;
@@ -849,6 +854,9 @@
for (int i = 0; i < filesets.length; i++) {
DirectoryScanner rs =
filesets[i].getDirectoryScanner(getProject());
+ if (rs instanceof ZipScanner) {
+ ((ZipScanner) rs).setEncoding(encoding);
+ }
Vector resources = new Vector();
String[] directories = rs.getIncludedDirectories();
for (int j = 0; j < directories.length; j++) {
1.21 +35 -4 ant/src/main/org/apache/tools/ant/types/ZipFileSet.java
Index: ZipFileSet.java
===================================================================
RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/types/ZipFileSet.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- ZipFileSet.java 27 May 2003 09:30:17 -0000 1.20
+++ ZipFileSet.java 3 Jul 2003 15:43:09 -0000 1.21
@@ -98,6 +98,9 @@
private int fileMode = DEFAULT_FILE_MODE;
private int dirMode = DEFAULT_DIR_MODE;
+ private boolean fileModeHasBeenSet = false;
+ private boolean dirModeHasBeenSet = false;
+
public ZipFileSet() {
super();
}
@@ -114,6 +117,8 @@
hasDir = fileset.hasDir;
fileMode = fileset.fileMode;
dirMode = fileset.dirMode;
+ fileModeHasBeenSet = fileset.fileModeHasBeenSet;
+ dirModeHasBeenSet = fileset.dirModeHasBeenSet;
}
/**
@@ -243,7 +248,8 @@
public void setFileMode(String octalString) {
if (isReference()) {
throw tooManyAttributes();
- }
+ }
+ fileModeHasBeenSet = true;
this.fileMode =
UnixStat.FILE_FLAG | Integer.parseInt(octalString, 8);
}
@@ -259,28 +265,53 @@
}
/**
+ * Whether the user has specified the mode explicitly.
+ *
+ * @since Ant 1.6
+ */
+ public boolean hasFileModeBeenSet() {
+ if (isReference()) {
+ return ((ZipFileSet)getRef(getProject())).hasFileModeBeenSet();
+ }
+ return fileModeHasBeenSet;
+ }
+
+ /**
* A 3 digit octal string, specify the user, group and
* other modes in the standard Unix fashion;
* optional, default=0755
*
- * @since Ant 1.6
+ * @since Ant 1.5.2
*/
public void setDirMode(String octalString) {
if (isReference()) {
throw tooManyAttributes();
- }
+ }
+ dirModeHasBeenSet = true;
this.dirMode =
UnixStat.DIR_FLAG | Integer.parseInt(octalString, 8);
}
/**
- * @since Ant 1.6
+ * @since Ant 1.5.2
*/
public int getDirMode(Project p) {
if (isReference()) {
return ((ZipFileSet)getRef(p)).getDirMode(p);
}
return dirMode;
+ }
+
+ /**
+ * Whether the user has specified the mode explicitly.
+ *
+ * @since Ant 1.6
+ */
+ public boolean hasDirModeBeenSet() {
+ if (isReference()) {
+ return ((ZipFileSet)getRef(getProject())).hasDirModeBeenSet();
+ }
+ return dirModeHasBeenSet;
}
/**
1.19 +31 -23 ant/src/main/org/apache/tools/ant/types/ZipScanner.java
Index: ZipScanner.java
===================================================================
RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/types/ZipScanner.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- ZipScanner.java 18 Apr 2003 23:40:28 -0000 1.18
+++ ZipScanner.java 3 Jul 2003 15:43:09 -0000 1.19
@@ -60,12 +60,12 @@
import java.util.Vector;
import java.util.Hashtable;
import java.util.Enumeration;
-import java.util.zip.ZipInputStream;
-import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
+import org.apache.tools.zip.ZipEntry;
+import org.apache.tools.zip.ZipFile;
/**
* ZipScanner accesses the pattern matching algorithm in DirectoryScanner,
@@ -93,6 +93,13 @@
private Hashtable myentries;
/**
+ * encoding of file names.
+ *
+ * @since Ant 1.6
+ */
+ private String encoding;
+
+ /**
* Sets the srcFile for scanning. This is the jar or zip file that
* is scanned for matching entries.
*
@@ -103,6 +110,15 @@
}
/**
+ * Sets encoding of file names.
+ *
+ * @since Ant 1.6
+ */
+ public void setEncoding(String encoding) {
+ this.encoding = encoding;
+ }
+
+ /**
* Returns the names of the files which matched at least one of the
* include patterns and none of the exclude patterns.
* The names are relative to the base directory.
@@ -230,37 +246,29 @@
}
ZipEntry entry = null;
- ZipInputStream in = null;
+ ZipFile zf = null;
myentries = new Hashtable();
try {
try {
- in = new ZipInputStream(new FileInputStream(srcFile));
+ zf = new ZipFile(srcFile, encoding);
+ } catch (ZipException ex) {
+ throw new BuildException("problem reading " + srcFile, ex);
} catch (IOException ex) {
throw new BuildException("problem opening " + srcFile, ex);
}
- while (true) {
- try {
- entry = in.getNextEntry();
- if (entry == null) {
- break;
- }
- myentries.put(new String(entry.getName()),
- new Resource(entry.getName(), true,
- entry.getTime(),
- entry.isDirectory()));
- } catch (ZipException ex) {
- throw new BuildException("problem reading " + srcFile,
- ex);
- } catch (IOException e) {
- throw new BuildException("problem reading zip entry from "
- + srcFile, e);
- }
+ Enumeration enum = zf.getEntries();
+ while (enum.hasMoreElements()) {
+ entry = (ZipEntry) enum.nextElement();
+ myentries.put(new String(entry.getName()),
+ new Resource(entry.getName(), true,
+ entry.getTime(),
+ entry.isDirectory()));
}
} finally {
- if (in != null) {
+ if (zf != null) {
try {
- in.close();
+ zf.close();
} catch (IOException ex) {
// swallow
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org