View Javadoc
1   package org.codehaus.plexus.maven.plugin;
2   
3   /*
4    * The MIT License
5    *
6    * Copyright (c) 2006, The Codehaus
7    *
8    * Permission is hereby granted, free of charge, to any person obtaining a copy of
9    * this software and associated documentation files (the "Software"), to deal in
10   * the Software without restriction, including without limitation the rights to
11   * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12   * of the Software, and to permit persons to whom the Software is furnished to do
13   * so, subject to the following conditions:
14   *
15   * The above copyright notice and this permission notice shall be included in all
16   * copies or substantial portions of the Software.
17   *
18   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24   * SOFTWARE.
25   */
26  
27  import java.io.File;
28  import java.io.IOException;
29  import java.util.Locale;
30  
31  import org.apache.maven.project.MavenProject;
32  import org.apache.maven.reporting.AbstractMavenReport;
33  import org.apache.maven.reporting.MavenReportException;
34  import org.codehaus.doxia.sink.Sink;
35  import org.codehaus.doxia.site.renderer.SiteRenderer;
36  import org.codehaus.plexus.maven.plugin.report.ComponentSet;
37  import org.jdom.Document;
38  import org.jdom.JDOMException;
39  import org.jdom.input.SAXBuilder;
40  
41  /**
42   * @goal components-report
43   *
44   * @execute phase="process-resources" lifecycle="plexus-site"
45   *
46   * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
47   * @version $Id$
48   */
49  public class PlexusComponentsReport
50      extends AbstractMavenReport
51  {
52      /**
53       * @parameter default-value="${project.build.outputDirectory}/META-INF/plexus/components.xml"
54       * @required
55       */
56      private File componentsXml;
57  
58      /**
59       * @parameter expression="${project}"
60       * @readonly
61       */
62      private MavenProject project;
63  
64      /**
65       * @component org.codehaus.doxia.site.renderer.SiteRenderer
66       */
67      private SiteRenderer siteRenderer;
68  
69      /**
70       * @parameter expression="${project.reporting.outputDirectory}
71       */
72      private String outputDirectory;
73  
74      /**
75       * Location of javadoc report
76       * 
77       * @parameter expression="${javaDocDestDir}" default-value="apidocs"
78       */
79      private String javaDocDestDir;
80  
81      /**
82       * Location of xref report
83       * 
84       * @parameter expression="${jxrDestDir}" default-value="xref"
85       */
86      private String jxrDestDir;
87  
88      // ----------------------------------------------------------------------
89      // MavenReport Implementation
90      // ----------------------------------------------------------------------
91  
92      public String getOutputName()
93      {
94          return "plexus/plexus-components";
95      }
96  
97      public String getName( Locale locale )
98      {
99          return "Plexus Components";
100     }
101 
102     public String getCategoryName()
103     {
104         return CATEGORY_PROJECT_REPORTS;
105     }
106 
107     public String getDescription( Locale locale )
108     {
109         return "Plexus components report description";
110     }
111 
112     protected MavenProject getProject()
113     {
114         return project;
115     }
116 
117     protected SiteRenderer getSiteRenderer()
118     {
119         return siteRenderer;
120     }
121 
122     protected String getOutputDirectory()
123     {
124         return outputDirectory;
125     }
126 
127     public boolean canGenerateReport()
128     {
129         return componentsXml.isFile();
130     }
131 
132     protected void executeReport( Locale locale )
133         throws MavenReportException
134     {
135         String title = "Plexus Components Report";
136 
137         Sink sink = getSink();
138 
139         sink.head();
140         sink.title();
141         sink.text( title );
142         sink.title_();
143         sink.head_();
144 
145         sink.body();
146 
147         sink.section1();
148         sink.sectionTitle1();
149         sink.text( title );
150         sink.sectionTitle1_();
151 
152         Document document;
153 
154         try
155         {
156             document = new SAXBuilder().build( componentsXml );
157         }
158         catch ( JDOMException e )
159         {
160             throw new MavenReportException(
161                                             "Error while building document of " + componentsXml.getAbsolutePath() + ".",
162                                             e );
163         }
164         catch ( IOException e )
165         {
166             throw new MavenReportException(
167                                             "Error while building document of " + componentsXml.getAbsolutePath() + ".",
168                                             e );
169         }
170 
171         if ( document.getRootElement().getName().equals( "component-set" ) )
172         {
173             ComponentSet componentSet = new ComponentSet( document.getRootElement() );
174 
175             componentSet.print( sink, javaDocDestDir, jxrDestDir );
176         }
177 
178         sink.body_();
179         sink.flush();
180     }
181 }