edu.rice.cs.drjava.model.javadoc
Class DefaultJavadocModel

java.lang.Object
  extended by edu.rice.cs.drjava.model.javadoc.DefaultJavadocModel
All Implemented Interfaces:
JavadocModel

public class DefaultJavadocModel
extends Object
implements JavadocModel

Default implementation of JavadocModel interface; generates Javadoc HTML files for a set of documents.

Version:
$Id: DefaultJavadocModel.java 5553 2012-05-01 17:28:45Z rcartwright $

Field Summary
private  CompilerErrorModel _javadocErrorModel
          The error model containing all current Javadoc errors.
private  JVMBuilder _jvmBuilder
          Launcher for javadoc process
private  GlobalModel _model
          Used by CompilerErrorModel to open documents that have errors.
private  JavadocEventNotifier _notifier
          Manages listeners to this model.
 
Fields inherited from interface edu.rice.cs.drjava.model.javadoc.JavadocModel
SUGGESTED_DIR_NAME
 
Constructor Summary
DefaultJavadocModel(GlobalModel model, File javaCommand, Iterable<File> toolsPath)
          Main constructor.
 
Method Summary
private  void _attemptSaveAllDocuments()
          If any documents are modified, this gives the user a chance to save them before proceeding.
private  List<DJError> _extractErrors(String text)
          Reads through javadoc output text, looking for Javadoc errors.
private  File _getFileFromDocument(OpenDefinitionsDocument doc, FileSaveSelector saver)
          Attempts to get the file from the given document.
private  Iterable<String> _getLinkArgs()
           
private  void _javadocAllWorker(File destDirFile, FileSaveSelector saver)
          This method handles most of the logic of performing a Javadoc operation, once we know that it won't be canceled.
private  void _notifyCompileBeforeJavadoc(CompilerListener afterCompile)
          Helper method to notify JavadocModel listeners that all open files must be compiled before Javadoc is run.
private  DJError _parseJavadocErrorLine(String line)
          Convert a line of Javadoc text to a DJError.
private  void _rawJavadocDocument(File file)
           
private  void _runJavadoc(Iterable<String> files, File destDir, Iterable<String> extraArgs, boolean allDocs)
          Run a new process to generate javdocs, and then tell the listeners when we're done.
 void addListener(JavadocListener listener)
          Add a JavadocListener to the model.
 CompilerErrorModel getJavadocErrorModel()
          Accessor for the Javadoc error model.
 boolean isAvailable()
          true iff the classes to run javadoc are available
 void javadocAll(DirectorySelector select, FileSaveSelector saver)
          Javadocs all open documents, after ensuring that all are saved.
 void javadocDocument(OpenDefinitionsDocument doc, FileSaveSelector saver)
          Generates Javadoc for the given document only, after ensuring it is saved.
 void removeAllListeners()
          Removes all JavadocListeners from this model.
 void removeListener(JavadocListener listener)
          Remove a JavadocListener from the model.
 void resetJavadocErrors()
          Clears all current Javadoc errors.
 File suggestJavadocDestination(OpenDefinitionsDocument doc)
          Suggests a default location for generating Javadoc, based on the given document's source root.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_model

private GlobalModel _model
Used by CompilerErrorModel to open documents that have errors.


_notifier

private final JavadocEventNotifier _notifier
Manages listeners to this model.


_jvmBuilder

private final JVMBuilder _jvmBuilder
Launcher for javadoc process


_javadocErrorModel

private CompilerErrorModel _javadocErrorModel
The error model containing all current Javadoc errors.

Constructor Detail

DefaultJavadocModel

public DefaultJavadocModel(GlobalModel model,
                           File javaCommand,
                           Iterable<File> toolsPath)
Main constructor.

Parameters:
model - Source of documents for this JavadocModel
javaCommand - Location of the java command to use (null means the default: java.home)
toolsPath - Location of the tools library containing the javadoc code (null means the default: javaCommand's boot class path)
Method Detail

isAvailable

public boolean isAvailable()
Description copied from interface: JavadocModel
true iff the classes to run javadoc are available

Specified by:
isAvailable in interface JavadocModel

addListener

public void addListener(JavadocListener listener)
Add a JavadocListener to the model.

Specified by:
addListener in interface JavadocModel
Parameters:
listener - a listener that reacts to Javadoc events

removeListener

public void removeListener(JavadocListener listener)
Remove a JavadocListener from the model. If the listener is not installed, this method has no effect.

Specified by:
removeListener in interface JavadocModel
Parameters:
listener - a listener that reacts to Javadoc events

removeAllListeners

public void removeAllListeners()
Removes all JavadocListeners from this model.

Specified by:
removeAllListeners in interface JavadocModel

getJavadocErrorModel

public CompilerErrorModel getJavadocErrorModel()
Accessor for the Javadoc error model.

Specified by:
getJavadocErrorModel in interface JavadocModel
Returns:
the ErrorModel managing Javadoc errors.

resetJavadocErrors

public void resetJavadocErrors()
Clears all current Javadoc errors.

Specified by:
resetJavadocErrors in interface JavadocModel

javadocAll

public void javadocAll(DirectorySelector select,
                       FileSaveSelector saver)
                throws IOException
Javadocs all open documents, after ensuring that all are saved. The user provides a destination, and the global model provides the package info. Must run in the event-handling thread.

Specified by:
javadocAll in interface JavadocModel
Parameters:
select - a command object for selecting a directory and warning a user about bad input
saver - a command object for saving a document (if it moved/changed)
Throws:
IOException - if there is a problem manipulating files

_javadocAllWorker

private void _javadocAllWorker(File destDirFile,
                               FileSaveSelector saver)
This method handles most of the logic of performing a Javadoc operation, once we know that it won't be canceled.

Parameters:
destDirFile - the destination directory for the doc files
saver - a command object for saving a document (if it moved/changed)

javadocDocument

public void javadocDocument(OpenDefinitionsDocument doc,
                            FileSaveSelector saver)
                     throws IOException
Generates Javadoc for the given document only, after ensuring it is saved. Saves the output in a temp directory which is passed to _javadocDocuemntWorker, which is passed to a subsequent javadocEnded event.

Specified by:
javadocDocument in interface JavadocModel
Parameters:
doc - Document to generate Javadoc for
saver - a command object for saving the document (if it moved/changed)
Throws:
IOException - if there is a problem manipulating files

_rawJavadocDocument

private void _rawJavadocDocument(File file)
                          throws IOException
Throws:
IOException

_notifyCompileBeforeJavadoc

private void _notifyCompileBeforeJavadoc(CompilerListener afterCompile)
Helper method to notify JavadocModel listeners that all open files must be compiled before Javadoc is run.


suggestJavadocDestination

public File suggestJavadocDestination(OpenDefinitionsDocument doc)
Suggests a default location for generating Javadoc, based on the given document's source root. (Appends JavadocModel.SUGGESTED_DIR_NAME to the sourceroot.) Ensures that the document is saved first, or else no reasonable suggestion will be found.

Specified by:
suggestJavadocDestination in interface JavadocModel
Parameters:
doc - Document with the source root to use as the default.
Returns:
Suggested destination directory, or null if none could be determined.

_attemptSaveAllDocuments

private void _attemptSaveAllDocuments()
If any documents are modified, this gives the user a chance to save them before proceeding. Callers can check _getter.hasModifiedDocuments() after calling this method to determine if the user cancelled the save process.


_runJavadoc

private void _runJavadoc(Iterable<String> files,
                         File destDir,
                         Iterable<String> extraArgs,
                         boolean allDocs)
Run a new process to generate javdocs, and then tell the listeners when we're done.

Parameters:
files - List of files to generate
destDir - Directory where the results are being saved
extraArgs - List of additional arguments to use with javadoc (besides those gathered from config settings)
allDocs - Whether this is running on all documents. If Javadoc is not run on all documents, the target directory will be deleted when DrJava exits

_getLinkArgs

private Iterable<String> _getLinkArgs()

_extractErrors

private List<DJError> _extractErrors(String text)
Reads through javadoc output text, looking for Javadoc errors. This code will detect Exceptions and Errors thrown during generation of the output, as well as errors and warnings generated by Javadoc. This code works for both JDK 1.3 and 1.4, assuming you pass in data from the correct stream. (Be safe and check both.)


_parseJavadocErrorLine

private DJError _parseJavadocErrorLine(String line)
Convert a line of Javadoc text to a DJError. If unable to do so, returns null.


_getFileFromDocument

private File _getFileFromDocument(OpenDefinitionsDocument doc,
                                  FileSaveSelector saver)
                           throws IOException
Attempts to get the file from the given document. If the file has moved, we use the given FileSaveSelector to let the user save it in a new location.

Parameters:
doc - OpenDefinitionsDocument from which to get the file
saver - FileSaveSelector to allow the user to save the file if it has moved.
Throws:
IllegalStateException - if the doc has no file (hasn't been saved)
IOException - if the file can't be saved after it was moved