Hi Dan,
Thanks a lot for looking into this.
I use the log task this way:
<!-- write the txt log -->
<svn>
<log path="${main.dir}"
firstRevision="${archive.latest.revision}"
lastRevision="${svn.revision}"
destFile="${tmp.dir}/Changes.txt"/>
</svn>
<!-- write the xml log -->
<svn>
<log path="${main.dir}"
firstRevision="${archive.latest.revision}"
lastRevision="${svn.revision}"
destFile="${change.dir}/Changes_${version.number}.xml"
xml="true"/>
</svn>
This allow me to gather all the log informations between the firstRevision
and the lastRevision and store them in a destFile. As I wanted the output to
be either in txt or xml format, I added the "xml" flag. That's where JDom
comes into play to generate a proper XML output. If you do not provide a
destFile, it should log the output in the ant console.
I mainly use this task to automatically build the changelog of my project
when I build it.
Cheers,
Nico
-----Original Message-----
From: Daniel Rall [mailto:dlr@finemaltcoding.com]
Sent: 28 February 2006 10:16
Cc: dev@subclipse.tigris.org
Subject: Re: [Subclipse-dev] svnant log task
Nico, can you provide a summary of how this code works? I glanced briefly
at the code, and see that you're using both JDom and svnClientAdapter, which
struck me as somewhat odd.
Thanks, Dan
On Fri, 11 Nov 2005, delhomme wrote:
> Hi again,
>
> Like for the info task, I needed a log task for svnant. I have found
> in the email archive an implementation of it, but it was not covering my
needs.
> Therefore, I extended it. Could you please check it (file attached)
> and tell me if the change I made are sensible for you. I would as well
> like to know when is the next svnant release planned and what new
> fuctionnalities we could expect.
>
> Thanks a lot,
>
> Cheers,
>
> Nico
> [-- octet-filter file type: "ASCII C program text" --]
>
> [-- Statistics (lines words chars): 260 825 7393 /tmp/Log.java --]
>
> /*
> * $Id: $
> */
> package org.tigris.subversion.svnant;
>
> import java.io.File;
> import java.io.FileWriter;
> import java.io.IOException;
> import java.text.ParseException;
> import java.text.SimpleDateFormat;
>
> import org.apache.tools.ant.BuildException;
> import org.jdom.CDATA;
> import org.jdom.Document;
> import org.jdom.Element;
> import org.jdom.output.Format;
> import org.jdom.output.XMLOutputter;
> import org.tigris.subversion.svnclientadapter.ISVNClientAdapter;
> import org.tigris.subversion.svnclientadapter.ISVNLogMessage;
> import
> org.tigris.subversion.svnclientadapter.ISVNLogMessageChangePath;
> import org.tigris.subversion.svnclientadapter.SVNClientException;
> import org.tigris.subversion.svnclientadapter.SVNRevision;
> import org.tigris.subversion.svnclientadapter.SVNUrl;
>
> /**
> * svn Log.
> *
> * @author delhomme <a href="mailto:nidelhomme@voila.fr">Nicolas
> Delhomme</a>
> * Created on 09-Nov-2005
> */
> public class Log extends SvnCommand {
>
> /** url */
> private SVNUrl url = null;
>
> /** working dir */
> private File path = null;
>
> /**
> * first revision
> * default value to revision START
> * */
> private SVNRevision firstRevision = SVNRevision.START;
>
> /**
> * last revision
> * default value to revision HEAD
> * */
> private SVNRevision lastRevision = SVNRevision.HEAD;
>
> /** destination file */
> private File destFile = null;
>
> /** format */
> private boolean xml = false;
>
> /** date format */
> protected static final SimpleDateFormat dateFormat = new
SimpleDateFormat(
> "yyyy-MM-dd HH:mm");
>
> public void execute(ISVNClientAdapter svnClient) throws
> BuildException {
>
> // check the attributes
> validateAttributes();
>
> // proceed
> log("Svn : Log");
> Document xmlDoc = null;
> Element root = null;
> FileWriter fileWriter = null;
>
> try {
>
> if (destFile != null) {
> log("Svn : Saving the Log in a file");
> if (xml) {
> log("Svn : In XML format");
> // create the xml doc
> xmlDoc = new Document();
> // create root element
> root = new Element("log");
> } else {
> log("Svn : In Txt format");
> }
> fileWriter = new FileWriter(destFile);
> }
>
> // get the log messages
> ISVNLogMessage[] logMessages = {};
> if (url != null){
> logMessages = svnClient.getLogMessages(url,
> lastRevision, firstRevision);
> } else {
> logMessages = svnClient.getLogMessages(path,
> lastRevision,
firstRevision);
> }
>
> // find the values
> for (int i = 0; i < logMessages.length; i++) {
>
> // find where to write the results
> if (destFile != null) {
>
> // write the results
> if (xml) {
> Element logentry = new
Element("logentry");
> logentry.addContent(new
Element("author").addContent(new CDATA(logMessages[i].getAuthor())));
> logentry.addContent(new
Element("date").addContent(new
CDATA(dateFormat.format(logMessages[i].getDate()))));
> SVNRevision.Number revision
= logMessages[i].getRevision();
> if (revision != null){
>
logentry.addContent(new Element("revision").addContent(new
CDATA(revision.toString())));
> }
> logentry.addContent(new
Element("message").addContent(new
> CDATA(logMessages[i].getMessage())));
>
> // get some more details
> ISVNLogMessageChangePath
changePaths[] = logMessages[i].getChangedPaths();
> for (int j = 0; j <
changePaths.length; j++) {
> // create root
element for one path entry
> Element pathentry =
new Element("pathentry");
>
> // add the data
>
pathentry.addContent(new
Element("path").addContent(changePaths[j].getPath()));
>
pathentry.addContent(new
Element("action").addContent(String.valueOf(changePaths[j].getAction())));
> String copySrcPath =
changePaths[j].getCopySrcPath();
> if (copySrcPath !=
null){
>
pathentry.addContent(new Element("copyfrom-path").addContent(copySrcPath));
> }
> SVNRevision.Number
copyRevision = changePaths[j].getCopySrcRevision();
> if (copyRevision !=
null){
>
pathentry.addContent(new
Element("copyfrom-rev").addContent(copyRevision.toString()));
> }
> //add it
>
logentry.addContent(pathentry);
> }
>
> // xml output
> root.addContent(logentry);
> } else {
> // text output
>
fileWriter.write(formatMessage(logMessages[i]));
> }
> } else {
> log(formatMessage(logMessages[i]));
> }
> }
>
> // clean up
> if (destFile != null) {
> if (xml) {
> xmlDoc.setRootElement(root);
> new
XMLOutputter(Format.getPrettyFormat()).output(xmlDoc, fileWriter);
> }
> fileWriter.close();
> }
> } catch (SVNClientException e) {
> throw new BuildException("Cannot get the log
messages", e);
> } catch (IOException e) {
> throw new BuildException("Cannot find the destFile",
e);
> }
> }
>
> /**
> * Ensure we have a consistent and legal set of attributes
> */
> protected void validateAttributes() throws BuildException {
> if (url == null && path == null)
> throw new BuildException("You must set either the
URL or the path.");
> if (firstRevision == null) {
> throw new BuildException(
> "Invalid revision. Revision should
be a number, a date in MM/DD/YYYY HH:MM AM_PM format or HEAD, BASE, COMMITED
or PREV");
> }
> if (lastRevision == null) {
> throw new BuildException(
> "Invalid revision. Revision should
be a number, a date in MM/DD/YYYY HH:MM AM_PM format or HEAD, BASE, COMMITED
or PREV");
> }
> }
>
> /**
> * Set the URL; required if no path.
> *
> * @param url
> * The url to set
> */
> public void setUrl(SVNUrl url) {
> this.url = url;
> }
>
> /**
> * Set the working path/file; required if no url.
> *
> * @param path
> * The path to set
> */
> public void setPath(File path) {
> this.path = path;
> }
>
> /**
> * Set the destination file; optionnal
> */
> public void setDestFile(File destFile) {
> this.destFile = destFile;
> }
>
> /**
> * Set the first revision, meaning the older one; optionnal; default
to revision.START
> *
> * @param revision
> */
> public void setFirstRevision(String revision) {
> try {
> this.firstRevision =
SVNRevision.getRevision(revision);
> } catch (ParseException e) {
> this.firstRevision = null;
> }
> }
>
> /**
> * Set the last revision, meaning the most recent one; optionnal;
default to revision.WORKING
> *
> * @param revision
> */
> public void setLastRevision(String revision) {
> try {
> this.lastRevision =
SVNRevision.getRevision(revision);
> } catch (ParseException e) {
> this.lastRevision = null;
> }
> }
>
> /**
> * Define if the file output has to be written in xml or txt. To be
used together with the destFile argument; optionnal; default to false
> */
> public void setXml(boolean bool) {
> this.xml = bool;
> }
>
> /*
> * Format the log message as a String.
> */
> private String formatMessage(ISVNLogMessage logMessage) {
> String string = "";
> string += "------------------------------\n";
> string += "Author: " + logMessage.getAuthor() + "\n";
> string += "Date: " +
dateFormat.format(logMessage.getDate()) + "\n";
> string += "Message: " + logMessage.getMessage().trim()+
"\n";
> string += "Files:\n";
> ISVNLogMessageChangePath changePaths[] =
logMessage.getChangedPaths();
> for (int i = 0; i < changePaths.length; i++) {
> string += "\t" + changePaths[i].getAction() + ": "
> + changePaths[i].getPath()+ "\n";
> String copySrcPath =
changePaths[i].getCopySrcPath();
> if (copySrcPath != null) {
> string += "From: " + copySrcPath+ "\n";
> }
> }
> return string;
> }
> }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@subclipse.tigris.org
> For additional commands, e-mail: dev-help@subclipse.tigris.org
--
Daniel Rall
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subclipse.tigris.org
For additional commands, e-mail: dev-help@subclipse.tigris.org
Received on Tue Feb 28 10:44:52 2006