1 package org.codehaus.plexus.maven.plugin;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
43
44
45
46
47
48
49 public class PlexusComponentsReport
50 extends AbstractMavenReport
51 {
52
53
54
55
56 private File componentsXml;
57
58
59
60
61
62 private MavenProject project;
63
64
65
66
67 private SiteRenderer siteRenderer;
68
69
70
71
72 private String outputDirectory;
73
74
75
76
77
78
79 private String javaDocDestDir;
80
81
82
83
84
85
86 private String jxrDestDir;
87
88
89
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 }