Skip to content

Commit

Permalink
8274172: Convert JavadocTester to use NIO
Browse files Browse the repository at this point in the history
Reviewed-by: prappo
  • Loading branch information
jonathan-gibbons committed Sep 28, 2021
1 parent 2657bcb commit 5b0c9cc
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 140 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -28,13 +28,14 @@
* get overwritten when the sourcepath is equal to the destination
* directory.
* Also test that -docfilessubdirs and -excludedocfilessubdir both work.
* @library ../../lib
* @library /tools/lib ../../lib
* @modules jdk.javadoc/jdk.javadoc.internal.tool
* @build javadoc.tester.*
* @build toolbox.ToolBox javadoc.tester.*
* @run main TestDocFileDir
*/

import javadoc.tester.JavadocTester;
import toolbox.ToolBox;

public class TestDocFileDir extends JavadocTester {

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

ToolBox tb = new ToolBox();

// Output dir = "", Input dir = ""
@Test
public void test1() {
copyDir(testSrc("pkg"), ".");
tb.copyDir(testSrc("pkg"), "pkg");
setOutputDirectoryCheck(DirectoryCheck.NO_HTML_FILES);
javadoc("pkg/C.java");
checkExit(Exit.OK);
Expand All @@ -58,7 +61,7 @@ public void test1() {
@Test
public void test2() {
String outdir = "out2";
copyDir(testSrc("pkg"), outdir);
tb.copyDir(testSrc("pkg"), outdir + "/pkg");
setOutputDirectoryCheck(DirectoryCheck.NO_HTML_FILES);
javadoc("-d", outdir,
"-sourcepath", "blah" + PS + outdir + PS + "blah",
Expand Down
12 changes: 5 additions & 7 deletions test/langtools/jdk/javadoc/doclet/testMetadata/TestMetadata.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -165,9 +165,8 @@ public void runTests() throws Exception {
);

void checkBodyClasses() throws IOException {
Path outputDirPath = outputDir.toPath();
for (Path p : tb.findFiles(".html", outputDirPath)) {
checkBodyClass(outputDirPath.relativize(p));
for (Path p : tb.findFiles(".html", outputDir)) {
checkBodyClass(outputDir.relativize(p));
}
}

Expand Down Expand Up @@ -231,9 +230,8 @@ void checkBodyClass(Path p) {
);

void checkMetadata() throws IOException {
Path outputDirPath = outputDir.toPath();
for (Path p : tb.findFiles(".html", outputDirPath)) {
checkMetadata(outputDirPath.relativize(p));
for (Path p : tb.findFiles(".html", outputDir)) {
checkMetadata(outputDir.relativize(p));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;

import javadoc.tester.JavadocTester;

Expand Down Expand Up @@ -200,9 +203,9 @@ public void checkLinks() {
}

private void touch(String file) {
File f = new File(outputDir, file);
Path f = outputDir.resolve(file);
out.println("touch " + f);
try (FileOutputStream fos = new FileOutputStream(f)) {
try (OutputStream fos = Files.newOutputStream(f)) {
} catch (IOException e) {
checking("Touch file");
failed("Error creating file: " + e);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -41,10 +41,9 @@
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ void checkLists() {
checking("Check lists");
ListChecker c = new ListChecker(out, this::readFile);
try {
c.checkDirectory(outputDir.toPath());
c.checkDirectory(outputDir);
c.report();
int errors = c.getErrorCount();
if (errors == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ void checkStyles(Set<String> styles) {
checking("Check CSS class names");
CSSClassChecker c = new CSSClassChecker(out, this::readFile, styles);
try {
c.checkDirectory(outputDir.toPath());
c.checkDirectory(outputDir);
c.report();
int errors = c.getErrorCount();
if (errors == 0) {
Expand Down
Loading

3 comments on commit 5b0c9cc

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GoeLin
Copy link
Member

@GoeLin GoeLin commented on 5b0c9cc Mar 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk17u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 5b0c9cc Mar 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GoeLin the backport was successfully created on the branch GoeLin-backport-5b0c9ccc in my personal fork of openjdk/jdk17u-dev. To create a pull request with this backport targeting openjdk/jdk17u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 5b0c9ccc from the openjdk/jdk repository.

The commit being backported was authored by Jonathan Gibbons on 28 Sep 2021 and was reviewed by Pavel Rappo.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk17u-dev:

$ git fetch https://github.com/openjdk-bots/jdk17u-dev GoeLin-backport-5b0c9ccc:GoeLin-backport-5b0c9ccc
$ git checkout GoeLin-backport-5b0c9ccc
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk17u-dev GoeLin-backport-5b0c9ccc

Please sign in to comment.