User: rinkrank
Date: 02/03/16 10:13:10
Modified: src/xjavadoc/ant XJavadocTask.java
Added: src/xjavadoc/ant XJavaDocMain.java
Removed: src/xjavadoc/ant XJavadocRunner.java
Log:
miscellaneous fixes that became apparent when integrating xjavadoc into xdoclet
Revision Changes Path
1.4 +65 -21 xjavadoc/src/xjavadoc/ant/XJavadocTask.java
Index: XJavadocTask.java
===================================================================
RCS file: /cvsroot/xdoclet/xjavadoc/src/xjavadoc/ant/XJavadocTask.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -w -r1.3 -r1.4
--- XJavadocTask.java 20 Feb 2002 00:12:03 -0000 1.3
+++ XJavadocTask.java 16 Mar 2002 18:13:10 -0000 1.4
@@ -36,17 +36,19 @@
package xjavadoc.ant;
import java.io.BufferedOutputStream;
-import java.io.File;
import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.IOException;
+import java.io.File;
+
import java.util.Vector;
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.FileSet;
import xjavadoc.XJavaDoc;
+import xjavadoc.SourceSet;
/**
* This class should be subclassed to be used for XDoclet, revXDoclet etc.
@@ -64,12 +66,22 @@
/**
* @todo-javadoc Describe the field
*/
- private String _docletClass;
+ private boolean _isForked = false;
+
+ /**
+ * @todo-javadoc Describe the field
+ */
+ private String _className = "xjavadoc.ant.XJavaDocMain";
+
+ /**
+ * @todo-javadoc Describe the field
+ */
+ private File _tmpFile = DEFAULT_TMP_FILE;
/**
* @todo-javadoc Describe the field
*/
- public final static String TMP_FILE = System.getProperty("java.io.tmpdir") +
File.separator + "xjavadoc.ser";
+ private final static File DEFAULT_TMP_FILE = new
File(System.getProperty("java.io.tmpdir"), "xjavadoc.ser");
/**
@@ -78,21 +90,31 @@
* @todo-javadoc Write javadocs for constructor
*/
public XJavadocTask() {
- setClassname("xjavadoc.ant.XJavadocRunner");
- setFork(true);
setFailonerror(true);
+ setClassname(_className);
}
/**
- * Sets the Doclet attribute of the XJavadocTask object
+ * Sets the TempFile attribute of the XJavadocTask object
*
- * @param docletClass The new Doclet value
+ * @param tmpFile The new TempFile value
+ */
+ public void setXjavadoctempfile(File tmpFile) {
+ _tmpFile = tmpFile;
+ }
+
+
+ /**
+ * Sets the Classname attribute of the XJavadocTask object
+ *
+ * @param s The new Classname value
* @exception BuildException Describe the exception
* @todo-javadoc Write javadocs for exception
*/
- public void setDoclet(String docletClass) throws BuildException {
- _docletClass = docletClass;
+ public void setClassname(String s) throws BuildException {
+ super.setClassname(s);
+ _className = s;
}
@@ -116,21 +138,22 @@
* @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);
+ File dir = fs.getDir(project);
+
DirectoryScanner ds = fs.getDirectoryScanner(project);
- // We only want java source files
- ds.setIncludes(new String[]{"**/*.java"});
String[] files = ds.getIncludedFiles();
- XJavaDoc.getInstance().setDir(fs.getDir(project));
- XJavaDoc.getInstance().setFiles(files);
- XJavaDoc.getInstance().setDocletClass(_docletClass);
- saveContext(XJavaDoc.getInstance());
- super.execute();
+ sourceSets[i] = new SourceSet(dir, files);
}
-
+ save(sourceSets, _tmpFile);
+ createArg().setValue(_tmpFile.getAbsolutePath());
+ createArg().setValue(_className);
+ super.execute();
} catch (IOException e) {
e.printStackTrace();
throw new BuildException(e);
@@ -142,17 +165,38 @@
/**
* Describe what the method does
*
- * @param xJavaDoc Describe what the parameter does
+ * @exception BuildException Describe the exception
+ * @todo-javadoc Write javadocs for method
+ * @todo-javadoc Write javadocs for exception
+ */
+ protected void validateOptions() throws BuildException {
+ if (filesets.size() == 0) {
+ throw new BuildException("At least one fileset must be
specified", location);
+ }
+ if (_className == null) {
+ throw new BuildException("Main class name is null!", location);
+ }
+ }
+
+
+ /**
+ * Describe what the method does
+ *
+ * @param o Describe what the parameter does
+ * @param f Describe what the parameter does
* @exception java.io.IOException Describe the exception
+ * @todo-javadoc Write javadocs for method parameter
+ * @todo-javadoc Write javadocs for method parameter
+ * @todo-javadoc Write javadocs for method parameter
* @todo-javadoc Write javadocs for method
* @todo-javadoc Write javadocs for method parameter
* @todo-javadoc Write javadocs for exception
*/
- private void saveContext(XJavaDoc xJavaDoc) throws java.io.IOException {
- FileOutputStream fos = new FileOutputStream(TMP_FILE);
+ protected void save(Object o, File f) throws java.io.IOException {
+ FileOutputStream fos = new FileOutputStream(f);
ObjectOutputStream oos = new ObjectOutputStream(new
BufferedOutputStream(fos));
- oos.writeObject(xJavaDoc);
+ oos.writeObject(o);
oos.flush();
fos.close();
}
1.1 xjavadoc/src/xjavadoc/ant/XJavaDocMain.java
Index: XJavaDocMain.java
===================================================================
/*
* Copyright (c) 2001, Aslak Helles�y, BEKK Consulting
* 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;
/**
* Baseclass for classes that want to use XJavaDoc from Ant. The start method
* will be called after the XJavaDoc is initialised with SourceSets, passing in
* the argument which is optionally specified by the corresponding XJavadocTask
* subclass.
*
* @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"));
}
/**
* This method is invoked by Ant in the end of the execute method
*
* @param args Describe the command line arguments
* @todo-javadoc Describe the command line arguments
*/
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();
}
}
/**
* Describe what the method does
*
* @param fileName Describe what the parameter does
* @return Describe the return value
* @exception IOException Describe the exception
* @exception ClassNotFoundException Describe the exception
* @todo-javadoc Write javadocs for method parameter
* @todo-javadoc Write javadocs for method parameter
* @todo-javadoc Write javadocs for return value
* @todo-javadoc Write javadocs for method parameter
* @todo-javadoc Write javadocs for method parameter
* @todo-javadoc Write javadocs for method
* @todo-javadoc Write javadocs for return value
* @todo-javadoc Write javadocs for exception
* @todo-javadoc Write javadocs for exception
*/
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
*
* @param serialisedSourceSets Describe what the parameter does
* @exception IOException Describe the exception
* @exception ClassNotFoundException Describe the exception
* @todo-javadoc Write javadocs for method
* @todo-javadoc Write javadocs for method parameter
* @todo-javadoc Write javadocs for exception
* @todo-javadoc Write javadocs for exception
*/
protected static void loadSourceSets(String serialisedSourceSets) throws
IOException, ClassNotFoundException {
SourceSet[] sourceSets =
(SourceSet[])loadAndDelete(serialisedSourceSets);
for (int i = 0; i < sourceSets.length; i++) {
XJavaDoc.getInstance().addSourceSet(sourceSets[i]);
}
}
}
_______________________________________________
Xdoclet-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-devel