tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Conor MacNeill" <co...@m64.com>
Subject RE: omission of items attribute in jar taskdef (ant)
Date Tue, 07 Dec 1999 14:43:38 GMT
>
> Take a look at the Zip taskdef and rip my code out of there. I
> was going to
> do this for the Jar one, but was going to wait until I had more
> time to deal
> with it in the proper way...which is to make a more generic file utility
> class instead of having all this duplicated code in each taskdef.
>
> -jon
>
>

Actually I have just changed the Jar class to extend Zip. I made most of the
methods in Zip protected and added an initZipOutputStream. In Zip this is
just implemented as

    protected void initZipOutputStream(ZipOutputStream zOut)
	throws IOException, BuildException
    {
	zOut.setMethod(ZipOutputStream.DEFLATED);
    }

but in Jar it is implemented as

    protected void initZipOutputStream(ZipOutputStream zOut)
	throws IOException, BuildException
    {
	zOut.setMethod(ZipOutputStream.DEFLATED);

	// add manifest first
	if (manifest != null) {
	    ZipEntry ze = new ZipEntry("META-INF/");
	    zOut.putNextEntry(ze);
	    zipFile(manifest, zOut, "META-INF/MANIFEST.MF");
	} else {
	    ZipEntry ze = new ZipEntry("META-INF/");
	    zOut.putNextEntry(ze);
	    String s = "/org/apache/tools/ant/defaultManifest.mf";
	    InputStream in = this.getClass().getResourceAsStream(s);
            if ( in == null )
		throw new BuildException ( "Could not find: " + s );
	    else
		zipFile(in, zOut, "META-INF/MANIFEST.MF");
	}
    }

Most of the methods in Jar disappear. I noticed that zipDir does not create
the directory entries whereas the Jar equivalent, jarDir, did. I have
preserved this behaviour by overriding zipDir in Jar. I'm not sure if this
difference is required, but if not then Jar.java could become even smaller.

I'd provide you with diffs but CVS appears to be down at the moment

Cheers

--
Conor MacNeill
conor@m64.com
M64 Pty Limited



Mime
View raw message