git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@896790 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -1,16 +0,0 @@ | |||
| #!/bin/sh | |||
| cygwin=false; | |||
| case "`uname`" in | |||
| CYGWIN*) cygwin=true ;; | |||
| esac | |||
| PWD=`pwd` | |||
| if $cygwin ; then | |||
| PWD=`cygpath --windows "$PWD"` | |||
| fi | |||
| cd ../../.. | |||
| /bin/sh ./build.sh -buildfile $PWD/build.xml $* | |||
| cd $PWD | |||
| @@ -1,62 +0,0 @@ | |||
| <project name="clearcase-proposal" basedir="." default="compile"> | |||
| <property file=".ant.properties"/> | |||
| <property file="${user.home}/.ant.properties"/> | |||
| <!--property name="build.sysclasspath" value="ignore"/--> | |||
| <property name="build.compiler" value="jikes"/> | |||
| <!--property name="build.compiler.emacs" value="on"/--> | |||
| <property name="build.compiler.pedantic" value="true"/> | |||
| <property name="build.compiler.depend" value="true"/> | |||
| <property name="build.compiler.fulldepend" value="true"/> | |||
| <property name="debug" value="on"/> | |||
| <property name="optimize" value="off"/> | |||
| <property name="deprecation" value="on"/> | |||
| <property name="build.dir" value="build"/> | |||
| <property name="build.lib" value="${build.dir}/lib"/> | |||
| <property name="build.src" value="${build.dir}/src"/> | |||
| <property name="build.classes" value="${build.dir}/classes"/> | |||
| <property name="build.dist" value="${build.dir}/dist"/> | |||
| <property name="java.dir" value="src/java"/> | |||
| <property name="tests.dir" value="src/testcases"/> | |||
| <property name="ant.base.dir" location="../../.."/> | |||
| <property name="lib.dir" location="${ant.base.dir}/lib"/> | |||
| <property name="bootstrap.dir" location="${ant.base.dir}/bootstrap"/> | |||
| <path id="project.class.path"> | |||
| <pathelement path="${build.classes}" /> | |||
| <fileset dir="${lib.dir}" includes="**/*.jar"/> | |||
| <fileset dir="${bootstrap.dir}/lib" includes="ant.jar"/> | |||
| </path> | |||
| <target name="compile" | |||
| description="--> compile the source code"> | |||
| <mkdir dir="${build.classes}"/> | |||
| <javac srcdir="src/main" | |||
| destdir="${build.classes}" | |||
| debug="${debug}" | |||
| optimize="${optimize}" | |||
| deprecation="${deprecation}" | |||
| includeantruntime="no"> | |||
| <classpath refid="project.class.path"/> | |||
| </javac> | |||
| </target> | |||
| <target name="dist" | |||
| depends="clean,compile" | |||
| description="--> create a jar"> | |||
| <mkdir dir="${build.dist}"/> | |||
| <jar destfile="${build.dist}/cc-tasks.jar" basedir="${build.classes}"/> | |||
| </target> | |||
| <target name="clean" | |||
| description="--> cleans up build and dist directories"> | |||
| <delete dir="${build.dir}" /> | |||
| <delete> | |||
| <fileset dir="." includes="**/*.bak" defaultexcludes="no"/> | |||
| </delete> | |||
| </target> | |||
| </project> | |||
| @@ -1,34 +0,0 @@ | |||
| <project name="cc-checkin" basedir="." default="noop"/> | |||
| <!-- default value for test.dir, override to specify a cc location --> | |||
| <property name="test.dir" location="."/> | |||
| <target name="noop"/> | |||
| <target name="test-allcheckedout" description="should co all ci files"> | |||
| <cc-checkin viewpath="${test.dir}" comment="test-allcheckedout"> | |||
| <include name="**/*.cctest.ci"/> | |||
| </cc-checkin> | |||
| </target> | |||
| <target name="test-allcheckedin" description="should ci nothing"> | |||
| <cc-checkin viewpath="${test.dir}" comment="test-allcheckedin"> | |||
| <include name="**/*.cctest.co"/> | |||
| </cc-checkin> | |||
| </target> | |||
| <target name="test-allprivate" description="should ci nothing"> | |||
| <cc-checkin viewpath="${test.dir}" comment="test-allprivate"> | |||
| <include name="**/*.cctest.private"/> | |||
| </cc-checkin> | |||
| </target> | |||
| <target name="test-mix" description="should ci only co files"> | |||
| <cc-checkin viewpath="${test.dir}"> | |||
| <include name="**/*.cctest.private"/> | |||
| <include name="**/*.cctest.ci"/> | |||
| <include name="**/*.cctest.co"/> | |||
| </cc-checkin> | |||
| </target> | |||
| </project> | |||
| @@ -1,34 +0,0 @@ | |||
| <project name="cc-checkout" basedir="." default="noop"/> | |||
| <!-- default value for test.dir, override to specify a cc location --> | |||
| <property name="test.dir" location="."/> | |||
| <target name="noop"/> | |||
| <target name="test-allcheckedout" description="should co nothing"> | |||
| <cc-checkout viewpath="${test.dir}" comment="test-allcheckedout"> | |||
| <include name="**/*.cctest.ci"/> | |||
| </cc-checkout> | |||
| </target> | |||
| <target name="test-allcheckedin" description="should co all files"> | |||
| <cc-checkout viewpath="${test.dir}" comment="test-allcheckedin"> | |||
| <include name="**/*.cctest.co"/> | |||
| </cc-checkout> | |||
| </target> | |||
| <target name="test-allprivate" description="should co nothing"> | |||
| <cc-checkout viewpath="${test.dir}" comment="test-allprivate"> | |||
| <include name="**/*.cctest.private"/> | |||
| </cc-checkout> | |||
| </target> | |||
| <target name="test-mix" description="should co only ci files"> | |||
| <cc-checkout viewpath="${test.dir}"> | |||
| <include name="**/*.cctest.private"/> | |||
| <include name="**/*.cctest.ci"/> | |||
| <include name="**/*.cctest.co"/> | |||
| </cc-checkout> | |||
| </target> | |||
| </project> | |||
| @@ -1,34 +0,0 @@ | |||
| <project name="cc-mkelem" basedir="." default="noop"/> | |||
| <!-- default value for test.dir, override to specify a cc location --> | |||
| <property name="test.dir" location="."/> | |||
| <target name="noop"/> | |||
| <target name="test-allcheckedout" description="should mkelem nothing"> | |||
| <cc-mkelem viewpath="${test.dir}" comment="test-allcheckedout"> | |||
| <include name="**/*.cctest.ci"/> | |||
| </cc-mkelem> | |||
| </target> | |||
| <target name="test-allcheckedin" description="should mkelem nothing"> | |||
| <cc-mkelem viewpath="${test.dir}" comment="test-allcheckedin"> | |||
| <include name="**/*.cctest.co"/> | |||
| </cc-mkelem> | |||
| </target> | |||
| <target name="test-allprivate" description="should mkelem all files"> | |||
| <cc-mkelem viewpath="${test.dir}" comment="test-allprivate"> | |||
| <include name="**/*.cctest.private"/> | |||
| </cc-mkelem> | |||
| </target> | |||
| <target name="test-mix" description="should mkelem only private files"> | |||
| <cc-mkelem viewpath="${test.dir}"> | |||
| <include name="**/*.cctest.private"/> | |||
| <include name="**/*.cctest.ci"/> | |||
| <include name="**/*.cctest.co"/> | |||
| </cc-mkelem> | |||
| </target> | |||
| </project> | |||
| @@ -1,123 +0,0 @@ | |||
| /* | |||
| * 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.optional.clearcase; | |||
| import java.util.Vector; | |||
| import org.apache.tools.ant.BuildException; | |||
| /** | |||
| * Creates a permanent new version of an element | |||
| * | |||
| * @see http://clearcase.rational.com/doc/latest/ccase_ux/ccref/checkin.html | |||
| * | |||
| */ | |||
| public class CCCheckin extends CCMatchingTask { | |||
| private boolean nowarn = false; | |||
| private boolean ptime = false; | |||
| private boolean keep = false; | |||
| private boolean identical = true; | |||
| protected Vector getOptions(){ | |||
| Vector v = new Vector(); | |||
| v.addElement("ci"); | |||
| if (nowarn){ | |||
| v.addElement("-nowarn"); | |||
| } | |||
| if (ptime){ | |||
| v.addElement("-ptime"); | |||
| } | |||
| if (comment != null){ | |||
| v.addElement("-cfile"); | |||
| v.addElement(commentFile.getPath()); | |||
| } | |||
| if (keep){ | |||
| v.addElement("-keep"); | |||
| } | |||
| if (identical){ | |||
| v.addElement("-identical"); | |||
| } | |||
| v.addElement("<pname>"); | |||
| return v; | |||
| } | |||
| protected void execute(String[] args, CCFile file) throws BuildException { | |||
| args[args.length - 1] = file.getPath(); | |||
| CmdResult res = CCUtils.cleartool(args); | |||
| if (res.getStatus() != 0){ | |||
| throw new BuildException(res.getStdErr()); | |||
| } | |||
| } | |||
| protected boolean accept(CCFile file) { | |||
| return file.isCheckedOut(); | |||
| } | |||
| // bean setters | |||
| public void setNowarn(boolean nowarn) { | |||
| this.nowarn = nowarn; | |||
| } | |||
| public void setPtime(boolean ptime) { | |||
| this.ptime = ptime; | |||
| } | |||
| public void setKeep(boolean keep) { | |||
| this.keep = keep; | |||
| } | |||
| public void setIdentical(boolean identical) { | |||
| this.identical = identical; | |||
| } | |||
| } | |||
| @@ -1,131 +0,0 @@ | |||
| /* | |||
| * 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.optional.clearcase; | |||
| import java.util.Vector; | |||
| /** | |||
| * Creates a modifiable copy of a version | |||
| * | |||
| * @see http://clearcase.rational.com/doc/latest/ccase_ux/ccref/checkout.html | |||
| * | |||
| */ | |||
| public class CCCheckout extends CCMatchingTask { | |||
| private boolean reserved = true; | |||
| private String branch = null; | |||
| private boolean version = false; | |||
| private boolean nwarn = false; | |||
| private String out = null; | |||
| private boolean ndata = false; | |||
| private boolean ptime = false; | |||
| protected Vector getOptions(){ | |||
| Vector v = new Vector(); | |||
| v.addElement("co"); | |||
| v.addElement(reserved ? "-reserved":"-unreserved"); | |||
| if (nwarn){ | |||
| v.addElement("-nwarn"); | |||
| } | |||
| if (branch != null){ | |||
| v.addElement("-branch"); | |||
| v.addElement(branch); | |||
| } else if (version) { | |||
| v.addElement("-version"); | |||
| } | |||
| if (out != null){ | |||
| v.addElement("-out"); | |||
| v.addElement(out); | |||
| } else if (ndata){ | |||
| v.addElement("-ndata"); | |||
| } | |||
| if (ptime){ | |||
| v.addElement("-ptime"); | |||
| } | |||
| v.addElement("<pname>"); | |||
| return v; | |||
| } | |||
| protected boolean accept(CCFile file) { | |||
| return file.isCheckedIn(); | |||
| } | |||
| // bean setters | |||
| public void setPtime(boolean ptime) { | |||
| this.ptime = ptime; | |||
| } | |||
| public void setReserved(boolean reserved) { | |||
| this.reserved = reserved; | |||
| } | |||
| public void setOut(String out) { | |||
| this.out = out; | |||
| } | |||
| public void setNdata(boolean ndata) { | |||
| this.ndata = ndata; | |||
| } | |||
| public void setBranch(String branch) { | |||
| this.branch = branch; | |||
| } | |||
| public void setVersion(boolean version) { | |||
| this.version = version; | |||
| } | |||
| public void setNwarn(boolean nwarn) { | |||
| this.nwarn = nwarn; | |||
| } | |||
| } | |||
| @@ -1,135 +0,0 @@ | |||
| /* | |||
| * 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.optional.clearcase; | |||
| import java.io.File; | |||
| import org.apache.tools.ant.BuildException; | |||
| /** | |||
| * An extended file that gives state information. | |||
| * | |||
| */ | |||
| public class CCFile extends File { | |||
| /** is it checkedout */ | |||
| private boolean checkedout = false; | |||
| /** is it under source control ? */ | |||
| private boolean versioned = false; | |||
| /** was this file already described once ? */ | |||
| private boolean described = false; | |||
| public CCFile(String parent, String child) { | |||
| super(parent, child); | |||
| } | |||
| public CCFile(File parent, String child) { | |||
| super(parent, child); | |||
| } | |||
| public CCFile(String pathname) { | |||
| super(pathname); | |||
| } | |||
| /** | |||
| * @return whether the file is checkedout. A non checkedout file | |||
| * does not imply it is a checkedin one. | |||
| * @see #isCheckedIn() | |||
| * @see #isVersioned() | |||
| */ | |||
| public boolean isCheckedOut() { | |||
| if (!described){ | |||
| refresh(); | |||
| } | |||
| return checkedout; | |||
| } | |||
| /** | |||
| * @return whether the file is versioned or not. | |||
| */ | |||
| public boolean isVersioned() { | |||
| if (!described){ | |||
| refresh(); | |||
| } | |||
| return versioned; | |||
| } | |||
| /** | |||
| * @return whether the file is checkedin or not. A non checkedin file | |||
| * does not imply it is a checkedout one. | |||
| * @see #isCheckedOut() | |||
| * @see #isVersioned() | |||
| */ | |||
| public boolean isCheckedIn(){ | |||
| return isVersioned() && !isCheckedOut(); | |||
| } | |||
| /** | |||
| * Refresh the file status in case it changed since the | |||
| * first access. | |||
| */ | |||
| public void refresh() { | |||
| String[] args = {"describe", "-fmt", "\"%m %o\"", getAbsolutePath() }; | |||
| CmdResult res = CCUtils.cleartool(args); | |||
| if (res.getStatus() != 0){ | |||
| throw new BuildException(res.getStdErr()); | |||
| } | |||
| String stdout = res.getStdout(); | |||
| versioned = (stdout.indexOf("view private object") == -1); | |||
| checkedout = (stdout.indexOf("checkout") != -1); | |||
| described = true; | |||
| } | |||
| } | |||
| @@ -1,212 +0,0 @@ | |||
| /* | |||
| * 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.optional.clearcase; | |||
| import java.io.File; | |||
| import java.util.Vector; | |||
| import java.util.Hashtable; | |||
| import java.util.Enumeration; | |||
| import org.apache.tools.ant.taskdefs.MatchingTask; | |||
| import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.DirectoryScanner; | |||
| /** | |||
| * Base task for all Clearcase tasks involving multiple-file processing. | |||
| * | |||
| */ | |||
| public abstract class CCMatchingTask extends MatchingTask { | |||
| /** view path to use. Equivalent to base directory of processing */ | |||
| protected File viewpath; | |||
| /** cc helper tools */ | |||
| protected CCUtils utils = new CCUtils(this); | |||
| /** the set of collected files to checkin */ | |||
| protected Hashtable files = null; | |||
| /** comments to use for the operation */ | |||
| protected String comment = null; | |||
| /** the comment file created from the comments. It avoids escaping issues */ | |||
| protected File commentFile; | |||
| /** cleartool options (and command as well) */ | |||
| protected String[] options; | |||
| /** | |||
| * @return a vector of options representing the cleartool arguments. | |||
| * The last arguments is normally allocated and replaced at the last | |||
| * moment before running the command. | |||
| * @see #execute(String[], CCFile) | |||
| */ | |||
| protected abstract Vector getOptions(); | |||
| /** | |||
| * @param file the clearcase file | |||
| * @return whether this file should be accepted or not by the | |||
| * command to restrict the file processing and errors. For | |||
| * example you might not want to checkin files that are | |||
| * already checked in and that are collected by the fileset | |||
| */ | |||
| protected boolean accept(CCFile file){ | |||
| return true; | |||
| } | |||
| public void execute() throws BuildException { | |||
| try { | |||
| preExecute(); | |||
| doExecute(); | |||
| } finally { | |||
| postExecute(); | |||
| } | |||
| } | |||
| /** check for attributes and builds the options array */ | |||
| protected void preExecute() throws BuildException { | |||
| if (viewpath == null){ | |||
| throw new BuildException("Invalid viewpath"); | |||
| } | |||
| if (comment != null){ | |||
| commentFile = CCUtils.createCommentFile(comment); | |||
| } | |||
| Vector v = getOptions(); | |||
| options = new String[v.size()]; | |||
| v.copyInto(options); | |||
| } | |||
| /** clean up method calls after doExecute */ | |||
| protected void postExecute(){ | |||
| if (commentFile != null){ | |||
| commentFile.delete(); | |||
| } | |||
| } | |||
| /** | |||
| * The core processing. It loops over all files and calls | |||
| * <tt>execute(String[], CCFile)</tt> | |||
| */ | |||
| protected void doExecute() throws BuildException { | |||
| Enumeration elems = getFiles().elements(); | |||
| log("Processing " + files.size() + " elements..."); | |||
| while ( elems.hasMoreElements() ){ | |||
| execute(options, (CCFile)elems.nextElement()); | |||
| } | |||
| } | |||
| /** | |||
| * Calls the cleartool command with the appropriate parameters. Note the | |||
| * the last array element is supposed to be used by the filepath. | |||
| * @param args the cleartool command to execute. The last element being allocated | |||
| * and representing the filepath. | |||
| * @param file the file element to process. | |||
| * @throws BuildException thrown if an error occurs when processing the | |||
| * cleartool command. | |||
| */ | |||
| protected void execute(String[] args, CCFile file) throws BuildException { | |||
| args[args.length - 1] = file.getPath(); | |||
| CmdResult res = utils.cleartool(args); | |||
| if (res.getStatus() != 0){ | |||
| throw new BuildException(res.getStdErr()); | |||
| } | |||
| } | |||
| /** | |||
| * Restrict the set of files/directories to be processed. | |||
| * @return the set of files to be processed. The key is made up | |||
| * the filepath and the value is the <tt>CCFile</tt> instance. | |||
| * @see #accept(CCFile) | |||
| */ | |||
| protected Hashtable getFiles(){ | |||
| if (files != null){ | |||
| return files; | |||
| } | |||
| files = new Hashtable(); | |||
| DirectoryScanner ds = getDirectoryScanner(viewpath); | |||
| String[] includes = ds.getIncludedDirectories(); | |||
| addElements(files, ds.getBasedir(), includes); | |||
| includes = ds.getIncludedFiles(); | |||
| addElements(files, ds.getBasedir(), includes); | |||
| return files; | |||
| } | |||
| /** | |||
| * Helper method to restrict a set of relative elements and add them | |||
| * to a map. | |||
| * @param map the map w/ a path/CCFile mapping to add elements to. | |||
| * @param basedir the base directory for all elements in the array. | |||
| * @param elems the set of elements to restrict. | |||
| * @see #accept(CCFile) | |||
| */ | |||
| protected void addElements(Hashtable map, File basedir, String[] elems){ | |||
| for (int i = 0; i < elems.length; i++){ | |||
| CCFile f = new CCFile(basedir, elems[i]); | |||
| if ( accept(f) ){ | |||
| map.put(f.getPath(), f); | |||
| } | |||
| } | |||
| } | |||
| // Ant bean setters | |||
| public void setViewPath(File value){ | |||
| this.viewpath = value; | |||
| } | |||
| public void setComment(String value){ | |||
| comment = value; | |||
| } | |||
| } | |||
| @@ -1,195 +0,0 @@ | |||
| /* | |||
| * 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.optional.clearcase; | |||
| import java.util.Vector; | |||
| import java.util.Hashtable; | |||
| import java.util.Enumeration; | |||
| import java.io.File; | |||
| import org.apache.tools.ant.Task; | |||
| import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.DirectoryScanner; | |||
| import org.apache.tools.ant.types.FileSet; | |||
| import org.apache.tools.ant.taskdefs.MatchingTask; | |||
| /** | |||
| * Creates a file or directory element. | |||
| * | |||
| * @see http://clearcase.rational.com/doc/latest/ccase_ux/ccref/mkelem.html | |||
| * | |||
| */ | |||
| public class CCMkelem extends CCMatchingTask { | |||
| private String type; | |||
| private boolean nocheckout; | |||
| private boolean checkin; | |||
| private boolean preserveTime; | |||
| private Hashtable codirs = new Hashtable(); | |||
| public void execute(String[] args, CCFile file) throws BuildException { | |||
| CCFile parent = (CCFile)codirs.get(file.getParent()); | |||
| if (parent == null){ | |||
| parent = new CCFile(file.getParent()); | |||
| if ( !parent.isVersioned() ){ | |||
| mkelemDirectory(parent); | |||
| // ensure versioned dir | |||
| } else if ( parent.isCheckedIn() ){ | |||
| utils.checkout( parent ); | |||
| } | |||
| codirs.put(parent.getPath(), parent); | |||
| } | |||
| args[args.length - 1] = file.getAbsolutePath(); | |||
| CmdResult res = CCUtils.cleartool(args); | |||
| if (res.getStatus() != 0) { | |||
| throw new BuildException(res.getStdErr()); | |||
| } | |||
| } | |||
| protected void postExecute() { | |||
| // checkin back all co directories | |||
| Enumeration dirs = codirs.elements(); | |||
| while( dirs.hasMoreElements() ){ | |||
| File dir = (File)dirs.nextElement(); | |||
| utils.checkin( dir ); | |||
| } | |||
| super.postExecute(); | |||
| } | |||
| /** create the command line options based on user input */ | |||
| protected Vector getOptions(){ | |||
| Vector v = new Vector(); | |||
| v.addElement("mkelem"); | |||
| if (type != null){ | |||
| v.addElement("-eltype"); | |||
| v.addElement(type); | |||
| } | |||
| if (comment == null){ | |||
| v.addElement("-nc"); | |||
| } else { | |||
| commentFile = CCUtils.createCommentFile(comment); | |||
| v.addElement("-cfi"); | |||
| v.addElement(commentFile.getAbsolutePath()); | |||
| } | |||
| if (nocheckout){ | |||
| v.addElement("-nco"); | |||
| } else if (checkin){ | |||
| v.addElement("-ci"); | |||
| if (preserveTime){ | |||
| v.addElement("-ptime"); | |||
| } | |||
| } | |||
| v.addElement("<pname>"); // dummy arg for file | |||
| return v; | |||
| } | |||
| private void mkelemDirectory(CCFile dir) throws BuildException { | |||
| // resolve symoblic link if any... | |||
| dir = new CCFile( utils.resolveSymbolicLink(dir.getAbsoluteFile()).getAbsolutePath() ); | |||
| // make sure that the parent is versioned... | |||
| CCFile parent = new CCFile(dir.getParent()); | |||
| boolean should_ci = false; | |||
| if ( !parent.isVersioned() ){ | |||
| mkelemDirectory(parent); | |||
| codirs.put(parent.getPath(), parent.getAbsoluteFile()); | |||
| } | |||
| // ...and checkout it if already checked in. | |||
| if ( parent.isCheckedIn() ){ | |||
| utils.checkout(parent.getAbsoluteFile()); | |||
| codirs.put(parent.getPath(), parent.getAbsoluteFile()); | |||
| } | |||
| // rename the unversioned directory into a temporary one... | |||
| File mkelem_file = new File(dir.getAbsolutePath() + "_mkelem"); | |||
| dir.renameTo( mkelem_file ); | |||
| // then create it via Clearcase... | |||
| utils.mkdir( dir ); | |||
| codirs.put(dir.getPath(), dir.getAbsoluteFile()); | |||
| // .. and populate it back with its files... | |||
| File[] files = dir.listFiles(); | |||
| for (int i = 0; i < files.length; i++){ | |||
| File newFile = new File(dir, files[i].getName()); | |||
| if ( !files[i].renameTo( newFile ) ) { | |||
| throw new BuildException("Could not rename dir '" + files[i] + "' into '" + newFile + "'" ); | |||
| } | |||
| } | |||
| // delete this one only if things went smoothly... | |||
| mkelem_file.delete(); | |||
| } | |||
| // bean setters | |||
| public void setType(String value){ | |||
| type = value; | |||
| } | |||
| public void setNoCheckout(boolean value){ | |||
| nocheckout = value; | |||
| } | |||
| public void setCheckin(boolean value){ | |||
| checkin = value; | |||
| } | |||
| public void setPreserveTime(boolean value){ | |||
| preserveTime = value; | |||
| } | |||
| } | |||
| @@ -1,125 +0,0 @@ | |||
| /* | |||
| * 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.optional.clearcase; | |||
| import java.util.Vector; | |||
| import org.apache.tools.ant.BuildException; | |||
| /** | |||
| * Attaches version labels to version of elements. | |||
| * | |||
| * @see http://clearcase.rational.com/doc/latest/ccase_ux/ccref/mklabel.html#2051 | |||
| * | |||
| */ | |||
| public class CCMklabel extends CCMatchingTask { | |||
| private boolean replace = false; | |||
| private boolean follow = false; | |||
| private String version = null; | |||
| private boolean recurse = false; | |||
| protected Vector getOptions(){ | |||
| Vector v = new Vector(); | |||
| v.addElement("mklabel"); | |||
| if (replace){ | |||
| v.addElement("-replace"); | |||
| } | |||
| if (recurse){ | |||
| v.addElement("-recurse"); | |||
| } | |||
| if (follow){ | |||
| v.addElement("-follow"); | |||
| } | |||
| if (comment != null){ | |||
| v.addElement("-cfile"); | |||
| v.addElement(commentFile.getPath()); | |||
| } | |||
| if (version != null){ | |||
| v.addElement("-version"); | |||
| v.addElement(version); | |||
| } | |||
| v.addElement("<pname>"); | |||
| return v; | |||
| } | |||
| protected void doExecute() throws BuildException { | |||
| // not very nice, but we'll try to speed up things | |||
| // by assuming a recurse is set only to the viewpath. | |||
| if (recurse){ | |||
| options[options.length - 1] = viewpath.getPath(); | |||
| utils.cleartool(options); | |||
| } else { | |||
| super.doExecute(); | |||
| } | |||
| } | |||
| protected boolean accept(CCFile file) { | |||
| //@fixme does it fail on checkedout files ? | |||
| return file.isVersioned(); | |||
| } | |||
| // bean setters | |||
| public void setRecurse(boolean value){ | |||
| recurse = value; | |||
| } | |||
| public void setVersion(String value){ | |||
| version = value; | |||
| } | |||
| public void setReplace(boolean value){ | |||
| replace = value; | |||
| } | |||
| public void setFollow(boolean value){ | |||
| follow = value; | |||
| } | |||
| } | |||
| @@ -1,123 +0,0 @@ | |||
| /* | |||
| * 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.optional.clearcase; | |||
| import java.util.Vector; | |||
| import java.util.Hashtable; | |||
| import java.util.Enumeration; | |||
| import java.io.File; | |||
| import org.apache.tools.ant.Task; | |||
| import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.DirectoryScanner; | |||
| import org.apache.tools.ant.taskdefs.MatchingTask; | |||
| import org.apache.tools.ant.types.FileSet; | |||
| /** | |||
| * Removes the name of an element or VOB symbolic link from a directory version | |||
| * | |||
| * @see http://clearcase.rational.com/doc/latest/ccase_ux/ccref/rmname.html | |||
| * | |||
| */ | |||
| public class CCRmname extends CCMatchingTask { | |||
| private boolean force = false; | |||
| /** used to cache co directories */ | |||
| private Hashtable codirs = new Hashtable(); | |||
| protected Vector getOptions() { | |||
| Vector v = new Vector(); | |||
| v.addElement("rmname"); | |||
| if (comment != null){ | |||
| v.addElement("-cfile"); | |||
| v.addElement(commentFile.getPath()); | |||
| } else { | |||
| v.addElement("-comment"); | |||
| v.addElement(CCUtils.DEFAULT_COMMENT); | |||
| } | |||
| if (force){ | |||
| v.addElement("-f"); | |||
| } | |||
| v.addElement("<pname>"); | |||
| return v; | |||
| } | |||
| public void execute(String[] args, CCFile file) throws BuildException { | |||
| CCFile parent = new CCFile(file.getParent()); | |||
| // we have first to co the parent | |||
| if ( parent.isCheckedIn() ){ | |||
| utils.checkout(parent); | |||
| } | |||
| // remove the element | |||
| args[args.length - 1] = file.getAbsolutePath(); | |||
| CmdResult res = utils.cleartool(args); | |||
| // if it failed, unco otherwise ci the parent | |||
| if (res.getStatus() != 0){ | |||
| utils.uncheckout(parent); | |||
| throw new BuildException(res.getStdErr()); | |||
| } else { | |||
| utils.checkin(parent); | |||
| } | |||
| } | |||
| protected boolean accept(CCFile file){ | |||
| return file.isCheckedIn(); | |||
| } | |||
| // bean setters | |||
| public void setForce(boolean value){ | |||
| force = value; | |||
| } | |||
| } | |||
| @@ -1,304 +0,0 @@ | |||
| /* | |||
| * 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.optional.clearcase; | |||
| import java.io.ByteArrayOutputStream; | |||
| import java.io.File; | |||
| import java.io.IOException; | |||
| import java.io.Writer; | |||
| import java.io.BufferedWriter; | |||
| import java.io.FileWriter; | |||
| import java.util.Hashtable; | |||
| import java.util.Vector; | |||
| import java.util.Enumeration; | |||
| import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.Task; | |||
| import org.apache.tools.ant.util.regexp.RegexpMatcher; | |||
| import org.apache.tools.ant.util.regexp.RegexpMatcherFactory; | |||
| import org.apache.tools.ant.util.FileUtils; | |||
| import org.apache.tools.ant.taskdefs.Execute; | |||
| import org.apache.tools.ant.taskdefs.ExecuteStreamHandler; | |||
| import org.apache.tools.ant.taskdefs.PumpStreamHandler; | |||
| /** | |||
| * Helper methods related to clearcase commands. | |||
| * | |||
| */ | |||
| public final class CCUtils { | |||
| public final static String DEFAULT_COMMENT = "\"Automatic operation from Jakarta Ant\""; | |||
| private final static RegexpMatcherFactory __reFactory = new RegexpMatcherFactory(); | |||
| /** the matchers cache: pattern/matcher */ | |||
| private final static Hashtable matchers = new Hashtable(); | |||
| private Task task; | |||
| public CCUtils(Task task){ | |||
| this.task = task; | |||
| } | |||
| /** | |||
| * return a group of matches of a given RE in a string. | |||
| * @param pattern the pattern to match in the input data. | |||
| * @param input the data where to look for the pattern. | |||
| * @return the group of matches if any, 0 being the full match | |||
| * and the rest being parenthesized expressions. <tt>null</tt> | |||
| * if there are no matches. | |||
| */ | |||
| public Vector matches(String pattern, String input){ | |||
| RegexpMatcher matcher = (RegexpMatcher)matchers.get(pattern); | |||
| if (matcher == null){ | |||
| matcher = __reFactory.newRegexpMatcher(); | |||
| matcher.setPattern(pattern); | |||
| matchers.put(pattern, matcher); | |||
| } | |||
| return matcher.getGroups(input); | |||
| } | |||
| /** | |||
| * Try to resolve a symbolic link if it is one. | |||
| * @param toresolve the symbolic link to resolve. | |||
| * @return the resolved link if it is a symbolic link, otherwise | |||
| * return the original link. | |||
| */ | |||
| public File resolveSymbolicLink(File toresolve) throws BuildException { | |||
| String[] args = { "ls", "-l", toresolve.getAbsolutePath() }; | |||
| CmdResult res = cleartool(args); | |||
| if (res.getStatus() != 0 ){ | |||
| throw new BuildException(res.getStdErr()); | |||
| } | |||
| Vector groups = matches("symbolic link(.*)-->(.*)", res.getStdout()); | |||
| if (groups == null){ | |||
| return toresolve; // or null ? | |||
| } | |||
| String path = (String)groups.elementAt(2); | |||
| path = path.trim(); | |||
| File resolved = new File(path); | |||
| if ( !resolved.isAbsolute() ){ | |||
| resolved = new File(toresolve.getParent(), path); | |||
| } | |||
| return resolved; | |||
| } | |||
| /** | |||
| * Move a file to another. (ie rename) | |||
| */ | |||
| public void move(File from, File to) throws BuildException { | |||
| String[] args = {"move", "-nc", from.getPath(), to.getPath()}; | |||
| CmdResult res = cleartool(args); | |||
| if (res.getStatus() != 0) { | |||
| throw new BuildException(res.getStdErr()); | |||
| } | |||
| } | |||
| /** | |||
| * return the list of checkedout files in a given viewpath. | |||
| * @param viewpath the path to the view/directory to look for | |||
| * checkedout files. | |||
| * @param recurse <tt>true</tt> to look for files recursively, | |||
| * otherwise <tt>false</tt> | |||
| * @return the list of checkedout files in the view (full pathname). | |||
| */ | |||
| public Hashtable lsco(File viewpath, boolean recurse) { | |||
| String recurseParam = recurse ? "-r" : ""; | |||
| String fullpath = viewpath.getAbsolutePath(); | |||
| //@fixme is -cvi conflicting with -r ? | |||
| String[] args = {"lsco", recurseParam, "-cvi", "-s", "-me", fullpath}; | |||
| CmdResult res = cleartool(args); | |||
| if (res.getStatus() != 0) { | |||
| throw new BuildException(res.getStdErr()); | |||
| } | |||
| Vector lines = res.getStdoutLines(); | |||
| Hashtable map = toFiles(lines); | |||
| return map; | |||
| } | |||
| /** | |||
| * Transform a set of paths into canonical paths. | |||
| * Typically this should be used to transform a set of | |||
| * output lines by cleartool representing file paths. | |||
| */ | |||
| public static Hashtable toFiles(Vector paths){ | |||
| Hashtable map = new Hashtable(); | |||
| for (int i = 0; i < paths.size(); i++) { | |||
| String path = (String) paths.elementAt(i); | |||
| try { | |||
| // the path is normally the full path, we normally | |||
| // not need to do a new File(viewpath, path) | |||
| File f = new File(path); | |||
| path = f.getCanonicalPath(); | |||
| map.put(path, path); | |||
| } catch (IOException e) { | |||
| // assume it's not a file... | |||
| } | |||
| } | |||
| return map; | |||
| } | |||
| /** | |||
| * Returns the list of files that are *not* checked out. | |||
| * @see #lsco(File, boolean) | |||
| */ | |||
| public Hashtable lsnco(File viewpath){ | |||
| String[] args = {"find", viewpath.getAbsolutePath(), "-type", "f", "-cvi", "-nxn", "-print"}; | |||
| CmdResult res = cleartool(args); | |||
| Vector lines = res.getStdoutLines(); | |||
| Hashtable all = toFiles(lines); | |||
| Hashtable co = lsco(viewpath, true); | |||
| // remove the co files | |||
| Enumeration keys = co.keys(); | |||
| while ( keys.hasMoreElements() ){ | |||
| Object path = keys.nextElement(); | |||
| Object o = all.remove(path); | |||
| if (o == null){ | |||
| // oops how come a co file is not found by find ? | |||
| } | |||
| } | |||
| return all; | |||
| } | |||
| /** returns the list of private files in the view */ | |||
| public Hashtable lsprivate(File viewpath){ | |||
| // for a snapshot view, we must use ls -r -view_only | |||
| return null; | |||
| } | |||
| public void checkin(File file){ | |||
| String[] args = {"ci", "-nc", "-identical", file.getAbsolutePath()} ; | |||
| CmdResult res = cleartool(args); | |||
| if (res.getStatus() != 0){ | |||
| throw new BuildException(res.getStdErr()); | |||
| } | |||
| } | |||
| public void checkout(File file){ | |||
| String[] args = {"co", "-nc", "-unreserved", file.getAbsolutePath()} ; | |||
| CmdResult res = cleartool(args); | |||
| if (res.getStatus() != 0){ | |||
| throw new BuildException(res.getStdErr()); | |||
| } | |||
| } | |||
| public void uncheckout(File file){ | |||
| String[] args = {"unco", "-rm", file.getAbsolutePath() }; | |||
| CmdResult res = cleartool(args); | |||
| if (res.getStatus() != 0){ | |||
| throw new BuildException(res.getStdErr()); | |||
| } | |||
| } | |||
| public void mkdir(File file, String comment) { | |||
| } | |||
| public void mkdir(File file){ | |||
| String[] args = {"mkdir", "-nc", file.getAbsolutePath() }; | |||
| CmdResult res = cleartool(args); | |||
| if (res.getStatus() != 0){ | |||
| throw new BuildException(res.getStdErr()); | |||
| } | |||
| } | |||
| /** | |||
| * Helper method to execute a given cleartool command. | |||
| * @param args the parameters used to execute cleartool. | |||
| * @return the result of the command. | |||
| */ | |||
| public static CmdResult cleartool(String[] args) { | |||
| String[] nargs = new String[args.length + 1]; | |||
| nargs[0] = "cleartool"; | |||
| System.arraycopy(args, 0, nargs, 1, args.length); | |||
| ByteArrayOutputStream out = new ByteArrayOutputStream(); | |||
| ByteArrayOutputStream err = new ByteArrayOutputStream(); | |||
| ExecuteStreamHandler handler = new PumpStreamHandler(out, err); | |||
| Execute exe = new Execute(handler); | |||
| exe.setCommandline(nargs); | |||
| try { | |||
| int retcode = exe.execute(); | |||
| return new CmdResult(retcode, out.toString(), err.toString()); | |||
| } catch (IOException e){ | |||
| throw new BuildException(e); | |||
| } | |||
| } | |||
| /** | |||
| * Create the comment file used by cleartool commands. | |||
| */ | |||
| public static File createCommentFile(String comment) { | |||
| FileUtils futils = FileUtils.newFileUtils(); | |||
| File f = futils.createTempFile("ant_cc", ".tmp", new File(".")); | |||
| Writer writer = null; | |||
| try { | |||
| writer = new BufferedWriter(new FileWriter(f)); | |||
| writer.write(comment); | |||
| writer.flush(); | |||
| } catch (IOException e){ | |||
| throw new BuildException(e); | |||
| } finally { | |||
| if (writer != null){ | |||
| try { | |||
| writer.close(); | |||
| } catch (IOException e){ | |||
| } | |||
| } | |||
| } | |||
| return f; | |||
| } | |||
| } | |||
| @@ -1,97 +0,0 @@ | |||
| /* | |||
| * 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.optional.clearcase; | |||
| import java.util.Vector; | |||
| import org.apache.tools.ant.util.StringUtils; | |||
| /** | |||
| * | |||
| */ | |||
| public class CmdResult { | |||
| private String stdout; | |||
| private String stderr; | |||
| private int code = 0; | |||
| public CmdResult(int code, String stdout, String stderr){ | |||
| this.code = code; | |||
| this.stdout = stdout; | |||
| this.stderr = stderr; | |||
| } | |||
| public String getStdout(){ | |||
| return stdout; | |||
| } | |||
| public Vector getStdoutLines(){ | |||
| return StringUtils.lineSplit(stdout); | |||
| } | |||
| public String getStdErr(){ | |||
| return stderr; | |||
| } | |||
| public Vector getStdErrLines(){ | |||
| return StringUtils.lineSplit(stderr); | |||
| } | |||
| public int getStatus(){ | |||
| return code; | |||
| } | |||
| } | |||