# HG changeset patch
# User ksrini
# Date 1447967656 28800
# Node ID e9fccc09cfc633138b1bcf85372c0e8c4a8052b8
# Parent 6d7a40b2a54b24acf4414be72785dc4125af922f
8130880: Create sampleapi regression test
Reviewed-by: ksrini, vromero
Contributed-by: sergei.pikalev@oracle.com
diff -r 6d7a40b2a54b -r e9fccc09cfc6 langtools/test/tools/javadoc/sampleapi/README.txt
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javadoc/sampleapi/README.txt Thu Nov 19 13:14:16 2015 -0800
@@ -0,0 +1,59 @@
+
+ SampleAPI Generator for javadoc
+
+1. General description
+
+ The primary goal is to provide one or more data sets to be used as input
+to the javadoc tool, such that it can be used to generate representative samples
+of all the different content on all the different types of pages that can be
+generated by javadoc.
+
+ The tool is implemented as generator based on xml descriptions of data sets.
+The xml description of data set provides top level entities (class, interface,
+enum, annotation) with all possible content. Desired output parameters (fields,
+methods, inner/nested classes) are also described in xml as lists of modifiers,
+types and annotations. The generator "multiply" the entities from the lists
+providing the set of all possible combinations.
+
+ After the api generation the tool connects the javadoc style comments to
+the generated entities with full possible sets of supported tags.
+
+2. Tool structure
+
+ Sources:
+ test/tools/javadoc/sampleapi/lib - generator sources
+ test/tools/javadoc/sampleapi/res/xml - sample data sets in xml
+ test/tools/javadoc/sampleapi/res/txt - sample texts for doc comments
+
+3. Public API
+
+3.1 Command line runner
+
+ * test/tools/javadoc/sampleapi/lib/sampleapi/SampleApiDefaultRunner.java
+
+ class sampleapi.SampleApiDefaultRunner
+
+ Options: [-?|-h|--help] [-o:
|--outdir:]
+ -?|-h|--help - print help
+ -o:|--outdir: - set to generate output
+
+3.2 Programmatic access
+
+ * test/tools/javadoc/sampleapi/lib/sampleapi/SampleApi.java
+
+ class sampleapi.SampleApi
+
+ public void generate(File dir)
+ public void generate(Path dir)
+ public void generate(String dir)
+
+3.3 How to run other xml data set description
+
+ Put data set xml description into res/xml directory
+
+ * test/tools/javadoc/sampleapi/lib/sampleapi/generator/PackageGenerator.java
+
+ class sampleapi.generator.PackageGenerator
+
+ public void processDataSet(String dsName)
+ public void generate(File outDir)
diff -r 6d7a40b2a54b -r e9fccc09cfc6 langtools/test/tools/javadoc/sampleapi/SampleApiTest.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javadoc/sampleapi/SampleApiTest.java Thu Nov 19 13:14:16 2015 -0800
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2015, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8130880
+ * @library lib
+ * @run main sampleapi.SampleApiDefaultRunner -o:out/src
+ * @run main SampleApiTest
+ */
+
+import com.sun.tools.javadoc.*;
+import java.nio.file.Paths;
+
+public class SampleApiTest {
+
+ public static void main(String... args) {
+
+ // html4
+ Main.execute(
+ new String[] {
+ "-d", "out/doc.html4",
+ "-verbose",
+ "-private",
+ "-use",
+ "-splitindex",
+ "-linksource",
+ "-html4",
+ "-javafx",
+ "-windowtitle", "SampleAPI",
+ "-sourcepath", "out/src",
+ "sampleapi.simple",
+ "sampleapi.tiny",
+ "sampleapi.fx"
+ });
+
+ // html5
+ Main.execute(
+ new String[] {
+ "-d", "out/doc.html5",
+ "-verbose",
+ "-private",
+ "-use",
+ "-splitindex",
+ "-linksource",
+ "-html5",
+ "-javafx",
+ "-windowtitle", "SampleAPI",
+ "-sourcepath", "out/src",
+ "sampleapi.simple",
+ "sampleapi.tiny",
+ "sampleapi.fx"
+ });
+ }
+}
diff -r 6d7a40b2a54b -r e9fccc09cfc6 langtools/test/tools/javadoc/sampleapi/lib/sampleapi/SampleApi.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javadoc/sampleapi/lib/sampleapi/SampleApi.java Thu Nov 19 13:14:16 2015 -0800
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2015, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sampleapi;
+
+import java.io.File;
+import java.nio.file.Path;
+
+import sampleapi.generator.PackageGenerator;
+
+public class SampleApi {
+
+ PackageGenerator pkgGen = new PackageGenerator();
+
+ public void generate(File dir) throws Fault {
+ pkgGen.processDataSet("simple");
+ pkgGen.generate(dir);
+ pkgGen.processDataSet("tiny");
+ pkgGen.generate(dir);
+ pkgGen.processDataSet("fx");
+ pkgGen.generate(dir);
+ }
+
+ public void generate(Path dir) throws Fault {
+ generate(dir.toFile());
+ }
+
+ public void generate(String dir) throws Fault {
+ generate(new File(dir));
+ }
+
+ public static class Fault extends Exception {
+ public Fault(String msg) {
+ super(msg);
+ }
+ }
+}
diff -r 6d7a40b2a54b -r e9fccc09cfc6 langtools/test/tools/javadoc/sampleapi/lib/sampleapi/SampleApiDefaultRunner.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javadoc/sampleapi/lib/sampleapi/SampleApiDefaultRunner.java Thu Nov 19 13:14:16 2015 -0800
@@ -0,0 +1,137 @@
+/*
+ * Copyright (c) 2015, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sampleapi;
+
+import java.io.File;
+
+import sampleapi.SampleApi.Fault;
+
+public class SampleApiDefaultRunner {
+
+ public static final String MSG_DUP_OUTDIR =
+ "SampleApi: duplicated outdir detected: ";
+ public static final String MSG_USE_FIRST =
+ " will use first occurance: ";
+ public static final String MSG_INVAL_OUTDIR =
+ "SampleApi: outdir is not valid: ";
+ public static final String MSG_CANNOT_GEN =
+ "SampleApi: cannot generate output: ";
+ public static final String MSG_WRONG_OPTION =
+ "SampleApi: incorrect option: ";
+ public static final String MSG_USE_HELP =
+ " use -? for help";
+
+ public static void main(String... args) throws Exception {
+ if (args.length == 0) {
+ printHelp();
+ System.exit(1);
+ }
+
+ String outDirName = "";
+
+ boolean isOutDirSet = false;
+ boolean isHelpPrinted = false;
+ for (String arg : args) {
+ Option option = new Option(arg);
+ switch (option.getOptionName()) {
+ case "-?":
+ case "-h":
+ case "--help":
+ if (!isHelpPrinted) {
+ printHelp();
+ isHelpPrinted = true;
+ }
+ break;
+ case "-o":
+ case "--outdir":
+ if (!isOutDirSet) {
+ outDirName = option.getOptionValue();
+ isOutDirSet = true;
+ } else {
+ System.err.println(MSG_DUP_OUTDIR + option.getOptionValue());
+ System.err.println(MSG_USE_FIRST + outDirName);
+ }
+ break;
+ default:
+ System.err.println(MSG_WRONG_OPTION + arg);
+ System.err.println(MSG_USE_HELP);
+ break;
+ }
+
+ }
+
+ if (!isOutDirSet) {
+ System.exit(1);
+ }
+
+ if (outDirName.length() == 0) {
+ System.err.println(MSG_INVAL_OUTDIR + outDirName);
+ System.exit(1);
+ }
+
+ File outDir = new File(outDirName);
+ outDir.mkdirs();
+ SampleApi apiGen = new SampleApi();
+
+ try {
+ apiGen.generate(outDir);
+ } catch (Fault e) {
+ System.err.println(MSG_CANNOT_GEN + e.getMessage());
+ e.printStackTrace();
+ }
+ }
+
+ private static void printHelp() {
+ System.out.println("SampleApi:");
+ System.out.println(" options: [-?|-h|--help] [-o:|--outdir:]");
+ System.out.println(" -?|-h|--help - print help");
+ System.out.println(" -o:|--outdir: - set to generate output");
+ }
+
+ private static class Option {
+
+ private String optionName;
+ private String optionValue;
+
+ public Option(String arg) {
+ int delimPos = arg.indexOf(':');
+
+ if (delimPos == -1) {
+ optionName = arg;
+ optionValue = "";
+ } else {
+ optionName = arg.substring(0, delimPos);
+ optionValue = arg.substring(delimPos + 1, arg.length());
+ }
+ }
+
+ public String getOptionName() {
+ return optionName;
+ }
+
+ public String getOptionValue() {
+ return optionValue;
+ }
+ }
+}
diff -r 6d7a40b2a54b -r e9fccc09cfc6 langtools/test/tools/javadoc/sampleapi/lib/sampleapi/generator/DocCommentGenerator.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javadoc/sampleapi/lib/sampleapi/generator/DocCommentGenerator.java Thu Nov 19 13:14:16 2015 -0800
@@ -0,0 +1,470 @@
+/*
+ * Copyright (c) 2015, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package sampleapi.generator;
+
+import java.io.File;
+import java.io.BufferedInputStream;
+import java.io.IOException;
+import java.util.Set;
+import javax.lang.model.element.Modifier;
+
+import com.sun.tools.javac.tree.JCTree;
+import com.sun.tools.javac.tree.JCTree.*;
+import com.sun.tools.javac.util.List;
+
+class DocCommentGenerator {
+
+ public enum Text {
+ BROWNFOX(BROWNFOX_TEXT),
+ NOWISTHETIME(NOWISTHETIME_TEXT),
+ THISPANGRAM(THISPANGRAM_TEXT),
+ LOREMIPSUM(LOREMIPSUM_TEXT),
+ LIEUROPANLINGUES(LIEUROPANLINGUES_TEXT),
+ CODE(CODE_TEXT);
+
+ String commentText;
+
+ Text(String text) {
+ commentText = text;
+ }
+
+ @Override
+ public String toString() {
+ return commentText;
+ }
+ }
+
+ public enum Tag {
+ AUTHOR("@author", "Cody J. Writer"),
+ PARAM("@param", ""),
+ RETURN("@return", Text.NOWISTHETIME.toString()),
+ SINCE("@since", "1.0"),
+ THROWS("@throws", "If problem detected"),
+ EXCEPTION("@exception", "If problem detected"),
+ SERIAL("@serial", ""),
+ SERIALDATA("@serialData", "The types and order of data could be here."),
+ SERIALFIELD("@serialField", "\n Serial field in special array"),
+ FX_PROPSETTER("@propertySetter", "Set the property"),
+ FX_PROPGETTER("@propertyGetter", "Get the property"),
+ FX_PROPDESC("@propertyDescription", ""),
+ FX_DEFVALUE("@defaultValue", ""),
+ FX_TREATASPRIVATE("@treatAsPrivate", "");
+
+ String tagName;
+ String tagValue;
+
+ Tag(String tagName, String tagValue) {
+ this.tagName = tagName;
+ this.tagValue = tagValue;
+ }
+
+ public String toString() {
+ return value("", "");
+ }
+
+ public String value(String value) {
+ return value(value, "");
+ }
+
+ public String value(String value, String extra) {
+ return tagName
+ + ((value.length() != 0) ? " " + value : "")
+ + ((tagValue.length() != 0) ? " " + tagValue : "")
+ + ((extra.length() != 0) ? " " + extra : "");
+ }
+ }
+
+ public enum InlineTag {
+ LITERAL("@literal", "Use < and > brackets instead of < and > escapes."),
+ CODE("@code", "(i) -> new Abc