1
2
3
4
5 package xjavadoc.ant;
6
7 import java.io.File;
8 import java.util.StringTokenizer;
9
10 import org.apache.tools.ant.BuildException;
11 import org.apache.tools.ant.types.FileSet;
12 import org.apache.tools.ant.types.Parameter;
13 import org.apache.tools.ant.types.selectors.BaseExtendSelector;
14
15 import xjavadoc.ClassIterator;
16 import xjavadoc.XClass;
17 import xjavadoc.XCollections;
18 import xjavadoc.XJavaDoc;
19 import xjavadoc.filesystem.FileSourceSet;
20
21 /***
22 * Custom file filter for Ant based on XJavadoc. Filters java sources according
23 * to some Java specific features. <br/>
24 * Usage:<br/>
25 * <pre>
26 *<copy todir="filtered-src">
27 * <fileset dir="src">
28 * <or>
29 * <custom classname="xjavadoc.XJavadocFilter" classpathref="lib.jars">
30 * <parameter name="implements" value="javax.ejb.EntityBean" />
31 * </custom>
32 * <custom classname="xjavadoc.XJavadocFilter" classpathref="lib.jars">
33 * <parameter name="implements" value="javax.ejb.SessionBean" />
34 * </custom>
35 * </or>
36 * </fileset>
37 *</copy>
38 *</pre> Valid parameters are:<br/>
39 *
40 * <dl>
41 * <dt> <strong>implements</strong> </dt>
42 * <dd> full qualified name of the class or interface to implement</dd>
43 * <dt> <strong>contains-tag</strong> </dt>
44 * <dd> javadoc tag to contain</dd>
45 * </dl>
46 *
47 *
48 * @author Ludovic Claude
49 * @created 02 November 2002
50 * @version $Revision: 1.4 $
51 */
52 public class XJavadocFilter extends BaseExtendSelector
53 {
54 XJavaDoc _xJavaDoc = new XJavaDoc();
55
56 /***
57 * Constructor for XJavadocFilter.
58 */
59 public XJavadocFilter()
60 {
61 super();
62 }
63
64 /***
65 * @param basedir
66 * @param filename
67 * @param file
68 * @return
69 * @exception BuildException
70 * @see org.apache.tools.ant.types.selectors.FileSelector#isSelected(File,
71 * String, File)
72 */
73 public boolean isSelected( File basedir, String filename, File file )
74 throws BuildException
75 {
76
77 if( !filename.endsWith( ".java" ) )
78 return false;
79
80 _xJavaDoc.reset( true );
81 try
82 {
83
84
85 _xJavaDoc.addSourceSet( new FileSourceSet( basedir, new String[]{filename} ) );
86
87 for( ClassIterator i = XCollections.classIterator( _xJavaDoc.getSourceClasses() ); i.hasNext(); )
88 {
89 XClass clazz = i.next();
90 Parameter[] params = getParameters();
91
92 for( int j = 0; j < params.length; j++ )
93 {
94 Parameter param = params[j];
95
96 if( param.getName().equals( "implements" ) )
97 {
98 String mandatoryClass = param.getValue();
99
100 if( !clazz.isA( mandatoryClass ) )
101 return false;
102 }
103 else if( param.getName().equals( "contains-tag" ) )
104 {
105 String mandatoryTag = param.getValue();
106
107 if( !clazz.getDoc().hasTag( mandatoryTag ) )
108 return false;
109 }
110 }
111 }
112 }
113 catch( OutOfMemoryError e )
114 {
115 System.err.println( e.getMessage() );
116 XJavaDoc.printMemoryStatus();
117 System.err.println( "Try to increase heap size. Can be done by defining ANT_OPTS=-Xmx640m" );
118 System.err.println( "See the JDK tooldocs." );
119 throw new BuildException( e.getMessage(), e );
120 }
121 catch( Throwable t )
122 {
123 t.printStackTrace();
124 throw new BuildException( "Unexpected error", t );
125 }
126 finally
127 {
128
129
130 _xJavaDoc.printLogMessages( System.out, XJavaDoc.NO_IMPORTED_PACKAGES );
131 _xJavaDoc.printLogMessages( System.out, XJavaDoc.ONE_OR_MORE_IMPORTED_PACKAGES );
132 _xJavaDoc.reset( true );
133 System.gc();
134 }
135 return true;
136 }
137
138 }