1 package org.apache.maven.scm.provider.synergy.consumer;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.text.ParseException;
23 import java.text.SimpleDateFormat;
24 import java.util.ArrayList;
25 import java.util.List;
26 import java.util.Locale;
27 import java.util.StringTokenizer;
28
29 import org.apache.maven.scm.log.ScmLogger;
30 import org.apache.maven.scm.provider.synergy.util.SynergyTask;
31 import org.apache.maven.scm.provider.synergy.util.SynergyUtil;
32 import org.apache.maven.scm.util.AbstractConsumer;
33
34
35
36
37
38
39
40 public class SynergyGetCompletedTasksConsumer
41 extends AbstractConsumer
42 {
43
44
45
46 static final String CCMDATEFORMAT_PROPERTY = "maven.scm.synergy.ccmDateFormat";
47
48
49
50
51 static final String LANGUAGE_PROPERTY = "maven.scm.synergy.language";
52
53
54
55
56 static final String COUNTRY_PROPERTY = "maven.scm.synergy.country";
57
58
59
60
61
62 private String ccmDateFormat = "EEE MMM dd HH:mm:ss yyyy";
63
64 private String language = "en";
65
66 private String country = "US";
67
68 public static final String OUTPUT_FORMAT = "%displayname" + SynergyUtil.SEPARATOR + "%owner"
69 + SynergyUtil.SEPARATOR + "%completion_date" + SynergyUtil.SEPARATOR + "%task_synopsis" + SynergyUtil.SEPARATOR;
70
71 private List<SynergyTask> entries = new ArrayList<SynergyTask>();
72
73
74
75
76 public List<SynergyTask> getTasks()
77 {
78 return entries;
79 }
80
81 public SynergyGetCompletedTasksConsumer( ScmLogger logger )
82 {
83 super( logger );
84 String dateFormat = System.getProperty( CCMDATEFORMAT_PROPERTY );
85 if ( dateFormat != null && !dateFormat.equals( "" ) )
86 {
87 this.ccmDateFormat = dateFormat;
88 }
89 if ( logger.isDebugEnabled() )
90 {
91 logger.debug( "dateFormat = " + this.ccmDateFormat );
92 }
93 String language = System.getProperty( LANGUAGE_PROPERTY );
94 if ( language != null && !language.equals( "" ) )
95 {
96 this.language = language;
97 }
98 if ( logger.isDebugEnabled() )
99 {
100 logger.debug( "language = " + this.language );
101 }
102 String country = System.getProperty( COUNTRY_PROPERTY );
103 if ( country != null && !country.equals( "" ) )
104 {
105 this.country = country;
106 }
107 if ( logger.isDebugEnabled() )
108 {
109 logger.debug( "country = " + this.country );
110 }
111 }
112
113
114 public void consumeLine( String line )
115 {
116 if ( getLogger().isDebugEnabled() )
117 {
118 getLogger().debug( "Consume: " + line );
119 }
120 StringTokenizer tokenizer = new StringTokenizer( line.trim(), SynergyUtil.SEPARATOR );
121 if ( tokenizer.countTokens() == 4 )
122 {
123 SynergyTask task = new SynergyTask();
124 task.setNumber( Integer.parseInt( tokenizer.nextToken() ) );
125 task.setUsername( tokenizer.nextToken() );
126 try
127 {
128 task.setModifiedTime( new SimpleDateFormat( ccmDateFormat, new Locale( language, country ) )
129 .parse( tokenizer.nextToken() ) );
130 }
131 catch ( ParseException e )
132 {
133 if ( getLogger().isErrorEnabled() )
134 {
135 getLogger().error( "Wrong date format", e );
136 }
137 }
138 task.setComment( tokenizer.nextToken() );
139
140
141 entries.add( task );
142 }
143 else
144 {
145 if ( getLogger().isErrorEnabled() )
146 {
147 getLogger().error(
148 "Invalid token count in SynergyGetCompletedTasksConsumer ["
149 + tokenizer.countTokens() + "]" );
150 }
151
152 if ( getLogger().isDebugEnabled() )
153 {
154 while ( tokenizer.hasMoreElements() )
155 {
156 getLogger().debug( tokenizer.nextToken() );
157 }
158 }
159 }
160
161 }
162 }