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