compatibility for now because I try to deal with multiple files, they will stay here. This code has not been tested yet and the commands even be validated since I do not have clearcase at home (how surprising eh ? :) Some tests at work show that output is not exactly the one described in the manual and that I nearly never have the full path but rather the absolute path from the view. ie under Windows the drive is missing and under Unix the '/vobs/' is missing.... If a Clearcase guru wants to contribute he is very welcome... :-) git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270541 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -0,0 +1,124 @@ | |||
| /* | |||
| * The Apache Software License, Version 1.1 | |||
| * | |||
| * Copyright (c) 2001 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 | |||
| * | |||
| * @author <a href="mailto:sbailliez@apache.org">Stephane Bailliez</a> | |||
| */ | |||
| 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; | |||
| } | |||
| } | |||
| @@ -0,0 +1,132 @@ | |||
| /* | |||
| * The Apache Software License, Version 1.1 | |||
| * | |||
| * Copyright (c) 2001 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 | |||
| * | |||
| * @author <a href="mailto:sbailliez@apache.org">Stephane Bailliez</a> | |||
| */ | |||
| 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; | |||
| } | |||
| } | |||
| @@ -0,0 +1,135 @@ | |||
| /* | |||
| * The Apache Software License, Version 1.1 | |||
| * | |||
| * Copyright (c) 2001 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. | |||
| * | |||
| * @author <a href="mailto:sbailliez@apache.org">Stephane Bailliez</a> | |||
| */ | |||
| public class CCFile extends File { | |||
| /** is it checkedout */ | |||
| private boolean checkedout; | |||
| /** is it under source control ? */ | |||
| private boolean versioned; | |||
| /** was this file already described once ? */ | |||
| private boolean described; | |||
| 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); | |||
| } | |||
| } | |||
| @@ -0,0 +1,161 @@ | |||
| /* | |||
| * The Apache Software License, Version 1.1 | |||
| * | |||
| * Copyright (c) 2001 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; | |||
| /** | |||
| * | |||
| * @author <a href="mailto:sbailliez@apache.org">Stephane Bailliez</a> | |||
| */ | |||
| public abstract class CCMatchingTask extends MatchingTask { | |||
| protected File viewpath; | |||
| protected CCUtils utils = new CCUtils(this); | |||
| protected Hashtable files = null; | |||
| protected String comment = null; | |||
| protected File commentFile; | |||
| protected String[] options; | |||
| public void setViewPath(File value){ | |||
| this.viewpath = value; | |||
| } | |||
| public void setComment(String value){ | |||
| comment = value; | |||
| } | |||
| protected abstract Vector getOptions(); | |||
| protected boolean accept(CCFile file){ | |||
| return true; | |||
| } | |||
| public void execute() throws BuildException { | |||
| try { | |||
| preExecute(); | |||
| doExecute(); | |||
| } finally { | |||
| postExecute(); | |||
| } | |||
| } | |||
| 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); | |||
| } | |||
| protected void postExecute(){ | |||
| if (commentFile != null){ | |||
| commentFile.delete(); | |||
| } | |||
| } | |||
| protected void doExecute() throws BuildException { | |||
| Enumeration elems = getFiles().elements(); | |||
| log("Processing " + files.size() + " elements..."); | |||
| while ( elems.hasMoreElements() ){ | |||
| execute(options, (CCFile)elems.nextElement()); | |||
| } | |||
| } | |||
| 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()); | |||
| } | |||
| } | |||
| 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; | |||
| } | |||
| 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); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,160 @@ | |||
| /* | |||
| * The Apache Software License, Version 1.1 | |||
| * | |||
| * Copyright (c) 2001 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 | |||
| * | |||
| * @author <a href="mailto:sbailliez@apache.org">Stephane Bailliez</a> | |||
| */ | |||
| 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() ){ | |||
| // 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; | |||
| } | |||
| // 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; | |||
| } | |||
| } | |||
| @@ -0,0 +1,126 @@ | |||
| /* | |||
| * The Apache Software License, Version 1.1 | |||
| * | |||
| * Copyright (c) 2001 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 | |||
| * | |||
| * @author <a href="mailto:sbailliez@apache.org">Stephane Bailliez</a> | |||
| */ | |||
| 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; | |||
| } | |||
| } | |||
| @@ -0,0 +1,124 @@ | |||
| /* | |||
| * The Apache Software License, Version 1.1 | |||
| * | |||
| * Copyright (c) 2001 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 | |||
| * | |||
| * @author <a href="mailto:sbailliez@apache.org">Stephane Bailliez</a> | |||
| */ | |||
| 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; | |||
| } | |||
| } | |||
| @@ -0,0 +1,294 @@ | |||
| /* | |||
| * The Apache Software License, Version 1.1 | |||
| * | |||
| * Copyright (c) 2001 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.StringUtils; | |||
| 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. | |||
| * | |||
| * @author <a href="mailto:sbailliez@apache.org">Stephane Bailliez</a> | |||
| */ | |||
| 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 Exception { | |||
| 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 Exception { | |||
| 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()); | |||
| } | |||
| } | |||
| /** | |||
| * 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; | |||
| } | |||
| } | |||
| @@ -0,0 +1,98 @@ | |||
| /* | |||
| * The Apache Software License, Version 1.1 | |||
| * | |||
| * Copyright (c) 2001 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; | |||
| /** | |||
| * | |||
| * @author <a href="mailto:sbailliez@apache.org">Stephane Bailliez</a> | |||
| */ | |||
| 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; | |||
| } | |||
| } | |||