1 package org.apache.maven.scm.provider.vss.commands;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.scm.ScmException;
23 import org.apache.maven.scm.provider.vss.repository.VssScmProviderRepository;
24
25 import java.io.File;
26 import java.text.DateFormat;
27 import java.text.ParseException;
28 import java.util.Calendar;
29 import java.util.Date;
30 import java.util.GregorianCalendar;
31
32
33
34
35
36
37 public class VssParameterContext
38 {
39
40 private String vssPath = null;
41
42 private String autoResponse;
43
44 private String ssDir;
45
46 private String vssLogin;
47
48 private String comment;
49
50 private String user;
51
52 private String fromLabel;
53
54 private String toLabel;
55
56 private boolean quiet;
57
58 private boolean recursive;
59
60 private boolean writable;
61
62 private String label;
63
64 private String style;
65
66 private String version;
67
68 private String date;
69
70 private String localPath;
71
72 private String timestamp;
73
74
75
76
77 private String writableFiles = null;
78
79
80
81
82 private String fromDate = null;
83
84
85
86
87 private String toDate = null;
88
89
90
91
92 private int numDays = Integer.MIN_VALUE;
93
94
95
96
97 private boolean getLocalCopy = true;
98
99
100
101
102 private DateFormat dateFormat = DateFormat
103 .getDateInstance( DateFormat.SHORT );
104
105 private String outputFileName;
106
107 public static VssParameterContext getInstance( Object obj )
108 {
109 return new VssParameterContext( (VssScmProviderRepository) obj );
110 }
111
112 public VssParameterContext( VssScmProviderRepository repo )
113 {
114 autoResponse = System.getProperty( "maven.scm.autoResponse" );
115 this.ssDir = repo.getVssdir();
116 this.user = repo.getUser();
117
118 }
119
120
121
122
123
124
125 public String getGetLocalCopy()
126 {
127 return ( !getLocalCopy ) ? VssConstants.FLAG_NO_GET : "";
128 }
129
130
131
132
133
134
135
136
137
138
139
140 private String calcDate( String startDate, int daysToAdd )
141 throws ParseException
142 {
143 Date currentDate = new Date();
144 Calendar calendar = new GregorianCalendar();
145 currentDate = dateFormat.parse( startDate );
146 calendar.setTime( currentDate );
147 calendar.add( Calendar.DATE, daysToAdd );
148 return dateFormat.format( calendar.getTime() );
149 }
150
151
152
153
154
155
156
157
158 public String getFileTimeStamp()
159 {
160 if ( timestamp == null )
161 {
162 return "";
163 }
164 return timestamp;
165 }
166
167
168
169
170
171
172
173
174 public String getLocalpath()
175 throws ScmException
176 {
177 String lclPath = "";
178 if ( localPath != null )
179 {
180
181 File dir = new File( localPath );
182 if ( !dir.exists() )
183 {
184 boolean done = dir.mkdirs();
185 if ( !done )
186 {
187 String msg = "Directory " + localPath + " creation was not " + "successful for an unknown reason";
188 throw new ScmException( msg );
189 }
190
191 }
192 lclPath = VssConstants.FLAG_OVERRIDE_WORKING_DIR + localPath;
193 }
194 return lclPath;
195 }
196
197
198
199
200
201
202 public String getLabel()
203 {
204 String shortLabel = "";
205 if ( label != null && label.length() > 0 )
206 {
207 shortLabel = VssConstants.FLAG_LABEL + getShortLabel();
208 }
209 return shortLabel;
210 }
211
212
213
214
215
216
217
218 public String getVersionDateLabel()
219 {
220 String versionDateLabel = "";
221 if ( version != null )
222 {
223 versionDateLabel = VssConstants.FLAG_VERSION + version;
224 }
225 else if ( date != null )
226 {
227 versionDateLabel = VssConstants.FLAG_VERSION_DATE + date;
228 }
229 else
230 {
231
232
233 String shortLabel = getShortLabel();
234 if ( shortLabel != null && !shortLabel.equals( "" ) )
235 {
236 versionDateLabel = VssConstants.FLAG_VERSION_LABEL + shortLabel;
237 }
238 }
239 return versionDateLabel;
240 }
241
242
243
244
245
246
247 public String getVersion()
248 {
249 return version != null ? VssConstants.FLAG_VERSION + version : "";
250 }
251
252
253
254
255
256
257
258 private String getShortLabel()
259 {
260 String shortLabel;
261 if ( label != null && label.length() > 31 )
262 {
263 shortLabel = this.label.substring( 0, 30 );
264
265
266
267 }
268 else
269 {
270 shortLabel = label;
271 }
272 return shortLabel;
273 }
274
275
276
277
278
279
280 public String getStyle()
281 {
282 return style != null ? style : "";
283 }
284
285
286
287
288
289
290 public String getRecursive()
291 {
292 return recursive ? VssConstants.FLAG_RECURSION : "";
293 }
294
295
296
297
298
299
300 public String getWritable()
301 {
302 return writable ? VssConstants.FLAG_WRITABLE : "";
303 }
304
305
306
307
308
309
310 public String getQuiet()
311 {
312 return quiet ? VssConstants.FLAG_QUIET : "";
313 }
314
315 public String getVersionLabel()
316 {
317 if ( fromLabel == null && toLabel == null )
318 {
319 return "";
320 }
321 if ( fromLabel != null && toLabel != null )
322 {
323 if ( fromLabel.length() > 31 )
324 {
325 fromLabel = fromLabel.substring( 0, 30 );
326
327
328
329 }
330 if ( toLabel.length() > 31 )
331 {
332 toLabel = toLabel.substring( 0, 30 );
333
334
335
336 }
337 return VssConstants.FLAG_VERSION_LABEL + toLabel + VssConstants.VALUE_FROMLABEL + fromLabel;
338 }
339 else if ( fromLabel != null )
340 {
341 if ( fromLabel.length() > 31 )
342 {
343 fromLabel = fromLabel.substring( 0, 30 );
344
345
346
347 }
348 return VssConstants.FLAG_VERSION + VssConstants.VALUE_FROMLABEL + fromLabel;
349 }
350 else
351 {
352 if ( toLabel.length() > 31 )
353 {
354 toLabel = toLabel.substring( 0, 30 );
355
356
357
358 }
359 return VssConstants.FLAG_VERSION_LABEL + toLabel;
360 }
361 }
362
363
364
365
366
367
368 public String getUser()
369 {
370 return user != null ? VssConstants.FLAG_USER + user : "";
371 }
372
373
374
375
376
377
378 public String getComment()
379 {
380 return comment != null ? VssConstants.FLAG_COMMENT + comment : VssConstants.FLAG_COMMENT + "-";
381 }
382
383
384
385
386
387
388
389 public String getLogin()
390 {
391 return vssLogin != null ? ( VssConstants.FLAG_LOGIN + vssLogin ) : "";
392 }
393
394
395
396
397
398
399 public String getAutoresponse()
400 {
401 if ( autoResponse == null )
402 {
403 return VssConstants.FLAG_AUTORESPONSE_DEF;
404 }
405 else if ( autoResponse.equalsIgnoreCase( "Y" ) )
406 {
407 return VssConstants.FLAG_AUTORESPONSE_YES;
408 }
409 else if ( autoResponse.equalsIgnoreCase( "N" ) )
410 {
411 return VssConstants.FLAG_AUTORESPONSE_NO;
412 }
413 else
414 {
415 return VssConstants.FLAG_AUTORESPONSE_DEF;
416 }
417 }
418
419
420
421
422
423
424 public String getSSCommand()
425 {
426 if ( ssDir == null )
427 {
428 return VssConstants.SS_EXE;
429 }
430 return ssDir.endsWith( File.separator ) ? ssDir + VssConstants.SS_EXE : ssDir + File.separator + VssConstants.SS_EXE;
431 }
432
433 public String getVssPath()
434 {
435 return vssPath;
436 }
437
438
439
440
441
442
443
444
445 public String getVersionDate()
446 throws ScmException
447 {
448 if ( fromDate == null && toDate == null && numDays == Integer.MIN_VALUE )
449 {
450 return "";
451 }
452 if ( fromDate != null && toDate != null )
453 {
454 return VssConstants.FLAG_VERSION_DATE + toDate + VssConstants.VALUE_FROMDATE + fromDate;
455 }
456 else if ( toDate != null && numDays != Integer.MIN_VALUE )
457 {
458 try
459 {
460 return VssConstants.FLAG_VERSION_DATE + toDate + VssConstants.VALUE_FROMDATE + calcDate( toDate, numDays );
461 }
462 catch ( ParseException ex )
463 {
464 String msg = "Error parsing date: " + toDate;
465 throw new ScmException( msg );
466 }
467 }
468 else if ( fromDate != null && numDays != Integer.MIN_VALUE )
469 {
470 try
471 {
472 return VssConstants.FLAG_VERSION_DATE + calcDate( fromDate, numDays ) + VssConstants.VALUE_FROMDATE + fromDate;
473 }
474 catch ( ParseException ex )
475 {
476 String msg = "Error parsing date: " + fromDate;
477 throw new ScmException( msg );
478 }
479 }
480 else
481 {
482 return fromDate != null ? VssConstants.FLAG_VERSION + VssConstants.VALUE_FROMDATE + fromDate : VssConstants.FLAG_VERSION_DATE + toDate;
483 }
484 }
485
486
487
488
489
490
491 public String getOutput()
492 {
493 return outputFileName != null ? VssConstants.FLAG_OUTPUT + outputFileName : "";
494 }
495
496
497
498
499
500
501
502 public String getWritableFiles()
503 {
504
505 if ( writableFiles == null )
506 {
507 return "";
508 }
509 return writableFiles;
510 }
511
512 }