Skip to content

Commit 1edbbb0

Browse files
fhassakjyemin
authored andcommitted
JAVA-2560 : Use jdk.javadoc.doclet package
This change adds a requirement that a minimum of Java 9 is used to build the driver, as the jdk.javadoc.doclet package was introduced in Java 9.
1 parent 531a4d9 commit 1edbbb0

File tree

9 files changed

+42
-89
lines changed

9 files changed

+42
-89
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ dist: trusty
22
sudo: true
33
language: java
44
jdk:
5-
- oraclejdk8
5+
- oraclejdk9
66

77
notifications:
88
email:
@@ -38,6 +38,7 @@ before_script:
3838
script:
3939
- ./gradlew -q assemble
4040
- ./gradlew check -Ptravistest=true
41+
- ./gradlew docs
4142

4243
after_script:
4344
- pkill mongod

CONTRIBUTING.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ Pull Requests
1717

1818
Pull requests should generally be made against the master (default) branch and include relevant tests, if applicable.
1919

20-
Code should compile and tests should pass under all Java versions which the driver currently supports. Currently the Java driver
21-
supports a minimum version of Java 6. Please run './gradlew test' to confirm. By default, running the tests requires that you started a
22-
mongod server on localhost, listening on the default port and configured to run with
20+
Code should compile with a Java 9 or later `javac` executable and tests should pass under all Java versions which the driver currently
21+
supports. Currently the Java driver supports a minimum version of Java 6. Please run './gradlew test' to confirm. By default, running the
22+
tests requires that you start a mongod server on localhost, listening on the default port and configured to run with
2323
[`enableTestCommands`](http://docs.mongodb.org/manual/reference/parameters/#param.enableTestCommands), which may be set with the
2424
`--setParameter enableTestCommands=1` command-line parameter. At minimum, please test against the latest release version of the MongoDB
25-
server.
25+
server and the latest version of Java currently available.
2626

2727
The results of pull request testing will be appended to the request. If any tests do not pass, or relevant tests are not included, the
2828
pull request will not be considered.

build.gradle

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -282,14 +282,16 @@ task docs(type: Javadoc) {
282282
def setJavaDocOptions(MinimalJavadocOptions options) {
283283
options.author = true
284284
options.version = true
285-
options.links 'http://docs.oracle.com/javase/7/docs/api/'
285+
options.links 'https://docs.oracle.com/javase/9/docs/api/'
286286
options.tagletPath single(project(':util').sourceSets.main.output.classesDirs)
287287
options.taglets 'ManualTaglet'
288288
options.taglets 'DochubTaglet'
289289
options.taglets 'ServerReleaseTaglet'
290290
options.encoding = 'UTF-8'
291291
options.charSet 'UTF-8'
292292
options.docEncoding 'UTF-8'
293+
options.addBooleanOption("html4", true)
294+
options.addBooleanOption("-allow-script-in-comments", true)
293295
options.header = '''
294296
<script type="text/javascript">
295297
<!-- Set the location hash in the classFrame -->
@@ -312,15 +314,6 @@ def setJavaDocOptions(MinimalJavadocOptions options) {
312314
}
313315
</script>
314316
'''
315-
316-
// Add --allow-script-in-comments if available (since 1.8.0_121)
317-
try {
318-
if (Class.forName('com.sun.tools.doclets.formats.html.ConfigurationImpl')
319-
.newInstance().optionLength('--allow-script-in-comments') > 0) {
320-
options.addBooleanOption("-allow-script-in-comments", true)
321-
}
322-
} catch (ignored) {
323-
}
324317
}
325318

326319
//////////////////////////////////////////
@@ -331,8 +324,8 @@ task wrapper(type: Wrapper) {
331324
}
332325

333326
gradle.buildFinished { BuildResult result ->
334-
if (result.failure && !JavaVersion.current().isJava8Compatible()) {
335-
gradle.rootProject.logger.error("\nWARNING:\nJDK ${JavaVersion.VERSION_1_8} is required to build the driver: " +
327+
if (result.failure && !JavaVersion.current().isJava9Compatible()) {
328+
gradle.rootProject.logger.error("\nWARNING:\nJDK ${JavaVersion.VERSION_1_9} is required to build the driver: " +
336329
"you are using JDK ${JavaVersion.current()}.")
337330
}
338331
}

driver-core/src/main/com/mongodb/client/model/Projections.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ public static Bson fields(final Bson... projections) {
185185
*
186186
* @param projections the list of projections to combine
187187
* @return the combined projection
188-
* @mongodb.driver.manual
189188
*/
190189
public static Bson fields(final List<? extends Bson> projections) {
191190
notNull("sorts", projections);

util/build.gradle

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,8 @@
1616

1717
apply plugin: 'java'
1818

19-
sourceCompatibility = '1.6'
20-
targetCompatibility = '1.6'
21-
22-
dependencies {
23-
compile files("${System.getProperty('java.home')}/../lib/tools.jar")
24-
}
19+
sourceCompatibility = JavaVersion.VERSION_1_6
20+
targetCompatibility = JavaVersion.VERSION_1_6
2521

2622
sourceSets {
2723
main { java.srcDirs = ['src/main'] }

util/src/main/DocTaglet.java

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,57 +14,43 @@
1414
* limitations under the License.
1515
*/
1616

17-
import com.sun.javadoc.Tag;
18-
import com.sun.tools.doclets.Taglet;
17+
import com.sun.source.doctree.DocTree;
18+
import com.sun.source.doctree.UnknownBlockTagTree;
19+
import jdk.javadoc.doclet.Taglet;
20+
import javax.lang.model.element.Element;
21+
import java.util.HashSet;
22+
import java.util.List;
23+
import java.util.Set;
1924

20-
public abstract class DocTaglet implements Taglet {
21-
22-
public boolean inConstructor() {
23-
return true;
24-
}
25-
26-
public boolean inField() {
27-
return true;
28-
}
29-
30-
public boolean inMethod() {
31-
return true;
32-
}
33-
34-
public boolean inOverview() {
35-
return true;
36-
}
25+
import static java.util.Arrays.asList;
26+
import static jdk.javadoc.doclet.Taglet.Location.*;
3727

38-
public boolean inPackage() {
39-
return true;
40-
}
28+
public abstract class DocTaglet implements Taglet {
4129

42-
public boolean inType() {
43-
return true;
30+
@Override
31+
public Set<Location> getAllowedLocations() {
32+
return new HashSet<Location>(asList(CONSTRUCTOR, METHOD, FIELD, OVERVIEW, PACKAGE, TYPE));
4433
}
4534

35+
@Override
4636
public boolean isInlineTag() {
4737
return false;
4838
}
4939

50-
public String toString(final Tag[] tags) {
51-
if (tags.length == 0) {
40+
@Override
41+
public String toString(List<? extends DocTree> tags, Element element) {
42+
if (tags.size() == 0) {
5243
return null;
5344
}
5445

5546
StringBuilder buf = new StringBuilder(String.format("<dl><dt><span class=\"strong\">%s</span></dt>", getHeader()));
56-
for (Tag t : tags) {
57-
buf.append("<dd>").append(genLink(t.text())).append("</dd>");
47+
for (DocTree tag : tags) {
48+
String text = ((UnknownBlockTagTree) tag).getContent().get(0).toString();
49+
buf.append("<dd>").append(genLink(text)).append("</dd>");
5850
}
5951
return buf.toString();
6052
}
6153

62-
protected abstract String getHeader();
63-
64-
public String toString(final Tag tag) {
65-
return toString(new Tag[]{tag});
66-
}
67-
6854
protected String genLink(final String text) {
6955
String relativePath = text;
7056
String display = text;
@@ -78,5 +64,7 @@ protected String genLink(final String text) {
7864
return String.format("<a href='%s%s'>%s</a>", getBaseDocURI(), relativePath, display);
7965
}
8066

67+
protected abstract String getHeader();
68+
8169
protected abstract String getBaseDocURI();
8270
}

util/src/main/DochubTaglet.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,9 @@
1414
* limitations under the License.
1515
*/
1616

17-
import com.sun.tools.doclets.Taglet;
18-
19-
import java.util.Map;
20-
2117
public class DochubTaglet extends DocTaglet {
2218

23-
public static void register(final Map<String, Taglet> tagletMap) {
24-
DochubTaglet t = new DochubTaglet();
25-
tagletMap.put(t.getName(), t);
26-
}
27-
19+
@Override
2820
public String getName() {
2921
return "mongodb.driver.dochub";
3022
}

util/src/main/ManualTaglet.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,9 @@
1414
* limitations under the License.
1515
*/
1616

17-
import com.sun.tools.doclets.Taglet;
18-
19-
import java.util.Map;
20-
2117
public class ManualTaglet extends DocTaglet {
2218

23-
public static void register(final Map<String, Taglet> tagletMap) {
24-
ManualTaglet t = new ManualTaglet();
25-
tagletMap.put(t.getName(), t);
26-
}
27-
19+
@Override
2820
public String getName() {
2921
return "mongodb.driver.manual";
3022
}

util/src/main/ServerReleaseTaglet.java

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,21 @@
1414
* limitations under the License.
1515
*/
1616

17-
import com.sun.tools.doclets.Taglet;
18-
19-
import java.util.Map;
20-
2117
public class ServerReleaseTaglet extends DocTaglet {
2218

23-
public static void register(final Map<String, Taglet> tagletMap) {
24-
Taglet t = new ServerReleaseTaglet();
25-
tagletMap.put(t.getName(), t);
26-
}
27-
2819
@Override
2920
public String getName() {
3021
return "mongodb.server.release";
3122
}
3223

3324
@Override
34-
protected String getBaseDocURI() {
35-
return "http://docs.mongodb.org/manual/release-notes/";
25+
protected String getHeader() {
26+
return "Since server release";
3627
}
3728

3829
@Override
39-
protected String getHeader() {
40-
return "Since server release";
30+
protected String getBaseDocURI() {
31+
return "http://docs.mongodb.org/manual/release-notes/";
4132
}
33+
4234
}

0 commit comments

Comments
 (0)