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