bodewig 2002/09/25 08:30:30
Modified: . Tag: ANT_15_BRANCH WHATSNEW
src/main/org/apache/tools/ant/taskdefs Tag: ANT_15_BRANCH
Tstamp.java
src/testcases/org/apache/tools/ant/taskdefs Tag:
ANT_15_BRANCH TStampTest.java
Log:
merge tstamp prefix/format fix from HEAD
Revision Changes Path
No revision
No revision
1.263.2.79 +4 -0 jakarta-ant/WHATSNEW
Index: WHATSNEW
===================================================================
RCS file: /home/cvs/jakarta-ant/WHATSNEW,v
retrieving revision 1.263.2.78
retrieving revision 1.263.2.79
diff -u -r1.263.2.78 -r1.263.2.79
--- WHATSNEW 23 Sep 2002 10:58:16 -0000 1.263.2.78
+++ WHATSNEW 25 Sep 2002 15:30:29 -0000 1.263.2.79
@@ -1,6 +1,10 @@
Changes from Ant 1.5.1Beta1 to the current CVS version
======================================================
+Fixed bugs:
+-----------
+* <tstamp>'s prefix attribute failed to apply to nested <format> elements.
+
Other changes:
--------------
No revision
No revision
1.27.2.3 +19 -14
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Tstamp.java
Index: Tstamp.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Tstamp.java,v
retrieving revision 1.27.2.2
retrieving revision 1.27.2.3
diff -u -r1.27.2.2 -r1.27.2.3
--- Tstamp.java 24 Jun 2002 02:28:08 -0000 1.27.2.2
+++ Tstamp.java 25 Sep 2002 15:30:30 -0000 1.27.2.3
@@ -112,18 +112,18 @@
Enumeration i = customFormats.elements();
while (i.hasMoreElements()) {
CustomFormat cts = (CustomFormat) i.nextElement();
- cts.execute(project, d, location);
+ cts.execute(getProject(), d, getLocation());
}
SimpleDateFormat dstamp = new SimpleDateFormat ("yyyyMMdd");
- project.setNewProperty(prefix + "DSTAMP", dstamp.format(d));
+ setProperty("DSTAMP", dstamp.format(d));
SimpleDateFormat tstamp = new SimpleDateFormat ("HHmm");
- project.setNewProperty(prefix + "TSTAMP", tstamp.format(d));
+ setProperty("TSTAMP", tstamp.format(d));
SimpleDateFormat today
= new SimpleDateFormat ("MMMM d yyyy", Locale.US);
- project.setNewProperty(prefix + "TODAY", today.format(d));
+ setProperty("TODAY", today.format(d));
} catch (Exception e) {
throw new BuildException(e);
@@ -135,12 +135,20 @@
* @return a ready to fill-in format
*/
public CustomFormat createFormat() {
- CustomFormat cts = new CustomFormat(prefix);
+ CustomFormat cts = new CustomFormat();
customFormats.addElement(cts);
return cts;
}
/**
+ * helper that encapsulates prefix logic and property setting
+ * policy (i.e. we use setNewProperty instead of setProperty).
+ */
+ private void setProperty(String name, String value) {
+ getProject().setNewProperty(prefix + name, value);
+ }
+
+ /**
* This nested element that allows a property to be set
* to the current date and time in a given format.
* The date/time patterns are as defined in the
@@ -158,14 +166,11 @@
private String variant;
private int offset = 0;
private int field = Calendar.DATE;
- private String prefix = "";
/**
- * Create a format with the current prefix
- * @param prefix
+ * Create a format
*/
- public CustomFormat(String prefix) {
- this.prefix = prefix;
+ public CustomFormat() {
}
/**
@@ -173,7 +178,7 @@
* @param propertyName
*/
public void setProperty(String propertyName) {
- this.propertyName = prefix + propertyName;
+ this.propertyName = propertyName;
}
/**
@@ -204,7 +209,7 @@
if (st.hasMoreElements()) {
variant = st.nextToken();
if (st.hasMoreElements()) {
- throw new BuildException("bad locale format",
+ throw new BuildException("bad locale format",
getLocation());
}
}
@@ -212,7 +217,7 @@
country = "";
}
} catch (NoSuchElementException e) {
- throw new BuildException("bad locale format", e,
+ throw new BuildException("bad locale format", e,
getLocation());
}
}
@@ -307,7 +312,7 @@
if (timeZone != null){
sdf.setTimeZone(timeZone);
}
- project.setNewProperty(propertyName, sdf.format(date));
+ Tstamp.this.setProperty(propertyName, sdf.format(date));
}
}
No revision
No revision
1.1.2.3 +13 -0
jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/TStampTest.java
Index: TStampTest.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/TStampTest.java,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -r1.1.2.2 -r1.1.2.3
--- TStampTest.java 17 Jun 2002 07:54:20 -0000 1.1.2.2
+++ TStampTest.java 25 Sep 2002 15:30:30 -0000 1.1.2.3
@@ -121,6 +121,7 @@
assertEquals(expected, today);
}
+
/**
* verifies that custom props have priority over the
* originals
@@ -130,6 +131,18 @@
tstamp.setPrefix("prefix");
tstamp.execute();
String prop= project.getProperty("prefix.DSTAMP");
+ assertNotNull(prop);
+ }
+
+ public void testFormatPrefix() throws Exception {
+ Tstamp.CustomFormat format = tstamp.createFormat();
+ format.setProperty("format");
+ format.setPattern("HH:mm:ss z");
+ format.setTimezone("GMT");
+
+ tstamp.setPrefix("prefix");
+ tstamp.execute();
+ String prop= project.getProperty("prefix.format");
assertNotNull(prop);
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>