author | katleman |
Tue, 21 Jan 2014 18:17:23 -0800 | |
changeset 22365 | 895bfde469d4 |
parent 15566 | 2c686ad681f5 |
child 30730 | d3ce7619db2c |
permissions | -rw-r--r-- |
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
1 |
/* |
15566 | 2 |
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. |
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
4 |
* |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
8 |
* |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
13 |
* accompanied this code). |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
14 |
* |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
18 |
* |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
21 |
* questions. |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
22 |
*/ |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
23 |
|
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
24 |
/* |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
25 |
* @test |
15566 | 26 |
* @bug 6493690 8007490 |
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
27 |
* @summary javadoc should have a javax.tools.Tool service provider |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
28 |
* @build APITest |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
29 |
* @run main RunTest |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
30 |
*/ |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
31 |
|
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
32 |
import java.io.ByteArrayOutputStream; |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
33 |
import java.io.File; |
15566 | 34 |
import java.io.PrintStream; |
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
35 |
import javax.tools.DocumentationTool; |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
36 |
import javax.tools.ToolProvider; |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
37 |
|
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
38 |
/** |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
39 |
* Tests for DocumentationTool.run method. |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
40 |
*/ |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
41 |
public class RunTest extends APITest { |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
42 |
public static void main(String... args) throws Exception { |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
43 |
new RunTest().run(); |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
44 |
} |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
45 |
|
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
46 |
/** |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
47 |
* Verify that run method can be invoked. |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
48 |
*/ |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
49 |
@Test |
15566 | 50 |
public void testRunOK() throws Exception { |
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
51 |
File testSrc = new File(System.getProperty("test.src")); |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
52 |
File srcFile = new File(testSrc, "pkg/C.java"); |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
53 |
File outDir = getOutDir(); |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
54 |
String[] args = { "-d", outDir.getPath(), srcFile.getPath() }; |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
55 |
|
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
56 |
ByteArrayOutputStream stdout = new ByteArrayOutputStream(); |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
57 |
ByteArrayOutputStream stderr = new ByteArrayOutputStream(); |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
58 |
DocumentationTool tool = ToolProvider.getSystemDocumentationTool(); |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
59 |
int rc = tool.run(null, stdout, stderr, args); |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
60 |
System.err.println("stdout >>" + stdout.toString() + "<<"); |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
61 |
System.err.println("stderr >>" + stderr.toString() + "<<"); |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
62 |
|
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
63 |
if (rc == 0) { |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
64 |
System.err.println("call succeeded"); |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
65 |
checkFiles(outDir, standardExpectFiles); |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
66 |
String out = stdout.toString(); |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
67 |
for (String f: standardExpectFiles) { |
14552
0512d803a331
8003650: java.lang.Exception: expected string not found: pkg/package-frame.html
jjg
parents:
14545
diff
changeset
|
68 |
String f1 = f.replace('/', File.separatorChar); |
0512d803a331
8003650: java.lang.Exception: expected string not found: pkg/package-frame.html
jjg
parents:
14545
diff
changeset
|
69 |
if (f1.endsWith(".html") && !out.contains(f1)) |
0512d803a331
8003650: java.lang.Exception: expected string not found: pkg/package-frame.html
jjg
parents:
14545
diff
changeset
|
70 |
error("expected string not found: " + f1); |
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
71 |
} |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
72 |
} else { |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
73 |
error("call failed"); |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
74 |
} |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
75 |
} |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
76 |
|
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
77 |
/** |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
78 |
* Verify that run method can be invoked. |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
79 |
*/ |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
80 |
@Test |
15566 | 81 |
public void testRunFail() throws Exception { |
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
82 |
File outDir = getOutDir(); |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
83 |
String badfile = "badfile.java"; |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
84 |
String[] args = { "-d", outDir.getPath(), badfile }; |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
85 |
|
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
86 |
ByteArrayOutputStream stdout = new ByteArrayOutputStream(); |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
87 |
ByteArrayOutputStream stderr = new ByteArrayOutputStream(); |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
88 |
DocumentationTool tool = ToolProvider.getSystemDocumentationTool(); |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
89 |
int rc = tool.run(null, stdout, stderr, args); |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
90 |
System.err.println("stdout >>" + stdout.toString() + "<<"); |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
91 |
System.err.println("stderr >>" + stderr.toString() + "<<"); |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
92 |
|
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
93 |
if (rc == 0) { |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
94 |
error("call succeeded unexpectedly"); |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
95 |
} else { |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
96 |
String err = stderr.toString(); |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
97 |
if (err.contains(badfile)) |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
98 |
System.err.println("call failed as expected"); |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
99 |
else |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
100 |
error("expected diagnostic not found"); |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
101 |
} |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
102 |
} |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
103 |
|
15566 | 104 |
/** |
105 |
* Verify that null args are accepted. |
|
106 |
*/ |
|
107 |
@Test |
|
108 |
public void testNullArgs() throws Exception { |
|
109 |
File testSrc = new File(System.getProperty("test.src")); |
|
110 |
File srcFile = new File(testSrc, "pkg/C.java"); |
|
111 |
File outDir = getOutDir(); |
|
112 |
String[] args = { "-d", outDir.getPath(), srcFile.getPath() }; |
|
113 |
||
114 |
ByteArrayOutputStream stdout = new ByteArrayOutputStream(); |
|
115 |
PrintStream prevStdout = System.out; |
|
116 |
System.setOut(new PrintStream(stdout)); |
|
117 |
||
118 |
ByteArrayOutputStream stderr = new ByteArrayOutputStream(); |
|
119 |
PrintStream prevStderr = System.err; |
|
120 |
System.setErr(new PrintStream(stderr)); |
|
121 |
||
122 |
int rc ; |
|
123 |
try { |
|
124 |
DocumentationTool tool = ToolProvider.getSystemDocumentationTool(); |
|
125 |
rc = tool.run(null, null, null, args); |
|
126 |
} finally { |
|
127 |
System.setOut(prevStdout); |
|
128 |
System.setErr(prevStderr); |
|
129 |
} |
|
130 |
||
131 |
System.err.println("stdout >>" + stdout.toString() + "<<"); |
|
132 |
System.err.println("stderr >>" + stderr.toString() + "<<"); |
|
133 |
||
134 |
if (rc == 0) { |
|
135 |
System.err.println("call succeeded"); |
|
136 |
checkFiles(outDir, standardExpectFiles); |
|
137 |
String out = stdout.toString(); |
|
138 |
for (String f: standardExpectFiles) { |
|
139 |
String f1 = f.replace('/', File.separatorChar); |
|
140 |
if (f1.endsWith(".html") && !out.contains(f1)) |
|
141 |
error("expected string not found: " + f1); |
|
142 |
} |
|
143 |
} else { |
|
144 |
error("call failed"); |
|
145 |
} |
|
146 |
} |
|
14545
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
147 |
} |
2e7bab0639b8
6493690: javadoc should have a javax.tools.Tool service provider installed in tools.jar
jjg
parents:
diff
changeset
|
148 |