ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject Performing changes to the PVCS repository.
Date Mon, 22 Mar 2004 17:01:15 GMT
I don't know if this issue has been discussed earlier here, but I 
wanted to contribute with a few lines in case someone finds it useful.

There is a very easy way to commit changes into a PVCS repository using 
the 'Pvcs' class from the Ant 'optional.pvcs' package. At present, this 
class supports ckeckouts and updates from the repository, making use on 
its 'execute' method of the PCLI commands (provided by PVCS).

You can use the PCLI commands you may need by constructing them and 
overriding the 'execute' method. In order to do this, you need access 
to the 'runCmd' method which is a protected one, so create a new class 
and inherit from the 'Pvcs' class or put it in the same package.

Also, note that you may perform any PVCS task this way from a Java 
program (not even using Ant). In this case, in order to keep using the 
existing Pvcs class, I think it is necessary to create an 'Ant task' so 
that a working directory can be established at runtime and the name of 
the antRun script set.

Finally, an example is included. 'MiPvcs' has a 'createFolder' method 
which is the one to be invoked by a Java programmer in order to create 
folders (or projects) into a previously established project database:


public class MiPvcs extends Pvcs {
	private static final String PCLI_EXE = "pcli";
	private String msg;

	public int createFolder(String folder) { 
		//An Ant project is created so that the name of the 
antRun script
                //can be set and a working directory established at 
		Project aProj = new Project();
		int result = -1;
		//Defining the command to execute
		Commandline commandLine = new Commandline();
		if (getWorkspace() != null) {
		  commandLine.createArgument().setValue("-sp" + 
		if (getRepository() != null && !getRepository().trim
().equals("")) {
		  commandLine.createArgument().setValue("-pr" + 
		} else {		    
		    msg = "A repository path is needed";
		    return -1;
		String uid = getUserId();
		if (uid != null) {
		  commandLine.createArgument().setValue("-id" + uid);
		//If Pvcsproject() == null, by default, "/" is 
established by PCLI
		//The project's path can also be established within the 
                //argument (the folder or project to create)
		if (getPvcsproject() != null) {
		  commandLine.createArgument().setValue("-pp" + 
		//The last argument is the folder or project to create
		try {
		  result = runCmd(commandLine,  
		  		new PumpStreamHandler(System.out, 
		  				new LogOutputStream

		  System.out.println("Result: " + result);
		  switch (result) {
		  	case 0: break;
		  	case -3:
		  	case -6 : msg = "Check out that the repository 
exists and the 
project has not been created yet"; break;		  	
		  	case -11 : msg = "An argument is missing"; 
		  	case -12 : msg = "Security exception"; break;
		  	default : msg = "Execution failed: " + 

	    } catch (Exception e) { 
	        msg = "Execution failed: " + commandLine.toString();
	        return -1;
	    return result;

        //The method below has been copied from the 'Pvcs' class itself.
        //As it's private you need to define it again here (if you feel 
you need it)
	private String getExecutable(String exe) {
		StringBuffer correctedExe = new StringBuffer();
		if (getPvcsbin() != null) {
		   if (getPvcsbin().endsWith(File.separator)) {
		   } else {
		return correctedExe.append(exe).toString();
	public String getErrorMsg() {
		return msg;

Take a look at the 'Pvcs' class itself for better code.
Thanks to Thomas Christensen for his help.

Juan Manuel López García.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message