Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/test/tools/javadoc/6942366/T6942366.java
38813 views
1
/*
2
* Copyright (c) 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
*/
23
24
/*
25
* @test
26
* @bug 6942366
27
* @summary javadoc no longer inherits doc from sourcepath
28
* @build p.Base Test
29
* @run main T6942366
30
*/
31
32
import java.io.*;
33
import java.util.*;
34
35
public class T6942366 {
36
public static void main(String... args) throws Exception {
37
new T6942366().run();
38
}
39
40
File testSrc;
41
File testClasses;
42
int count;
43
int errors;
44
45
void run() throws Exception {
46
testSrc = new File(System.getProperty("test.src"));
47
testClasses = new File(System.getProperty("test.classes"));
48
49
test(true, false);
50
test(false, true);
51
test(true, true);
52
53
if (errors > 0)
54
throw new Exception(errors + " errors found");
55
}
56
57
void test(boolean useSourcePath, boolean useClassPath) throws Exception {
58
System.out.println("test " + (++count) + " sp:" + useSourcePath + " cp:" + useClassPath);
59
File testDir = new File("test" + count);
60
testDir.mkdirs();
61
62
List<String> args = new ArrayList<String>();
63
//args.add("-verbose");
64
args.add("-d");
65
args.add(testDir.getPath());
66
if (useSourcePath) {
67
args.add("-sourcepath");
68
args.add(testSrc.getPath());
69
}
70
if (useClassPath) {
71
args.add("-classpath");
72
args.add(testClasses.getPath());
73
} else {
74
// override classpath to avoid stuff jtreg might have put on papth
75
args.add("-classpath");
76
args.add(".");
77
}
78
79
// use a very simple bootclasspath to avoid stuff jtreg might have put on path
80
File javaHome = new File(System.getProperty("java.home"));
81
File rt_jar = new File(javaHome, "lib/rt.jar");
82
if (!rt_jar.exists())
83
throw new Exception("rt.jar not found");
84
args.add("-bootclasspath");
85
args.add(rt_jar.getPath());
86
87
args.add(new File(testSrc, "Test.java").getPath());
88
System.out.println("javadoc: " + args);
89
90
int rc = com.sun.tools.javadoc.Main.execute(args.toArray(new String[args.size()]));
91
if (rc != 0)
92
throw new Exception("unexpected exit from javadoc, rc=" + rc);
93
94
if (useSourcePath && useClassPath) {
95
long srcLastMod = new File(testSrc, "Test.java").lastModified();
96
long classLastMod = new File(testClasses, "Test.class").lastModified();
97
System.out.println("Test.java last modified: " + new Date(srcLastMod));
98
System.out.println("Test.class last modified: " + new Date(classLastMod));
99
System.out.println((srcLastMod > classLastMod ? "source" : "class") + " is newer");
100
}
101
102
String s = "javadoc-for-Base.m";
103
boolean expect = useSourcePath;
104
boolean found = contains(new File(testDir, "Test.html"), s);
105
if (found) {
106
if (expect)
107
System.out.println("javadoc content \"" + s + "\" found, as expected");
108
else
109
error("javadoc content \"" + s + "\" found unexpectedly");
110
} else {
111
if (expect)
112
error("javadoc content \"" + s + "\" not found");
113
else
114
System.out.println("javadoc content \"" + s + "\" not found, as expected");
115
}
116
117
System.out.println();
118
}
119
120
boolean contains(File f, String s) throws Exception {
121
byte[] buf = new byte[(int) f.length()];
122
try (DataInputStream in = new DataInputStream(new FileInputStream(f))) {
123
in.readFully(buf);
124
}
125
return new String(buf).contains(s);
126
}
127
128
void error(String msg) {
129
System.out.println("Error: " + msg);
130
errors++;
131
}
132
133
}
134
135
136