Skip to content

Commit 5b0c9cc

Browse files
8274172: Convert JavadocTester to use NIO
Reviewed-by: prappo
1 parent 2657bcb commit 5b0c9cc

File tree

8 files changed

+152
-140
lines changed

8 files changed

+152
-140
lines changed

test/langtools/jdk/javadoc/doclet/testDocFileDir/TestDocFileDir.java

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -28,13 +28,14 @@
2828
* get overwritten when the sourcepath is equal to the destination
2929
* directory.
3030
* Also test that -docfilessubdirs and -excludedocfilessubdir both work.
31-
* @library ../../lib
31+
* @library /tools/lib ../../lib
3232
* @modules jdk.javadoc/jdk.javadoc.internal.tool
33-
* @build javadoc.tester.*
33+
* @build toolbox.ToolBox javadoc.tester.*
3434
* @run main TestDocFileDir
3535
*/
3636

3737
import javadoc.tester.JavadocTester;
38+
import toolbox.ToolBox;
3839

3940
public class TestDocFileDir extends JavadocTester {
4041

@@ -43,10 +44,12 @@ public static void main(String... args) throws Exception {
4344
tester.runTests();
4445
}
4546

47+
ToolBox tb = new ToolBox();
48+
4649
// Output dir = "", Input dir = ""
4750
@Test
4851
public void test1() {
49-
copyDir(testSrc("pkg"), ".");
52+
tb.copyDir(testSrc("pkg"), "pkg");
5053
setOutputDirectoryCheck(DirectoryCheck.NO_HTML_FILES);
5154
javadoc("pkg/C.java");
5255
checkExit(Exit.OK);
@@ -58,7 +61,7 @@ public void test1() {
5861
@Test
5962
public void test2() {
6063
String outdir = "out2";
61-
copyDir(testSrc("pkg"), outdir);
64+
tb.copyDir(testSrc("pkg"), outdir + "/pkg");
6265
setOutputDirectoryCheck(DirectoryCheck.NO_HTML_FILES);
6366
javadoc("-d", outdir,
6467
"-sourcepath", "blah" + PS + outdir + PS + "blah",

test/langtools/jdk/javadoc/doclet/testMetadata/TestMetadata.java

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -165,9 +165,8 @@ public void runTests() throws Exception {
165165
);
166166

167167
void checkBodyClasses() throws IOException {
168-
Path outputDirPath = outputDir.toPath();
169-
for (Path p : tb.findFiles(".html", outputDirPath)) {
170-
checkBodyClass(outputDirPath.relativize(p));
168+
for (Path p : tb.findFiles(".html", outputDir)) {
169+
checkBodyClass(outputDir.relativize(p));
171170
}
172171
}
173172

@@ -231,9 +230,8 @@ void checkBodyClass(Path p) {
231230
);
232231

233232
void checkMetadata() throws IOException {
234-
Path outputDirPath = outputDir.toPath();
235-
for (Path p : tb.findFiles(".html", outputDirPath)) {
236-
checkMetadata(outputDirPath.relativize(p));
233+
for (Path p : tb.findFiles(".html", outputDir)) {
234+
checkMetadata(outputDir.relativize(p));
237235
}
238236
}
239237

test/langtools/jdk/javadoc/doclet/testRelativeLinks/TestRelativeLinks.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
import java.io.File;
3636
import java.io.FileOutputStream;
3737
import java.io.IOException;
38+
import java.io.OutputStream;
39+
import java.nio.file.Files;
40+
import java.nio.file.Path;
3841

3942
import javadoc.tester.JavadocTester;
4043

@@ -200,9 +203,9 @@ public void checkLinks() {
200203
}
201204

202205
private void touch(String file) {
203-
File f = new File(outputDir, file);
206+
Path f = outputDir.resolve(file);
204207
out.println("touch " + f);
205-
try (FileOutputStream fos = new FileOutputStream(f)) {
208+
try (OutputStream fos = Files.newOutputStream(f)) {
206209
} catch (IOException e) {
207210
checking("Touch file");
208211
failed("Error creating file: " + e);

test/langtools/jdk/javadoc/doclet/testSearchScript/TestSearchScript.java

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -41,10 +41,9 @@
4141
import javax.script.ScriptEngine;
4242
import javax.script.ScriptEngineManager;
4343
import javax.script.ScriptException;
44-
import java.io.BufferedReader;
45-
import java.io.File;
46-
import java.io.FileReader;
4744
import java.io.IOException;
45+
import java.nio.file.Files;
46+
import java.nio.file.Path;
4847
import java.util.List;
4948

5049
import jtreg.SkippedException;
@@ -71,9 +70,9 @@ private Invocable getEngine() throws ScriptException, IOException, NoSuchMethodE
7170
// see https://github.com/graalvm/graaljs/blob/master/docs/user/ScriptEngine.md
7271
Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE);
7372
bindings.put("polyglot.js.nashorn-compat", true);
74-
engine.eval(new BufferedReader(new FileReader(new File(testSrc, "javadoc-search.js"))));
73+
engine.eval(Files.newBufferedReader(Path.of(testSrc).resolve("javadoc-search.js")));
7574
Invocable inv = (Invocable) engine;
76-
inv.invokeFunction("loadIndexFiles", outputDir.getAbsolutePath());
75+
inv.invokeFunction("loadIndexFiles", outputDir.toAbsolutePath().toString());
7776
return inv;
7877
}
7978

test/langtools/jdk/javadoc/doclet/testSingletonLists/TestSingletonLists.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ void checkLists() {
206206
checking("Check lists");
207207
ListChecker c = new ListChecker(out, this::readFile);
208208
try {
209-
c.checkDirectory(outputDir.toPath());
209+
c.checkDirectory(outputDir);
210210
c.report();
211211
int errors = c.getErrorCount();
212212
if (errors == 0) {

test/langtools/jdk/javadoc/doclet/testStylesheet/TestStylesheet.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ void checkStyles(Set<String> styles) {
381381
checking("Check CSS class names");
382382
CSSClassChecker c = new CSSClassChecker(out, this::readFile, styles);
383383
try {
384-
c.checkDirectory(outputDir.toPath());
384+
c.checkDirectory(outputDir);
385385
c.report();
386386
int errors = c.getErrorCount();
387387
if (errors == 0) {

0 commit comments

Comments
 (0)