View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership. The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License. You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
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   * @author peter
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); // get the reference to Collection<Class>
67          } catch (ClassNotFoundException e){
68              e.printStackTrace(System.err);
69          } catch (IOException e) {
70              e.printStackTrace(System.err);
71          }
72  //	ClassDependParameters cdp = cdpBuilder.build();
73  //	Set result = classDepend.filterClassDependencyRelationShipMap(classDependencyRelationMap, cdp);
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  }