1 package net.sf.statscm;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import java.io.File;
20 import java.util.Locale;
21
22 import net.sf.statcvs.output.ConfigurationException;
23 import net.sf.statcvs.output.ConfigurationOptions;
24
25 import org.apache.maven.model.Build;
26 import org.apache.maven.model.Developer;
27 import org.apache.maven.project.MavenProject;
28 import org.jfree.util.Log;
29
30
31
32
33
34
35
36
37 public class StatConf extends ConfigurationOptions
38 {
39
40
41
42
43 protected static final String STATSCM_DIR_NAME = "statscm";
44
45
46
47
48 protected static final String CONNECTION_TYPE_SVN = "svn";
49
50
51
52
53 protected static final String CONNECTION_TYPE_CVS = "cvs";
54
55
56
57
58
59 protected String FILE_SEPARATOR = System.getProperty( "file.separator" );
60
61
62
63
64 private String connectionType;
65
66
67
68
69
70 private Locale locale = Locale.US;
71
72
73
74
75 StatConf()
76 {
77 }
78
79 public static void setConfigFile(String configFile) {
80 try {
81 ConfigurationOptions.setConfigFile(configFile);
82 } catch (ConfigurationException e) {
83 Log.error("Error reading Configuration File.", e);
84 }
85 }
86
87
88
89
90 private File baseDirectory = new File( "." );
91
92
93
94
95
96
97
98
99
100 public void configure( MavenProject project, Locale locale ) throws ConfigurationException
101 {
102 this.locale = locale;
103
104 if ( project.getBasedir() != null )
105 {
106 baseDirectory = project.getBasedir();
107 }
108
109 if ( project.getScm() == null )
110 {
111 throw new ConfigurationException( "There must be scm section in your pom.xml file." );
112 }
113
114
115 setOutputFormat( "xdoc" );
116
117
118 String buildBaseDirectory = null;
119 Build build = project.getBuild();
120 if ( build != null )
121 {
122 buildBaseDirectory = build.getDirectory();
123 }
124 if ( buildBaseDirectory == null )
125 {
126 buildBaseDirectory = baseDirectory.getAbsolutePath() + FILE_SEPARATOR + "target";
127 }
128 setOutputDir( buildBaseDirectory + FILE_SEPARATOR + "generated-site"
129 + FILE_SEPARATOR + "xdoc" + FILE_SEPARATOR + STATSCM_DIR_NAME );
130
131
132 connectionType = null;
133 if ( project.getScm().getConnection() != null )
134 {
135 connectionType = extractConnectionType( project.getScm().getConnection() );
136 }
137 if ( connectionType == null )
138 {
139 connectionType = extractConnectionType( project.getScm().getDeveloperConnection() );
140 }
141 if ( connectionType == null )
142 {
143 throw new ConfigurationException( "There must be scm connection url section in your pom.xml file for a supported SCM type." );
144 }
145
146
147
148 if ( project.getScm().getUrl() != null )
149 {
150 if ( project.getScm().getUrl().toLowerCase( Locale.getDefault() ).indexOf( "viewvc" ) > -1 )
151 {
152 setViewVcURL( project.getScm().getUrl() );
153 }
154 else if ( project.getScm().getUrl().toLowerCase( Locale.getDefault() ).indexOf( "viewcvs" ) > -1 )
155 {
156 setViewCvsURL("");
157 }
158 else if ( project.getScm().getUrl().toLowerCase( Locale.getDefault() ).indexOf( "jcvs" ) > -1 )
159 {
160 setJCVSWebURL("");
161 }
162 else if ( project.getScm().getUrl().toLowerCase( Locale.getDefault() ).indexOf( "chora" ) > -1 )
163 {
164 setChoraURL("");
165 }
166 }
167
168
169 if ( project.getIssueManagement() != null
170 && project.getIssueManagement().getSystem() != null )
171 {
172 String bugSystem = project.getIssueManagement().getSystem().toLowerCase( Locale.getDefault() );
173 if ( "bugzilla".equals( bugSystem ) )
174 {
175 setBugzillaUrl( project.getIssueManagement().getUrl() );
176 }
177 else if ( "mantis".equals( bugSystem ) )
178 {
179 setMantisUrl( project.getIssueManagement().getUrl() );
180 }
181 else if ( "trac".equals( bugSystem ))
182 {
183
184
185
186
187
188
189
190 }
191 }
192
193
194 if ( project.getName() != null )
195 {
196 setProjectName( project.getName() );
197 }
198
199
200 if (project.getDevelopers() != null) {
201 java.util.List developers = project.getDevelopers();
202 for ( java.util.Iterator i = developers.iterator(); i.hasNext(); )
203 {
204 Developer developer = (Developer) i.next();
205 if (developer.getName() != null)
206 {
207 getConfigProperties().setProperty("user." + developer.getId() + ".realName", developer.getName());
208 }
209 if (developer.getUrl() != null)
210 {
211 getConfigProperties().setProperty("user." + developer.getId() + ".url", developer.getUrl() );
212 }
213 if (developer.getEmail() != null)
214 {
215 getConfigProperties().setProperty("user." + developer.getId() + ".email", developer.getEmail());
216 }
217 }
218 }
219
220
221 }
222
223
224
225
226
227
228 protected String getConnectionType()
229 {
230 return connectionType;
231 }
232
233
234
235
236
237
238 public boolean isStatSVN()
239 {
240 return CONNECTION_TYPE_SVN.equals( getConnectionType() );
241 }
242
243
244
245
246
247
248 public boolean isStatCVS()
249 {
250 return CONNECTION_TYPE_CVS.equals( getConnectionType() );
251 }
252
253
254
255
256
257
258
259
260 protected String extractConnectionType( String connectionUrl )
261 {
262 if ( connectionUrl == null )
263 {
264 return null;
265 }
266 else
267 {
268 String con = connectionUrl.toLowerCase( Locale.getDefault() );
269 String[] scmTypes = { CONNECTION_TYPE_SVN, CONNECTION_TYPE_CVS };
270 for ( int i = 0; i < scmTypes.length; i++ )
271 {
272 if ( con.indexOf( scmTypes[i] + ":" ) > -1 )
273 {
274 return scmTypes[i];
275 }
276 }
277 return null;
278 }
279 }
280
281
282
283
284
285
286 public String getSCMLogFileName()
287 {
288 return getOutputDir() + "scm.log";
289 }
290
291
292
293
294
295
296 public File getBaseDirectory()
297 {
298 return baseDirectory;
299 }
300
301 public Locale getLocale()
302 {
303 return locale;
304 }
305
306 public void setLocale( Locale locale )
307 {
308 this.locale = locale;
309 }
310
311 }