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