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 | */
|
---|
17 | package org.apache.tools.ant.types.optional.depend;
|
---|
18 |
|
---|
19 | import java.util.Vector;
|
---|
20 | import java.util.Enumeration;
|
---|
21 | import org.apache.tools.ant.Project;
|
---|
22 | import org.apache.tools.ant.DirectoryScanner;
|
---|
23 | import org.apache.tools.ant.types.FileSet;
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * A ClassfileSet is a FileSet that enlists all classes that depend on a
|
---|
27 | * certain set of root classes.
|
---|
28 | *
|
---|
29 | * ClassfileSet extends FileSet, its inherited properties
|
---|
30 | * defining the domain searched for dependent classes.
|
---|
31 | *
|
---|
32 | */
|
---|
33 | public class ClassfileSet extends FileSet {
|
---|
34 | /**
|
---|
35 | * The list of root classes for this class file set. These are the
|
---|
36 | * classes which must be included in the fileset and which are the
|
---|
37 | * starting point for the dependency search.
|
---|
38 | */
|
---|
39 | private Vector rootClasses = new Vector();
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * The list of filesets which contain root classes.
|
---|
43 | */
|
---|
44 | private Vector rootFileSets = new Vector();
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * Inner class used to contain info about root classes.
|
---|
48 | */
|
---|
49 | public static class ClassRoot {
|
---|
50 | /** The name of the root class */
|
---|
51 | private String rootClass;
|
---|
52 |
|
---|
53 | /**
|
---|
54 | * Set the root class name.
|
---|
55 | *
|
---|
56 | * @param name the name of the root class.
|
---|
57 | */
|
---|
58 | public void setClassname(String name) {
|
---|
59 | this.rootClass = name;
|
---|
60 | }
|
---|
61 |
|
---|
62 | /**
|
---|
63 | * Get the name of the root class.
|
---|
64 | *
|
---|
65 | * @return the name of the root class.
|
---|
66 | */
|
---|
67 | public String getClassname() {
|
---|
68 | return rootClass;
|
---|
69 | }
|
---|
70 | }
|
---|
71 |
|
---|
72 | /**
|
---|
73 | * Default constructor.
|
---|
74 | */
|
---|
75 | public ClassfileSet() {
|
---|
76 | }
|
---|
77 |
|
---|
78 | /**
|
---|
79 | * Add a fileset to which contains a collection of root classes used to
|
---|
80 | * drive the search from classes.
|
---|
81 | *
|
---|
82 | * @param rootFileSet a root file set to be used to search for dependent
|
---|
83 | * classes.
|
---|
84 | */
|
---|
85 | public void addRootFileset(FileSet rootFileSet) {
|
---|
86 | rootFileSets.addElement(rootFileSet);
|
---|
87 | }
|
---|
88 |
|
---|
89 | /**
|
---|
90 | * Create a ClassfileSet from another ClassfileSet.
|
---|
91 | *
|
---|
92 | * @param s the other classfileset.
|
---|
93 | */
|
---|
94 | protected ClassfileSet(ClassfileSet s) {
|
---|
95 | super(s);
|
---|
96 | rootClasses = (Vector) s.rootClasses.clone();
|
---|
97 | }
|
---|
98 |
|
---|
99 | /**
|
---|
100 | * Set the root class attribute.
|
---|
101 | *
|
---|
102 | * @param rootClass the name of the root class.
|
---|
103 | */
|
---|
104 | public void setRootClass(String rootClass) {
|
---|
105 | rootClasses.addElement(rootClass);
|
---|
106 | }
|
---|
107 |
|
---|
108 | /**
|
---|
109 | * Return the DirectoryScanner associated with this FileSet.
|
---|
110 | *
|
---|
111 | * @param p the project used to resolve dirs, etc.
|
---|
112 | *
|
---|
113 | * @return a dependency scanner.
|
---|
114 | */
|
---|
115 | public DirectoryScanner getDirectoryScanner(Project p) {
|
---|
116 | if (isReference()) {
|
---|
117 | return getRef(p).getDirectoryScanner(p);
|
---|
118 | }
|
---|
119 | Vector allRootClasses = (Vector) rootClasses.clone();
|
---|
120 | for (Enumeration e = rootFileSets.elements(); e.hasMoreElements();) {
|
---|
121 | FileSet additionalRootSet = (FileSet) e.nextElement();
|
---|
122 | DirectoryScanner additionalScanner
|
---|
123 | = additionalRootSet.getDirectoryScanner(p);
|
---|
124 | String[] files = additionalScanner.getIncludedFiles();
|
---|
125 | for (int i = 0; i < files.length; ++i) {
|
---|
126 | if (files[i].endsWith(".class")) {
|
---|
127 | String classFilePath
|
---|
128 | = files[i].substring(0, files[i].length() - 6);
|
---|
129 | String className
|
---|
130 | = classFilePath.replace('/', '.').replace('\\', '.');
|
---|
131 | allRootClasses.addElement(className);
|
---|
132 | }
|
---|
133 | }
|
---|
134 | }
|
---|
135 | DirectoryScanner parentScanner = super.getDirectoryScanner(p);
|
---|
136 | DependScanner scanner = new DependScanner(parentScanner);
|
---|
137 | scanner.setBasedir(getDir(p));
|
---|
138 | scanner.setRootClasses(allRootClasses);
|
---|
139 | scanner.scan();
|
---|
140 | return scanner;
|
---|
141 | }
|
---|
142 |
|
---|
143 | /**
|
---|
144 | * Add a nested root class definition to this class file set.
|
---|
145 | *
|
---|
146 | * @param root the configured class root.
|
---|
147 | */
|
---|
148 | public void addConfiguredRoot(ClassRoot root) {
|
---|
149 | rootClasses.addElement(root.getClassname());
|
---|
150 | }
|
---|
151 |
|
---|
152 | /**
|
---|
153 | * Clone this data type.
|
---|
154 | *
|
---|
155 | * @return a clone of the class file set.
|
---|
156 | */
|
---|
157 | public Object clone() {
|
---|
158 | return new ClassfileSet(isReference()
|
---|
159 | ? (ClassfileSet) (getRef(getProject())) : this);
|
---|
160 | }
|
---|
161 |
|
---|
162 | }
|
---|