source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/src/main/org/apache/tools/ant/types/optional/depend/DependScanner.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: 6.1 KB
Line 
1/*
2 * Copyright 2001-2002, 2004-2005 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.types.optional.depend;
18
19import java.io.File;
20import java.util.Enumeration;
21import java.util.Hashtable;
22import java.util.Vector;
23import org.apache.tools.ant.BuildException;
24import org.apache.tools.ant.DirectoryScanner;
25import org.apache.tools.ant.types.Path;
26import org.apache.tools.ant.util.depend.DependencyAnalyzer;
27
28
29/**
30 * DirectoryScanner for finding class dependencies.
31 */
32public class DependScanner extends DirectoryScanner {
33 /**
34 * The name of the analyzer to use by default.
35 */
36 public static final String DEFAULT_ANALYZER_CLASS
37 = "org.apache.tools.ant.util.depend.bcel.FullAnalyzer";
38
39 /**
40 * The root classes to drive the search for dependent classes.
41 */
42 private Vector rootClasses;
43
44 /**
45 * The names of the classes to include in the fileset.
46 */
47 private Vector included;
48
49 /**
50 * The parent scanner which gives the basic set of files. Only files which
51 * are in this set and which can be reached from a root class will end
52 * up being included in the result set.
53 */
54 private DirectoryScanner parentScanner;
55
56 /**
57 * Create a DependScanner, using the given scanner to provide the basic
58 * set of files from which class files come.
59 *
60 * @param parentScanner the DirectoryScanner which returns the files from
61 * which class files must come.
62 */
63 public DependScanner(DirectoryScanner parentScanner) {
64 this.parentScanner = parentScanner;
65 }
66
67 /**
68 * Sets the root classes to be used to drive the scan.
69 *
70 * @param rootClasses the rootClasses to be used for this scan.
71 */
72 public synchronized void setRootClasses(Vector rootClasses) {
73 this.rootClasses = rootClasses;
74 }
75
76 /**
77 * Get the names of the class files on which baseClass depends.
78 *
79 * @return the names of the files.
80 */
81 public String[] getIncludedFiles() {
82 String[] files = new String[getIncludedFilesCount()];
83 for (int i = 0; i < files.length; i++) {
84 files[i] = (String) included.elementAt(i);
85 }
86 return files;
87 }
88
89 /**
90 * @see DirectoryScanner#getIncludedFilesCount
91 */
92 public synchronized int getIncludedFilesCount() {
93 if (included == null) {
94 throw new IllegalStateException();
95 }
96 return included.size();
97 }
98
99 /**
100 * Scans the base directory for files on which baseClass depends.
101 *
102 * @exception IllegalStateException when basedir was set incorrectly.
103 */
104 public synchronized void scan() throws IllegalStateException {
105 included = new Vector();
106 String analyzerClassName = DEFAULT_ANALYZER_CLASS;
107 DependencyAnalyzer analyzer = null;
108 try {
109 Class analyzerClass = Class.forName(analyzerClassName);
110 analyzer = (DependencyAnalyzer) analyzerClass.newInstance();
111 } catch (Exception e) {
112 throw new BuildException("Unable to load dependency analyzer: "
113 + analyzerClassName, e);
114 }
115 analyzer.addClassPath(new Path(null, basedir.getPath()));
116
117 for (Enumeration e = rootClasses.elements(); e.hasMoreElements();) {
118 String rootClass = (String) e.nextElement();
119 analyzer.addRootClass(rootClass);
120 }
121 Enumeration e = analyzer.getClassDependencies();
122
123 String[] parentFiles = parentScanner.getIncludedFiles();
124 Hashtable parentSet = new Hashtable();
125 for (int i = 0; i < parentFiles.length; ++i) {
126 parentSet.put(parentFiles[i], parentFiles[i]);
127 }
128 while (e.hasMoreElements()) {
129 String classname = (String) e.nextElement();
130 String filename = classname.replace('.', File.separatorChar);
131 filename = filename + ".class";
132 File depFile = new File(basedir, filename);
133 if (depFile.exists() && parentSet.containsKey(filename)) {
134 // This is included
135 included.addElement(filename);
136 }
137 }
138 }
139
140 /**
141 * @see DirectoryScanner#addDefaultExcludes
142 */
143 public void addDefaultExcludes() {
144 }
145
146 /**
147 * @see DirectoryScanner#getExcludedDirectories
148 */
149 public String[] getExcludedDirectories() {
150 return null;
151 }
152
153 /**
154 * @see DirectoryScanner#getExcludedFiles
155 */
156 public String[] getExcludedFiles() {
157 return null;
158 }
159
160 /**
161 * @see DirectoryScanner#getIncludedDirectories
162 */
163 public String[] getIncludedDirectories() {
164 return new String[0];
165 }
166
167 /**
168 * @see DirectoryScanner#getIncludedDirsCount
169 */
170 public int getIncludedDirsCount() {
171 return 0;
172 }
173
174 /**
175 * @see DirectoryScanner#getNotIncludedDirectories
176 */
177 public String[] getNotIncludedDirectories() {
178 return null;
179 }
180
181 /**
182 * @see DirectoryScanner#getNotIncludedFiles
183 */
184 public String[] getNotIncludedFiles() {
185 return null;
186 }
187
188 /**
189 * @see DirectoryScanner#setExcludes
190 */
191 public void setExcludes(String[] excludes) {
192 }
193
194 /**
195 * @see DirectoryScanner#setIncludes
196 */
197 public void setIncludes(String[] includes) {
198 }
199
200 /**
201 * @see DirectoryScanner#setCaseSensitive
202 */
203 public void setCaseSensitive(boolean isCaseSensitive) {
204 }
205}
Note: See TracBrowser for help on using the repository browser.