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 org.apache.maven.scm.log.ScmLogger;
23  import org.apache.maven.scm.provider.synergy.util.SynergyTask;
24  import org.apache.maven.scm.provider.synergy.util.SynergyUtil;
25  import org.apache.maven.scm.util.AbstractConsumer;
26  
27  import java.text.ParseException;
28  import java.text.SimpleDateFormat;
29  import java.util.ArrayList;
30  import java.util.List;
31  import java.util.Locale;
32  import java.util.StringTokenizer;
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      /**
45       * The date format as returned by your installation of CM Synergy. Fri Dec 3
46       * 17:51:56 2004
47       */
48      private String ccmDateFormat = "EEE MMM dd HH:mm:ss yyyy";
49  
50      private String language = "en";
51  
52      private String country = "US";
53  
54      public static final String OUTPUT_FORMAT = "%displayname" + SynergyUtil.SEPARATOR + "%owner"
55          + SynergyUtil.SEPARATOR + "%completion_date" + SynergyUtil.SEPARATOR + "%task_synopsis" + SynergyUtil.SEPARATOR;
56  
57      private List<SynergyTask> entries = new ArrayList<SynergyTask>();
58  
59      /**
60       * @return the tasks
61       */
62      public List<SynergyTask> getTasks()
63      {
64          return entries;
65      }
66  
67      public SynergyGetCompletedTasksConsumer( ScmLogger logger )
68      {
69          super( logger );
70          String dateFormat = System.getProperty( "maven.scm.synergy.ccmDateFormat" );
71          if ( dateFormat != null && !dateFormat.equals( "" ) )
72          {
73              this.ccmDateFormat = dateFormat;
74          }
75          if ( logger.isDebugEnabled() )
76          {
77              logger.debug( "dateFormat = " + this.ccmDateFormat );
78          }
79          String language = System.getProperty( "maven.scm.synergy.language" );
80          if ( language != null && !language.equals( "" ) )
81          {
82              this.language = language;
83          }
84          if ( logger.isDebugEnabled() )
85          {
86              logger.debug( "language = " + this.language );
87          }
88          String country = System.getProperty( "maven.scm.synergy.country" );
89          if ( country != null && !country.equals( "" ) )
90          {
91              this.country = country;
92          }
93          if ( logger.isDebugEnabled() )
94          {
95              logger.debug( "country = " + this.country );
96          }
97      }
98  
99      /** {@inheritDoc} */
100     public void consumeLine( String line )
101     {
102         if ( getLogger().isDebugEnabled() )
103         {
104             getLogger().debug( "Consume: " + line );
105         }
106         StringTokenizer tokenizer = new StringTokenizer( line.trim(), SynergyUtil.SEPARATOR );
107         if ( tokenizer.countTokens() == 4 )
108         {
109             SynergyTask task = new SynergyTask();
110             task.setNumber( Integer.parseInt( tokenizer.nextToken() ) );
111             task.setUsername( tokenizer.nextToken() );
112             try
113             {
114                 task.setModifiedTime( new SimpleDateFormat( ccmDateFormat, new Locale( language, country ) )
115                     .parse( tokenizer.nextToken() ) );
116             }
117             catch ( ParseException e )
118             {
119                 if ( getLogger().isErrorEnabled() )
120                 {
121                     getLogger().error( "Wrong date format", e );
122                 }
123             }
124             task.setComment( tokenizer.nextToken() );
125 
126             // Add the task to the list
127             entries.add( task );
128         }
129         else
130         {
131             if ( getLogger().isErrorEnabled() )
132             {
133                 getLogger().error(
134                                    "Invalid token count in SynergyGetCompletedTasksConsumer ["
135                                        + tokenizer.countTokens() + "]" );
136             }
137 
138             if ( getLogger().isDebugEnabled() )
139             {
140                 while ( tokenizer.hasMoreElements() )
141                 {
142                     getLogger().debug( tokenizer.nextToken() );
143                 }
144             }
145         }
146 
147     }
148 }