use of org.apache.maven.scm.provider.integrity.APISession in project maven-scm by apache.
the class IntegrityDiffCommand method executeDiffCommand.
/**
* Since we can't arbitrarily apply the same start and end revisions to all files in the sandbox,
* this command will be adapted to show differences between the local version and the repository
*/
@Override
public DiffScmResult executeDiffCommand(ScmProviderRepository repository, ScmFileSet fileSet, ScmVersion startRevision, ScmVersion endRevision) throws ScmException {
DiffScmResult result;
IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
APISession api = iRepo.getAPISession();
getLogger().info("Showing differences bettween local files in " + fileSet.getBasedir().getAbsolutePath() + " and server project " + iRepo.getConfigruationPath());
// Since the si diff command is not completely API ready, we will use the CLI for this command
Commandline shell = new Commandline();
shell.setWorkingDirectory(fileSet.getBasedir());
shell.setExecutable("si");
shell.createArg().setValue("diff");
shell.createArg().setValue("--hostname=" + api.getHostName());
shell.createArg().setValue("--port=" + api.getPort());
shell.createArg().setValue("--user=" + api.getUserName());
shell.createArg().setValue("-R");
shell.createArg().setValue("--filter=changed:all");
shell.createArg().setValue("--filter=format:text");
IntegrityDiffConsumer shellConsumer = new IntegrityDiffConsumer(getLogger());
try {
getLogger().debug("Executing: " + shell.getCommandline());
int exitCode = CommandLineUtils.executeCommandLine(shell, shellConsumer, new CommandLineUtils.StringStreamConsumer());
boolean success = (exitCode == 128 ? false : true);
ScmResult scmResult = new ScmResult(shell.getCommandline().toString(), "", "Exit Code: " + exitCode, success);
// a NPE in org.codehaus.plexus.util.FileUtils.fileWrite(FileUtils.java:426)
return new DiffScmResult(new ArrayList<ScmFile>(), new HashMap<String, CharSequence>(), "", scmResult);
} catch (CommandLineException cle) {
getLogger().error("Command Line Exception: " + cle.getMessage());
result = new DiffScmResult(shell.getCommandline().toString(), cle.getMessage(), "", false);
}
return result;
}
use of org.apache.maven.scm.provider.integrity.APISession in project maven-scm by apache.
the class IntegrityFileInfoCommand method executeFileInfoCommand.
/**
* Even though this command is supported via the MKS JAVA API, since at this time we really don't
* know what the SCM plugin is looking to get in return for this command, we're simply going to
* run this command via the CLI and return the output verbatim
*/
@Override
public ScmResult executeFileInfoCommand(ScmProviderRepository repository, File workingDirectory, String filename) throws ScmException {
getLogger().info("Attempting to display scm file information for file: " + filename);
if (null == filename || filename.length() == 0) {
throw new ScmException("A single filename is required to execute the fileinfo command!");
}
ScmResult result;
IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
APISession api = iRepo.getAPISession();
Commandline shell = new Commandline();
shell.setWorkingDirectory(workingDirectory);
shell.setExecutable("si");
shell.createArg().setValue("memberinfo");
shell.createArg().setValue("--hostname=" + api.getHostName());
shell.createArg().setValue("--port=" + api.getPort());
shell.createArg().setValue("--user=" + api.getUserName());
shell.createArg().setValue('"' + filename + '"');
IntegrityFileInfoConsumer shellConsumer = new IntegrityFileInfoConsumer(getLogger());
try {
getLogger().debug("Executing: " + shell.getCommandline());
int exitCode = CommandLineUtils.executeCommandLine(shell, shellConsumer, new CommandLineUtils.StringStreamConsumer());
boolean success = (exitCode == 128 ? false : true);
result = new ScmResult(shell.getCommandline().toString(), "", "Exit Code: " + exitCode, success);
} catch (CommandLineException cle) {
getLogger().error("Command Line Exception: " + cle.getMessage());
result = new ScmResult(shell.getCommandline().toString(), cle.getMessage(), "", false);
}
return result;
}
use of org.apache.maven.scm.provider.integrity.APISession in project maven-scm by apache.
the class IntegrityLoginCommand method executeLoginCommand.
/**
* {@inheritDoc}
*/
@Override
public LoginScmResult executeLoginCommand(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters params) throws ScmException {
getLogger().info("Attempting to connect with the MKS Integrity Server");
LoginScmResult result;
IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
APISession api = iRepo.getAPISession();
try {
// First we will establish a connection to the MKS Integrity Server
Response res = api.connect(iRepo.getHost(), iRepo.getPort(), iRepo.getUser(), iRepo.getPassword());
int exitCode = res.getExitCode();
boolean success = (exitCode == 0 ? true : false);
result = new LoginScmResult(res.getCommandString(), "", "Exit Code: " + exitCode, success);
// Next we will prepare the Project and Sandbox for the other commands
Project siProject = new Project(api, iRepo.getConfigruationPath());
Sandbox siSandbox = new Sandbox(api, siProject, fileSet.getBasedir().getAbsolutePath());
iRepo.setProject(siProject);
iRepo.setSandbox(siSandbox);
} catch (APIException aex) {
ExceptionHandler eh = new ExceptionHandler(aex);
getLogger().error("MKS API Exception: " + eh.getMessage());
getLogger().info(eh.getCommand() + " exited with return code " + eh.getExitCode());
result = new LoginScmResult(eh.getCommand(), eh.getMessage(), "Exit Code: " + eh.getExitCode(), false);
}
return result;
}
Aggregations