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:
import org.apache.tools.ant.taskdefs.optional.pvcs.*;
import java.io.File;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.LogOutputStream;
import org.apache.tools.ant.taskdefs.PumpStreamHandler;
import org.apache.tools.ant.types.Commandline;
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
runtime
Project aProj = new Project();
setProject(aProj);
int result = -1;
//Defining the command to execute
Commandline commandLine = new Commandline();
commandLine.setExecutable(getExecutable(PCLI_EXE));
commandLine.createArgument().setValue("CreateProject");
if (getWorkspace() != null) {
commandLine.createArgument().setValue("-sp" +
getWorkspace());
}
if (getRepository() != null && !getRepository().trim
().equals("")) {
commandLine.createArgument().setValue("-pr" +
getRepository());
} 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
last
//argument (the folder or project to create)
if (getPvcsproject() != null) {
commandLine.createArgument().setValue("-pp" +
getPvcsproject());
}
//The last argument is the folder or project to create
commandLine.createArgument().setValue(folder);
try {
result = runCmd(commandLine,
new PumpStreamHandler(System.out,
new LogOutputStream
(this,
Project.MSG_WARN)));
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";
break;
case -12 : msg = "Security exception"; break;
default : msg = "Execution failed: " +
commandLine.toString();
break;
}
} 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)) {
correctedExe.append(getPvcsbin());
} else {
correctedExe.append(getPvcsbin()).append
(File.separator);
}
}
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.
[EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]