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  
27  import org.apache.commons.lang.SystemUtils;
28  import org.apache.maven.plugin.MojoExecutionException;
29  import org.apache.maven.plugin.testing.AbstractMojoTestCase;
30  import org.codehaus.plexus.util.FileUtils;
31  import org.codehaus.plexus.util.StringUtils;
32  
33  /**
34   * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
35   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
36   */
37  public class JavadocReportTest
38      extends AbstractMojoTestCase
39  {
40      private static final String LINE_SEPARATOR = " ";
41  
42      /**
43       * @see junit.framework.TestCase#setUp()
44       */
45      protected void setUp()
46          throws Exception
47      {
48          // required for mojo lookups to work
49          super.setUp();
50          createTestRepo();
51      }
52  
53      /**
54       * @see junit.framework.TestCase#tearDown()
55       */
56      protected void tearDown()
57          throws Exception
58      {
59          super.tearDown();
60      }
61  
62      /**
63       * Create test repository in target directory.
64       *
65       * @throws IOException if any
66       */
67      private void createTestRepo()
68          throws IOException
69      {
70          // ----------------------------------------------------------------------
71          // UMLGraph
72          // ----------------------------------------------------------------------
73  
74          File f = new File( getBasedir(), "target/local-repo/umlgraph/UMLGraph/2.1" );
75          f.mkdirs();
76  
77          FileUtils
78              .copyFile(
79                         new File( getBasedir(),
80                                   "src/test/resources/unit/doclet-test/artifact-doclet/umlgraph/UMLGraph/maven-metadata-local.xml" ),
81                         new File( getBasedir(), "target/local-repo/umlgraph/UMLGraph/maven-metadata-local.xml" ) );
82  
83          FileUtils
84              .copyFile(
85                         new File( getBasedir(),
86                                   "src/test/resources/unit/doclet-test/artifact-doclet/umlgraph/UMLGraph/2.1/UMLGraph-2.1.jar" ),
87                         new File( getBasedir(), "target/local-repo/umlgraph/UMLGraph/2.1/UMLGraph-2.1.jar" ) );
88  
89          FileUtils
90              .copyFile(
91                         new File( getBasedir(),
92                                   "src/test/resources/unit/doclet-test/artifact-doclet/umlgraph/UMLGraph/2.1/UMLGraph-2.1.pom" ),
93                         new File( getBasedir(), "target/local-repo/umlgraph/UMLGraph/2.1/UMLGraph-2.1.pom" ) );
94  
95          // ----------------------------------------------------------------------
96          // UMLGraph-bis
97          // ----------------------------------------------------------------------
98  
99          f = new File( getBasedir(), "target/local-repo/umlgraph/UMLGraph-bis/2.1" );
100         f.mkdirs();
101 
102         FileUtils
103             .copyFile(
104                        new File( getBasedir(),
105                                  "src/test/resources/unit/doclet-path-test/artifact-doclet/umlgraph/UMLGraph-bis/maven-metadata-local.xml" ),
106                        new File( getBasedir(), "target/local-repo/umlgraph/UMLGraph-bis/maven-metadata-local.xml" ) );
107 
108         FileUtils
109             .copyFile(
110                        new File( getBasedir(),
111                                  "src/test/resources/unit/doclet-path-test/artifact-doclet/umlgraph/UMLGraph-bis/2.1/UMLGraph-bis-2.1.jar" ),
112                        new File( getBasedir(), "target/local-repo/umlgraph/UMLGraph-bis/2.1/UMLGraph-bis-2.1.jar" ) );
113 
114         FileUtils
115             .copyFile(
116                        new File( getBasedir(),
117                                  "src/test/resources/unit/doclet-path-test/artifact-doclet/umlgraph/UMLGraph-bis/2.1/UMLGraph-bis-2.1.pom" ),
118                        new File( getBasedir(), "target/local-repo/umlgraph/UMLGraph-bis/2.1/UMLGraph-bis-2.1.pom" ) );
119 
120         // ----------------------------------------------------------------------
121         // commons-attributes-compiler
122         // http://www.tullmann.org/pat/taglets/
123         // ----------------------------------------------------------------------
124 
125         f = new File( getBasedir(), "target/local-repo/org/tullmann/taglets/1.0" );
126         f.mkdirs();
127 
128         FileUtils
129             .copyFile(
130                        new File( getBasedir(),
131                                  "src/test/resources/unit/taglet-test/artifact-taglet/org/tullmann/taglets/maven-metadata-local.xml" ),
132                        new File( getBasedir(), "target/local-repo/org/tullmann/taglets/maven-metadata-local.xml" ) );
133 
134         FileUtils
135             .copyFile(
136                        new File( getBasedir(),
137                                  "src/test/resources/unit/taglet-test/artifact-taglet/org/tullmann/taglets/1.0/taglets-1.0.jar" ),
138                        new File( getBasedir(), "target/local-repo/org/tullmann/taglets/1.0/taglets-1.0.jar" ) );
139 
140         FileUtils
141             .copyFile(
142                        new File( getBasedir(),
143                                  "src/test/resources/unit/taglet-test/artifact-taglet/org/tullmann/taglets/1.0/taglets-1.0.pom" ),
144                        new File( getBasedir(), "target/local-repo/org/tullmann/taglets/1.0/taglets-1.0.pom" ) );
145     }
146 
147     /**
148      * Convenience method that reads the contents of the specified file object into a string with a
149      * <code>space</code> as line separator.
150      *
151      * @see #LINE_SEPARATOR
152      * @param file the file to be read
153      * @return a String object that contains the contents of the file
154      * @throws IOException if any
155      */
156     private static String readFile( File file )
157         throws IOException
158     {
159         String str = "", strTmp = "";
160         BufferedReader in = new BufferedReader( new FileReader( file ) );
161 
162         try
163         {
164             while ( ( strTmp = in.readLine() ) != null )
165             {
166                 str = str + LINE_SEPARATOR + strTmp;
167             }
168         }
169         finally
170         {
171             in.close();
172         }
173 
174         return str;
175     }
176 
177     /**
178      * Test when default configuration is provided for the plugin
179      *
180      * @throws Exception if any
181      */
182     public void testDefaultConfiguration()
183         throws Exception
184     {
185         File testPom = new File( getBasedir(),
186                                  "src/test/resources/unit/default-configuration/default-configuration-plugin-config.xml" );
187         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
188         mojo.execute();
189 
190         // package level generated javadoc files
191         File generatedFile = new File( getBasedir(),
192                                        "target/test/unit/default-configuration/target/site/apidocs/def/configuration/App.html" );
193         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
194 
195         generatedFile = new File( getBasedir(),
196                                   "target/test/unit/default-configuration/target/site/apidocs/def/configuration/AppSample.html" );
197         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
198 
199         generatedFile = new File( getBasedir(),
200                                   "target/test/unit/default-configuration/target/site/apidocs/def/configuration/package-frame.html" );
201         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
202 
203         generatedFile = new File( getBasedir(),
204                                   "target/test/unit/default-configuration/target/site/apidocs/def/configuration/package-summary.html" );
205         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
206 
207         generatedFile = new File( getBasedir(),
208                                   "target/test/unit/default-configuration/target/site/apidocs/def/configuration/package-tree.html" );
209         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
210 
211         generatedFile = new File( getBasedir(),
212                                   "target/test/unit/default-configuration/target/site/apidocs/def/configuration/package-use.html" );
213         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
214 
215         // class level generated javadoc files
216         generatedFile = new File( getBasedir(),
217                                   "target/test/unit/default-configuration/target/site/apidocs/def/configuration/class-use/App.html" );
218         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
219 
220         generatedFile = new File( getBasedir(),
221                                   "target/test/unit/default-configuration/target/site/apidocs/def/configuration/class-use/AppSample.html" );
222         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
223 
224         // project level generated javadoc files
225         generatedFile = new File( getBasedir(),
226                                   "target/test/unit/default-configuration/target/site/apidocs/allclasses-frame.html" );
227         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
228 
229         generatedFile = new File( getBasedir(),
230                                   "target/test/unit/default-configuration/target/site/apidocs/allclasses-noframe.html" );
231         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
232 
233         generatedFile = new File( getBasedir(),
234                                   "target/test/unit/default-configuration/target/site/apidocs/constant-values.html" );
235         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
236 
237         generatedFile = new File( getBasedir(),
238                                   "target/test/unit/default-configuration/target/site/apidocs/deprecated-list.html" );
239         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
240 
241         generatedFile = new File( getBasedir(),
242                                   "target/test/unit/default-configuration/target/site/apidocs/help-doc.html" );
243         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
244 
245         generatedFile = new File( getBasedir(),
246                                   "target/test/unit/default-configuration/target/site/apidocs/index-all.html" );
247         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
248 
249         generatedFile = new File( getBasedir(), "target/test/unit/default-configuration/target/site/apidocs/index.html" );
250         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
251 
252         generatedFile = new File( getBasedir(),
253                                   "target/test/unit/default-configuration/target/site/apidocs/overview-tree.html" );
254         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
255 
256         generatedFile = new File( getBasedir(),
257                                   "target/test/unit/default-configuration/target/site/apidocs/package-list" );
258         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
259 
260         generatedFile = new File( getBasedir(),
261                                   "target/test/unit/default-configuration/target/site/apidocs/stylesheet.css" );
262         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
263     }
264 
265     /**
266      * Method for testing the subpackages and excludePackageNames parameter
267      *
268      * @throws Exception if any
269      */
270     public void testSubpackages()
271         throws Exception
272     {
273         File testPom = new File( getBasedir(),
274                                  "src/test/resources/unit/subpackages-test/subpackages-test-plugin-config.xml" );
275         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
276         mojo.execute();
277 
278         // check the excluded packages
279         File generatedFile = new File( getBasedir(),
280                                        "target/test/unit/subpackages-test/target/site/apidocs/subpackages/test/excluded" );
281         assertTrue( !FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
282 
283         generatedFile = new File( getBasedir(),
284                                   "target/test/unit/subpackages-test/target/site/apidocs/subpackages/test/included/exclude" );
285         assertTrue( !FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
286 
287         // check if the classes in the specified subpackages were included
288         generatedFile = new File( getBasedir(),
289                                   "target/test/unit/subpackages-test/target/site/apidocs/subpackages/test/App.html" );
290         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
291 
292         generatedFile = new File( getBasedir(),
293                                   "target/test/unit/subpackages-test/target/site/apidocs/subpackages/test/AppSample.html" );
294         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
295 
296         generatedFile = new File( getBasedir(),
297                                   "target/test/unit/subpackages-test/target/site/apidocs/subpackages/test/included/IncludedApp.html" );
298         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
299 
300         generatedFile = new File( getBasedir(),
301                                   "target/test/unit/subpackages-test/target/site/apidocs/subpackages/test/included/IncludedAppSample.html" );
302         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
303     }
304 
305     /**
306      * Test the recursion and exclusion of the doc-files subdirectories.
307      *
308      * @throws Exception if any
309      */
310     public void testDocfiles()
311         throws Exception
312     {
313         File testPom = new File( getBasedir(), "src/test/resources/unit/docfiles-test/docfiles-test-plugin-config.xml" );
314         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
315         mojo.execute();
316 
317         // check if the doc-files subdirectories were copied
318         File generatedFile = new File( getBasedir(), "target/test/unit/docfiles-test/target/site/apidocs/doc-files" );
319         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
320 
321         generatedFile = new File( getBasedir(),
322                                   "target/test/unit/docfiles-test/target/site/apidocs/doc-files/included-dir1/sample-included1.gif" );
323         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
324 
325         generatedFile = new File( getBasedir(),
326                                   "target/test/unit/docfiles-test/target/site/apidocs/doc-files/included-dir2/sample-included2.gif" );
327         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
328 
329         generatedFile = new File( getBasedir(),
330                                   "target/test/unit/docfiles-test/target/site/apidocs/doc-files/excluded-dir1" );
331         assertTrue( !FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
332 
333         generatedFile = new File( getBasedir(),
334                                   "target/test/unit/docfiles-test/target/site/apidocs/doc-files/excluded-dir2" );
335         assertTrue( !FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
336     }
337 
338     /**
339      * Test javadoc plugin using custom configuration. noindex, notree and nodeprecated parameters
340      * were set to true.
341      *
342      * @throws Exception if any
343      */
344     public void testCustomConfiguration()
345         throws Exception
346     {
347         File testPom = new File( getBasedir(),
348                                  "src/test/resources/unit/custom-configuration/custom-configuration-plugin-config.xml" );
349         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
350         mojo.execute();
351 
352         // check if there is a tree page generated (notree == true)
353         File generatedFile = new File( getBasedir(),
354                                        "target/test/unit/custom-configuration/target/site/apidocs/overview-tree.html" );
355         assertTrue( !FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
356 
357         generatedFile = new File( getBasedir(),
358                                   "target/test/unit/custom-configuration/target/site/apidocs/custom/configuration/package-tree.html" );
359         assertTrue( !FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
360 
361         // check if the main index page was generated (noindex == true)
362         generatedFile = new File( getBasedir(),
363                                   "target/test/unit/custom-configuration/target/site/apidocs/index-all.html" );
364         assertTrue( !FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
365 
366         // check if the deprecated list and the deprecated api were generated (nodeprecated == true)
367         // @todo Fix: the class-use of the deprecated api is still created eventhough the deprecated api of that class
368         // is no longer generated
369         generatedFile = new File( getBasedir(),
370                                   "target/test/unit/custom-configuration/target/site/apidocs/deprecated-list.html" );
371         assertTrue( !FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
372 
373         generatedFile = new File( getBasedir(),
374                                   "target/test/unit/custom-configuration/target/site/apidocs/custom/configuration/App.html" );
375         assertTrue( !FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
376 
377         // read the contents of the html files based on some of the parameter values
378         // author == false
379         String str = readFile( new File( getBasedir(),
380                                          "target/test/unit/custom-configuration/target/site/apidocs/custom/configuration/AppSample.html" ) );
381         assertTrue( str.toLowerCase().indexOf( "author" ) == -1 );
382 
383         // bottom
384         assertTrue( str.toUpperCase().indexOf( "SAMPLE BOTTOM CONTENT" ) != -1 );
385 
386         // offlineLinks
387         assertTrue( str.toLowerCase().indexOf(
388                                                "HREF=\"http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html"
389                                                    .toLowerCase() ) != -1 );
390 
391         // header
392         assertTrue( str.toUpperCase().indexOf( "MAVEN JAVADOC PLUGIN TEST" ) != -1 );
393 
394         // footer
395         assertTrue( str.toUpperCase().indexOf( "MAVEN JAVADOC PLUGIN TEST FOOTER" ) != -1 );
396 
397         // nohelp == true
398         assertTrue( str.toUpperCase().indexOf( "/help-doc.html".toUpperCase() ) == -1 );
399 
400         // check the wildcard (*) package exclusions -- excludePackageNames parameter
401         generatedFile = new File( getBasedir(),
402                                   "target/test/unit/custom-configuration/target/site/apidocs/custom/configuration/exclude1/Exclude1App.html" );
403         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
404 
405         generatedFile = new File( getBasedir(),
406                                   "target/test/unit/custom-configuration/target/site/apidocs/custom/configuration/exclude1/subexclude/SubexcludeApp.html" );
407         assertTrue( !FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
408 
409         generatedFile = new File( getBasedir(),
410                                   "target/test/unit/custom-configuration/target/site/apidocs/custom/configuration/exclude2/Exclude2App.html" );
411         assertTrue( !FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
412     }
413 
414     /**
415      * Method to test the doclet artifact configuration
416      *
417      * @throws Exception if any
418      */
419     public void testDoclets()
420         throws Exception
421     {
422         // ----------------------------------------------------------------------
423         // doclet-test: check if the file generated by UmlGraph exists and if
424         // doclet path contains the UmlGraph artifact
425         // ----------------------------------------------------------------------
426 
427         File testPom = new File( getBasedir(), "src/test/resources/unit/doclet-test/doclet-test-plugin-config.xml" );
428         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
429         mojo.execute();
430 
431         File generatedFile = new File( getBasedir(), "target/test/unit/doclet-test/target/site/apidocs/graph.dot" );
432         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
433 
434         File optionsFile = new File( mojo.getOutputDirectory(), "options" );
435         assertTrue( optionsFile.exists() );
436         String options = readFile( optionsFile );
437         assertTrue( options.indexOf( "/target/local-repo/umlgraph/UMLGraph/2.1/UMLGraph-2.1.jar" ) != -1 );
438 
439         // ----------------------------------------------------------------------
440         // doclet-path: check if the file generated by UmlGraph exists and if
441         // doclet path contains the twice UmlGraph artifacts
442         // ----------------------------------------------------------------------
443 
444         testPom = new File( getBasedir(), "src/test/resources/unit/doclet-path-test/doclet-path-test-plugin-config.xml" );
445         mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
446         mojo.execute();
447 
448         generatedFile = new File( getBasedir(), "target/test/unit/doclet-test/target/site/apidocs/graph.dot" );
449         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
450 
451         optionsFile = new File( mojo.getOutputDirectory(), "options" );
452         assertTrue( optionsFile.exists() );
453         options = readFile( optionsFile );
454         assertTrue( options.indexOf( "/target/local-repo/umlgraph/UMLGraph/2.1/UMLGraph-2.1.jar" ) != -1 );
455         assertTrue( options.indexOf( "/target/local-repo/umlgraph/UMLGraph-bis/2.1/UMLGraph-bis-2.1.jar" ) != -1 );
456     }
457 
458     /**
459      * Method to test the aggregate parameter
460      *
461      * @throws Exception if any
462      */
463     public void testAggregate()
464         throws Exception
465     {
466         File testPom = new File( getBasedir(),
467                                  "src/test/resources/unit/aggregate-test/aggregate-test-plugin-config.xml" );
468         JavadocReport mojo = (JavadocReport) lookupMojo( "aggregate", testPom );
469         mojo.execute();
470 
471         // check if project1 api files exist
472         File generatedFile = new File( getBasedir(),
473                                        "target/test/unit/aggregate-test/target/site/apidocs/aggregate/test/project1/Project1App.html" );
474         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
475 
476         generatedFile = new File( getBasedir(),
477                                   "target/test/unit/aggregate-test/target/site/apidocs/aggregate/test/project1/Project1AppSample.html" );
478         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
479 
480         generatedFile = new File( getBasedir(),
481                                   "target/test/unit/aggregate-test/target/site/apidocs/aggregate/test/project1/Project1Sample.html" );
482         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
483 
484         generatedFile = new File( getBasedir(),
485                                   "target/test/unit/aggregate-test/target/site/apidocs/aggregate/test/project1/Project1Test.html" );
486         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
487 
488         // check if project2 api files exist
489         generatedFile = new File( getBasedir(),
490                                   "target/test/unit/aggregate-test/target/site/apidocs/aggregate/test/project2/Project2App.html" );
491         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
492 
493         generatedFile = new File( getBasedir(),
494                                   "target/test/unit/aggregate-test/target/site/apidocs/aggregate/test/project2/Project2AppSample.html" );
495         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
496 
497         generatedFile = new File( getBasedir(),
498                                   "target/test/unit/aggregate-test/target/site/apidocs/aggregate/test/project2/Project2Sample.html" );
499         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
500 
501         generatedFile = new File( getBasedir(),
502                                   "target/test/unit/aggregate-test/target/site/apidocs/aggregate/test/project2/Project2Test.html" );
503         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
504 
505     }
506 
507     /**
508      * Method to test when the path to the project sources has an apostrophe (')
509      *
510      * @throws Exception if any
511      */
512     public void testQuotedPath()
513         throws Exception
514     {
515         File testPom = new File( getBasedir(),
516                                  "src/test/resources/unit/quotedpath'test/quotedpath-test-plugin-config.xml" );
517         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
518         mojo.execute();
519 
520         // package level generated javadoc files
521         File generatedFile = new File( getBasedir(),
522                                        "target/test/unit/quotedpath'test/target/site/apidocs/quotedpath/test/App.html" );
523         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
524 
525         generatedFile = new File( getBasedir(),
526                                   "target/test/unit/quotedpath'test/target/site/apidocs/quotedpath/test/AppSample.html" );
527         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
528 
529         // project level generated javadoc files
530         generatedFile = new File( getBasedir(), "target/test/unit/quotedpath'test/target/site/apidocs/index-all.html" );
531         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
532 
533         generatedFile = new File( getBasedir(), "target/test/unit/quotedpath'test/target/site/apidocs/index.html" );
534         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
535 
536         generatedFile = new File( getBasedir(),
537                                   "target/test/unit/quotedpath'test/target/site/apidocs/overview-tree.html" );
538         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
539 
540         generatedFile = new File( getBasedir(), "target/test/unit/quotedpath'test/target/site/apidocs/package-list" );
541         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
542 
543         generatedFile = new File( getBasedir(), "target/test/unit/quotedpath'test/target/site/apidocs/stylesheet.css" );
544         assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
545     }
546 
547     /**
548      * @throws Exception if any
549      */
550     public void testExceptions()
551         throws Exception
552     {
553         try
554         {
555             File testPom = new File( getBasedir(),
556                                      "src/test/resources/unit/default-configuration/exception-test-plugin-config.xml" );
557             JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
558             mojo.execute();
559 
560             fail( "Must throw exception." );
561         }
562         catch ( Exception e )
563         {
564             assertTrue( true );
565 
566             try
567             {
568                 FileUtils.deleteDirectory( new File( getBasedir(), "exception" ) );
569             }
570             catch ( IOException ie )
571             {
572                 // nop
573             }
574         }
575     }
576 
577     /**
578      * Method to test the taglet artifact configuration
579      *
580      * @throws Exception if any
581      */
582     public void testTaglets()
583         throws Exception
584     {
585         // ----------------------------------------------------------------------
586         // taglet-test: check if a taglet is used
587         // ----------------------------------------------------------------------
588 
589         File testPom = new File( getBasedir(), "src/test/resources/unit/taglet-test/taglet-test-plugin-config.xml" );
590         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
591         mojo.execute();
592 
593         File index = new File( getBasedir(), "target/test/unit/taglet-test/target/site/apidocs/index.html" );
594         assertTrue( FileUtils.fileExists( index.getAbsolutePath() ) );
595 
596         File appFile = new File( getBasedir(), "target/test/unit/taglet-test/target/site/apidocs/taglet/test/App.html" );
597         assertTrue( appFile.exists() );
598         String appString = readFile( appFile );
599         assertTrue( appString.indexOf( "<b>To Do:</b>" ) != -1 );
600     }
601 
602     /**
603      * Method to test the jdk5 javadoc
604      *
605      * @throws Exception if any
606      */
607     public void testJdk5()
608         throws Exception
609     {
610         if ( !SystemUtils.isJavaVersionAtLeast( 1.5f ) )
611         {
612             getContainer().getLogger().warn(
613                                              "JDK 5.0 or more is required to run javadoc for "
614                                                  + "'org.apache.maven.plugin.javadoc.JavadocReportTest#testJdk5()'." );
615             return;
616         }
617 
618         File testPom = new File( getBasedir(), "src/test/resources/unit/jdk5-test/jdk5-test-plugin-config.xml" );
619         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
620         mojo.execute();
621 
622         File index = new File( getBasedir(), "target/test/unit/jdk5-test/target/site/apidocs/index.html" );
623         assertTrue( FileUtils.fileExists( index.getAbsolutePath() ) );
624 
625         File overviewSummary = new File( getBasedir(),
626                                          "target/test/unit/jdk5-test/target/site/apidocs/overview-summary.html" );
627         assertTrue( FileUtils.fileExists( overviewSummary.getAbsolutePath() ) );
628         String readed = readFile( overviewSummary );
629         assertTrue( readed.indexOf( "<b>Test the package-info</b>" ) != -1 );
630 
631         File packageSummary = new File( getBasedir(),
632                                         "target/test/unit/jdk5-test/target/site/apidocs/jdk5/test/package-summary.html" );
633         assertTrue( FileUtils.fileExists( packageSummary.getAbsolutePath() ) );
634         readed = readFile( packageSummary );
635         assertTrue( readed.indexOf( "<b>Test the package-info</b>" ) != -1 );
636     }
637 
638     /**
639      * Test to find the javadoc executable when <code>java.home</code> is not in the JDK_HOME. In this case, try to
640      * use the <code>JAVA_HOME</code> environment variable.
641      *
642      * @throws Exception if any
643      */
644     public void testToFindJavadoc()
645         throws Exception
646     {
647         String oldJreHome = System.getProperty( "java.home" );
648         System.setProperty( "java.home", "foo/bar" );
649 
650         File testPom = new File( getBasedir(), "src/test/resources/unit/javaHome-test/javaHome-test-plugin-config.xml" );
651         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
652         mojo.execute();
653 
654         System.setProperty( "java.home", oldJreHome );
655     }
656 
657     /**
658      * Test the javadoc resources.
659      *
660      * @throws Exception if any
661      */
662     public void testJavadocResources()
663         throws Exception
664     {
665         File testPom = new File( getBasedir(),
666                                  "src/test/resources/unit/resources-test/resources-test-plugin-config.xml" );
667         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
668         mojo.execute();
669 
670         File app = new File( getBasedir(),
671                              "target/test/unit/resources-test/target/site/apidocs/resources/test/App.html" );
672         assertTrue( FileUtils.fileExists( app.getAbsolutePath() ) );
673         String readed = readFile( app );
674         assertTrue( readed.indexOf( "<img src=\"doc-files/maven-feather.png\" alt=\"Maven\"/>" ) != -1 );
675         File feather = new File( getBasedir(),
676                                  "target/test/unit/resources-test/target/site/apidocs/resources/test/doc-files/maven-feather.png" );
677         assertTrue( FileUtils.fileExists( feather.getAbsolutePath() ) );
678 
679         File app2 = new File( getBasedir(),
680                               "target/test/unit/resources-test/target/site/apidocs/resources/test2/App2.html" );
681         assertTrue( FileUtils.fileExists( app2.getAbsolutePath() ) );
682         readed = readFile( app2 );
683         assertTrue( readed.indexOf( "<img src=\"doc-files/maven-feather.png\" alt=\"Maven\"/>" ) != -1 );
684         File feather2 = new File( getBasedir(),
685                                   "target/test/unit/resources-test/target/site/apidocs/resources/test2/doc-files/maven-feather.png" );
686         assertFalse( FileUtils.fileExists( feather2.getAbsolutePath() ) );
687 
688         // with excludes
689         testPom = new File( getBasedir(),
690                                  "src/test/resources/unit/resources-with-excludes-test/resources-with-excludes-test-plugin-config.xml" );
691         mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
692         mojo.execute();
693 
694         app = new File( getBasedir(),
695                              "target/test/unit/resources-with-excludes-test/target/site/apidocs/resources/test/App.html" );
696         assertTrue( FileUtils.fileExists( app.getAbsolutePath() ) );
697         readed = readFile( app );
698         assertTrue( readed.indexOf( "<img src=\"doc-files/maven-feather.png\" alt=\"Maven\"/>" ) != -1 );
699         feather = new File( getBasedir(),
700                                  "target/test/unit/resources-with-excludes-test/target/site/apidocs/resources/test/doc-files/maven-feather.png" );
701         assertFalse( FileUtils.fileExists( feather.getAbsolutePath() ) );
702 
703         app2 = new File( getBasedir(),
704                               "target/test/unit/resources-with-excludes-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         feather2 = new File( getBasedir(),
709                                   "target/test/unit/resources-with-excludes-test/target/site/apidocs/resources/test2/doc-files/maven-feather.png" );
710         assertTrue( FileUtils.fileExists( feather2.getAbsolutePath() ) );
711     }
712 
713     /**
714      * Test the javadoc resources in the aggregation case.
715      *
716      * @throws Exception if any
717      */
718     public void testAggregateJavadocResources()
719         throws Exception
720     {
721         File testPom = new File( getBasedir(),
722                                  "src/test/resources/unit/aggregate-resources-test/aggregate-resources-test-plugin-config.xml" );
723         JavadocReport mojo = (JavadocReport) lookupMojo( "aggregate", testPom );
724         mojo.execute();
725 
726         // Test overview
727         File overviewSummary = new File( getBasedir(),
728                                          "target/test/unit/aggregate-resources-test/target/site/apidocs/overview-summary.html" );
729         assertTrue( FileUtils.fileExists( overviewSummary.getAbsolutePath() ) );
730         String readed = readFile( overviewSummary );
731         assertTrue( readed.indexOf( "<TR BGCOLOR=\"white\" CLASS=\"TableRowColor\">" + LINE_SEPARATOR
732             + "<TD WIDTH=\"20%\"><B><A HREF=\"resources/test/package-summary.html\">resources.test</A></B></TD>"
733             + LINE_SEPARATOR + "<TD>blabla</TD>" + LINE_SEPARATOR + "</TR>" ) != -1 );
734         assertTrue( readed.indexOf( "<TR BGCOLOR=\"white\" CLASS=\"TableRowColor\">" + LINE_SEPARATOR
735             + "<TD WIDTH=\"20%\"><B><A HREF=\"resources/test2/package-summary.html\">resources.test2</A></B></TD>"
736             + LINE_SEPARATOR + "<TD>&nbsp;</TD>" + LINE_SEPARATOR + "</TR>" ) != -1 );
737         assertTrue( readed.indexOf( "<TR BGCOLOR=\"white\" CLASS=\"TableRowColor\">" + LINE_SEPARATOR
738             + "<TD WIDTH=\"20%\"><B><A HREF=\"resources2/test/package-summary.html\">resources2.test</A></B></TD>"
739             + LINE_SEPARATOR + "<TD>blabla</TD>" + LINE_SEPARATOR + "</TR>" ) != -1 );
740         assertTrue( readed.indexOf( "<TR BGCOLOR=\"white\" CLASS=\"TableRowColor\">" + LINE_SEPARATOR
741             + "<TD WIDTH=\"20%\"><B><A HREF=\"resources2/test2/package-summary.html\">resources2.test2</A></B></TD>"
742             + LINE_SEPARATOR + "<TD>&nbsp;</TD>" + LINE_SEPARATOR + "</TR>" ) != -1 );
743 
744         // Test doc-files
745         File app = new File( getBasedir(),
746                              "target/test/unit/aggregate-resources-test/target/site/apidocs/resources/test/App.html" );
747         assertTrue( FileUtils.fileExists( app.getAbsolutePath() ) );
748         readed = readFile( app );
749         assertTrue( readed.indexOf( "<img src=\"doc-files/maven-feather.png\" alt=\"Maven\"/>" ) != -1 );
750         File feather = new File( getBasedir(),
751                                  "target/test/unit/aggregate-resources-test/target/site/apidocs/resources/test/doc-files/maven-feather.png" );
752         assertTrue( FileUtils.fileExists( feather.getAbsolutePath() ) );
753     }
754 
755     /**
756      * Test the javadoc for a POM project.
757      *
758      * @throws Exception if any
759      */
760     public void testPom()
761         throws Exception
762     {
763         File testPom = new File( getBasedir(), "src/test/resources/unit/pom-test/pom-test-plugin-config.xml" );
764         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
765         mojo.execute();
766 
767         assertFalse( new File( getBasedir(), "target/test/unit/pom-test" ).exists() );
768     }
769 
770     /**
771      * Test the javadoc with tag.
772      *
773      * @throws Exception if any
774      */
775     public void testTag()
776         throws Exception
777     {
778         File testPom = new File( getBasedir(), "src/test/resources/unit/tag-test/tag-test-plugin-config.xml" );
779         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
780         mojo.execute();
781 
782         File app = new File( getBasedir(), "target/test/unit/tag-test/target/site/apidocs/tag/test/App.html" );
783         assertTrue( FileUtils.fileExists( app.getAbsolutePath() ) );
784         String readed = readFile( app );
785         assertTrue( readed.indexOf( "<B>To do something:</B>" ) != -1 );
786         assertTrue( readed.indexOf( "<B>Generator Class:</B>" ) != -1 );
787         assertTrue( readed.indexOf( "<B>Version:</B>" ) != -1 );
788         assertTrue( readed.indexOf( "<DT><B>Version:</B></DT>" + LINE_SEPARATOR + "  <DD>1.0</DD>" + LINE_SEPARATOR
789             + "</DL>" ) != -1 );
790     }
791 
792     /**
793      * Test newline in the header/footer parameter
794      *
795      * @throws Exception if any
796      */
797     public void testHeaderFooter()
798         throws Exception
799     {
800         File testPom = new File( getBasedir(), "src/test/resources/unit/header-footer-test/header-footer-test-plugin-config.xml" );
801         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
802         try
803         {
804             mojo.execute();
805         }
806         catch ( MojoExecutionException e )
807         {
808             assertTrue( "Doesnt handle correctly newline for header or footer parameter", false );
809         }
810 
811         assertTrue( true );
812     }
813 
814     /**
815      * Test newline in various string parameters
816      *
817      * @throws Exception if any
818      */
819     public void testNewline()
820         throws Exception
821     {
822         File testPom = new File( getBasedir(), "src/test/resources/unit/newline-test/newline-test-plugin-config.xml" );
823         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
824         try
825         {
826             mojo.execute();
827         }
828         catch ( MojoExecutionException e )
829         {
830             fail( "Doesn't handle correctly newline for string parameters. See options and packages files." );
831         }
832 
833         assertTrue( true );
834     }
835 
836     /**
837      * Method to test the jdk6 javadoc
838      *
839      * @throws Exception if any
840      */
841     public void testJdk6()
842         throws Exception
843     {
844         if ( !SystemUtils.isJavaVersionAtLeast( 1.6f ) )
845         {
846             getContainer().getLogger().warn(
847                                              "JDK 6.0 or more is required to run javadoc for "
848                                                  + "'org.apache.maven.plugin.javadoc.JavadocReportTest#testJdk6()'." );
849             return;
850         }
851 
852         File testPom = new File( getBasedir(), "src/test/resources/unit/jdk6-test/jdk6-test-plugin-config.xml" );
853         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
854         mojo.execute();
855 
856         File index = new File( getBasedir(), "target/test/unit/jdk6-test/target/site/apidocs/index.html" );
857         assertTrue( FileUtils.fileExists( index.getAbsolutePath() ) );
858 
859         File overviewSummary = new File( getBasedir(),
860                                          "target/test/unit/jdk6-test/target/site/apidocs/overview-summary.html" );
861         assertTrue( FileUtils.fileExists( overviewSummary.getAbsolutePath() ) );
862         String readed = readFile( overviewSummary );
863         assertTrue( readed.indexOf( "Top - Copyright &#169; All rights reserved." ) != -1 );
864         assertTrue( readed.indexOf( "Header - Copyright &#169; All rights reserved." ) != -1 );
865         assertTrue( readed.indexOf( "Footer - Copyright &#169; All rights reserved." ) != -1 );
866 
867         File packageSummary = new File( getBasedir(),
868                                         "target/test/unit/jdk6-test/target/site/apidocs/jdk6/test/package-summary.html" );
869         assertTrue( FileUtils.fileExists( packageSummary.getAbsolutePath() ) );
870         readed = readFile( packageSummary );
871         assertTrue( readed.indexOf( "Top - Copyright &#169; All rights reserved." ) != -1 );
872         assertTrue( readed.indexOf( "Header - Copyright &#169; All rights reserved." ) != -1 );
873         assertTrue( readed.indexOf( "Footer - Copyright &#169; All rights reserved." ) != -1 );
874     }
875 
876     /**
877      * Method to test proxy support in the javadoc
878      *
879      * @throws Exception if any
880      */
881     public void testProxy()
882         throws Exception
883     {
884         File testPom = new File( getBasedir(), "src/test/resources/unit/proxy-test/proxy-test-plugin-config.xml" );
885         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
886         mojo.execute();
887 
888         File commandLine = new File( getBasedir(), "target/test/unit/proxy-test/target/site/apidocs/javadoc." + ( SystemUtils.IS_OS_WINDOWS ? "bat" : "sh" ) );
889         assertTrue( FileUtils.fileExists( commandLine.getAbsolutePath() ) );
890         String readed = readFile( commandLine );
891         assertTrue( readed.indexOf( "-J-Dhttp.proxySet=true" ) != -1 );
892         assertTrue( readed.indexOf( "-J-Dhttp.proxyHost=http://localhost" ) != -1 );
893         assertTrue( readed.indexOf( "-J-Dhttp.proxyPort=80" ) != -1 );
894         assertTrue( readed.indexOf( "-J-Dhttp.proxyUser=\\\"toto\\\"" ) != -1 );
895         assertTrue( readed.indexOf( "-J-Dhttp.proxyPassword=\\\"toto\\\"" ) != -1 );
896         assertTrue( readed.indexOf( "-J-Dhttp.nonProxyHosts=\\\"www.google.com|*.somewhere.com\\\"" ) != -1 );
897     }
898 
899     /**
900      * Method to test error or conflict in Javadoc options and in standard doclet options.
901      *
902      * @throws Exception if any
903      */
904     public void testValidateOptions()
905         throws Exception
906     {
907         File testPom = new File( getBasedir(),
908                                  "src/test/resources/unit/validate-options-test/wrong-encoding-test-plugin-config.xml" );
909         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
910         try
911         {
912             mojo.execute();
913             assertTrue( "Not wrong encoding catch", false );
914         }
915         catch ( MojoExecutionException e )
916         {
917             assertTrue( "Not wrong encoding catch", e.getMessage().indexOf( "Encoding not supported" ) != -1 );
918         }
919 
920         testPom = new File( getBasedir(),
921                             "src/test/resources/unit/validate-options-test/conflict-options-test-plugin-config.xml" );
922         mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
923         try
924         {
925             mojo.execute();
926             assertTrue( "Not conflict catch", false );
927         }
928         catch ( MojoExecutionException e )
929         {
930             assertTrue( "Not conflict catch", e.getMessage().indexOf( "Option <nohelp/> conflicts with <helpfile/>" ) != -1 );
931         }
932     }
933 
934     /**
935      * Method to test the <code>&lt;tagletArtifacts/&gt;</code> parameter.
936      *
937      * @throws Exception if any
938      */
939     public void testTagletArtifacts()
940         throws Exception
941     {
942         File testPom =
943             new File( getBasedir(),
944                       "src/test/resources/unit/tagletArtifacts-test/tagletArtifacts-test-plugin-config.xml" );
945         JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
946 
947         setVariableValueToObject( mojo, "remoteRepositories", mojo.project.getRemoteArtifactRepositories() );
948 
949         mojo.execute();
950 
951         File optionsFile = new File( mojo.getOutputDirectory(), "options" );
952         assertTrue( optionsFile.exists() );
953         String options = readFile( optionsFile );
954         // count -taglet
955         assertEquals( 20, StringUtils.countMatches( options, LINE_SEPARATOR + "-taglet" + LINE_SEPARATOR ) );
956         assertTrue( options.indexOf( "org.apache.maven.tools.plugin.javadoc.MojoAggregatorTypeTaglet" ) != -1 );
957         assertTrue( options.indexOf( "org.apache.maven.tools.plugin.javadoc.MojoComponentFieldTaglet" ) != -1 );
958         assertTrue( options.indexOf( "org.apache.maven.tools.plugin.javadoc.MojoConfiguratorTypeTaglet" ) != -1 );
959         assertTrue( options.indexOf( "org.apache.maven.tools.plugin.javadoc.MojoExecuteTypeTaglet" ) != -1 );
960         assertTrue( options.indexOf( "org.apache.maven.tools.plugin.javadoc.MojoExecutionStrategyTypeTaglet" ) != -1 );
961         assertTrue( options.indexOf( "org.apache.maven.tools.plugin.javadoc.MojoGoalTypeTaglet" ) != -1 );
962         assertTrue( options.indexOf( "org.apache.maven.tools.plugin.javadoc.MojoInheritByDefaultTypeTaglet" ) != -1 );
963         assertTrue( options.indexOf( "org.apache.maven.tools.plugin.javadoc.MojoInstantiationStrategyTypeTaglet" ) != -1 );
964         assertTrue( options.indexOf( "org.apache.maven.tools.plugin.javadoc.MojoParameterFieldTaglet" ) != -1 );
965         assertTrue( options.indexOf( "org.apache.maven.tools.plugin.javadoc.MojoPhaseTypeTaglet" ) != -1 );
966         assertTrue( options.indexOf( "org.apache.maven.tools.plugin.javadoc.MojoReadOnlyFieldTaglet" ) != -1 );
967         assertTrue( options.indexOf( "org.apache.maven.tools.plugin.javadoc.MojoRequiredFieldTaglet" ) != -1 );
968         assertTrue( options.indexOf( "org.apache.maven.tools.plugin.javadoc.MojoRequiresDependencyResolutionTypeTaglet" ) != -1 );
969         assertTrue( options.indexOf( "org.apache.maven.tools.plugin.javadoc.MojoRequiresDirectInvocationTypeTaglet" ) != -1 );
970         assertTrue( options.indexOf( "org.apache.maven.tools.plugin.javadoc.MojoRequiresOnLineTypeTaglet" ) != -1 );
971         assertTrue( options.indexOf( "org.apache.maven.tools.plugin.javadoc.MojoRequiresProjectTypeTaglet" ) != -1 );
972         assertTrue( options.indexOf( "org.apache.maven.tools.plugin.javadoc.MojoRequiresReportsTypeTaglet" ) != -1 );
973         assertTrue( options.indexOf( "org.codehaus.plexus.javadoc.PlexusConfigurationTaglet" ) != -1 );
974         assertTrue( options.indexOf( "org.codehaus.plexus.javadoc.PlexusRequirementTaglet" ) != -1 );
975         assertTrue( options.indexOf( "org.codehaus.plexus.javadoc.PlexusComponentTaglet" ) != -1 );
976     }
977 }