Skip to content
This repository was archived by the owner on Dec 19, 2023. It is now read-only.

Commit d6ba2df

Browse files
juleshoubenjmisur
authored andcommitted
Jdk9doclet gradle (#261)
Hi, I added the change to support gradle for the jdk9doclet to this seperate branch. Can this be integrated into master? Kind regards, Jules Houben
1 parent 7bc0db0 commit d6ba2df

File tree

2 files changed

+112
-5
lines changed

2 files changed

+112
-5
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*-
2+
* #%L
3+
* Spring Auto REST Docs Json Doclet for JDK9+
4+
* %%
5+
* Copyright (C) 2015 - 2018 Scalable Capital GmbH
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
package capital.scalable.restdocs.jsondoclet;
21+
22+
import jdk.javadoc.doclet.Doclet;
23+
24+
import java.util.Arrays;
25+
import java.util.List;
26+
27+
public abstract class DirectoryLocationOption implements Doclet.Option, Comparable<DirectoryLocationOption> {
28+
29+
private final String[] names;
30+
private final String argumentName;
31+
private final int argumentCount;
32+
private final String description;
33+
private final String parameters;
34+
35+
public DirectoryLocationOption() {
36+
this.argumentName = "-d";
37+
this.argumentCount = 1;
38+
this.names = new String[]{argumentName};
39+
this.description = "Directory location";
40+
this.parameters = "-d";
41+
}
42+
43+
@Override
44+
public String getDescription() {
45+
return description;
46+
}
47+
48+
@Override
49+
public Kind getKind() {
50+
return Kind.STANDARD;
51+
}
52+
53+
@Override
54+
public List<String> getNames() {
55+
return Arrays.asList(names);
56+
}
57+
58+
@Override
59+
public String getParameters() {
60+
return parameters;
61+
}
62+
63+
@Override
64+
public String toString() {
65+
return Arrays.toString(names);
66+
}
67+
68+
@Override
69+
public int getArgumentCount() {
70+
return argumentCount;
71+
}
72+
73+
@Override
74+
public int compareTo(DirectoryLocationOption that) {
75+
return this.getNames().get(0).compareTo(that.getNames().get(0));
76+
}
77+
78+
79+
}

spring-auto-restdocs-json-doclet-jdk9/src/main/java/capital/scalable/restdocs/jsondoclet/ExtractDocumentationAsJsonDoclet.java

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@
3131
import java.nio.file.Files;
3232
import java.nio.file.Path;
3333
import java.nio.file.Paths;
34+
import java.util.*;
3435

3536
import com.fasterxml.jackson.annotation.JsonAutoDetect;
3637
import com.fasterxml.jackson.databind.ObjectMapper;
38+
import jdk.javadoc.doclet.Doclet;
3739
import jdk.javadoc.doclet.DocletEnvironment;
3840
import jdk.javadoc.doclet.StandardDoclet;
3941

@@ -42,10 +44,12 @@
4244
*/
4345
public 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

Comments
 (0)