cmlenz 2003/03/16 13:29:04
Modified: integration/ant/src/java/org/apache/cactus/integration/ant
WebXmlMergeTask.java
Log:
Implement up-to-date checking, and add a boolean 'force' attribute to
override the checking in build files
Revision Changes Path
1.4 +45 -12
jakarta-cactus/integration/ant/src/java/org/apache/cactus/integration/ant/WebXmlMergeTask.java
Index: WebXmlMergeTask.java
===================================================================
RCS file:
/home/cvs/jakarta-cactus/integration/ant/src/java/org/apache/cactus/integration/ant/WebXmlMergeTask.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- WebXmlMergeTask.java 16 Mar 2003 10:36:29 -0000 1.3
+++ WebXmlMergeTask.java 16 Mar 2003 21:29:04 -0000 1.4
@@ -104,6 +104,12 @@
private File destFile;
/**
+ * Whether the merge should be performed even when the destination file is
+ * up to date.
+ */
+ private boolean force = false;
+
+ /**
* Whether the resulting XML file should be indented.
*/
private boolean indent = false;
@@ -151,25 +157,41 @@
throw new BuildException("The [destfile] attribute is required");
}
- // FIXME: Skip merge if destfile newer than srcfile and mergefile
try
{
- WebXml srcWebXml = parseWebXml(this.srcFile);
if (this.mergeFile != null)
{
- WebXml mergeWebXml = parseWebXml(this.mergeFile);
- checkServletVersions(srcWebXml, mergeWebXml);
- merge(srcWebXml, mergeWebXml);
+ if (force ||
+ (srcFile.lastModified() > destFile.lastModified()) ||
+ (mergeFile.lastModified() > destFile.lastModified()))
+ {
+ WebXml srcWebXml = parseWebXml(this.srcFile);
+ WebXml mergeWebXml = parseWebXml(this.mergeFile);
+ checkServletVersions(srcWebXml, mergeWebXml);
+ merge(srcWebXml, mergeWebXml);
+ writeWebXml(srcWebXml, this.destFile);
+ }
+ else
+ {
+ log("The destination file is up to date",
+ Project.MSG_VERBOSE);
+ }
+ }
+ else
+ {
+ throw new BuildException("The [mergefile] attribute is "
+ + "required");
}
- writeWebXml(srcWebXml, this.destFile);
}
catch (ParserConfigurationException pce)
{
- throw new BuildException("XML parser configuration problem", pce);
+ throw new BuildException("XML parser configuration problem: "
+ + pce.getMessage(), pce);
}
catch (IOException ioe)
{
- throw new BuildException("An I/O error occurred", ioe);
+ throw new BuildException("An I/O error occurred: "
+ + ioe.getMessage(), ioe);
}
}
@@ -215,6 +237,17 @@
}
/**
+ * Sets whether the merge should be performed even when the destination
+ * file is up to date.
+ *
+ * @param isForce Whether the merge should be forced
+ */
+ public void setForce(boolean isForce)
+ {
+ this.force = isForce;
+ }
+
+ /**
* Sets the encoding of the resulting XML file. Default is 'UTF-8'.
*
* @param theEncoding The encoding to set
@@ -228,11 +261,11 @@
* Whether the result XML file should be indented for better readability.
* Default is 'false'.
*
- * @param theIndent Whether the result should be indented
+ * @param isIndent Whether the result should be indented
*/
- public void setIndent(boolean theIndent)
+ public void setIndent(boolean isIndent)
{
- this.indent = theIndent;
+ this.indent = isIndent;
}
// Private Methods ---------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]