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_PREVIOUS_REV = 5;

// FIXME formatters are not thread-safe

/** 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 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);

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
@@ -102,6 +97,10 @@ class ChangeLogParser {
for (int i = 0; i < moduleNames.length; i++) {
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) {
try {
return INPUT_DATE.parse(date);
return inputDate.parse(date);
} catch (ParseException e) {
try {
return CVS1129_INPUT_DATE.parse(date);
return cvs1129InputDate.parse(date);
} catch (ParseException e2) {
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 {
/** output format for dates written to xml file */
private static final SimpleDateFormat OUTPUT_DATE
private final SimpleDateFormat outputDate
= new SimpleDateFormat("yyyy-MM-dd");
/** output format for times written to xml file */
private static final SimpleDateFormat OUTPUT_TIME
private static SimpleDateFormat outputTime
= new SimpleDateFormat("HH:mm");
/** stateless helper for writing the XML document */
private static final DOMElementWriter DOM_WRITER = new DOMElementWriter();

static {
public ChangeLogWriter() {
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 {
Element ent = doc.createElement("entry");
DOMUtils.appendTextElement(ent, "date",
OUTPUT_DATE.format(entry.getDate()));
outputDate.format(entry.getDate()));
DOMUtils.appendTextElement(ent, "time",
OUTPUT_TIME.format(entry.getDate()));
outputTime.format(entry.getDate()));
DOMUtils.appendCDATAElement(ent, "author", entry.getAuthor());

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


Loading…
Cancel
Save