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