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