git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@794198 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -48,6 +48,7 @@ import org.apache.tools.ant.Project; | |||
| import org.apache.tools.ant.taskdefs.Manifest.Section; | |||
| import org.apache.tools.ant.types.EnumeratedAttribute; | |||
| import org.apache.tools.ant.types.Path; | |||
| import org.apache.tools.ant.types.Resource; | |||
| import org.apache.tools.ant.types.ResourceCollection; | |||
| import org.apache.tools.ant.types.ZipFileSet; | |||
| import org.apache.tools.ant.types.spi.Service; | |||
| @@ -532,7 +533,7 @@ public class Jar extends Zip { | |||
| Project.MSG_WARN); | |||
| } | |||
| zipDir(null, zOut, "META-INF/", ZipFileSet.DEFAULT_DIR_MODE, | |||
| zipDir((Resource) null, zOut, "META-INF/", ZipFileSet.DEFAULT_DIR_MODE, | |||
| JAR_MARKER); | |||
| // time to write the manifest | |||
| ByteArrayOutputStream baos = new ByteArrayOutputStream(); | |||
| @@ -49,6 +49,8 @@ import org.apache.tools.ant.types.ZipFileSet; | |||
| import org.apache.tools.ant.types.ZipScanner; | |||
| import org.apache.tools.ant.types.resources.ArchiveResource; | |||
| import org.apache.tools.ant.types.resources.FileProvider; | |||
| import org.apache.tools.ant.types.resources.FileResource; | |||
| import org.apache.tools.ant.types.resources.ZipResource; | |||
| import org.apache.tools.ant.util.FileNameMapper; | |||
| import org.apache.tools.ant.util.FileUtils; | |||
| import org.apache.tools.ant.util.GlobPatternMapper; | |||
| @@ -950,7 +952,9 @@ public class Zip extends MatchingTask { | |||
| addParentDirs(base, name.substring(0, nextToLastSlash + 1), | |||
| zOut, prefix, defaultDirMode); | |||
| } | |||
| addParentDirs(base, name, zOut, prefix, thisDirMode); | |||
| zipDir(r, zOut, prefix + name, thisDirMode, | |||
| r instanceof ZipResource | |||
| ? ((ZipResource) r).getExtraFields() : null); | |||
| } | |||
| /** | |||
| @@ -1551,7 +1555,7 @@ public class Zip extends MatchingTask { | |||
| /** | |||
| * Add a directory to the zip stream. | |||
| * @param dir the directort to add to the archive | |||
| * @param dir the directory to add to the archive | |||
| * @param zOut the stream to write to | |||
| * @param vPath the name this entry shall have in the archive | |||
| * @param mode the Unix permissions to set. | |||
| @@ -1562,6 +1566,23 @@ public class Zip extends MatchingTask { | |||
| protected void zipDir(File dir, ZipOutputStream zOut, String vPath, | |||
| int mode, ZipExtraField[] extra) | |||
| throws IOException { | |||
| zipDir(dir == null ? (Resource) null : new FileResource(dir), | |||
| zOut, vPath, mode, extra); | |||
| } | |||
| /** | |||
| * Add a directory to the zip stream. | |||
| * @param dir the directory to add to the archive | |||
| * @param zOut the stream to write to | |||
| * @param vPath the name this entry shall have in the archive | |||
| * @param mode the Unix permissions to set. | |||
| * @param extra ZipExtraFields to add | |||
| * @throws IOException on error | |||
| * @since Ant 1.8.0 | |||
| */ | |||
| protected void zipDir(Resource dir, ZipOutputStream zOut, String vPath, | |||
| int mode, ZipExtraField[] extra) | |||
| throws IOException { | |||
| if (doFilesonly) { | |||
| logOnFirstPass("skipping directory " + vPath | |||
| + " for file-only archive", | |||
| @@ -1579,13 +1600,14 @@ public class Zip extends MatchingTask { | |||
| if (!skipWriting) { | |||
| ZipEntry ze = new ZipEntry (vPath); | |||
| if (dir != null && dir.exists()) { | |||
| // ZIPs store time with a granularity of 2 seconds, round up | |||
| ze.setTime(dir.lastModified() + (roundUp ? ROUNDUP_MILLIS : 0)); | |||
| // ZIPs store time with a granularity of 2 seconds, round up | |||
| int millisToAdd = roundUp ? ROUNDUP_MILLIS : 0; | |||
| if (dir != null && dir.isExists()) { | |||
| ze.setTime(dir.getLastModified() + millisToAdd); | |||
| } else { | |||
| // ZIPs store time with a granularity of 2 seconds, round up | |||
| ze.setTime(System.currentTimeMillis() | |||
| + (roundUp ? ROUNDUP_MILLIS : 0)); | |||
| ze.setTime(System.currentTimeMillis() + millisToAdd); | |||
| } | |||
| ze.setSize (0); | |||
| ze.setMethod (ZipEntry.STORED); | |||
| @@ -31,6 +31,7 @@ import org.apache.tools.ant.types.Reference; | |||
| import org.apache.tools.ant.util.FileUtils; | |||
| import org.apache.tools.zip.ZipFile; | |||
| import org.apache.tools.zip.ZipEntry; | |||
| import org.apache.tools.zip.ZipExtraField; | |||
| /** | |||
| * A Resource representation of an entry in a zipfile. | |||
| @@ -39,6 +40,7 @@ import org.apache.tools.zip.ZipEntry; | |||
| public class ZipResource extends ArchiveResource { | |||
| private String encoding; | |||
| private ZipExtraField[] extras; | |||
| /** | |||
| * Default constructor. | |||
| @@ -165,6 +167,18 @@ public class ZipResource extends ArchiveResource { | |||
| "Use the zip task for zip output."); | |||
| } | |||
| /** | |||
| * Retrieves extra fields. | |||
| * @return an array of the extra fields | |||
| * @since Ant 1.8.0 | |||
| */ | |||
| public ZipExtraField[] getExtraFields() { | |||
| if (extras == null) { | |||
| return new ZipExtraField[0]; | |||
| } | |||
| return extras; | |||
| } | |||
| /** | |||
| * fetches information from the named entry inside the archive. | |||
| */ | |||
| @@ -198,6 +212,7 @@ public class ZipResource extends ArchiveResource { | |||
| setDirectory(e.isDirectory()); | |||
| setSize(e.getSize()); | |||
| setMode(e.getUnixMode()); | |||
| extras = e.getExtraFields(); | |||
| } | |||
| } | |||
| @@ -86,8 +86,9 @@ | |||
| <fileset dir="${input}/build"/> | |||
| <fileset dir="${input}/src" excludes="**/*.java"/> | |||
| </jar> | |||
| <au:assertDestIsUptodate src="${output}/jar.jar" | |||
| <au:assertDestIsOutofdate src="${output}/jar.jar" | |||
| dest="${output}/reference.jar"/> | |||
| <copy file="${output}/jar.jar" tofile="${output}/reference.jar"/> | |||
| <sleep seconds="1"/> | |||
| <jar jarfile="${output}/jar.jar"> | |||
| @@ -104,4 +105,21 @@ | |||
| <au:assertDestIsUptodate src="${output}/jar.jar" | |||
| dest="${output}/reference.jar"/> | |||
| </target> | |||
| <target name="testNewEmptyDirUpdatesArchive"> | |||
| <mkdir dir="${input}"/> | |||
| <touch file="${input}/x"/> | |||
| <mkdir dir="${output}"/> | |||
| <jar jarfile="${output}/jar.jar"> | |||
| <fileset dir="${input}"/> | |||
| </jar> | |||
| <copy file="${output}/jar.jar" tofile="${output}/reference.jar"/> | |||
| <mkdir dir="${input}/y"/> | |||
| <jar jarfile="${output}/jar.jar"> | |||
| <fileset dir="${input}"/> | |||
| </jar> | |||
| <au:assertDestIsOutofdate src="${output}/jar.jar" | |||
| dest="${output}/reference.jar"/> | |||
| </target> | |||
| </project> | |||