Skip to content
Permalink
Browse files
8274172: Convert JavadocTester to use NIO
Reviewed-by: prappo
  • Loading branch information
jonathan-gibbons committed Sep 28, 2021
1 parent 2657bcb commit 5b0c9ccc495b6bf8061c161d48f73238c7167bc0
@@ -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
@@ -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 {

@@ -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);
@@ -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",
@@ -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
@@ -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));
}
}

@@ -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));
}
}

@@ -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;

@@ -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);
@@ -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
@@ -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;
@@ -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;
}

@@ -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) {
@@ -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) {
Loading

1 comment on commit 5b0c9cc

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on 5b0c9cc Sep 29, 2021

Please sign in to comment.