e.g. Calendar Search Help
You must enter a value before pressing Search
ant

Class: org.apache.tools.ant.types.optional.depend.ClassfileSet   ©

 OK to copy?
001 /*
002  * Copyright  2001-2002,2004 The Apache Software Foundation
003  *
004  *  Licensed under the Apache License, Version 2.0 (the "License");
005  *  you may not use this file except in compliance with the License.
006  *  You may obtain a copy of the License at
007  *
008  *      http://www.apache.org/licenses/LICENSE-2.0
009  *
010  *  Unless required by applicable law or agreed to in writing, software
011  *  distributed under the License is distributed on an "AS IS" BASIS,
012  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013  *  See the License for the specific language governing permissions and
014  *  limitations under the License.
015  *
016  */
017 package org.apache.tools.ant.types.optional.depend;
018 
019 import java.util.Enumeration;
020 import java.util.Vector;
021 import org.apache.tools.ant.DirectoryScanner;
022 import org.apache.tools.ant.Project;
023 import org.apache.tools.ant.types.FileSet;
024 
025 /**
026  * A ClassfileSet is a FileSet, that enlists all classes that depend on a
027  * certain set of root classes.
028  *
029  * A ClassfileSet extends FileSets. The
030  * nested FileSet attribute provides the domain, that is used for searching
031  * for dependent classes
032  *
033  */
034 public class ClassfileSet extends FileSet {
035     /**
036      * The list of root classes for this class file set. These are the
037      * classes which must be included in the fileset and which are the
038      * starting point for the dependency search.
039      */
040     private Vector rootClasses = new Vector();
041 
042     /**
043      * The list of filesets which contain root classes
044      */
045     private Vector rootFileSets = new Vector();
046 
047     /**
048      * Inner class used to contain info about root classes
049      */
050     public static class ClassRoot {
051         /** The name of the root class */
052         private String rootClass;
053 
054         /**
055          * Set the root class name
056          *
057          * @param name the name of the root class
058          */
059         public void setClassname(String name) {
060             this.rootClass = name;
061         }
062 
063         /**
064          * Get the name of the root class
065          *
066          * @return the name of the root class.
067          */
068         public String getClassname() {
069             return rootClass;
070         }
071     }
072 
073     /**
074      * Default constructor
075      */
076     public ClassfileSet() {
077     }
078 
079     /**
080      * Add a fileset to which contains a collection of root classes used to
081      * drive the search from classes
082      *
083      * @param rootFileSet a root file set to be used to search for dependent
084      * classes
085      */
086     public void addRootFileset(FileSet rootFileSet) {
087         rootFileSets.addElement(rootFileSet);
088     }
089 
090     /**
091      * Create a ClassfileSet from another ClassfileSet
092      *
093      * @param s the other classfileset
094      */
095     protected ClassfileSet(ClassfileSet s) {
096         super(s);
Rate097         rootClasses = (Vector) s.rootClasses.clone();
098     }
099 
100     /**
101      * Set the root class attribute
102      *
103      * @param rootClass the name of the root class.
104      */
105     public void setRootClass(String rootClass) {
106         rootClasses.addElement(rootClass);
107     }
108 
109     /**
110      * Return the DirectoryScanner associated with this FileSet.
111      *
112      * @param p the project used to resolve dirs, etc.
113      *
114      * @return a dependency scanner.
115      */
116     public DirectoryScanner getDirectoryScanner(Project p) {
117         if (isReference()) {
118             return getRef(p).getDirectoryScanner(p);
119         }
120 
Rate121         Vector allRootClasses = (Vector) rootClasses.clone();
122         for (Enumeration e = rootFileSets.elements(); e.hasMoreElements();) {
123             FileSet additionalRootSet = (FileSet) e.nextElement();
124             DirectoryScanner additionalScanner
125                 = additionalRootSet.getDirectoryScanner(p);
126             String[] files = additionalScanner.getIncludedFiles();
127             for (int i = 0; i < files.length; ++i) {
128                 if (files[i].endsWith(".class")) {
129                     String classFilePath
130                         = files[i].substring(0, files[i].length() - 6);
131                     String className
132                         = classFilePath.replace('/', '.').replace('\\', '.');
133                     allRootClasses.addElement(className);
134                 }
135             }
136         }
137 
138 
139         DirectoryScanner parentScanner = super.getDirectoryScanner(p);
140         DependScanner scanner = new DependScanner(parentScanner);
141         scanner.setBasedir(getDir(p));
142         scanner.setRootClasses(allRootClasses);
143         scanner.scan();
144         return scanner;
145     }
146 
147     /**
148      * Add a nested root class definition to this class file set
149      *
150      * @param root the configured class root.
151      */
152     public void addConfiguredRoot(ClassRoot root) {
153         rootClasses.addElement(root.getClassname());
154     }
155 
156     /**
157      * Clone this data type.
158      *
159      * @return a clone of the class file set
160      */
161     public Object clone() {
162         if (isReference()) {
163             return new ClassfileSet((ClassfileSet) getRef(getProject()));
164         } else {
165             return new ClassfileSet(this);
166         }
167     }
168 }

            
All Examples in File:
Example
Line
Rating (found
useful by...)
97 0% of 0
121 0% of 0