Browse Source

org.apache.tools.ant.taskdefs.cvslib.CvsTagDiff

The goal of this task is to give a list of differences between two tags or
dates. It produces an xml report like the changelog report of the CvsChangeLog
task. The output gives the list of modified files, removed files and new files.

The proposed task name is cvstagdiff.

PR: 8086
Submitted by: fred@castify.net (Frederic Lavigne)


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272429 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Donald 23 years ago
parent
commit
784f04c929
6 changed files with 865 additions and 0 deletions
  1. +1
    -0
      build.xml
  2. +159
    -0
      docs/manual/CoreTasks/cvstagdiff.html
  3. +1
    -0
      docs/manual/coretasklist.html
  4. +7
    -0
      docs/manual/tasksoverview.html
  5. +162
    -0
      src/etc/tagdiff.xsl
  6. +535
    -0
      src/main/org/apache/tools/ant/taskdefs/cvslib/CvsTagDiff.java

+ 1
- 0
build.xml View File

@@ -790,6 +790,7 @@
<include name="jdepend-frames.xsl"/> <include name="jdepend-frames.xsl"/>
<include name="checkstyle-frames.xsl"/> <include name="checkstyle-frames.xsl"/>
<include name="log.xsl"/> <include name="log.xsl"/>
<include name="tagdiff.xsl"/>
</fileset> </fileset>
</copy> </copy>




+ 159
- 0
docs/manual/CoreTasks/cvstagdiff.html View File

@@ -0,0 +1,159 @@
<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<title>CvsTagDiff Task</title>
</head>

<body>

<h2><a name="cvstagdiff">CvsTagDiff</a></h2>
<h3>Description</h3>
<p>Generates an XML-formatted report file of the changes between two tags or dates recorded in a
<a href="http://www.cvshome.org/" target="_top">CVS</a> repository. </p>
<h3>Parameters</h3>
<table border="1" cellpadding="2" cellspacing="0">
<tr>
<td valign="top"><b>Attribute</b></td>
<td valign="top"><b>Description</b></td>
<td align="center" valign="top"><b>Required</b></td>
</tr>
<tr>
<td valign="top">startTag</td>
<td valign="top">The earliest tag from which diffs are to be
included in the report.</td>
<td align="center" valign="top" rowspan="2">exactly one of the two.</td>
</tr>
<tr>
<td valign="top">startDate</td>
<td valign="top">The earliest date from which diffs are to be
included in the report.</td>
</tr>
<tr>
<td valign="top">endTag</td>
<td valign="top">The latest tag from which diffs are to be
included in the report.</td>
<td align="center" valign="top" rowspan="2">exactly one of the two.</td>
</tr>
<tr>
<td valign="top">endDate</td>
<td valign="top">The latest date from which diffs are to be
included in the report.</td>
</tr>
<tr>
<td valign="top">destfile</td>
<td valign="top">The file in which to write the diff report.</td>
<td align="center" valign="top">Yes</td>
</tr>
</table>

<h3>Parameters inherited from the <code>cvs</code> task</h3>
<table border="1" cellpadding="2" cellspacing="0">
<tr>
<td valign="top"><b>Attribute</b></td>
<td valign="top"><b>Description</b></td>
<td align="center" valign="top"><b>Required</b></td>
</tr>
<tr>
<td valign="top">compression</td>
<td valign="top"><code>true</code>, <code>false</code>, or the number 1-9 (corresponding to possible values for CVS <code>-z#</code> argument). Any other value is treated as false</td>
<td align="center" valign="top">No. Defaults to no compression. if passed <code>true</code>, level 3 compression is assumed.</td>
</tr>
<tr>
<td valign="top">cvsRoot</td>
<td valign="top">the CVSROOT variable.</td>
<td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">cvsRsh</td>
<td valign="top">the CVS_RSH variable.</td>
<td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">package</td>
<td valign="top">the package/module to analyze.</td>
<td align="center" valign="top">Yes</td>
</tr>
<tr>
<td valign="top">quiet</td>
<td valign="top">suppress informational messages.</td>
<td align="center" valign="top">No, default &quot;false&quot;</td>
</tr>
<tr>
<td valign="top">port</td>
<td valign="top">Port used by CVS to communicate with the server.</td>
<td align="center" valign="top">No, default port 2401.</td>
</tr>
<tr>
<td valign="top">passfile</td>
<td valign="top">Password file to read passwords from.</td>
<td align="center" valign="top">No, default file ~/.cvspass.</td>
</tr>
<tr>
<td valign="top">failonerror</td>
<td valign="top">Stop the buildprocess if the command exits with a
returncode other than 0. Defaults to false</td>
<td align="center" valign="top">No</td>
</tr>
</table>

<h3>Examples</h3>
<pre> &lt;cvstagdiff cvsRoot=&quot;:pserver:anoncvs@cvs.apache.org:/home/cvspublic&quot;
destfile=&quot;tagdiff.xml&quot;
package=&quot;jakarta-ant&quot;
startTag=&quot;ANT_14&quot;
endTag=&quot;ANT_141&quot;
/&gt;</pre>

<p>Generates a tagdiff report for all the changes that have been made
in the <code>jakarta-ant</code> module between the tags <code>ANT_14</code> and <code>ANT_141</code>.
It writes these changes into the file <code>tagdiff.xml</code>.</p>

<pre> &lt;cvstagdiff
destfile=&quot;tagdiff.xml&quot;
package=&quot;jakarta-ant&quot;
startDate=&quot;2002-01-01&quot;
endDate=&quot;2002-31-01&quot;
/&gt;</pre>

<p>Generates a tagdiff report for all the changes that have been made
in the <code>jakarta-ant</code> module in january 2002. In this example <code>cvsRoot</code>
has not been set. The current <code>cvsRoot</code> will be used (assuming the build is started
from a folder stored in <code>cvs</code>.
It writes these changes into the file <code>tagdiff.xml</code>.</p>

<h4>Generate Report</h4>
<p>Ant 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.</p>

<pre>
&lt;style in="tagdiff.xml"
out="tagdiff.html"
style="${ant.home}/etc/tagdiff.xsl"&gt;
&lt;param name="title" expression="Ant Diff"/&gt;
&lt;param name="module" expression="jakarta-ant"/&gt;
&lt;param name="cvsweb" expression="http://cvs.apache.org/viewcvs/"/&gt;
&lt;/style&gt;
</pre>

<h4>Sample Output</h4>
<pre>
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;tagdiff startTag=&quot;ANT_14&quot; endTag=&quot;ANT_141&quot;&gt;
&lt;entry&gt;
&lt;file&gt;
&lt;name&gt;src/main/org/apache/tools/ant/DirectoryScanner.java&lt;/name&gt;
&lt;revision&gt;1.15.2.1&lt;/revision&gt;
&lt;prevrevision&gt;1.15&lt;/prevrevision&gt;
&lt;/file&gt;
&lt;/entry&gt;
&lt;/tagdiff&gt;
</pre>

<hr><p align="center">Copyright &copy; 2002 Apache Software Foundation. All rights
Reserved.</p>

</body>
</html>


+ 1
- 0
docs/manual/coretasklist.html View File

@@ -33,6 +33,7 @@
<a href="CoreTasks/cvs.html">Cvs</a><br> <a href="CoreTasks/cvs.html">Cvs</a><br>
<a href="CoreTasks/changelog.html">CvsChangeLog</a><br> <a href="CoreTasks/changelog.html">CvsChangeLog</a><br>
<a href="CoreTasks/cvspass.html">CVSPass</a><br> <a href="CoreTasks/cvspass.html">CVSPass</a><br>
<a href="CoreTasks/cvstagdiff.html">CvsTagDiff</a><br>
<a href="CoreTasks/delete.html">Delete</a><br> <a href="CoreTasks/delete.html">Delete</a><br>
<a href="CoreTasks/deltree.html"><i>Deltree</i></a><br> <a href="CoreTasks/deltree.html"><i>Deltree</i></a><br>
<a href="CoreTasks/dependset.html">Dependset</a><br> <a href="CoreTasks/dependset.html">Dependset</a><br>


+ 7
- 0
docs/manual/tasksoverview.html View File

@@ -959,6 +959,13 @@ documentation.</p>
has the same affect as a <i>cvs login</i> command.</p></td> has the same affect as a <i>cvs login</i> command.</p></td>
</tr> </tr>


<tr valign="top">
<td nowrap><a href="CoreTasks/cvstagdiff.html">CvsTagDiff</a></td>
<td><p>Generates an XML-formatted report file of the changes between
two tags or dates recorded in a <a href="http://www.cvshome.org/"
target="_top">CVS</a> repository.</p></td>
</tr>

<tr valign="top"> <tr valign="top">
<td nowrap><a href="OptionalTasks/clearcase.html">ClearCase</a></td> <td nowrap><a href="OptionalTasks/clearcase.html">ClearCase</a></td>
<td><p>Tasks to perform the ClearCase <i>cccheckin</i>, <i>cccheckout</i>, <td><p>Tasks to perform the ClearCase <i>cccheckin</i>, <i>cccheckout</i>,


+ 162
- 0
src/etc/tagdiff.xsl View File

@@ -0,0 +1,162 @@
<!-- a stylesheet to display changelogs ala netbeans -->
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:param name="title"/>
<xsl:param name="module"/>
<xsl:param name="cvsweb"/>

<xsl:output method="html" indent="yes"/>

<!-- Copy standard document elements. Elements that
should be ignored must be filtered by apply-templates
tags. -->
<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="attribute::*[. != '']"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>

<xsl:template match="tagdiff">
<HTML>
<HEAD>
<TITLE><xsl:value-of select="$title"/></TITLE>
</HEAD>
<BODY link="#000000" alink="#000000" vlink="#000000" text="#000000">
<style type="text/css">
body, p {
font-family: verdana,arial,helvetica;
font-size: 80%;
color:#000000;
}
.dateAndAuthor {
font-family: verdana,arial,helvetica;
font-size: 80%;
font-weight: bold;
text-align:left;
background:#a6caf0;
}
tr, td{
font-family: verdana,arial,helvetica;
font-size: 80%;
background:#eeeee0;
}
</style>
<h1>
<a name="top"><xsl:value-of select="$title"/></a>
</h1>
Tagdiff between <xsl:value-of select="@startTag"/> <xsl:value-of select="@startDate"/> and
<xsl:value-of select="@endTag"/> <xsl:value-of select="@endDate"/>
<p align="right">Designed for use with <a href="http://jakarta.apache.org">Ant</a>.</p>
<hr size="2"/>
<a name="TOP"/>
<table width="100%">
<tr>
<td align="right">
<a href="#New">New Files</a> |
<a href="#Modified">Modified Files</a> |
<a href="#Removed">Removed Files</a>
</td>
</tr>
</table>
<TABLE BORDER="0" WIDTH="100%" CELLPADDING="3" CELLSPACING="1">
<xsl:call-template name="show-entries">
<xsl:with-param name="title">New Files</xsl:with-param>
<xsl:with-param name="anchor">New</xsl:with-param>
<xsl:with-param name="entries" select=".//entry[file/revision][not(file/prevrevision)]"/>
</xsl:call-template>

<xsl:call-template name="show-entries">
<xsl:with-param name="title">Modified Files</xsl:with-param>
<xsl:with-param name="anchor">Modified</xsl:with-param>
<xsl:with-param name="entries" select=".//entry[file/revision][file/prevrevision]"/>
</xsl:call-template>

<xsl:call-template name="show-entries">
<xsl:with-param name="title">Removed Files</xsl:with-param>
<xsl:with-param name="anchor">Removed</xsl:with-param>
<xsl:with-param name="entries" select=".//entry[not(file/revision)][not(file/prevrevision)]"/>
</xsl:call-template>
</TABLE>
</BODY>
</HTML>
</xsl:template>

<xsl:template name="show-entries">
<xsl:param name="title"/>
<xsl:param name="anchor"/>
<xsl:param name="entries"/>
<TR>
<TD colspan="2" class="dateAndAuthor">
<a>
<xsl:attribute name="name"><xsl:value-of select="$anchor"/></xsl:attribute>
<xsl:value-of select="$title"/> - <xsl:value-of select="count($entries)"/> entries
</a>
<a href="#TOP">(back to top)</a>
</TD>
</TR>
<TR>
<TD width="20">
<xsl:text> </xsl:text>
</TD>
<TD>
<ul>
<xsl:apply-templates select="$entries"/>
</ul>
</TD>
</TR>
</xsl:template>

<xsl:template match="entry">
<xsl:apply-templates select="file"/>
</xsl:template>

<xsl:template match="date">
<i><xsl:value-of select="."/></i>
</xsl:template>

<xsl:template match="time">
<i><xsl:value-of select="."/></i>
</xsl:template>

<xsl:template match="author">
<i>
<a>
<xsl:attribute name="href">mailto:<xsl:value-of select="."/></xsl:attribute>
<xsl:value-of select="."/>
</a>
</i>
</xsl:template>

<xsl:template match="file">
<li>
<a target="_new">
<xsl:attribute name="href"><xsl:value-of select="$cvsweb"/><xsl:value-of select="$module" />/<xsl:value-of select="name" /></xsl:attribute>
<xsl:value-of select="name" />
</a>
<xsl:if test="string-length(prevrevision) > 0 or string-length(revision) > 0">
<xsl:text> </xsl:text>
<a target="_new">
<xsl:choose>
<xsl:when test="string-length(prevrevision) = 0 ">
<xsl:attribute name="href"><xsl:value-of select="$cvsweb"/><xsl:value-of select="$module" />/<xsl:value-of select="name" />?rev=<xsl:value-of select="revision" />&amp;content-type=text/x-cvsweb-markup</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="href"><xsl:value-of select="$cvsweb"/><xsl:value-of select="$module" />/<xsl:value-of select="name" />?r1=<xsl:value-of select="revision" />&amp;r2=<xsl:value-of select="prevrevision"/>&amp;diff_format=h</xsl:attribute>
</xsl:otherwise>
</xsl:choose> (<xsl:value-of select="revision"/>)
</a>
</xsl:if>
</li>
</xsl:template>

<!-- Any elements within a msg are processed,
so that we can preserve HTML tags. -->
<xsl:template match="msg">
<b><xsl:apply-templates/></b>
</xsl:template>
</xsl:stylesheet>

+ 535
- 0
src/main/org/apache/tools/ant/taskdefs/cvslib/CvsTagDiff.java View File

@@ -0,0 +1,535 @@
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Ant", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.tools.ant.taskdefs.cvslib;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.taskdefs.Cvs;
import org.apache.tools.ant.util.FileUtils;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.Enumeration;
import java.util.Vector;

/**
* Cvs tag diff.
* The task will examine the output of cvs rdiff between two tags.
* It produces an XML output representing the list of changes.
* <PRE>
* &lt;!-- Root element --&gt;
* &lt;!ELEMENT tagdiff ( entry+ ) &gt;
* &lt;!-- Start tag of the report --&gt;
* &lt;!ATTLIST tagdiff startTag NMTOKEN #IMPLIED &gt;
* &lt;!-- End tag of the report --&gt;
* &lt;!ATTLIST tagdiff endTag NMTOKEN #IMPLIED &gt;
* &lt;!-- Start date of the report --&gt;
* &lt;!ATTLIST tagdiff startDate NMTOKEN #IMPLIED &gt;
* &lt;!-- End date of the report --&gt;
* &lt;!ATTLIST tagdiff endDate NMTOKEN #IMPLIED &gt;
*
* &lt;!-- CVS tag entry --&gt;
* &lt;!ELEMENT entry ( file ) &gt;
* &lt;!-- File added, changed or removed --&gt;
* &lt;!ELEMENT file ( name, revision?, prevrevision? ) &gt;
* &lt;!-- Name of the file --&gt;
* &lt;!ELEMENT name ( #PCDATA ) &gt;
* &lt;!-- Revision number --&gt;
* &lt;!ELEMENT revision ( #PCDATA ) &gt;
* &lt;!-- Previous revision number --&gt;
* &lt;!ELEMENT prevrevision ( #PCDATA ) &gt;
* </PRE>
*
* @author <a href="mailto:fred@castify.net">Frederic Lavigne</a>
* @version $Revision$ $Date$
* @ant.task name="cvstagdiff"
*/
public class CvsTagDiff extends Task {
/**
* Token to identify a new file in the rdiff log
*/
static final String FILE_IS_NEW = " is new; current revision ";
/**
* Token to identify a modified file in the rdiff log
*/
static final String FILE_HAS_CHANGED = " changed from revision ";
/**
* Token to identify a removed file in the rdiff log
*/
static final String FILE_WAS_REMOVED = " is removed";
/**
* The cvs task which will perform the rdiff.
*/
private Cvs m_cvs;

/**
* The cvs package/module to analyse
*/
private String m_package;

/**
* The earliest tag from which diffs are to be included in the report.
*/
private String m_startTag;
/**
* The latest tag from which diffs are to be included in the report.
*/
private String m_endTag;

/**
* The earliest date from which diffs are to be included in the report.
*/
private String m_startDate;
/**
* The latest date from which diffs are to be included in the report.
*/
private String m_endDate;
/**
* The file in which to write the diff report.
*/
private File m_destfile;
/**
* Used to create the temp file for cvs log
*/
private FileUtils m_fileUtils = FileUtils.newFileUtils();
/**
* Initialize this task.
* CvsTagDiff initializes a member cvs task in init() to perform the rdiff in execute().
*
* @exception BuildException if an error occurs
*/
public void init() throws BuildException {
m_cvs = (Cvs)getProject().createTask("cvs");
}
/**
* @see org.apache.tools.ant.taskdefs.AbstractCvsTask#setCompressionLevel(int)
*/
public void setCompressionLevel(int level) {
m_cvs.setCompressionLevel(level);
}

/**
* @see org.apache.tools.ant.taskdefs.AbstractCvsTask#setCompression(boolean)
*/
public void setCompression(boolean usecomp) {
m_cvs.setCompression(usecomp);
}

/**
* @see org.apache.tools.ant.taskdefs.AbstractCvsTask#setCvsRoot
*/
public void setCvsRoot(String cvsRoot) {
m_cvs.setCvsRoot(cvsRoot);
}

/**
* @see org.apache.tools.ant.taskdefs.AbstractCvsTask#setCvsRsh
*/
public void setCvsRsh(String rsh) {
m_cvs.setCvsRsh(rsh);
}

/**
* @see org.apache.tools.ant.taskdefs.AbstractCvsTask#setPackage
*/
public void setPackage(String p) {
m_package = p;
}

/**
* @see org.apache.tools.ant.taskdefs.AbstractCvsTask#setQuiet
*/
public void setQuiet(boolean quiet) {
m_cvs.setQuiet(quiet);
}

/**
* @see org.apache.tools.ant.taskdefs.AbstractCvsTask#setPort
*/
public void setPort(int port) {
m_cvs.setPort(port);
}

/**
* @see org.apache.tools.ant.taskdefs.AbstractCvsTask#setPassfile
*/
public void setPassfile(File f) {
m_cvs.setPassfile(f);
}

/**
* @see org.apache.tools.ant.taskdefs.AbstractCvsTask#setFailOnError
*/
public void setFailOnError(boolean b) {
m_cvs.setFailOnError(b);
}

/**
* Set the start tag.
*
* @param s the start tag.
*/
public void setStartTag(String s) {
m_startTag = s;
}

/**
* Set the start date.
*
* @param s the start date.
*/
public void setStartDate(String s) {
m_startDate = s;
}

/**
* Set the end tag.
*
* @param s the end tag.
*/
public void setEndTag(String s) {
m_endTag = s;
}
/**
* Set the end date.
*
* @param s the end date.
*/
public void setEndDate(String s) {
m_endDate = s;
}

/**
* Set the output file for the diff.
*
* @param f the output file for the diff.
*/
public void setDestFile(File f) {
m_destfile = f;
}
/**
* Execute task.
*
* @exception BuildException if an error occurs
*/
public void execute() throws BuildException {
// validate the input parameters
validate();
// build the rdiff command
String rdiff = "rdiff -s " +
(m_startTag!=null?("-r " + m_startTag):("-D " + m_startDate)) + " " +
(m_endTag!=null?("-r " + m_endTag):("-D " + m_endDate)) + " " +
m_package;
log("Cvs command is " + rdiff, Project.MSG_VERBOSE);
m_cvs.setCommand(rdiff);

File tmpFile = null;
try {
tmpFile = m_fileUtils.createTempFile("cvstagdiff", ".log", null);
m_cvs.setOutput(tmpFile);
// run the cvs command
m_cvs.execute();

// parse the rdiff
CvsTagEntry[] entries = parseRDiff(tmpFile);

// write the tag diff
writeTagDiff(entries);

} finally {
if (tmpFile != null) {
tmpFile.delete();
}
}
}
/**
* Parse the tmpFile and return and array of CvsTagEntry to be written in the output.
*
* @param tmpFile the File containing the output of the cvs rdiff command
* @return the entries in the output
* @exception BuildException if an error occurs
*/
private CvsTagEntry[] parseRDiff(File tmpFile) throws BuildException {
// parse the output of the command
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(tmpFile));
// entries are of the form:
// File module/filename is new; current revision 1.1
// or
// File module/filename changed from revision 1.4 to 1.6
// or
// File module/filename is removed; not included in release tag SKINLF_12
int headerLength = 5 + m_package.length() + 1; // get rid of 'File module/"
Vector entries = new Vector();
String line = reader.readLine();
int index;
CvsTagEntry entry = null;
while (null != line) {
line = line.substring(headerLength);
if ((index = line.indexOf(FILE_IS_NEW)) != -1) {
// it is a new file
// set the revision but not the prevrevision
String filename = line.substring(0, index);
String rev = line.substring(index + FILE_IS_NEW.length());
entries.add(entry = new CvsTagEntry(filename, rev));
log(entry.toString(), Project.MSG_VERBOSE);
} else if ((index = line.indexOf(FILE_HAS_CHANGED)) != -1) {
// it is a modified file
// set the revision and the prevrevision
String filename = line.substring(0, index);
int revSeparator = line.indexOf(" to ", index);
String prevRevision = line.substring(index + FILE_HAS_CHANGED.length(), revSeparator);
String revision = line.substring(revSeparator + 4); // 4 is " to " length
entries.add(entry = new CvsTagEntry(filename, revision, prevRevision));
log(entry.toString(), Project.MSG_VERBOSE);
} else if ((index = line.indexOf(FILE_WAS_REMOVED)) != -1) {
// it is a removed file
String filename = line.substring(0, index);
entries.add(entry = new CvsTagEntry(filename));
log(entry.toString(), Project.MSG_VERBOSE);
}
line = reader.readLine();
}
CvsTagEntry[] array = new CvsTagEntry[entries.size()];
entries.copyInto(array);
return array;
} catch (IOException e) {
throw new BuildException("Error in parsing", e);
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
}
}
}
}

/**
* Write the rdiff log.
*
* @param entries a <code>CvsTagEntry[]</code> value
* @exception BuildException if an error occurs
*/
private void writeTagDiff(CvsTagEntry[] entries) throws BuildException {
FileOutputStream output = null;
try {
output = new FileOutputStream(m_destfile);
PrintWriter writer = new PrintWriter(new OutputStreamWriter(output, "UTF-8"));
writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
writer.print("<tagdiff ");
if (m_startTag != null) {
writer.print("startTag=\"" + m_startTag + "\" ");
} else {
writer.print("startDate=\"" + m_startDate + "\" ");
}
if (m_endTag != null) {
writer.print("endTag=\"" + m_endTag + "\" ");
} else {
writer.print("endDate=\"" + m_endDate + "\" ");
}
writer.println(">");
for (int i = 0, c = entries.length; i < c; i++) {
writeTagEntry(writer, entries[i]);
}
writer.println("</tagdiff>");
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) { }
}
}
}
/**
* Write a single entry to the given writer.
*
* @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>");
if (entry.getRevision() != null) {
writer.println("\t\t\t<revision>" + entry.getRevision() + "</revision>");
}
if (entry.getPreviousRevision() != null) {
writer.println("\t\t\t<prevrevision>" + entry.getPreviousRevision() + "</prevrevision>");
}
writer.println("\t\t</file>");
writer.println("\t</entry>");
}
/**
* Validate the parameters specified for task.
*
* @exception BuildException if a parameter is not correctly set
*/
private void validate() throws BuildException {
if (null == m_package) {
throw new BuildException("Package/module must be set.");
}
if (null == m_destfile) {
throw new BuildException("Destfile must be set.");
}
if (null == m_startTag && null == m_startDate) {
throw new BuildException("Start tag or start date must be set.");
}

if (null != m_startTag && null != m_startDate) {
throw new BuildException("Only one of start tag and start date must be set.");
}
if (null == m_endTag && null == m_endDate) {
throw new BuildException("End tag or end date must be set.");
}

if (null != m_endTag && null != m_endDate) {
throw new BuildException("Only one of end tag and end date must be set.");
}
}
/**
* Holds the information of a line of rdiff
*/
static class CvsTagEntry {
String m_filename;
String m_prevRevision;
String m_revision;

public CvsTagEntry(String filename) {
this(filename, null, null);
}

public CvsTagEntry(String filename, String revision) {
this(filename, revision, null);
}

public CvsTagEntry(String filename, String revision, String prevRevision) {
m_filename = filename;
m_revision = revision;
m_prevRevision = prevRevision;
}

public String getFile() {
return m_filename;
}

public String getRevision() {
return m_revision;
}

public String getPreviousRevision() {
return m_prevRevision;
}

public String toString() {
StringBuffer buffer = new StringBuffer();
buffer.append(m_filename);
if ((m_revision == null) && (m_prevRevision == null)) {
buffer.append(" was removed");
} else if (m_revision != null && m_prevRevision == null) {
buffer.append(" is new; current revision is ").append(m_revision);
} else if (m_revision != null && m_prevRevision != null) {
buffer.append(" has changed from ").append(m_prevRevision).append(" to ").append(m_revision);
}
return buffer.toString();
}
}

}

Loading…
Cancel
Save