User: rinkrank
  Date: 02/04/21 13:38:35

  Modified:    src/xjavadoc/ant XJavaDocMain.java XJavadocTask.java
  Log:
  -more optimisations by removing proxyclass
  -handled classloading issues in xjavadoc in stead of xdoclet
  -minor api modifications
  
  Revision  Changes    Path
  1.3       +162 -145  xjavadoc/src/xjavadoc/ant/XJavaDocMain.java
  
  Index: XJavaDocMain.java
  ===================================================================
  RCS file: /cvsroot/xdoclet/xjavadoc/src/xjavadoc/ant/XJavaDocMain.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -w -r1.2 -r1.3
  --- XJavaDocMain.java 8 Apr 2002 17:04:18 -0000       1.2
  +++ XJavaDocMain.java 21 Apr 2002 20:38:34 -0000      1.3
  @@ -1,49 +1,27 @@
   /*
  - * Copyright (c) 2001, Aslak Helles�y, BEKK Consulting
  + * Copyright (c) 2001,2002 The XDoclet team
    * All rights reserved.
  - *
  - * Redistribution and use in source and binary forms, with or without modification,
  - * are permitted provided that the following conditions are met:
  - *
  - * - Redistributions of source code must retain the above copyright notice,
  - *   this list of conditions and the following disclaimer.
  - *
  - * - Redistributions in binary form must reproduce the above copyright
  - *   notice, this list of conditions and the following disclaimer in the
  - *   documentation and/or other materials provided with the distribution.
  - *
  - * - Neither the name of BEKK Consulting nor the names of its
  - *   contributors may be used to endorse or promote products derived from
  - *   this software without specific prior written permission.
  - *
  - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
  - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  - * DAMAGE.
  - */
  -
  -/*
  - * Change log
  - *
    */
   package xjavadoc.ant;
   
   import xjavadoc.XJavaDoc;
  +
   import xjavadoc.XClass;
  +
   import xjavadoc.XDoc;
  +
   import xjavadoc.SourceSet;
  +
   import java.io.BufferedInputStream;
  +
   import java.io.FileInputStream;
  +
   import java.io.InputStream;
  +
   import java.io.IOException;
  +
   import java.io.ObjectInputStream;
  +
   import java.io.File;
   
   /**
  @@ -55,25 +33,9 @@
    * @author <a href="mailto:[EMAIL PROTECTED]";>Aslak Helles�y</a>
    * @created 19. februar 2002
    */
  -public class XJavaDocMain {
  -
  -     /**
  -      * This method is invoked when XJavaDoc is ready. No classes are scanned yet,
  -      * but XJavaDoc knows about the classes, so just go ahead and get them!
  -      *
  -      * @param extraContextFileName Filename of any additional serialised context
  -      * @exception Exception Describe the exception
  -      * @todo-javadoc Write javadocs for method parameter
  -      * @todo-javadoc Write javadocs for exception
  -      * @frenchanimal cat="chat" dog="chien" asshole="lepen"
  -      */
  -     protected void start(String extraContextFileName) throws Exception {
  -             XClass myself = XJavaDoc.getInstance().getXClass(getClass().getName());
  -             XDoc thisMethodDoc = myself.getMethod("start(java.lang.String)").doc();
  -             System.out.println(thisMethodDoc.firstSentence());
  -             System.out.println(thisMethodDoc.tagAttributeValue("frenchanimal", 
"dog"));
  -     }
   
  +public class XJavaDocMain
  +{
   
        /**
         * This method is invoked by Ant in the end of the execute method
  @@ -81,22 +43,38 @@
         * @param args Describe the command line arguments
         * @todo-javadoc Describe the command line arguments
         */
  -     public final static void main(String[] args) {
  -             try {
  +
  +     public final static void main( String[] args )
  +     {
  +
  +             try
  +             {
  +
                        // second last arg is the filename of the serialised source 
sets
  +
                        loadSourceSets(args[args.length - 2]);
   
  +
                        // last arg is the classname of the XJavaDocMain (sub)class to 
invoke
  +
                        XJavaDocMain main = 
(XJavaDocMain)Class.forName(args[args.length - 1]).newInstance();
   
  +
                        // pass the first arg. That should be set in 
XjavadocSubclass.execute()
  +
                        // prior to calling super.execute()
  -                     main.start(args[0]);
  -             } catch (Throwable t) {
  -                     t.printStackTrace();
  +
  +                     main.start( args );
  +
                }
  +             catch( Throwable t )
  +             {
  +
  +                     t.printStackTrace();
  +
        }
   
  +     }
   
        /**
         * Describe what the method does
  @@ -115,16 +93,23 @@
         * @todo-javadoc Write javadocs for exception
         * @todo-javadoc Write javadocs for exception
         */
  -     protected static Object loadAndDelete(String fileName) throws IOException, 
ClassNotFoundException {
  +
  +     protected static Object loadAndDelete( String fileName ) throws IOException, 
ClassNotFoundException
  +     {
  +
                File f = new File(fileName);
  +
                FileInputStream fis = new FileInputStream(fileName);
  +
                ObjectInputStream ois = new ObjectInputStream(new 
BufferedInputStream(fis));
  +
                Object o = ois.readObject();
  +
                f.delete();
  +
                return o;
        }
   
  -
        /**
         * Describe what the method does
         *
  @@ -136,10 +121,42 @@
         * @todo-javadoc Write javadocs for exception
         * @todo-javadoc Write javadocs for exception
         */
  -     protected static void loadSourceSets(String serialisedSourceSets) throws 
IOException, ClassNotFoundException {
  +
  +     protected static void loadSourceSets( String serialisedSourceSets ) throws 
IOException, ClassNotFoundException
  +     {
  +
                SourceSet[] sourceSets = 
(SourceSet[])loadAndDelete(serialisedSourceSets);
  -             for (int i = 0; i < sourceSets.length; i++) {
  +
  +             for( int i = 0; i < sourceSets.length; i++ )
  +             {
  +
                        XJavaDoc.getInstance().addSourceSet(sourceSets[i]);
  +
                }
  +
        }
  +
  +     /**
  +      * This method is invoked when XJavaDoc is ready. No classes are scanned yet,
  +      * but XJavaDoc knows about the classes, so just go ahead and get them!
  +      *
  +      * @param args
  +      * @exception Exception  Describe the exception
  +      * @frenchanimal         cat="chat" dog="chien" asshole="lepen"
  +      */
  +
  +     protected void start( String[] args ) throws Exception
  +     {
  +
  +             XClass myself = XJavaDoc.getInstance().getXClass( getClass().getName() 
);
  +
  +             XDoc thisMethodDoc = myself.getMethod( "start(java.lang.String)" 
).doc();
  +
  +             System.out.println( thisMethodDoc.firstSentence() );
  +
  +             System.out.println( thisMethodDoc.tagAttributeValue( "frenchanimal", 
"dog" ) );
  +
   }
  +
  +}
  +
  
  
  
  1.10      +151 -128  xjavadoc/src/xjavadoc/ant/XJavadocTask.java
  
  Index: XJavadocTask.java
  ===================================================================
  RCS file: /cvsroot/xdoclet/xjavadoc/src/xjavadoc/ant/XJavadocTask.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -w -r1.9 -r1.10
  --- XJavadocTask.java 27 Mar 2002 22:37:01 -0000      1.9
  +++ XJavadocTask.java 21 Apr 2002 20:38:35 -0000      1.10
  @@ -1,37 +1,6 @@
   /*
  - * Copyright (c) 2001, Aslak Helles�y, BEKK Consulting
  + * Copyright (c) 2001,2002 The XDoclet team
    * All rights reserved.
  - *
  - * Redistribution and use in source and binary forms, with or without modification,
  - * are permitted provided that the following conditions are met:
  - *
  - * - Redistributions of source code must retain the above copyright notice,
  - *   this list of conditions and the following disclaimer.
  - *
  - * - Redistributions in binary form must reproduce the above copyright
  - *   notice, this list of conditions and the following disclaimer in the
  - *   documentation and/or other materials provided with the distribution.
  - *
  - * - Neither the name of BEKK Consulting nor the names of its
  - *   contributors may be used to endorse or promote products derived from
  - *   this software without specific prior written permission.
  - *
  - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
  - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  - * DAMAGE.
  - */
  -
  -/*
  - * Change log
  - *
    */
   package xjavadoc.ant;
   
  @@ -42,11 +11,15 @@
   import java.io.IOException;
   import java.io.File;
   
  -import java.util.Vector;
  +import java.util.ArrayList;
  +import java.util.Iterator;
  +import org.apache.tools.ant.AntClassLoader;
   import org.apache.tools.ant.BuildException;
   import org.apache.tools.ant.DirectoryScanner;
   import org.apache.tools.ant.taskdefs.Java;
  +import org.apache.tools.ant.types.Reference;
   import org.apache.tools.ant.types.FileSet;
  +import org.apache.tools.ant.types.Path;
   import xjavadoc.XJavaDoc;
   import xjavadoc.SourceSet;
   
  @@ -57,69 +30,69 @@
    * @author Ara Abrahamian
    * @created February 17, 2002
    */
  -public class XJavadocTask extends Java {
  +public class XJavadocTask extends Java
  +{
  +
        /**
         * @todo-javadoc Describe the field
         */
  -     private final Vector filesets = new Vector();
  +     private final static String _fileName = "xjavadoc." + System.getProperty( 
"user.name" ) + ".ser";
   
        /**
         * @todo-javadoc Describe the field
         */
  -     private boolean _isForked = false;
  -
  +     private final static File DEFAULT_TMP_FILE = new File( System.getProperty( 
"java.io.tmpdir" ), _fileName );
        /**
         * @todo-javadoc Describe the field
         */
  -     private String _className = "xjavadoc.ant.XJavaDocMain";
  +     private final ArrayList _fileSets = new ArrayList();
   
        /**
         * @todo-javadoc Describe the field
         */
  -     private File _tmpFile = DEFAULT_TMP_FILE;
  +     private boolean    _isForked = false;
   
        /**
         * @todo-javadoc Describe the field
         */
  -     private final static String fileName = "xjavadoc." + 
System.getProperty("user.name") + ".ser";
  +     private String     _className = "xjavadoc.ant.XJavaDocMain";
   
        /**
         * @todo-javadoc Describe the field
         */
  -     private final static File DEFAULT_TMP_FILE = new 
File(System.getProperty("java.io.tmpdir"), fileName);
  -
  +     private File       _tmpFile = DEFAULT_TMP_FILE;
   
        /**
         * Describe what the XJavadocTask constructor does
         *
         * @todo-javadoc Write javadocs for constructor
         */
  -     public XJavadocTask() {
  +     public XJavadocTask()
  +     {
                setFailonerror(true);
                setClassname(_className);
        }
   
  -
        /**
         * Sets the Fork attribute of the XJavadocTask object
         *
         * @param fork The new Fork value
         */
  -     public void setFork(boolean fork) {
  +     public void setFork( boolean fork )
  +     {
                _isForked = fork;
        }
   
  -
        /**
         * Sets the TempFile attribute of the XJavadocTask object
         *
         * @param tmpFile The new TempFile value
         */
  -     public void setXjavadoctempfile(File tmpFile) {
  +     public void setXjavadoctempfile( File tmpFile )
  +     {
                _tmpFile = tmpFile;
        }
   
  -
        /**
         * Sets the Classname attribute of the XJavadocTask object
         *
  @@ -127,12 +100,31 @@
         * @exception BuildException Describe the exception
         * @todo-javadoc Write javadocs for exception
         */
  -     public void setClassname(String s) throws BuildException {
  +     public void setClassname( String s ) throws BuildException
  +     {
                super.setClassname(s);
                _className = s;
        }
   
  +     public void setClasspath( Path s )
  +     {
  +             super.setClasspath( s );
  +     }
  +
  +     public void setClasspathRef( Reference r )
  +     {
  +             super.setClasspathRef( r );
  +     }
  +
  +     public void setSourcepath( Path path )
  +     {
  +             String dir = path.toString();
  +             FileSet fileSet = new FileSet();
   
  +             fileSet.setDir( new File( dir ) );
  +             fileSet.setIncludes( "**/*.java" );
  +             addFileset( fileSet );
  +     }
        /**
         * Describe the method
         *
  @@ -140,11 +132,11 @@
         * @todo-javadoc Describe the method
         * @todo-javadoc Describe the method parameter
         */
  -     public void addFileset(FileSet set) {
  -             filesets.addElement(set);
  +     public void addFileset( FileSet set )
  +     {
  +             _fileSets.add( set );
        }
   
  -
        /**
         * Describe what the method does
         *
  @@ -152,12 +144,24 @@
         * @todo-javadoc Write javadocs for method
         * @todo-javadoc Write javadocs for exception
         */
  -     public void execute() throws BuildException {
  -             validateOptions();
  -             try {
  -                     SourceSet[] sourceSets = new SourceSet[filesets.size()];
  -                     for (int i = 0; i < filesets.size(); i++) {
  -                             FileSet fs = (FileSet)filesets.elementAt(i);
  +     public void execute() throws BuildException
  +     {
  +             if( "".equals( createClasspath() ) )
  +             {
  +                     setClasspath( Path.systemClasspath );
  +             }
  +
  +             AntClassLoader loader = new AntClassLoader( project, createClasspath() 
);
  +
  +             XJavaDoc.getInstance().setClassLoader( loader );
  +
  +             try
  +             {
  +                     SourceSet[] sourceSets = new SourceSet[_fileSets.size()];
  +
  +                     for( int i = 0; i < _fileSets.size(); i++ )
  +                     {
  +                             FileSet fs = ( FileSet ) _fileSets.get( i );
                                File dir = fs.getDir(project);
   
                                DirectoryScanner ds = fs.getDirectoryScanner(project);
  @@ -165,29 +169,46 @@
   
                                sourceSets[i] = new SourceSet(dir, files);
                        }
  +
  +                     // serialise the sourcesets. they will be read back in by the 
main class (_className)
                        save(sourceSets, _tmpFile);
                        createArg().setValue(_tmpFile.getAbsolutePath());
                        createArg().setValue(_className);
  +
                        Class mainClass = Class.forName(_className);
   
  -                     System.out.println("Running " + _className + " loaded by " + 
mainClass.getClassLoader().getClass().getName() + ". Forked:" + _isForked);
                        super.setFork(_isForked);
  +
  +                     // Have to fork to avoid LinkageError problems.
  +                     super.setFork( true );
  +
                        super.execute();
  -             } catch (IOException e) {
  +             }
  +             catch( IOException e )
  +             {
                        e.printStackTrace();
                        throw new BuildException(e);
  -             } catch (NoClassDefFoundError e) {
  +             }
  +             catch( NoClassDefFoundError e )
  +             {
                        e.printStackTrace();
                        throw new BuildException(e);
  -             } catch (ClassNotFoundException e) {
  +             }
  +             catch( ClassNotFoundException e )
  +             {
                        e.printStackTrace();
                        throw new BuildException(e);
  -             } catch (BuildException e) {
  +             }
  +             catch( BuildException e )
  +             {
                        Throwable cause = e.getException();
  -                     if (cause != null) {
  +
  +                     if( cause != null )
  +                     {
                                cause.printStackTrace();
                        }
  -                     else {
  +                     else
  +                     {
                                e.printStackTrace();
                        }
                        throw e;
  @@ -195,7 +216,6 @@
   
        }
   
  -
        /**
         * Describe what the method does
         *
  @@ -203,16 +223,18 @@
         * @todo-javadoc Write javadocs for method
         * @todo-javadoc Write javadocs for exception
         */
  -     protected void validateOptions() throws BuildException {
  -             if (filesets.size() == 0) {
  +     protected void validateOptions() throws BuildException
  +     {
  +             if( _fileSets.size() == 0 )
  +             {
                        throw new BuildException("At least one fileset must be 
specified", location);
                }
  -             if (_className == null) {
  +             if( _className == null )
  +             {
                        throw new BuildException("Main class name is null!", location);
                }
        }
   
  -
        /**
         * Describe what the method does
         *
  @@ -226,7 +248,8 @@
         * @todo-javadoc Write javadocs for method parameter
         * @todo-javadoc Write javadocs for exception
         */
  -     protected void save(Object o, File f) throws java.io.IOException {
  +     protected void save( Object o, File f ) throws java.io.IOException
  +     {
                FileOutputStream fos = new FileOutputStream(f);
                ObjectOutputStream oos = new ObjectOutputStream(new 
BufferedOutputStream(fos));
   
  
  
  

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

Reply via email to