View Javadoc
1   package org.apache.maven.scm.provider.synergy.consumer;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   * http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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   * Mainly inspired from CruiseControl
36   *
37   * @author <a href="julien.henry@capgemini.com">Julien Henry</a>
38   *
39   */
40  public class SynergyGetCompletedTasksConsumer
41      extends AbstractConsumer
42  {
43      /**
44       * Name of the System property to set the ccmDateFormat
45       */
46      static final String CCMDATEFORMAT_PROPERTY = "maven.scm.synergy.ccmDateFormat";
47  
48      /**
49       * Name of the System property to set the language
50       */
51      static final String LANGUAGE_PROPERTY = "maven.scm.synergy.language";
52  
53      /**
54       * Name of the System property to set the country
55       */
56      static final String COUNTRY_PROPERTY = "maven.scm.synergy.country";
57  
58      /**
59       * The date format as returned by your installation of CM Synergy. Fri Dec 3
60       * 17:51:56 2004
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       * @return the tasks
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     /** {@inheritDoc} */
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             // Add the task to the list
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 }