mbenson 2004/04/26 12:20:25
Modified: src/main/org/apache/tools/ant/types/selectors Tag:
ANT_16_BRANCH DateSelector.java
docs/manual/CoreTypes Tag: ANT_16_BRANCH selectors.html
. Tag: ANT_16_BRANCH WHATSNEW
Log:
Merge DateSelector pattern attribute to 1.6 branch.
Revision Changes Path
No revision
No revision
1.8.2.5 +43 -22
ant/src/main/org/apache/tools/ant/types/selectors/DateSelector.java
Index: DateSelector.java
===================================================================
RCS file:
/home/cvs/ant/src/main/org/apache/tools/ant/types/selectors/DateSelector.java,v
retrieving revision 1.8.2.4
retrieving revision 1.8.2.5
diff -u -r1.8.2.4 -r1.8.2.5
--- DateSelector.java 9 Mar 2004 17:01:56 -0000 1.8.2.4
+++ DateSelector.java 26 Apr 2004 19:20:24 -0000 1.8.2.5
@@ -19,6 +19,7 @@
import java.io.File;
import java.text.DateFormat;
+import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.util.Locale;
@@ -39,6 +40,7 @@
private boolean includeDirs = false;
private int granularity = 0;
private int cmp = 2;
+ private String pattern;
/** Key to used for parameterized custom selector */
public static final String MILLIS_KEY = "millis";
/** Key to used for parameterized custom selector */
@@ -49,6 +51,8 @@
public static final String GRANULARITY_KEY = "granularity";
/** Key to used for parameterized custom selector */
public static final String WHEN_KEY = "when";
+ /** Key to used for parameterized custom selector */
+ public static final String PATTERN_KEY = "pattern";
/**
* Creates a new <code>DateSelector</code> instance.
@@ -76,6 +80,9 @@
}
buf.append(" granularity: ");
buf.append(granularity);
+ if (pattern != null) {
+ buf.append(" pattern: ").append(pattern);
+ }
buf.append("}");
return buf.toString();
}
@@ -95,6 +102,9 @@
* @return the millisecond value
*/
public long getMillis() {
+ if (dateTime != null) {
+ validate();
+ }
return millis;
}
@@ -106,24 +116,6 @@
*/
public void setDatetime(String dateTime) {
this.dateTime = dateTime;
- if (dateTime != null) {
- DateFormat df = DateFormat.getDateTimeInstance(
- DateFormat.SHORT,
- DateFormat.SHORT,
- Locale.US);
- try {
- setMillis(df.parse(dateTime).getTime());
- if (millis < 0) {
- setError("Date of " + dateTime
- + " results in negative milliseconds value
relative"
- + " to epoch (January 1, 1970, 00:00:00 GMT).");
- }
- } catch (ParseException pe) {
- setError("Date of " + dateTime
- + " Cannot be parsed correctly. It should be in"
- + " MM/DD/YYYY HH:MM AM_PM format.");
- }
- }
}
/**
@@ -155,6 +147,15 @@
}
/**
+ * Sets the pattern to be used for the SimpleDateFormat
+ *
+ * @param pattern the pattern that defines the date format
+ */
+ public void setPattern(String pattern) {
+ this.pattern = pattern;
+ }
+
+ /**
* When using this as a custom selector, this method will be called.
* It translates each parameter into the appropriate setXXX() call.
*
@@ -189,6 +190,8 @@
TimeComparisons cmp = new TimeComparisons();
cmp.setValue(parameters[i].getValue());
setWhen(cmp);
+ } else if (PATTERN_KEY.equalsIgnoreCase(paramname)) {
+ setPattern(parameters[i].getValue());
} else {
setError("Invalid parameter " + paramname);
}
@@ -204,10 +207,26 @@
if (dateTime == null && millis < 0) {
setError("You must provide a datetime or the number of "
+ "milliseconds.");
- } else if (millis < 0) {
- setError("Date of " + dateTime
- + " results in negative milliseconds value"
- + " relative to epoch (January 1, 1970, 00:00:00 GMT).");
+ } else if (millis < 0 && dateTime != null) {
+ // check millis and only set it once.
+ DateFormat df = ((pattern == null)
+ ? DateFormat.getDateTimeInstance(
+ DateFormat.SHORT, DateFormat.SHORT, Locale.US)
+ : new SimpleDateFormat(pattern));
+
+ try {
+ setMillis(df.parse(dateTime).getTime());
+ if (millis < 0) {
+ setError("Date of " + dateTime
+ + " results in negative milliseconds value"
+ + " relative to epoch (January 1, 1970, 00:00:00
GMT).");
+ }
+ } catch (ParseException pe) {
+ setError("Date of " + dateTime
+ + " Cannot be parsed correctly. It should be in"
+ + ((pattern == null)
+ ? " MM/DD/YYYY HH:MM AM_PM" : pattern) + " format.");
+ }
}
}
@@ -221,7 +240,9 @@
* @return whether the file should be selected or not
*/
public boolean isSelected(File basedir, String filename, File file) {
+
validate();
+
if (file.isDirectory() && (!includeDirs)) {
return true;
}
No revision
No revision
1.15.2.6 +26 -7 ant/docs/manual/CoreTypes/selectors.html
Index: selectors.html
===================================================================
RCS file: /home/cvs/ant/docs/manual/CoreTypes/selectors.html,v
retrieving revision 1.15.2.5
retrieving revision 1.15.2.6
diff -u -r1.15.2.5 -r1.15.2.6
--- selectors.html 9 Feb 2004 22:12:10 -0000 1.15.2.5
+++ selectors.html 26 Apr 2004 19:20:24 -0000 1.15.2.6
@@ -134,8 +134,10 @@
</tr>
<tr>
<td valign="top">datetime</td>
- <td valign="top">Specifies the date and time to test for using
- a string of the format MM/DD/YYYY HH:MM AM_or_PM.
+ <td valign="top">Specifies the date and time to test for.
+ Should be in the format MM/DD/YYYY HH:MM AM_or_PM, or
+ an alternative pattern specified via the <i>pattern</i>
+ attribute.
</td>
<td valign="top" align="center" rowspan="2">At least one of the
two.</td>
</tr>
@@ -160,6 +162,23 @@
The default is equal.
<td valign="top" align="center">No</td>
</tr>
+ <tr>
+ <td valign="top">granularity</td>
+ <td valign="top">The number of milliseconds leeway to use when
+ comparing file modification times. This is needed because not every
+ file system supports tracking the last modified time to the
+ millisecond level. Default is 0 milliseconds, or 2 seconds on DOS
systems.
+ </td>
+ <td valign="top" align="center">No</td>
+ </tr>
+ <tr>
+ <td valign="top">pattern</td>
+ <td valign="top">The <CODE>SimpleDateFormat</CODE>-compatible pattern
+ to use when interpreting the <i>datetime</i> attribute.
+ <i>Since Ant 1.6.2</i>
+ </td>
+ <td valign="top" align="center">No</td>
+ </tr>
</table>
<p>Here is an example of how to use the Date Selector:</p>
@@ -675,8 +694,8 @@
the following rules: <ul>
<li> <b> algorithm </b>: same as attribute algorithm </li>
<li> <b> cache </b>: same as attribute cache </li>
- <li> <b> comparator </b>: same as attribute cache </li>
- <li> <b> update </b>: same as attribute comparator </li>
+ <li> <b> comparator </b>: same as attribute comparator </li>
+ <li> <b> update </b>: same as attribute update </li>
<li> <b> seldirs </b>: same as attribute seldirs </li>
<li> <b> algorithm.* </b>: Value is transfered to the algorithm via
its
<i>set</i>XX-methods </li>
@@ -687,7 +706,7 @@
</ul></p>
<table border="1" cellpadding="2" cellspacing="0">
- <tr><td colspan="2"><font size="+1"><b> Algorithm�s
</b></font></td></tr>
+ <tr><td colspan="2"><font size="+1"><b> Algorithm's
</b></font></td></tr>
<tr>
<td valign="top"><b>Name</b></td>
<td valign="top"><b>Description</b></td>
@@ -710,7 +729,7 @@
</ul>
</td>
</tr>
- <tr><td colspan="2"><font size="+1"><b> Cache�s </b></font></td></tr>
+ <tr><td colspan="2"><font size="+1"><b> Cache's </b></font></td></tr>
<tr>
<td valign="top"> propertyfile </td>
<td valign="top"> Use the java.util.Properties class and its
possibility
@@ -722,7 +741,7 @@
</ul>
</td>
</tr>
- <tr><td colspan="2"><font size="+1"><b> Comparator�s
</b></font></td></tr>
+ <tr><td colspan="2"><font size="+1"><b> Comparator's
</b></font></td></tr>
<tr>
<td valign="top"> equal </td>
<td valign="top"> Very simple object comparison. </td>
No revision
No revision
1.503.2.87 +2 -0 ant/WHATSNEW
Index: WHATSNEW
===================================================================
RCS file: /home/cvs/ant/WHATSNEW,v
retrieving revision 1.503.2.86
retrieving revision 1.503.2.87
diff -u -r1.503.2.86 -r1.503.2.87
--- WHATSNEW 23 Apr 2004 16:57:26 -0000 1.503.2.86
+++ WHATSNEW 26 Apr 2004 19:20:24 -0000 1.503.2.87
@@ -112,6 +112,8 @@
* New attribute "negate" on <propertyset> to invert selection criteria.
+* New "pattern" attribute for <date> selector.
+
Changes from Ant 1.6.0 to Ant 1.6.1
===================================
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]