use of org.codehaus.plexus.util.cli.Commandline in project maven-scm by apache.
the class PerforceUnEditCommand method createCommandLine.
public static Commandline createCommandLine(PerforceScmProviderRepository repo, File workingDirectory, ScmFileSet files) {
Commandline command = PerforceScmProvider.createP4Command(repo, workingDirectory);
command.createArg().setValue("revert");
List<File> fs = files.getFileList();
for (File file : fs) {
command.createArg().setValue(file.getName());
}
return command;
}
use of org.codehaus.plexus.util.cli.Commandline in project maven-scm by apache.
the class PerforceUnEditCommand method executeUnEditCommand.
/**
* {@inheritDoc}
*/
protected ScmResult executeUnEditCommand(ScmProviderRepository repo, ScmFileSet files) throws ScmException {
Commandline cl = createCommandLine((PerforceScmProviderRepository) repo, files.getBasedir(), files);
PerforceUnEditConsumer consumer = new PerforceUnEditConsumer();
try {
CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
int exitCode = CommandLineUtils.executeCommandLine(cl, consumer, err);
if (exitCode != 0) {
String cmdLine = CommandLineUtils.toString(cl.getCommandline());
StringBuilder msg = new StringBuilder("Exit code: " + exitCode + " - " + err.getOutput());
msg.append('\n');
msg.append("Command line was:" + cmdLine);
throw new CommandLineException(msg.toString());
}
} catch (CommandLineException e) {
if (getLogger().isErrorEnabled()) {
getLogger().error("CommandLineException " + e.getMessage(), e);
}
}
if (consumer.isSuccess()) {
return new UnEditScmResult(cl.toString(), consumer.getEdits());
}
return new UnEditScmResult(cl.toString(), "Unable to revert", consumer.getOutput(), consumer.isSuccess());
}
use of org.codehaus.plexus.util.cli.Commandline in project maven-scm by apache.
the class PerforceScmProvider method createP4Command.
public static Commandline createP4Command(PerforceScmProviderRepository repo, File workingDir) {
Commandline command = new Commandline();
command.setExecutable("p4");
if (workingDir != null) {
// SCM-209
command.createArg().setValue("-d");
command.createArg().setValue(workingDir.getAbsolutePath());
}
if (repo.getHost() != null) {
command.createArg().setValue("-p");
String value = "";
if (!StringUtils.isBlank(repo.getProtocol())) {
value += repo.getProtocol() + ":";
}
value += repo.getHost();
if (repo.getPort() != 0) {
value += ":" + Integer.toString(repo.getPort());
}
command.createArg().setValue(value);
}
if (StringUtils.isNotEmpty(repo.getUser())) {
command.createArg().setValue("-u");
command.createArg().setValue(repo.getUser());
}
if (StringUtils.isNotEmpty(repo.getPassword())) {
command.createArg().setValue("-P");
command.createArg().setValue(repo.getPassword());
}
return command;
}
use of org.codehaus.plexus.util.cli.Commandline in project maven-scm by apache.
the class PerforceScmProvider method isLive.
public static boolean isLive() {
if (live == null) {
if (!Boolean.getBoolean("maven.scm.testing")) {
// We are not executing in the tests so we are live.
live = Boolean.TRUE;
} else {
// anything that requires an active server connection.
try {
Commandline command = new Commandline();
command.setExecutable("p4");
Process proc = command.execute();
BufferedReader br = new BufferedReader(new InputStreamReader(proc.getInputStream()));
@SuppressWarnings("unused") String line;
while ((line = br.readLine()) != null) {
// System.out.println(line);
}
int rc = proc.exitValue();
live = (rc == 0 ? Boolean.TRUE : Boolean.FALSE);
} catch (Exception e) {
e.printStackTrace();
live = Boolean.FALSE;
}
}
}
return live.booleanValue();
}
use of org.codehaus.plexus.util.cli.Commandline in project maven-scm by apache.
the class PerforceAddCommand method executeAddCommand.
/**
* {@inheritDoc}
*/
protected ScmResult executeAddCommand(ScmProviderRepository repo, ScmFileSet files, String message, boolean binary) throws ScmException {
Commandline cl = createCommandLine((PerforceScmProviderRepository) repo, files.getBasedir(), files);
PerforceAddConsumer consumer = new PerforceAddConsumer();
try {
CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
int exitCode = CommandLineUtils.executeCommandLine(cl, consumer, err);
if (exitCode != 0) {
String cmdLine = CommandLineUtils.toString(cl.getCommandline());
StringBuilder msg = new StringBuilder("Exit code: " + exitCode + " - " + err.getOutput());
msg.append('\n');
msg.append("Command line was:" + cmdLine);
throw new CommandLineException(msg.toString());
}
} catch (CommandLineException e) {
if (getLogger().isErrorEnabled()) {
getLogger().error("CommandLineException " + e.getMessage(), e);
}
}
return new AddScmResult(cl.toString(), consumer.getAdditions());
}
Aggregations