8279513: jdk/javadoc/doclet/testDocletExample/TestDocletExample.java fails after 8278795

Reviewed-by: prappo
This commit is contained in:
Jonathan Gibbons 2022-05-25 17:45:02 +00:00
parent f786e2a22f
commit 7156f98e32
3 changed files with 44 additions and 7 deletions

View File

@ -9,7 +9,7 @@
# should be taken to handle test failures of intermittent or
# randomness tests.
keys=intermittent randomness
keys=intermittent randomness needs-src needs-src-jdk_javadoc
# Group definitions
groups=TEST.groups

View File

@ -25,6 +25,7 @@
* @test
* @bug 8272944
* @summary Use snippets in jdk.javadoc documentation
* @key needs-src needs-src-jdk_javadoc
* @library /tools/lib ../../lib
* @modules jdk.compiler/com.sun.tools.javac.api
* jdk.compiler/com.sun.tools.javac.main
@ -53,11 +54,12 @@ public class TestDocletExample extends TestRunner {
t.runTests(m -> new Object[] { Path.of(m.getName()) });
}
SnippetUtils snippets = new SnippetUtils("jdk.javadoc");
SnippetUtils snippets;
ToolBox tb = new ToolBox();
TestDocletExample() {
TestDocletExample() throws SnippetUtils.ConfigurationException {
super(System.out);
snippets = new SnippetUtils("jdk.javadoc");
}
@Test
@ -65,6 +67,9 @@ public class TestDocletExample extends TestRunner {
var docletPkg = snippets.getElements().getPackageElement("jdk.javadoc.doclet");
var dc = snippets.getDocTrees().getDocCommentTree(docletPkg);
var entryPointSnippet = snippets.getSnippetById(dc, "entry-point");
if (entryPointSnippet == null) {
throw new Error("Cannot find snippet \"entry-point\"");
}
var entryPointCode = entryPointSnippet.getBody().getBody();
var code = """
class C {
@ -89,6 +94,9 @@ public class TestDocletExample extends TestRunner {
var docletPkg = snippets.getElements().getPackageElement("jdk.javadoc.doclet");
var dc = snippets.getDocTrees().getDocCommentTree(docletPkg);
var exampleSnippet = snippets.getSnippetById(dc, "Example.java");
if (exampleSnippet == null) {
throw new Error("Cannot find snippet \"Example.java\"");
}
var exampleCode = exampleSnippet.getBody().getBody();
// compile it

View File

@ -24,6 +24,7 @@
package snippets;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.URI;
@ -86,6 +87,16 @@ import com.sun.source.util.JavacTask;
* code to compile and run snippets, where that is appropriate.
*/
public class SnippetUtils {
/**
* Exception used to report a configuration issue that prevents
* the test from executing as expected.
*/
public static class ConfigurationException extends Exception {
public ConfigurationException(String message) {
super(message);
}
}
private static final JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
private final StandardJavaFileManager fileManager;
@ -105,8 +116,10 @@ public class SnippetUtils {
* @param modules the modules
*
* @throws IllegalArgumentException if no modules are specified
* @throws ConfigurationException if the main source directory cannot be found
* or if a module's source directory cannot be found
*/
public SnippetUtils(String... modules) {
public SnippetUtils(String... modules) throws ConfigurationException {
this(findSourceDir(), null, null, Set.of(modules));
}
@ -126,13 +139,29 @@ public class SnippetUtils {
* @param modules the modules
*
* @throws IllegalArgumentException if no modules are specified
* @throws ConfigurationException if {@code srcDir} does not exist
* or if a module's source directory cannot be found
*/
public SnippetUtils(Path srcDir, PrintWriter pw, DiagnosticListener<JavaFileObject> dl, Set<String> modules) {
public SnippetUtils(Path srcDir, PrintWriter pw, DiagnosticListener<JavaFileObject> dl, Set<String> modules)
throws ConfigurationException {
if (modules.isEmpty()) {
throw new IllegalArgumentException("no modules specified");
}
if (!Files.exists(srcDir)) {
throw new ConfigurationException("directory not found: " + srcDir);
}
this.srcDir = srcDir;
for (var m : modules) {
var moduleSourceDir = getModuleSourceDir(m);
if (!Files.exists(moduleSourceDir)) {
throw new ConfigurationException(("cannot find source directory for " + m
+ ": " + moduleSourceDir));
}
}
fileManager = compiler.getStandardFileManager(dl, null, null);
List<String> opts = new ArrayList<>();
@ -528,7 +557,7 @@ public class SnippetUtils {
return SourceKind.OTHER;
}
private static Path findSourceDir() {
private static Path findSourceDir() throws ConfigurationException {
String testSrc = System.getProperty("test.src");
Path p = Path.of(testSrc).toAbsolutePath();
while (p.getParent() != null) {
@ -538,6 +567,6 @@ public class SnippetUtils {
}
p = p.getParent();
}
throw new IllegalArgumentException("Cannot find src/ from " + testSrc);
throw new ConfigurationException("Cannot find src/ from " + testSrc);
}
}