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