1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.river.tool;
20
21 import org.apache.river.tool.classdepend.ClassDepend;
22 import org.apache.river.tool.classdepend.ClassDependParameters.CDPBuilder;
23 import org.apache.river.tool.classdepend.ClassDependencyRelationship;
24 import java.io.IOException;
25 import java.util.ArrayList;
26 import java.util.Iterator;
27 import java.util.List;
28 import java.util.Map;
29 import java.util.Set;
30 import java.util.TreeSet;
31
32
33
34
35
36 public class GenTrustedClasses {
37
38 public static void main(String[] args) {
39 String classpath = null;
40 List<String> providers = new ArrayList<String>();
41 ClassDepend classDepend;
42 CDPBuilder cdpBuilder = new CDPBuilder();
43 List<String> classes = new ArrayList<String>();
44 for (int i = 0, l = args.length; i < l; i++){
45 if ("-cp".equals(args[i])){
46 i++;
47 classpath = args[i];
48 } else if ("-prov".equals(args[i])){
49 i++;
50 providers.add(args[i]);
51 } else if ("-in".equals(args[i])){
52 i++;
53 cdpBuilder.addInsidePackage(args[i]);
54 } else {
55 classes.add(args[i]);
56 }
57 }
58 try {
59 classDepend = ClassDepend.newInstance(classpath, null, true);
60 } catch (IOException ex) {
61 ex.printStackTrace(System.err);
62 return;
63 }
64 Map classDependencyRelationMap = null;
65 try{
66 classDependencyRelationMap = classDepend.getDependencyRelationshipMap(classes, true);
67 } catch (ClassNotFoundException e){
68 e.printStackTrace(System.err);
69 } catch (IOException e) {
70 e.printStackTrace(System.err);
71 }
72
73
74 List classDependencyRelations = new ArrayList(providers.size());
75 Iterator it = providers.iterator();
76 while (it.hasNext()){
77 classDependencyRelations.add(classDependencyRelationMap.get(it.next()));
78 }
79 Set<String> classNames = new TreeSet<String>();
80 it = classDependencyRelations.iterator();
81 while (it.hasNext()){
82 ClassDependencyRelationship cdrs = (ClassDependencyRelationship) it.next();
83 Set dependants = cdrs.getDependants();
84 Iterator i = dependants.iterator();
85 while (i.hasNext()){
86 classNames.add(i.next().toString());
87 }
88 }
89 it = classNames.iterator();
90 while (it.hasNext()){
91 System.out.println(it.next());
92 }
93 }
94
95 }