@@ -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 r diff
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 <code>SvnRevisionEntry[]</code> 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("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
writer.print("<revisiondiff ");
if (mystartRevision != null) {
writer.print("start=\"" + mystartRevision + "\" ");
}
if (myendRevision != null) {
writer.print("end=\"" + myendRevision + "\" ");
}
if (getSvnURL() != null) {
writer.print("svnurl=\"" + getSvnURL() + "\" ");
}
writer.println(">");
for (int i = 0, c = entries.length; i < c; i++) {
writeRevisionEntry(writer, entries[i]);
}
writer.println("</revisiondiff>");
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 <code>PrintWriter</code> value
* @param entry a <code>SvnRevisionEntry</code> value
*/
private void writeRevisionEntry(PrintWriter writer, SvnEntry.Path entry) {
writer.println("\t<path>");
writer.println("\t\t<name><![CDATA[" + entry.getName() + "]]></name>");
writer.println("\t\t<action>" + entry.getActionDescription()
+ "</action>");
writer.println("\t</path>");
}
/**
* Validate the parameters specified for task.
*