001package org.apache.maven.scm.provider.synergy.consumer; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import java.text.ParseException; 023import java.text.SimpleDateFormat; 024import java.util.ArrayList; 025import java.util.List; 026import java.util.Locale; 027import java.util.StringTokenizer; 028 029import org.apache.maven.scm.log.ScmLogger; 030import org.apache.maven.scm.provider.synergy.util.SynergyTask; 031import org.apache.maven.scm.provider.synergy.util.SynergyUtil; 032import org.apache.maven.scm.util.AbstractConsumer; 033 034/** 035 * Mainly inspired from CruiseControl 036 * 037 * @author <a href="julien.henry@capgemini.com">Julien Henry</a> 038 * 039 */ 040public class SynergyGetCompletedTasksConsumer 041 extends AbstractConsumer 042{ 043 /** 044 * Name of the System property to set the ccmDateFormat 045 */ 046 static final String CCMDATEFORMAT_PROPERTY = "maven.scm.synergy.ccmDateFormat"; 047 048 /** 049 * Name of the System property to set the language 050 */ 051 static final String LANGUAGE_PROPERTY = "maven.scm.synergy.language"; 052 053 /** 054 * Name of the System property to set the country 055 */ 056 static final String COUNTRY_PROPERTY = "maven.scm.synergy.country"; 057 058 /** 059 * The date format as returned by your installation of CM Synergy. Fri Dec 3 060 * 17:51:56 2004 061 */ 062 private String ccmDateFormat = "EEE MMM dd HH:mm:ss yyyy"; 063 064 private String language = "en"; 065 066 private String country = "US"; 067 068 public static final String OUTPUT_FORMAT = "%displayname" + SynergyUtil.SEPARATOR + "%owner" 069 + SynergyUtil.SEPARATOR + "%completion_date" + SynergyUtil.SEPARATOR + "%task_synopsis" + SynergyUtil.SEPARATOR; 070 071 private List<SynergyTask> entries = new ArrayList<SynergyTask>(); 072 073 /** 074 * @return the tasks 075 */ 076 public List<SynergyTask> getTasks() 077 { 078 return entries; 079 } 080 081 public SynergyGetCompletedTasksConsumer( ScmLogger logger ) 082 { 083 super( logger ); 084 String dateFormat = System.getProperty( CCMDATEFORMAT_PROPERTY ); 085 if ( dateFormat != null && !dateFormat.equals( "" ) ) 086 { 087 this.ccmDateFormat = dateFormat; 088 } 089 if ( logger.isDebugEnabled() ) 090 { 091 logger.debug( "dateFormat = " + this.ccmDateFormat ); 092 } 093 String language = System.getProperty( LANGUAGE_PROPERTY ); 094 if ( language != null && !language.equals( "" ) ) 095 { 096 this.language = language; 097 } 098 if ( logger.isDebugEnabled() ) 099 { 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}