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         testPom = new File( getBasedir(), "src/test/resources/unit/docfiles-with-java-test/docfiles-with-java-test-plugin-config.xml" );
335         mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
336         mojo.execute();
337     }
338 
339     /**
340      * Test javadoc plugin using custom configuration. noindex, notree and nodeprecated parameters
341      * were set to true.
342      *
343      * @throws Exception if any
344      */
345     public void testCustomConfiguration()
346         throws Exception
347     {
348         File testPom = new File( getBasedir(),
349                                  "src/test/resources/unit/custom-configuration/custom-configuration-plugin-config.xml" );
350         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
351         mojo.execute();
352 
353         // check if there is a tree page generated (notree == true)
354         File generatedFile = new File( getBasedir(),
355                                        "target/test/unit/custom-configuration/target/site/apidocs/overview-tree.html" );
356         assertTrue( !FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
357 
358         generatedFile = new File( getBasedir(),
359                                   "target/test/unit/custom-configuration/target/site/apidocs/custom/configuration/package-tree.html" );
360         assertTrue( !FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
361 
362         // check if the main index page was generated (noindex == true)
363         generatedFile = new File( getBasedir(),
364                                   "target/test/unit/custom-configuration/target/site/apidocs/index-all.html" );
365         assertTrue( !FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
366 
367         // check if the deprecated list and the deprecated api were generated (nodeprecated == true)
368         // @todo Fix: the class-use of the deprecated api is still created eventhough the deprecated api of that class
369         // is no longer generated
370         generatedFile = new File( getBasedir(),
371                                   "target/test/unit/custom-configuration/target/site/apidocs/deprecated-list.html" );
372         assertTrue( !FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
373 
374         generatedFile = new File( getBasedir(),
375                                   "target/test/unit/custom-configuration/target/site/apidocs/custom/configuration/App.html" );
376         assertTrue( !FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
377 
378         // read the contents of the html files based on some of the parameter values
379         // author == false
380         String str = readFile( new File( getBasedir(),
381                                          "target/test/unit/custom-configuration/target/site/apidocs/custom/configuration/AppSample.html" ) );
382         assertTrue( str.toLowerCase().indexOf( "author" ) == -1 );
383 
384         // bottom
385         assertTrue( str.toUpperCase().indexOf( "SAMPLE BOTTOM CONTENT" ) != -1 );
386 
387         // offlineLinks
388         assertTrue( str.toLowerCase().indexOf(
389                                                "HREF=\"http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html"
390                                                    .toLowerCase() ) != -1 );
391 
392         // header
393         assertTrue( str.toUpperCase().indexOf( "MAVEN JAVADOC PLUGIN TEST" ) != -1 );
394 
395         // footer
396         assertTrue( str.toUpperCase().indexOf( "MAVEN JAVADOC PLUGIN TEST FOOTER" ) != -1 );
397 
398         // nohelp == true
399         assertTrue( str.toUpperCase().indexOf( "/help-doc.html".toUpperCase() ) == -1 );
400 
401         // check the wildcard (*) package exclusions -- excludePackageNames parameter
402         generatedFile = new File( getBasedir(),
403                                   "target/test/unit/custom-configuration/target/site/apidocs/custom/configuration/exclude1/Exclude1App.html" );
404         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
405 
406         generatedFile = new File( getBasedir(),
407                                   "target/test/unit/custom-configuration/target/site/apidocs/custom/configuration/exclude1/subexclude/SubexcludeApp.html" );
408         assertTrue( !FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
409 
410         generatedFile = new File( getBasedir(),
411                                   "target/test/unit/custom-configuration/target/site/apidocs/custom/configuration/exclude2/Exclude2App.html" );
412         assertTrue( !FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
413 
414         File options =
415             new File( getBasedir(), "target/test/unit/custom-configuration/target/site/apidocs/options" );
416         assertTrue( options.isFile() );
417         String contentOptions = null;
418         Reader reader = null;
419         try
420         {
421             reader = ReaderFactory.newPlatformReader( options );
422             contentOptions = IOUtil.toString( reader );
423         }
424         finally
425         {
426             IOUtil.close( reader );
427         }
428 
429         assertTrue( contentOptions != null );
430         if ( JavadocUtilTest.isWebSiteOnline( null, getContainer().getLogger(), "http://java.sun.com" ) )
431         {
432             assertTrue( contentOptions.indexOf( "-link" ) != -1 );
433             assertTrue( contentOptions.indexOf( "http://java.sun.com/j2se/" ) != -1
434                 || contentOptions.indexOf( "http://java.sun.com/javase/" ) != -1 );
435         }
436     }
437 
438     /**
439      * Method to test the doclet artifact configuration
440      *
441      * @throws Exception if any
442      */
443     public void testDoclets()
444         throws Exception
445     {
446         // ----------------------------------------------------------------------
447         // doclet-test: check if the file generated by UmlGraph exists and if
448         // doclet path contains the UmlGraph artifact
449         // ----------------------------------------------------------------------
450 
451         File testPom = new File( getBasedir(), "src/test/resources/unit/doclet-test/doclet-test-plugin-config.xml" );
452         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
453         mojo.execute();
454 
455         File generatedFile = new File( getBasedir(), "target/test/unit/doclet-test/target/site/apidocs/graph.dot" );
456         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
457 
458         File optionsFile = new File( mojo.getOutputDirectory(), "options" );
459         assertTrue( optionsFile.exists() );
460         String options = readFile( optionsFile );
461         assertTrue( options.indexOf( "/target/local-repo/umlgraph/UMLGraph/2.1/UMLGraph-2.1.jar" ) != -1 );
462 
463         // ----------------------------------------------------------------------
464         // doclet-path: check if the file generated by UmlGraph exists and if
465         // doclet path contains the twice UmlGraph artifacts
466         // ----------------------------------------------------------------------
467 
468         testPom = new File( getBasedir(), "src/test/resources/unit/doclet-path-test/doclet-path-test-plugin-config.xml" );
469         mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
470         mojo.execute();
471 
472         generatedFile = new File( getBasedir(), "target/test/unit/doclet-test/target/site/apidocs/graph.dot" );
473         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
474 
475         optionsFile = new File( mojo.getOutputDirectory(), "options" );
476         assertTrue( optionsFile.exists() );
477         options = readFile( optionsFile );
478         assertTrue( options.indexOf( "/target/local-repo/umlgraph/UMLGraph/2.1/UMLGraph-2.1.jar" ) != -1 );
479         assertTrue( options.indexOf( "/target/local-repo/umlgraph/UMLGraph-bis/2.1/UMLGraph-bis-2.1.jar" ) != -1 );
480     }
481 
482     /**
483      * Method to test the aggregate parameter
484      *
485      * @throws Exception if any
486      */
487     public void testAggregate()
488         throws Exception
489     {
490         File testPom = new File( getBasedir(),
491                                  "src/test/resources/unit/aggregate-test/aggregate-test-plugin-config.xml" );
492         JavadocReport mojo = (JavadocReport) lookupMojo( "aggregate", testPom );
493         mojo.execute();
494 
495         // check if project1 api files exist
496         File generatedFile = new File( getBasedir(),
497                                        "target/test/unit/aggregate-test/target/site/apidocs/aggregate/test/project1/Project1App.html" );
498         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
499 
500         generatedFile = new File( getBasedir(),
501                                   "target/test/unit/aggregate-test/target/site/apidocs/aggregate/test/project1/Project1AppSample.html" );
502         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
503 
504         generatedFile = new File( getBasedir(),
505                                   "target/test/unit/aggregate-test/target/site/apidocs/aggregate/test/project1/Project1Sample.html" );
506         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
507 
508         generatedFile = new File( getBasedir(),
509                                   "target/test/unit/aggregate-test/target/site/apidocs/aggregate/test/project1/Project1Test.html" );
510         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
511 
512         // check if project2 api files exist
513         generatedFile = new File( getBasedir(),
514                                   "target/test/unit/aggregate-test/target/site/apidocs/aggregate/test/project2/Project2App.html" );
515         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
516 
517         generatedFile = new File( getBasedir(),
518                                   "target/test/unit/aggregate-test/target/site/apidocs/aggregate/test/project2/Project2AppSample.html" );
519         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
520 
521         generatedFile = new File( getBasedir(),
522                                   "target/test/unit/aggregate-test/target/site/apidocs/aggregate/test/project2/Project2Sample.html" );
523         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
524 
525         generatedFile = new File( getBasedir(),
526                                   "target/test/unit/aggregate-test/target/site/apidocs/aggregate/test/project2/Project2Test.html" );
527         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
528 
529     }
530 
531     /**
532      * Method to test when the path to the project sources has an apostrophe (')
533      *
534      * @throws Exception if any
535      */
536     public void testQuotedPath()
537         throws Exception
538     {
539         File testPom = new File( getBasedir(),
540                                  "src/test/resources/unit/quotedpath'test/quotedpath-test-plugin-config.xml" );
541         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
542         mojo.execute();
543 
544         // package level generated javadoc files
545         File generatedFile = new File( getBasedir(),
546                                        "target/test/unit/quotedpath'test/target/site/apidocs/quotedpath/test/App.html" );
547         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
548 
549         generatedFile = new File( getBasedir(),
550                                   "target/test/unit/quotedpath'test/target/site/apidocs/quotedpath/test/AppSample.html" );
551         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
552 
553         // project level generated javadoc files
554         generatedFile = new File( getBasedir(), "target/test/unit/quotedpath'test/target/site/apidocs/index-all.html" );
555         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
556 
557         generatedFile = new File( getBasedir(), "target/test/unit/quotedpath'test/target/site/apidocs/index.html" );
558         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
559 
560         generatedFile = new File( getBasedir(),
561                                   "target/test/unit/quotedpath'test/target/site/apidocs/overview-tree.html" );
562         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
563 
564         generatedFile = new File( getBasedir(), "target/test/unit/quotedpath'test/target/site/apidocs/package-list" );
565         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
566 
567         generatedFile = new File( getBasedir(), "target/test/unit/quotedpath'test/target/site/apidocs/stylesheet.css" );
568         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
569     }
570 
571     /**
572      * @throws Exception if any
573      */
574     public void testExceptions()
575         throws Exception
576     {
577         try
578         {
579             File testPom = new File( getBasedir(),
580                                      "src/test/resources/unit/default-configuration/exception-test-plugin-config.xml" );
581             JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
582             mojo.execute();
583 
584             fail( "Must throw exception." );
585         }
586         catch ( Exception e )
587         {
588             assertTrue( true );
589 
590             try
591             {
592                 FileUtils.deleteDirectory( new File( getBasedir(), "exception" ) );
593             }
594             catch ( IOException ie )
595             {
596                 // nop
597             }
598         }
599     }
600 
601     /**
602      * Method to test the taglet artifact configuration
603      *
604      * @throws Exception if any
605      */
606     public void testTaglets()
607         throws Exception
608     {
609         // ----------------------------------------------------------------------
610         // taglet-test: check if a taglet is used
611         // ----------------------------------------------------------------------
612 
613         File testPom = new File( getBasedir(), "src/test/resources/unit/taglet-test/taglet-test-plugin-config.xml" );
614         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
615         mojo.execute();
616 
617         File index = new File( getBasedir(), "target/test/unit/taglet-test/target/site/apidocs/index.html" );
618         assertTrue( FileUtils.fileExists( index.getAbsolutePath() ) );
619 
620         File appFile = new File( getBasedir(), "target/test/unit/taglet-test/target/site/apidocs/taglet/test/App.html" );
621         assertTrue( appFile.exists() );
622         String appString = readFile( appFile );
623         assertTrue( appString.indexOf( "<b>To Do:</b>" ) != -1 );
624     }
625 
626     /**
627      * Method to test the jdk5 javadoc
628      *
629      * @throws Exception if any
630      */
631     public void testJdk5()
632         throws Exception
633     {
634         if ( !SystemUtils.isJavaVersionAtLeast( 1.5f ) )
635         {
636             getContainer().getLogger().warn(
637                                              "JDK 5.0 or more is required to run javadoc for '"
638                                                  + getClass().getName() + "#" + getName() + "()'." );
639             return;
640         }
641 
642         File testPom = new File( getBasedir(), "src/test/resources/unit/jdk5-test/jdk5-test-plugin-config.xml" );
643         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
644         mojo.execute();
645 
646         File index = new File( getBasedir(), "target/test/unit/jdk5-test/target/site/apidocs/index.html" );
647         assertTrue( FileUtils.fileExists( index.getAbsolutePath() ) );
648 
649         File overviewSummary = new File( getBasedir(),
650                                          "target/test/unit/jdk5-test/target/site/apidocs/overview-summary.html" );
651         assertTrue( FileUtils.fileExists( overviewSummary.getAbsolutePath() ) );
652         String readed = readFile( overviewSummary );
653         assertTrue( readed.indexOf( "<b>Test the package-info</b>" ) != -1 );
654 
655         File packageSummary = new File( getBasedir(),
656                                         "target/test/unit/jdk5-test/target/site/apidocs/jdk5/test/package-summary.html" );
657         assertTrue( FileUtils.fileExists( packageSummary.getAbsolutePath() ) );
658         readed = readFile( packageSummary );
659         assertTrue( readed.indexOf( "<b>Test the package-info</b>" ) != -1 );
660     }
661 
662     /**
663      * Test to find the javadoc executable when <code>java.home</code> is not in the JDK_HOME. In this case, try to
664      * use the <code>JAVA_HOME</code> environment variable.
665      *
666      * @throws Exception if any
667      */
668     public void testToFindJavadoc()
669         throws Exception
670     {
671         String oldJreHome = System.getProperty( "java.home" );
672         System.setProperty( "java.home", "foo/bar" );
673 
674         File testPom = new File( getBasedir(), "src/test/resources/unit/javaHome-test/javaHome-test-plugin-config.xml" );
675         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
676         mojo.execute();
677 
678         System.setProperty( "java.home", oldJreHome );
679     }
680 
681     /**
682      * Test the javadoc resources.
683      *
684      * @throws Exception if any
685      */
686     public void testJavadocResources()
687         throws Exception
688     {
689         File testPom = new File( getBasedir(),
690                                  "src/test/resources/unit/resources-test/resources-test-plugin-config.xml" );
691         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
692         mojo.execute();
693 
694         File app = new File( getBasedir(),
695                              "target/test/unit/resources-test/target/site/apidocs/resources/test/App.html" );
696         assertTrue( FileUtils.fileExists( app.getAbsolutePath() ) );
697         String readed = readFile( app );
698         assertTrue( readed.indexOf( "<img src=\"doc-files/maven-feather.png\" alt=\"Maven\"/>" ) != -1 );
699         File feather = new File( getBasedir(),
700                                  "target/test/unit/resources-test/target/site/apidocs/resources/test/doc-files/maven-feather.png" );
701         assertTrue( FileUtils.fileExists( feather.getAbsolutePath() ) );
702 
703         File app2 = new File( getBasedir(),
704                               "target/test/unit/resources-test/target/site/apidocs/resources/test2/App2.html" );
705         assertTrue( FileUtils.fileExists( app2.getAbsolutePath() ) );
706         readed = readFile( app2 );
707         assertTrue( readed.indexOf( "<img src=\"doc-files/maven-feather.png\" alt=\"Maven\"/>" ) != -1 );
708         File feather2 = new File( getBasedir(),
709                                   "target/test/unit/resources-test/target/site/apidocs/resources/test2/doc-files/maven-feather.png" );
710         assertFalse( FileUtils.fileExists( feather2.getAbsolutePath() ) );
711 
712         // with excludes
713         testPom = new File( getBasedir(),
714                                  "src/test/resources/unit/resources-with-excludes-test/resources-with-excludes-test-plugin-config.xml" );
715         mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
716         mojo.execute();
717 
718         app = new File( getBasedir(),
719                              "target/test/unit/resources-with-excludes-test/target/site/apidocs/resources/test/App.html" );
720         assertTrue( FileUtils.fileExists( app.getAbsolutePath() ) );
721         readed = readFile( app );
722         assertTrue( readed.indexOf( "<img src=\"doc-files/maven-feather.png\" alt=\"Maven\"/>" ) != -1 );
723         feather = new File( getBasedir(),
724                                  "target/test/unit/resources-with-excludes-test/target/site/apidocs/resources/test/doc-files/maven-feather.png" );
725         assertFalse( FileUtils.fileExists( feather.getAbsolutePath() ) );
726 
727         app2 = new File( getBasedir(),
728                               "target/test/unit/resources-with-excludes-test/target/site/apidocs/resources/test2/App2.html" );
729         assertTrue( FileUtils.fileExists( app2.getAbsolutePath() ) );
730         readed = readFile( app2 );
731         assertTrue( readed.indexOf( "<img src=\"doc-files/maven-feather.png\" alt=\"Maven\"/>" ) != -1 );
732         feather2 = new File( getBasedir(),
733                                   "target/test/unit/resources-with-excludes-test/target/site/apidocs/resources/test2/doc-files/maven-feather.png" );
734         assertTrue( FileUtils.fileExists( feather2.getAbsolutePath() ) );
735     }
736 
737     /**
738      * Test the javadoc resources in the aggregation case.
739      *
740      * @throws Exception if any
741      */
742     public void testAggregateJavadocResources()
743         throws Exception
744     {
745         File testPom = new File( getBasedir(),
746                                  "src/test/resources/unit/aggregate-resources-test/aggregate-resources-test-plugin-config.xml" );
747         JavadocReport mojo = (JavadocReport) lookupMojo( "aggregate", testPom );
748         mojo.execute();
749 
750         // Test overview
751         File overviewSummary = new File( getBasedir(),
752                                          "target/test/unit/aggregate-resources-test/target/site/apidocs/overview-summary.html" );
753         assertTrue( FileUtils.fileExists( overviewSummary.getAbsolutePath() ) );
754         String readed = readFile( overviewSummary );
755         assertTrue( readed.indexOf( "<TR BGCOLOR=\"white\" CLASS=\"TableRowColor\">" + LINE_SEPARATOR
756             + "<TD WIDTH=\"20%\"><B><A HREF=\"resources/test/package-summary.html\">resources.test</A></B></TD>"
757             + LINE_SEPARATOR + "<TD>blabla</TD>" + LINE_SEPARATOR + "</TR>" ) != -1 );
758         assertTrue( readed.indexOf( "<TR BGCOLOR=\"white\" CLASS=\"TableRowColor\">" + LINE_SEPARATOR
759             + "<TD WIDTH=\"20%\"><B><A HREF=\"resources/test2/package-summary.html\">resources.test2</A></B></TD>"
760             + LINE_SEPARATOR + "<TD>&nbsp;</TD>" + LINE_SEPARATOR + "</TR>" ) != -1 );
761         assertTrue( readed.indexOf( "<TR BGCOLOR=\"white\" CLASS=\"TableRowColor\">" + LINE_SEPARATOR
762             + "<TD WIDTH=\"20%\"><B><A HREF=\"resources2/test/package-summary.html\">resources2.test</A></B></TD>"
763             + LINE_SEPARATOR + "<TD>blabla</TD>" + LINE_SEPARATOR + "</TR>" ) != -1 );
764         assertTrue( readed.indexOf( "<TR BGCOLOR=\"white\" CLASS=\"TableRowColor\">" + LINE_SEPARATOR
765             + "<TD WIDTH=\"20%\"><B><A HREF=\"resources2/test2/package-summary.html\">resources2.test2</A></B></TD>"
766             + LINE_SEPARATOR + "<TD>&nbsp;</TD>" + LINE_SEPARATOR + "</TR>" ) != -1 );
767 
768         // Test doc-files
769         File app = new File( getBasedir(),
770                              "target/test/unit/aggregate-resources-test/target/site/apidocs/resources/test/App.html" );
771         assertTrue( FileUtils.fileExists( app.getAbsolutePath() ) );
772         readed = readFile( app );
773         assertTrue( readed.indexOf( "<img src=\"doc-files/maven-feather.png\" alt=\"Maven\"/>" ) != -1 );
774         File feather = new File( getBasedir(),
775                                  "target/test/unit/aggregate-resources-test/target/site/apidocs/resources/test/doc-files/maven-feather.png" );
776         assertTrue( FileUtils.fileExists( feather.getAbsolutePath() ) );
777     }
778 
779     /**
780      * Test the javadoc for a POM project.
781      *
782      * @throws Exception if any
783      */
784     public void testPom()
785         throws Exception
786     {
787         File testPom = new File( getBasedir(), "src/test/resources/unit/pom-test/pom-test-plugin-config.xml" );
788         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
789         mojo.execute();
790 
791         assertFalse( new File( getBasedir(), "target/test/unit/pom-test" ).exists() );
792     }
793 
794     /**
795      * Test the javadoc with tag.
796      *
797      * @throws Exception if any
798      */
799     public void testTag()
800         throws Exception
801     {
802         File testPom = new File( getBasedir(), "src/test/resources/unit/tag-test/tag-test-plugin-config.xml" );
803         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
804         mojo.execute();
805 
806         File app = new File( getBasedir(), "target/test/unit/tag-test/target/site/apidocs/tag/test/App.html" );
807         assertTrue( FileUtils.fileExists( app.getAbsolutePath() ) );
808         String readed = readFile( app );
809         assertTrue( readed.indexOf( "<B>To do something:</B>" ) != -1 );
810         assertTrue( readed.indexOf( "<B>Generator Class:</B>" ) != -1 );
811         assertTrue( readed.indexOf( "<B>Version:</B>" ) != -1 );
812         assertTrue( readed.indexOf( "<DT><B>Version:</B></DT>" + LINE_SEPARATOR + "  <DD>1.0</DD>" + LINE_SEPARATOR
813             + "</DL>" ) != -1 );
814     }
815 
816     /**
817      * Test newline in the header/footer parameter
818      *
819      * @throws Exception if any
820      */
821     public void testHeaderFooter()
822         throws Exception
823     {
824         File testPom = new File( getBasedir(), "src/test/resources/unit/header-footer-test/header-footer-test-plugin-config.xml" );
825         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
826         try
827         {
828             mojo.execute();
829         }
830         catch ( MojoExecutionException e )
831         {
832             assertTrue( "Doesnt handle correctly newline for header or footer parameter", false );
833         }
834 
835         assertTrue( true );
836     }
837 
838     /**
839      * Test newline in various string parameters
840      *
841      * @throws Exception if any
842      */
843     public void testNewline()
844         throws Exception
845     {
846         File testPom = new File( getBasedir(), "src/test/resources/unit/newline-test/newline-test-plugin-config.xml" );
847         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
848         try
849         {
850             mojo.execute();
851         }
852         catch ( MojoExecutionException e )
853         {
854             fail( "Doesn't handle correctly newline for string parameters. See options and packages files." );
855         }
856 
857         assertTrue( true );
858     }
859 
860     /**
861      * Method to test the jdk6 javadoc
862      *
863      * @throws Exception if any
864      */
865     public void testJdk6()
866         throws Exception
867     {
868         if ( !SystemUtils.isJavaVersionAtLeast( 1.6f ) )
869         {
870             getContainer().getLogger().warn(
871                                              "JDK 6.0 or more is required to run javadoc for '"
872                                                  + getClass().getName() + "#" + getName() + "()'." );
873             return;
874         }
875 
876         File testPom = new File( getBasedir(), "src/test/resources/unit/jdk6-test/jdk6-test-plugin-config.xml" );
877         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
878         mojo.execute();
879 
880         File index = new File( getBasedir(), "target/test/unit/jdk6-test/target/site/apidocs/index.html" );
881         assertTrue( FileUtils.fileExists( index.getAbsolutePath() ) );
882 
883         File overviewSummary = new File( getBasedir(),
884                                          "target/test/unit/jdk6-test/target/site/apidocs/overview-summary.html" );
885         assertTrue( FileUtils.fileExists( overviewSummary.getAbsolutePath() ) );
886         String readed = readFile( overviewSummary );
887         assertTrue( readed.indexOf( "Top - Copyright &#169; All rights reserved." ) != -1 );
888         assertTrue( readed.indexOf( "Header - Copyright &#169; All rights reserved." ) != -1 );
889         assertTrue( readed.indexOf( "Footer - Copyright &#169; All rights reserved." ) != -1 );
890 
891         File packageSummary = new File( getBasedir(),
892                                         "target/test/unit/jdk6-test/target/site/apidocs/jdk6/test/package-summary.html" );
893         assertTrue( FileUtils.fileExists( packageSummary.getAbsolutePath() ) );
894         readed = readFile( packageSummary );
895         assertTrue( readed.indexOf( "Top - Copyright &#169; All rights reserved." ) != -1 );
896         assertTrue( readed.indexOf( "Header - Copyright &#169; All rights reserved." ) != -1 );
897         assertTrue( readed.indexOf( "Footer - Copyright &#169; All rights reserved." ) != -1 );
898     }
899 
900     /**
901      * Method to test proxy support in the javadoc
902      *
903      * @throws Exception if any
904      */
905     public void testProxy()
906         throws Exception
907     {
908         Settings settings = new Settings();
909         Proxy proxy = new Proxy();
910 
911         //dummy proxy
912         proxy.setActive( true );
913         proxy.setHost( "127.0.0.1" );
914         proxy.setPort( 80 );
915         proxy.setProtocol( "http" );
916         proxy.setUsername( "toto" );
917         proxy.setPassword( "toto" );
918         proxy.setNonProxyHosts( "www.google.com|*.somewhere.com" );
919         settings.addProxy( proxy );
920 
921         File testPom = new File( getBasedir(), "src/test/resources/unit/proxy-test/proxy-test-plugin-config.xml" );
922         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
923         assertNotNull( mojo );
924         setVariableValueToObject( mojo, "settings", settings );
925         mojo.execute();
926 
927         File commandLine = new File( getBasedir(), "target/test/unit/proxy-test/target/site/apidocs/javadoc." + ( SystemUtils.IS_OS_WINDOWS ? "bat" : "sh" ) );
928         assertTrue( FileUtils.fileExists( commandLine.getAbsolutePath() ) );
929         String readed = readFile( commandLine );
930         assertTrue( readed.indexOf( "-J-Dhttp.proxySet=true" ) != -1 );
931         assertTrue( readed.indexOf( "-J-Dhttp.proxyHost=127.0.0.1" ) != -1 );
932         assertTrue( readed.indexOf( "-J-Dhttp.proxyPort=80" ) != -1 );
933         assertTrue( readed.indexOf( "-J-Dhttp.proxyUser=\\\"toto\\\"" ) != -1 );
934         assertTrue( readed.indexOf( "-J-Dhttp.proxyPassword=\\\"toto\\\"" ) != -1 );
935         assertTrue( readed.indexOf( "-J-Dhttp.nonProxyHosts=\\\"www.google.com|*.somewhere.com\\\"" ) != -1 );
936 
937         File options = new File( getBasedir(), "target/test/unit/proxy-test/target/site/apidocs/options" );
938         assertTrue( FileUtils.fileExists( options.getAbsolutePath() ) );
939         String optionsContent = readFile( options );
940         // NO -link http://java.sun.com/j2se/1.5.0/docs/api/package-list
941         if ( JavadocUtilTest.isWebSiteOnline( null, getContainer().getLogger(), "http://java.sun.com" ) )
942         {
943             assertTrue( optionsContent.indexOf( "-link" ) == -1 );
944         }
945 
946         // real proxy
947         ProxyServer proxyServer = null;
948         AuthAsyncProxyServlet proxyServlet = null;
949         try
950         {
951             proxyServlet = new AuthAsyncProxyServlet();
952             proxyServer = new ProxyServer( proxyServlet );
953             proxyServer.start();
954 
955             settings = new Settings();
956             proxy = new Proxy();
957             proxy.setActive( true );
958             proxy.setHost( proxyServer.getHostName() );
959             proxy.setPort( proxyServer.getPort() );
960             proxy.setProtocol( "http" );
961             settings.addProxy( proxy );
962 
963             mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
964             setVariableValueToObject( mojo, "settings", settings );
965             mojo.execute();
966             readed = readFile( commandLine );
967             assertTrue( readed.indexOf( "-J-Dhttp.proxySet=true" ) != -1 );
968             assertTrue( readed.indexOf( "-J-Dhttp.proxyHost=" + proxyServer.getHostName() ) != -1 );
969             assertTrue( readed.indexOf( "-J-Dhttp.proxyPort=" + proxyServer.getPort() ) != -1 );
970 
971             optionsContent = readFile( options );
972             // -link http://java.sun.com/j2se/1.5.0/docs/api/package-list
973             if ( JavadocUtilTest.isWebSiteOnline( null, getContainer().getLogger(), "http://java.sun.com" ) )
974             {
975                 assertTrue( optionsContent.indexOf( "-link" ) != -1 );
976             }
977             assertTrue( true );
978         }
979         catch ( Exception e )
980         {
981             assertTrue( false );
982         }
983         finally
984         {
985             if ( proxyServer != null )
986             {
987                 proxyServer.stop();
988             }
989         }
990 
991         // auth proxy
992         Map authentications = new HashMap();
993         authentications.put( "foo", "bar" );
994         try
995         {
996             proxyServlet = new AuthAsyncProxyServlet();
997             proxyServer = new ProxyServer( proxyServlet );
998             proxyServer.start();
999 
1000             settings = new Settings();
1001             proxy = new Proxy();
1002             proxy.setActive( true );
1003             proxy.setHost( proxyServer.getHostName() );
1004             proxy.setPort( proxyServer.getPort() );
1005             proxy.setProtocol( "http" );
1006             proxy.setUsername( "foo" );
1007             proxy.setPassword( "bar" );
1008             settings.addProxy( proxy );
1009 
1010             mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
1011             setVariableValueToObject( mojo, "settings", settings );
1012             mojo.execute();
1013             readed = readFile( commandLine );
1014             assertTrue( readed.indexOf( "-J-Dhttp.proxySet=true" ) != -1 );
1015             assertTrue( readed.indexOf( "-J-Dhttp.proxyHost=" + proxyServer.getHostName() ) != -1 );
1016             assertTrue( readed.indexOf( "-J-Dhttp.proxyPort=" + proxyServer.getPort() ) != -1 );
1017             assertTrue( readed.indexOf( "-J-Dhttp.proxyUser=\\\"foo\\\"" ) != -1 );
1018             assertTrue( readed.indexOf( "-J-Dhttp.proxyPassword=\\\"bar\\\"" ) != -1 );
1019 
1020             optionsContent = readFile( options );
1021             // -link http://java.sun.com/j2se/1.5.0/docs/api/package-list
1022             if ( JavadocUtilTest.isWebSiteOnline( null, getContainer().getLogger(), "http://java.sun.com" ) )
1023             {
1024                 assertTrue( optionsContent.indexOf( "-link" ) != -1 );
1025             }
1026             assertTrue( true );
1027         }
1028         catch ( Exception e )
1029         {
1030             assertTrue( false );
1031         }
1032         finally
1033         {
1034             if ( proxyServer != null )
1035             {
1036                 proxyServer.stop();
1037             }
1038         }
1039     }
1040 
1041     /**
1042      * Method to test error or conflict in Javadoc options and in standard doclet options.
1043      *
1044      * @throws Exception if any
1045      */
1046     public void testValidateOptions()
1047         throws Exception
1048     {
1049         // encoding
1050         File testPom =
1051             new File( getBasedir(),
1052                       "src/test/resources/unit/validate-options-test/wrong-encoding-test-plugin-config.xml" );
1053         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
1054         try
1055         {
1056             mojo.execute();
1057             assertTrue( "Not wrong encoding catch", false );
1058         }
1059         catch ( MojoExecutionException e )
1060         {
1061             assertTrue( "Not wrong encoding catch",
1062                         e.getMessage().indexOf( "Unsupported option <encoding/>" ) != -1 );
1063         }
1064         testPom =
1065             new File( getBasedir(),
1066                       "src/test/resources/unit/validate-options-test/wrong-docencoding-test-plugin-config.xml" );
1067         mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
1068         try
1069         {
1070             mojo.execute();
1071             assertTrue( "Not wrong docencoding catch", false );
1072         }
1073         catch ( MojoExecutionException e )
1074         {
1075             assertTrue( "Not wrong docencoding catch", e.getMessage()
1076                                                         .indexOf( "Unsupported option <docencoding/>" ) != -1 );
1077         }
1078         testPom =
1079             new File( getBasedir(),
1080                       "src/test/resources/unit/validate-options-test/wrong-charset-test-plugin-config.xml" );
1081         mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
1082         try
1083         {
1084             mojo.execute();
1085             assertTrue( "Not wrong charset catch", false );
1086         }
1087         catch ( MojoExecutionException e )
1088         {
1089             assertTrue( "Not wrong charset catch", e.getMessage().indexOf( "Unsupported option <charset/>" ) != -1 );
1090         }
1091 
1092         // locale
1093         testPom =
1094             new File( getBasedir(),
1095                       "src/test/resources/unit/validate-options-test/wrong-locale-test-plugin-config.xml" );
1096         mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
1097         try
1098         {
1099             mojo.execute();
1100             assertTrue( "Not wrong locale catch", false );
1101         }
1102         catch ( MojoExecutionException e )
1103         {
1104             assertTrue( "Not wrong locale catch", e.getMessage().indexOf( "Unsupported option <locale/>" ) != -1 );
1105         }
1106         testPom =
1107             new File( getBasedir(),
1108                       "src/test/resources/unit/validate-options-test/wrong-locale-with-variant-test-plugin-config.xml" );
1109         mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
1110         mojo.execute();
1111         assertTrue( "Not wrong locale catch", true );
1112 
1113         // conflict options
1114         testPom =
1115             new File( getBasedir(),
1116                       "src/test/resources/unit/validate-options-test/conflict-options-test-plugin-config.xml" );
1117         mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
1118         try
1119         {
1120             mojo.execute();
1121             assertTrue( "Not conflict catch", false );
1122         }
1123         catch ( MojoExecutionException e )
1124         {
1125             assertTrue( "Not conflict catch", e.getMessage()
1126                                                .indexOf( "Option <nohelp/> conflicts with <helpfile/>" ) != -1 );
1127         }
1128     }
1129 
1130     /**
1131      * Method to test the <code>&lt;tagletArtifacts/&gt;</code> parameter.
1132      *
1133      * @throws Exception if any
1134      */
1135     public void testTagletArtifacts()
1136         throws Exception
1137     {
1138         File testPom =
1139             new File( getBasedir(),
1140                       "src/test/resources/unit/tagletArtifacts-test/tagletArtifacts-test-plugin-config.xml" );
1141         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
1142 
1143         setVariableValueToObject( mojo, "remoteRepositories", mojo.project.getRemoteArtifactRepositories() );
1144 
1145         mojo.execute();
1146 
1147         File optionsFile = new File( mojo.getOutputDirectory(), "options" );
1148         assertTrue( optionsFile.exists() );
1149         String options = readFile( optionsFile );
1150         // count -taglet
1151         assertEquals( 20, StringUtils.countMatches( options, LINE_SEPARATOR + "-taglet" + LINE_SEPARATOR ) );
1152         assertTrue( options.indexOf( "org.apache.maven.tools.plugin.javadoc.MojoAggregatorTypeTaglet" ) != -1 );
1153         assertTrue( options.indexOf( "org.apache.maven.tools.plugin.javadoc.MojoComponentFieldTaglet" ) != -1 );
1154         assertTrue( options.indexOf( "org.apache.maven.tools.plugin.javadoc.MojoConfiguratorTypeTaglet" ) != -1 );
1155         assertTrue( options.indexOf( "org.apache.maven.tools.plugin.javadoc.MojoExecuteTypeTaglet" ) != -1 );
1156         assertTrue( options.indexOf( "org.apache.maven.tools.plugin.javadoc.MojoExecutionStrategyTypeTaglet" ) != -1 );
1157         assertTrue( options.indexOf( "org.apache.maven.tools.plugin.javadoc.MojoGoalTypeTaglet" ) != -1 );
1158         assertTrue( options.indexOf( "org.apache.maven.tools.plugin.javadoc.MojoInheritByDefaultTypeTaglet" ) != -1 );
1159         assertTrue( options.indexOf( "org.apache.maven.tools.plugin.javadoc.MojoInstantiationStrategyTypeTaglet" ) != -1 );
1160         assertTrue( options.indexOf( "org.apache.maven.tools.plugin.javadoc.MojoParameterFieldTaglet" ) != -1 );
1161         assertTrue( options.indexOf( "org.apache.maven.tools.plugin.javadoc.MojoPhaseTypeTaglet" ) != -1 );
1162         assertTrue( options.indexOf( "org.apache.maven.tools.plugin.javadoc.MojoReadOnlyFieldTaglet" ) != -1 );
1163         assertTrue( options.indexOf( "org.apache.maven.tools.plugin.javadoc.MojoRequiredFieldTaglet" ) != -1 );
1164         assertTrue( options.indexOf( "org.apache.maven.tools.plugin.javadoc.MojoRequiresDependencyResolutionTypeTaglet" ) != -1 );
1165         assertTrue( options.indexOf( "org.apache.maven.tools.plugin.javadoc.MojoRequiresDirectInvocationTypeTaglet" ) != -1 );
1166         assertTrue( options.indexOf( "org.apache.maven.tools.plugin.javadoc.MojoRequiresOnLineTypeTaglet" ) != -1 );
1167         assertTrue( options.indexOf( "org.apache.maven.tools.plugin.javadoc.MojoRequiresProjectTypeTaglet" ) != -1 );
1168         assertTrue( options.indexOf( "org.apache.maven.tools.plugin.javadoc.MojoRequiresReportsTypeTaglet" ) != -1 );
1169         assertTrue( options.indexOf( "org.codehaus.plexus.javadoc.PlexusConfigurationTaglet" ) != -1 );
1170         assertTrue( options.indexOf( "org.codehaus.plexus.javadoc.PlexusRequirementTaglet" ) != -1 );
1171         assertTrue( options.indexOf( "org.codehaus.plexus.javadoc.PlexusComponentTaglet" ) != -1 );
1172     }
1173 
1174     /**
1175      * Method to test the <code>&lt;stylesheetfile/&gt;</code> parameter.
1176      *
1177      * @throws Exception if any
1178      */
1179     public void testStylesheetfile()
1180         throws Exception
1181     {
1182         File testPom = new File( getBasedir(), "src/test/resources/unit/stylesheetfile-test/pom.xml" );
1183 
1184         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
1185         assertNotNull( mojo );
1186 
1187         setVariableValueToObject( mojo, "remoteRepositories", mojo.project.getRemoteArtifactRepositories() );
1188 
1189         File stylesheetfile =
1190             new File( getBasedir(), "target/test/unit/stylesheetfile-test/target/site/apidocs/stylesheet.css" );
1191 
1192         File options = new File( getBasedir(), "target/test/unit/stylesheetfile-test/target/site/apidocs/options" );
1193 
1194         // stylesheet == maven OR java
1195         setVariableValueToObject( mojo, "stylesheet", "javamaven" );
1196 
1197         try
1198         {
1199             mojo.execute();
1200             assertTrue( false );
1201         }
1202         catch ( Exception e )
1203         {
1204             assertTrue( true );
1205         }
1206 
1207         // stylesheet == java
1208         setVariableValueToObject( mojo, "stylesheet", "java" );
1209         mojo.execute();
1210 
1211         String content = readFile( stylesheetfile );
1212         assertTrue( content.indexOf( "/* Javadoc style sheet */" ) != -1 );
1213 
1214         String optionsContent = readFile( options );
1215         assertTrue( optionsContent.indexOf( "-stylesheetfile" ) == -1 );
1216 
1217         // stylesheet == maven
1218         setVariableValueToObject( mojo, "stylesheet", "maven" );
1219         mojo.execute();
1220 
1221         content = readFile( stylesheetfile );
1222         assertTrue( content.indexOf( "/* Javadoc style sheet */" ) != -1
1223             && content.indexOf( "Licensed to the Apache Software Foundation (ASF) under one" ) != -1 );
1224 
1225         optionsContent = readFile( options );
1226         assertTrue( optionsContent.indexOf( "-stylesheetfile" ) != -1 );
1227         assertTrue( optionsContent
1228                                   .indexOf( "'" + stylesheetfile.getAbsolutePath().replaceAll( "\\\\", "/" ) + "'" ) != -1 );
1229 
1230         // stylesheetfile defined as a project resource
1231         setVariableValueToObject( mojo, "stylesheet", null );
1232         setVariableValueToObject( mojo, "stylesheetfile", "com/mycompany/app/javadoc/css/stylesheet.css" );
1233         mojo.execute();
1234 
1235         content = readFile( stylesheetfile );
1236         assertTrue( content.indexOf( "/* Custom Javadoc style sheet in project */" ) != -1 );
1237 
1238         optionsContent = readFile( options );
1239         assertTrue( optionsContent.indexOf( "-stylesheetfile" ) != -1 );
1240         File stylesheetResource =
1241             new File( getBasedir(),
1242                       "src/test/resources/unit/stylesheetfile-test/src/main/resources/com/mycompany/app/javadoc/css/stylesheet.css" );
1243         assertTrue( optionsContent.indexOf( "'" + stylesheetResource.getAbsolutePath().replaceAll( "\\\\", "/" )
1244             + "'" ) != -1 );
1245 
1246         // stylesheetfile defined in a javadoc plugin dependency
1247         setVariableValueToObject( mojo, "stylesheetfile", "com/mycompany/app/javadoc/css2/stylesheet.css" );
1248         mojo.execute();
1249 
1250         content = readFile( stylesheetfile );
1251         assertTrue( content.indexOf( "/* Custom Javadoc style sheet in artefact */" ) != -1 );
1252 
1253         optionsContent = readFile( options );
1254         assertTrue( optionsContent.indexOf( "-stylesheetfile" ) != -1 );
1255         assertTrue( optionsContent
1256                                   .indexOf( "'" + stylesheetfile.getAbsolutePath().replaceAll( "\\\\", "/" ) + "'" ) != -1 );
1257 
1258         // stylesheetfile defined as file
1259         File css =
1260             new File( getBasedir(),
1261                       "src/test/resources/unit/stylesheetfile-test/src/main/resources/com/mycompany/app/javadoc/css3/stylesheet.css" );
1262         setVariableValueToObject( mojo, "stylesheetfile", css.getAbsolutePath() );
1263         mojo.execute();
1264 
1265         content = readFile( stylesheetfile );
1266         assertTrue( content.indexOf( "/* Custom Javadoc style sheet as file */" ) != -1 );
1267 
1268         optionsContent = readFile( options );
1269         assertTrue( optionsContent.indexOf( "-stylesheetfile" ) != -1 );
1270         stylesheetResource =
1271             new File( getBasedir(),
1272                       "src/test/resources/unit/stylesheetfile-test/src/main/resources/com/mycompany/app/javadoc/css3/stylesheet.css" );
1273         assertTrue( optionsContent.indexOf( "'" + stylesheetResource.getAbsolutePath().replaceAll( "\\\\", "/" )
1274             + "'" ) != -1 );
1275     }
1276 
1277     /**
1278      * Method to test the <code>&lt;helpfile/&gt;</code> parameter.
1279      *
1280      * @throws Exception if any
1281      */
1282     public void testHelpfile()
1283         throws Exception
1284     {
1285         File testPom = new File( getBasedir(), "src/test/resources/unit/helpfile-test/pom.xml" );
1286 
1287         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
1288         assertNotNull( mojo );
1289 
1290         setVariableValueToObject( mojo, "remoteRepositories", mojo.project.getRemoteArtifactRepositories() );
1291 
1292         File helpfile =
1293             new File( getBasedir(), "target/test/unit/helpfile-test/target/site/apidocs/help-doc.html" );
1294 
1295         File options = new File( getBasedir(), "target/test/unit/helpfile-test/target/site/apidocs/options" );
1296 
1297         // helpfile by default
1298         mojo.execute();
1299 
1300         String content = readFile( helpfile );
1301         assertTrue( content.indexOf( "<!-- Generated by javadoc" ) != -1 );
1302 
1303         String optionsContent = readFile( options );
1304         assertTrue( optionsContent.indexOf( "-helpfile" ) == -1 );
1305 
1306         // helpfile defined in a javadoc plugin dependency
1307         setVariableValueToObject( mojo, "helpfile", "com/mycompany/app/javadoc/helpfile/help-doc.html" );
1308         mojo.execute();
1309 
1310         content = readFile( helpfile );
1311         assertTrue( content.indexOf( "<!--  Help file from artefact -->" ) != -1 );
1312 
1313         optionsContent = readFile( options );
1314         assertTrue( optionsContent.indexOf( "-helpfile" ) != -1 );
1315         File help = new File( getBasedir(), "target/test/unit/helpfile-test/target/site/apidocs/help-doc.html" );
1316         assertTrue( optionsContent.indexOf( "'" + help.getAbsolutePath().replaceAll( "\\\\", "/" ) + "'" ) != -1 );
1317 
1318         // helpfile defined as a project resource
1319         setVariableValueToObject( mojo, "helpfile", "com/mycompany/app/javadoc/helpfile2/help-doc.html" );
1320         mojo.execute();
1321 
1322         content = readFile( helpfile );
1323         assertTrue( content.indexOf( "<!--  Help file from file -->" ) != -1 );
1324 
1325         optionsContent = readFile( options );
1326         assertTrue( optionsContent.indexOf( "-helpfile" ) != -1 );
1327         help =
1328             new File( getBasedir(),
1329                       "src/test/resources/unit/helpfile-test/src/main/resources/com/mycompany/app/javadoc/helpfile2/help-doc.html" );
1330         assertTrue( optionsContent.indexOf( "'" + help.getAbsolutePath().replaceAll( "\\\\", "/" ) + "'" ) != -1 );
1331 
1332         // helpfile defined as file
1333         help =
1334             new File( getBasedir(),
1335                       "src/test/resources/unit/helpfile-test/src/main/resources/com/mycompany/app/javadoc/helpfile2/help-doc.html" );
1336         setVariableValueToObject( mojo, "helpfile", help.getAbsolutePath() );
1337         mojo.execute();
1338 
1339         content = readFile( helpfile );
1340         assertTrue( content.indexOf( "<!--  Help file from file -->" ) != -1 );
1341 
1342         optionsContent = readFile( options );
1343         assertTrue( optionsContent.indexOf( "-helpfile" ) != -1 );
1344         assertTrue( optionsContent.indexOf( "'" + help.getAbsolutePath().replaceAll( "\\\\", "/" ) + "'" ) != -1 );
1345     }
1346 }