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