Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 279   Methods: 10
NCLOC: 133   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ChangeLogParser.java 0% 0% 0% 0%
 1   
 /*
 2   
  * The Apache Software License, Version 1.1
 3   
  *
 4   
  * Copyright (c) 2002 The Apache Software Foundation.  All rights
 5   
  * reserved.
 6   
  *
 7   
  * Redistribution and use in source and binary forms, with or without
 8   
  * modification, are permitted provided that the following conditions
 9   
  * are met:
 10   
  *
 11   
  * 1. Redistributions of source code must retain the above copyright
 12   
  *    notice, this list of conditions and the following disclaimer.
 13   
  *
 14   
  * 2. Redistributions in binary form must reproduce the above copyright
 15   
  *    notice, this list of conditions and the following disclaimer in
 16   
  *    the documentation and/or other materials provided with the
 17   
  *    distribution.
 18   
  *
 19   
  * 3. The end-user documentation included with the redistribution, if
 20   
  *    any, must include the following acknowlegement:
 21   
  *       "This product includes software developed by the
 22   
  *        Apache Software Foundation (http://www.apache.org/)."
 23   
  *    Alternately, this acknowlegement may appear in the software itself,
 24   
  *    if and wherever such third-party acknowlegements normally appear.
 25   
  *
 26   
  * 4. The names "Ant" and "Apache Software
 27   
  *    Foundation" must not be used to endorse or promote products derived
 28   
  *    from this software without prior written permission. For written
 29   
  *    permission, please contact apache@apache.org.
 30   
  *
 31   
  * 5. Products derived from this software may not be called "Apache"
 32   
  *    nor may "Apache" appear in their names without prior written
 33   
  *    permission of the Apache Group.
 34   
  *
 35   
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 36   
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 37   
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 38   
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 39   
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 40   
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 41   
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 42   
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 43   
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 44   
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 45   
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 46   
  * SUCH DAMAGE.
 47   
  * ====================================================================
 48   
  *
 49   
  * This software consists of voluntary contributions made by many
 50   
  * individuals on behalf of the Apache Software Foundation.  For more
 51   
  * information on the Apache Software Foundation, please see
 52   
  * <http://www.apache.org/>.
 53   
  */
 54   
 package org.apache.tools.ant.taskdefs.cvslib;
 55   
 
 56   
 import java.text.ParseException;
 57   
 import java.text.SimpleDateFormat;
 58   
 import java.util.Date;
 59   
 import java.util.Enumeration;
 60   
 import java.util.Hashtable;
 61   
 import java.util.TimeZone;
 62   
 
 63   
 /**
 64   
  * A class used to parse the output of the CVS log command.
 65   
  *
 66   
  * @author <a href="mailto:peter@apache.org">Peter Donald</a>
 67   
  * @version $Revision: 1.18 $ $Date: 2003/02/10 14:13:43 $
 68   
  */
 69   
 class ChangeLogParser {
 70   
     //private static final int GET_ENTRY = 0;
 71   
     private static final int GET_FILE = 1;
 72   
     private static final int GET_DATE = 2;
 73   
     private static final int GET_COMMENT = 3;
 74   
     private static final int GET_REVISION = 4;
 75   
     private static final int GET_PREVIOUS_REV = 5;
 76   
 
 77   
     /** input format for dates read in from cvs log */
 78   
     private static final SimpleDateFormat c_inputDate
 79   
         = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
 80   
 
 81   
     static {
 82  0
         TimeZone utc = TimeZone.getTimeZone("UTC");
 83  0
         c_inputDate.setTimeZone(utc);
 84   
     }
 85   
 
 86   
     //The following is data used while processing stdout of CVS command
 87   
     private String m_file;
 88   
     private String m_date;
 89   
     private String m_author;
 90   
     private String m_comment;
 91   
     private String m_revision;
 92   
     private String m_previousRevision;
 93   
 
 94   
     private int m_status = GET_FILE;
 95   
 
 96   
     /** rcs entries */
 97   
     private final Hashtable m_entries = new Hashtable();
 98   
 
 99   
     /**
 100   
      * Get a list of rcs entrys as an array.
 101   
      *
 102   
      * @return a list of rcs entrys as an array
 103   
      */
 104  0
     CVSEntry[] getEntrySetAsArray() {
 105  0
         final CVSEntry[] array = new CVSEntry[ m_entries.size() ];
 106  0
         Enumeration enum = m_entries.elements();
 107  0
         int i = 0;
 108  0
         while (enum.hasMoreElements()) {
 109  0
             array[i++] = (CVSEntry) enum.nextElement();
 110   
         }
 111  0
         return array;
 112   
     }
 113   
 
 114   
     /**
 115   
      * Receive notification about the process writing
 116   
      * to standard output.
 117   
      */
 118  0
     public void stdout(final String line) {
 119  0
         switch(m_status) {
 120   
             case GET_FILE:
 121   
                 // make sure attributes are reset when
 122   
                 // working on a 'new' file.
 123  0
                 reset();
 124  0
                 processFile(line);
 125  0
                 break;
 126   
             case GET_REVISION:
 127  0
                 processRevision(line);
 128  0
                 break;
 129   
 
 130   
             case GET_DATE:
 131  0
                 processDate(line);
 132  0
                 break;
 133   
 
 134   
             case GET_COMMENT:
 135  0
                 processComment(line);
 136  0
                 break;
 137   
 
 138   
             case GET_PREVIOUS_REV:
 139  0
                 processGetPreviousRevision(line);
 140  0
                 break;
 141   
         }
 142   
     }
 143   
 
 144   
     /**
 145   
      * Process a line while in "GET_COMMENT" state.
 146   
      *
 147   
      * @param line the line
 148   
      */
 149  0
     private void processComment(final String line) {
 150  0
         final String lineSeparator = System.getProperty("line.separator");
 151  0
         if (line.startsWith("======")) {
 152   
             //We have ended changelog for that particular file
 153   
             //so we can save it
 154  0
             final int end
 155   
                 = m_comment.length() - lineSeparator.length(); //was -1
 156  0
             m_comment = m_comment.substring(0, end);
 157  0
             saveEntry();
 158  0
             m_status = GET_FILE;
 159  0
         } else if (line.startsWith("----------------------------")) {
 160  0
             final int end
 161   
                 = m_comment.length() - lineSeparator.length(); //was -1
 162  0
             m_comment = m_comment.substring(0, end);
 163  0
             m_status = GET_PREVIOUS_REV;
 164   
         } else {
 165  0
             m_comment += line + lineSeparator;
 166   
         }
 167   
     }
 168   
 
 169   
     /**
 170   
      * Process a line while in "GET_FILE" state.
 171   
      *
 172   
      * @param line the line
 173   
      */
 174  0
     private void processFile(final String line) {
 175  0
         if (line.startsWith("Working file:")) {
 176  0
             m_file = line.substring(14, line.length());
 177  0
             m_status = GET_REVISION;
 178   
         }
 179   
     }
 180   
 
 181   
     /**
 182   
      * Process a line while in "REVISION" state.
 183   
      *
 184   
      * @param line the line
 185   
      */
 186  0
     private void processRevision(final String line) {
 187  0
         if (line.startsWith("revision")) {
 188  0
             m_revision = line.substring(9);
 189  0
             m_status = GET_DATE;
 190  0
         } else if (line.startsWith("======")) {
 191   
             //There was no revisions in this changelog
 192   
             //entry so lets move unto next file
 193  0
             m_status = GET_FILE;
 194   
         }
 195   
     }
 196   
 
 197   
     /**
 198   
      * Process a line while in "DATE" state.
 199   
      *
 200   
      * @param line the line
 201   
      */
 202  0
     private void processDate(final String line) {
 203  0
         if (line.startsWith("date:")) {
 204  0
             m_date = line.substring(6, 25);
 205  0
             String lineData = line.substring(line.indexOf(";") + 1);
 206  0
             m_author = lineData.substring(10, lineData.indexOf(";"));
 207   
 
 208  0
             m_status = GET_COMMENT;
 209   
 
 210   
             //Reset comment to empty here as we can accumulate multiple lines
 211   
             //in the processComment method
 212  0
             m_comment = "";
 213   
         }
 214   
     }
 215   
 
 216   
     /**
 217   
      * Process a line while in "GET_PREVIOUS_REVISION" state.
 218   
      *
 219   
      * @param line the line
 220   
      */
 221  0
     private void processGetPreviousRevision(final String line) {
 222  0
         if (!line.startsWith("revision")) {
 223  0
             throw new IllegalStateException("Unexpected line from CVS: "
 224   
                 + line);
 225   
         }
 226  0
         m_previousRevision = line.substring(9);
 227   
 
 228  0
         saveEntry();
 229   
 
 230  0
         m_revision = m_previousRevision;
 231  0
         m_status = GET_DATE;
 232   
     }
 233   
 
 234   
     /**
 235   
      * Utility method that saves the current entry.
 236   
      */
 237  0
     private void saveEntry() {
 238  0
         final String entryKey = m_date + m_author + m_comment;
 239  0
         CVSEntry entry;
 240  0
         if (!m_entries.containsKey(entryKey)) {
 241  0
             entry = new CVSEntry(parseDate(m_date), m_author, m_comment);
 242  0
             m_entries.put(entryKey, entry);
 243   
         } else {
 244  0
             entry = (CVSEntry) m_entries.get(entryKey);
 245   
         }
 246   
 
 247  0
         entry.addFile(m_file, m_revision, m_previousRevision);
 248   
     }
 249   
 
 250   
     /**
 251   
      * Parse date out from expected format.
 252   
      *
 253   
      * @param date the string holding dat
 254   
      * @return the date object or null if unknown date format
 255   
      */
 256  0
     private Date parseDate(final String date) {
 257  0
         try {
 258  0
             return c_inputDate.parse(date);
 259   
         } catch (ParseException e) {
 260   
             //final String message = REZ.getString( "changelog.bat-date.error", date );
 261   
             //getContext().error( message );
 262  0
             return null;
 263   
         }
 264   
     }
 265   
     
 266   
     /**
 267   
      * reset all internal attributes except status.
 268   
      */
 269  0
     private void reset(){
 270  0
         m_file = null;
 271  0
         m_date = null;
 272  0
         m_author = null;
 273  0
         m_comment = null;
 274  0
         m_revision = null;
 275  0
         m_previousRevision = null;
 276   
     }
 277   
 
 278   
 }
 279