diff --git a/proposal/sandbox/svn/docs/revisiondiff.html b/proposal/sandbox/svn/docs/revisiondiff.html new file mode 100644 index 000000000..f9c61e9eb --- /dev/null +++ b/proposal/sandbox/svn/docs/revisiondiff.html @@ -0,0 +1,129 @@ + +
+ +Generates an XML-formatted report file of the changes between two +revisions recorded in a Subversion repository.
+ +Important: This task needs "svn" on the path. If it isn't,
+you will get an error (such as error 2 on windows). If
+<svn>
doesn't work, try to execute
+svn.exe
from the command line in the target directory in
+which you are working.
Attribute | +Description | +Required | +
start | +The earliest revision from which diffs are to be + included in the report. | +Yes. | +
end | +The latest revision from which diffs are to be + included in the report. | +Yes. | +
destfile | +The file in which to write the diff report. | +Yes | +
svn
taskAttribute | +Description | +Required | +
svnURL | +the svn URL to diff. | +No | +
failonerror | +Stop the buildprocess if the command exits with a + returncode other than 0. Defaults to false | +No | +
<revisiondiff + svnURL="http://svn.apache.org/repos/asf/jakarta/bcel/trunk" + destfile="diff.xml" + start="152904" + end="153682" + />+ +
Generates a revisiondiff report for all the changes that have been
+made in the Apache BCEL
module between the revisions
+152904
and 153682
. It writes these changes
+into the file diff.xml
.
<revisiondiff + destfile="diff.xml" + package="ant" + start="{2002-01-01}" + end="{2002-02-01}" + dest="my-working-copy-of-BCEL" + />+ +
Generates a diff report for all the changes that have been made in
+the Apache BCEL
module in january 2002. In this example
+svnURL
has not been set, it is assumed that
+my-working-copy-of-BCEL
contains a checked out copy of
+the BCEL module. It writes these changes into the file
+diff.xml
.
This antlib includes a basic XSLT stylesheet that you can use to +generate a HTML report based on the xml output. The following example +illustrates how to generate a HTML report from the XML report.
+ ++ <style in="diff.xml" + out="diff.html" + style="your-path-to/etc/revisiondiff.xsl"> + <param name="title" expression="Jakarta BCEL diff"/> + <param name="repo" expression="http://svn.apache.org/repos/asf/jakarta/bcel/trunk"/> + </style> ++ +
+<?xml version="1.0" encoding="UTF-8"?> +<revisiondiff start="153872" end="152873" svnurl="http://svn.apache.org/repos/asf/jakarta/bcel/trunk" > + <path> + <name><![CDATA[LICENSE.txt]]></name> + <action>modified</action> + </path> + <path> + <name><![CDATA[NOTICE.txt]]></name> + <action>deleted</action> + </path> +</revisiondiff> ++ +
Copyright © 2005 The Apache Software Foundation. All rights +Reserved.
+ + + + diff --git a/proposal/sandbox/svn/src/etc/revisiondiff.xsl b/proposal/sandbox/svn/src/etc/revisiondiff.xsl new file mode 100644 index 000000000..a0391c33b --- /dev/null +++ b/proposal/sandbox/svn/src/etc/revisiondiff.xsl @@ -0,0 +1,140 @@ + +Designed for use with Apache Ant.
++ New Files | + Modified Files | + Removed Files + | +
+ * <!-- Root element --> + * <!ELEMENT revisiondiff ( paths? ) > + * <!-- Start revision of the report --> + * <!ATTLIST revisiondiff startRevision NMTOKEN #IMPLIED > + * <!-- End revision of the report --> + * <!ATTLIST revisiondiff endRevision NMTOKEN #IMPLIED > + * <!-- Start date of the report --> + * + * <!-- Path added, changed or removed --> + * <!ELEMENT path ( name,action ) > + * <!-- Name of the file --> + * <!ELEMENT name ( #PCDATA ) > + * <!ELEMENT action (added|modified|deleted)> + *+ * + * @ant.task name="svnrevisiondiff" + */ +public class SvnRevisionDiff extends AbstractSvnTask { + + /** + * Used to create the temp file for svn log + */ + private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); + + /** + * Token to identify the word file in the rdiff log + */ + static final String INDEX = "Index: "; + /** + * Token to identify a deleted file based on the Index line. + */ + static final String DELETED = " (deleted)"; + + /** + * Token to identify added files based on the diff line. + */ + static final String IS_NEW = "\t(revision 0)"; + + /** + * Token that starts diff line of old revision. + */ + static final String DASHES = "--- "; + + /** + * The earliest revision from which diffs are to be included in the report. + */ + private String mystartRevision; + + /** + * The latest revision from which diffs are to be included in the report. + */ + private String myendRevision; + + /** + * The file in which to write the diff report. + */ + private File mydestfile; + + /** + * Set the start revision. + * + * @param s the start revision. + */ + public void setStart(String s) { + mystartRevision = s; + } + + /** + * Set the end revision. + * + * @param s the end revision. + */ + public void setEnd(String s) { + myendRevision = s; + } + + /** + * Set the output file for the diff. + * + * @param f the output file for the diff. + */ + public void setDestFile(File f) { + mydestfile = f; + } + + /** + * Execute task. + * + * @exception BuildException if an error occurs + */ + public void execute() throws BuildException { + // validate the input parameters + validate(); + + // build the rdiff command + setSubCommand("diff"); + setRevision(mystartRevision + ":" + myendRevision); + addSubCommandArgument("--no-diff-deleted"); + + File tmpFile = null; + try { + tmpFile = + FILE_UTILS.createTempFile("svnrevisiondiff", ".log", null); + tmpFile.deleteOnExit(); + setOutput(tmpFile); + + // run the svn command + super.execute(); + + // parse the rdiff + SvnEntry.Path[] entries = parseDiff(tmpFile); + + // write the revision diff + writeRevisionDiff(entries); + + } finally { + if (tmpFile != null) { + tmpFile.delete(); + } + } + } + + /** + * Parse the tmpFile and return and array of SvnRevisionEntry to be + * written in the output. + * + * @param tmpFile the File containing the output of the svn rdiff command + * @return the entries in the output + * @exception BuildException if an error occurs + */ + private SvnEntry.Path[] parseDiff(File tmpFile) throws BuildException { + // parse the output of the command + BufferedReader reader = null; + + try { + reader = new BufferedReader(new FileReader(tmpFile)); + ArrayList entries = new ArrayList(); + + String line = reader.readLine(); + String name = null; + String currDiffLine = null; + boolean deleted = false; + boolean added = false; + + while (null != line) { + if (line.length() > INDEX.length()) { + if (line.startsWith(INDEX)) { + if (name != null) { + SvnEntry.Path p = + new SvnEntry.Path(name, + deleted + ? SvnEntry.Path.DELETED + : (added + ? SvnEntry.Path.ADDED + : SvnEntry.Path.MODIFIED) + ); + entries.add(p); + deleted = added = false; + } + + name = line.substring(INDEX.length()); + if (line.endsWith(DELETED)) { + name = name.substring(0, name.length() + - DELETED.length()); + deleted = true; + } + + currDiffLine = DASHES + name; + } else if (currDiffLine != null + && line.startsWith(currDiffLine) + && line.endsWith(IS_NEW)) { + added = true; + } + } + line = reader.readLine(); + } + if (name != null) { + SvnEntry.Path p = new SvnEntry.Path(name, + deleted + ? SvnEntry.Path.DELETED + : (added + ? SvnEntry.Path.ADDED + : SvnEntry.Path.MODIFIED) + ); + entries.add(p); + } + + SvnEntry.Path[] array = (SvnEntry.Path[]) + entries.toArray(new SvnEntry.Path[entries.size()]); + return array; + } catch (IOException e) { + throw new BuildException("Error in parsing", e); + } finally { + if (reader != null) { + try { + reader.close(); + } catch (IOException e) { + log(e.toString(), Project.MSG_ERR); + } + } + } + } + + /** + * Write the rdiff log. + * + * @param entries a
SvnRevisionEntry[]
value
+ * @exception BuildException if an error occurs
+ */
+ private void writeRevisionDiff(SvnEntry.Path[] entries) throws BuildException {
+ FileOutputStream output = null;
+ try {
+ output = new FileOutputStream(mydestfile);
+ PrintWriter writer = new PrintWriter(
+ new OutputStreamWriter(output, "UTF-8"));
+ writer.println("");
+ writer.print("PrintWriter
value
+ * @param entry a SvnRevisionEntry
value
+ */
+ private void writeRevisionEntry(PrintWriter writer, SvnEntry.Path entry) {
+ writer.println("\t