View Javadoc
1   package org.apache.maven.plugins.javadoc;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import static org.apache.commons.io.FileUtils.copyDirectory;
23  import static org.apache.commons.io.FileUtils.deleteDirectory;
24  import static org.assertj.core.api.Assertions.assertThat;
25  import static org.junit.Assume.assumeThat;
26  import static org.hamcrest.CoreMatchers.anyOf;
27  import static org.hamcrest.CoreMatchers.containsString;
28  import static org.hamcrest.CoreMatchers.is;
29  
30  import static org.mockito.Mockito.mock;
31  import static org.mockito.Mockito.spy;
32  import static org.mockito.Mockito.when;
33  
34  import java.io.File;
35  import java.io.IOException;
36  import java.net.HttpURLConnection;
37  import java.net.URL;
38  import java.nio.charset.Charset;
39  import java.nio.charset.StandardCharsets;
40  import java.nio.file.Files;
41  import java.nio.file.Path;
42  import java.util.HashMap;
43  import java.util.List;
44  import java.util.Map;
45  import java.util.Objects;
46  
47  import org.apache.maven.execution.MavenSession;
48  import org.apache.maven.model.Plugin;
49  import org.apache.maven.plugin.LegacySupport;
50  import org.apache.maven.plugin.MojoExecution;
51  import org.apache.maven.plugin.MojoExecutionException;
52  import org.apache.maven.plugin.testing.AbstractMojoTestCase;
53  import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
54  import org.apache.maven.plugins.javadoc.ProxyServer.AuthAsyncProxyServlet;
55  import org.apache.maven.project.MavenProject;
56  import org.apache.maven.project.ProjectBuildingRequest;
57  import org.apache.maven.repository.internal.MavenRepositorySystemSession;
58  import org.apache.maven.settings.Proxy;
59  import org.apache.maven.settings.Settings;
60  import org.apache.maven.shared.utils.StringUtils;
61  import org.apache.maven.shared.utils.io.FileUtils;
62  import org.codehaus.plexus.languages.java.version.JavaVersion;
63  import org.hamcrest.MatcherAssert;
64  import org.junit.AssumptionViolatedException;
65  import org.junit.Ignore;
66  import org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager;
67  
68  /**
69   * Test {@link org.apache.maven.plugins.javadoc.JavadocReport} class.
70   *
71   * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
72   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
73   */
74  public class JavadocReportTest
75      extends AbstractMojoTestCase
76  {
77  
78      private static final char LINE_SEPARATOR = ' ';
79  
80      public static final String OPTIONS_UMLAUT_ENCODING = "Options Umlaut Encoding ö ä ü ß";
81  
82      /** flag to copy repo only one time */
83      private static boolean TEST_REPO_CREATED = false;
84  
85      private Path unit;
86  
87      private File localRepo;
88  
89      /** {@inheritDoc} */
90      @Override
91      protected void setUp()
92          throws Exception
93      {
94          super.setUp();
95  
96          unit = new File( getBasedir(), "src/test/resources/unit" ).toPath();
97  
98          localRepo = new File( getBasedir(), "target/local-repo/" );
99  
100         createTestRepo();
101     }
102 
103 
104     private JavadocReport lookupMojo( Path testPom )
105         throws Exception
106     {
107         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom.toFile() );
108 
109         MojoExecution mojoExec = new MojoExecution( new Plugin(), "javadoc", null );
110 
111         setVariableValueToObject( mojo, "mojo", mojoExec );
112 
113         MavenProject currentProject = new MavenProjectStub();
114         currentProject.setGroupId( "GROUPID" );
115         currentProject.setArtifactId( "ARTIFACTID" );
116 
117         setVariableValueToObject( mojo, "session", newMavenSession( currentProject ) );
118 
119         return mojo;
120     }
121 
122     /**
123      * Create test repository in target directory.
124      *
125      * @throws IOException if any
126      */
127     private void createTestRepo()
128         throws IOException
129     {
130         if ( TEST_REPO_CREATED )
131         {
132             return;
133         }
134 
135         localRepo.mkdirs();
136 
137         // ----------------------------------------------------------------------
138         // UMLGraph
139         // ----------------------------------------------------------------------
140 
141         Path sourceDir = unit.resolve( "doclet-test/artifact-doclet" );
142         assertThat( sourceDir ).exists();
143         copyDirectory( sourceDir.toFile(), localRepo );
144 
145         // ----------------------------------------------------------------------
146         // UMLGraph-bis
147         // ----------------------------------------------------------------------
148 
149         sourceDir = unit.resolve( "doclet-path-test/artifact-doclet" );
150         assertThat( sourceDir ).exists();
151         copyDirectory( sourceDir.toFile(), localRepo );
152 
153         // ----------------------------------------------------------------------
154         // commons-attributes-compiler
155         // http://www.tullmann.org/pat/taglets/
156         // ----------------------------------------------------------------------
157 
158         sourceDir = unit.resolve( "taglet-test/artifact-taglet" );
159         assertThat( sourceDir ).exists();
160         copyDirectory( sourceDir.toFile(), localRepo );
161 
162         // ----------------------------------------------------------------------
163         // stylesheetfile-test
164         // ----------------------------------------------------------------------
165 
166         sourceDir = unit.resolve( "stylesheetfile-test/artifact-stylesheetfile" );
167         assertThat( sourceDir ).exists();
168         copyDirectory( sourceDir.toFile(), localRepo );
169 
170         // ----------------------------------------------------------------------
171         // helpfile-test
172         // ----------------------------------------------------------------------
173 
174         sourceDir = unit.resolve( "helpfile-test/artifact-helpfile" );
175         assertThat( sourceDir ).exists();
176         copyDirectory( sourceDir.toFile(), localRepo );
177 
178         // Remove SCM files
179         List<String> files =
180             FileUtils.getFileAndDirectoryNames( localRepo, FileUtils.getDefaultExcludesAsString(), null, true,
181                                                 true, true, true );
182         for ( String filename : files )
183         {
184             File file = new File( filename );
185 
186             if ( file.isDirectory() )
187             {
188                 deleteDirectory( file );
189             }
190             else
191             {
192                 file.delete();
193             }
194         }
195 
196         TEST_REPO_CREATED = true;
197     }
198 
199     /**
200      * Convenience method that reads the contents of the specified file object into a string with a
201      * <code>space</code> as line separator.
202      *
203      * @see #LINE_SEPARATOR
204      * @param file the file to be read
205      * @return a String object that contains the contents of the file
206      * @throws IOException if any
207      */
208     private static String readFile( Path file )
209         throws IOException
210     {
211         return readFile( file, StandardCharsets.UTF_8 );
212     }
213 
214     /**
215      * Convenience method that reads the contents of the specified file object into a string with a
216      * <code>space</code> as line separator.
217      *
218      * @see #LINE_SEPARATOR
219      * @param file the file to be read
220      * @param cs charset to use
221      * @return a String object that contains the contents of the file
222      * @throws IOException if any
223      */
224     private static String readFile( Path file, Charset cs )
225             throws IOException
226     {
227         StringBuilder str = new StringBuilder( (int) Files.size( file ) );
228 
229         for ( String strTmp : Files.readAllLines( file, cs ) )
230         {
231             str.append( LINE_SEPARATOR);
232             str.append( strTmp );
233         }
234 
235         return str.toString();
236     }
237 
238     /**
239      * Test when default configuration is provided for the plugin
240      *
241      * @throws Exception if any
242      */
243     public void testDefaultConfiguration()
244         throws Exception
245     {
246         Path testPom = unit.resolve( "default-configuration/default-configuration-plugin-config.xml" );
247         JavadocReport mojo = lookupMojo( testPom );
248         mojo.execute();
249 
250         // package level generated javadoc files
251         Path apidocs = new File( getBasedir(), "target/test/unit/default-configuration/target/site/apidocs" ).toPath();
252 
253         String appHtml = "def/configuration/App.html";
254         Path generatedFile = apidocs.resolve( appHtml );
255         assertThat( generatedFile ).exists();
256 
257         // only test when URL can be reached
258 
259         String url = Objects.requireNonNull( mojo.getDefaultJavadocApiLink() ).getUrl();
260         HttpURLConnection connection = (HttpURLConnection) new URL( url ).openConnection();
261         connection.setRequestMethod( "HEAD" );
262         if ( connection.getResponseCode() == HttpURLConnection.HTTP_OK  )
263         {
264             try 
265             {
266                 assumeThat( connection.getURL().toString(), is( url ) );
267 
268                 // https://bugs.openjdk.java.net/browse/JDK-8216497
269                 MatcherAssert.assertThat( url + " available, but " + appHtml + " is missing link to java.lang.Object",
270                             new String( Files.readAllBytes(generatedFile), StandardCharsets.UTF_8 ),
271                             anyOf( containsString( "/docs/api/java/lang/Object.html" ), 
272                             containsString( "/docs/api/java.base/java/lang/Object.html" ) ) );
273             }
274             catch ( AssumptionViolatedException e )
275             {
276                 System.out.println( "Warning: ignoring defaultAPI check: " + e.getMessage() );
277             }
278         }
279 
280         assertThat( apidocs.resolve( "def/configuration/AppSample.html" )).exists();
281         assertThat( apidocs.resolve( "def/configuration/package-summary.html" )).exists();
282         assertThat( apidocs.resolve( "def/configuration/package-tree.html" )).exists();
283         assertThat( apidocs.resolve( "def/configuration/package-use.html" )).exists();
284 
285         // package-frame and allclasses-(no)frame not generated anymore since Java 11
286         if ( JavaVersion.JAVA_SPECIFICATION_VERSION.isBefore( "11" ) )
287         {
288             assertThat( apidocs.resolve( "def/configuration/package-frame.html" )).exists();;
289             assertThat( apidocs.resolve( "allclasses-frame.html" )).exists();
290             assertThat( apidocs.resolve( "allclasses-noframe.html" )).exists();
291         }
292 
293         // class level generated javadoc files
294         assertThat( apidocs.resolve( "def/configuration/class-use/App.html" )).exists();
295         assertThat( apidocs.resolve( "def/configuration/class-use/AppSample.html" )).exists();
296 
297         // project level generated javadoc files
298         assertThat( apidocs.resolve( "constant-values.html" )).exists();
299         assertThat( apidocs.resolve( "deprecated-list.html" ) ).exists();
300         assertThat( apidocs.resolve( "help-doc.html" )).exists();
301         assertThat( apidocs.resolve( "index-all.html" )).exists();
302         assertThat( apidocs.resolve( "index.html" )).exists();
303         assertThat( apidocs.resolve( "overview-tree.html" )).exists();
304         assertThat( apidocs.resolve( "stylesheet.css" )).exists();
305 
306         if ( JavaVersion.JAVA_VERSION.isAtLeast( "10" ) )
307         {
308             assertThat( apidocs.resolve( "element-list" )).exists();
309         }
310         else
311         {
312             assertThat( apidocs.resolve( "package-list" )).exists();
313         }
314     }
315 
316     /**
317      * Method for testing the subpackages and excludePackageNames parameter
318      *
319      * @throws Exception if any
320      */
321     public void testSubpackages()
322         throws Exception
323     {
324         Path testPom = unit.resolve( "subpackages-test/subpackages-test-plugin-config.xml" );
325         JavadocReport mojo = lookupMojo( testPom );
326         mojo.execute();
327 
328         Path apidocs = new File( getBasedir(), "target/test/unit/subpackages-test/target/site/apidocs" ).toPath();
329 
330         // check the excluded packages
331         assertThat( apidocs.resolve( "subpackages/test/excluded" ) ).doesNotExist();
332         assertThat( apidocs.resolve( "subpackages/test/included/exclude" ) ).doesNotExist();
333 
334         // check if the classes in the specified subpackages were included
335         assertThat( apidocs.resolve( "subpackages/test/App.html" ) ).exists();
336         assertThat( apidocs.resolve( "subpackages/test/AppSample.html" ) ).exists();
337         assertThat( apidocs.resolve( "subpackages/test/included/IncludedApp.html" ) ).exists();
338         assertThat( apidocs.resolve( "subpackages/test/included/IncludedAppSample.html" ) ).exists();
339     }
340 
341     public void testIncludesExcludes()
342             throws Exception
343     {
344         Path testPom = unit.resolve( "file-include-exclude-test/file-include-exclude-plugin-config.xml" );
345         JavadocReport mojo = lookupMojo( testPom );
346         mojo.execute();
347 
348         Path apidocs = new File( getBasedir(), "target/test/unit/file-include-exclude-test/target/site/apidocs" ).toPath();
349 
350         // check if the classes in the specified subpackages were included
351         assertThat( apidocs.resolve( "subpackages/test/App.html" ) ).exists();
352         assertThat( apidocs.resolve( "subpackages/test/AppSample.html" ) ).exists();
353         assertThat( apidocs.resolve( "subpackages/test/included/IncludedApp.html" ) ).exists();
354         assertThat( apidocs.resolve( "subpackages/test/included/IncludedAppSample.html" ) ).exists();
355         assertThat( apidocs.resolve( "subpackages/test/PariahApp.html" ) ).doesNotExist();
356     }
357 
358     /**
359      * Test the recursion and exclusion of the doc-files subdirectories.
360      *
361      * @throws Exception if any
362      */
363     public void testDocfiles()
364         throws Exception
365     {
366         // Should be an assumption, but not supported by TestCase
367         // Seems like a bug in Javadoc 9 and above
368         if ( JavaVersion.JAVA_SPECIFICATION_VERSION.isAtLeast( "9" ) )
369         {
370             return;
371         }
372 
373         Path testPom = unit.resolve( "docfiles-test/docfiles-test-plugin-config.xml" );
374         JavadocReport mojo = lookupMojo( testPom );
375         mojo.execute();
376 
377         Path apidocs = new File( getBasedir(), "target/test/unit/docfiles-test/target/site/apidocs/" ).toPath();
378 
379         // check if the doc-files subdirectories were copied
380         assertThat( apidocs.resolve( "docfiles/test/doc-files" )).exists();
381         assertThat( apidocs.resolve( "docfiles/test/doc-files/included-dir1/sample-included1.gif" )).exists();
382         assertThat( apidocs.resolve( "docfiles/test/doc-files/included-dir2/sample-included2.gif" )).exists();
383         assertThat( apidocs.resolve( "docfiles/test/doc-files/excluded-dir1" )).doesNotExist();
384         assertThat( apidocs.resolve( "docfiles/test/doc-files/excluded-dir2" )).doesNotExist();
385 
386         testPom = unit.resolve( "docfiles-with-java-test/docfiles-with-java-test-plugin-config.xml" );
387         mojo = lookupMojo( testPom );
388         mojo.execute();
389     }
390 
391     /**
392      * Test javadoc plugin using custom configuration. noindex, notree and nodeprecated parameters
393      * were set to true.
394      *
395      * @throws Exception if any
396      */
397     public void testCustomConfiguration()
398         throws Exception
399     {
400         Path testPom = unit.resolve( "custom-configuration/custom-configuration-plugin-config.xml" );
401         JavadocReport mojo = lookupMojo( testPom );
402         mojo.execute();
403 
404         Path apidocs = new File( getBasedir(), "target/test/unit/custom-configuration/target/site/apidocs" ).toPath();
405 
406         // check if there is a tree page generated (notree == true)
407         assertThat( apidocs.resolve( "overview-tree.html" ) ).doesNotExist();
408         assertThat( apidocs.resolve( "custom/configuration/package-tree.html" ) ).doesNotExist();
409 
410         // check if the main index page was generated (noindex == true)
411         assertThat( apidocs.resolve( "index-all.html" ) ).doesNotExist();
412 
413         // check if the deprecated list and the deprecated api were generated (nodeprecated == true)
414         // @todo Fix: the class-use of the deprecated api is still created eventhough the deprecated api of that class
415         // is no longer generated
416         assertThat( apidocs.resolve( "deprecated-list.html" ) ).doesNotExist();
417         assertThat( apidocs.resolve( "custom/configuration/App.html" ) ).doesNotExist();
418 
419         // read the contents of the html files based on some of the parameter values
420         // author == false
421         String str = readFile( apidocs.resolve( "custom/configuration/AppSample.html" ) );
422         assertFalse( str.toLowerCase().contains( "author" ) );
423 
424         // bottom
425         assertTrue( str.toUpperCase().contains( "SAMPLE BOTTOM CONTENT" ) );
426 
427         // offlineLinks
428         if ( JavaVersion.JAVA_VERSION.isBefore( "11.0.2" ) )
429         {
430             assertThat( str ).containsIgnoringCase(
431                     "href=\"http://java.sun.com/j2se/1.4.2/docs/api/java/lang/string.html" );
432         }
433         else
434         {
435             assertTrue( str.toLowerCase().contains(
436                     "href=\"http://java.sun.com/j2se/1.4.2/docs/api/java.base/java/lang/string.html" ) );
437         }
438 
439         // header
440         assertTrue( str.toUpperCase().contains( "MAVEN JAVADOC PLUGIN TEST" ) );
441 
442         // footer
443         if ( JavaVersion.JAVA_VERSION.isBefore( "16-ea" ) )
444         {
445             assertTrue( str.toUpperCase().contains( "MAVEN JAVADOC PLUGIN TEST FOOTER" ) );
446         }
447 
448         // nohelp == true
449         assertFalse( str.toUpperCase().contains( "/HELP-DOC.HTML" ) );
450 
451         // check the wildcard (*) package exclusions -- excludePackageNames parameter
452         assertThat( apidocs.resolve( "custom/configuration/exclude1/Exclude1App.html" ) ).exists();
453         assertThat( apidocs.resolve( "custom/configuration/exclude1/subexclude/SubexcludeApp.html" ) ).doesNotExist();
454         assertThat( apidocs.resolve( "custom/configuration/exclude2/Exclude2App.html" ) ).doesNotExist();
455 
456         assertThat( apidocs.resolve( "options" ) ).isRegularFile();
457 
458         String contentOptions = new String( Files.readAllBytes( apidocs.resolve( "options" ) ), StandardCharsets.UTF_8 );
459 
460         assertNotNull( contentOptions );
461         assertThat( contentOptions ).contains( "-link" ).contains( "http://java.sun.com/j2se/" );
462     }
463 
464     /**
465      * Method to test the doclet artifact configuration
466      *
467      * @throws Exception if any
468      */
469     public void testDoclets()
470         throws Exception
471     {
472         if ( JavaVersion.JAVA_SPECIFICATION_VERSION.isAtLeast( "13" ) )
473         {
474             // As of JDK 13, the com.sun.javadoc API is no longer supported.
475             return;
476         }
477 
478         // ----------------------------------------------------------------------
479         // doclet-test: check if the file generated by UmlGraph exists and if
480         // doclet path contains the UmlGraph artifact
481         // ----------------------------------------------------------------------
482 
483         Path testPom = unit.resolve( "doclet-test/doclet-test-plugin-config.xml" );
484         JavadocReport mojo = lookupMojo( testPom );
485 
486         MavenSession session = spy( newMavenSession( mojo.project ) );
487         ProjectBuildingRequest buildingRequest = mock( ProjectBuildingRequest.class );
488         when( buildingRequest.getRemoteRepositories() ).thenReturn( mojo.project.getRemoteArtifactRepositories() );
489         when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
490         MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
491         repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManager( localRepo ) );
492         when( buildingRequest.getRepositorySession() ).thenReturn( repositorySession );
493         when( session.getRepositorySession() ).thenReturn( repositorySession );
494         LegacySupport legacySupport = lookup( LegacySupport.class );
495         legacySupport.setSession( session );
496 
497         setVariableValueToObject( mojo, "session", session );
498 
499         mojo.execute();
500 
501         Path generatedFile = new File( getBasedir(), "target/test/unit/doclet-test/target/site/apidocs/graph.dot" ).toPath();
502         assertThat( generatedFile ).exists();
503 
504         Path optionsFile = new File( mojo.getOutputDirectory(), "options" ).toPath();
505         assertThat( optionsFile ).exists();
506         String options = readFile( optionsFile );
507         assertThat( options ).contains( "/target/local-repo/umlgraph/UMLGraph/2.1/UMLGraph-2.1.jar" );
508 
509         // ----------------------------------------------------------------------
510         // doclet-path: check if the file generated by UmlGraph exists and if
511         // doclet path contains the twice UmlGraph artifacts
512         // ----------------------------------------------------------------------
513 
514         testPom = unit.resolve( "doclet-path-test/doclet-path-test-plugin-config.xml" );
515         mojo = lookupMojo( testPom );
516         setVariableValueToObject( mojo, "session", session );
517         mojo.execute();
518 
519         generatedFile = new File( getBasedir(), "target/test/unit/doclet-test/target/site/apidocs/graph.dot" ).toPath();
520         assertThat( generatedFile ).exists();
521 
522         optionsFile = new File( mojo.getOutputDirectory(), "options" ).toPath();
523         assertThat( optionsFile ).exists();
524         options = readFile( optionsFile );
525         assertThat( options ).contains( "/target/local-repo/umlgraph/UMLGraph/2.1/UMLGraph-2.1.jar" )
526                 .contains( "/target/local-repo/umlgraph/UMLGraph-bis/2.1/UMLGraph-bis-2.1.jar" );
527     }
528 
529     /**
530      * Method to test when the path to the project sources has an apostrophe (')
531      *
532      * @throws Exception if any
533      */
534     public void testQuotedPath()
535         throws Exception
536     {
537         Path testPom = unit.resolve( "quotedpath'test/quotedpath-test-plugin-config.xml" );
538         JavadocReport mojo = lookupMojo( testPom );
539         mojo.execute();
540 
541         Path apidocs = new File( getBasedir(), "target/test/unit/quotedpath'test/target/site/apidocs" ).toPath();
542 
543         // package level generated javadoc files
544         assertThat( apidocs.resolve( "quotedpath/test/App.html" ) ).exists();
545         assertThat( apidocs.resolve( "quotedpath/test/AppSample.html" ) ).exists();
546 
547         // project level generated javadoc files
548         assertThat( apidocs.resolve( "index-all.html" ) ).exists();
549         assertThat( apidocs.resolve( "index.html" ) ).exists();
550         assertThat( apidocs.resolve( "overview-tree.html" ) ).exists();
551         assertThat( apidocs.resolve( "stylesheet.css" ) ).exists();
552 
553         if ( JavaVersion.JAVA_VERSION.isBefore( "10" ) )
554         {
555             assertThat( apidocs.resolve( "package-list" ) ).exists();
556         }
557         else
558         {
559             assertThat( apidocs.resolve( "element-list" ) ).exists();
560         }
561     }
562 
563     /**
564      * Method to test when the options file has umlauts.
565      *
566      * @throws Exception if any
567      */
568     public void testOptionsUmlautEncoding()
569         throws Exception
570     {
571         Path testPom = unit.resolve( "optionsumlautencoding-test/optionsumlautencoding-test-plugin-config.xml" );
572         JavadocReport mojo = lookupMojo( testPom );
573         mojo.execute();
574 
575         Path optionsFile = new File( mojo.getOutputDirectory(), "options" ).toPath();
576         assertThat( optionsFile ).exists();
577 
578         // check for a part of the window title
579         String content;
580         String expected;
581         if ( JavaVersion.JAVA_VERSION.isAtLeast( "9" ) && JavaVersion.JAVA_VERSION.isBefore( "12" ) )
582         {
583             content = readFile( optionsFile, StandardCharsets.UTF_8 );
584             expected = OPTIONS_UMLAUT_ENCODING;
585         }
586         else
587         {
588             content = readFile( optionsFile, Charset.defaultCharset() );
589             expected = new String( OPTIONS_UMLAUT_ENCODING.getBytes( Charset.defaultCharset() ) );
590         }
591 
592         assertThat( content ).contains( expected );
593 
594         Path apidocs = new File( getBasedir(), "target/test/unit/optionsumlautencoding-test/target/site/apidocs" ).toPath();
595 
596         // package level generated javadoc files
597         assertThat( apidocs.resolve( "optionsumlautencoding/test/App.html" ) ).exists();
598         assertThat( apidocs.resolve( "optionsumlautencoding/test/AppSample.html" ) ).exists();
599 
600         // project level generated javadoc files
601         assertThat( apidocs.resolve( "index-all.html" ) ).exists();
602         assertThat( apidocs.resolve( "index.html" ) ).exists();
603         assertThat( apidocs.resolve( "overview-tree.html" ) ).exists();
604         assertThat( apidocs.resolve( "stylesheet.css" ) ).exists();
605 
606         if ( JavaVersion.JAVA_VERSION.isBefore( "10" ) )
607         {
608             assertThat( apidocs.resolve( "package-list" )).exists();
609         }
610         else
611         {
612             assertThat( apidocs.resolve( "element-list" )).exists();
613         }
614     }
615 
616     /**
617      * @throws Exception if any
618      */
619     public void testExceptions()
620         throws Exception
621     {
622         try
623         {
624             Path testPom = unit.resolve( "default-configuration/exception-test-plugin-config.xml" );
625             JavadocReport mojo = lookupMojo( testPom );
626             mojo.execute();
627 
628             fail( "Must throw exception." );
629         }
630         catch ( Exception e )
631         {
632             assertTrue( true );
633 
634             try
635             {
636                 deleteDirectory( new File( getBasedir(), "exception" ) );
637             }
638             catch ( IOException ie )
639             {
640                 // nop
641             }
642         }
643     }
644 
645     /**
646      * Method to test the taglet artifact configuration
647      *
648      * @throws Exception if any
649      */
650     public void testTaglets()
651         throws Exception
652     {
653         // ----------------------------------------------------------------------
654         // taglet-test: check if a taglet is used
655         // ----------------------------------------------------------------------
656 
657         // Should be an assumption, but not supported by TestCase
658         // com.sun.tools.doclets.Taglet not supported by Java9 anymore
659         // Should be refactored with jdk.javadoc.doclet.Taglet
660         if ( JavaVersion.JAVA_SPECIFICATION_VERSION.isAtLeast( "10" ) )
661         {
662             return;
663         }
664 
665         Path testPom = unit.resolve( "taglet-test/taglet-test-plugin-config.xml" );
666         JavadocReport mojo = lookupMojo( testPom );
667 
668         MavenSession session = spy( newMavenSession( mojo.project ) );
669         ProjectBuildingRequest buildingRequest = mock( ProjectBuildingRequest.class );
670         when( buildingRequest.getRemoteRepositories() ).thenReturn( mojo.project.getRemoteArtifactRepositories() );
671         when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
672         MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
673         repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManager( localRepo ) );
674         when( buildingRequest.getRepositorySession() ).thenReturn( repositorySession );
675         when( session.getRepositorySession() ).thenReturn( repositorySession );
676         LegacySupport legacySupport = lookup( LegacySupport.class );
677         legacySupport.setSession( session );
678 
679         setVariableValueToObject( mojo, "session", session );
680 
681         mojo.execute();
682 
683         Path apidocs = new File( getBasedir(), "target/test/unit/taglet-test/target/site/apidocs" ).toPath();
684 
685         assertThat( apidocs.resolve( "index.html" )).exists();
686 
687         Path appFile = apidocs.resolve( "taglet/test/App.html" );
688         assertThat( appFile ).exists();
689         String appString = readFile( appFile );
690         assertThat( appString ).contains( "<b>To Do:</b>" );
691     }
692 
693     /**
694      * Method to test the jdk5 javadoc
695      *
696      * @throws Exception if any
697      */
698     public void testJdk5()
699         throws Exception
700     {
701         // Should be an assumption, but not supported by TestCase
702         // Java 5 not supported by Java9 anymore
703         if ( JavaVersion.JAVA_SPECIFICATION_VERSION.isAtLeast( "9" ) )
704         {
705             return;
706         }
707 
708         Path testPom = unit.resolve( "jdk5-test/jdk5-test-plugin-config.xml" );
709         JavadocReport mojo = lookupMojo( testPom );
710         mojo.execute();
711 
712         Path apidocs = new File( getBasedir(), "target/test/unit/jdk5-test/target/site/apidocs" ).toPath();
713 
714         assertThat( apidocs.resolve( "index.html" ) ).exists();
715 
716         Path overviewSummary = apidocs.resolve( "overview-summary.html" );
717         assertThat( overviewSummary ).exists();
718         String content = readFile( overviewSummary );
719         assertThat( content ).contains( "<b>Test the package-info</b>" );
720 
721         Path packageSummary = apidocs.resolve( "jdk5/test/package-summary.html" );
722         assertThat( packageSummary ).exists();
723         content = readFile( packageSummary );
724         assertThat( content ).contains( "<b>Test the package-info</b>" );
725     }
726 
727     /**
728      * Test to find the javadoc executable when <code>java.home</code> is not in the JDK_HOME. In this case, try to
729      * use the <code>JAVA_HOME</code> environment variable.
730      *
731      * @throws Exception if any
732      */
733     public void testToFindJavadoc()
734         throws Exception
735     {
736         String oldJreHome = System.getProperty( "java.home" );
737         System.setProperty( "java.home", "foo/bar" );
738 
739         Path testPom = unit.resolve( "javaHome-test/javaHome-test-plugin-config.xml" );
740         JavadocReport mojo = lookupMojo( testPom );
741         mojo.execute();
742 
743         System.setProperty( "java.home", oldJreHome );
744     }
745 
746     /**
747      * Test the javadoc resources.
748      *
749      * @throws Exception if any
750      */
751     public void testJavadocResources()
752         throws Exception
753     {
754         Path testPom = unit.resolve( "resources-test/resources-test-plugin-config.xml" );
755         JavadocReport mojo = lookupMojo( testPom );
756         mojo.execute();
757 
758         Path apidocs = new File( getBasedir(), "target/test/unit/resources-test/target/site/apidocs/" ).toPath();
759 
760         Path app = apidocs.resolve( "resources/test/App.html" );
761         assertThat( app ).exists();
762         String content = readFile( app );
763         assertThat( content ).contains( "<img src=\"doc-files/maven-feather.png\" alt=\"Maven\">" );
764         assertThat( apidocs.resolve( "resources/test/doc-files/maven-feather.png" )).exists();
765 
766         Path app2 = apidocs.resolve( "resources/test2/App2.html" );
767         assertThat( app2 ).exists();
768         content = readFile( app2 );
769         assertThat( content ).contains( "<img src=\"doc-files/maven-feather.png\" alt=\"Maven\">" );
770         assertThat( apidocs.resolve( "resources/test2/doc-files/maven-feather.png" )).doesNotExist();
771 
772         // with excludes
773         testPom = unit.resolve( "resources-with-excludes-test/resources-with-excludes-test-plugin-config.xml" );
774         mojo = lookupMojo( testPom );
775         mojo.execute();
776 
777         apidocs = new File( getBasedir(),
778                 "target/test/unit/resources-with-excludes-test/target/site/apidocs" ).toPath();
779 
780         app = apidocs.resolve( "resources/test/App.html" );
781         assertThat( app ).exists();
782         content = readFile( app );
783         assertThat( content ).contains( "<img src=\"doc-files/maven-feather.png\" alt=\"Maven\">" );
784 
785         JavaVersion javadocVersion = (JavaVersion) getVariableValueFromObject( mojo, "javadocRuntimeVersion" );
786         if( javadocVersion.isAtLeast( "1.8" ) /* && javadocVersion.isBefore( "14" ) */ )
787         {
788             // https://bugs.openjdk.java.net/browse/JDK-8032205
789             assertThat( apidocs.resolve( "resources/test/doc-files/maven-feather.png" ))
790                     .as("Javadoc runtime version: " + javadocVersion
791                             + "\nThis bug appeared in JDK8 and was planned to be fixed in JDK9, see JDK-8032205")
792                     .exists();
793         }
794         else
795         {
796             assertThat( apidocs.resolve( "resources/test/doc-files/maven-feather.png" ) ).doesNotExist();
797         }
798         assertThat( apidocs.resolve( "resources/test2/doc-files/maven-feather.png" ) ).exists();
799 
800         app2 = apidocs.resolve( "resources/test2/App2.html" );
801         assertThat( app2 ).exists();
802         content = readFile( app2 );
803         assertThat( content ).contains( "<img src=\"doc-files/maven-feather.png\" alt=\"Maven\">" );
804         assertThat( apidocs.resolve( "resources/test2/doc-files/maven-feather.png" ) ).exists();
805     }
806 
807     /**
808      * Test the javadoc for a POM project.
809      *
810      * @throws Exception if any
811      */
812     public void testPom()
813         throws Exception
814     {
815         Path testPom = unit.resolve( "pom-test/pom-test-plugin-config.xml" );
816         JavadocReport mojo = lookupMojo( testPom );
817         mojo.execute();
818 
819         assertThat( new File( getBasedir(), "target/test/unit/pom-test/target/site" )).doesNotExist();
820     }
821 
822     /**
823      * Test the javadoc with tag.
824      *
825      * @throws Exception if any
826      */
827     public void testTag()
828         throws Exception
829     {
830         Path testPom = unit.resolve( "tag-test/tag-test-plugin-config.xml" );
831         JavadocReport mojo = lookupMojo( testPom );
832         mojo.execute();
833 
834         Path app = new File( getBasedir(), "target/test/unit/tag-test/target/site/apidocs/tag/test/App.html" ).toPath();
835         assertThat( app ).exists();
836         String readed = readFile( app );
837         assertThat( readed ).contains( ">To do something:</" ).contains( ">Generator Class:</" );
838 
839         // In javadoc-options-javadoc-resources.xml tag 'version' has only a name,
840         // which is not enough for Java 11 anymore
841         if ( JavaVersion.JAVA_SPECIFICATION_VERSION.isBefore( "11" ) )
842         {
843             assertThat( readed ).contains( ">Version:</" );
844             assertTrue( readed.toLowerCase().contains( "</dt>" + LINE_SEPARATOR + "  <dd>1.0</dd>" ) || readed.toLowerCase().contains(
845                     "</dt>" + LINE_SEPARATOR + "<dd>1.0</dd>" /* JDK 8 */ ) );
846         }
847     }
848 
849     /**
850      * Test newline in the header/footer parameter
851      *
852      * @throws Exception if any
853      */
854     public void testHeaderFooter()
855         throws Exception
856     {
857         Path testPom = unit.resolve( "header-footer-test/header-footer-test-plugin-config.xml" );
858         JavadocReport mojo = lookupMojo( testPom );
859         try
860         {
861             mojo.execute();
862         }
863         catch ( MojoExecutionException e )
864         {
865             fail( "Doesnt handle correctly newline for header or footer parameter" );
866         }
867 
868         assertTrue( true );
869     }
870 
871     /**
872      * Test newline in various string parameters
873      *
874      * @throws Exception if any
875      */
876     public void testNewline()
877         throws Exception
878     {
879         Path testPom = unit.resolve( "newline-test/newline-test-plugin-config.xml" );
880         JavadocReport mojo = lookupMojo( testPom );
881         try
882         {
883             mojo.execute();
884         }
885         catch ( MojoExecutionException e )
886         {
887             fail( "Doesn't handle correctly newline for string parameters. See options and packages files." );
888         }
889 
890         assertTrue( true );
891     }
892 
893     /**
894      * Method to test the jdk6 javadoc
895      *
896      * @throws Exception if any
897      */
898     public void testJdk6()
899         throws Exception
900     {
901         // Should be an assumption, but not supported by TestCase
902         // Java 6 not supported by Java 12 anymore
903         if ( JavaVersion.JAVA_SPECIFICATION_VERSION.isAtLeast( "12" ) )
904         {
905             return;
906         }
907 
908         Path testPom = unit.resolve( "jdk6-test/jdk6-test-plugin-config.xml" );
909         JavadocReport mojo = lookupMojo( testPom );
910         mojo.execute();
911 
912         Path apidocs = new File( getBasedir(), "target/test/unit/jdk6-test/target/site/apidocs" ).toPath();
913         assertThat( apidocs.resolve( "index.html" ) ).exists();
914 
915         Path overview;
916         if ( JavaVersion.JAVA_SPECIFICATION_VERSION.isBefore( "11" ) )
917         {
918             overview = apidocs.resolve( "overview-summary.html" );
919         }
920         else
921         {
922             overview = apidocs.resolve( "index.html" );
923         }
924 
925         assertThat( overview ).exists();
926         String content = readFile( overview );
927         assertThat( content ).contains( "Top - Copyright &#169; All rights reserved." )
928                 .contains( "Header - Copyright &#169; All rights reserved." )
929                 .contains( "Footer - Copyright &#169; All rights reserved." );
930 
931         Path packageSummary = apidocs.resolve( "jdk6/test/package-summary.html" );
932         assertThat( packageSummary ).exists();
933         content = readFile( packageSummary );
934         assertThat( content ).contains( "Top - Copyright &#169; All rights reserved." )
935                 .contains( "Header - Copyright &#169; All rights reserved." )
936                 .contains( "Footer - Copyright &#169; All rights reserved." );
937     }
938 
939     /**
940      * Method to test proxy support in the javadoc
941      *
942      * @throws Exception if any
943      */
944     @Ignore("We don't really want to have unit test which need internet access")
945     public void testProxy()
946         throws Exception
947     {
948         // ignore test as annotation doesn't ignore anything..
949         if ( true )
950         {
951             return;
952         }
953         Settings settings = new Settings();
954         Proxy proxy = new Proxy();
955 
956         // dummy proxy
957         proxy.setActive( true );
958         proxy.setHost( "127.0.0.1" );
959         proxy.setPort( 80 );
960         proxy.setProtocol( "http" );
961         proxy.setUsername( "toto" );
962         proxy.setPassword( "toto" );
963         proxy.setNonProxyHosts( "www.google.com|*.somewhere.com" );
964         settings.addProxy( proxy );
965 
966         Path testPom = new File( getBasedir(), "src/test/resources/unit/proxy-test/proxy-test-plugin-config.xml" ).toPath();
967         JavadocReport mojo = lookupMojo( testPom );
968 
969         MavenSession session = spy( newMavenSession( mojo.project ) );
970         ProjectBuildingRequest buildingRequest = mock( ProjectBuildingRequest.class );
971         when( buildingRequest.getRemoteRepositories() ).thenReturn( mojo.project.getRemoteArtifactRepositories() );
972         when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
973         MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
974         repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManager( localRepo ) );
975         when( buildingRequest.getRepositorySession() ).thenReturn( repositorySession );
976         when( session.getRepositorySession() ).thenReturn( repositorySession );
977         LegacySupport legacySupport = lookup( LegacySupport.class );
978         legacySupport.setSession( session );
979 
980         setVariableValueToObject( mojo, "settings", settings );
981         setVariableValueToObject( mojo, "session", session );
982         mojo.execute();
983 
984         Path commandLine = new File( getBasedir(), "target/test/unit/proxy-test/target/site/apidocs/javadoc." + ( SystemUtils.IS_OS_WINDOWS ? "bat" : "sh" ) ).toPath();
985         assertThat( commandLine ).exists();
986         String readed = readFile( commandLine );
987         assertThat( readed ).contains( "-J-Dhttp.proxyHost=127.0.0.1" ).contains( "-J-Dhttp.proxyPort=80" )
988                 .contains( "-J-Dhttp.nonProxyHosts=\\\"www.google.com^|*.somewhere.com\\\"" );
989 
990         Path options = new File( getBasedir(), "target/test/unit/proxy-test/target/site/apidocs/options" ).toPath();
991         assertThat( options ).exists();
992         String optionsContent = readFile( options );
993         // NO -link expected
994         assertThat( optionsContent ).doesNotContain( "-link" );
995 
996         // real proxy
997         ProxyServer proxyServer = null;
998         AuthAsyncProxyServlet proxyServlet;
999         try
1000         {
1001             proxyServlet = new AuthAsyncProxyServlet();
1002             proxyServer = new ProxyServer( proxyServlet );
1003             proxyServer.start();
1004 
1005             settings = new Settings();
1006             proxy = new Proxy();
1007             proxy.setActive( true );
1008             proxy.setHost( proxyServer.getHostName() );
1009             proxy.setPort( proxyServer.getPort() );
1010             proxy.setProtocol( "http" );
1011             settings.addProxy( proxy );
1012 
1013             mojo = lookupMojo( testPom );
1014             setVariableValueToObject( mojo, "settings", settings );
1015             setVariableValueToObject( mojo, "session", session );
1016             mojo.execute();
1017             readed = readFile( commandLine );
1018             assertTrue( readed.contains( "-J-Dhttp.proxyHost=" + proxyServer.getHostName() ) );
1019             assertTrue( readed.contains( "-J-Dhttp.proxyPort=" + proxyServer.getPort() ) );
1020 
1021             optionsContent = readFile( options );
1022             // -link expected
1023             // TODO: This got disabled for now!
1024             // This test fails since the last commit but I actually think it only ever worked by accident.
1025             // It did rely on a commons-logging-1.0.4.pom which got resolved by a test which did run previously.
1026             // But after updating to commons-logging.1.1.1 there is no pre-resolved artifact available in
1027             // target/local-repo anymore, thus the javadoc link info cannot get built and the test fails
1028             // I'll for now just disable this line of code, because the test as far as I can see _never_
1029             // did go upstream. The remoteRepository list used is always empty!.
1030             //
1031             //            assertTrue( optionsContent.contains( "-link 'http://commons.apache.org/logging/apidocs'" ) );
1032         }
1033         finally
1034         {
1035             if ( proxyServer != null )
1036             {
1037                 proxyServer.stop();
1038             }
1039         }
1040 
1041         // auth proxy
1042         Map<String, String> authentications = new HashMap<>();
1043         authentications.put( "foo", "bar" );
1044         try
1045         {
1046             proxyServlet = new AuthAsyncProxyServlet( authentications );
1047             proxyServer = new ProxyServer( proxyServlet );
1048             proxyServer.start();
1049 
1050             settings = new Settings();
1051             proxy = new Proxy();
1052             proxy.setActive( true );
1053             proxy.setHost( proxyServer.getHostName() );
1054             proxy.setPort( proxyServer.getPort() );
1055             proxy.setProtocol( "http" );
1056             proxy.setUsername( "foo" );
1057             proxy.setPassword( "bar" );
1058             settings.addProxy( proxy );
1059 
1060             mojo = lookupMojo( testPom );
1061             setVariableValueToObject( mojo, "settings", settings );
1062             setVariableValueToObject( mojo, "session", session );
1063             mojo.execute();
1064             readed = readFile( commandLine );
1065             assertThat( readed ).contains( "-J-Dhttp.proxyHost=" + proxyServer.getHostName() )
1066                     .contains( "-J-Dhttp.proxyPort=" + proxyServer.getPort() );
1067 
1068             optionsContent = readFile( options );
1069             // -link expected
1070             // see comment above (line 829)
1071             //             assertTrue( optionsContent.contains( "-link 'http://commons.apache.org/logging/apidocs'" ) );
1072         }
1073         finally
1074         {
1075             if ( proxyServer != null )
1076             {
1077                 proxyServer.stop();
1078             }
1079         }
1080     }
1081 
1082     /**
1083      * Method to test error or conflict in Javadoc options and in standard doclet options.
1084      *
1085      * @throws Exception if any
1086      */
1087     public void testValidateOptions()
1088         throws Exception
1089     {
1090         // encoding
1091         Path testPom = unit.resolve( "validate-options-test/wrong-encoding-test-plugin-config.xml" );
1092         JavadocReport mojo = lookupMojo( testPom );
1093         try
1094         {
1095             mojo.execute();
1096             fail( "No wrong encoding catch" );
1097         }
1098         catch ( MojoExecutionException e )
1099         {
1100             assertTrue( "No wrong encoding catch", e.getMessage().contains( "Unsupported option <encoding/>" ) );
1101         }
1102         testPom = unit.resolve( "validate-options-test/wrong-docencoding-test-plugin-config.xml" );
1103         mojo = lookupMojo( testPom );
1104         try
1105         {
1106             mojo.execute();
1107             fail( "No wrong docencoding catch" );
1108         }
1109         catch ( MojoExecutionException e )
1110         {
1111             assertTrue( "No wrong docencoding catch", e.getMessage().contains( "Unsupported option <docencoding/>" ) );
1112         }
1113         testPom = unit.resolve( "validate-options-test/wrong-charset-test-plugin-config.xml" );
1114         mojo = lookupMojo( testPom );
1115         try
1116         {
1117             mojo.execute();
1118             fail( "No wrong charset catch" );
1119         }
1120         catch ( MojoExecutionException e )
1121         {
1122             assertTrue( "No wrong charset catch", e.getMessage().contains( "Unsupported option <charset/>" ) );
1123         }
1124 
1125         // locale
1126         testPom = unit.resolve( "validate-options-test/wrong-locale-test-plugin-config.xml" );
1127         mojo = lookupMojo( testPom );
1128         try
1129         {
1130             mojo.execute();
1131             fail( "No wrong locale catch" );
1132         }
1133         catch ( MojoExecutionException e )
1134         {
1135             assertTrue( "No wrong locale catch", e.getMessage().contains( "Unsupported option <locale/>" ) );
1136         }
1137         testPom = unit.resolve( "validate-options-test/wrong-locale-with-variant-test-plugin-config.xml" );
1138         mojo = lookupMojo( testPom );
1139         mojo.execute();
1140         assertTrue( "No wrong locale catch", true );
1141 
1142         // conflict options
1143         testPom = unit.resolve( "validate-options-test/conflict-options-test-plugin-config.xml" );
1144         mojo = lookupMojo( testPom );
1145         try
1146         {
1147             mojo.execute();
1148             fail( "No conflict catch" );
1149         }
1150         catch ( MojoExecutionException e )
1151         {
1152             assertTrue( "No conflict catch", e.getMessage().contains( "Option <nohelp/> conflicts with <helpfile/>" ) );
1153         }
1154     }
1155 
1156     /**
1157      * Method to test the <code>&lt;tagletArtifacts/&gt;</code> parameter.
1158      *
1159      * @throws Exception if any
1160      */
1161     public void testTagletArtifacts()
1162         throws Exception
1163     {
1164         // Should be an assumption, but not supported by TestCase
1165         // com.sun.tools.doclets.Taglet not supported by Java 10 anymore
1166         if ( JavaVersion.JAVA_SPECIFICATION_VERSION.isAtLeast( "10" ) )
1167         {
1168             return;
1169         }
1170 
1171         Path testPom = unit.resolve( "tagletArtifacts-test/tagletArtifacts-test-plugin-config.xml" );
1172         JavadocReport mojo = lookupMojo( testPom );
1173 
1174         MavenSession session = spy( newMavenSession( mojo.project ) );
1175         ProjectBuildingRequest buildingRequest = mock( ProjectBuildingRequest.class );
1176         when( buildingRequest.getRemoteRepositories() ).thenReturn( mojo.project.getRemoteArtifactRepositories() );
1177         when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
1178         MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
1179         repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManager( localRepo ) );
1180         when( buildingRequest.getRepositorySession() ).thenReturn( repositorySession );
1181         when( session.getRepositorySession() ).thenReturn( repositorySession );
1182         LegacySupport legacySupport = lookup( LegacySupport.class );
1183         legacySupport.setSession( session );
1184         setVariableValueToObject( mojo, "session", session );
1185 
1186         mojo.execute();
1187 
1188         Path optionsFile = new File( mojo.getOutputDirectory(), "options" ).toPath();
1189         assertThat( optionsFile ).exists();
1190         String options = readFile( optionsFile );
1191         // count -taglet
1192         assertThat( StringUtils.countMatches( options, LINE_SEPARATOR + "-taglet" + LINE_SEPARATOR ) ).isEqualTo( 22 );
1193         assertThat( options ).contains( "org.apache.maven.tools.plugin.javadoc.MojoAggregatorTypeTaglet" )
1194                 .contains( "org.apache.maven.tools.plugin.javadoc.MojoComponentFieldTaglet" )
1195                 .contains( "org.apache.maven.tools.plugin.javadoc.MojoConfiguratorTypeTaglet" )
1196                 .contains( "org.apache.maven.tools.plugin.javadoc.MojoExecuteTypeTaglet" )
1197                 .contains( "org.apache.maven.tools.plugin.javadoc.MojoExecutionStrategyTypeTaglet" )
1198                 .contains( "org.apache.maven.tools.plugin.javadoc.MojoGoalTypeTaglet" )
1199                 .contains( "org.apache.maven.tools.plugin.javadoc.MojoInheritByDefaultTypeTaglet" )
1200                 .contains( "org.apache.maven.tools.plugin.javadoc.MojoInstantiationStrategyTypeTaglet" )
1201                 .contains( "org.apache.maven.tools.plugin.javadoc.MojoParameterFieldTaglet" )
1202                 .contains( "org.apache.maven.tools.plugin.javadoc.MojoPhaseTypeTaglet" )
1203                 .contains( "org.apache.maven.tools.plugin.javadoc.MojoReadOnlyFieldTaglet" )
1204                 .contains( "org.apache.maven.tools.plugin.javadoc.MojoRequiredFieldTaglet" )
1205                 .contains( "org.apache.maven.tools.plugin.javadoc.MojoRequiresDependencyResolutionTypeTaglet" )
1206                 .contains( "org.apache.maven.tools.plugin.javadoc.MojoRequiresDirectInvocationTypeTaglet" )
1207                 .contains( "org.apache.maven.tools.plugin.javadoc.MojoRequiresOnLineTypeTaglet" )
1208                 .contains( "org.apache.maven.tools.plugin.javadoc.MojoRequiresProjectTypeTaglet" )
1209                 .contains( "org.apache.maven.tools.plugin.javadoc.MojoRequiresReportsTypeTaglet" )
1210                 .contains( "org.codehaus.plexus.javadoc.PlexusConfigurationTaglet" )
1211                 .contains( "org.codehaus.plexus.javadoc.PlexusRequirementTaglet" )
1212                 .contains( "org.codehaus.plexus.javadoc.PlexusComponentTaglet" );
1213     }
1214 
1215     /**
1216      * Method to test the <code>&lt;stylesheetfile/&gt;</code> parameter.
1217      *
1218      * @throws Exception if any
1219      */
1220     public void testStylesheetfile()
1221         throws Exception
1222     {
1223         Path testPom = unit.resolve( "stylesheetfile-test/pom.xml" );
1224 
1225         JavadocReport mojo = lookupMojo( testPom );
1226         assertNotNull( mojo );
1227 
1228         MavenSession session = spy( newMavenSession( mojo.project ) );
1229         ProjectBuildingRequest buildingRequest = mock( ProjectBuildingRequest.class );
1230         when( buildingRequest.getRemoteRepositories() ).thenReturn( mojo.project.getRemoteArtifactRepositories() );
1231         when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
1232         MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
1233         repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManager( localRepo ) );
1234         when( buildingRequest.getRepositorySession() ).thenReturn( repositorySession );
1235         when( session.getRepositorySession() ).thenReturn( repositorySession );
1236         LegacySupport legacySupport = lookup( LegacySupport.class );
1237         legacySupport.setSession( session );
1238         setVariableValueToObject( mojo, "session", session );
1239 
1240         Path apidocs = new File( getBasedir(), "target/test/unit/stylesheetfile-test/target/site/apidocs" ).toPath();
1241 
1242         Path stylesheetfile = apidocs.resolve( "stylesheet.css" );
1243         Path options = apidocs.resolve( "options" );
1244 
1245         // stylesheet == maven OR java
1246         setVariableValueToObject( mojo, "stylesheet", "javamaven" );
1247 
1248         try
1249         {
1250             mojo.execute();
1251             fail();
1252         }
1253         catch ( Exception e )
1254         {
1255             assertTrue( true );
1256         }
1257 
1258         // stylesheet == java
1259         setVariableValueToObject( mojo, "stylesheet", "java" );
1260         mojo.execute();
1261 
1262         String content = readFile( stylesheetfile );
1263         if ( JavaVersion.JAVA_VERSION.isAtLeast( "13-ea" ) )
1264         {
1265             assertTrue( content.contains( "/*" + LINE_SEPARATOR
1266                                         + " * Javadoc style sheet" + LINE_SEPARATOR
1267                                         + " */" ) );
1268         }
1269         else if ( JavaVersion.JAVA_VERSION.isAtLeast( "10" ) )
1270         {
1271             assertTrue( content.contains( "/* " + LINE_SEPARATOR
1272                                         + " * Javadoc style sheet" + LINE_SEPARATOR
1273                                         + " */" ) );
1274         }
1275         else
1276         {
1277             assertTrue( content.contains( "/* Javadoc style sheet */" ) );
1278         }
1279 
1280         String optionsContent = readFile( options );
1281         assertFalse( optionsContent.contains( "-stylesheetfile" ) );
1282 
1283         // stylesheet == maven
1284         setVariableValueToObject( mojo, "stylesheet", "maven" );
1285         mojo.execute();
1286 
1287         content = readFile( stylesheetfile );
1288         assertTrue( content.contains( "/* Javadoc style sheet */" )
1289             && content.contains( "Licensed to the Apache Software Foundation (ASF) under one" ) );
1290 
1291         optionsContent = readFile( options );
1292         assertTrue( optionsContent.contains( "-stylesheetfile" ) );
1293         assertTrue( optionsContent.contains( "'" + stylesheetfile.toFile().getAbsolutePath().replaceAll( "\\\\", "/" ) + "'" ) );
1294 
1295         // stylesheetfile defined as a project resource
1296         setVariableValueToObject( mojo, "stylesheet", null );
1297         setVariableValueToObject( mojo, "stylesheetfile", "com/mycompany/app/javadoc/css/stylesheet.css" );
1298         mojo.execute();
1299 
1300         content = readFile( stylesheetfile );
1301         assertTrue( content.contains( "/* Custom Javadoc style sheet in project */" ) );
1302 
1303         optionsContent = readFile( options );
1304         assertTrue( optionsContent.contains( "-stylesheetfile" ) );
1305         Path stylesheetResource =
1306                 unit.resolve( "stylesheetfile-test/src/main/resources/com/mycompany/app/javadoc/css/stylesheet.css" );
1307         assertTrue( optionsContent.contains( "'" + stylesheetResource.toFile().getAbsolutePath().replaceAll( "\\\\", "/" )
1308             + "'" ) );
1309 
1310         // stylesheetfile defined in a javadoc plugin dependency
1311         setVariableValueToObject( mojo, "stylesheetfile", "com/mycompany/app/javadoc/css2/stylesheet.css" );
1312         mojo.execute();
1313 
1314         content = readFile( stylesheetfile );
1315         assertTrue( content.contains( "/* Custom Javadoc style sheet in artefact */" ) );
1316 
1317         optionsContent = readFile( options );
1318         assertTrue( optionsContent.contains( "-stylesheetfile" ) );
1319         assertTrue( optionsContent.contains( "'" + stylesheetfile.toFile().getAbsolutePath().replaceAll( "\\\\", "/" ) + "'" ) );
1320 
1321         // stylesheetfile defined as file
1322         Path css =
1323                 unit.resolve( "stylesheetfile-test/src/main/resources/com/mycompany/app/javadoc/css3/stylesheet.css" );
1324         setVariableValueToObject( mojo, "stylesheetfile", css.toFile().getAbsolutePath() );
1325         mojo.execute();
1326 
1327         content = readFile( stylesheetfile );
1328         assertTrue( content.contains( "/* Custom Javadoc style sheet as file */" ) );
1329 
1330         optionsContent = readFile( options );
1331         assertTrue( optionsContent.contains( "-stylesheetfile" ) );
1332         stylesheetResource =
1333                 unit.resolve( "stylesheetfile-test/src/main/resources/com/mycompany/app/javadoc/css3/stylesheet.css" );
1334         assertTrue( optionsContent.contains( "'" + stylesheetResource.toFile().getAbsolutePath().replaceAll( "\\\\", "/" ) + "'" ) );
1335     }
1336 
1337     /**
1338      * Method to test the <code>&lt;helpfile/&gt;</code> parameter.
1339      *
1340      * @throws Exception if any
1341      */
1342     public void testHelpfile()
1343         throws Exception
1344     {
1345         Path testPom = unit.resolve( "helpfile-test/pom.xml" );
1346 
1347         JavadocReport mojo = lookupMojo( testPom );
1348         assertNotNull( mojo );
1349 
1350         MavenSession session = spy( newMavenSession( mojo.project ) );
1351         ProjectBuildingRequest buildingRequest = mock( ProjectBuildingRequest.class );
1352         when( buildingRequest.getRemoteRepositories() ).thenReturn( mojo.project.getRemoteArtifactRepositories() );
1353         when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
1354         MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
1355         repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManager( localRepo ) );
1356         when( buildingRequest.getRepositorySession() ).thenReturn( repositorySession );
1357         when( session.getRepositorySession() ).thenReturn( repositorySession );
1358         LegacySupport legacySupport = lookup( LegacySupport.class );
1359         legacySupport.setSession( session );
1360         setVariableValueToObject( mojo, "session", session );
1361 
1362         Path apidocs = new File( getBasedir(), "target/test/unit/helpfile-test/target/site/apidocs" ).toPath();
1363 
1364         Path helpfile = apidocs.resolve( "help-doc.html" );
1365         Path options = apidocs.resolve( "options" );
1366 
1367         // helpfile by default
1368         mojo.execute();
1369 
1370         String content = readFile( helpfile );
1371         assertTrue( content.contains( "<!-- Generated by javadoc" ) );
1372 
1373         String optionsContent = readFile( options );
1374         assertFalse( optionsContent.contains( "-helpfile" ) );
1375 
1376         // helpfile defined in a javadoc plugin dependency
1377         setVariableValueToObject( mojo, "helpfile", "com/mycompany/app/javadoc/helpfile/help-doc.html" );
1378 
1379         setVariableValueToObject( mojo, "session", session );
1380 
1381         mojo.execute();
1382 
1383         content = readFile( helpfile );
1384         assertTrue( content.contains( "<!--  Help file from artefact -->" ) );
1385 
1386         optionsContent = readFile( options );
1387         assertTrue( optionsContent.contains( "-helpfile" ) );
1388         Path help = apidocs.resolve( "help-doc.html" );
1389         assertTrue( optionsContent.contains( "'" + help.toFile().getAbsolutePath().replaceAll( "\\\\", "/" ) + "'" ) );
1390 
1391         // helpfile defined as a project resource
1392         setVariableValueToObject( mojo, "helpfile", "com/mycompany/app/javadoc/helpfile2/help-doc.html" );
1393         mojo.execute();
1394 
1395         content = readFile( helpfile );
1396         assertTrue( content.contains( "<!--  Help file from file -->" ) );
1397 
1398         optionsContent = readFile( options );
1399         assertTrue( optionsContent.contains( "-helpfile" ) );
1400         help = unit.resolve( "helpfile-test/src/main/resources/com/mycompany/app/javadoc/helpfile2/help-doc.html" );
1401         assertTrue( optionsContent.contains( "'" + help.toFile().getAbsolutePath().replaceAll( "\\\\", "/" ) + "'" ) );
1402 
1403         // helpfile defined as file
1404         help = unit.resolve( "helpfile-test/src/main/resources/com/mycompany/app/javadoc/helpfile2/help-doc.html" );
1405         setVariableValueToObject( mojo, "helpfile", help.toFile().getAbsolutePath() );
1406         mojo.execute();
1407 
1408         content = readFile( helpfile );
1409         assertTrue( content.contains( "<!--  Help file from file -->" ) );
1410 
1411         optionsContent = readFile( options );
1412         assertTrue( optionsContent.contains( "-helpfile" ) );
1413         assertTrue( optionsContent.contains( "'" + help.toFile().getAbsolutePath().replaceAll( "\\\\", "/" ) + "'" ) );
1414     }
1415 }