diff --git a/proposal/sandbox/svn/docs/revisiondiff.html b/proposal/sandbox/svn/docs/revisiondiff.html index f9c61e9eb..9d282ee90 100644 --- a/proposal/sandbox/svn/docs/revisiondiff.html +++ b/proposal/sandbox/svn/docs/revisiondiff.html @@ -100,7 +100,7 @@ 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">
+               style="your-path-to/etc/diff.xsl">
           <param name="title" expression="Jakarta BCEL diff"/>
           <param name="repo" expression="http://svn.apache.org/repos/asf/jakarta/bcel/trunk"/>
         </style>
diff --git a/proposal/sandbox/svn/docs/tagdiff.html b/proposal/sandbox/svn/docs/tagdiff.html
new file mode 100644
index 000000000..c0ca6d545
--- /dev/null
+++ b/proposal/sandbox/svn/docs/tagdiff.html
@@ -0,0 +1,158 @@
+
+
+
+RevisionDiff Task
+
+
+

TagDiff

+

Description

+ +

Generates an XML-formatted report file of the changes between two +tags 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.

+ +

This task assumes that your repository follows the best-practice +layout of

+
+BASEURL
+  |
+  |
+  -----> trunk
+  -----> tags
+           |
+           |
+           ----------> tag1
+           ----------> tag2
+
+ +

Parameters

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
AttributeDescriptionRequired
tag1The first tag.Yes.
tag2The second tag.No, defaults to "trunk/"
destfileThe file in which to write the diff report.Yes
baseURLThe baseURL of the repository, used to calculate + the two URLs to compare.Yes
+ +

Parameters inherited from the svn task

+ + + + + + + + + + + +
AttributeDescriptionRequired
failonerrorStop the buildprocess if the command exits with a + returncode other than 0. Defaults to falseNo
+ +

Examples

+
+  <tagdiff failonerror="true"
+      baseURL="http://svn.apache.org/repos/asf/jakarta/bcel/"
+      destfile="diff.xml"
+      tag1="initial"
+      tag2="BCEL_5_0"
+  />
+
+ +

Generates a tagdiff report for all the changes that have been +made in the Apache BCEL module between the tags +initial and BCEL_5_0. It writes these changes +into the file diff.xml.

+ +
+  <tagdiff failonerror="true"
+      baseURL="http://svn.apache.org/repos/asf/jakarta/bcel/"
+      destfile="diff.xml"
+      tag1="BCEL_5_0"
+      tag2="trunk"
+  />
+
+ +

Generates a tagdiff report for all the changes that have been made +in the Apache BCEL module between the tag +BCEL_5_0 and the trunk. It writes these +changes into the file diff.xml.

+ +
+  <tagdiff failonerror="true"
+      baseURL="http://svn.apache.org/repos/asf/jakarta/bcel/"
+      destfile="diff.xml"
+      tag1="BCEL_5_0"
+  />
+
+ +

Does the same, using trunk as tag2 +implicitly.

+ +

Generate Report

+ +

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/diff.xsl">
+          <param name="title" expression="Jakarta BCEL diff"/>
+          <param name="repo" expression="http://svn.apache.org/repos/asf/jakarta/bcel/trunk"/>
+        </style>
+
+ +

(Shortened) Example Output

+
+<?xml version="1.0" encoding="UTF-8"?>
+<tagdiff tag1="BCEL_5_0" svnurl="http://svn.apache.org/repos/asf/jakarta/bcel/" >
+  <path>
+    <name><![CDATA[default.properties]]></name>
+    <action>added</action>
+  </path>
+  <path>
+    <name><![CDATA[xdocs/images/classloader.gif]]></name>
+    <action>modified</action>
+  </path>
+  <path>
+    <name><![CDATA[README]]></name>
+    <action>deleted</action>
+  </path>
+</tagdiff>
+
+ +

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/diff.xsl similarity index 95% rename from proposal/sandbox/svn/src/etc/revisiondiff.xsl rename to proposal/sandbox/svn/src/etc/diff.xsl index a0391c33b..467ffb997 100644 --- a/proposal/sandbox/svn/src/etc/revisiondiff.xsl +++ b/proposal/sandbox/svn/src/etc/diff.xsl @@ -32,7 +32,7 @@ - + <xsl:value-of select="$title"/> @@ -60,7 +60,7 @@

- diff between and + diff between and

Designed for use with Apache Ant.


diff --git a/proposal/sandbox/svn/src/etc/testcases/revisiondiff.xml b/proposal/sandbox/svn/src/etc/testcases/revisiondiff.xml index e46dcb8fc..771bc87dc 100644 --- a/proposal/sandbox/svn/src/etc/testcases/revisiondiff.xml +++ b/proposal/sandbox/svn/src/etc/testcases/revisiondiff.xml @@ -46,7 +46,7 @@ diff --git a/proposal/sandbox/svn/src/etc/testcases/tagdiff.xml b/proposal/sandbox/svn/src/etc/testcases/tagdiff.xml new file mode 100644 index 000000000..4854dab79 --- /dev/null +++ b/proposal/sandbox/svn/src/etc/testcases/tagdiff.xml @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/proposal/sandbox/svn/src/main/org/apache/tools/ant/taskdefs/svn/SvnDiffHandler.java b/proposal/sandbox/svn/src/main/org/apache/tools/ant/taskdefs/svn/SvnDiffHandler.java new file mode 100644 index 000000000..0a42e11df --- /dev/null +++ b/proposal/sandbox/svn/src/main/org/apache/tools/ant/taskdefs/svn/SvnDiffHandler.java @@ -0,0 +1,196 @@ +/* + * Copyright 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.tools.ant.taskdefs.svn; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.io.UnsupportedEncodingException; +import java.util.ArrayList; +import java.util.StringTokenizer; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.util.FileUtils; + +/** + * Parses the output of a svn diff command and/or writes an XML report + * based on such a diff output. + * + * It produces an XML output representing the list of changes. + */ +final class SvnDiffHandler { + + /** + * Token to identify the word file in the rdiff log + */ + private static final String INDEX = "Index: "; + /** + * Token to identify a deleted file based on the Index line. + */ + private static final String DELETED = " (deleted)"; + + /** + * Token to identify added files based on the diff line. + */ + private static final String IS_NEW = "\t(revision 0)"; + + /** + * Token that starts diff line of old revision. + */ + private static final String DASHES = "--- "; + + /** + * Parse the tmpFile and return and array of entries 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 + */ + static 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 { + FileUtils.close(reader); + } + } + + /** + * Write the diff log. + * + * @param entries a SvnRevisionEntry[] value + * @exception BuildException if an error occurs + */ + static void writeDiff(File destFile, SvnEntry.Path[] entries, + String rootElementName, + String tag1Name, String tag1Value, + String tag2Name, String tag2Value, + String svnURL) throws BuildException { + FileOutputStream output = null; + try { + output = new FileOutputStream(destFile); + PrintWriter writer = new PrintWriter( + new OutputStreamWriter(output, "UTF-8")); + writer.println(""); + writer.print("<" + rootElementName + " "); + if (tag1Name != null && tag1Value != null) { + writer.print(tag1Name + "=\"" + tag1Value + "\" "); + } + if (tag2Name != null && tag2Value != null) { + writer.print(tag2Name + "=\"" + tag2Value + "\" "); + } + + if (svnURL != null) { + writer.print("svnurl=\"" + svnURL + "\" "); + } + + writer.println(">"); + for (int i = 0, c = entries.length; i < c; i++) { + writeRevisionEntry(writer, entries[i]); + } + writer.println(""); + writer.flush(); + writer.close(); + } catch (UnsupportedEncodingException uee) { + throw new BuildException(uee); + } catch (IOException ioe) { + throw new BuildException(ioe.toString(), ioe); + } finally { + FileUtils.close(output); + } + } + + /** + * Write a single entry to the given writer. + * + * @param writer a PrintWriter value + * @param entry a SvnRevisionEntry value + */ + private static void writeRevisionEntry(PrintWriter writer, + SvnEntry.Path entry) { + writer.println("\t"); + writer.println("\t\t"); + writer.println("\t\t" + entry.getActionDescription() + + ""); + writer.println("\t"); + } + +} diff --git a/proposal/sandbox/svn/src/main/org/apache/tools/ant/taskdefs/svn/SvnRevisionDiff.java b/proposal/sandbox/svn/src/main/org/apache/tools/ant/taskdefs/svn/SvnRevisionDiff.java index e347a1f6f..cf45aeade 100644 --- a/proposal/sandbox/svn/src/main/org/apache/tools/ant/taskdefs/svn/SvnRevisionDiff.java +++ b/proposal/sandbox/svn/src/main/org/apache/tools/ant/taskdefs/svn/SvnRevisionDiff.java @@ -39,10 +39,11 @@ import org.apache.tools.ant.util.FileUtils; * <!-- Root element --> * <!ELEMENT revisiondiff ( paths? ) > * <!-- Start revision of the report --> - * <!ATTLIST revisiondiff startRevision NMTOKEN #IMPLIED > + * <!ATTLIST revisiondiff start NMTOKEN #IMPLIED > * <!-- End revision of the report --> - * <!ATTLIST revisiondiff endRevision NMTOKEN #IMPLIED > - * <!-- Start date of the report --> + * <!ATTLIST revisiondiff end NMTOKEN #IMPLIED > + * <!-- Subversion URL if known --> + * <!ATTLIST revisiondiff svnurl NMTOKEN #IMPLIED > * * <!-- Path added, changed or removed --> * <!ELEMENT path ( name,action ) > @@ -60,25 +61,6 @@ public class SvnRevisionDiff extends AbstractSvnTask { */ 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. */ @@ -145,12 +127,13 @@ public class SvnRevisionDiff extends AbstractSvnTask { // run the svn command super.execute(); - // parse the rdiff - SvnEntry.Path[] entries = parseDiff(tmpFile); + // parse the diff + SvnEntry.Path[] entries = SvnDiffHandler.parseDiff(tmpFile); // write the revision diff - writeRevisionDiff(entries); - + SvnDiffHandler.writeDiff(mydestfile, entries, "revisiondiff", + "start", mystartRevision, + "end", myendRevision, getSvnURL()); } finally { if (tmpFile != null) { tmpFile.delete(); @@ -158,148 +141,6 @@ public class SvnRevisionDiff extends AbstractSvnTask { } } - /** - * 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(""); - for (int i = 0, c = entries.length; i < c; i++) { - writeRevisionEntry(writer, entries[i]); - } - writer.println(""); - writer.flush(); - writer.close(); - } catch (UnsupportedEncodingException uee) { - log(uee.toString(), Project.MSG_ERR); - } catch (IOException ioe) { - throw new BuildException(ioe.toString(), ioe); - } finally { - if (null != output) { - try { - output.close(); - } catch (IOException ioe) { - log(ioe.toString(), Project.MSG_ERR); - } - } - } - } - - /** - * Write a single entry to the given writer. - * - * @param writer a PrintWriter value - * @param entry a SvnRevisionEntry value - */ - private void writeRevisionEntry(PrintWriter writer, SvnEntry.Path entry) { - writer.println("\t"); - writer.println("\t\t"); - writer.println("\t\t" + entry.getActionDescription() - + ""); - writer.println("\t"); - } - /** * Validate the parameters specified for task. * diff --git a/proposal/sandbox/svn/src/main/org/apache/tools/ant/taskdefs/svn/SvnTagDiff.java b/proposal/sandbox/svn/src/main/org/apache/tools/ant/taskdefs/svn/SvnTagDiff.java new file mode 100644 index 000000000..42db960cd --- /dev/null +++ b/proposal/sandbox/svn/src/main/org/apache/tools/ant/taskdefs/svn/SvnTagDiff.java @@ -0,0 +1,210 @@ +/* + * Copyright 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.tools.ant.taskdefs.svn; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.io.UnsupportedEncodingException; +import java.util.ArrayList; +import java.util.StringTokenizer; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.util.FileUtils; + +/** + * Examines the output of svn diff between two tags or a tag and trunk. + * + *

This task only works if you follow the best-practice structure of + *

+ * BASEURL
+ *   |
+ *   |
+ *   -----> trunk
+ *   -----> tags
+ *            |
+ *            |
+ *            ----------> tag1
+ *            ----------> tag2
+ * 
+ * + * It produces an XML output representing the list of changes. + *
+ * <!-- Root element -->
+ * <!ELEMENT tagdiff ( paths? ) >
+ * <!-- First tag -->
+ * <!ATTLIST tagdiff tag1 NMTOKEN #IMPLIED >
+ * <!-- Second tag -->
+ * <!ATTLIST tagdiff tag2 NMTOKEN #IMPLIED >
+ * <!-- Subversion BaseURL -->
+ * <!ATTLIST tagdiff svnurl NMTOKEN #IMPLIED >
+ *
+ * <!-- Path added, changed or removed -->
+ * <!ELEMENT path ( name,action ) >
+ * <!-- Name of the file -->
+ * <!ELEMENT name ( #PCDATA ) >
+ * <!ELEMENT action (added|modified|deleted)>
+ * 
+ * + * @ant.task name="svntagdiff" + */ +public class SvnTagDiff extends AbstractSvnTask { + + /** + * Used to create the temp file for svn log + */ + private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); + + /** + * The earliest revision from which diffs are to be included in the report. + */ + private String tag1; + + /** + * The latest revision from which diffs are to be included in the report. + */ + private String tag2; + + /** + * The file in which to write the diff report. + */ + private File mydestfile; + + /** + * Base URL. + */ + private String baseURL; + + /** + * Set the first tag. + * + * @param s the first tag. + */ + public void setTag1(String s) { + tag1 = s; + } + + /** + * Set the second tag. + * + * @param s the second tag. + */ + public void setTag2(String s) { + tag2 = s; + } + + /** + * Set the output file for the diff. + * + * @param f the output file for the diff. + */ + public void setDestFile(File f) { + mydestfile = f; + } + + /** + * Set the base URL from which to calculate tag URLs. + * + * @param u the base URL from which to calculate tag URLs. + */ + public void setBaseURL(String u) { + baseURL = u; + if (!u.endsWith("/")) { + baseURL += "/"; + } + } + + /** + * Execute task. + * + * @exception BuildException if an error occurs + */ + public void execute() throws BuildException { + // validate the input parameters + validate(); + + // build the rdiff command + setSubCommand("diff"); + addSubCommandArgument("--no-diff-deleted"); + if (tag1.equals("trunk") || tag1.equals("trunk/")) { + addSubCommandArgument(baseURL + "trunk/"); + } else { + if (tag1.endsWith("/")) { + addSubCommandArgument(baseURL + "tags/" + tag1); + } else { + addSubCommandArgument(baseURL + "tags/" + tag1 + "/"); + } + } + if (tag2 == null || tag2.equals("trunk") || tag2.equals("trunk/")) { + addSubCommandArgument(baseURL + "trunk/"); + } else { + if (tag2.endsWith("/")) { + addSubCommandArgument(baseURL + "tags/" + tag2); + } else { + addSubCommandArgument(baseURL + "tags/" + tag2 + "/"); + } + } + + File tmpFile = null; + try { + tmpFile = + FILE_UTILS.createTempFile("svntagdiff", ".log", null); + tmpFile.deleteOnExit(); + setOutput(tmpFile); + + // run the svn command + super.execute(); + + // parse the diff + SvnEntry.Path[] entries = SvnDiffHandler.parseDiff(tmpFile); + + // write the revision diff + SvnDiffHandler.writeDiff(mydestfile, entries, "tagdiff", + "tag1", tag1, "tag2", + tag2 == null ? "trunk" : tag2, + baseURL); + } finally { + if (tmpFile != null) { + tmpFile.delete(); + } + } + } + + /** + * Validate the parameters specified for task. + * + * @exception BuildException if a parameter is not correctly set + */ + private void validate() throws BuildException { + if (null == mydestfile) { + throw new BuildException("Destfile must be set."); + } + + if (null == tag1) { + throw new BuildException("tag1 must be set."); + } + + if (null == baseURL) { + throw new BuildException("baseURL must be set."); + } + } +} diff --git a/proposal/sandbox/svn/src/main/org/apache/tools/ant/taskdefs/svn/antlib.xml b/proposal/sandbox/svn/src/main/org/apache/tools/ant/taskdefs/svn/antlib.xml index d78dde35a..94bc54c98 100644 --- a/proposal/sandbox/svn/src/main/org/apache/tools/ant/taskdefs/svn/antlib.xml +++ b/proposal/sandbox/svn/src/main/org/apache/tools/ant/taskdefs/svn/antlib.xml @@ -27,4 +27,8 @@ name="revisiondiff" classname="org.apache.tools.ant.taskdefs.svn.SvnRevisionDiff" /> + diff --git a/proposal/sandbox/svn/src/testcases/org/apache/tools/ant/taskdefs/svn/SvnRevisionDiffTest.java b/proposal/sandbox/svn/src/testcases/org/apache/tools/ant/taskdefs/svn/SvnRevisionDiffTest.java index c52d210fd..69c063ed7 100644 --- a/proposal/sandbox/svn/src/testcases/org/apache/tools/ant/taskdefs/svn/SvnRevisionDiffTest.java +++ b/proposal/sandbox/svn/src/testcases/org/apache/tools/ant/taskdefs/svn/SvnRevisionDiffTest.java @@ -74,9 +74,9 @@ public class SvnRevisionDiffTest extends BuildFileTest { int end = log.indexOf(">", start); Assert.assertTrue(end > -1); Assert.assertTrue(log.indexOf("start=\"152904\"", start) > -1); - Assert.assertTrue(log.indexOf("start=\"152904\"") < end); + Assert.assertTrue(log.indexOf("start=\"152904\"", start) < end); Assert.assertTrue(log.indexOf("end=\"153682\"", start) > -1); - Assert.assertTrue(log.indexOf("end=\"153682\"") < end); + Assert.assertTrue(log.indexOf("end=\"153682\"", start) < end); } private static final void assertAttributesNoURL(String log) { diff --git a/proposal/sandbox/svn/src/testcases/org/apache/tools/ant/taskdefs/svn/SvnTagDiffTest.java b/proposal/sandbox/svn/src/testcases/org/apache/tools/ant/taskdefs/svn/SvnTagDiffTest.java new file mode 100644 index 000000000..d2fb13e34 --- /dev/null +++ b/proposal/sandbox/svn/src/testcases/org/apache/tools/ant/taskdefs/svn/SvnTagDiffTest.java @@ -0,0 +1,144 @@ +/* + * Copyright 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +package org.apache.tools.ant.taskdefs.svn; + +import java.io.IOException; +import java.io.FileReader; + +import org.apache.tools.ant.BuildFileTest; +import org.apache.tools.ant.util.FileUtils; + +import junit.framework.Assert; + +/** + */ +public class SvnTagDiffTest extends BuildFileTest { + + public SvnTagDiffTest(String name) { + super(name); + } + + public void setUp() { + configureProject("src/etc/testcases/tagdiff.xml"); + } + + public void tearDown() { + executeTarget("cleanup"); + } + + public void testDiffWithTwoTags() throws IOException { + String log = executeTargetAndReadLogFully("diff-with-two-tags"); + assertAttributes(log, "initial", "BCEL_5_0"); + assertAdded1(log); + } + + public void testDiffWithExplicitTrunk() throws IOException { + String log = executeTargetAndReadLogFully("diff-with-explicit-trunk"); + assertDiffWithTrunk(log); + } + + public void testDiffWithImplicitTrunk() throws IOException { + String log = executeTargetAndReadLogFully("diff-with-implicit-trunk"); + assertDiffWithTrunk(log); + } + + private static void assertDiffWithTrunk(String log) { + assertAttributes(log, "BCEL_5_0", "trunk"); + assertAdded(log); + assertModified(log); + assertDeleted(log); + } + + private String executeTargetAndReadLogFully(String target) + throws IOException { + executeTarget(target); + FileReader r = new FileReader(getProject() + .resolveFile("tmpdir/diff.xml")); + try { + return FileUtils.readFully(r); + } finally { + r.close(); + } + } + + private static final void assertAttributes(String log, String tag1, + String tag2) { + int start = log.indexOf(" -1); + int end = log.indexOf(">", start); + Assert.assertTrue(end > -1); + Assert.assertTrue(log.indexOf("tag1=\"" + tag1 + "\"", start) > -1); + Assert.assertTrue(log.indexOf("tag1=\"" + tag1 + "\"", start) < end); + Assert.assertTrue(log.indexOf("tag2=\"" + tag2 + "\"", start) > -1); + Assert.assertTrue(log.indexOf("tag2=\"" + tag2 + "\"", start) < end); + Assert.assertTrue(log.indexOf("svnurl=\"http://svn.apache.org/repos/" + + "asf/jakarta/bcel/\"", start) > -1); + Assert.assertTrue(log.indexOf("svnurl=\"http://svn.apache.org/repos/" + + "asf/jakarta/bcel/\"", start) < end); + } + + private static final void assertAdded(String log) { + int name = log.indexOf(""); + Assert.assertTrue(name > -1); + + int pathAfterName = log.indexOf("", name); + Assert.assertTrue(pathAfterName > -1); + + Assert.assertTrue(log.indexOf("added", name) > -1); + Assert.assertTrue(log.indexOf("added", name) + < pathAfterName); + } + + private static final void assertModified(String log) { + int name = log.indexOf(""); + Assert.assertTrue(name > -1); + + int pathAfterName = log.indexOf("", name); + Assert.assertTrue(pathAfterName > -1); + + Assert.assertTrue(log.indexOf("modified", name) > -1); + Assert.assertTrue(log.indexOf("modified", name) + < pathAfterName); + } + + private static final void assertDeleted(String log) { + int name = log.indexOf(""); + Assert.assertTrue(name > -1); + + int pathAfterName = log.indexOf("", name); + Assert.assertTrue(pathAfterName > -1); + + Assert.assertTrue(log.indexOf("deleted", name) > -1); + Assert.assertTrue(log.indexOf("deleted", name) + < pathAfterName); + } + + private static final void assertAdded1(String log) { + int name = log.indexOf(""); + Assert.assertTrue(name > -1); + + int pathAfterName = log.indexOf("", name); + Assert.assertTrue(pathAfterName > -1); + + Assert.assertTrue(log.indexOf("added", name) > -1); + Assert.assertTrue(log.indexOf("added", name) + < pathAfterName); + } + +}