User: rinkrank
  Date: 02/05/23 17:57:34

  Modified:    core/src/xdoclet/loader Tag: MODULE_REFACTORING_BRANCH
                        ModuleFinder.java
  Log:
  added support for reading modules from a directory
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.3.2.12  +67 -47    xdoclet/core/src/xdoclet/loader/ModuleFinder.java
  
  Index: ModuleFinder.java
  ===================================================================
  RCS file: /cvsroot/xdoclet/xdoclet/core/src/xdoclet/loader/ModuleFinder.java,v
  retrieving revision 1.3.2.11
  retrieving revision 1.3.2.12
  diff -u -w -r1.3.2.11 -r1.3.2.12
  --- ModuleFinder.java 21 May 2002 21:13:45 -0000      1.3.2.11
  +++ ModuleFinder.java 24 May 2002 00:57:34 -0000      1.3.2.12
  @@ -6,6 +6,7 @@
   
   import java.io.File;
   import java.io.FileFilter;
  +import java.io.FileInputStream;
   import java.io.IOException;
   import java.io.InputStream;
   import java.util.*;
  @@ -23,10 +24,11 @@
    *
    * @author    <a href="mailto:[EMAIL PROTECTED]";>Aslak Helles�y</a>
    * @created   7. april 2002
  - * @version   $Revision: 1.3.2.11 $
  + * @version   $Revision: 1.3.2.12 $
    */
   public class ModuleFinder
   {
  +
       private final static FileFilter jarFilter =
           new FileFilter()
           {
  @@ -35,69 +37,82 @@
                   return file.getName().endsWith(".jar");
               }
           };
  +    private static List modules = null;
   
       /**
  -     * Find the newest Jar file in classpath. This method is used to see if a 
generation is needed because one of the
  -     * xdoclet Jars has changed since the last generation.
  +     * Get the newest Jar file on the classpath. This method is used to see if a 
generation is needed because one of the
  +     * xdoclet jars might have changed since the last generation.
        *
  -     * @return   The newest JAR file in the Classpath
  +     * @return   The timestamp of the newest jar file on the classpath
        */
  -    public static File getNewestJarFileOnClassPath()
  +    public static File getNewestFileOnClassPath()
       {
  -        List jars = findJarFiles();
  -        Iterator i = jars.iterator();
  +        List moduleFiles = findModuleFiles();
           long newest = Long.MIN_VALUE;
           File newestFile = null;
   
  +        Iterator i = moduleFiles.iterator();
  +
           while (i.hasNext()) {
  -            File jar = (File) i.next();
  +            File moduleFile = (File) i.next();
   
  -            if (jar.lastModified() >= newest) {
  -                newestFile = jar;
  -                newest = jar.lastModified();
  +            if (moduleFile.lastModified() >= newest) {
  +                newestFile = moduleFile;
  +                newest = moduleFile.lastModified();
               }
           }
           return newestFile;
       }
   
  -    public static List findModules(boolean verbose)
  +    /**
  +     * Returns a List of XDocletModule objects
  +     *
  +     * @return
  +     */
  +    public static List findModules()
       {
  +        if (modules == null) {
  +            modules = new ArrayList();
  +
           Log log = LogUtil.getLog(ModuleFinder.class, "findModules");
   
           log.info("Registering XDoclet modules (searching for jars containing 
META-INF/xdoclet.xml) ...");
   
  -        ArrayList result = new ArrayList();
           XDocletXmlParser parser = new XDocletXmlParser();
   
  -        List jarFiles = findJarFiles();
  -        Iterator jarFileIterator = jarFiles.iterator();
  +            List moduleFiles = findModuleFiles();
  +            Iterator moduleFileIterator = moduleFiles.iterator();
   
  -        while (jarFileIterator.hasNext()) {
  -            File file = (File) jarFileIterator.next();
  +            while (moduleFileIterator.hasNext()) {
  +                File file = (File) moduleFileIterator.next();
   
               try {
  +                    InputStream xdocletXmlIs = null;
  +
  +                    if (file.isDirectory()) {
  +                        xdocletXmlIs = new FileInputStream(new File(file, 
"META-INF" + File.separator + "xdoclet.xml"));
  +                    }
  +                    else {
                   JarFile jar = new JarFile(file);
                   JarEntry xdocletXml = jar.getJarEntry("META-INF/xdoclet.xml");
   
                   if (xdocletXml != null) {
                       log.info(file.getAbsolutePath() + " exists. Parsing it.");
   
  -                    InputStream xdocletXmlIs = jar.getInputStream(xdocletXml);
  -                    XDocletModule module = parser.parse(xdocletXmlIs);
  -
  -                    if (module != null) {
  -                        result.add(module);
  +                            xdocletXmlIs = jar.getInputStream(xdocletXml);
                       }
                       else {
  -                        log.warn("META-INF/xdoclet.xml is bad in " + 
file.getAbsolutePath());
  +                            log.info("Skipping " + file.getAbsolutePath() + " (No 
META-INF/xdoclet.xml in here)");
                       }
                   }
  -                else {
  -                    if (verbose) {
  -                        log.info("Skipping " + file.getAbsolutePath() + " (No 
META-INF/xdoclet.xml in here)");
  +                    if (xdocletXmlIs != null) {
  +                        XDocletModule module = parser.parse(xdocletXmlIs);
  +
  +                        if (module != null) {
  +                            modules.add(module);
                       }
                       else {
  -                        log.debug("Skipping " + file.getAbsolutePath() + " (No 
META-INF/xdoclet.xml in here)");
  +                            log.warn("META-INF/xdoclet.xml is bad in " + 
file.getAbsolutePath());
                       }
                   }
               }
  @@ -106,13 +121,12 @@
               }
           }
   
  -        if (verbose)
  -            log.info("Finished. Registered " + result.size() + " modules.");
  -
  -        return result;
  +            log.info("Finished. Registered " + modules.size() + " modules.");
  +        }
  +        return modules;
       }
   
  -    private static List findJarFiles()
  +    private static List findModuleFiles()
       {
           String classpath = System.getProperty("xdoclet.class.path");
   
  @@ -131,6 +145,12 @@
                   File[] jars = file.listFiles(jarFilter);
   
                   result.addAll(Arrays.asList(jars));
  +
  +                // a module doesn't have to be a jar. can be a straight directory 
too.
  +                // required in order to solve the chicken and egg for xdoclet 
itself (externalizer)
  +                if (new File(file, "META-INF" + File.separator + 
"xdoclet.xml").exists()) {
  +                    result.add(file);
  +                }
               }
               else if (jarFilter.accept(file)) {
                   result.add(file);
  
  
  

_______________________________________________________________

Don't miss the 2002 Sprint PCS Application Developer's Conference
August 25-28 in Las Vegas -- http://devcon.sprintpcs.com/adp/index.cfm

_______________________________________________
Xdoclet-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-devel

Reply via email to