View Javadoc

1   package net.sf.jlayercheck.util;
2   
3   import java.io.File;
4   import java.io.FileInputStream;
5   import java.io.FileNotFoundException;
6   import java.io.IOException;
7   import java.util.Enumeration;
8   import java.util.zip.ZipEntry;
9   import java.util.zip.ZipFile;
10  
11  import org.objectweb.asm.ClassReader;
12  
13  /**
14   * Utility methods for calling the asm parser on a number of files.
15   * 
16   * @author webmaster@earth3d.org
17   */
18  public class DependencyParser {
19  
20      public static void callForFilesystem(final String[] args, DependencyVisitor v) throws IOException {
21  		File f = new File(args[0]);
22  
23          checkDirectory(v, f);
24  	}
25  
26  	protected static void checkDirectory(DependencyVisitor v, File f) throws IOException, FileNotFoundException {
27          File files[] = f.listFiles();
28          for(File file : files) {
29          	if (file.isDirectory()) {
30          		checkDirectory(v, file);
31          	} else {
32          		String name = file.getAbsolutePath();
33          		if (name.endsWith(".class")) {
34          			new ClassReader(new FileInputStream(file)).accept(v, 0);
35          		}
36          	}
37          }
38  	}
39  
40  	public static void callForZipFile(final String zipfilename, DependencyVisitor v) throws IOException {
41  		ZipFile f = new ZipFile(zipfilename);
42  
43          Enumeration< ? extends ZipEntry> en = f.entries();
44          while (en.hasMoreElements()) {
45              ZipEntry e = en.nextElement();
46              String name = e.getName();
47              if (name.endsWith(".class")) {
48                  new ClassReader(f.getInputStream(e)).accept(v, 0);
49              }
50          }
51  	}
52  }