-
Notifications
You must be signed in to change notification settings - Fork 0
/
PackageLister.java
56 lines (48 loc) · 1.42 KB
/
PackageLister.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import java.io.File;
import java.io.IOException;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.zip.*;
public class PackageLister
{
private static void populateSet(File jar, Set packages) throws IOException
{
ZipFile zipFile = new ZipFile(jar);
for(Enumeration e = zipFile.entries(); e.hasMoreElements();)
{
ZipEntry entry = (ZipEntry) e.nextElement();
String path = entry.getName();
if(path.endsWith(".class"))
{
String parentPath = new File(path).getParent();
packages.add(parentPath);
}
}
}
public static void main(String[] args)
{
try
{
HashSet packages = new HashSet();
for(int i = 0; i < args.length; i++)
{
String arg=args[i];
File jar = new File(arg);
populateSet(jar, packages);
}
for(Iterator i = packages.iterator(); i.hasNext();)
{
String pkg = (String) i.next();
System.out.print("+" + pkg.replaceAll("/",".") + " ");
}
System.out.println();
}
catch(IOException e)
{
System.err.println(e);
System.exit(1);
}
}
}