Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/langtools/jdk/javadoc/tool/QuietOption.java
40957 views
1
/*
2
* Copyright (c) 2015, 2020, 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 8035473 8182765
27
* @summary make sure tool is quiet when told to, and chatty otherwise
28
*/
29
30
31
import java.io.BufferedReader;
32
import java.io.File;
33
import java.io.InputStreamReader;
34
import java.util.ArrayList;
35
import java.util.Iterator;
36
import java.util.List;
37
38
/**
39
* Dummy javadoc comment.
40
*/
41
public class QuietOption {
42
43
final File javadoc;
44
final File testSrc;
45
final String thisClassName;
46
47
/**
48
* Dummy javadoc comment.
49
*/
50
public QuietOption() {
51
File javaHome = new File(System.getProperty("java.home"));
52
if (javaHome.getName().endsWith("jre"))
53
javaHome = javaHome.getParentFile();
54
javadoc = new File(new File(javaHome, "bin"), "javadoc");
55
testSrc = new File(System.getProperty("test.src"));
56
thisClassName = QuietOption.class.getName();
57
}
58
59
/**
60
* Dummy javadoc comment.
61
* @param args dummy
62
* @throws Exception if error
63
*/
64
public static void main(String... args) throws Exception {
65
QuietOption test = new QuietOption();
66
test.run1();
67
test.run2();
68
}
69
70
// make sure javadoc is quiet
71
void run1() throws Exception {
72
List<String> output = doTest(javadoc.getPath(),
73
"-classpath", ".", // insulates us from ambient classpath
74
"-quiet",
75
new File(testSrc, thisClassName + ".java").getPath());
76
77
if (!output.isEmpty()) {
78
// Remove any lines that might have been generated by the runtime
79
Iterator<String> iter = output.iterator();
80
while (iter.hasNext()) {
81
String line = iter.next();
82
if (line.matches("^Picked up .*JAVA.*OPTIONS:.*")) {
83
System.out.println("IGNORING: " + line);
84
iter.remove();
85
}
86
}
87
}
88
89
if (!output.isEmpty()) {
90
System.out.println(output);
91
throw new Exception("run1: Shhh!, very chatty javadoc!.");
92
}
93
}
94
95
// make sure javadoc is chatty
96
void run2() throws Exception {
97
List<String> output = doTest(javadoc.getPath(),
98
"-classpath", ".", // insulates us from ambient classpath
99
new File(testSrc, thisClassName + ".java").getPath());
100
101
if (output.isEmpty()) {
102
System.out.println(output);
103
throw new Exception("run2: speak up and please be heard!.");
104
}
105
}
106
107
/**
108
* More dummy comments.
109
*/
110
List<String> doTest(String... args) throws Exception {
111
List<String> output = new ArrayList<>();
112
// run javadoc in separate process to ensure doclet executed under
113
// normal user conditions w.r.t. classloader
114
Process p = new ProcessBuilder()
115
.command(args)
116
.redirectErrorStream(true)
117
.start();
118
try (BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()))) {
119
String line = in.readLine();
120
while (line != null) {
121
output.add(line.trim());
122
line = in.readLine();
123
}
124
}
125
int rc = p.waitFor();
126
if (rc != 0) {
127
throw new Exception("javadoc failed, rc:" + rc);
128
}
129
return output;
130
}
131
}
132
133