Browse Source

Add a new cvsversion task

Modify CvsChangeLog to accept a branch as the tag attribute
ChangeLogTask.java now inherits from AbstractCvsTask
PR: 13510


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@275969 13f79535-47bb-0310-9956-ffa450edef68
master
Antoine Levy-Lambert 21 years ago
parent
commit
5ec7e1db1b
8 changed files with 377 additions and 32 deletions
  1. +5
    -0
      WHATSNEW
  2. +49
    -1
      docs/manual/CoreTasks/changelog.html
  3. +93
    -0
      docs/manual/CoreTasks/cvsversion.html
  4. +1
    -0
      docs/manual/coretasklist.html
  5. +14
    -4
      src/main/org/apache/tools/ant/taskdefs/AbstractCvsTask.java
  6. +25
    -27
      src/main/org/apache/tools/ant/taskdefs/cvslib/ChangeLogTask.java
  7. +189
    -0
      src/main/org/apache/tools/ant/taskdefs/cvslib/CvsVersion.java
  8. +1
    -0
      src/main/org/apache/tools/ant/taskdefs/defaults.properties

+ 5
- 0
WHATSNEW View File

@@ -66,6 +66,11 @@ Other changes:
detected by Ant and treated just like Java 1.4. You can now specify detected by Ant and treated just like Java 1.4. You can now specify
source="1.5" in the <javac> task. source="1.5" in the <javac> task.


* created new task <cvsversion>

* added support for branch logging via the tag attribute in <cvschangelog>
Bugzilla Report 13510.

Changes from Ant 1.5.4 to Ant 1.6.0 Changes from Ant 1.5.4 to Ant 1.6.0
=================================== ===================================




+ 49
- 1
docs/manual/CoreTasks/changelog.html View File

@@ -21,6 +21,49 @@ from the command line in the target directory in which you are working.
<td valign="top"><b>Description</b></td> <td valign="top"><b>Description</b></td>
<td align="center" valign="top"><b>Required</b></td> <td align="center" valign="top"><b>Required</b></td>
</tr> </tr>
<tr>
<td colspan="3">Attributes from parent Cvs task which are meaningful here<br/>
Since ant 1.6.1</td>
</tr>
<tr>
<td valign="top">cvsRoot</td>
<td valign="top">the <code>CVSROOT</code> variable.</td>
<td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">cvsRsh</td>
<td valign="top">the <code>CVS_RSH</code> variable.</td>
<td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">package</td>
<td valign="top">the package/module to check out.</td>
<td align="center" valign="top">No</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 build process if the command exits with a
return code other than <code>0</code>. Defaults to false</td>
<td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">tag</td>
<td valign="top">query the changelog for a specific branch.</td>
<td align="center" valign="top">No</td>
</tr>
<tr>
<td colspan="3">Specific attributes</td>
</tr>
<tr> <tr>
<td valign="top">dir</td> <td valign="top">dir</td>
<td valign="top">The directory from which to run the CVS <em>log</em> <td valign="top">The directory from which to run the CVS <em>log</em>
@@ -138,6 +181,11 @@ under the <code>dve/network</code> directory, substituting the name
anytime it encounters a change made by the user ID &quot;donaldp&quot;. anytime it encounters a change made by the user ID &quot;donaldp&quot;.
It writes these changes into the file <code>changelog.xml</code>.</p> It writes these changes into the file <code>changelog.xml</code>.</p>


<p>Generates a change log report on the <code>ANT_16_BRANCH</code>.</p>
<pre>
&lt;cvschangelog dir=&quot;c:/dev/asf/ant.head&quot; passfile=&quot;c:/home/myself/.cvspass&quot;
destfile=&quot;changelogant.xml&quot; tag=&quot;ANT_16_BRANCH&quot; /&gt;
</pre>
<h4>Generate Report</h4> <h4>Generate Report</h4>
<p>Ant includes a basic XSLT stylesheet that you can use to generate <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 a HTML report based on the xml output. The following example illustrates
@@ -172,7 +220,7 @@ This allows temp[lates to be stored inside jar]]&gt;&lt;/msg&gt;
&lt;/changelog&gt; &lt;/changelog&gt;
</pre> </pre>


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


</body> </body>


+ 93
- 0
docs/manual/CoreTasks/cvsversion.html View File

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

<head>
<meta http-equiv="Content-Language" content="en-us">
<title>CVSVersion Task</title>
<link rel="stylesheet" type="text/css" href="../stylesheets/antmanual.css">
</head>

<body>

<h2><a name="cvs">CvsVersion</a></h2>
<h3>Description</h3>
<p>
This task allows to retrieve a CVS client and server version
</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 colspan="3">Attributes from parent Cvs task which are meaningful here</td>
</tr>
<tr>
<td valign="top">cvsRoot</td>
<td valign="top">the <code>CVSROOT</code> variable.</td>
<td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">cvsRsh</td>
<td valign="top">the <code>CVS_RSH</code> variable.</td>
<td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">dest</td>
<td valign="top">directory containing the checked out version of the project</td>
<td align="center" valign="top">No, default is project's basedir.</td>
</tr>
<tr>
<td valign="top">package</td>
<td valign="top">the package/module to check out.</td>
<td align="center" valign="top">No</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 build process if the command exits with a
return code other than <code>0</code>. Defaults to false</td>
<td align="center" valign="top">No</td>
</tr>
<tr>
<td colspan="3">Specific attributes</td>
</tr>
<tr>
<td valign="top">cvsclientproperty</td>
<td valign="top">Name of a property where the cvsclient version
should be stored</td>
<td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">cvsserverproperty</td>
<td valign="top">Name of a property where the cvs server version
should be stored</td>
<td align="center" valign="top">No</td>
</tr>
</table>
<h3>Examples</h3>
<pre> &lt;cvsversion cvsRoot=&quot;:pserver:anoncvs@cvs.apache.org:/home/cvspublic&quot;
passfile=&quot;/home/myself/.cvspass&quot;
cvsserverproperty=&quot;apachecvsversion&quot;
cvsclientproperty=&quot;localcvsversion&quot;
/&gt;</pre>
<p>finds out the cvs client and server versions and stores the versions in the
properties called apachecvsversion and localcvsversion</p>

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

</body>
</html>


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

@@ -34,6 +34,7 @@
<a href="CoreTasks/copyfile.html"><i>Copyfile</i></a><br> <a href="CoreTasks/copyfile.html"><i>Copyfile</i></a><br>
<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/cvsversion.html">CvsVersion</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/cvstagdiff.html">CvsTagDiff</a><br>
<a href="CoreTasks/defaultexcludes.html">Defaultexcludes</a><br> <a href="CoreTasks/defaultexcludes.html">Defaultexcludes</a><br>


+ 14
- 4
src/main/org/apache/tools/ant/taskdefs/AbstractCvsTask.java View File

@@ -1,7 +1,7 @@
/* /*
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
* *
* Copyright (c) 2002-2003 The Apache Software Foundation. All rights
* Copyright (c) 2002-2004 The Apache Software Foundation. All rights
* reserved. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -111,7 +111,10 @@ public abstract class AbstractCvsTask extends Task {
* the package/module to check out. * the package/module to check out.
*/ */
private String cvsPackage; private String cvsPackage;

/**
* the tag
*/
private String tag;
/** /**
* the default command. * the default command.
*/ */
@@ -609,6 +612,13 @@ public abstract class AbstractCvsTask extends Task {


return this.cvsPackage; return this.cvsPackage;
} }
/**
* tag or branch
* @return tag or branch
*/
public String getTag() {
return tag;
}


/** /**
* The tag of the package/module to operate upon. * The tag of the package/module to operate upon.
@@ -617,8 +627,8 @@ public abstract class AbstractCvsTask extends Task {
public void setTag(String p) { public void setTag(String p) {
// Check if not real tag => set it to null // Check if not real tag => set it to null
if (p != null && p.trim().length() > 0) { if (p != null && p.trim().length() > 0) {
addCommandArgument("-r");
addCommandArgument(p);
tag = p;
addCommandArgument("-r" + p);
} }
} }




+ 25
- 27
src/main/org/apache/tools/ant/taskdefs/cvslib/ChangeLogTask.java View File

@@ -1,7 +1,7 @@
/* /*
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
* *
* Copyright (c) 2002-2003 The Apache Software Foundation. All rights
* Copyright (c) 2002-2004 The Apache Software Foundation. All rights
* reserved. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -68,8 +68,8 @@ import java.util.Vector;
import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project; import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.taskdefs.Execute; import org.apache.tools.ant.taskdefs.Execute;
import org.apache.tools.ant.taskdefs.AbstractCvsTask;
import org.apache.tools.ant.types.Commandline; import org.apache.tools.ant.types.Commandline;
import org.apache.tools.ant.types.FileSet; import org.apache.tools.ant.types.FileSet;


@@ -102,9 +102,9 @@ import org.apache.tools.ant.types.FileSet;
* @author <a href="mailto:peter@apache.org">Peter Donald</a> * @author <a href="mailto:peter@apache.org">Peter Donald</a>
* @version $Revision$ $Date$ * @version $Revision$ $Date$
* @since Ant 1.5 * @since Ant 1.5
* @ant.task name="cvschangelog"
* @ant.task name="cvschangelog" category="scm"
*/ */
public class ChangeLogTask extends Task {
public class ChangeLogTask extends AbstractCvsTask {
/** User list */ /** User list */
private File m_usersFile; private File m_usersFile;


@@ -226,7 +226,6 @@ public class ChangeLogTask extends Task {
try { try {


validate(); validate();

final Properties userList = new Properties(); final Properties userList = new Properties();


loadUserlist(userList); loadUserlist(userList);
@@ -239,11 +238,22 @@ public class ChangeLogTask extends Task {
userList.put(user.getUserID(), user.getDisplayname()); userList.put(user.getUserID(), user.getDisplayname());
} }


final Commandline command = new Commandline();


command.setExecutable("cvs");
command.createArgument().setValue("log");
setCommand("log");


if (getTag() != null) {
CvsVersion myCvsVersion = new CvsVersion();
myCvsVersion.setProject(getProject());
myCvsVersion.setTaskName("cvsversion");
myCvsVersion.setCvsRoot(getCvsRoot());
myCvsVersion.setCvsRsh(getCvsRsh());
myCvsVersion.setPassfile(getPassFile());
myCvsVersion.setDest(m_dir);
myCvsVersion.execute();
if (myCvsVersion.supportsCvsLogWithSOption()) {
addCommandArgument("-S");
}
}
if (null != m_start) { if (null != m_start) {
final SimpleDateFormat outputDate = final SimpleDateFormat outputDate =
new SimpleDateFormat("yyyy-MM-dd"); new SimpleDateFormat("yyyy-MM-dd");
@@ -252,8 +262,8 @@ public class ChangeLogTask extends Task {
final String dateRange = ">=" + outputDate.format(m_start); final String dateRange = ">=" + outputDate.format(m_start);


// Supply '-d' as a separate argument - Bug# 14397 // Supply '-d' as a separate argument - Bug# 14397
command.createArgument().setValue("-d");
command.createArgument().setValue(dateRange);
addCommandArgument("-d");
addCommandArgument(dateRange);
} }


// Check if list of files to check has been specified // Check if list of files to check has been specified
@@ -267,7 +277,7 @@ public class ChangeLogTask extends Task {
final String[] files = scanner.getIncludedFiles(); final String[] files = scanner.getIncludedFiles();


for (int i = 0; i < files.length; i++) { for (int i = 0; i < files.length; i++) {
command.createArgument().setValue(files[i]);
addCommandArgument(files[i]);
} }
} }
} }
@@ -276,23 +286,11 @@ public class ChangeLogTask extends Task {
final RedirectingStreamHandler handler = final RedirectingStreamHandler handler =
new RedirectingStreamHandler(parser); new RedirectingStreamHandler(parser);


log(command.describeCommand(), Project.MSG_VERBOSE);

final Execute exe = new Execute(handler);

exe.setWorkingDirectory(m_dir);
exe.setCommandline(command.getCommandline());
exe.setAntRun(getProject());
try {
final int resultCode = exe.execute();

if (Execute.isFailure(resultCode)) {
throw new BuildException("Error running cvs log");
}
} catch (final IOException ioe) {
throw new BuildException(ioe.toString());
}
log(getCommand(), Project.MSG_VERBOSE);


setDest(m_dir);
setExecuteStreamHandler(handler);
super.execute();
final String errors = handler.getErrors(); final String errors = handler.getErrors();


if (null != errors) { if (null != errors) {


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

@@ -0,0 +1,189 @@
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2004 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 "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.taskdefs.AbstractCvsTask;

import java.io.ByteArrayOutputStream;
import java.util.StringTokenizer;

/**
* this task allows to find out the client and the server version of a
* CVS installation
*
* example usage :
* &lt;cvsversion
* cvsRoot=&quot;:pserver:anoncvs@cvs.apache.org:/home/cvspublic&quot;
* passfile=&quot;c:/programme/cygwin/home/antoine/.cvspass&quot;
* clientversionproperty=&quot;apacheclient&quot;
* serverversionproperty=&quot;apacheserver&quot; /&gt;
*
* the task can be used also in the API by calling its execute method,
* then calling getServerVersion and/or getClientVersion
*
* @ant.task category="scm"
* @author Antoine Levy-Lambert
*/
public class CvsVersion extends AbstractCvsTask {
static final long VERSION_1_11_2 = 11102;
static final long MULTIPLY = 100;
private String clientVersion;
private String serverVersion;
private String clientVersionProperty;
private String serverVersionProperty;
/**
* get the CVS client version
* @return CVS client version
*/
public String getClientVersion() {
return clientVersion;
}
/**
* get the CVS server version
* @return CVS server version
*/
public String getServerVersion() {
return serverVersion;
}
/**
* set a property where to store the CVS client version
* @param clientVersionProperty property for CVS client version
*/
public void setClientVersionProperty(String clientVersionProperty) {
this.clientVersionProperty = clientVersionProperty;
}

/**
* set a property where to store the CVS server version
* @param serverVersionProperty property for CVS server version
*/
public void setServerVersionProperty(String serverVersionProperty) {
this.serverVersionProperty = serverVersionProperty;
}
/**
* find out if the server version supports log with S option
* @return boolean indicating if the server version supports log with S option
*/
public boolean supportsCvsLogWithSOption() {
if (serverVersion == null) {
return false;
}
StringTokenizer mySt = new StringTokenizer(serverVersion, ".");
long versionNumber;
long counter = MULTIPLY * MULTIPLY;
long version = 0;
while (mySt.hasMoreTokens()) {
String s = mySt.nextToken();
int i = 0;
for (i = 0; i < s.length(); i++) {
if (!Character.isDigit(s.charAt(i))) {
break;
}
}
String s2 = s.substring(0, i);
version = version + counter * Long.parseLong(s2);
if (counter == 1) {
break;
}
counter = counter / MULTIPLY;
}
return (version >= VERSION_1_11_2);
}
/**
* the execute method running CvsVersion
*/
public void execute() {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
this.setOutputStream(bos);
ByteArrayOutputStream berr = new ByteArrayOutputStream();
this.setErrorStream(berr);
setCommand("version");
super.execute();
String output = bos.toString();
StringTokenizer st = new StringTokenizer(output);
boolean client = false;
boolean server = false;
boolean cvs = false;
while (st.hasMoreTokens()) {
String currentToken = st.nextToken();
if (currentToken.equals("Client:")) {
client = true;
} else if (currentToken.equals("Server:")) {
server = true;
} else if (currentToken.equals("(CVS)")) {
cvs = true;
}
if (client && cvs) {
if (st.hasMoreTokens()) {
clientVersion = st.nextToken();
}
client = false;
cvs = false;
} else if (server && cvs) {
if (st.hasMoreTokens()) {
serverVersion = st.nextToken();
}
server = false;
cvs = false;
}

}
if (clientVersionProperty != null) {
getProject().setNewProperty(clientVersionProperty, clientVersion);
}
if (serverVersionProperty != null) {
getProject().setNewProperty(serverVersionProperty, serverVersion);
}
}
}

+ 1
- 0
src/main/org/apache/tools/ant/taskdefs/defaults.properties View File

@@ -66,6 +66,7 @@ loadproperties=org.apache.tools.ant.taskdefs.LoadProperties
basename=org.apache.tools.ant.taskdefs.Basename basename=org.apache.tools.ant.taskdefs.Basename
dirname=org.apache.tools.ant.taskdefs.Dirname dirname=org.apache.tools.ant.taskdefs.Dirname
cvschangelog=org.apache.tools.ant.taskdefs.cvslib.ChangeLogTask cvschangelog=org.apache.tools.ant.taskdefs.cvslib.ChangeLogTask
cvsversion=org.apache.tools.ant.tasksdefs.cvslib.CvsVersion
buildnumber=org.apache.tools.ant.taskdefs.BuildNumber buildnumber=org.apache.tools.ant.taskdefs.BuildNumber
concat=org.apache.tools.ant.taskdefs.Concat concat=org.apache.tools.ant.taskdefs.Concat
cvstagdiff=org.apache.tools.ant.taskdefs.cvslib.CvsTagDiff cvstagdiff=org.apache.tools.ant.taskdefs.cvslib.CvsTagDiff


Loading…
Cancel
Save