View Javadoc
1 package xdoclet.xjavadoc; 2 3 import org.apache.tools.ant.types.FileSet; 4 import org.apache.tools.ant.DirectoryScanner; 5 import org.apache.tools.ant.Project; 6 import org.apache.tools.ant.ProjectComponent; 7 8 import xdoclet.MetadataProvider; 9 import xdoclet.XDocletException; 10 11 import xjavadoc.XClass; 12 import xjavadoc.XJavaDoc; 13 import xjavadoc.SourceSet; 14 import xjavadoc.filesystem.FileSourceSet; 15 16 import java.util.*; 17 18 /*** 19 * {@link MetadataProvider} implementation that returns {@link xjavadoc.XClass}. 20 * 21 * @todo make independent of Ant 22 * @author <a href="mailto:aslak.hellesoy at bekk.no">Aslak Hellesøy</a> 23 * @version $Revision: 1.10 $ 24 */ 25 public class XJavadocMetadataProvider extends ProjectComponent implements MetadataProvider { 26 27 private final XJavaDoc _xJavaDoc = new XJavaDoc(); 28 private List _fileSets = new ArrayList(); 29 30 /*** 31 * Ant's <fileset> definition. To define the files to parse. 32 * 33 * @param fileSet a fileset to add 34 */ 35 public void addFileset( FileSet fileSet ) 36 { 37 _fileSets.add(fileSet); 38 } 39 40 public XJavaDoc getXJavaDoc() { 41 return _xJavaDoc; 42 } 43 44 /*** 45 * Sets the tags to ignore if validation is true. The value should be a 46 * comma-separated list of tag names (without the tag name) 47 * 48 * @param tags tags that should be ignored when doing validation. 49 */ 50 public void setIgnoredtags( String tags ) 51 { 52 getXJavaDoc().getTagFactory().setIgnoredTags( tags ); 53 } 54 55 /*** 56 * Sets whether or not tags will be validated. 57 * 58 * @param flag 59 */ 60 public void setValidating( boolean flag ) 61 { 62 getXJavaDoc().getTagFactory().setValidating( flag ); 63 } 64 65 public void setClasspath( String classpath ) throws XDocletException { 66 getXJavaDoc().registerTags( classpath ); 67 } 68 69 /////////// MetadataProvider interface /////////// 70 /*** 71 * {@inheritDoc} 72 * @return a Collection of {@link xjavadoc.XClass}. 73 */ 74 public final Collection createMetadataCollection() throws XDocletException { 75 if( getProject() != null ) { 76 Hashtable properties = getProject().getProperties(); 77 getXJavaDoc().setPropertyMap( properties ); 78 } 79 80 addFilesets(); 81 82 Collection result = _xJavaDoc.getSourceClasses(); 83 84 if( result.isEmpty() ) { 85 throw new XDocletException("No sources found."); 86 } 87 88 return result; 89 } 90 91 private void addFilesets() { 92 for (Iterator i = _fileSets.iterator(); i.hasNext();) { 93 FileSet fileSet = (FileSet) i.next(); 94 Project project = fileSet.getProject(); 95 96 DirectoryScanner directoryScanner = fileSet.getDirectoryScanner( project ); 97 String[] files = directoryScanner.getIncludedFiles(); 98 SourceSet sourceSet = new FileSourceSet( fileSet.getDir( project ), files ); 99 getXJavaDoc().addSourceSet( sourceSet ); 100 } 101 } 102 103 public String getFilenameSubstitutionValue(Object o) { 104 return getXClass(o).getName(); 105 } 106 107 public String getPackageName(Object o) { 108 return getXClass(o).getContainingPackage().getName(); 109 } 110 111 public void cleanup() throws XDocletException { 112 _xJavaDoc.printLogMessages( System.out, XJavaDoc.NO_IMPORTED_PACKAGES ); 113 _xJavaDoc.printLogMessages( System.out, XJavaDoc.ONE_OR_MORE_IMPORTED_PACKAGES ); 114 _xJavaDoc.reset(true); 115 System.gc(); 116 } 117 118 private static XClass getXClass(Object o) { 119 if (o instanceof XClass) { 120 return (XClass) o; 121 } else { 122 throw new IllegalStateException(o.getClass().getName() + " can't be cast to " + XClass.class.getName() 123 + ". Please override the getFileNameSubstitutionValue method."); 124 } 125 } 126 }

This page was automatically generated by Maven