8159537: create build file to generate diags reports for all locales
authorjjg
Mon, 20 Jun 2016 13:21:09 -0700
changeset 39176 eef1aa371e87
parent 39107 2a5697a98620
child 39177 9d13e7c2d65e
8159537: create build file to generate diags reports for all locales Reviewed-by: mcimadamore
langtools/make/diags-examples.xml
langtools/test/tools/javac/diags/HTMLWriter.java
langtools/test/tools/javac/diags/RunExamples.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/make/diags-examples.xml	Mon Jun 20 13:21:09 2016 -0700
@@ -0,0 +1,124 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Copyright (c) 2016, 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.  Oracle designates this
+  ~ particular file as subject to the "Classpath" exception as provided
+  ~ by Oracle in the LICENSE file that accompanied this code.
+  ~
+  ~ 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.
+  -->
+
+<!--
+This is an extension to the langtools make/build.xml file,
+that provides targets to run the examples that generate
+example diagnostics in different locales.
+
+Usage:
+    ant -f langtools/make/run-examples.xml -Dlangtools.jdk.home=<JDK>
+
+By default, the reports will be generated in langtools/build/diags-examples/report/.
+-->
+
+<project name="diags-examples" default="diags-examples" basedir="..">
+    <import file="build.xml"/>
+
+    <!-- specify working directory for the tool -->
+    <property name="diags.examples.dir" location="${build.dir}/diag-examples"/>
+
+    <!-- compiled classes for the tool -->
+    <property name="diags.examples.classes" location="${diags.examples.dir}/classes}"/>
+
+    <!-- directory for generated reports -->
+    <property name="diags.examples.report" location="${diags.examples.dir}/report"/>
+
+    <!-- default target, generates reports for all available locales -->
+    <target name="diags-examples" depends="run-en_US,run-ja,run-zh_CN"/>
+
+    <!-- generate report for US English locale -->
+    <target name="run-en_US" depends="-build-runner,-def-runner">
+        <mkdir dir="${diags.examples.report}"/>
+        <runner lang="en" country="US" outfile="${diags.examples.report}/en_US.html"/>
+    </target>
+
+    <!-- generate report for Japanese locale -->
+    <target name="run-ja" depends="-build-runner,-def-runner">
+        <mkdir dir="${diags.examples.report}"/>
+        <runner lang="ja" outfile="${diags.examples.report}/ja.html"/>
+    </target>
+
+    <!-- generate report for Mandarin Chinese locale -->
+    <target name="run-zh_CN" depends="-build-runner,-def-runner">
+        <mkdir dir="${diags.examples.report}"/>
+        <runner lang="zh" country="CN" outfile="${diags.examples.report}/zh_CN.html"/>
+    </target>
+
+    <!-- compile the tool that runs the examples -->
+    <target name="-build-runner" depends="build">
+        <mkdir dir="${diags.examples.classes}"/>
+        <javac fork="true"
+            executable="${build.bin}/javac"
+            srcdir="test/tools/javac/diags"
+            destdir="${diags.examples.classes}"
+            includes="ArgTypeCompilerFactory.java,Example.java,FileManager.java,HTMLWriter.java,RunExamples.java,DocCommentProcessor.java"
+            sourcepath=""
+            includeAntRuntime="no"
+            debug="${javac.debug}"
+            debuglevel="${javac.debuglevel}">
+            <compilerarg line="-XaddExports:jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED"/>
+            <compilerarg line="-XaddExports:jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED"/>
+            <compilerarg line="-XaddExports:jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED"/>
+            <compilerarg line="-XaddExports:jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED"/>
+            <compilerarg line="-XaddExports:jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED"/>
+            <compilerarg line="-XaddExports:jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED"/>
+        </javac>
+    </target>
+
+    <!-- define a task to run the tool that runs the examples -->
+    <target name="-def-runner">
+        <macrodef name="runner">
+            <attribute name="lang"/>
+            <attribute name="country" default=""/>
+            <attribute name="outfile"/>
+            <sequential>
+            <java fork="true"
+                  jvm="${langtools.jdk.home}/bin/java"
+                  dir="test/tools/javac/diags"
+                  classpath="${diags.examples.classes};${dist.lib.dir}/javac.jar;${dist.lib.dir}/javap.jar"
+                  classname="RunExamples">
+                <jvmarg value="-Duser.language=@{lang}"/>
+                <jvmarg value="-Duser.country=@{country}"/>
+                <jvmarg value="-Dtest.classes=${diags.examples.classes}"/>
+                <arg value="-examples"/>
+                <arg value="examples"/>
+                <arg value="-o"/>
+                <arg file="@{outfile}"/>
+                <arg value="-showFiles"/>
+                <arg value="-title"/>
+                <arg value="Examples of javac diagnostics"/>
+                <jvmarg line="-XaddExports:jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED"/>
+                <jvmarg line="-XaddExports:jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED"/>
+                <jvmarg line="-XaddExports:jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED"/>
+                <jvmarg line="-XaddExports:jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED"/>
+                <jvmarg line="-XaddExports:jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED"/>
+                <jvmarg line="-XaddExports:jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED"/>
+            </java>
+            </sequential>
+        </macrodef>
+    </target>
+</project>
--- a/langtools/test/tools/javac/diags/HTMLWriter.java	Wed Jul 05 21:52:00 2017 +0200
+++ b/langtools/test/tools/javac/diags/HTMLWriter.java	Mon Jun 20 13:21:09 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2016, 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
@@ -40,7 +40,7 @@
      * @throws IOException if there is a problem writing to the underlying stream
      */
     public HTMLWriter(Writer out) throws IOException {
-        this(out, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">");
+        this(out, "<!DOCTYPE html\">");
     }
 
     /**
@@ -328,7 +328,7 @@
      */
     public void writeLink(File file, String body) throws IOException {
         startTag(A);
-        StringBuffer sb = new StringBuffer();
+        StringBuilder sb = new StringBuilder();
         String path = file.getPath().replace(File.separatorChar, '/');
         if (file.isAbsolute() && !path.startsWith("/"))
             sb.append('/');
@@ -472,13 +472,15 @@
     public static final String BORDER = "border";
     /** The HTML "br" tag. */
     public static final String BR = "br";
+    /** The HTML "charset" attribute. */
+    public static final String CHARSET  = "charset";
     /** The HTML "class" attribute. */
     public static final String CLASS  = "class";
     /** The HTML "classid" attribute. */
     public static final String CLASSID  = "classid";
     /** The HTML "code" tag. */
     public static final String CODE  = "code";
-    /** The HTML "color" attribte. */
+    /** The HTML "color" attribute. */
     public static final String COLOR  = "color";
     /** The HTML "col" attribute value. */
     public static final String COL = "col";
@@ -522,6 +524,8 @@
     public static final String LI = "li";
     /** The HTML "link" tag. */
     public static final String LINK = "link";
+    /** The HTML "meta" attribute. */
+    public static final String META = "meta";
     /** The HTML "name" attribute. */
     public static final String NAME = "name";
     /** The HTML "object" tag. */
--- a/langtools/test/tools/javac/diags/RunExamples.java	Wed Jul 05 21:52:00 2017 +0200
+++ b/langtools/test/tools/javac/diags/RunExamples.java	Mon Jun 20 13:21:09 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2016, 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
@@ -354,7 +354,10 @@
                 html.write(title);
                 html.endTag(HTMLWriter.TITLE);
             }
+            html.startTag(HTMLWriter.META);
+            html.writeAttr(HTMLWriter.CHARSET, "UTF-8");
             html.startTag(HTMLWriter.STYLE);
+            html.write(null); // revert to body text
             html.newLine();
             html.writeLine("div.file { background-color:#e0ffe0; margin-left:30px; margin-right:30px;\n"
                     + "  padding: 3px; border: thin solid silver; }");