|
@@ -0,0 +1,353 @@ |
|
|
|
|
|
/* |
|
|
|
|
|
* 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 java.io.File; |
|
|
|
|
|
import java.io.FileInputStream; |
|
|
|
|
|
import java.io.FileOutputStream; |
|
|
|
|
|
import java.io.IOException; |
|
|
|
|
|
import java.io.OutputStreamWriter; |
|
|
|
|
|
import java.io.PrintWriter; |
|
|
|
|
|
import java.io.UnsupportedEncodingException; |
|
|
|
|
|
import java.util.Date; |
|
|
|
|
|
import java.util.Enumeration; |
|
|
|
|
|
import java.util.Properties; |
|
|
|
|
|
import java.util.Vector; |
|
|
|
|
|
import org.apache.tools.ant.BuildException; |
|
|
|
|
|
import org.apache.tools.ant.Project; |
|
|
|
|
|
import org.apache.tools.ant.Task; |
|
|
|
|
|
import org.apache.tools.ant.taskdefs.Execute; |
|
|
|
|
|
import org.apache.tools.ant.types.Commandline; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Change log task. |
|
|
|
|
|
* The task will examine the output of cvs log and group related changes together. |
|
|
|
|
|
* It produces an XML output representing the list of changes. |
|
|
|
|
|
* <PRE> |
|
|
|
|
|
* <FONT color=#0000ff><!-- Root element --></FONT> |
|
|
|
|
|
* <FONT color=#6a5acd><!ELEMENT</FONT> changelog <FONT color=#ff00ff>(entry</FONT><FONT color=#ff00ff>+</FONT><FONT color=#ff00ff>)</FONT><FONT color=#6a5acd>></FONT> |
|
|
|
|
|
* <FONT color=#0000ff><!-- CVS Entry --></FONT> |
|
|
|
|
|
* <FONT color=#6a5acd><!ELEMENT</FONT> entry <FONT color=#ff00ff>(date,author,file</FONT><FONT color=#ff00ff>+</FONT><FONT color=#ff00ff>,msg)</FONT><FONT color=#6a5acd>></FONT> |
|
|
|
|
|
* <FONT color=#0000ff><!-- Date of cvs entry --></FONT> |
|
|
|
|
|
* <FONT color=#6a5acd><!ELEMENT</FONT> date <FONT color=#ff00ff>(#PCDATA)</FONT><FONT color=#6a5acd>></FONT> |
|
|
|
|
|
* <FONT color=#0000ff><!-- Author of change --></FONT> |
|
|
|
|
|
* <FONT color=#6a5acd><!ELEMENT</FONT> author <FONT color=#ff00ff>(#PCDATA)</FONT><FONT color=#6a5acd>></FONT> |
|
|
|
|
|
* <FONT color=#0000ff><!-- List of files affected --></FONT> |
|
|
|
|
|
* <FONT color=#6a5acd><!ELEMENT</FONT> msg <FONT color=#ff00ff>(#PCDATA)</FONT><FONT color=#6a5acd>></FONT> |
|
|
|
|
|
* <FONT color=#0000ff><!-- File changed --></FONT> |
|
|
|
|
|
* <FONT color=#6a5acd><!ELEMENT</FONT> file <FONT color=#ff00ff>(name,revision,prevrevision</FONT><FONT color=#ff00ff>?</FONT><FONT color=#ff00ff>)</FONT><FONT color=#6a5acd>></FONT> |
|
|
|
|
|
* <FONT color=#0000ff><!-- Name of the file --></FONT> |
|
|
|
|
|
* <FONT color=#6a5acd><!ELEMENT</FONT> name <FONT color=#ff00ff>(#PCDATA)</FONT><FONT color=#6a5acd>></FONT> |
|
|
|
|
|
* <FONT color=#0000ff><!-- Revision number --></FONT> |
|
|
|
|
|
* <FONT color=#6a5acd><!ELEMENT</FONT> revision <FONT color=#ff00ff>(#PCDATA)</FONT><FONT color=#6a5acd>></FONT> |
|
|
|
|
|
* <FONT color=#0000ff><!-- Previous revision number --></FONT> |
|
|
|
|
|
* <FONT color=#6a5acd><!ELEMENT</FONT> prevrevision <FONT color=#ff00ff>(#PCDATA)</FONT><FONT color=#6a5acd>></FONT> |
|
|
|
|
|
* </PRE> |
|
|
|
|
|
* |
|
|
|
|
|
* @author <a href="mailto:jeff.martin@synamic.co.uk">Jeff Martin</a> |
|
|
|
|
|
* @author <a href="mailto:peter@apache.org">Peter Donald</a> |
|
|
|
|
|
* @version $Revision$ $Date$ |
|
|
|
|
|
* @ant.task name="changelog" |
|
|
|
|
|
*/ |
|
|
|
|
|
public class ChangeLogTask |
|
|
|
|
|
extends Task |
|
|
|
|
|
{ |
|
|
|
|
|
/** User list */ |
|
|
|
|
|
private File m_usersFile; |
|
|
|
|
|
|
|
|
|
|
|
/** User list */ |
|
|
|
|
|
private Vector m_cvsUsers = new Vector(); |
|
|
|
|
|
|
|
|
|
|
|
/** Input dir */ |
|
|
|
|
|
private File m_basedir; |
|
|
|
|
|
|
|
|
|
|
|
/** Output file */ |
|
|
|
|
|
private File m_destfile; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* The earliest date at which to start processing entrys. |
|
|
|
|
|
*/ |
|
|
|
|
|
private Date m_start; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* The latest date at which to stop processing entrys. |
|
|
|
|
|
*/ |
|
|
|
|
|
private Date m_stop; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Set the base dir for cvs. |
|
|
|
|
|
*/ |
|
|
|
|
|
public void setBasedir( final File basedir ) |
|
|
|
|
|
{ |
|
|
|
|
|
m_basedir = basedir; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Set the output file for the log. |
|
|
|
|
|
*/ |
|
|
|
|
|
public void setDestfile( final File destfile ) |
|
|
|
|
|
{ |
|
|
|
|
|
m_destfile = destfile; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Set a lookup list of user names & addresses |
|
|
|
|
|
*/ |
|
|
|
|
|
public void setUsersfile( final File usersFile ) |
|
|
|
|
|
{ |
|
|
|
|
|
m_usersFile = usersFile; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Add a user to list changelog knows about. |
|
|
|
|
|
* |
|
|
|
|
|
* @param user the user |
|
|
|
|
|
*/ |
|
|
|
|
|
public void addUser( final CvsUser user ) |
|
|
|
|
|
{ |
|
|
|
|
|
m_cvsUsers.addElement( user ); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Set the date at which the changelog should start. |
|
|
|
|
|
* |
|
|
|
|
|
* @param start The date at which the changelog should start. |
|
|
|
|
|
*/ |
|
|
|
|
|
public void setStart( final Date start ) |
|
|
|
|
|
{ |
|
|
|
|
|
m_start = start; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Set the date at which the changelog should stop. |
|
|
|
|
|
* |
|
|
|
|
|
* @param stop The date at which the changelog should stop. |
|
|
|
|
|
*/ |
|
|
|
|
|
public void setEnd( final Date stop ) |
|
|
|
|
|
{ |
|
|
|
|
|
m_stop = stop; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Execute task |
|
|
|
|
|
*/ |
|
|
|
|
|
public void execute() throws BuildException |
|
|
|
|
|
{ |
|
|
|
|
|
validate(); |
|
|
|
|
|
|
|
|
|
|
|
final Properties userList = new Properties(); |
|
|
|
|
|
|
|
|
|
|
|
loadUserlist( userList ); |
|
|
|
|
|
|
|
|
|
|
|
for( Enumeration e = m_cvsUsers.elements(); e.hasMoreElements(); ) |
|
|
|
|
|
{ |
|
|
|
|
|
final CvsUser user = (CvsUser)e.nextElement(); |
|
|
|
|
|
user.validate(); |
|
|
|
|
|
userList.put( user.getUserID(), user.getDisplayname() ); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
final Commandline command = new Commandline(); |
|
|
|
|
|
command.setExecutable( "cvs" ); |
|
|
|
|
|
command.createArgument().setValue( "log" ); |
|
|
|
|
|
|
|
|
|
|
|
final ChangeLogParser parser = new ChangeLogParser( userList ); |
|
|
|
|
|
final RedirectingStreamHandler handler = |
|
|
|
|
|
new RedirectingStreamHandler( parser ); |
|
|
|
|
|
final Execute exe = new Execute( handler ); |
|
|
|
|
|
exe.setWorkingDirectory( m_basedir ); |
|
|
|
|
|
exe.setCommandline( command.getCommandline() ); |
|
|
|
|
|
exe.setAntRun( getProject() ); |
|
|
|
|
|
try |
|
|
|
|
|
{ |
|
|
|
|
|
final int resultCode = exe.execute(); |
|
|
|
|
|
if( 0 != resultCode ) |
|
|
|
|
|
{ |
|
|
|
|
|
throw new BuildException( "Error running cvs log" ); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
catch( final IOException ioe ) |
|
|
|
|
|
{ |
|
|
|
|
|
throw new BuildException( ioe.toString() ); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
final CVSEntry[] entrySet = parser.getEntrySetAsArray(); |
|
|
|
|
|
final CVSEntry[] filteredEntrySet = filterEntrySet( entrySet ); |
|
|
|
|
|
writeChangeLog( filteredEntrySet ); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Validate the parameters specified for task. |
|
|
|
|
|
* |
|
|
|
|
|
* @throws BuildException if fails validation checks |
|
|
|
|
|
*/ |
|
|
|
|
|
private void validate() |
|
|
|
|
|
throws BuildException |
|
|
|
|
|
{ |
|
|
|
|
|
if( null == m_basedir ) |
|
|
|
|
|
{ |
|
|
|
|
|
final String message = "Basedir must be set."; |
|
|
|
|
|
throw new BuildException( message ); |
|
|
|
|
|
} |
|
|
|
|
|
if( null == m_destfile ) |
|
|
|
|
|
{ |
|
|
|
|
|
final String message = "Destfile must be set."; |
|
|
|
|
|
throw new BuildException( message ); |
|
|
|
|
|
} |
|
|
|
|
|
if( !m_basedir.exists() ) |
|
|
|
|
|
{ |
|
|
|
|
|
final String message = "Cannot find base dir " + m_basedir.getAbsolutePath(); |
|
|
|
|
|
throw new BuildException( message ); |
|
|
|
|
|
} |
|
|
|
|
|
if( null != m_usersFile && !m_usersFile.exists() ) |
|
|
|
|
|
{ |
|
|
|
|
|
final String message = "Cannot find user lookup list " + m_usersFile.getAbsolutePath(); |
|
|
|
|
|
throw new BuildException( message ); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Load the userli4st from the userList file (if specified) and |
|
|
|
|
|
* add to list of users. |
|
|
|
|
|
* |
|
|
|
|
|
* @throws BuildException if file can not be loaded for some reason |
|
|
|
|
|
*/ |
|
|
|
|
|
private void loadUserlist( final Properties userList ) |
|
|
|
|
|
throws BuildException |
|
|
|
|
|
{ |
|
|
|
|
|
if( null != m_usersFile ) |
|
|
|
|
|
{ |
|
|
|
|
|
try |
|
|
|
|
|
{ |
|
|
|
|
|
userList.load( new FileInputStream( m_usersFile ) ); |
|
|
|
|
|
} |
|
|
|
|
|
catch( final IOException ioe ) |
|
|
|
|
|
{ |
|
|
|
|
|
throw new BuildException( ioe.toString(), ioe ); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Filter the specified entrys accoridn to an appropriate |
|
|
|
|
|
* rule. |
|
|
|
|
|
* |
|
|
|
|
|
* @param entrySet the entry set to filter |
|
|
|
|
|
* @return the filtered entry set |
|
|
|
|
|
*/ |
|
|
|
|
|
private CVSEntry[] filterEntrySet( final CVSEntry[] entrySet ) |
|
|
|
|
|
{ |
|
|
|
|
|
final Vector results = new Vector(); |
|
|
|
|
|
for( int i = 0; i < entrySet.length; i++ ) |
|
|
|
|
|
{ |
|
|
|
|
|
final CVSEntry cvsEntry = entrySet[ i ]; |
|
|
|
|
|
final Date date = cvsEntry.getDate(); |
|
|
|
|
|
if( null != m_start && m_start.after( date ) ) |
|
|
|
|
|
{ |
|
|
|
|
|
//Skip dates that are too early |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
if( null != m_stop && m_stop.before( date ) ) |
|
|
|
|
|
{ |
|
|
|
|
|
//Skip dates that are too late |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
results.add( cvsEntry ); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
final CVSEntry[] resultArray = new CVSEntry[ results.size() ]; |
|
|
|
|
|
results.copyInto( resultArray ); |
|
|
|
|
|
return resultArray; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Print changelog to file specified in task. |
|
|
|
|
|
* |
|
|
|
|
|
* @throws BuildException if theres an error writing changelog |
|
|
|
|
|
*/ |
|
|
|
|
|
private void writeChangeLog( final CVSEntry[] entrySet ) |
|
|
|
|
|
throws BuildException |
|
|
|
|
|
{ |
|
|
|
|
|
FileOutputStream output = null; |
|
|
|
|
|
try |
|
|
|
|
|
{ |
|
|
|
|
|
output = new FileOutputStream( m_destfile ); |
|
|
|
|
|
final PrintWriter writer = |
|
|
|
|
|
new PrintWriter( new OutputStreamWriter( output, "UTF-8" ) ); |
|
|
|
|
|
|
|
|
|
|
|
final ChangeLogWriter serializer = new ChangeLogWriter(); |
|
|
|
|
|
serializer.printChangeLog( writer, entrySet ); |
|
|
|
|
|
} |
|
|
|
|
|
catch( final UnsupportedEncodingException uee ) |
|
|
|
|
|
{ |
|
|
|
|
|
getProject().log( uee.toString(), Project.MSG_ERR ); |
|
|
|
|
|
} |
|
|
|
|
|
catch( final IOException ioe ) |
|
|
|
|
|
{ |
|
|
|
|
|
throw new BuildException( ioe.toString(), ioe ); |
|
|
|
|
|
} |
|
|
|
|
|
finally |
|
|
|
|
|
{ |
|
|
|
|
|
if( null != output ) |
|
|
|
|
|
{ |
|
|
|
|
|
try |
|
|
|
|
|
{ |
|
|
|
|
|
output.close(); |
|
|
|
|
|
} |
|
|
|
|
|
catch( final IOException ioe ) |
|
|
|
|
|
{ |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |