I’m using a GitHub hosted project that’s developed a JavaDoc doclet. In my Gradle build file, I’ve created a task to configure and run the doclet (and generate the associated JavaDoc):
task generateRestApiDocs(type: Javadoc) {
source = sourceSets.main.allJava
// Save the output into web directory under apidocs
def file = new File("web/apidocs")
destinationDir = file
options.classpath = configurations.doclet.files.asType(List)
options.docletpath = configurations.doclet.files.asType(List)
// Use the Swagger JAXRS doclet
options.doclet = "com.carma.swagger.doclet.ServiceDoclet"
}
One of the options of the Doclet I’m using is to pass a list of packages to exclude from documentation generation.
It’s property is called: excludeResourcePrefixes
.
Internally, the library is doing the following to extract the values and use them:
} else if (option[0].equals("-excludeResourcePrefixes")) {
parsedOptions.excludeResourcePrefixes.addAll(asList(copyOfRange(option, 1, option.length)));
The options property above is the default String[][]
found on JavaDoc’s RootDoc.java#options
. According to RootDoc.java
comments, options passed in as an array will be treated as String[][]:
/**
* Command line options.
* <p>
* For example, given:
* <pre>
* javadoc -foo this that -bar other ...</pre>
*
* this method will return:
* <pre>
* options()[0][0] = "-foo"
* options()[0][1] = "this"
* options()[0][2] = "that"
* options()[1][0] = "-bar"
* options()[1][1] = "other"</pre>
*
* @return an array of arrays of String.
*/
String[][] options();
So what I need to do is pass an array of values for the excludeResourcePrefixes
property.
I tried several different addXX
methods on the CoreJavadocOptions.java
class but none of them seem to work completely correct.
What I need in my JavaDoc options “file” is:
-excludeResourcePrefixes com.me.server.rest.administration com.me.server.rest.workspace
Here is what I tried:
options.addStringsOption("excludeResourcePrefixes").setValue([
"com.me.server.rest.administration",
"com.me.server.rest.workspace"
])
Creates:
-excludeResourcePrefixes 'com.me.server.rest.administration:com.me.server.rest.workspace'
Won’t work b/c we need items to be separated and also not wrapped as a single string (e.g. ‘’).
Next:
options.addStringsOption("excludeResourcePrefixes", " ").setValue([
"com.me.server.rest.administration",
"com.me.server.rest.workspace"
])
This produces and won’t work again because the items are being treated as a single string:
-excludeResourcePrefixes 'com.me.server.rest.administration com.me.server.rest.workspace'
Unfortunately, the only thing I could get to work was:
options.addMultilineStringsOption("excludeResourcePrefixes").setValue([
"com.me.server.rest.administration",
"com.me.server.rest.workspace"
])
This produced:
-excludeResourcePrefixes 'com.me.server.rest.administration'
-excludeResourcePrefixes 'com.me.server.rest.workspace'
While not ideal, it does work because luckily Swagger-Jaxrs-Doclet’s DocletOptions.java
class will loop through all the options and will just add any duplicate options to the existing excludes collection versus overwriting it:
} else if (option[0].equals("-excludeResourcePrefixes")) {
parsedOptions.excludeResourcePrefixes.addAll(asList(copyOfRange(option, 1, option.length)));
So my ultimate question, is how can I use CoreJavadocOptions.java
to add an ‘array’ of command-line arguments to the JavaDoc options object so that they will be correctly “arrayed” by the RootDoc class?
In some ways I think a new addArrayOption(String name, List values) would be a worthy addition to the CoreJavadocOptions.java
class.