/*
  Jar Jar Links - A utility to repackage and embed Java libraries
  Copyright (C) 2004  Tonic Systems, Inc.

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; see the file COPYING.  if not, write to
  the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  Boston, MA 02111-1307 USA
*/

package com.tonicsystems.jarjar;

import java.io.*;
import java.util.*;
import java.util.zip.ZipEntry;
import org.objectweb.asm.ClassAdapter;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import net.sf.cglib.core.TypeUtils;
import net.sf.cglib.transform.NullClassVisitor;

public class DepFind
{
    public static void main(String[] args)
    throws Exception
    {
        try {
            new DepFind(args);
        } catch (WrappedIOException e) {
            throw (IOException)e.getCause();
        }
    }

    private DepFind(String[] args)
    throws Exception
    {
        if (args.length != 2) {
            System.err.println("Syntax: java com.tonicsystems.jarjar.DepFind <find-classpath> <source-classpath>");
            System.exit(1);
        }

        final Set names = new HashSet();
        ClassVisitor gatherNamesVisitor = new NullClassVisitor() {
            public void visit(int access, String name, String superName, String[] interfaces, String sourceFile) {
                names.add(name);
            }
        };

        File curDir = new File(System.getProperty("user.dir"));

        ClassPathIterator cp = new ClassPathIterator(curDir, args[0]);
        while (cp.hasNext()) {
            new ClassReader(cp.getInputStream(cp.next())).accept(gatherNamesVisitor, true);
        }
        
        DepFindVisitor depFind = new DepFindVisitor(names);
        cp = new ClassPathIterator(curDir, args[1]);
        while (cp.hasNext()) {
            try {
                new ClassReader(cp.getInputStream(cp.next())).accept(depFind, true);
            } catch (DepFindException e) {
                System.out.println(e.getClassName()); //  e.getDependency()
            }
        }
    }
}

@@ -2065,32 +2065,117 @@
 cp.hasNext()) %7B%0A
+            Object cls = cp.next();%0A            // System.err.println(%22d0: %22 + cls);%0A
             new 
@@ -2201,32 +2201,26 @@
 nputStream(c
-p.next()
+ls
 )).accept(ga
@@ -2417,32 +2417,125 @@
           try %7B%0A
+                Object cls = cp.next();%0A                // System.err.println(%22d1: %22 + cls);%0A
                 
@@ -2569,24 +2569,18 @@
 Stream(c
-p.next()
+ls
 )).accep
@@ -2695,14 +2695,22 @@
 me()
-); // 
+ + %22%5Ct =%3E  %22 +
  e.g
@@ -2723,16 +2723,18 @@
 ndency()
+);
 %0A       

add debugging, print class which causes dependency