felipeal 2004/11/19 17:55:46
Modified: changelog/src/main/org/apache/maven/changelog
ChangeLogEntry.java
changelog/src/main/org/apache/maven/cvslib
CvsChangeLogParser.java
changelog/src/test/org/apache/maven/changelog
ChangeLogEntryTest.java
changelog/src/test/org/apache/maven/cvslib
CvsChangeLogParserTest.java
changelog/xdocs changes.xml
Added: changelog/src/test-resources/cvslib cvslog_new.txt
Log:
fixed MPCHANGELOG-48: plugin now handles CVS 1.12 date format
Revision Changes Path
1.5 +2 -40
maven-plugins/changelog/src/main/org/apache/maven/changelog/ChangeLogEntry.java
Index: ChangeLogEntry.java
===================================================================
RCS file:
/home/cvs/maven-plugins/changelog/src/main/org/apache/maven/changelog/ChangeLogEntry.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ChangeLogEntry.java 2 Mar 2004 15:00:17 -0000 1.4
+++ ChangeLogEntry.java 20 Nov 2004 01:55:46 -0000 1.5
@@ -17,7 +17,6 @@
* ====================================================================
*/
-import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Enumeration;
@@ -70,12 +69,7 @@
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;
@@ -89,20 +83,6 @@
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
*/
public ChangeLogEntry()
@@ -231,24 +211,6 @@
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
*/
1.4 +54 -10
maven-plugins/changelog/src/main/org/apache/maven/cvslib/CvsChangeLogParser.java
Index: CvsChangeLogParser.java
===================================================================
RCS file:
/home/cvs/maven-plugins/changelog/src/main/org/apache/maven/cvslib/CvsChangeLogParser.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- CvsChangeLogParser.java 8 Jul 2004 08:36:51 -0000 1.3
+++ CvsChangeLogParser.java 20 Nov 2004 01:55:46 -0000 1.4
@@ -21,9 +21,11 @@
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;
@@ -41,6 +43,19 @@
*/
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,18 +238,47 @@
{
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;
}
/**
1.3 +10 -16
maven-plugins/changelog/src/test/org/apache/maven/changelog/ChangeLogEntryTest.java
Index: ChangeLogEntryTest.java
===================================================================
RCS file:
/home/cvs/maven-plugins/changelog/src/test/org/apache/maven/changelog/ChangeLogEntryTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ChangeLogEntryTest.java 2 Mar 2004 15:00:19 -0000 1.2
+++ ChangeLogEntryTest.java 20 Nov 2004 01:55:46 -0000 1.3
@@ -36,6 +36,9 @@
/** the [EMAIL PROTECTED] ChangeLogEntry} used for testing */
private ChangeLogEntry instance;
+ /** the [EMAIL PROTECTED] 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 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);
}
/**
@@ -190,20 +198,6 @@
instance.setDate(date);
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
1.3 +23 -3
maven-plugins/changelog/src/test/org/apache/maven/cvslib/CvsChangeLogParserTest.java
Index: CvsChangeLogParserTest.java
===================================================================
RCS file:
/home/cvs/maven-plugins/changelog/src/test/org/apache/maven/cvslib/CvsChangeLogParserTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- CvsChangeLogParserTest.java 2 Mar 2004 15:00:19 -0000 1.2
+++ CvsChangeLogParserTest.java 20 Nov 2004 01:55:46 -0000 1.3
@@ -37,6 +37,8 @@
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 @@
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 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 @@
assertTrue("ChangeLogEntry erroneously picked up",
entry.toString().indexOf("ChangeLogEntry.java") == -1);
}
-
}
// Add test methods here, they have to start with 'test' name.
1.1
maven-plugins/changelog/src/test-resources/cvslib/cvslog_new.txt
Index: cvslog_new.txt
===================================================================
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
=============================================================================
1.45 +1 -0 maven-plugins/changelog/xdocs/changes.xml
Index: changes.xml
===================================================================
RCS file: /home/cvs/maven-plugins/changelog/xdocs/changes.xml,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -r1.44 -r1.45
--- changes.xml 14 Oct 2004 15:01:44 -0000 1.44
+++ changes.xml 20 Nov 2004 01:55:46 -0000 1.45
@@ -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>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]