Coverage Report - org.apache.maven.scm.provider.hg.command.changelog.HgChangeLogConsumer
 
Classes in this File Line Coverage Branch Coverage Complexity
HgChangeLogConsumer
0 %
0/60
0 %
0/34
5,25
 
 1  
 package org.apache.maven.scm.provider.hg.command.changelog;
 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.util.ArrayList;
 23  
 import java.util.Date;
 24  
 import java.util.List;
 25  
 import java.util.Locale;
 26  
 
 27  
 import org.apache.maven.scm.ChangeFile;
 28  
 import org.apache.maven.scm.ChangeSet;
 29  
 import org.apache.maven.scm.ScmFileStatus;
 30  
 import org.apache.maven.scm.log.ScmLogger;
 31  
 import org.apache.maven.scm.provider.hg.command.HgConsumer;
 32  
 
 33  
 /**
 34  
  * @author <a href="mailto:thurner.rupert@ymono.net">thurner rupert</a>
 35  
  * @version $Id: HgChangeLogConsumer.java 1328505 2012-04-20 21:11:40Z olamy $
 36  
  */
 37  
 public class HgChangeLogConsumer
 38  
     extends HgConsumer
 39  
 {
 40  
 
 41  
     private static final String TIME_PATTERN = "EEE MMM dd HH:mm:ss yyyy Z";
 42  
 
 43  
     private static final String REVNO_TAG = "changeset: ";
 44  
 
 45  
     private static final String TAG_TAG = "tag:         ";
 46  
 
 47  
     private static final String AUTHOR_TAG = "user: ";
 48  
 
 49  
     private static final String TIME_STAMP_TOKEN = "date: ";
 50  
 
 51  
     private static final String MESSAGE_TOKEN = "description:";
 52  
 
 53  
     private static final String FILES_TOKEN = "files: ";
 54  
 
 55  0
     private String prevLine = "";
 56  
 
 57  0
     private String prevPrevLine = "";
 58  
 
 59  0
     private List<ChangeSet> logEntries = new ArrayList<ChangeSet>();
 60  
 
 61  
     private ChangeSet currentChange;
 62  
 
 63  
     private String currentRevision;
 64  
 
 65  
     @SuppressWarnings( "unused" )
 66  
     private String currentTag; // don't know what to do with this
 67  
 
 68  
     private String userDatePattern;
 69  
 
 70  
     private boolean spoolingComments;
 71  
 
 72  0
     private List<String> currentComment = null;
 73  
 
 74  
     public HgChangeLogConsumer( ScmLogger logger, String userDatePattern )
 75  
     {
 76  0
         super( logger );
 77  
 
 78  0
         this.userDatePattern = userDatePattern;
 79  0
     }
 80  
 
 81  
     public List<ChangeSet> getModifications()
 82  
     {
 83  0
         return logEntries;
 84  
     }
 85  
 
 86  
     /** {@inheritDoc} */
 87  
     public void consumeLine( String line )
 88  
     {
 89  
 
 90  
         // override default behaviour which tries to pick through things for some standard messages.  that
 91  
         // does not apply here
 92  0
         doConsume( null, line );
 93  0
     }
 94  
 
 95  
     /** {@inheritDoc} */
 96  
     public void doConsume( ScmFileStatus status, String line )
 97  
     {
 98  0
         String tmpLine = line;
 99  
         // If current status == null then this is a new entry
 100  
         // If the line == "" and previous line was "", then this is also a new entry
 101  0
         if ( ( line.equals( "" ) && ( prevLine.equals( "" ) && prevPrevLine.equals( "" ) ) ) || currentComment == null )
 102  
         {
 103  0
             if ( currentComment != null )
 104  
             {
 105  0
                 StringBuilder comment = new StringBuilder();
 106  0
                 for ( int i = 0; i < currentComment.size() - 1; i++ )
 107  
                 {
 108  0
                     comment.append( currentComment.get( i ) );
 109  0
                     if ( i + 1 < currentComment.size() - 1 )
 110  
                     {
 111  0
                         comment.append( '\n' );
 112  
                     }
 113  
                 }
 114  0
                 currentChange.setComment( comment.toString() );
 115  
 
 116  
             }
 117  
 
 118  0
             spoolingComments = false;
 119  
 
 120  
             //Init a new changeset
 121  0
             currentChange = new ChangeSet();
 122  0
             currentChange.setFiles( new ArrayList<ChangeFile>( 0 ) );
 123  0
             logEntries.add( currentChange );
 124  
 
 125  
             //Reset memeber vars
 126  0
             currentComment = new ArrayList<String>();
 127  0
             currentRevision = "";
 128  
         }
 129  
 
 130  0
         if ( spoolingComments )
 131  
         {
 132  0
             currentComment.add( line );
 133  
         }
 134  0
         else if ( line.startsWith( MESSAGE_TOKEN ) )
 135  
         {
 136  0
             spoolingComments = true;
 137  
         }
 138  0
         else if ( line.startsWith( REVNO_TAG ) )
 139  
         {
 140  0
             tmpLine = line.substring( REVNO_TAG.length() );
 141  0
             tmpLine = tmpLine.trim();
 142  0
             currentRevision = tmpLine.substring( tmpLine.indexOf( ':' ) + 1 );
 143  0
             currentChange.setRevision( currentRevision );
 144  
 
 145  
         }
 146  0
         else if ( line.startsWith( TAG_TAG ) )
 147  
         {
 148  0
             tmpLine = line.substring( TAG_TAG.length() ).trim();
 149  0
             currentTag = tmpLine;
 150  
         }
 151  0
         else if ( line.startsWith( AUTHOR_TAG ) )
 152  
         {
 153  0
             tmpLine = line.substring( AUTHOR_TAG.length() );
 154  0
             tmpLine = tmpLine.trim();
 155  0
             currentChange.setAuthor( tmpLine );
 156  
         }
 157  0
         else if ( line.startsWith( TIME_STAMP_TOKEN ) )
 158  
         {
 159  
             // TODO: FIX Date Parsing to match Mercurial or fix with template
 160  0
             tmpLine = line.substring( TIME_STAMP_TOKEN.length() ).trim();
 161  0
             Date date = parseDate( tmpLine, userDatePattern, TIME_PATTERN, Locale.ENGLISH );
 162  0
             currentChange.setDate( date );
 163  0
         }
 164  0
         else if ( line.startsWith( FILES_TOKEN ) )
 165  
         {
 166  0
             tmpLine = line.substring( FILES_TOKEN.length() ).trim();
 167  0
             String[] files = tmpLine.split( " " );
 168  0
             for ( int i = 0; i < files.length; i++ )
 169  
             {
 170  0
                 String file = files[i];
 171  0
                 ChangeFile changeFile = new ChangeFile( file, currentRevision );
 172  0
                 currentChange.addFile( changeFile );
 173  
             }
 174  0
         }
 175  0
         else if ( line.length() > 0 )
 176  
         {
 177  0
             if ( getLogger().isWarnEnabled() )
 178  
             {
 179  0
                 getLogger().warn( "Could not figure out: " + line );
 180  
             }
 181  
         }
 182  
 
 183  
         // record previous line
 184  0
         prevLine = line;
 185  0
         prevPrevLine = prevLine;
 186  0
     }
 187  
 }