use of org.apache.maven.scm.command.login.LoginScmResult 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);
}
Aggregations