1
1
/*
2
- * Copyright (c) 2002, 2020 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2002, 2021 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
43
43
import java .net .InetSocketAddress ;
44
44
import java .net .URL ;
45
45
import java .net .URLConnection ;
46
+ import java .net .UnknownHostException ;
46
47
import java .nio .file .Files ;
47
48
import java .nio .file .Path ;
48
49
import java .security .KeyStore ;
50
+ import java .time .Duration ;
51
+ import java .time .Instant ;
49
52
50
53
import javax .net .ssl .HostnameVerifier ;
51
54
import javax .net .ssl .HttpsURLConnection ;
@@ -84,9 +87,31 @@ public static void main(String... args) throws Exception {
84
87
*/
85
88
@ Test
86
89
public void testRedirects () throws Exception {
87
- // first, test to see if access to external URLs is available
90
+ // This test relies on access to an external resource, which may or may not be
91
+ // reliably available, depending on the host system configuration and other
92
+ // networking issues. Therefore, it is disabled by default, unless the system
93
+ // property "javadoc.dev" is set "true".
94
+ String property = "javadoc.dev" ;
95
+ if (!Boolean .getBoolean (property )) {
96
+ out .println ("Test case disabled by default; "
97
+ + "set system property \" " + property + "\" to true to enable it." );
98
+ return ;
99
+ }
100
+
101
+ // test to see if access to external URLs is available, and that the URL uses a redirect
102
+
88
103
URL testURL = new URL ("http://docs.oracle.com/en/java/javase/11/docs/api/element-list" );
104
+ String testURLHost = testURL .getHost ();
105
+ try {
106
+ InetAddress testAddr = InetAddress .getByName (testURLHost );
107
+ out .println ("Found " + testURLHost + ": " + testAddr );
108
+ } catch (UnknownHostException e ) {
109
+ out .println ("Setup failed (" + testURLHost + " not found); this test skipped" );
110
+ return ;
111
+ }
112
+
89
113
boolean haveRedirectURL = false ;
114
+ Instant start = Instant .now ();
90
115
try {
91
116
URLConnection conn = testURL .openConnection ();
92
117
conn .connect ();
@@ -107,10 +132,12 @@ public void testRedirects() throws Exception {
107
132
}
108
133
} catch (Exception e ) {
109
134
out .println ("Exception occurred: " + e );
135
+ Instant now = Instant .now ();
136
+ out .println ("Attempt took " + Duration .between (start , now ).toSeconds () + " seconds" );
110
137
}
111
138
112
139
if (!haveRedirectURL ) {
113
- out .println ("Setup failed; this test skipped" );
140
+ out .println ("Setup failed (no redirect URL) ; this test skipped" );
114
141
return ;
115
142
}
116
143
@@ -119,6 +146,7 @@ public void testRedirects() throws Exception {
119
146
javadoc ("-d" , outRedirect ,
120
147
"-sourcepath" , testSrc ,
121
148
"-link" , apiURL ,
149
+ "-Xdoclint:none" ,
122
150
"pkg" );
123
151
checkExit (Exit .OK );
124
152
checkOutput ("pkg/B.html" , true ,
@@ -157,16 +185,19 @@ public void testWithServers() throws Exception {
157
185
new JavacTask (tb )
158
186
.outdir (libModules )
159
187
.options ("--module-source-path" , libSrc .toString (),
160
- "--module" , "mA,mB" )
188
+ "--module" , "mA,mB" ,
189
+ "-Xdoclint:none" )
161
190
.run ()
162
191
.writeAll ();
163
192
164
193
javadoc ("-d" , libApi .toString (),
165
194
"--module-source-path" , libSrc .toString (),
166
- "--module" , "mA,mB" );
195
+ "--module" , "mA,mB" ,
196
+ "-Xdoclint:none" );
167
197
168
198
// start web servers
169
- InetAddress localHost = InetAddress .getLocalHost ();
199
+ // use loopback address to avoid any issues if proxy is in use
200
+ InetAddress localHost = InetAddress .getLoopbackAddress ();
170
201
try {
171
202
oldServer = HttpServer .create (new InetSocketAddress (localHost , 0 ), 0 );
172
203
String oldURL = "http:/" + oldServer .getAddress ();
@@ -201,7 +232,8 @@ public void testWithServers() throws Exception {
201
232
"--module-source-path" , src .toString (),
202
233
"--module-path" , libModules .toString (),
203
234
"-link" , "http:/" + oldServer .getAddress (),
204
- "--module" , "mC" );
235
+ "--module" , "mC" ,
236
+ "-Xdoclint:none" );
205
237
206
238
} finally {
207
239
HttpsURLConnection .setDefaultHostnameVerifier (prevHostNameVerifier );
0 commit comments