author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 36526 | langtools/test/jdk/javadoc/tool/6942366/T6942366.java@3b41f1c69604 |
permissions | -rw-r--r-- |
7332 | 1 |
/* |
36526 | 2 |
* Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved. |
7332 | 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 |
*/ |
|
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 6942366 |
|
27 |
* @summary javadoc no longer inherits doc from sourcepath |
|
36526 | 28 |
* @modules jdk.javadoc/jdk.javadoc.internal.tool |
7332 | 29 |
* @build p.Base Test |
30 |
* @run main T6942366 |
|
31 |
*/ |
|
32 |
||
33 |
import java.io.*; |
|
34 |
import java.util.*; |
|
35 |
||
36 |
public class T6942366 { |
|
37 |
public static void main(String... args) throws Exception { |
|
38 |
new T6942366().run(); |
|
39 |
} |
|
40 |
||
41 |
File testSrc; |
|
42 |
File testClasses; |
|
43 |
int count; |
|
44 |
int errors; |
|
45 |
||
46 |
void run() throws Exception { |
|
47 |
testSrc = new File(System.getProperty("test.src")); |
|
48 |
testClasses = new File(System.getProperty("test.classes")); |
|
49 |
||
50 |
test(true, false); |
|
51 |
test(false, true); |
|
52 |
test(true, true); |
|
53 |
||
54 |
if (errors > 0) |
|
55 |
throw new Exception(errors + " errors found"); |
|
56 |
} |
|
57 |
||
58 |
void test(boolean useSourcePath, boolean useClassPath) throws Exception { |
|
59 |
System.out.println("test " + (++count) + " sp:" + useSourcePath + " cp:" + useClassPath); |
|
60 |
File testDir = new File("test" + count); |
|
61 |
testDir.mkdirs(); |
|
62 |
||
63 |
List<String> args = new ArrayList<String>(); |
|
64 |
//args.add("-verbose"); |
|
65 |
args.add("-d"); |
|
66 |
args.add(testDir.getPath()); |
|
67 |
if (useSourcePath) { |
|
68 |
args.add("-sourcepath"); |
|
69 |
args.add(testSrc.getPath()); |
|
70 |
} |
|
71 |
if (useClassPath) { |
|
72 |
args.add("-classpath"); |
|
73 |
args.add(testClasses.getPath()); |
|
74 |
} else { |
|
75 |
// override classpath to avoid stuff jtreg might have put on papth |
|
76 |
args.add("-classpath"); |
|
77 |
args.add("."); |
|
78 |
} |
|
79 |
||
80 |
args.add(new File(testSrc, "Test.java").getPath()); |
|
81 |
System.out.println("javadoc: " + args); |
|
82 |
||
35426
374342e56a56
8035473: [javadoc] Revamp the existing Doclet APIs
ksrini
parents:
30730
diff
changeset
|
83 |
int rc = jdk.javadoc.internal.tool.Main.execute(args.toArray(new String[args.size()])); |
7332 | 84 |
if (rc != 0) |
85 |
throw new Exception("unexpected exit from javadoc, rc=" + rc); |
|
86 |
||
87 |
if (useSourcePath && useClassPath) { |
|
88 |
long srcLastMod = new File(testSrc, "Test.java").lastModified(); |
|
89 |
long classLastMod = new File(testClasses, "Test.class").lastModified(); |
|
90 |
System.out.println("Test.java last modified: " + new Date(srcLastMod)); |
|
91 |
System.out.println("Test.class last modified: " + new Date(classLastMod)); |
|
92 |
System.out.println((srcLastMod > classLastMod ? "source" : "class") + " is newer"); |
|
93 |
} |
|
94 |
||
95 |
String s = "javadoc-for-Base.m"; |
|
96 |
boolean expect = useSourcePath; |
|
97 |
boolean found = contains(new File(testDir, "Test.html"), s); |
|
98 |
if (found) { |
|
99 |
if (expect) |
|
100 |
System.out.println("javadoc content \"" + s + "\" found, as expected"); |
|
101 |
else |
|
102 |
error("javadoc content \"" + s + "\" found unexpectedly"); |
|
103 |
} else { |
|
104 |
if (expect) |
|
105 |
error("javadoc content \"" + s + "\" not found"); |
|
106 |
else |
|
107 |
System.out.println("javadoc content \"" + s + "\" not found, as expected"); |
|
108 |
} |
|
109 |
||
110 |
System.out.println(); |
|
111 |
} |
|
112 |
||
113 |
boolean contains(File f, String s) throws Exception { |
|
114 |
byte[] buf = new byte[(int) f.length()]; |
|
115 |
try (DataInputStream in = new DataInputStream(new FileInputStream(f))) { |
|
116 |
in.readFully(buf); |
|
117 |
} |
|
118 |
return new String(buf).contains(s); |
|
119 |
} |
|
120 |
||
121 |
void error(String msg) { |
|
122 |
System.out.println("Error: " + msg); |
|
123 |
errors++; |
|
124 |
} |
|
125 |
||
126 |
} |
|
127 |