Browse Source

fix SimpleDateFormat cases (the instances are used single threaded)

master
Stefan Bodewig 8 years ago
parent
commit
8e56f57ab5
2 changed files with 15 additions and 16 deletions
  1. +8
    -9
      src/main/org/apache/tools/ant/taskdefs/cvslib/ChangeLogParser.java
  2. +7
    -7
      src/main/org/apache/tools/ant/taskdefs/cvslib/ChangeLogWriter.java

+ 8
- 9
src/main/org/apache/tools/ant/taskdefs/cvslib/ChangeLogParser.java View File

@@ -44,21 +44,16 @@ class ChangeLogParser {
private static final int GET_REVISION = 4; private static final int GET_REVISION = 4;
private static final int GET_PREVIOUS_REV = 5; private static final int GET_PREVIOUS_REV = 5;


// FIXME formatters are not thread-safe

/** input format for dates read in from cvs log */ /** input format for dates read in from cvs log */
private static final SimpleDateFormat INPUT_DATE
private final SimpleDateFormat inputDate
= new SimpleDateFormat("yyyy/MM/dd HH:mm:ss", Locale.US); = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss", Locale.US);
/** /**
* New formatter used to parse CVS date/timestamp. * New formatter used to parse CVS date/timestamp.
*/ */
private static final SimpleDateFormat CVS1129_INPUT_DATE =
private final SimpleDateFormat cvs1129InputDate =
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z", Locale.US); new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z", Locale.US);


static { static {
TimeZone utc = TimeZone.getTimeZone("UTC");
INPUT_DATE.setTimeZone(utc);
CVS1129_INPUT_DATE.setTimeZone(utc);
} }


//The following is data used while processing stdout of CVS command //The following is data used while processing stdout of CVS command
@@ -102,6 +97,10 @@ class ChangeLogParser {
for (int i = 0; i < moduleNames.length; i++) { for (int i = 0; i < moduleNames.length; i++) {
moduleNameLengths[i] = moduleNames[i].length(); moduleNameLengths[i] = moduleNames[i].length();
} }

TimeZone utc = TimeZone.getTimeZone("UTC");
inputDate.setTimeZone(utc);
cvs1129InputDate.setTimeZone(utc);
} }


/** /**
@@ -297,10 +296,10 @@ class ChangeLogParser {
*/ */
private Date parseDate(final String date) { private Date parseDate(final String date) {
try { try {
return INPUT_DATE.parse(date);
return inputDate.parse(date);
} catch (ParseException e) { } catch (ParseException e) {
try { try {
return CVS1129_INPUT_DATE.parse(date);
return cvs1129InputDate.parse(date);
} catch (ParseException e2) { } catch (ParseException e2) {
throw new IllegalStateException("Invalid date format: " + date); throw new IllegalStateException("Invalid date format: " + date);
} }


+ 7
- 7
src/main/org/apache/tools/ant/taskdefs/cvslib/ChangeLogWriter.java View File

@@ -34,18 +34,18 @@ import org.w3c.dom.Element;
*/ */
public class ChangeLogWriter { public class ChangeLogWriter {
/** output format for dates written to xml file */ /** output format for dates written to xml file */
private static final SimpleDateFormat OUTPUT_DATE
private final SimpleDateFormat outputDate
= new SimpleDateFormat("yyyy-MM-dd"); = new SimpleDateFormat("yyyy-MM-dd");
/** output format for times written to xml file */ /** output format for times written to xml file */
private static final SimpleDateFormat OUTPUT_TIME
private static SimpleDateFormat outputTime
= new SimpleDateFormat("HH:mm"); = new SimpleDateFormat("HH:mm");
/** stateless helper for writing the XML document */ /** stateless helper for writing the XML document */
private static final DOMElementWriter DOM_WRITER = new DOMElementWriter(); private static final DOMElementWriter DOM_WRITER = new DOMElementWriter();


static {
public ChangeLogWriter() {
TimeZone utc = TimeZone.getTimeZone("UTC"); TimeZone utc = TimeZone.getTimeZone("UTC");
OUTPUT_DATE.setTimeZone(utc);
OUTPUT_TIME.setTimeZone(utc);
outputDate.setTimeZone(utc);
outputTime.setTimeZone(utc);
} }


/** /**
@@ -87,9 +87,9 @@ public class ChangeLogWriter {
final CVSEntry entry) throws IOException { final CVSEntry entry) throws IOException {
Element ent = doc.createElement("entry"); Element ent = doc.createElement("entry");
DOMUtils.appendTextElement(ent, "date", DOMUtils.appendTextElement(ent, "date",
OUTPUT_DATE.format(entry.getDate()));
outputDate.format(entry.getDate()));
DOMUtils.appendTextElement(ent, "time", DOMUtils.appendTextElement(ent, "time",
OUTPUT_TIME.format(entry.getDate()));
outputTime.format(entry.getDate()));
DOMUtils.appendCDATAElement(ent, "author", entry.getAuthor()); DOMUtils.appendCDATAElement(ent, "author", entry.getAuthor());


final Enumeration enumeration = entry.getFiles().elements(); final Enumeration enumeration = entry.getFiles().elements();


Loading…
Cancel
Save