fixed MPCHANGELOG-48: plugin now handles CVS 1.12 date format

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@116250 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
felipeal 2004-11-20 01:55:46 +00:00
parent 80207e8a6e
commit 7bb322ce54
6 changed files with 141 additions and 69 deletions

View File

@ -17,7 +17,6 @@ package org.apache.maven.changelog;
* ====================================================================
*/
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Enumeration;
@ -29,7 +28,7 @@ import java.util.Vector;
* @task add time of change to the entry
* @task investigate betwixt for toXML method
* @author <a href="mailto:dion@multitask.com.au">dIon Gillard</a>
* @version $Id: ChangeLogEntry.java,v 1.4 2004/03/02 15:00:17 evenisse Exp $
* @version $Id: ChangeLogEntry.java,v 1.5 2004/11/20 01:55:46 felipeal Exp $
*/
public class ChangeLogEntry
{
@ -70,12 +69,7 @@ public class ChangeLogEntry
private static final SimpleDateFormat TIME_FORMAT =
new SimpleDateFormat("HH:mm:ss");
/**
* Formatter used to parse CVS date/timestamp.
*/
private static final SimpleDateFormat CVS_TIMESTAMP_FORMAT =
new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
/** Date the changes were committed */
private Date date;
@ -88,20 +82,6 @@ public class ChangeLogEntry
/** ChangeLogFiles committed on the date, by the author, with comment*/
private Vector files = new Vector();
/**
* Constructor for the Entry object
*
* @param date the date of the change
* @param author who made the change
* @param comment the commit comments for the change
*/
public ChangeLogEntry(String date, String author, String comment)
{
setDate(date);
setAuthor(author);
setComment(comment);
}
/**
* Constructor used when attributes aren't available until later
*/
@ -231,24 +211,6 @@ public class ChangeLogEntry
this.date = new Date(date.getTime());
}
/**
* Setter for property date that takes a string and parses it
* @param date - a string in yyyy/MM/dd HH:mm:ss format
*/
public void setDate(String date)
{
try
{
this.date = CVS_TIMESTAMP_FORMAT.parse(date);
}
catch (ParseException e)
{
throw new IllegalArgumentException("I don't understand this date: "
+ date);
}
}
/**
* @return date in yyyy-mm-dd format
*/

View File

@ -21,9 +21,11 @@ import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeMap;
@ -37,10 +39,23 @@ import org.apache.maven.changelog.ChangeLogFile;
* A class to parse cvs log output
*
* @author <a href="mailto:dion@multitask.com.au">dIon Gillard</a>
* @version $Id: CvsChangeLogParser.java,v 1.3 2004/07/08 08:36:51 evenisse Exp $
* @version $Id: CvsChangeLogParser.java,v 1.4 2004/11/20 01:55:46 felipeal Exp $
*/
class CvsChangeLogParser implements ChangeLogParser
{
/**
* Old formatter used to parse CVS date/timestamp.
*/
private static final SimpleDateFormat OLD_CVS_TIMESTAMP_FORMAT =
new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
/**
* New formatter used to parse CVS date/timestamp.
*/
private static final SimpleDateFormat NEW_CVS_TIMESTAMP_FORMAT =
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
/**
* Custom date/time formatter. Rounds ChangeLogEntry times to the nearest
* minute.
@ -223,20 +238,49 @@ class CvsChangeLogParser implements ChangeLogParser
{
if (line.startsWith(DATE_TAG))
{
StringTokenizer tokenizer = new StringTokenizer(line, " ;");
// date: YYYY/mm/dd HH:mm:ss; author: name
tokenizer.nextToken(); // date tag
String date = tokenizer.nextToken();
String time = tokenizer.nextToken();
getCurrentLogEntry().setDate(date + " " + time);
tokenizer.nextToken(); // author tag
// assumes author can't contain spaces
String author = tokenizer.nextToken();
//date: YYYY/mm/dd HH:mm:ss; author: name
//or date: YYYY-mm-dd HH:mm:ss Z; author: name
StringTokenizer tokenizer = new StringTokenizer(line, ";");
String dateToken = tokenizer.nextToken();
String dateString =
dateToken.trim().substring("date: ".length()).trim();
getCurrentLogEntry().setDate(parseDate(dateString));
String authorToken = tokenizer.nextToken();
String author =
authorToken.trim().substring("author: ".length()).trim();
getCurrentLogEntry().setAuthor(author);
setStatus(GET_COMMENT);
}
}
/**
* Tries to parse the given String according to all known CVS timeformats.
*
* @param dateString String to parse
* @return <code>java.util.Date</code> representing the time.
* @throws IllegalArgumentException if it's not possible to parse the date.
*/
private Date parseDate(String dateString)
{
Date date;
try
{
date = OLD_CVS_TIMESTAMP_FORMAT.parse(dateString);
}
catch (ParseException e)
{
//try other format
try {
date = NEW_CVS_TIMESTAMP_FORMAT.parse(dateString);
} catch (ParseException e1) {
throw new IllegalArgumentException("I don't understand this date: "
+ dateString);
}
}
return date;
}
/**
* Process the current input line in the Get Comment state.
* @param line a line of text from the cvs log output

View File

@ -0,0 +1,51 @@
RCS file: /home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/cvslib/ChangeLogEntry.java,v
Working file: ChangeLogEntry.java
head: 1.9
branch:
locks: strict
access list:
symbolic names:
MAVEN_1_0_B3: 1.8
keyword substitution: kv
total revisions: 9; selected revisions: 1
description:
=============================================================================
RCS file: /home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/cvslib/ChangeLogFile.java,v
Working file: ChangeLogFile.java
head: 1.7
branch:
locks: strict
access list:
symbolic names:
MAVEN_1_0_B3: 1.5
keyword substitution: kv
total revisions: 7; selected revisions: 2
description:
----------------------------
revision 1.7
date: 2002-04-14 22:16:13 +0000; author: dion; state: Exp; lines: +1 -10
Removed getPreviousRev method
----------------------------
revision 1.6
date: 2002-04-14 15:04:51 +0000; author: dion; state: Exp; lines: +20 -1
- added to String for debugging
=============================================================================
RCS file: /home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/cvslib/ChangeLogParser.java,v
Working file: ChangeLogParser.java
head: 1.11
branch:
locks: strict
access list:
symbolic names:
MAVEN_1_0_B3: 1.9
keyword substitution: kv
total revisions: 11; selected revisions: 2
description:
----------------------------
revision 1.11
date: 2002-04-15 02:14:37 +0000; author: dion; state: Exp; lines: +2 -2
Fixed javadoc comment
=============================================================================

View File

@ -28,7 +28,7 @@ import junit.textui.TestRunner;
* Tests for the {@link ChangeLogEntry} class
*
* @author dion
* @version $Id: ChangeLogEntryTest.java,v 1.2 2004/03/02 15:00:19 evenisse Exp $
* @version $Id: ChangeLogEntryTest.java,v 1.3 2004/11/20 01:55:46 felipeal Exp $
*/
public class ChangeLogEntryTest extends TestCase
{
@ -36,6 +36,9 @@ public class ChangeLogEntryTest extends TestCase
/** the {@link ChangeLogEntry} used for testing */
private ChangeLogEntry instance;
/** the {@link java.util.Date} used for testing */
private Date date;
/**
* Create a test with the given name
* @param testName the name of the test
@ -68,10 +71,15 @@ public class ChangeLogEntryTest extends TestCase
*/
public void setUp()
{
Calendar cal = Calendar.getInstance();
cal.set(2002, 3, 1, 0, 0, 0);
cal.set(Calendar.MILLISECOND, 0);
this.date = cal.getTime();
instance = new ChangeLogEntry();
instance.setAuthor("dion");
instance.setComment("comment");
instance.setDate("2002/04/01 00:00:00");
instance.setDate(date);
}
/**
@ -191,20 +199,6 @@ public class ChangeLogEntryTest extends TestCase
assertEquals("Date value not set correctly", date, instance.getDate());
}
/**
* Test of setDate method with String
*/
public void testSetDateFromString()
{
instance.setDate("2002/03/04 00:00:00");
Calendar cal = Calendar.getInstance();
cal.set(2002, 2, 4, 0, 0, 0);
cal.set(Calendar.MILLISECOND, 0);
assertEquals("Date value not set correctly from a string",
cal.getTime(), instance.getDate());
}
/**
* Test of getDateFormatted method
*/

View File

@ -28,7 +28,7 @@ import org.apache.maven.changelog.ChangeLogEntry;
/**
* Test cases for {@link CvsChangeLogParser}
* @author dion
* @version $Id: CvsChangeLogParserTest.java,v 1.2 2004/03/02 15:00:19 evenisse Exp $
* @version $Id: CvsChangeLogParserTest.java,v 1.3 2004/11/20 01:55:46 felipeal Exp $
*/
public class CvsChangeLogParserTest extends TestCase
{
@ -37,6 +37,8 @@ public class CvsChangeLogParserTest extends TestCase
private CvsChangeLogParser instance;
/** file with test results to check against */
private String testFile;
/** file with test results to check against */
private String testFile2;
/**
* Create a test with the given name
@ -56,6 +58,7 @@ public class CvsChangeLogParserTest extends TestCase
String baseDir = System.getProperty("basedir");
assertNotNull("The system property basedir was not defined.", baseDir);
testFile = baseDir + "/src/test-resources/cvslib/cvslog.txt";
testFile2 = baseDir + "/src/test-resources/cvslib/cvslog_new.txt";
instance = new CvsChangeLogParser();
}
@ -65,7 +68,25 @@ public class CvsChangeLogParserTest extends TestCase
*/
public void testParse() throws Exception
{
FileInputStream fis = new FileInputStream(testFile);
parse(testFile);
}
/**
* Test of parse method
* @throws Exception when there is an unexpected problem
*/
public void testParse2() throws Exception
{
parse(testFile2);
}
/**
* Test of parse method
* @throws Exception when there is an unexpected problem
*/
public void parse(String file) throws Exception
{
FileInputStream fis = new FileInputStream(file);
Collection entries = instance.parse(fis);
assertEquals("Wrong number of entries returned", 3, entries.size());
ChangeLogEntry entry = null;
@ -75,7 +96,6 @@ public class CvsChangeLogParserTest extends TestCase
assertTrue("ChangeLogEntry erroneously picked up",
entry.toString().indexOf("ChangeLogEntry.java") == -1);
}
}
// Add test methods here, they have to start with 'test' name.

View File

@ -26,6 +26,7 @@
</properties>
<body>
<release version="1.8-SNAPSHOT" date="in CVS">
<action dev="felipeal" type="fix" issue="MPCHANGELOG-48" due-to="Erwin van der Koogh">Handles new CVS date format (introduced by cvs 1.12).</action>
<action dev="evenisse" type="fix" issue="MPCHANGELOG-45" due-to="Jim Crossley">Perforce Repository URL should include project.</action>
<action dev="dion" type="fix" issue="MPCHANGELOG-46" due-to="Juha Komulainen">Handle ViewCVS URLs with ? in them.</action>
<action dev="brett" type="update">Upgrade to Maven 1.1 libraries.</action>