--- old/make/tools/classanalyzer/src/com/sun/classanalyzer/ShowDeps.java Wed Oct 20 09:31:01 2010 +++ new/make/tools/classanalyzer/src/com/sun/classanalyzer/ShowDeps.java Wed Oct 20 09:31:01 2010 @@ -22,8 +22,7 @@ */ package com.sun.classanalyzer; -import java.io.File; -import java.io.IOException; +import java.io.*; import java.util.*; /** @@ -32,9 +31,39 @@ * ignore references to classes listed in the file (including .classlists * created by the ClassAnalyzer tool). */ - public class ShowDeps { + private final ClassPaths cpaths; + private final Set classes = new TreeSet(); + + public ShowDeps(ClassPaths cpaths) { + this.cpaths = cpaths; + } + + public void run() throws IOException { + cpaths.parse(); + + // find the classes that don't exist + Set unresolved = new TreeSet(); + for (Klass k : Klass.getAllClasses()) { + if (k.getFileSize() == 0) { + unresolved.add(k); + } + } + + // print references to classes that don't exist + for (Klass k : Klass.getAllClasses()) { + for (Klass other : k.getReferencedClasses()) { + if (unresolved.contains(other)) { + String name = other.toString(); + if (!ignore.contains(name)) { + System.out.format("%s -> %s\n", k, other); + } + } + } + } + } + static void usage() { System.out.println("java ShowDeps [-ignore ] file..."); System.out.println(" where is a class or JAR file, or a directory"); @@ -43,14 +72,14 @@ System.out.println(" java ShowDeps Foo.jar"); System.out.println(" java ShowDeps -ignore base.classlist Foo.jar"); System.out.println(" java ShowDeps -ignore base.classlist -ignore " + - "jaxp-parsers.classlist "); + "jaxp-parsers.classlist "); System.exit(-1); } + private static Set ignore = new HashSet(); public static void main(String[] args) throws IOException { // process -ignore options int argi = 0; - Set ignore = new HashSet(); while (argi < args.length && args[argi].equals("-ignore")) { argi++; Scanner s = new Scanner(new File(args[argi++])); @@ -57,12 +86,13 @@ try { while (s.hasNextLine()) { String line = s.nextLine(); - if (!line.endsWith(".class")) + if (!line.endsWith(".class")) { continue; + } int len = line.length(); // convert to class names String clazz = line.replace('\\', '.').replace('/', '.') - .substring(0, len-6); + .substring(0, len - 6); ignore.add(clazz); } } finally { @@ -70,31 +100,13 @@ } } - if (argi >= args.length) + if (argi >= args.length) { usage(); - - // parse all classes - while (argi < args.length) - ClassPath.setClassPath(args[argi++]); - ClassPath.parseAllClassFiles(); - - // find the classes that don't exist - Set unresolved = new TreeSet(); - for (Klass k : Klass.getAllClasses()) { - if (k.getFileSize() == 0) - unresolved.add(k); } - // print references to classes that don't exist - for (Klass k: Klass.getAllClasses()) { - for (Klass other : k.getReferencedClasses()) { - if (unresolved.contains(other)) { - String name = other.toString(); - if (!ignore.contains(name)) { - System.out.format("%s -> %s\n", k, other); - } - } - } - } + // parse all classes + ClassPaths cpaths = new ClassPaths(Arrays.copyOfRange(args, argi, args.length)); + ShowDeps instance = new ShowDeps(cpaths); + instance.run(); } }