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