3131import java .nio .file .Files ;
3232import java .nio .file .Path ;
3333import java .nio .file .Paths ;
34+ import java .util .*;
3435
3536import com .fasterxml .jackson .annotation .JsonAutoDetect ;
3637import com .fasterxml .jackson .databind .ObjectMapper ;
38+ import jdk .javadoc .doclet .Doclet ;
3739import jdk .javadoc .doclet .DocletEnvironment ;
3840import jdk .javadoc .doclet .StandardDoclet ;
3941
4244 */
4345public class ExtractDocumentationAsJsonDoclet extends StandardDoclet {
4446
47+ private String directoryLocationPath ;
48+
49+
4550 @ Override
4651 public boolean run (DocletEnvironment docEnv ) {
47-
48- Path destinationDir = Paths .get ("../generated-javadoc-json" ).toAbsolutePath ();
52+ Path destinationDir = getDestinationDir ();
4953 ObjectMapper mapper = createObjectMapper ();
5054
5155 docEnv .getIncludedElements ()
@@ -62,6 +66,30 @@ public boolean run(DocletEnvironment docEnv) {
6266 return true ;
6367 }
6468
69+ private Path getDestinationDir () {
70+ if (directoryLocationPath != null ) {
71+ return Paths .get (directoryLocationPath ).toAbsolutePath ();
72+ } else {
73+ return Paths .get ("../generated-javadoc-json" ).toAbsolutePath ();
74+ }
75+ }
76+
77+ @ Override
78+ public Set <Doclet .Option > getSupportedOptions () {
79+ Set <Doclet .Option > result = new HashSet <>();
80+
81+ Doclet .Option directoryLocationOption = new DirectoryLocationOption () {
82+ @ Override
83+ public boolean process (String opt , List <String > args ) {
84+ directoryLocationPath = args .get (0 );
85+ return true ;
86+ }
87+ };
88+ result .add (directoryLocationOption );
89+ result .addAll (super .getSupportedOptions ());
90+ return result ;
91+ }
92+
6593 private static PackageElement findPackageElement (Element classOrInterface ) {
6694 Element pkg = classOrInterface .getEnclosingElement ();
6795 int i = 10 ;
@@ -76,8 +104,8 @@ private static PackageElement findPackageElement(Element classOrInterface) {
76104 }
77105
78106 private static void writeToFile (Path destinationDir , ObjectMapper mapper ,
79- PackageElement packageElement , TypeElement classOrInterface ,
80- ClassDocumentation cd ) {
107+ PackageElement packageElement , TypeElement classOrInterface ,
108+ ClassDocumentation cd ) {
81109 try {
82110 Path path = path (destinationDir , packageElement , classOrInterface );
83111 try (BufferedWriter writer = Files .newBufferedWriter (path , UTF_8 )) {
@@ -90,7 +118,7 @@ private static void writeToFile(Path destinationDir, ObjectMapper mapper,
90118 }
91119
92120 private static Path path (Path destinationDir , PackageElement packageElement ,
93- TypeElement classOrInterface ) throws IOException {
121+ TypeElement classOrInterface ) throws IOException {
94122 String packageName = packageElement .getQualifiedName ().toString ();
95123 String packageDir = packageName .replace ("." , File .separator );
96124 Path packagePath = Paths .get (packageDir );
0 commit comments