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         assertFalse( new File( apidocs, "resources/test/doc-files/maven-feather.png" ).exists() );
603 
604         app2 = new File( apidocs, "resources/test2/App2.html" );
605         assertTrue( app2.exists() );
606         content = readFile( app2 );
607         assertTrue( content.contains( "<img src=\"doc-files/maven-feather.png\" alt=\"Maven\"/>" ) );
608         assertTrue( new File( apidocs, "resources/test2/doc-files/maven-feather.png" ).exists() );
609     }
610 
611     /**
612      * Test the javadoc resources in the aggregation case.
613      *
614      * @throws Exception if any
615      */
616     public void testAggregateJavadocResources()
617         throws Exception
618     {
619         File testPom = new File( unit, "aggregate-resources-test/aggregate-resources-test-plugin-config.xml" );
620         JavadocReport mojo = (JavadocReport) lookupMojo( "aggregate", testPom );
621         mojo.execute();
622 
623         File apidocs = new File( getBasedir(), "target/test/unit/aggregate-resources-test/target/site/apidocs" );
624 
625         // Test overview
626         File overviewSummary = new File( apidocs, "overview-summary.html" );
627         assertTrue( overviewSummary.exists() );
628         String readed = readFile( overviewSummary );
629         assertTrue( readed.contains( "<TR BGCOLOR=\"white\" CLASS=\"TableRowColor\">" + LINE_SEPARATOR
630             + "<TD WIDTH=\"20%\"><B><A HREF=\"resources/test/package-summary.html\">resources.test</A></B></TD>"
631             + LINE_SEPARATOR + "<TD>blabla</TD>" + LINE_SEPARATOR + "</TR>" ) );
632         assertTrue( readed.contains( "<TR BGCOLOR=\"white\" CLASS=\"TableRowColor\">" + LINE_SEPARATOR
633             + "<TD WIDTH=\"20%\"><B><A HREF=\"resources/test2/package-summary.html\">resources.test2</A></B></TD>"
634             + LINE_SEPARATOR + "<TD>&nbsp;</TD>" + LINE_SEPARATOR + "</TR>" ) );
635         assertTrue( readed.contains( "<TR BGCOLOR=\"white\" CLASS=\"TableRowColor\">" + LINE_SEPARATOR
636             + "<TD WIDTH=\"20%\"><B><A HREF=\"resources2/test/package-summary.html\">resources2.test</A></B></TD>"
637             + LINE_SEPARATOR + "<TD>blabla</TD>" + LINE_SEPARATOR + "</TR>" ) );
638         assertTrue( readed.contains( "<TR BGCOLOR=\"white\" CLASS=\"TableRowColor\">" + LINE_SEPARATOR
639             + "<TD WIDTH=\"20%\"><B><A HREF=\"resources2/test2/package-summary.html\">resources2.test2</A></B></TD>"
640             + LINE_SEPARATOR + "<TD>&nbsp;</TD>" + LINE_SEPARATOR + "</TR>" ) );
641 
642         // Test doc-files
643         File app = new File( apidocs, "resources/test/App.html" );
644         assertTrue( app.exists() );
645         readed = readFile( app );
646         assertTrue( readed.contains( "<img src=\"doc-files/maven-feather.png\" alt=\"Maven\"/>" ) );
647         assertTrue( new File( apidocs, "resources/test/doc-files/maven-feather.png" ).exists() );
648     }
649 
650     /**
651      * Test the javadoc for a POM project.
652      *
653      * @throws Exception if any
654      */
655     public void testPom()
656         throws Exception
657     {
658         File testPom = new File( unit, "pom-test/pom-test-plugin-config.xml" );
659         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
660         mojo.execute();
661 
662         assertFalse( new File( getBasedir(), "target/test/unit/pom-test" ).exists() );
663     }
664 
665     /**
666      * Test the javadoc with tag.
667      *
668      * @throws Exception if any
669      */
670     public void testTag()
671         throws Exception
672     {
673         File testPom = new File( unit, "tag-test/tag-test-plugin-config.xml" );
674         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
675         mojo.execute();
676 
677         File app = new File( getBasedir(), "target/test/unit/tag-test/target/site/apidocs/tag/test/App.html" );
678         assertTrue( FileUtils.fileExists( app.getAbsolutePath() ) );
679         String readed = readFile( app );
680         assertTrue( readed.contains( "<B>To do something:</B>" ) );
681         assertTrue( readed.contains( "<B>Generator Class:</B>" ) );
682         assertTrue( readed.contains( "<B>Version:</B>" ) );
683         assertTrue( readed.contains( "<DT><B>Version:</B></DT>" + LINE_SEPARATOR + "  <DD>1.0</DD>" + LINE_SEPARATOR
684             + "</DL>" ) );
685     }
686 
687     /**
688      * Test newline in the header/footer parameter
689      *
690      * @throws Exception if any
691      */
692     public void testHeaderFooter()
693         throws Exception
694     {
695         File testPom = new File( unit, "header-footer-test/header-footer-test-plugin-config.xml" );
696         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
697         try
698         {
699             mojo.execute();
700         }
701         catch ( MojoExecutionException e )
702         {
703             assertTrue( "Doesnt handle correctly newline for header or footer parameter", false );
704         }
705 
706         assertTrue( true );
707     }
708 
709     /**
710      * Test newline in various string parameters
711      *
712      * @throws Exception if any
713      */
714     public void testNewline()
715         throws Exception
716     {
717         File testPom = new File( unit, "newline-test/newline-test-plugin-config.xml" );
718         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
719         try
720         {
721             mojo.execute();
722         }
723         catch ( MojoExecutionException e )
724         {
725             fail( "Doesn't handle correctly newline for string parameters. See options and packages files." );
726         }
727 
728         assertTrue( true );
729     }
730 
731     /**
732      * Method to test the jdk6 javadoc
733      *
734      * @throws Exception if any
735      */
736     public void testJdk6()
737         throws Exception
738     {
739         if ( !SystemUtils.isJavaVersionAtLeast( 1.6f ) )
740         {
741             getContainer().getLogger().warn(
742                                              "JDK 6.0 or more is required to run javadoc for '"
743                                                  + getClass().getName() + "#" + getName() + "()'." );
744             return;
745         }
746 
747         File testPom = new File( unit, "jdk6-test/jdk6-test-plugin-config.xml" );
748         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
749         mojo.execute();
750 
751         File apidocs = new File( getBasedir(), "target/test/unit/jdk6-test/target/site/apidocs" );
752 
753         assertTrue( new File( apidocs, "index.html" ).exists() );
754 
755         File overviewSummary = new File( apidocs, "overview-summary.html" );
756         assertTrue( overviewSummary.exists() );
757         String content = readFile( overviewSummary );
758         assertTrue( content.contains( "Top - Copyright &#169; All rights reserved." ) );
759         assertTrue( content.contains( "Header - Copyright &#169; All rights reserved." ) );
760         assertTrue( content.contains( "Footer - Copyright &#169; All rights reserved." ) );
761 
762         File packageSummary = new File( apidocs, "jdk6/test/package-summary.html" );
763         assertTrue( packageSummary.exists() );
764         content = readFile( packageSummary );
765         assertTrue( content.contains( "Top - Copyright &#169; All rights reserved." ) );
766         assertTrue( content.contains( "Header - Copyright &#169; All rights reserved." ) );
767         assertTrue( content.contains( "Footer - Copyright &#169; All rights reserved." ) );
768     }
769 
770     /**
771      * Method to test proxy support in the javadoc
772      *
773      * @throws Exception if any
774      */
775     public void testProxy()
776         throws Exception
777     {
778         Settings settings = new Settings();
779         Proxy proxy = new Proxy();
780 
781         // dummy proxy
782         proxy.setActive( true );
783         proxy.setHost( "127.0.0.1" );
784         proxy.setPort( 80 );
785         proxy.setProtocol( "http" );
786         proxy.setUsername( "toto" );
787         proxy.setPassword( "toto" );
788         proxy.setNonProxyHosts( "www.google.com|*.somewhere.com" );
789         settings.addProxy( proxy );
790 
791         File testPom = new File( getBasedir(), "src/test/resources/unit/proxy-test/proxy-test-plugin-config.xml" );
792         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
793         assertNotNull( mojo );
794         setVariableValueToObject( mojo, "settings", settings );
795         setVariableValueToObject( mojo, "remoteRepositories", mojo.project.getRemoteArtifactRepositories() );
796         mojo.execute();
797 
798         File commandLine = new File( getBasedir(), "target/test/unit/proxy-test/target/site/apidocs/javadoc." + ( SystemUtils.IS_OS_WINDOWS ? "bat" : "sh" ) );
799         assertTrue( FileUtils.fileExists( commandLine.getAbsolutePath() ) );
800         String readed = readFile( commandLine );
801         assertTrue( readed.contains( "-J-Dhttp.proxySet=true" ) );
802         assertTrue( readed.contains( "-J-Dhttp.proxyHost=127.0.0.1" ) );
803         assertTrue( readed.contains( "-J-Dhttp.proxyPort=80" ) );
804         assertTrue( readed.contains( "-J-Dhttp.proxyUser=\\\"toto\\\"" ) );
805         assertTrue( readed.contains( "-J-Dhttp.proxyPassword=\\\"toto\\\"" ) );
806         assertTrue( readed.contains( "-J-Dhttp.nonProxyHosts=\\\"www.google.com|*.somewhere.com\\\"" ) );
807 
808         File options = new File( getBasedir(), "target/test/unit/proxy-test/target/site/apidocs/options" );
809         assertTrue( FileUtils.fileExists( options.getAbsolutePath() ) );
810         String optionsContent = readFile( options );
811         // NO -link expected
812         assertFalse( optionsContent.contains( "-link" ) );
813 
814         // real proxy
815         ProxyServer proxyServer = null;
816         AuthAsyncProxyServlet proxyServlet = null;
817         try
818         {
819             proxyServlet = new AuthAsyncProxyServlet();
820             proxyServer = new ProxyServer( proxyServlet );
821             proxyServer.start();
822 
823             settings = new Settings();
824             proxy = new Proxy();
825             proxy.setActive( true );
826             proxy.setHost( proxyServer.getHostName() );
827             proxy.setPort( proxyServer.getPort() );
828             proxy.setProtocol( "http" );
829             settings.addProxy( proxy );
830 
831             mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
832             setVariableValueToObject( mojo, "settings", settings );
833             setVariableValueToObject( mojo, "remoteRepositories", mojo.project.getRemoteArtifactRepositories() );
834             mojo.execute();
835             readed = readFile( commandLine );
836             assertTrue( readed.contains( "-J-Dhttp.proxySet=true" ) );
837             assertTrue( readed.contains( "-J-Dhttp.proxyHost=" + proxyServer.getHostName() ) );
838             assertTrue( readed.contains( "-J-Dhttp.proxyPort=" + proxyServer.getPort() ) );
839 
840             optionsContent = readFile( options );
841             // -link expected
842 // TODO: This got disabled for now!
843 // This test fails since the last commit but I actually think it only ever worked by accident.
844 // It did rely on a commons-logging-1.0.4.pom which got resolved by a test which did run previously.
845 // But after updating to commons-logging.1.1.1 there is no pre-resolved artifact available in
846 // target/local-repo anymore, thus the javadoc link info cannot get built and the test fails
847 // I'll for now just disable this line of code, because the test as far as I can see _never_
848 // did go upstream. The remoteRepository list used is always empty!.
849 //
850 //            assertTrue( optionsContent.contains( "-link 'http://commons.apache.org/logging/apidocs'" ) );
851         }
852         finally
853         {
854             if ( proxyServer != null )
855             {
856                 proxyServer.stop();
857             }
858         }
859 
860         // auth proxy
861         Map<String, String> authentications = new HashMap<String, String>();
862         authentications.put( "foo", "bar" );
863         try
864         {
865             proxyServlet = new AuthAsyncProxyServlet( authentications );
866             proxyServer = new ProxyServer( proxyServlet );
867             proxyServer.start();
868 
869             settings = new Settings();
870             proxy = new Proxy();
871             proxy.setActive( true );
872             proxy.setHost( proxyServer.getHostName() );
873             proxy.setPort( proxyServer.getPort() );
874             proxy.setProtocol( "http" );
875             proxy.setUsername( "foo" );
876             proxy.setPassword( "bar" );
877             settings.addProxy( proxy );
878 
879             mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
880             setVariableValueToObject( mojo, "settings", settings );
881             setVariableValueToObject( mojo, "remoteRepositories", mojo.project.getRemoteArtifactRepositories() );
882             mojo.execute();
883             readed = readFile( commandLine );
884             assertTrue( readed.contains( "-J-Dhttp.proxySet=true" ) );
885             assertTrue( readed.contains( "-J-Dhttp.proxyHost=" + proxyServer.getHostName() ) );
886             assertTrue( readed.contains( "-J-Dhttp.proxyPort=" + proxyServer.getPort() ) );
887             assertTrue( readed.contains( "-J-Dhttp.proxyUser=\\\"foo\\\"" ) );
888             assertTrue( readed.contains( "-J-Dhttp.proxyPassword=\\\"bar\\\"" ) );
889 
890             optionsContent = readFile( options );
891             // -link expected
892 // see comment above (line 829)
893 //             assertTrue( optionsContent.contains( "-link 'http://commons.apache.org/logging/apidocs'" ) );
894         }
895         finally
896         {
897             if ( proxyServer != null )
898             {
899                 proxyServer.stop();
900             }
901         }
902     }
903 
904     /**
905      * Method to test error or conflict in Javadoc options and in standard doclet options.
906      *
907      * @throws Exception if any
908      */
909     public void testValidateOptions()
910         throws Exception
911     {
912         // encoding
913         File testPom = new File( unit, "validate-options-test/wrong-encoding-test-plugin-config.xml" );
914         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
915         try
916         {
917             mojo.execute();
918             assertTrue( "No wrong encoding catch", false );
919         }
920         catch ( MojoExecutionException e )
921         {
922             assertTrue( "No wrong encoding catch", e.getMessage().contains( "Unsupported option <encoding/>" ) );
923         }
924         testPom = new File( unit, "validate-options-test/wrong-docencoding-test-plugin-config.xml" );
925         mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
926         try
927         {
928             mojo.execute();
929             assertTrue( "No wrong docencoding catch", false );
930         }
931         catch ( MojoExecutionException e )
932         {
933             assertTrue( "No wrong docencoding catch", e.getMessage().contains( "Unsupported option <docencoding/>" ) );
934         }
935         testPom = new File( unit, "validate-options-test/wrong-charset-test-plugin-config.xml" );
936         mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
937         try
938         {
939             mojo.execute();
940             assertTrue( "No wrong charset catch", false );
941         }
942         catch ( MojoExecutionException e )
943         {
944             assertTrue( "No wrong charset catch", e.getMessage().contains( "Unsupported option <charset/>" ) );
945         }
946 
947         // locale
948         testPom = new File( unit, "validate-options-test/wrong-locale-test-plugin-config.xml" );
949         mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
950         try
951         {
952             mojo.execute();
953             assertTrue( "No wrong locale catch", false );
954         }
955         catch ( MojoExecutionException e )
956         {
957             assertTrue( "No wrong locale catch", e.getMessage().contains( "Unsupported option <locale/>" ) );
958         }
959         testPom = new File( unit, "validate-options-test/wrong-locale-with-variant-test-plugin-config.xml" );
960         mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
961         mojo.execute();
962         assertTrue( "No wrong locale catch", true );
963 
964         // conflict options
965         testPom = new File( unit, "validate-options-test/conflict-options-test-plugin-config.xml" );
966         mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
967         try
968         {
969             mojo.execute();
970             assertTrue( "No conflict catch", false );
971         }
972         catch ( MojoExecutionException e )
973         {
974             assertTrue( "No conflict catch", e.getMessage().contains( "Option <nohelp/> conflicts with <helpfile/>" ) );
975         }
976     }
977 
978     /**
979      * Method to test the <code>&lt;tagletArtifacts/&gt;</code> parameter.
980      *
981      * @throws Exception if any
982      */
983     public void testTagletArtifacts()
984         throws Exception
985     {
986         File testPom = new File( unit, "tagletArtifacts-test/tagletArtifacts-test-plugin-config.xml" );
987         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
988 
989         setVariableValueToObject( mojo, "remoteRepositories", mojo.project.getRemoteArtifactRepositories() );
990 
991         mojo.execute();
992 
993         File optionsFile = new File( mojo.getOutputDirectory(), "options" );
994         assertTrue( optionsFile.exists() );
995         String options = readFile( optionsFile );
996         // count -taglet
997         assertEquals( 20, StringUtils.countMatches( options, LINE_SEPARATOR + "-taglet" + LINE_SEPARATOR ) );
998         assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoAggregatorTypeTaglet" ) );
999         assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoComponentFieldTaglet" ) );
1000         assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoConfiguratorTypeTaglet" ) );
1001         assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoExecuteTypeTaglet" ) );
1002         assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoExecutionStrategyTypeTaglet" ) );
1003         assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoGoalTypeTaglet" ) );
1004         assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoInheritByDefaultTypeTaglet" ) );
1005         assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoInstantiationStrategyTypeTaglet" ) );
1006         assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoParameterFieldTaglet" ) );
1007         assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoPhaseTypeTaglet" ) );
1008         assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoReadOnlyFieldTaglet" ) );
1009         assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoRequiredFieldTaglet" ) );
1010         assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoRequiresDependencyResolutionTypeTaglet" ) );
1011         assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoRequiresDirectInvocationTypeTaglet" ) );
1012         assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoRequiresOnLineTypeTaglet" ) );
1013         assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoRequiresProjectTypeTaglet" ) );
1014         assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoRequiresReportsTypeTaglet" ) );
1015         assertTrue( options.contains( "org.codehaus.plexus.javadoc.PlexusConfigurationTaglet" ) );
1016         assertTrue( options.contains( "org.codehaus.plexus.javadoc.PlexusRequirementTaglet" ) );
1017         assertTrue( options.contains( "org.codehaus.plexus.javadoc.PlexusComponentTaglet" ) );
1018     }
1019 
1020     /**
1021      * Method to test the <code>&lt;stylesheetfile/&gt;</code> parameter.
1022      *
1023      * @throws Exception if any
1024      */
1025     public void testStylesheetfile()
1026         throws Exception
1027     {
1028         File testPom = new File( unit, "stylesheetfile-test/pom.xml" );
1029 
1030         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
1031         assertNotNull( mojo );
1032 
1033         setVariableValueToObject( mojo, "remoteRepositories", mojo.project.getRemoteArtifactRepositories() );
1034 
1035         File apidocs = new File( getBasedir(), "target/test/unit/stylesheetfile-test/target/site/apidocs" );
1036 
1037         File stylesheetfile = new File( apidocs, "stylesheet.css" );
1038         File options = new File( apidocs, "options" );
1039 
1040         // stylesheet == maven OR java
1041         setVariableValueToObject( mojo, "stylesheet", "javamaven" );
1042 
1043         try
1044         {
1045             mojo.execute();
1046             assertTrue( false );
1047         }
1048         catch ( Exception e )
1049         {
1050             assertTrue( true );
1051         }
1052 
1053         // stylesheet == java
1054         setVariableValueToObject( mojo, "stylesheet", "java" );
1055         mojo.execute();
1056 
1057         String content = readFile( stylesheetfile );
1058         assertTrue( content.contains( "/* Javadoc style sheet */" ) );
1059 
1060         String optionsContent = readFile( options );
1061         assertFalse( optionsContent.contains( "-stylesheetfile" ) );
1062 
1063         // stylesheet == maven
1064         setVariableValueToObject( mojo, "stylesheet", "maven" );
1065         mojo.execute();
1066 
1067         content = readFile( stylesheetfile );
1068         assertTrue( content.contains( "/* Javadoc style sheet */" )
1069             && content.contains( "Licensed to the Apache Software Foundation (ASF) under one" ) );
1070 
1071         optionsContent = readFile( options );
1072         assertTrue( optionsContent.contains( "-stylesheetfile" ) );
1073         assertTrue( optionsContent.contains( "'" + stylesheetfile.getAbsolutePath().replaceAll( "\\\\", "/" ) + "'" ) );
1074 
1075         // stylesheetfile defined as a project resource
1076         setVariableValueToObject( mojo, "stylesheet", null );
1077         setVariableValueToObject( mojo, "stylesheetfile", "com/mycompany/app/javadoc/css/stylesheet.css" );
1078         mojo.execute();
1079 
1080         content = readFile( stylesheetfile );
1081         assertTrue( content.contains( "/* Custom Javadoc style sheet in project */" ) );
1082 
1083         optionsContent = readFile( options );
1084         assertTrue( optionsContent.contains( "-stylesheetfile" ) );
1085         File stylesheetResource =
1086             new File( unit, "stylesheetfile-test/src/main/resources/com/mycompany/app/javadoc/css/stylesheet.css" );
1087         assertTrue( optionsContent.contains( "'" + stylesheetResource.getAbsolutePath().replaceAll( "\\\\", "/" )
1088             + "'" ) );
1089 
1090         // stylesheetfile defined in a javadoc plugin dependency
1091         setVariableValueToObject( mojo, "stylesheetfile", "com/mycompany/app/javadoc/css2/stylesheet.css" );
1092         mojo.execute();
1093 
1094         content = readFile( stylesheetfile );
1095         assertTrue( content.contains( "/* Custom Javadoc style sheet in artefact */" ) );
1096 
1097         optionsContent = readFile( options );
1098         assertTrue( optionsContent.contains( "-stylesheetfile" ) );
1099         assertTrue( optionsContent.contains( "'" + stylesheetfile.getAbsolutePath().replaceAll( "\\\\", "/" ) + "'" ) );
1100 
1101         // stylesheetfile defined as file
1102         File css =
1103             new File( unit, "stylesheetfile-test/src/main/resources/com/mycompany/app/javadoc/css3/stylesheet.css" );
1104         setVariableValueToObject( mojo, "stylesheetfile", css.getAbsolutePath() );
1105         mojo.execute();
1106 
1107         content = readFile( stylesheetfile );
1108         assertTrue( content.contains( "/* Custom Javadoc style sheet as file */" ) );
1109 
1110         optionsContent = readFile( options );
1111         assertTrue( optionsContent.contains( "-stylesheetfile" ) );
1112         stylesheetResource =
1113             new File( unit, "stylesheetfile-test/src/main/resources/com/mycompany/app/javadoc/css3/stylesheet.css" );
1114         assertTrue( optionsContent.contains( "'" + stylesheetResource.getAbsolutePath().replaceAll( "\\\\", "/" ) + "'" ) );
1115     }
1116 
1117     /**
1118      * Method to test the <code>&lt;helpfile/&gt;</code> parameter.
1119      *
1120      * @throws Exception if any
1121      */
1122     public void testHelpfile()
1123         throws Exception
1124     {
1125         File testPom = new File( unit, "helpfile-test/pom.xml" );
1126 
1127         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
1128         assertNotNull( mojo );
1129 
1130         setVariableValueToObject( mojo, "remoteRepositories", mojo.project.getRemoteArtifactRepositories() );
1131 
1132         File apidocs = new File( getBasedir(), "target/test/unit/helpfile-test/target/site/apidocs" );
1133 
1134         File helpfile = new File( apidocs, "help-doc.html" );
1135         File options = new File( apidocs, "options" );
1136 
1137         // helpfile by default
1138         mojo.execute();
1139 
1140         String content = readFile( helpfile );
1141         assertTrue( content.contains( "<!-- Generated by javadoc" ) );
1142 
1143         String optionsContent = readFile( options );
1144         assertFalse( optionsContent.contains( "-helpfile" ) );
1145 
1146         // helpfile defined in a javadoc plugin dependency
1147         setVariableValueToObject( mojo, "helpfile", "com/mycompany/app/javadoc/helpfile/help-doc.html" );
1148         mojo.execute();
1149 
1150         content = readFile( helpfile );
1151         assertTrue( content.contains( "<!--  Help file from artefact -->" ) );
1152 
1153         optionsContent = readFile( options );
1154         assertTrue( optionsContent.contains( "-helpfile" ) );
1155         File help = new File( apidocs, "help-doc.html" );
1156         assertTrue( optionsContent.contains( "'" + help.getAbsolutePath().replaceAll( "\\\\", "/" ) + "'" ) );
1157 
1158         // helpfile defined as a project resource
1159         setVariableValueToObject( mojo, "helpfile", "com/mycompany/app/javadoc/helpfile2/help-doc.html" );
1160         mojo.execute();
1161 
1162         content = readFile( helpfile );
1163         assertTrue( content.contains( "<!--  Help file from file -->" ) );
1164 
1165         optionsContent = readFile( options );
1166         assertTrue( optionsContent.contains( "-helpfile" ) );
1167         help = new File( unit, "helpfile-test/src/main/resources/com/mycompany/app/javadoc/helpfile2/help-doc.html" );
1168         assertTrue( optionsContent.contains( "'" + help.getAbsolutePath().replaceAll( "\\\\", "/" ) + "'" ) );
1169 
1170         // helpfile defined as file
1171         help = new File( unit, "helpfile-test/src/main/resources/com/mycompany/app/javadoc/helpfile2/help-doc.html" );
1172         setVariableValueToObject( mojo, "helpfile", help.getAbsolutePath() );
1173         mojo.execute();
1174 
1175         content = readFile( helpfile );
1176         assertTrue( content.contains( "<!--  Help file from file -->" ) );
1177 
1178         optionsContent = readFile( options );
1179         assertTrue( optionsContent.contains( "-helpfile" ) );
1180         assertTrue( optionsContent.contains( "'" + help.getAbsolutePath().replaceAll( "\\\\", "/" ) + "'" ) );
1181     }
1182 }