Mon, 16 Sep 2013 14:13:44 +0200
8021112: Spurious unchecked warning reported by javac
6480588: No way to suppress deprecation warnings when implementing deprecated interface
Summary: Fixing DeferredLintHandler configuration, so lint warnings are reported with correct @SuppressWarnings settings
Reviewed-by: jjg, vromero
1 /*
2 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
24 /*
25 * @test
26 * @bug 4645058 4747738 4855054
27 * @summary Javascript IE load error when linked by -linkoffline
28 * Window title shouldn't change when loading left frames (javascript)
29 * @author dkramer
30 * @run main JavascriptWinTitle
31 */
34 import com.sun.javadoc.*;
35 import java.util.*;
36 import java.io.*;
39 /**
40 * Runs javadoc and runs regression tests on the resulting HTML.
41 * It reads each file, complete with newlines, into a string to easily
42 * find strings that contain newlines.
43 */
44 public class JavascriptWinTitle {
46 private static final String BUGID = "4645058";
47 private static final String BUGNAME = "JavascriptWinTitle";
48 private static final String FS = System.getProperty("file.separator");
49 private static final String PS = System.getProperty("path.separator");
50 private static final String LS = System.getProperty("line.separator");
51 private static final String TMPDEST_DIR1 = "." + FS + "docs1" + FS;
52 private static final String TMPDEST_DIR2 = "." + FS + "docs2" + FS;
54 // Subtest number. Needed because runResultsOnHTML is run twice,
55 // and subtestNum should increment across subtest runs.
56 public static int subtestNum = 0;
57 public static int numSubtestsPassed = 0;
59 // Entry point
60 public static void main(String[] args) {
62 // Directory that contains source files that javadoc runs on
63 String srcdir = System.getProperty("test.src", ".");
65 // Test for all cases except the split index page
66 runJavadoc(new String[] {"-d", TMPDEST_DIR1,
67 "-doctitle", "Document Title",
68 "-windowtitle", "Window Title",
69 "-overview", (srcdir + FS + "overview.html"),
70 "-linkoffline",
71 "http://java.sun.com/j2se/1.4/docs/api", srcdir,
72 "-sourcepath", srcdir,
73 "p1", "p2"});
74 runTestsOnHTML(testArray);
76 printSummary();
77 }
79 /** Run javadoc */
80 public static void runJavadoc(String[] javadocArgs) {
81 if (com.sun.tools.javadoc.Main.execute(javadocArgs) != 0) {
82 throw new Error("Javadoc failed to execute");
83 }
84 }
86 /**
87 * Assign value for [ stringToFind, filename ]
88 * NOTE: The standard doclet uses the same separator "\n" for all OS's
89 */
90 private static final String[][] testArray = {
92 // Test the javascript "type" attribute is present:
93 { "<script type=\"text/javascript\">",
94 TMPDEST_DIR1 + "overview-summary.html" },
96 // Test onload is absent:
97 { "<body>",
98 TMPDEST_DIR1 + "overview-summary.html" },
100 // Test onload is present:
101 { "<body>",
102 TMPDEST_DIR1 + FS + "p1" + FS + "package-summary.html" },
104 // Test that "onload" is not present in BODY tag:
105 { "<body>",
106 TMPDEST_DIR1 + "overview-frame.html" },
108 // Test that "onload" is not present in BODY tag:
109 { "<body>",
110 TMPDEST_DIR1 + "allclasses-frame.html" },
112 // Test that "onload" is not present in BODY tag:
113 { "<body>",
114 TMPDEST_DIR1 + FS + "p1" + FS + "package-frame.html" },
116 // Test that win title javascript is followed by NOSCRIPT code.
117 {"<script type=\"text/javascript\"><!--" + LS +
118 " if (location.href.indexOf('is-external=true') == -1) {" + LS +
119 " parent.document.title=\"C (Window Title)\";" + LS +
120 " }" + LS + "//-->" + LS + "</script>",
121 TMPDEST_DIR1 + FS + "p1" + FS + "C.html"
122 }
124 };
126 public static void runTestsOnHTML(String[][] testArray) {
128 for (int i = 0; i < testArray.length; i++) {
130 subtestNum += 1;
132 // Read contents of file into a string
133 String fileString = readFileToString(testArray[i][1]);
135 // Get string to find
136 String stringToFind = testArray[i][0];
138 // Find string in file's contents
139 if (findString(fileString, stringToFind) == -1) {
140 System.out.println("\nSub-test " + (subtestNum)
141 + " for bug " + BUGID + " (" + BUGNAME + ") FAILED\n"
142 + "when searching for:\n"
143 + stringToFind);
144 } else {
145 numSubtestsPassed += 1;
146 System.out.println("\nSub-test " + (subtestNum) + " passed:\n" + stringToFind);
147 }
148 }
149 }
151 public static void printSummary() {
152 if ( numSubtestsPassed == subtestNum ) {
153 System.out.println("\nAll " + numSubtestsPassed + " subtests passed");
154 } else {
155 throw new Error("\n" + (subtestNum - numSubtestsPassed) + " of " + (subtestNum)
156 + " subtests failed for bug " + BUGID + " (" + BUGNAME + ")\n");
157 }
158 }
160 // Read the file into a String
161 public static String readFileToString(String filename) {
162 try {
163 File file = new File(filename);
164 if ( !file.exists() ) {
165 System.out.println("\nFILE DOES NOT EXIST: " + filename);
166 }
167 BufferedReader in = new BufferedReader(new FileReader(file));
169 // Create an array of characters the size of the file
170 char[] allChars = new char[(int)file.length()];
172 // Read the characters into the allChars array
173 in.read(allChars, 0, (int)file.length());
174 in.close();
176 // Convert to a string
177 String allCharsString = new String(allChars);
179 return allCharsString;
181 } catch (FileNotFoundException e) {
182 System.err.println(e);
183 return "";
184 } catch (IOException e) {
185 System.err.println(e);
186 return "";
187 }
188 }
190 public static int findString(String fileString, String stringToFind) {
191 return fileString.indexOf(stringToFind);
192 }
193 }