KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonicsystems > jarjar > DepFind


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;
22
23 import com.tonicsystems.jarjar.util.*;
24 import java.io.*;
25 import java.util.*;
26 import java.util.zip.ZipEntry JavaDoc;
27 import org.objectweb.asm.ClassReader;
28 import org.objectweb.asm.ClassVisitor;
29
30 public class DepFind
31 {
32     private File curDir = new File(System.getProperty("user.dir"));
33
34     public void setCurrentDirectory(File curDir) {
35         this.curDir = curDir;
36     }
37
38     public void run(String JavaDoc from, String JavaDoc to, DepHandler handler) throws IOException {
39         try {
40             ClassHeaderReader header = new ClassHeaderReader();
41             Map classes = new HashMap();
42             ClassPathIterator cp = new ClassPathIterator(curDir, to);
43             while (cp.hasNext()) {
44                 Object JavaDoc cls = cp.next();
45                 header.read(cp.getInputStream(cls));
46                 classes.put(header.getClassName(), cp.getSource(cls));
47             }
48             cp.close();
49
50             handler.handleStart();
51             cp = new ClassPathIterator(curDir, from);
52             while (cp.hasNext()) {
53                 Object JavaDoc cls = cp.next();
54                 Object JavaDoc source = cp.getSource(cls);
55                 new ClassReader(cp.getInputStream(cls)).accept(new DepFindVisitor(classes, source, handler), true);
56             }
57             cp.close();
58             handler.handleEnd();
59         } catch (RuntimeIOException e) {
60             throw (IOException)e.getCause();
61         }
62     }
63 }
64
Popular Tags