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         }
347         finally
348         {
349             IOUtil.close( reader );
350         }
351 
352         assertTrue( contentOptions != null );
353         assertTrue( contentOptions.contains( "-link" ) );
354         assertTrue( contentOptions.contains( "http://java.sun.com/j2se/" ) );
355     }
356 
357     /**
358      * Method to test the doclet artifact configuration
359      *
360      * @throws Exception if any
361      */
362     public void testDoclets()
363         throws Exception
364     {
365         // ----------------------------------------------------------------------
366         // doclet-test: check if the file generated by UmlGraph exists and if
367         // doclet path contains the UmlGraph artifact
368         // ----------------------------------------------------------------------
369 
370         File testPom = new File( unit, "doclet-test/doclet-test-plugin-config.xml" );
371         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
372         mojo.execute();
373 
374         File generatedFile = new File( getBasedir(), "target/test/unit/doclet-test/target/site/apidocs/graph.dot" );
375         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
376 
377         File optionsFile = new File( mojo.getOutputDirectory(), "options" );
378         assertTrue( optionsFile.exists() );
379         String options = readFile( optionsFile );
380         assertTrue( options.contains( "/target/local-repo/umlgraph/UMLGraph/2.1/UMLGraph-2.1.jar" ) );
381 
382         // ----------------------------------------------------------------------
383         // doclet-path: check if the file generated by UmlGraph exists and if
384         // doclet path contains the twice UmlGraph artifacts
385         // ----------------------------------------------------------------------
386 
387         testPom = new File( unit, "doclet-path-test/doclet-path-test-plugin-config.xml" );
388         mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
389         mojo.execute();
390 
391         generatedFile = new File( getBasedir(), "target/test/unit/doclet-test/target/site/apidocs/graph.dot" );
392         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
393 
394         optionsFile = new File( mojo.getOutputDirectory(), "options" );
395         assertTrue( optionsFile.exists() );
396         options = readFile( optionsFile );
397         assertTrue( options.contains( "/target/local-repo/umlgraph/UMLGraph/2.1/UMLGraph-2.1.jar" ) );
398         assertTrue( options.contains( "/target/local-repo/umlgraph/UMLGraph-bis/2.1/UMLGraph-bis-2.1.jar" ) );
399     }
400 
401     /**
402      * Method to test the aggregate parameter
403      *
404      * @throws Exception if any
405      */
406     public void testAggregate()
407         throws Exception
408     {
409         File testPom = new File( unit, "aggregate-test/aggregate-test-plugin-config.xml" );
410         JavadocReport mojo = (JavadocReport) lookupMojo( "aggregate", testPom );
411         mojo.execute();
412 
413         File apidocs = new File( getBasedir(), "target/test/unit/aggregate-test/target/site/apidocs/" );
414 
415         // check if project1 api files exist
416         assertTrue( new File( apidocs, "aggregate/test/project1/Project1App.html" ).exists() );
417         assertTrue( new File( apidocs, "aggregate/test/project1/Project1AppSample.html" ).exists() );
418         assertTrue( new File( apidocs, "aggregate/test/project1/Project1Sample.html" ).exists() );
419         assertTrue( new File( apidocs, "aggregate/test/project1/Project1Test.html" ).exists() );
420 
421         // check if project2 api files exist
422         assertTrue( new File( apidocs, "aggregate/test/project2/Project2App.html" ).exists() );
423         assertTrue( new File( apidocs, "aggregate/test/project2/Project2AppSample.html" ).exists() );
424         assertTrue( new File( apidocs, "aggregate/test/project2/Project2Sample.html" ).exists() );
425         assertTrue( new File( apidocs, "aggregate/test/project2/Project2Test.html" ).exists() );
426 
427     }
428 
429     /**
430      * Method to test when the path to the project sources has an apostrophe (')
431      *
432      * @throws Exception if any
433      */
434     public void testQuotedPath()
435         throws Exception
436     {
437         File testPom = new File( unit, "quotedpath'test/quotedpath-test-plugin-config.xml" );
438         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
439         mojo.execute();
440 
441         File apidocs = new File( getBasedir(), "target/test/unit/quotedpath'test/target/site/apidocs" );
442 
443         // package level generated javadoc files
444         assertTrue( new File( apidocs, "quotedpath/test/App.html" ).exists() );
445         assertTrue( new File( apidocs, "quotedpath/test/AppSample.html" ).exists() );
446 
447         // project level generated javadoc files
448         assertTrue( new File( apidocs, "index-all.html" ).exists() );
449         assertTrue( new File( apidocs, "index.html" ).exists() );
450         assertTrue( new File( apidocs, "overview-tree.html" ).exists() );
451         assertTrue( new File( apidocs, "package-list" ).exists() );
452         assertTrue( new File( apidocs, "stylesheet.css" ).exists() );
453     }
454 
455     /**
456      * @throws Exception if any
457      */
458     public void testExceptions()
459         throws Exception
460     {
461         try
462         {
463             File testPom = new File( unit, "default-configuration/exception-test-plugin-config.xml" );
464             JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
465             mojo.execute();
466 
467             fail( "Must throw exception." );
468         }
469         catch ( Exception e )
470         {
471             assertTrue( true );
472 
473             try
474             {
475                 FileUtils.deleteDirectory( new File( getBasedir(), "exception" ) );
476             }
477             catch ( IOException ie )
478             {
479                 // nop
480             }
481         }
482     }
483 
484     /**
485      * Method to test the taglet artifact configuration
486      *
487      * @throws Exception if any
488      */
489     public void testTaglets()
490         throws Exception
491     {
492         // ----------------------------------------------------------------------
493         // taglet-test: check if a taglet is used
494         // ----------------------------------------------------------------------
495 
496         File testPom = new File( unit, "taglet-test/taglet-test-plugin-config.xml" );
497         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
498         mojo.execute();
499 
500         File apidocs = new File( getBasedir(), "target/test/unit/taglet-test/target/site/apidocs" );
501 
502         assertTrue( new File( apidocs, "index.html" ).exists() );
503 
504         File appFile = new File( apidocs, "taglet/test/App.html" );
505         assertTrue( appFile.exists() );
506         String appString = readFile( appFile );
507         assertTrue( appString.contains( "<b>To Do:</b>" ) );
508     }
509 
510     /**
511      * Method to test the jdk5 javadoc
512      *
513      * @throws Exception if any
514      */
515     public void testJdk5()
516         throws Exception
517     {
518         if ( !SystemUtils.isJavaVersionAtLeast( 1.5f ) )
519         {
520             getContainer().getLogger().warn(
521                                              "JDK 5.0 or more is required to run javadoc for '"
522                                                  + getClass().getName() + "#" + getName() + "()'." );
523             return;
524         }
525 
526         File testPom = new File( unit, "jdk5-test/jdk5-test-plugin-config.xml" );
527         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
528         mojo.execute();
529 
530         File apidocs = new File( getBasedir(), "target/test/unit/jdk5-test/target/site/apidocs" );
531 
532         File index = new File( apidocs, "index.html" );
533         assertTrue( FileUtils.fileExists( index.getAbsolutePath() ) );
534 
535         File overviewSummary = new File( apidocs, "overview-summary.html" );
536         assertTrue( overviewSummary.exists() );
537         String content = readFile( overviewSummary );
538         assertTrue( content.contains( "<b>Test the package-info</b>" ) );
539 
540         File packageSummary = new File( apidocs, "jdk5/test/package-summary.html" );
541         assertTrue( packageSummary.exists() );
542         content = readFile( packageSummary );
543         assertTrue( content.contains( "<b>Test the package-info</b>" ) );
544     }
545 
546     /**
547      * Test to find the javadoc executable when <code>java.home</code> is not in the JDK_HOME. In this case, try to
548      * use the <code>JAVA_HOME</code> environment variable.
549      *
550      * @throws Exception if any
551      */
552     public void testToFindJavadoc()
553         throws Exception
554     {
555         String oldJreHome = System.getProperty( "java.home" );
556         System.setProperty( "java.home", "foo/bar" );
557 
558         File testPom = new File( unit, "javaHome-test/javaHome-test-plugin-config.xml" );
559         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
560         mojo.execute();
561 
562         System.setProperty( "java.home", oldJreHome );
563     }
564 
565     /**
566      * Test the javadoc resources.
567      *
568      * @throws Exception if any
569      */
570     public void testJavadocResources()
571         throws Exception
572     {
573         File testPom = new File( unit, "resources-test/resources-test-plugin-config.xml" );
574         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
575         mojo.execute();
576 
577         File apidocs = new File( getBasedir(), "target/test/unit/resources-test/target/site/apidocs/" );
578 
579         File app = new File( apidocs, "resources/test/App.html" );
580         assertTrue( app.exists() );
581         String content = readFile( app );
582         assertTrue( content.contains( "<img src=\"doc-files/maven-feather.png\" alt=\"Maven\">" ) );
583         assertTrue( new File( apidocs, "resources/test/doc-files/maven-feather.png" ).exists() );
584 
585         File app2 = new File( apidocs, "resources/test2/App2.html" );
586         assertTrue( app2.exists() );
587         content = readFile( app2 );
588         assertTrue( content.contains( "<img src=\"doc-files/maven-feather.png\" alt=\"Maven\">" ) );
589         assertFalse( new File( apidocs, "resources/test2/doc-files/maven-feather.png" ).exists() );
590 
591         // with excludes
592         testPom = new File( unit, "resources-with-excludes-test/resources-with-excludes-test-plugin-config.xml" );
593         mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
594         mojo.execute();
595 
596         apidocs = new File( getBasedir(), "target/test/unit/resources-with-excludes-test/target/site/apidocs" );
597 
598         app = new File( apidocs, "resources/test/App.html" );
599         assertTrue( app.exists() );
600         content = readFile( app );
601         assertTrue( content.contains( "<img src=\"doc-files/maven-feather.png\" alt=\"Maven\">" ) );
602 
603         float javadocVersion = (Float) getVariableValueFromObject( mojo, "fJavadocVersion" );
604         if( Float.compare( 1.8f, javadocVersion ) == 0 )
605         {
606             // https://bugs.openjdk.java.net/browse/JDK-8032205
607             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() );
608         }
609         else
610         {
611             assertFalse( new File( apidocs, "resources/test/doc-files/maven-feather.png" ).exists() );
612         }
613 
614         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         assertTrue( new File( apidocs, "resources/test2/doc-files/maven-feather.png" ).exists() );
619     }
620 
621     /**
622      * Test the javadoc resources in the aggregation case.
623      *
624      * @throws Exception if any
625      */
626     public void testAggregateJavadocResources()
627         throws Exception
628     {
629         File testPom = new File( unit, "aggregate-resources-test/aggregate-resources-test-plugin-config.xml" );
630         JavadocReport mojo = (JavadocReport) lookupMojo( "aggregate", testPom );
631         mojo.execute();
632 
633         File apidocs = new File( getBasedir(), "target/test/unit/aggregate-resources-test/target/site/apidocs" );
634 
635         // Test overview
636         File overviewSummary = new File( apidocs, "overview-summary.html" );
637         assertTrue( overviewSummary.exists() );
638         String overview = readFile( overviewSummary ).toLowerCase();
639         assertTrue( overview.contains( "<a href=\"resources/test/package-summary.html\">resources.test</a>" ) );
640         assertTrue( overview.contains( ">blabla</" ) );
641         assertTrue( overview.contains( "<a href=\"resources/test2/package-summary.html\">resources.test2</a>" ) );
642         assertTrue( overview.contains( "<a href=\"resources2/test/package-summary.html\">resources2.test</a>" ) );
643         assertTrue( overview.contains( "<a href=\"resources2/test2/package-summary.html\">resources2.test2</a>" ) );
644 
645         // Test doc-files
646         File app = new File( apidocs, "resources/test/App.html" );
647         assertTrue( app.exists() );
648         overview = readFile( app );
649         assertTrue( overview.contains( "<img src=\"doc-files/maven-feather.png\" alt=\"Maven\">" ) );
650         assertTrue( new File( apidocs, "resources/test/doc-files/maven-feather.png" ).exists() );
651     }
652 
653     /**
654      * Test the javadoc for a POM project.
655      *
656      * @throws Exception if any
657      */
658     public void testPom()
659         throws Exception
660     {
661         File testPom = new File( unit, "pom-test/pom-test-plugin-config.xml" );
662         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
663         mojo.execute();
664 
665         assertFalse( new File( getBasedir(), "target/test/unit/pom-test/target/site" ).exists() );
666     }
667 
668     /**
669      * Test the javadoc with tag.
670      *
671      * @throws Exception if any
672      */
673     public void testTag()
674         throws Exception
675     {
676         File testPom = new File( unit, "tag-test/tag-test-plugin-config.xml" );
677         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
678         mojo.execute();
679 
680         File app = new File( getBasedir(), "target/test/unit/tag-test/target/site/apidocs/tag/test/App.html" );
681         assertTrue( FileUtils.fileExists( app.getAbsolutePath() ) );
682         String readed = readFile( app );
683         assertTrue( readed.contains( ">To do something:</" ) );
684         assertTrue( readed.contains( ">Generator Class:</" ) );
685         assertTrue( readed.contains( ">Version:</" ) );
686         assertTrue( readed.toLowerCase().contains( "</dt>" + LINE_SEPARATOR + "  <dd>1.0</dd>" )
687             || readed.toLowerCase().contains( "</dt>" + LINE_SEPARATOR + "<dd>1.0</dd>" /* JDK 8 */) );
688     }
689 
690     /**
691      * Test newline in the header/footer parameter
692      *
693      * @throws Exception if any
694      */
695     public void testHeaderFooter()
696         throws Exception
697     {
698         File testPom = new File( unit, "header-footer-test/header-footer-test-plugin-config.xml" );
699         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
700         try
701         {
702             mojo.execute();
703         }
704         catch ( MojoExecutionException e )
705         {
706             assertTrue( "Doesnt handle correctly newline for header or footer parameter", false );
707         }
708 
709         assertTrue( true );
710     }
711 
712     /**
713      * Test newline in various string parameters
714      *
715      * @throws Exception if any
716      */
717     public void testNewline()
718         throws Exception
719     {
720         File testPom = new File( unit, "newline-test/newline-test-plugin-config.xml" );
721         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
722         try
723         {
724             mojo.execute();
725         }
726         catch ( MojoExecutionException e )
727         {
728             fail( "Doesn't handle correctly newline for string parameters. See options and packages files." );
729         }
730 
731         assertTrue( true );
732     }
733 
734     /**
735      * Method to test the jdk6 javadoc
736      *
737      * @throws Exception if any
738      */
739     public void testJdk6()
740         throws Exception
741     {
742         if ( !SystemUtils.isJavaVersionAtLeast( 1.6f ) )
743         {
744             getContainer().getLogger().warn(
745                                              "JDK 6.0 or more is required to run javadoc for '"
746                                                  + getClass().getName() + "#" + getName() + "()'." );
747             return;
748         }
749 
750         File testPom = new File( unit, "jdk6-test/jdk6-test-plugin-config.xml" );
751         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
752         mojo.execute();
753 
754         File apidocs = new File( getBasedir(), "target/test/unit/jdk6-test/target/site/apidocs" );
755 
756         assertTrue( new File( apidocs, "index.html" ).exists() );
757 
758         File overviewSummary = new File( apidocs, "overview-summary.html" );
759         assertTrue( overviewSummary.exists() );
760         String content = readFile( overviewSummary );
761         assertTrue( content.contains( "Top - Copyright &#169; All rights reserved." ) );
762         assertTrue( content.contains( "Header - Copyright &#169; All rights reserved." ) );
763         assertTrue( content.contains( "Footer - Copyright &#169; All rights reserved." ) );
764 
765         File packageSummary = new File( apidocs, "jdk6/test/package-summary.html" );
766         assertTrue( packageSummary.exists() );
767         content = readFile( packageSummary );
768         assertTrue( content.contains( "Top - Copyright &#169; All rights reserved." ) );
769         assertTrue( content.contains( "Header - Copyright &#169; All rights reserved." ) );
770         assertTrue( content.contains( "Footer - Copyright &#169; All rights reserved." ) );
771     }
772 
773     /**
774      * Method to test proxy support in the javadoc
775      *
776      * @throws Exception if any
777      */
778     public void testProxy()
779         throws Exception
780     {
781         Settings settings = new Settings();
782         Proxy proxy = new Proxy();
783 
784         // dummy proxy
785         proxy.setActive( true );
786         proxy.setHost( "127.0.0.1" );
787         proxy.setPort( 80 );
788         proxy.setProtocol( "http" );
789         proxy.setUsername( "toto" );
790         proxy.setPassword( "toto" );
791         proxy.setNonProxyHosts( "www.google.com|*.somewhere.com" );
792         settings.addProxy( proxy );
793 
794         File testPom = new File( getBasedir(), "src/test/resources/unit/proxy-test/proxy-test-plugin-config.xml" );
795         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
796         assertNotNull( mojo );
797         setVariableValueToObject( mojo, "settings", settings );
798         setVariableValueToObject( mojo, "remoteRepositories", mojo.project.getRemoteArtifactRepositories() );
799         mojo.execute();
800 
801         File commandLine = new File( getBasedir(), "target/test/unit/proxy-test/target/site/apidocs/javadoc." + ( SystemUtils.IS_OS_WINDOWS ? "bat" : "sh" ) );
802         assertTrue( FileUtils.fileExists( commandLine.getAbsolutePath() ) );
803         String readed = readFile( commandLine );
804         assertTrue( readed.contains( "-J-Dhttp.proxySet=true" ) );
805         assertTrue( readed.contains( "-J-Dhttp.proxyHost=127.0.0.1" ) );
806         assertTrue( readed.contains( "-J-Dhttp.proxyPort=80" ) );
807         assertTrue( readed.contains( "-J-Dhttp.proxyUser=\\\"toto\\\"" ) );
808         assertTrue( readed.contains( "-J-Dhttp.proxyPassword=\\\"toto\\\"" ) );
809         assertTrue( readed.contains( "-J-Dhttp.nonProxyHosts=\\\"www.google.com|*.somewhere.com\\\"" ) );
810 
811         File options = new File( getBasedir(), "target/test/unit/proxy-test/target/site/apidocs/options" );
812         assertTrue( FileUtils.fileExists( options.getAbsolutePath() ) );
813         String optionsContent = readFile( options );
814         // NO -link expected
815         assertFalse( optionsContent.contains( "-link" ) );
816 
817         // real proxy
818         ProxyServer proxyServer = null;
819         AuthAsyncProxyServlet proxyServlet;
820         try
821         {
822             proxyServlet = new AuthAsyncProxyServlet();
823             proxyServer = new ProxyServer( proxyServlet );
824             proxyServer.start();
825 
826             settings = new Settings();
827             proxy = new Proxy();
828             proxy.setActive( true );
829             proxy.setHost( proxyServer.getHostName() );
830             proxy.setPort( proxyServer.getPort() );
831             proxy.setProtocol( "http" );
832             settings.addProxy( proxy );
833 
834             mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
835             setVariableValueToObject( mojo, "settings", settings );
836             setVariableValueToObject( mojo, "remoteRepositories", mojo.project.getRemoteArtifactRepositories() );
837             mojo.execute();
838             readed = readFile( commandLine );
839             assertTrue( readed.contains( "-J-Dhttp.proxySet=true" ) );
840             assertTrue( readed.contains( "-J-Dhttp.proxyHost=" + proxyServer.getHostName() ) );
841             assertTrue( readed.contains( "-J-Dhttp.proxyPort=" + proxyServer.getPort() ) );
842 
843             optionsContent = readFile( options );
844             // -link expected
845 // TODO: This got disabled for now!
846 // This test fails since the last commit but I actually think it only ever worked by accident.
847 // It did rely on a commons-logging-1.0.4.pom which got resolved by a test which did run previously.
848 // But after updating to commons-logging.1.1.1 there is no pre-resolved artifact available in
849 // target/local-repo anymore, thus the javadoc link info cannot get built and the test fails
850 // I'll for now just disable this line of code, because the test as far as I can see _never_
851 // did go upstream. The remoteRepository list used is always empty!.
852 //
853 //            assertTrue( optionsContent.contains( "-link 'http://commons.apache.org/logging/apidocs'" ) );
854         }
855         finally
856         {
857             if ( proxyServer != null )
858             {
859                 proxyServer.stop();
860             }
861         }
862 
863         // auth proxy
864         Map<String, String> authentications = new HashMap<String, String>();
865         authentications.put( "foo", "bar" );
866         try
867         {
868             proxyServlet = new AuthAsyncProxyServlet( authentications );
869             proxyServer = new ProxyServer( proxyServlet );
870             proxyServer.start();
871 
872             settings = new Settings();
873             proxy = new Proxy();
874             proxy.setActive( true );
875             proxy.setHost( proxyServer.getHostName() );
876             proxy.setPort( proxyServer.getPort() );
877             proxy.setProtocol( "http" );
878             proxy.setUsername( "foo" );
879             proxy.setPassword( "bar" );
880             settings.addProxy( proxy );
881 
882             mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
883             setVariableValueToObject( mojo, "settings", settings );
884             setVariableValueToObject( mojo, "remoteRepositories", mojo.project.getRemoteArtifactRepositories() );
885             mojo.execute();
886             readed = readFile( commandLine );
887             assertTrue( readed.contains( "-J-Dhttp.proxySet=true" ) );
888             assertTrue( readed.contains( "-J-Dhttp.proxyHost=" + proxyServer.getHostName() ) );
889             assertTrue( readed.contains( "-J-Dhttp.proxyPort=" + proxyServer.getPort() ) );
890             assertTrue( readed.contains( "-J-Dhttp.proxyUser=\\\"foo\\\"" ) );
891             assertTrue( readed.contains( "-J-Dhttp.proxyPassword=\\\"bar\\\"" ) );
892 
893             optionsContent = readFile( options );
894             // -link expected
895 // see comment above (line 829)
896 //             assertTrue( optionsContent.contains( "-link 'http://commons.apache.org/logging/apidocs'" ) );
897         }
898         finally
899         {
900             if ( proxyServer != null )
901             {
902                 proxyServer.stop();
903             }
904         }
905     }
906 
907     /**
908      * Method to test error or conflict in Javadoc options and in standard doclet options.
909      *
910      * @throws Exception if any
911      */
912     public void testValidateOptions()
913         throws Exception
914     {
915         // encoding
916         File testPom = new File( unit, "validate-options-test/wrong-encoding-test-plugin-config.xml" );
917         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
918         try
919         {
920             mojo.execute();
921             assertTrue( "No wrong encoding catch", false );
922         }
923         catch ( MojoExecutionException e )
924         {
925             assertTrue( "No wrong encoding catch", e.getMessage().contains( "Unsupported option <encoding/>" ) );
926         }
927         testPom = new File( unit, "validate-options-test/wrong-docencoding-test-plugin-config.xml" );
928         mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
929         try
930         {
931             mojo.execute();
932             assertTrue( "No wrong docencoding catch", false );
933         }
934         catch ( MojoExecutionException e )
935         {
936             assertTrue( "No wrong docencoding catch", e.getMessage().contains( "Unsupported option <docencoding/>" ) );
937         }
938         testPom = new File( unit, "validate-options-test/wrong-charset-test-plugin-config.xml" );
939         mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
940         try
941         {
942             mojo.execute();
943             assertTrue( "No wrong charset catch", false );
944         }
945         catch ( MojoExecutionException e )
946         {
947             assertTrue( "No wrong charset catch", e.getMessage().contains( "Unsupported option <charset/>" ) );
948         }
949 
950         // locale
951         testPom = new File( unit, "validate-options-test/wrong-locale-test-plugin-config.xml" );
952         mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
953         try
954         {
955             mojo.execute();
956             assertTrue( "No wrong locale catch", false );
957         }
958         catch ( MojoExecutionException e )
959         {
960             assertTrue( "No wrong locale catch", e.getMessage().contains( "Unsupported option <locale/>" ) );
961         }
962         testPom = new File( unit, "validate-options-test/wrong-locale-with-variant-test-plugin-config.xml" );
963         mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
964         mojo.execute();
965         assertTrue( "No wrong locale catch", true );
966 
967         // conflict options
968         testPom = new File( unit, "validate-options-test/conflict-options-test-plugin-config.xml" );
969         mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
970         try
971         {
972             mojo.execute();
973             assertTrue( "No conflict catch", false );
974         }
975         catch ( MojoExecutionException e )
976         {
977             assertTrue( "No conflict catch", e.getMessage().contains( "Option <nohelp/> conflicts with <helpfile/>" ) );
978         }
979     }
980 
981     /**
982      * Method to test the <code>&lt;tagletArtifacts/&gt;</code> parameter.
983      *
984      * @throws Exception if any
985      */
986     public void testTagletArtifacts()
987         throws Exception
988     {
989         File testPom = new File( unit, "tagletArtifacts-test/tagletArtifacts-test-plugin-config.xml" );
990         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
991 
992         setVariableValueToObject( mojo, "remoteRepositories", mojo.project.getRemoteArtifactRepositories() );
993 
994         mojo.execute();
995 
996         File optionsFile = new File( mojo.getOutputDirectory(), "options" );
997         assertTrue( optionsFile.exists() );
998         String options = readFile( optionsFile );
999         // count -taglet
1000         assertEquals( 20, StringUtils.countMatches( options, LINE_SEPARATOR + "-taglet" + LINE_SEPARATOR ) );
1001         assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoAggregatorTypeTaglet" ) );
1002         assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoComponentFieldTaglet" ) );
1003         assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoConfiguratorTypeTaglet" ) );
1004         assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoExecuteTypeTaglet" ) );
1005         assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoExecutionStrategyTypeTaglet" ) );
1006         assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoGoalTypeTaglet" ) );
1007         assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoInheritByDefaultTypeTaglet" ) );
1008         assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoInstantiationStrategyTypeTaglet" ) );
1009         assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoParameterFieldTaglet" ) );
1010         assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoPhaseTypeTaglet" ) );
1011         assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoReadOnlyFieldTaglet" ) );
1012         assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoRequiredFieldTaglet" ) );
1013         assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoRequiresDependencyResolutionTypeTaglet" ) );
1014         assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoRequiresDirectInvocationTypeTaglet" ) );
1015         assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoRequiresOnLineTypeTaglet" ) );
1016         assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoRequiresProjectTypeTaglet" ) );
1017         assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoRequiresReportsTypeTaglet" ) );
1018         assertTrue( options.contains( "org.codehaus.plexus.javadoc.PlexusConfigurationTaglet" ) );
1019         assertTrue( options.contains( "org.codehaus.plexus.javadoc.PlexusRequirementTaglet" ) );
1020         assertTrue( options.contains( "org.codehaus.plexus.javadoc.PlexusComponentTaglet" ) );
1021     }
1022 
1023     /**
1024      * Method to test the <code>&lt;stylesheetfile/&gt;</code> parameter.
1025      *
1026      * @throws Exception if any
1027      */
1028     public void testStylesheetfile()
1029         throws Exception
1030     {
1031         File testPom = new File( unit, "stylesheetfile-test/pom.xml" );
1032 
1033         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
1034         assertNotNull( mojo );
1035 
1036         setVariableValueToObject( mojo, "remoteRepositories", mojo.project.getRemoteArtifactRepositories() );
1037 
1038         File apidocs = new File( getBasedir(), "target/test/unit/stylesheetfile-test/target/site/apidocs" );
1039 
1040         File stylesheetfile = new File( apidocs, "stylesheet.css" );
1041         File options = new File( apidocs, "options" );
1042 
1043         // stylesheet == maven OR java
1044         setVariableValueToObject( mojo, "stylesheet", "javamaven" );
1045 
1046         try
1047         {
1048             mojo.execute();
1049             assertTrue( false );
1050         }
1051         catch ( Exception e )
1052         {
1053             assertTrue( true );
1054         }
1055 
1056         // stylesheet == java
1057         setVariableValueToObject( mojo, "stylesheet", "java" );
1058         mojo.execute();
1059 
1060         String content = readFile( stylesheetfile );
1061         assertTrue( content.contains( "/* Javadoc style sheet */" ) );
1062 
1063         String optionsContent = readFile( options );
1064         assertFalse( optionsContent.contains( "-stylesheetfile" ) );
1065 
1066         // stylesheet == maven
1067         setVariableValueToObject( mojo, "stylesheet", "maven" );
1068         mojo.execute();
1069 
1070         content = readFile( stylesheetfile );
1071         assertTrue( content.contains( "/* Javadoc style sheet */" )
1072             && content.contains( "Licensed to the Apache Software Foundation (ASF) under one" ) );
1073 
1074         optionsContent = readFile( options );
1075         assertTrue( optionsContent.contains( "-stylesheetfile" ) );
1076         assertTrue( optionsContent.contains( "'" + stylesheetfile.getAbsolutePath().replaceAll( "\\\\", "/" ) + "'" ) );
1077 
1078         // stylesheetfile defined as a project resource
1079         setVariableValueToObject( mojo, "stylesheet", null );
1080         setVariableValueToObject( mojo, "stylesheetfile", "com/mycompany/app/javadoc/css/stylesheet.css" );
1081         mojo.execute();
1082 
1083         content = readFile( stylesheetfile );
1084         assertTrue( content.contains( "/* Custom Javadoc style sheet in project */" ) );
1085 
1086         optionsContent = readFile( options );
1087         assertTrue( optionsContent.contains( "-stylesheetfile" ) );
1088         File stylesheetResource =
1089             new File( unit, "stylesheetfile-test/src/main/resources/com/mycompany/app/javadoc/css/stylesheet.css" );
1090         assertTrue( optionsContent.contains( "'" + stylesheetResource.getAbsolutePath().replaceAll( "\\\\", "/" )
1091             + "'" ) );
1092 
1093         // stylesheetfile defined in a javadoc plugin dependency
1094         setVariableValueToObject( mojo, "stylesheetfile", "com/mycompany/app/javadoc/css2/stylesheet.css" );
1095         mojo.execute();
1096 
1097         content = readFile( stylesheetfile );
1098         assertTrue( content.contains( "/* Custom Javadoc style sheet in artefact */" ) );
1099 
1100         optionsContent = readFile( options );
1101         assertTrue( optionsContent.contains( "-stylesheetfile" ) );
1102         assertTrue( optionsContent.contains( "'" + stylesheetfile.getAbsolutePath().replaceAll( "\\\\", "/" ) + "'" ) );
1103 
1104         // stylesheetfile defined as file
1105         File css =
1106             new File( unit, "stylesheetfile-test/src/main/resources/com/mycompany/app/javadoc/css3/stylesheet.css" );
1107         setVariableValueToObject( mojo, "stylesheetfile", css.getAbsolutePath() );
1108         mojo.execute();
1109 
1110         content = readFile( stylesheetfile );
1111         assertTrue( content.contains( "/* Custom Javadoc style sheet as file */" ) );
1112 
1113         optionsContent = readFile( options );
1114         assertTrue( optionsContent.contains( "-stylesheetfile" ) );
1115         stylesheetResource =
1116             new File( unit, "stylesheetfile-test/src/main/resources/com/mycompany/app/javadoc/css3/stylesheet.css" );
1117         assertTrue( optionsContent.contains( "'" + stylesheetResource.getAbsolutePath().replaceAll( "\\\\", "/" ) + "'" ) );
1118     }
1119 
1120     /**
1121      * Method to test the <code>&lt;helpfile/&gt;</code> parameter.
1122      *
1123      * @throws Exception if any
1124      */
1125     public void testHelpfile()
1126         throws Exception
1127     {
1128         File testPom = new File( unit, "helpfile-test/pom.xml" );
1129 
1130         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
1131         assertNotNull( mojo );
1132 
1133         setVariableValueToObject( mojo, "remoteRepositories", mojo.project.getRemoteArtifactRepositories() );
1134 
1135         File apidocs = new File( getBasedir(), "target/test/unit/helpfile-test/target/site/apidocs" );
1136 
1137         File helpfile = new File( apidocs, "help-doc.html" );
1138         File options = new File( apidocs, "options" );
1139 
1140         // helpfile by default
1141         mojo.execute();
1142 
1143         String content = readFile( helpfile );
1144         assertTrue( content.contains( "<!-- Generated by javadoc" ) );
1145 
1146         String optionsContent = readFile( options );
1147         assertFalse( optionsContent.contains( "-helpfile" ) );
1148 
1149         // helpfile defined in a javadoc plugin dependency
1150         setVariableValueToObject( mojo, "helpfile", "com/mycompany/app/javadoc/helpfile/help-doc.html" );
1151         mojo.execute();
1152 
1153         content = readFile( helpfile );
1154         assertTrue( content.contains( "<!--  Help file from artefact -->" ) );
1155 
1156         optionsContent = readFile( options );
1157         assertTrue( optionsContent.contains( "-helpfile" ) );
1158         File help = new File( apidocs, "help-doc.html" );
1159         assertTrue( optionsContent.contains( "'" + help.getAbsolutePath().replaceAll( "\\\\", "/" ) + "'" ) );
1160 
1161         // helpfile defined as a project resource
1162         setVariableValueToObject( mojo, "helpfile", "com/mycompany/app/javadoc/helpfile2/help-doc.html" );
1163         mojo.execute();
1164 
1165         content = readFile( helpfile );
1166         assertTrue( content.contains( "<!--  Help file from file -->" ) );
1167 
1168         optionsContent = readFile( options );
1169         assertTrue( optionsContent.contains( "-helpfile" ) );
1170         help = new File( unit, "helpfile-test/src/main/resources/com/mycompany/app/javadoc/helpfile2/help-doc.html" );
1171         assertTrue( optionsContent.contains( "'" + help.getAbsolutePath().replaceAll( "\\\\", "/" ) + "'" ) );
1172 
1173         // helpfile defined as file
1174         help = new File( unit, "helpfile-test/src/main/resources/com/mycompany/app/javadoc/helpfile2/help-doc.html" );
1175         setVariableValueToObject( mojo, "helpfile", help.getAbsolutePath() );
1176         mojo.execute();
1177 
1178         content = readFile( helpfile );
1179         assertTrue( content.contains( "<!--  Help file from file -->" ) );
1180 
1181         optionsContent = readFile( options );
1182         assertTrue( optionsContent.contains( "-helpfile" ) );
1183         assertTrue( optionsContent.contains( "'" + help.getAbsolutePath().replaceAll( "\\\\", "/" ) + "'" ) );
1184     }
1185 }