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