/
JavadocUtilTest.java
727 lines (628 loc) · 26.1 KB
/
JavadocUtilTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
package org.apache.maven.plugins.javadoc;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.net.SocketTimeoutException;
import java.net.URI;
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.PatternSyntaxException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
import org.apache.maven.plugins.javadoc.ProxyServer.AuthAsyncProxyServlet;
import org.apache.maven.settings.Proxy;
import org.apache.maven.settings.Settings;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.util.FileUtils;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.server.handler.MovedContextHandler;
import org.eclipse.jetty.util.ByteArrayISO8859Writer;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
*/
public class JavadocUtilTest
extends PlexusTestCase
{
/**
* Method to test the javadoc version parsing.
*
*/
public void testParseJavadocVersion()
{
String version = null;
try
{
JavadocUtil.extractJavadocVersion( version );
fail( "Not catch null" );
}
catch ( IllegalArgumentException e )
{
assertTrue( true );
}
// Sun JDK 1.4
version = "java full version \"1.4.2_12-b03\"";
assertEquals( "1.4.2", JavadocUtil.extractJavadocVersion( version ) );
// Sun JDK 1.5
version = "java full version \"1.5.0_07-164\"";
assertEquals( "1.5.0", JavadocUtil.extractJavadocVersion( version ) );
// IBM JDK 1.4
version = "java full version \"J2RE 1.4.2 IBM Windows 32 build cn1420-20040626\"";
assertEquals( "1.4.2", JavadocUtil.extractJavadocVersion( version ) );
// IBM JDK 1.5
version = "javadoc version complète de \"J2RE 1.5.0 IBM Windows 32 build pwi32pdev-20070426a\"";
assertEquals( "1.5.0", JavadocUtil.extractJavadocVersion( version ) );
// IBM JDK 1.5
version = "J2RE 1.5.0 IBM Windows 32 build pwi32devifx-20070323 (ifix 117674: SR4 + 116644 + 114941 + 116110 + 114881)";
assertEquals( "1.5.0", JavadocUtil.extractJavadocVersion( version ) );
// FreeBSD
version = "java full version \"diablo-1.5.0-b01\"";
assertEquals( "1.5.0", JavadocUtil.extractJavadocVersion( version ) );
// BEA
version = "java full version \"1.5.0_11-b03\"";
assertEquals( "1.5.0", JavadocUtil.extractJavadocVersion( version ) );
// Other tests
version = "java full version \"1.5.0_07-164\"" + System.getProperty( "line.separator" );
assertEquals( "1.5.0", JavadocUtil.extractJavadocVersion( version ) );
version = System.getProperty( "line.separator" ) + "java full version \"1.5.0_07-164\"";
assertEquals( "1.5.0", JavadocUtil.extractJavadocVersion( version ) );
version = System.getProperty( "line.separator" ) + "java full version \"1.5.0_07-164\""
+ System.getProperty( "line.separator" );
assertEquals( "1.5.0", JavadocUtil.extractJavadocVersion( version ));
version = "java full" + System.getProperty( "line.separator" ) + " version \"1.5.0_07-164\"";
assertEquals( "1.5.0", JavadocUtil.extractJavadocVersion( version ) );
version = "java full version \"1.99.123-b01\"";
assertEquals( "1.99.123", JavadocUtil.extractJavadocVersion( version ) );
version = "java full version \"1.5.0.07-164\"";
assertEquals( "1.5.0", JavadocUtil.extractJavadocVersion( version ) );
version = "java full version \"1.4\"";
assertEquals( "1.4" , JavadocUtil.extractJavadocVersion( version ) );
version = "java full version \"1.A.B_07-164\"";
try
{
JavadocUtil.extractJavadocVersion( version );
// does not fail since JEP 223 support addition
//assertTrue( "Not catch wrong pattern", false );
}
catch ( PatternSyntaxException e )
{
assertTrue( true );
}
version = "SCO-UNIX-J2SE-1.5.0_09*FCS-UW714-OSR6*_20061114";
assertEquals( "1.5.0", JavadocUtil.extractJavadocVersion( version ) );
// Java 9 EA
version = "java full version \"9-ea+113\"";
assertEquals( "9", JavadocUtil.extractJavadocVersion( version ) );
// Java 9 EA Jigsaw
version = "java full version \"9-ea+113-2016-04-14-161743.javare.4852.nc\"";
assertEquals( "9", JavadocUtil.extractJavadocVersion( version ) );
version = "java version \"9-ea\"";
assertEquals( "9", JavadocUtil.extractJavadocVersion( version ) );
// JEP 223 example for future versions
version = "java full version \"9+100\"";
assertEquals( "9", JavadocUtil.extractJavadocVersion( version ) );
version = "java full version \"9.0.1+20\"";
assertEquals( "9.0.1", JavadocUtil.extractJavadocVersion( version ) );
version = "java full version \"10+100\"";
assertEquals( "10" , JavadocUtil.extractJavadocVersion( version ) );
version = "java full version \"10.0.1+20\"";
assertEquals( "10.0.1" , JavadocUtil.extractJavadocVersion( version ) );
}
/**
* Method to test the javadoc memory parsing.
*
*/
public void testParseJavadocMemory()
{
String memory = null;
try
{
JavadocUtil.parseJavadocMemory( memory );
fail( "Not catch null" );
}
catch ( IllegalArgumentException e )
{
assertTrue( true );
}
memory = "128";
assertEquals( JavadocUtil.parseJavadocMemory( memory ), "128m" );
memory = "128k";
assertEquals( JavadocUtil.parseJavadocMemory( memory ), "128k" );
memory = "128kb";
assertEquals( JavadocUtil.parseJavadocMemory( memory ), "128k" );
memory = "128m";
assertEquals( JavadocUtil.parseJavadocMemory( memory ), "128m" );
memory = "128mb";
assertEquals( JavadocUtil.parseJavadocMemory( memory ), "128m" );
memory = "1g";
assertEquals( JavadocUtil.parseJavadocMemory( memory ), "1024m" );
memory = "1gb";
assertEquals( JavadocUtil.parseJavadocMemory( memory ), "1024m" );
memory = "1t";
assertEquals( JavadocUtil.parseJavadocMemory( memory ), "1048576m" );
memory = "1tb";
assertEquals( JavadocUtil.parseJavadocMemory( memory ), "1048576m" );
memory = System.getProperty( "line.separator" ) + "128m";
assertEquals( JavadocUtil.parseJavadocMemory( memory ), "128m" );
memory = System.getProperty( "line.separator" ) + "128m" + System.getProperty( "line.separator" );
assertEquals( JavadocUtil.parseJavadocMemory( memory ), "128m" );
memory = " 128m";
assertEquals( JavadocUtil.parseJavadocMemory( memory ), "128m" );
memory = " 128m ";
assertEquals( JavadocUtil.parseJavadocMemory( memory ), "128m" );
memory = "1m28m";
try
{
JavadocUtil.parseJavadocMemory( memory );
fail( "Not catch wrong pattern" );
}
catch ( IllegalArgumentException e )
{
assertTrue( true );
}
memory = "ABC128m";
try
{
JavadocUtil.parseJavadocMemory( memory );
fail( "Not catch wrong pattern" );
}
catch ( IllegalArgumentException e )
{
assertTrue( true );
}
}
/**
* Method to test the validate encoding parsing.
*
*/
public void testValidateEncoding()
{
assertFalse( "Not catch null", JavadocUtil.validateEncoding( null ) );
assertTrue( "UTF-8 not supported on this plateform", JavadocUtil.validateEncoding( "UTF-8" ) );
assertTrue( "ISO-8859-1 not supported on this plateform", JavadocUtil.validateEncoding( "ISO-8859-1" ) );
assertFalse( "latin is supported on this plateform???", JavadocUtil.validateEncoding( "latin" ) );
assertFalse( "WRONG is supported on this plateform???", JavadocUtil.validateEncoding( "WRONG" ) );
}
/**
* Method to test isValidPackageList()
*
* @throws Exception if any
*/
public void testIsValidPackageList()
throws Exception
{
Settings settings = null;
Proxy proxy;
URL url = null;
URL wrongUrl;
try
{
JavadocUtil.isValidPackageList( url, settings, false );
fail();
}
catch ( IllegalArgumentException e )
{
assertTrue( true );
}
url = new File( getBasedir(), "/pom.xml" ).toURI().toURL();
assertTrue( JavadocUtil.isValidPackageList( url, settings, false ) );
try
{
assertFalse( JavadocUtil.isValidPackageList( url, settings, true ) );
}
catch ( IOException e )
{
assertTrue( true );
}
url = this.getClass().getResource( "/JavadocUtilTest-package-list.txt" ).toURI().toURL();
assertTrue( JavadocUtil.isValidPackageList( url, settings, true ) );
url = new URL( "http://maven.apache.org/plugins/maven-javadoc-plugin/apidocs/package-list" );
assertTrue( JavadocUtil.isValidPackageList( url, settings, true ) );
wrongUrl = new URL( "http://maven.apache.org/plugins/maven-javadoc-plugin/apidocs/package-list2" );
try
{
JavadocUtil.isValidPackageList( wrongUrl, settings, false );
fail();
}
catch ( IOException e )
{
assertTrue( true );
}
// real proxy
ProxyServer proxyServer = null;
AuthAsyncProxyServlet proxyServlet;
try
{
proxyServlet = new AuthAsyncProxyServlet();
proxyServer = new ProxyServer( proxyServlet );
proxyServer.start();
settings = new Settings();
assertTrue( JavadocUtil.isValidPackageList( url, settings, true ) );
try
{
JavadocUtil.isValidPackageList( wrongUrl, settings, false );
fail();
}
catch ( IOException e )
{
assertTrue( true );
}
}
finally
{
if ( proxyServer != null )
{
proxyServer.stop();
}
}
Map<String, String> authentications = new HashMap<>();
authentications.put( "foo", "bar" );
// wrong auth
try
{
proxyServlet = new AuthAsyncProxyServlet( authentications );
proxyServer = new ProxyServer( proxyServlet );
proxyServer.start();
settings = new Settings();
proxy = new Proxy();
proxy.setActive( true );
proxy.setHost( proxyServer.getHostName() );
proxy.setPort( proxyServer.getPort() );
proxy.setProtocol( "http" );
settings.addProxy( proxy );
JavadocUtil.isValidPackageList( url, settings, false );
fail();
}
catch ( FileNotFoundException e )
{
assertTrue( true );
}
finally
{
proxyServer.stop();
}
// auth proxy
try
{
proxyServlet = new AuthAsyncProxyServlet( authentications );
proxyServer = new ProxyServer( proxyServlet );
proxyServer.start();
settings = new Settings();
proxy = new Proxy();
proxy.setActive( true );
proxy.setHost( proxyServer.getHostName() );
proxy.setPort( proxyServer.getPort() );
proxy.setProtocol( "http" );
proxy.setUsername( "foo" );
proxy.setPassword( "bar" );
settings.addProxy( proxy );
assertTrue( JavadocUtil.isValidPackageList( url, settings, true ) );
try
{
JavadocUtil.isValidPackageList( wrongUrl, settings, false );
fail();
}
catch ( IOException e )
{
assertTrue( true );
}
}
finally
{
proxyServer.stop();
}
// timeout
try
{
proxyServlet = new AuthAsyncProxyServlet( authentications, 3000 ); // more than 2000, see fetchURL
proxyServer = new ProxyServer( proxyServlet );
proxyServer.start();
settings = new Settings();
proxy = new Proxy();
proxy.setActive( true );
proxy.setHost( proxyServer.getHostName() );
proxy.setPort( proxyServer.getPort() );
proxy.setProtocol( "http" );
proxy.setUsername( "foo" );
proxy.setPassword( "bar" );
settings.addProxy( proxy );
JavadocUtil.isValidPackageList( url, settings, true );
fail();
}
catch ( SocketTimeoutException e )
{
assertTrue( true );
}
finally
{
proxyServer.stop();
}
// nonProxyHosts
try
{
proxyServlet = new AuthAsyncProxyServlet( authentications );
proxyServer = new ProxyServer( proxyServlet );
proxyServer.start();
settings = new Settings();
proxy = new Proxy();
proxy.setActive( true );
proxy.setHost( proxyServer.getHostName() );
proxy.setPort( proxyServer.getPort() );
proxy.setProtocol( "http" );
proxy.setUsername( "foo" );
proxy.setPassword( "bar" );
proxy.setNonProxyHosts( "maven.apache.org" );
settings.addProxy( proxy );
assertTrue( JavadocUtil.isValidPackageList( url, settings, true ) );
}
finally
{
proxyServer.stop();
}
}
public void testGetRedirectUrlNotHttp()
throws Exception
{
URL url = new URI( "ftp://some.where" ).toURL();
assertEquals( url.toString(), JavadocUtil.getRedirectUrl( url, new Settings() ).toString() );
url = new URI( "file://some/where" ).toURL();
assertEquals( url.toString(), JavadocUtil.getRedirectUrl( url, new Settings() ).toString() );
}
/**
* Tests a redirect from localhost:port1 to localhost:port2
*/
public void testGetRedirectUrl()
throws Exception
{
Server server = null, redirectServer = null;
try
{
redirectServer = new Server( 0 );
redirectServer.setHandler( new AbstractHandler()
{
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
response.setStatus( HttpServletResponse.SC_OK );
ByteArrayISO8859Writer writer = new ByteArrayISO8859Writer( 100 );
writer.write( "<html>Hello world</html>" );
writer.flush();
response.setContentLength( writer.size() );
OutputStream out = response.getOutputStream();
writer.writeTo( out );
out.close();
writer.close();
}
} );
redirectServer.start();
server = new Server( 0 );
MovedContextHandler handler = new MovedContextHandler();
int redirectPort = ((ServerConnector)redirectServer.getConnectors()[0]).getLocalPort();
handler.setNewContextURL( "http://localhost:" + redirectPort );
server.setHandler( handler );
server.start();
URL url = new URI( "http://localhost:" + ((ServerConnector)redirectServer.getConnectors()[0]).getLocalPort() ).toURL();
URL redirectUrl = JavadocUtil.getRedirectUrl( url, new Settings() );
assertTrue( redirectUrl.toString().startsWith( "http://localhost:" + redirectPort ) );
}
finally
{
stopSilently( server );
stopSilently( redirectServer );
}
}
/**
* Tests that getRedirectUrl returns the same URL when there are no redirects.
*/
public void testGetRedirectUrlWithNoRedirects()
throws Exception
{
Server server = null;
try
{
server = new Server( 0 );
server.setHandler( new AbstractHandler()
{
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
response.setStatus( HttpServletResponse.SC_OK );
ByteArrayISO8859Writer writer = new ByteArrayISO8859Writer( 100 );
writer.write( "<html>Hello world</html>" );
writer.flush();
response.setContentLength( writer.size() );
OutputStream out = response.getOutputStream();
writer.writeTo( out );
out.close();
writer.close();
}
} );
server.start();
URL url = new URI( "http://localhost:" + ((ServerConnector)server.getConnectors()[0]).getLocalPort() ).toURL();
URL redirectUrl = JavadocUtil.getRedirectUrl( url, new Settings() );
assertEquals( url.toURI(), redirectUrl.toURI() );
}
finally
{
stopSilently( server );
}
}
/**
* Tests that getRedirectUrl adds an Accept header in HTTP requests. Necessary because some sites like Cloudflare
* reject requests without an Accept header.
*/
public void testGetRedirectUrlVerifyHeaders()
throws Exception
{
Server server = null;
try
{
server = new Server( 0 );
server.setHandler( new AbstractHandler()
{
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
if ( request.getHeader( "Accept" ) == null )
{
response.setStatus( HttpServletResponse.SC_FORBIDDEN );
}
else
{
response.setStatus( HttpServletResponse.SC_OK );
}
response.getOutputStream().close();
}
} );
server.start();
URL url = new URI( "http://localhost:" + ((ServerConnector)server.getConnectors()[0]).getLocalPort() ).toURL();
JavadocUtil.getRedirectUrl( url, new Settings() );
}
finally
{
stopSilently( server );
}
}
/**
* Method to test copyJavadocResources()
*
* @throws Exception if any
*/
public void testCopyJavadocResources()
throws Exception
{
File input = new File( getBasedir(), "src/test/resources/unit/docfiles-test/docfiles/" );
assertThat( input ).exists();
File output = new File( getBasedir(), "target/test/unit/docfiles-test/target/output" );
if ( output.exists() )
{
FileUtils.deleteDirectory( output );
}
assertTrue( output.mkdirs() );
JavadocUtil.copyJavadocResources( output, input, null );
assertThat( FileUtils.getFiles( output, null, null, false ) )
.containsExactlyInAnyOrder(
Paths.get( "test", "doc-files", "excluded-dir1", "sample-excluded1.gif" ).toFile(),
Paths.get( "test", "doc-files", "excluded-dir2", "sample-excluded2.gif" ).toFile(),
Paths.get( "test", "doc-files", "included-dir1", "sample-included1.gif" ).toFile(),
Paths.get( "test", "doc-files", "included-dir2", "sample-included2.gif" ).toFile()
);
assertThat( FileUtils.getDirectoryNames( new File( output, "test/doc-files" ), null, null, false ) )
.containsExactlyInAnyOrder( "", "excluded-dir1", "excluded-dir2", "included-dir1", "included-dir2" );
input = new File( getBasedir(), "src/test/resources/unit/docfiles-test/docfiles/" );
assertTrue( input.exists() );
output = new File( getBasedir(), "target/test/unit/docfiles-test/target/output" );
if ( output.exists() )
{
FileUtils.deleteDirectory( output );
}
assertTrue( output.mkdirs() );
JavadocUtil.copyJavadocResources( output, input, "excluded-dir1:excluded-dir2" );
assertThat( FileUtils.getFiles( output, null, null, false ) )
.containsExactlyInAnyOrder(
Paths.get( "test", "doc-files", "included-dir1", "sample-included1.gif" ).toFile(),
Paths.get( "test", "doc-files", "included-dir2", "sample-included2.gif" ).toFile()
);
assertThat( FileUtils.getDirectoryNames( new File( output, "test/doc-files" ), null, null, false ) )
.containsExactlyInAnyOrder( "", "included-dir1", "included-dir2" );
}
/**
* Method to test pruneDirs()
*
*/
public void testPruneDirs()
{
List<String> list = new ArrayList<>();
list.add( getBasedir() + "/target/classes" );
list.add( getBasedir() + "/target/classes" );
list.add( getBasedir() + "/target/classes" );
Set<Path> expected = Collections.singleton( Paths.get( getBasedir(), "target/classes" ) );
MavenProjectStub project = new MavenProjectStub();
project.setFile( new File( getBasedir(), "pom.xml" ) );
assertEquals( expected, JavadocUtil.pruneDirs( project, list ) );
}
/**
* Method to test unifyPathSeparator()
*
*/
public void testUnifyPathSeparator()
{
assertNull( JavadocUtil.unifyPathSeparator( null ) );
final String ps = File.pathSeparator;
// Windows
String path1 = "C:\\maven-javadoc-plugin\\src\\main\\java";
String path2 = "C:\\maven-javadoc-plugin\\src\\main\\javadoc";
assertEquals( path1 + ps + path2, JavadocUtil.unifyPathSeparator( path1 + ";" + path2 ) );
assertEquals( path1 + ps + path2, JavadocUtil.unifyPathSeparator( path1 + ":" + path2 ) );
path1 = "C:/maven-javadoc-plugin/src/main/java";
path2 = "C:/maven-javadoc-plugin/src/main/javadoc";
assertEquals( path1 + ps + path2, JavadocUtil.unifyPathSeparator( path1 + ";" + path2 ) );
assertEquals( path1 + ps + path2, JavadocUtil.unifyPathSeparator( path1 + ":" + path2 ) );
assertEquals( path1 + ps + path2 + ps + path1 + ps + path2, JavadocUtil.unifyPathSeparator( path1 + ";"
+ path2 + ";" + path1 + ":" + path2 ) );
// Unix
path1 = "/tmp/maven-javadoc-plugin/src/main/java";
path2 = "/tmp/maven-javadoc-plugin/src/main/javadoc";
assertEquals( path1 + ps + path2, JavadocUtil.unifyPathSeparator( path1 + ";" + path2 ) );
assertEquals( path1 + ps + path2, JavadocUtil.unifyPathSeparator( path1 + ":" + path2 ) );
assertEquals( path1 + ps + path2 + ps + path1 + ps + path2, JavadocUtil.unifyPathSeparator( path1 + ";"
+ path2 + ":" + path1 + ":" + path2 ) );
}
public void testGetIncludedFiles()
{
File sourceDirectory = new File("target/it").getAbsoluteFile();
String[] fileList = new String[] { "Main.java" };
Collection<String> excludePackages = Collections.singleton( "*.it" );
List<String> includedFiles = JavadocUtil.getIncludedFiles( sourceDirectory, fileList, excludePackages );
assertThat( includedFiles.toArray( new String[0] ) ).isEqualTo( fileList );
}
private void stopSilently( Server server )
{
try
{
if ( server != null )
{
server.stop();
}
}
catch ( Exception e )
{
// ignored
}
}
}