From 5ec7e1db1b76797c2513ada02a7cdc4fa23903b4 Mon Sep 17 00:00:00 2001 From: Antoine Levy-Lambert Date: Wed, 28 Jan 2004 22:47:14 +0000 Subject: [PATCH] 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 --- WHATSNEW | 5 + docs/manual/CoreTasks/changelog.html | 50 ++++- docs/manual/CoreTasks/cvsversion.html | 93 +++++++++ docs/manual/coretasklist.html | 1 + .../tools/ant/taskdefs/AbstractCvsTask.java | 18 +- .../ant/taskdefs/cvslib/ChangeLogTask.java | 52 +++-- .../tools/ant/taskdefs/cvslib/CvsVersion.java | 189 ++++++++++++++++++ .../tools/ant/taskdefs/defaults.properties | 1 + 8 files changed, 377 insertions(+), 32 deletions(-) create mode 100644 docs/manual/CoreTasks/cvsversion.html create mode 100644 src/main/org/apache/tools/ant/taskdefs/cvslib/CvsVersion.java diff --git a/WHATSNEW b/WHATSNEW index d039fa361..360b66033 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -66,6 +66,11 @@ Other changes: detected by Ant and treated just like Java 1.4. You can now specify source="1.5" in the task. +* created new task + +* added support for branch logging via the tag attribute in + Bugzilla Report 13510. + Changes from Ant 1.5.4 to Ant 1.6.0 =================================== diff --git a/docs/manual/CoreTasks/changelog.html b/docs/manual/CoreTasks/changelog.html index 733fd54ec..0f339206e 100644 --- a/docs/manual/CoreTasks/changelog.html +++ b/docs/manual/CoreTasks/changelog.html @@ -21,6 +21,49 @@ from the command line in the target directory in which you are working. Description Required + + Attributes from parent Cvs task which are meaningful here
+ Since ant 1.6.1 + + + cvsRoot + the CVSROOT variable. + No + + + cvsRsh + the CVS_RSH variable. + No + + + package + the package/module to check out. + No + + + port + Port used by CVS to communicate with the server. + No, default port 2401. + + + passfile + Password file to read passwords from. + No, default file ~/.cvspass. + + + failonerror + Stop the build process if the command exits with a + return code other than 0. Defaults to false + No + + + tag + query the changelog for a specific branch. + No + + + Specific attributes + dir The directory from which to run the CVS log @@ -138,6 +181,11 @@ under the dve/network directory, substituting the name anytime it encounters a change made by the user ID "donaldp". It writes these changes into the file changelog.xml.

+

Generates a change log report on the ANT_16_BRANCH.

+
+ <cvschangelog dir="c:/dev/asf/ant.head" passfile="c:/home/myself/.cvspass"
+                destfile="changelogant.xml" tag="ANT_16_BRANCH" />
+

Generate Report

Ant includes a basic XSLT stylesheet that you can use to generate 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]]></msg> </changelog> -


Copyright © 2002-2003 Apache Software Foundation. All rights +


Copyright © 2002-2004 Apache Software Foundation. All rights Reserved.

diff --git a/docs/manual/CoreTasks/cvsversion.html b/docs/manual/CoreTasks/cvsversion.html new file mode 100644 index 000000000..73d54dddb --- /dev/null +++ b/docs/manual/CoreTasks/cvsversion.html @@ -0,0 +1,93 @@ + + + + +CVSVersion Task + + + + + +

CvsVersion

+

Description

+

+This task allows to retrieve a CVS client and server version +

+

Parameters

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
AttributeDescriptionRequired
Attributes from parent Cvs task which are meaningful here
cvsRootthe CVSROOT variable.No
cvsRshthe CVS_RSH variable.No
destdirectory containing the checked out version of the projectNo, default is project's basedir.
packagethe package/module to check out.No
portPort used by CVS to communicate with the server.No, default port 2401.
passfilePassword file to read passwords from.No, default file ~/.cvspass.
failonerrorStop the build process if the command exits with a + return code other than 0. Defaults to falseNo
Specific attributes
cvsclientpropertyName of a property where the cvsclient version + should be storedNo
cvsserverpropertyName of a property where the cvs server version + should be storedNo
+

Examples

+
  <cvsversion cvsRoot=":pserver:anoncvs@cvs.apache.org:/home/cvspublic"
+       passfile="/home/myself/.cvspass"
+       cvsserverproperty="apachecvsversion"
+       cvsclientproperty="localcvsversion"
+  />
+

finds out the cvs client and server versions and stores the versions in the +properties called apachecvsversion and localcvsversion

+ +
+

Copyright © 2004 Apache Software +Foundation. All rights Reserved.

+ + + + diff --git a/docs/manual/coretasklist.html b/docs/manual/coretasklist.html index 9e68bc122..098813bf1 100644 --- a/docs/manual/coretasklist.html +++ b/docs/manual/coretasklist.html @@ -34,6 +34,7 @@ Copyfile
Cvs
CvsChangeLog
+CvsVersion
CVSPass
CvsTagDiff
Defaultexcludes
diff --git a/src/main/org/apache/tools/ant/taskdefs/AbstractCvsTask.java b/src/main/org/apache/tools/ant/taskdefs/AbstractCvsTask.java index ecd0745d8..62929d205 100644 --- a/src/main/org/apache/tools/ant/taskdefs/AbstractCvsTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/AbstractCvsTask.java @@ -1,7 +1,7 @@ /* * 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. * * 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. */ private String cvsPackage; - + /** + * the tag + */ + private String tag; /** * the default command. */ @@ -609,6 +612,13 @@ public abstract class AbstractCvsTask extends Task { return this.cvsPackage; } + /** + * tag or branch + * @return tag or branch + */ + public String getTag() { + return tag; + } /** * The tag of the package/module to operate upon. @@ -617,8 +627,8 @@ public abstract class AbstractCvsTask extends Task { public void setTag(String p) { // Check if not real tag => set it to null if (p != null && p.trim().length() > 0) { - addCommandArgument("-r"); - addCommandArgument(p); + tag = p; + addCommandArgument("-r" + p); } } diff --git a/src/main/org/apache/tools/ant/taskdefs/cvslib/ChangeLogTask.java b/src/main/org/apache/tools/ant/taskdefs/cvslib/ChangeLogTask.java index 2d8038707..b2a4ed037 100644 --- a/src/main/org/apache/tools/ant/taskdefs/cvslib/ChangeLogTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/cvslib/ChangeLogTask.java @@ -1,7 +1,7 @@ /* * 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. * * 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.DirectoryScanner; 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.AbstractCvsTask; import org.apache.tools.ant.types.Commandline; import org.apache.tools.ant.types.FileSet; @@ -102,9 +102,9 @@ import org.apache.tools.ant.types.FileSet; * @author Peter Donald * @version $Revision$ $Date$ * @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 */ private File m_usersFile; @@ -226,7 +226,6 @@ public class ChangeLogTask extends Task { try { validate(); - final Properties userList = new Properties(); loadUserlist(userList); @@ -239,11 +238,22 @@ public class ChangeLogTask extends Task { 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) { final SimpleDateFormat outputDate = new SimpleDateFormat("yyyy-MM-dd"); @@ -252,8 +262,8 @@ public class ChangeLogTask extends Task { final String dateRange = ">=" + outputDate.format(m_start); // 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 @@ -267,7 +277,7 @@ public class ChangeLogTask extends Task { final String[] files = scanner.getIncludedFiles(); 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 = 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(); if (null != errors) { diff --git a/src/main/org/apache/tools/ant/taskdefs/cvslib/CvsVersion.java b/src/main/org/apache/tools/ant/taskdefs/cvslib/CvsVersion.java new file mode 100644 index 000000000..854a76787 --- /dev/null +++ b/src/main/org/apache/tools/ant/taskdefs/cvslib/CvsVersion.java @@ -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 + * . + */ +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 : + * <cvsversion + * cvsRoot=":pserver:anoncvs@cvs.apache.org:/home/cvspublic" + * passfile="c:/programme/cygwin/home/antoine/.cvspass" + * clientversionproperty="apacheclient" + * serverversionproperty="apacheserver" /> + * + * 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); + } + } +} diff --git a/src/main/org/apache/tools/ant/taskdefs/defaults.properties b/src/main/org/apache/tools/ant/taskdefs/defaults.properties index f5ee03a33..426b29dc7 100644 --- a/src/main/org/apache/tools/ant/taskdefs/defaults.properties +++ b/src/main/org/apache/tools/ant/taskdefs/defaults.properties @@ -66,6 +66,7 @@ loadproperties=org.apache.tools.ant.taskdefs.LoadProperties basename=org.apache.tools.ant.taskdefs.Basename dirname=org.apache.tools.ant.taskdefs.Dirname cvschangelog=org.apache.tools.ant.taskdefs.cvslib.ChangeLogTask +cvsversion=org.apache.tools.ant.tasksdefs.cvslib.CvsVersion buildnumber=org.apache.tools.ant.taskdefs.BuildNumber concat=org.apache.tools.ant.taskdefs.Concat cvstagdiff=org.apache.tools.ant.taskdefs.cvslib.CvsTagDiff