diff --git a/changelog/src/main/org/apache/maven/changelog/ChangeLogEntry.java b/changelog/src/main/org/apache/maven/changelog/ChangeLogEntry.java
index 22631215..a8f5d60c 100644
--- a/changelog/src/main/org/apache/maven/changelog/ChangeLogEntry.java
+++ b/changelog/src/main/org/apache/maven/changelog/ChangeLogEntry.java
@@ -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 dIon Gillard
- * @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
*/
diff --git a/changelog/src/main/org/apache/maven/cvslib/CvsChangeLogParser.java b/changelog/src/main/org/apache/maven/cvslib/CvsChangeLogParser.java
index fc7ca02b..df5b2014 100644
--- a/changelog/src/main/org/apache/maven/cvslib/CvsChangeLogParser.java
+++ b/changelog/src/main/org/apache/maven/cvslib/CvsChangeLogParser.java
@@ -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 dIon Gillard
- * @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 java.util.Date 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
diff --git a/changelog/src/test-resources/cvslib/cvslog_new.txt b/changelog/src/test-resources/cvslib/cvslog_new.txt
new file mode 100644
index 00000000..4138ca19
--- /dev/null
+++ b/changelog/src/test-resources/cvslib/cvslog_new.txt
@@ -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
+=============================================================================
diff --git a/changelog/src/test/org/apache/maven/changelog/ChangeLogEntryTest.java b/changelog/src/test/org/apache/maven/changelog/ChangeLogEntryTest.java
index 9bbea245..34c45663 100644
--- a/changelog/src/test/org/apache/maven/changelog/ChangeLogEntryTest.java
+++ b/changelog/src/test/org/apache/maven/changelog/ChangeLogEntryTest.java
@@ -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
*/
diff --git a/changelog/src/test/org/apache/maven/cvslib/CvsChangeLogParserTest.java b/changelog/src/test/org/apache/maven/cvslib/CvsChangeLogParserTest.java
index 7abcc319..efa7329c 100644
--- a/changelog/src/test/org/apache/maven/cvslib/CvsChangeLogParserTest.java
+++ b/changelog/src/test/org/apache/maven/cvslib/CvsChangeLogParserTest.java
@@ -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.
diff --git a/changelog/xdocs/changes.xml b/changelog/xdocs/changes.xml
index bbd70182..65feedf3 100644
--- a/changelog/xdocs/changes.xml
+++ b/changelog/xdocs/changes.xml
@@ -26,6 +26,7 @@