bodewig 2005/03/30 22:51:06
Modified: src/main/org/apache/tools/ant/taskdefs/cvslib Tag:
ANT_16_BRANCH ChangeLogWriter.java CvsTagDiff.java
src/main/org/apache/tools/ant/util Tag: ANT_16_BRANCH
DOMElementWriter.java
Added: src/main/org/apache/tools/ant/util Tag: ANT_16_BRANCH
DOMUtils.java
Log:
Merge fix for 24281
Revision Changes Path
No revision
No revision
1.10.2.6 +40 -26
ant/src/main/org/apache/tools/ant/taskdefs/cvslib/ChangeLogWriter.java
Index: ChangeLogWriter.java
===================================================================
RCS file:
/home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/cvslib/ChangeLogWriter.java,v
retrieving revision 1.10.2.5
retrieving revision 1.10.2.6
diff -u -r1.10.2.5 -r1.10.2.6
--- ChangeLogWriter.java 9 Mar 2005 18:56:24 -0000 1.10.2.5
+++ ChangeLogWriter.java 31 Mar 2005 06:51:05 -0000 1.10.2.6
@@ -16,11 +16,18 @@
*/
package org.apache.tools.ant.taskdefs.cvslib;
+import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Enumeration;
import java.util.TimeZone;
+import org.apache.tools.ant.util.DOMElementWriter;
+import org.apache.tools.ant.util.DOMUtils;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
/**
* Class used to generate an XML changelog.
*
@@ -32,6 +39,8 @@
/** output format for times written to xml file */
private static final SimpleDateFormat c_outputTime
= new SimpleDateFormat("HH:mm");
+ /** stateless helper for writing the XML document */
+ private static final DOMElementWriter DOM_WRITER = new
DOMElementWriter();
static {
TimeZone utc = TimeZone.getTimeZone("UTC");
@@ -47,55 +56,60 @@
*/
public void printChangeLog(final PrintWriter output,
final CVSEntry[] entries) {
- output.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
- output.println("<changelog>");
- for (int i = 0; i < entries.length; i++) {
- final CVSEntry entry = entries[i];
+ try {
+ output.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
+ Document doc = DOMUtils.newDocument();
+ Element root = doc.createElement("changelog");
+ DOM_WRITER.openElement(root, output, 0, "\t");
+ output.println();
+ for (int i = 0; i < entries.length; i++) {
+ final CVSEntry entry = entries[i];
- printEntry(output, entry);
+ printEntry(doc, output, entry);
+ }
+ DOM_WRITER.closeElement(root, output, 0, "\t", true);
+ output.flush();
+ output.close();
+ } catch (IOException e) {
+ throw new org.apache.tools.ant.BuildException(e);
}
- output.println("</changelog>");
- output.flush();
- output.close();
}
/**
* Print out an individual entry in changelog.
*
+ * @param doc Document used to create elements.
* @param entry the entry to print
* @param output writer to which to send output.
*/
- private void printEntry(final PrintWriter output, final CVSEntry entry) {
- output.println("\t<entry>");
- output.println("\t\t<date>" + c_outputDate.format(entry.getDate())
- + "</date>");
- output.println("\t\t<time>" + c_outputTime.format(entry.getDate())
- + "</time>");
- output.println("\t\t<author><![CDATA[" + entry.getAuthor()
- + "]]></author>");
+ private void printEntry(Document doc, final PrintWriter output,
+ final CVSEntry entry) throws IOException {
+ Element ent = doc.createElement("entry");
+ DOMUtils.appendTextElement(ent, "date",
+ c_outputDate.format(entry.getDate()));
+ DOMUtils.appendTextElement(ent, "time",
+ c_outputTime.format(entry.getDate()));
+ DOMUtils.appendCDATAElement(ent, "author", entry.getAuthor());
final Enumeration enumeration = entry.getFiles().elements();
while (enumeration.hasMoreElements()) {
final RCSFile file = (RCSFile) enumeration.nextElement();
- output.println("\t\t<file>");
- output.println("\t\t\t<name>" + file.getName() + "</name>");
- output.println("\t\t\t<revision>" + file.getRevision()
- + "</revision>");
+ Element f = DOMUtils.createChildElement(ent, "file");
+ DOMUtils.appendCDATAElement(f, "name", file.getName());
+ DOMUtils.appendTextElement(f, "revision", file.getRevision());
final String previousRevision = file.getPreviousRevision();
if (previousRevision != null) {
- output.println("\t\t\t<prevrevision>" + previousRevision
- + "</prevrevision>");
+ DOMUtils.appendTextElement(f, "prevrevision",
+ previousRevision);
}
-
- output.println("\t\t</file>");
}
- output.println("\t\t<msg><![CDATA[" + entry.getComment() +
"]]></msg>");
- output.println("\t</entry>");
+ DOMUtils.appendCDATAElement(ent, "msg", entry.getComment());
+ DOM_WRITER.write(ent, output, 1, "\t");
}
}
1.16.2.9 +37 -25
ant/src/main/org/apache/tools/ant/taskdefs/cvslib/CvsTagDiff.java
Index: CvsTagDiff.java
===================================================================
RCS file:
/home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/cvslib/CvsTagDiff.java,v
retrieving revision 1.16.2.8
retrieving revision 1.16.2.9
diff -u -r1.16.2.8 -r1.16.2.9
--- CvsTagDiff.java 9 Mar 2005 18:56:24 -0000 1.16.2.8
+++ CvsTagDiff.java 31 Mar 2005 06:51:05 -0000 1.16.2.9
@@ -30,8 +30,13 @@
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.AbstractCvsTask;
+import org.apache.tools.ant.util.DOMElementWriter;
+import org.apache.tools.ant.util.DOMUtils;
import org.apache.tools.ant.util.FileUtils;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
/**
* Examines the output of cvs rdiff between two tags.
*
@@ -64,6 +69,15 @@
* @ant.task name="cvstagdiff"
*/
public class CvsTagDiff extends AbstractCvsTask {
+
+ /**
+ * Used to create the temp file for cvs log
+ */
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
+ /** stateless helper for writing the XML document */
+ private static final DOMElementWriter DOM_WRITER = new
DOMElementWriter();
+
/**
* Token to identify the word file in the rdiff log
*/
@@ -280,10 +294,6 @@
}
if ((index = line.indexOf(FILE_IS_NEW)) != -1) {
-//CVS 1.11
-//File apps/websphere/lib/something.jar is new; current revision 1.2
-//CVS 1.11.9
-//File apps/websphere/lib/something.jar is new; cvstag_2003_11_03_2 revision
1.2
// it is a new file
// set the revision but not the prevrevision
String filename = line.substring(0, index);
@@ -355,26 +365,27 @@
PrintWriter writer = new PrintWriter(
new OutputStreamWriter(output,
"UTF-8"));
writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
- writer.print("<tagdiff ");
+ Document doc = DOMUtils.newDocument();
+ Element root = doc.createElement("tagdiff");
if (mystartTag != null) {
- writer.print("startTag=\"" + mystartTag + "\" ");
+ root.setAttribute("startTag", mystartTag);
} else {
- writer.print("startDate=\"" + mystartDate + "\" ");
+ root.setAttribute("startDate", mystartDate);
}
if (myendTag != null) {
- writer.print("endTag=\"" + myendTag + "\" ");
+ root.setAttribute("endTag", myendTag);
} else {
- writer.print("endDate=\"" + myendDate + "\" ");
+ root.setAttribute("endDate", myendDate);
}
- writer.print("cvsroot=\"" + getCvsRoot() + "\" ");
- writer.print("package=\"" + mypackage + "\" ");
-
- writer.println(">");
+ root.setAttribute("cvsroot", getCvsRoot());
+ root.setAttribute("package", mypackage);
+ DOM_WRITER.openElement(root, writer, 0, "\t");
+ writer.println();
for (int i = 0, c = entries.length; i < c; i++) {
- writeTagEntry(writer, entries[i]);
+ writeTagEntry(doc, writer, entries[i]);
}
- writer.println("</tagdiff>");
+ DOM_WRITER.closeElement(root, writer, 0, "\t", true);
writer.flush();
writer.close();
} catch (UnsupportedEncodingException uee) {
@@ -395,23 +406,24 @@
/**
* Write a single entry to the given writer.
*
+ * @param doc Document used to create elements.
* @param writer a <code>PrintWriter</code> value
* @param entry a <code>CvsTagEntry</code> value
*/
- private void writeTagEntry(PrintWriter writer, CvsTagEntry entry) {
- writer.println("\t<entry>");
- writer.println("\t\t<file>");
- writer.println("\t\t\t<name>" + entry.getFile() + "</name>");
+ private void writeTagEntry(Document doc, PrintWriter writer,
+ CvsTagEntry entry)
+ throws IOException {
+ Element ent = doc.createElement("entry");
+ Element f = DOMUtils.createChildElement(ent, "file");
+ DOMUtils.appendCDATAElement(f, "name", entry.getFile());
if (entry.getRevision() != null) {
- writer.println("\t\t\t<revision>" + entry.getRevision()
- + "</revision>");
+ DOMUtils.appendTextElement(f, "revision", entry.getRevision());
}
if (entry.getPreviousRevision() != null) {
- writer.println("\t\t\t<prevrevision>"
- + entry.getPreviousRevision() +
"</prevrevision>");
+ DOMUtils.appendTextElement(f, "prevrevision",
+ entry.getPreviousRevision());
}
- writer.println("\t\t</file>");
- writer.println("\t</entry>");
+ DOM_WRITER.write(ent, writer, 1, "\t");
}
/**
No revision
No revision
1.20.2.6 +54 -21
ant/src/main/org/apache/tools/ant/util/DOMElementWriter.java
Index: DOMElementWriter.java
===================================================================
RCS file:
/home/cvs/ant/src/main/org/apache/tools/ant/util/DOMElementWriter.java,v
retrieving revision 1.20.2.5
retrieving revision 1.20.2.6
diff -u -r1.20.2.5 -r1.20.2.6
--- DOMElementWriter.java 17 May 2004 13:43:53 -0000 1.20.2.5
+++ DOMElementWriter.java 31 Mar 2005 06:51:05 -0000 1.20.2.6
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2004 The Apache Software Foundation
+ * Copyright 2000-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -76,26 +76,7 @@
String indentWith)
throws IOException {
- // Write indent characters
- for (int i = 0; i < indent; i++) {
- out.write(indentWith);
- }
-
- // Write element
- out.write("<");
- out.write(element.getTagName());
-
- // Write attributes
- NamedNodeMap attrs = element.getAttributes();
- for (int i = 0; i < attrs.getLength(); i++) {
- Attr attr = (Attr) attrs.item(i);
- out.write(" ");
- out.write(attr.getName());
- out.write("=\"");
- out.write(encode(attr.getValue()));
- out.write("\"");
- }
- out.write(">");
+ openElement(element, out, indent, indentWith);
// Write child elements and text
boolean hasChildren = false;
@@ -148,6 +129,58 @@
}
}
+ closeElement(element, out, indent, indentWith, hasChildren);
+ }
+
+ /**
+ * Writes the opening tag - including all attributes -
+ * correspondong to a DOM element.
+ *
+ * @param element the DOM element to write
+ * @param out where to send the output
+ * @param indent number of
+ * @param indentWith string that should be used to indent the
+ * corresponding tag.
+ * @throws IOException if an error happens while writing to the stream.
+ */
+ public void openElement(Element element, Writer out, int indent,
+ String indentWith)
+ throws IOException {
+ // Write indent characters
+ for (int i = 0; i < indent; i++) {
+ out.write(indentWith);
+ }
+
+ // Write element
+ out.write("<");
+ out.write(element.getTagName());
+
+ // Write attributes
+ NamedNodeMap attrs = element.getAttributes();
+ for (int i = 0; i < attrs.getLength(); i++) {
+ Attr attr = (Attr) attrs.item(i);
+ out.write(" ");
+ out.write(attr.getName());
+ out.write("=\"");
+ out.write(encode(attr.getValue()));
+ out.write("\"");
+ }
+ out.write(">");
+ }
+
+ /**
+ * Writes a DOM tree to a stream.
+ *
+ * @param element the Root DOM element of the tree
+ * @param out where to send the output
+ * @param indent number of
+ * @param indentWith string that should be used to indent the
+ * corresponding tag.
+ * @throws IOException if an error happens while writing to the stream.
+ */
+ public void closeElement(Element element, Writer out, int indent,
+ String indentWith, boolean hasChildren)
+ throws IOException {
// If we had child elements, we need to indent before we close
// the element, otherwise we're on the same line and don't need
// to indent
No revision
Index: DOMElementWriter.java
===================================================================
RCS file:
/home/cvs/ant/src/main/org/apache/tools/ant/util/DOMElementWriter.java,v
retrieving revision 1.20.2.5
retrieving revision 1.20.2.6
diff -u -r1.20.2.5 -r1.20.2.6
--- DOMElementWriter.java 17 May 2004 13:43:53 -0000 1.20.2.5
+++ DOMElementWriter.java 31 Mar 2005 06:51:05 -0000 1.20.2.6
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2004 The Apache Software Foundation
+ * Copyright 2000-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -76,26 +76,7 @@
String indentWith)
throws IOException {
- // Write indent characters
- for (int i = 0; i < indent; i++) {
- out.write(indentWith);
- }
-
- // Write element
- out.write("<");
- out.write(element.getTagName());
-
- // Write attributes
- NamedNodeMap attrs = element.getAttributes();
- for (int i = 0; i < attrs.getLength(); i++) {
- Attr attr = (Attr) attrs.item(i);
- out.write(" ");
- out.write(attr.getName());
- out.write("=\"");
- out.write(encode(attr.getValue()));
- out.write("\"");
- }
- out.write(">");
+ openElement(element, out, indent, indentWith);
// Write child elements and text
boolean hasChildren = false;
@@ -148,6 +129,58 @@
}
}
+ closeElement(element, out, indent, indentWith, hasChildren);
+ }
+
+ /**
+ * Writes the opening tag - including all attributes -
+ * correspondong to a DOM element.
+ *
+ * @param element the DOM element to write
+ * @param out where to send the output
+ * @param indent number of
+ * @param indentWith string that should be used to indent the
+ * corresponding tag.
+ * @throws IOException if an error happens while writing to the stream.
+ */
+ public void openElement(Element element, Writer out, int indent,
+ String indentWith)
+ throws IOException {
+ // Write indent characters
+ for (int i = 0; i < indent; i++) {
+ out.write(indentWith);
+ }
+
+ // Write element
+ out.write("<");
+ out.write(element.getTagName());
+
+ // Write attributes
+ NamedNodeMap attrs = element.getAttributes();
+ for (int i = 0; i < attrs.getLength(); i++) {
+ Attr attr = (Attr) attrs.item(i);
+ out.write(" ");
+ out.write(attr.getName());
+ out.write("=\"");
+ out.write(encode(attr.getValue()));
+ out.write("\"");
+ }
+ out.write(">");
+ }
+
+ /**
+ * Writes a DOM tree to a stream.
+ *
+ * @param element the Root DOM element of the tree
+ * @param out where to send the output
+ * @param indent number of
+ * @param indentWith string that should be used to indent the
+ * corresponding tag.
+ * @throws IOException if an error happens while writing to the stream.
+ */
+ public void closeElement(Element element, Writer out, int indent,
+ String indentWith, boolean hasChildren)
+ throws IOException {
// If we had child elements, we need to indent before we close
// the element, otherwise we're on the same line and don't need
// to indent
No revision
Index: DOMElementWriter.java
===================================================================
RCS file:
/home/cvs/ant/src/main/org/apache/tools/ant/util/DOMElementWriter.java,v
retrieving revision 1.20.2.5
retrieving revision 1.20.2.6
diff -u -r1.20.2.5 -r1.20.2.6
--- DOMElementWriter.java 17 May 2004 13:43:53 -0000 1.20.2.5
+++ DOMElementWriter.java 31 Mar 2005 06:51:05 -0000 1.20.2.6
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2004 The Apache Software Foundation
+ * Copyright 2000-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -76,26 +76,7 @@
String indentWith)
throws IOException {
- // Write indent characters
- for (int i = 0; i < indent; i++) {
- out.write(indentWith);
- }
-
- // Write element
- out.write("<");
- out.write(element.getTagName());
-
- // Write attributes
- NamedNodeMap attrs = element.getAttributes();
- for (int i = 0; i < attrs.getLength(); i++) {
- Attr attr = (Attr) attrs.item(i);
- out.write(" ");
- out.write(attr.getName());
- out.write("=\"");
- out.write(encode(attr.getValue()));
- out.write("\"");
- }
- out.write(">");
+ openElement(element, out, indent, indentWith);
// Write child elements and text
boolean hasChildren = false;
@@ -148,6 +129,58 @@
}
}
+ closeElement(element, out, indent, indentWith, hasChildren);
+ }
+
+ /**
+ * Writes the opening tag - including all attributes -
+ * correspondong to a DOM element.
+ *
+ * @param element the DOM element to write
+ * @param out where to send the output
+ * @param indent number of
+ * @param indentWith string that should be used to indent the
+ * corresponding tag.
+ * @throws IOException if an error happens while writing to the stream.
+ */
+ public void openElement(Element element, Writer out, int indent,
+ String indentWith)
+ throws IOException {
+ // Write indent characters
+ for (int i = 0; i < indent; i++) {
+ out.write(indentWith);
+ }
+
+ // Write element
+ out.write("<");
+ out.write(element.getTagName());
+
+ // Write attributes
+ NamedNodeMap attrs = element.getAttributes();
+ for (int i = 0; i < attrs.getLength(); i++) {
+ Attr attr = (Attr) attrs.item(i);
+ out.write(" ");
+ out.write(attr.getName());
+ out.write("=\"");
+ out.write(encode(attr.getValue()));
+ out.write("\"");
+ }
+ out.write(">");
+ }
+
+ /**
+ * Writes a DOM tree to a stream.
+ *
+ * @param element the Root DOM element of the tree
+ * @param out where to send the output
+ * @param indent number of
+ * @param indentWith string that should be used to indent the
+ * corresponding tag.
+ * @throws IOException if an error happens while writing to the stream.
+ */
+ public void closeElement(Element element, Writer out, int indent,
+ String indentWith, boolean hasChildren)
+ throws IOException {
// If we had child elements, we need to indent before we close
// the element, otherwise we're on the same line and don't need
// to indent
1.1.2.1 +0 -0 ant/src/main/org/apache/tools/ant/util/DOMUtils.java
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]