1

I am writing a tool to scrape Javadoc from pre-existing Java source files and preprocess it via a custom doclet (the specifics of the processing are not relevant). I have written the doclet, and I'm able to invoke the doclet from my code via the programmatic API as indicated in the Java documentation.

It appears that this mechanism is "write-only" in the sense that the results of running the doclet, if any, cannot be transmitted back to the invoker of the execute() method through a first class Java object. Instead, I have to resort to a kludge such as writing intermediate output to a file from within the doclet and then reading that back in from my caller.

So my question: is there any way to retrieve, say, a String generated by my custom doclet directly at the invoker? For eg:

public void foo() {
    // Invoke my custom doclet via Javadoc programmatically
    com.sun.tools.javadoc.Main.execute(new String[] {"-d", "docs", "- sourcepath", "/home/usr/src", "p1", "p2"});

    // Access the String output of my doclet here
    String processedJavadoc = getTheOutputOfMyDoclet();
}

Thanks in advance!

scorpiodawg
  • 5,202
  • 3
  • 38
  • 52

1 Answers1

0

Ok, so the most elegant way I could come up with to do this is to make the doclet class use a static member variable that is set to the RootDoc instance passed in by the Javadoc harness when it invokes the doclet's start() method, and then allow access to the caller to this static member via a getter. This comes with the obvious thread safety issues of using a static member, but it has worked ok for my purposes.

scorpiodawg
  • 5,202
  • 3
  • 38
  • 52