1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.tonicsystems.jarjar;
18
19 import com.tonicsystems.jarjar.util.*;
20 import java.io.*;
21 import java.util.*;
22 import java.util.zip.ZipEntry;
23 import org.objectweb.asm.ClassReader;
24 import org.objectweb.asm.ClassVisitor;
25
26 public class DepFind
27 {
28 private File curDir = new File(System.getProperty("user.dir"));
29
30 public void setCurrentDirectory(File curDir) {
31 this.curDir = curDir;
32 }
33
34 public void run(String from, String to, DepHandler handler) throws IOException {
35 try {
36 ClassHeaderReader header = new ClassHeaderReader();
37 Map<String, String> classes = new HashMap<String, String>();
38 ClassPathIterator cp = new ClassPathIterator(curDir, to, null);
39 try {
40 while (cp.hasNext()) {
41 ClassPathEntry entry = cp.next();
42 InputStream in = entry.openStream();
43 try {
44 header.read(in);
45 classes.put(header.getClassName(), entry.getSource());
46 } catch (Exception e) {
47 System.err.println("Error reading " + entry.getName() + ": " + e.getMessage());
48 } finally {
49 in.close();
50 }
51 }
52 } finally {
53 cp.close();
54 }
55
56 handler.handleStart();
57 cp = new ClassPathIterator(curDir, from, null);
58 try {
59 while (cp.hasNext()) {
60 ClassPathEntry entry = cp.next();
61 InputStream in = entry.openStream();
62 try {
63 new ClassReader(in).accept(
64 new DepFindVisitor(classes, entry.getSource(), handler),
65 ClassReader.SKIP_DEBUG);
66 } catch (Exception e) {
67 System.err.println("Error reading " + entry.getName() + ": " + e.getMessage());
68 } finally {
69 in.close();
70 }
71 }
72 } finally {
73 cp.close();
74 }
75 handler.handleEnd();
76 } catch (RuntimeIOException e) {
77 throw (IOException)e.getCause();
78 }
79 }
80 }