KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonicsystems > jarjar > util > AntJarProcessor


1 /*
2   Jar Jar Links - A utility to repackage and embed Java libraries
3   Copyright (C) 2004 Tonic Systems, Inc.
4
5   This program is free software; you can redistribute it and/or modify
6   it under the terms of the GNU General Public License as published by
7   the Free Software Foundation; either version 2 of the License, or
8   (at your option) any later version.
9
10   This program is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13   GNU General Public License for more details.
14
15   You should have received a copy of the GNU General Public License
16   along with this program; see the file COPYING. if not, write to
17   the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18   Boston, MA 02111-1307 USA
19 */

20
21 package com.tonicsystems.jarjar.util;
22
23 import com.tonicsystems.jarjar.util.*;
24 import java.io.File JavaDoc;
25 import java.io.IOException JavaDoc;
26 import java.io.InputStream JavaDoc;
27 import org.apache.tools.ant.BuildException;
28 import org.apache.tools.ant.taskdefs.Jar;
29 import org.apache.tools.zip.ZipOutputStream;
30
31 abstract public class AntJarProcessor extends Jar
32 {
33     private EntryStruct struct = new EntryStruct();
34     private JarProcessor proc;
35     protected boolean verbose;
36
37     abstract protected JarProcessor getJarProcessor();
38
39     public void setVerbose(boolean verbose) {
40         this.verbose = verbose;
41     }
42
43     public void execute() throws BuildException {
44         setFilesonly(true);
45         proc = getJarProcessor();
46         super.execute();
47     }
48
49     protected void zipDir(File JavaDoc dir, ZipOutputStream zOut, String JavaDoc vPath, int mode) throws IOException JavaDoc {
50         // ignore
51
}
52     
53     protected void zipFile(InputStream JavaDoc is, ZipOutputStream zOut, String JavaDoc vPath,
54                            long lastModified, File JavaDoc fromArchive, int mode) throws IOException JavaDoc {
55         struct.in = is;
56         struct.name = vPath;
57         struct.time = lastModified;
58         struct.file = fromArchive;
59         if (proc.process(struct))
60             super.zipFile(struct.in, zOut, struct.name, struct.time, struct.file, mode);
61     }
62
63     public void reset() {
64         super.reset();
65         cleanHelper();
66     }
67
68     protected void cleanUp() {
69         super.cleanUp();
70         cleanHelper();
71     }
72
73     protected void cleanHelper() {
74         verbose = false;
75     }
76 }
77
Popular Tags