use of org.codehaus.plexus.util.cli.CommandLineException in project maven-scm by apache.
the class PerforceCheckInCommand method executeCheckInCommand.
/**
* {@inheritDoc}
*/
@Override
protected CheckInScmResult executeCheckInCommand(ScmProviderRepository repo, ScmFileSet files, String message, ScmVersion version) throws ScmException {
Commandline cl = createCommandLine((PerforceScmProviderRepository) repo, files.getBasedir());
PerforceCheckInConsumer consumer = new PerforceCheckInConsumer();
try {
String jobs = System.getProperty("maven.scm.jobs");
if (getLogger().isDebugEnabled()) {
getLogger().debug(PerforceScmProvider.clean("Executing " + cl.toString()));
}
PerforceScmProviderRepository prepo = (PerforceScmProviderRepository) repo;
String changes = createChangeListSpecification(prepo, files, message, PerforceScmProvider.getRepoPath(getLogger(), prepo, files.getBasedir()), jobs);
if (getLogger().isDebugEnabled()) {
getLogger().debug("Sending changelist:\n" + changes);
}
CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
int exitCode = CommandLineUtils.executeCommandLine(cl, new ByteArrayInputStream(changes.getBytes()), 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 CheckInScmResult(cl.toString(), consumer.isSuccess() ? "Checkin successful" : "Unable to submit", consumer.getOutput(), consumer.isSuccess());
}
use of org.codehaus.plexus.util.cli.CommandLineException in project maven-scm by apache.
the class PerforceDiffCommand method executeDiffCommand.
/**
* {@inheritDoc}
*/
protected DiffScmResult executeDiffCommand(ScmProviderRepository repo, ScmFileSet files, ScmVersion startRev, ScmVersion endRev) throws ScmException {
Commandline cl = createCommandLine((PerforceScmProviderRepository) repo, files.getBasedir(), startRev, endRev);
PerforceDiffConsumer consumer = new PerforceDiffConsumer();
if (getLogger().isInfoEnabled()) {
getLogger().info("Executing: " + PerforceScmProvider.clean(cl.toString()));
}
boolean success = false;
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 DiffScmResult(cl.toString(), success ? "Diff successful" : "Unable to diff", consumer.getOutput(), success);
}
use of org.codehaus.plexus.util.cli.CommandLineException in project maven-scm by apache.
the class PerforceEditCommand method executeEditCommand.
/**
* {@inheritDoc}
*/
@Override
protected ScmResult executeEditCommand(ScmProviderRepository repo, ScmFileSet files) throws ScmException {
Commandline cl = createCommandLine((PerforceScmProviderRepository) repo, files.getBasedir(), files);
PerforceEditConsumer consumer = new PerforceEditConsumer();
try {
if (getLogger().isDebugEnabled()) {
getLogger().debug(PerforceScmProvider.clean("Executing " + cl.toString()));
}
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 EditScmResult(cl.toString(), consumer.getEdits());
}
return new EditScmResult(cl.toString(), "Unable to edit file(s)", consumer.getErrorMessage(), false);
}
use of org.codehaus.plexus.util.cli.CommandLineException in project maven-scm by apache.
the class PerforceLoginCommand method executeLoginCommand.
/**
* {@inheritDoc}
*/
public LoginScmResult executeLoginCommand(ScmProviderRepository repo, ScmFileSet files, CommandParameters params) throws ScmException {
Commandline cl = createCommandLine((PerforceScmProviderRepository) repo, files.getBasedir());
PerforceLoginConsumer consumer = new PerforceLoginConsumer();
boolean isSuccess = false;
try {
String password = repo.getPassword();
if (StringUtils.isEmpty(password)) {
if (getLogger().isInfoEnabled()) {
getLogger().info("No password found, proceeding without it.");
}
isSuccess = true;
} else {
CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
int exitCode = CommandLineUtils.executeCommandLine(cl, new ByteArrayInputStream(password.getBytes()), consumer, err);
isSuccess = consumer.isSuccess();
if (!isSuccess) {
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) {
throw new ScmException(e.getMessage(), e);
}
return new LoginScmResult(cl.toString(), isSuccess ? "Login successful" : "Login failed", consumer.getOutput(), isSuccess);
}
use of org.codehaus.plexus.util.cli.CommandLineException in project maven-scm by apache.
the class PerforceInfoCommand method executeCommand.
/**
* {@inheritDoc}
*/
protected ScmResult executeCommand(ScmProviderRepository repo, ScmFileSet scmFileSet, CommandParameters commandParameters) throws ScmException {
if (!PerforceScmProvider.isLive()) {
return null;
}
InputStreamReader isReader = null;
try {
Commandline command = PerforceScmProvider.createP4Command((PerforceScmProviderRepository) repo, null);
command.createArg().setValue("info");
if (getLogger().isDebugEnabled()) {
getLogger().debug(PerforceScmProvider.clean("Executing: " + command.toString()));
}
Process proc = command.execute();
isReader = new InputStreamReader(proc.getInputStream());
BufferedReader br = new BufferedReader(isReader);
String line;
entries = new HashMap<String, String>();
while ((line = br.readLine()) != null) {
int idx = line.indexOf(':');
if (idx == -1) {
if (line.indexOf("Client unknown.") == -1) {
throw new IllegalStateException("Unexpected results from 'p4 info' command: " + line);
}
if (getLogger().isDebugEnabled()) {
getLogger().debug("Cannot find client.");
}
entries.put("Client root", "");
} else {
String key = line.substring(0, idx);
String value = line.substring(idx + 1).trim();
entries.put(key, value);
}
}
} catch (CommandLineException e) {
throw new ScmException(e.getLocalizedMessage());
} catch (IOException e) {
throw new ScmException(e.getLocalizedMessage());
} finally {
IOUtil.close(isReader);
}
return null;
}
Aggregations