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