1 package org.apache.maven.report.projectinfo;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.io.IOException;
24 import java.io.Reader;
25 import java.util.List;
26 import java.util.Locale;
27
28 import org.apache.maven.doxia.sink.Sink;
29 import org.apache.maven.model.Model;
30 import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
31
32 import org.codehaus.plexus.i18n.I18N;
33 import org.codehaus.plexus.util.IOUtil;
34 import org.codehaus.plexus.util.ReaderFactory;
35 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
36
37
38
39
40
41
42
43
44
45 public class ModulesReport
46 extends AbstractProjectInfoReport
47 {
48
49
50
51
52 @Override
53 public void executeReport( Locale locale )
54 {
55 new ModulesRenderer( getSink(), getProject().getModel(), getI18N( locale ), locale ).render();
56 }
57
58
59 public String getOutputName()
60 {
61 return "modules";
62 }
63
64 @Override
65 protected String getI18Nsection()
66 {
67 return "modules";
68 }
69
70 @Override
71 public boolean canGenerateReport()
72 {
73 return ( getProject().getModel().getModules() != null && !getProject().getModel().getModules().isEmpty() );
74 }
75
76
77
78
79
80
81
82
83 private class ModulesRenderer
84 extends AbstractProjectInfoRenderer
85 {
86 private Model model;
87
88 ModulesRenderer( Sink sink, Model model, I18N i18n, Locale locale )
89 {
90 super( sink, i18n, locale );
91
92 this.model = model;
93 }
94
95 @Override
96 protected String getI18Nsection()
97 {
98 return "modules";
99 }
100
101 @Override
102 public void renderBody()
103 {
104 List<String> modules = model.getModules();
105
106 startSection( getTitle() );
107
108 paragraph( getI18nString( "intro" ) );
109
110 startTable();
111
112 String name = getI18nString( "header.name" );
113 String description = getI18nString( "header.description" );
114 tableHeader( new String[] {name, description} );
115
116 for ( String module : modules )
117 {
118 Model moduleModel;
119 File f = new File( project.getBasedir(), module + "/pom.xml" );
120
121 if ( f.exists() )
122 {
123 moduleModel = readModel( f );
124
125 if ( moduleModel == null )
126 {
127 getLog().warn( "Unable to read filesystem POM for module " + module );
128
129 moduleModel = new Model();
130 moduleModel.setName( module );
131 }
132 }
133 else
134 {
135 getLog().warn( "No filesystem POM found for module " + module );
136
137 moduleModel = new Model();
138 moduleModel.setName( module );
139 }
140
141 tableRow( new String[] {linkedName( moduleModel.getName(), module ), moduleModel.getDescription()} );
142 }
143
144 endTable();
145
146 endSection();
147 }
148 }
149
150 private String linkedName( String name, String link )
151 {
152 return "{" + name + ", ./" + link + "/}";
153 }
154
155
156
157
158
159
160
161
162 private Model readModel ( File pom )
163 {
164 MavenXpp3Reader xpp3 = new MavenXpp3Reader();
165 Reader reader = null;
166
167 try
168 {
169 reader = ReaderFactory.newXmlReader( pom );
170 return xpp3.read( reader );
171 }
172 catch ( IOException io )
173 {
174 getLog().debug( io );
175 return null;
176 }
177 catch ( XmlPullParserException xe )
178 {
179 getLog().debug( xe );
180 return null;
181 }
182 finally
183 {
184 IOUtil.close( reader );
185 }
186 }
187 }