source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/src/main/org/apache/tools/ant/util/depend/bcel/FullAnalyzer.java@ 14627

Last change on this file since 14627 was 14627, checked in by oranfry, 17 years ago

initial import of the gs3-release-maker

File size: 4.7 KB
Line 
1/*
2 * Copyright 2002,2004 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17package org.apache.tools.ant.util.depend.bcel;
18import java.io.File;
19import java.io.IOException;
20import java.util.Enumeration;
21import java.util.Hashtable;
22import java.util.Vector;
23import org.apache.bcel.classfile.ClassParser;
24import org.apache.bcel.classfile.DescendingVisitor;
25import org.apache.bcel.classfile.JavaClass;
26import org.apache.tools.ant.util.depend.AbstractAnalyzer;
27
28/**
29 * An analyzer capable fo traversing all class - class relationships.
30 *
31 */
32public class FullAnalyzer extends AbstractAnalyzer {
33 /**
34 * Default constructor
35 *
36 * Causes the BCEL classes to load to ensure BCEL dependencies can
37 * be satisfied
38 */
39 public FullAnalyzer() {
40 // force BCEL classes to load now
41 try {
42 new ClassParser("force");
43 } catch (IOException e) {
44 // ignore
45 }
46 }
47
48 /**
49 * Determine the dependencies of the configured root classes.
50 *
51 * @param files a vector to be populated with the files which contain
52 * the dependency classes
53 * @param classes a vector to be populated with the names of the
54 * depencency classes.
55 */
56 protected void determineDependencies(Vector files, Vector classes) {
57 // we get the root classes and build up a set of
58 // classes upon which they depend
59 Hashtable dependencies = new Hashtable();
60 Hashtable containers = new Hashtable();
61 Hashtable toAnalyze = new Hashtable();
62 for (Enumeration e = getRootClasses(); e.hasMoreElements();) {
63 String classname = (String) e.nextElement();
64 toAnalyze.put(classname, classname);
65 }
66
67 int count = 0;
68 int maxCount = isClosureRequired() ? MAX_LOOPS : 2;
69 while (toAnalyze.size() != 0 && count++ < maxCount) {
70 DependencyVisitor dependencyVisitor = new DependencyVisitor();
71 for (Enumeration e = toAnalyze.keys(); e.hasMoreElements();) {
72 String classname = (String) e.nextElement();
73 dependencies.put(classname, classname);
74 try {
75 File container = getClassContainer(classname);
76 if (container == null) {
77 continue;
78 }
79 containers.put(container, container);
80
81 ClassParser parser = null;
82 if (container.getName().endsWith(".class")) {
83 parser = new ClassParser(container.getPath());
84 } else {
85 parser = new ClassParser(container.getPath(),
86 classname.replace('.', '/') + ".class");
87 }
88
89 JavaClass javaClass = parser.parse();
90 DescendingVisitor traverser
91 = new DescendingVisitor(javaClass, dependencyVisitor);
92 traverser.visit();
93 } catch (IOException ioe) {
94 // ignore
95 }
96 }
97
98 toAnalyze.clear();
99
100 // now recover all the dependencies collected and add to the list.
101 Enumeration depsEnum = dependencyVisitor.getDependencies();
102 while (depsEnum.hasMoreElements()) {
103 String className = (String) depsEnum.nextElement();
104 if (!dependencies.containsKey(className)) {
105 toAnalyze.put(className, className);
106 }
107 }
108 }
109
110 files.removeAllElements();
111 for (Enumeration e = containers.keys(); e.hasMoreElements();) {
112 files.addElement((File) e.nextElement());
113 }
114
115 classes.removeAllElements();
116 for (Enumeration e = dependencies.keys(); e.hasMoreElements();) {
117 classes.addElement((String) e.nextElement());
118 }
119 }
120
121 /**
122 * Indicate if this analyzer can determine dependent files.
123 *
124 * @return true if the analyzer provides dependency file information.
125 */
126 protected boolean supportsFileDependencies() {
127 return true;
128 }
129}
130
Note: See TracBrowser for help on using the repository browser.