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