use of org.codehaus.plexus.util.cli.CommandLineException in project maven-scm by apache.
the class CvsExeExportCommand method executeCvsCommand.
/**
* {@inheritDoc}
*/
protected ExportScmResult executeCvsCommand(Commandline cl) throws ScmException {
CvsUpdateConsumer consumer = new CvsUpdateConsumer(getLogger());
CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
int exitCode;
try {
exitCode = CommandLineUtils.executeCommandLine(cl, consumer, stderr);
} catch (CommandLineException ex) {
throw new ScmException("Error while executing command.", ex);
}
if (exitCode != 0) {
return new ExportScmResult(cl.toString(), "The cvs command failed.", stderr.getOutput(), false);
}
return new ExportScmResult(cl.toString(), consumer.getUpdatedFiles());
}
use of org.codehaus.plexus.util.cli.CommandLineException 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.codehaus.plexus.util.cli.CommandLineException 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.codehaus.plexus.util.cli.CommandLineException in project maven-scm by apache.
the class SvnBranchCommand method executeBranchCommand.
public ScmResult executeBranchCommand(ScmProviderRepository repo, ScmFileSet fileSet, String branch, ScmBranchParameters scmBranchParameters) throws ScmException {
if (branch == null || StringUtils.isEmpty(branch.trim())) {
throw new ScmException("branch name must be specified");
}
if (!fileSet.getFileList().isEmpty()) {
throw new ScmException("This provider doesn't support branching subsets of a directory");
}
SvnScmProviderRepository repository = (SvnScmProviderRepository) repo;
File messageFile = FileUtils.createTempFile("maven-scm-", ".commit", null);
try {
FileUtils.fileWrite(messageFile.getAbsolutePath(), scmBranchParameters.getMessage());
} catch (IOException ex) {
return new BranchScmResult(null, "Error while making a temporary file for the commit message: " + ex.getMessage(), null, false);
}
Commandline cl = createCommandLine(repository, fileSet.getBasedir(), branch, messageFile, scmBranchParameters);
CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
if (getLogger().isInfoEnabled()) {
getLogger().info("Executing: " + SvnCommandLineUtils.cryptPassword(cl));
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
getLogger().info("Working directory: " + cl.getWorkingDirectory().getAbsolutePath());
}
}
int exitCode;
try {
exitCode = SvnCommandLineUtils.execute(cl, stdout, stderr, getLogger());
} catch (CommandLineException ex) {
throw new ScmException("Error while executing command.", ex);
} finally {
try {
FileUtils.forceDelete(messageFile);
} catch (IOException ex) {
// ignore
}
}
if (exitCode != 0) {
return new BranchScmResult(cl.toString(), "The svn branch command failed.", stderr.getOutput(), false);
}
List<ScmFile> fileList = new ArrayList<ScmFile>();
List<File> files = null;
try {
@SuppressWarnings("unchecked") List<File> listFiles = FileUtils.getFiles(fileSet.getBasedir(), "**", "**/.svn/**", false);
files = listFiles;
} catch (IOException e) {
throw new ScmException("Error while executing command.", e);
}
for (File f : files) {
fileList.add(new ScmFile(f.getPath(), ScmFileStatus.TAGGED));
}
return new BranchScmResult(cl.toString(), fileList);
}
use of org.codehaus.plexus.util.cli.CommandLineException in project maven-scm by apache.
the class SvnChangeLogCommand method executeChangeLogCommand.
private ChangeLogScmResult executeChangeLogCommand(ScmProviderRepository repo, ScmFileSet fileSet, Date startDate, Date endDate, ScmBranch branch, String datePattern, ScmVersion startVersion, ScmVersion endVersion, Integer limit) throws ScmException {
Commandline cl = createCommandLine((SvnScmProviderRepository) repo, fileSet.getBasedir(), branch, startDate, endDate, startVersion, endVersion, limit);
SvnChangeLogConsumer consumer = new SvnChangeLogConsumer(getLogger(), datePattern);
CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
if (getLogger().isInfoEnabled()) {
getLogger().info("Executing: " + SvnCommandLineUtils.cryptPassword(cl));
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
getLogger().info("Working directory: " + cl.getWorkingDirectory().getAbsolutePath());
}
}
int exitCode;
try {
exitCode = SvnCommandLineUtils.execute(cl, consumer, stderr, getLogger());
} catch (CommandLineException ex) {
throw new ScmException("Error while executing svn command.", ex);
}
if (exitCode != 0) {
return new ChangeLogScmResult(cl.toString(), "The svn command failed.", stderr.getOutput(), false);
}
ChangeLogSet changeLogSet = new ChangeLogSet(consumer.getModifications(), startDate, endDate);
changeLogSet.setStartVersion(startVersion);
changeLogSet.setEndVersion(endVersion);
return new ChangeLogScmResult(cl.toString(), changeLogSet);
}
Aggregations