use of org.codehaus.plexus.util.cli.CommandLineException in project maven-scm by apache.
the class SvnBlameCommand method executeBlameCommand.
/**
* {@inheritDoc}
*/
public BlameScmResult executeBlameCommand(ScmProviderRepository repo, ScmFileSet workingDirectory, String filename) throws ScmException {
Commandline cl = createCommandLine((SvnScmProviderRepository) repo, workingDirectory.getBasedir(), filename);
SvnBlameConsumer consumer = new SvnBlameConsumer(getLogger());
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 command.", ex);
}
if (exitCode != 0) {
return new BlameScmResult(cl.toString(), "The svn command failed.", stderr.getOutput(), false);
}
return new BlameScmResult(cl.toString(), consumer.getLines());
}
use of org.codehaus.plexus.util.cli.CommandLineException in project maven-scm by apache.
the class SvnExeExportCommand method executeExportCommand.
/**
* {@inheritDoc}
*/
protected ExportScmResult executeExportCommand(ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion version, String outputDirectory) throws ScmException {
if (outputDirectory == null) {
outputDirectory = fileSet.getBasedir().getAbsolutePath();
}
SvnScmProviderRepository repository = (SvnScmProviderRepository) repo;
String url = repository.getUrl();
if (version != null && StringUtils.isNotEmpty(version.getName())) {
if (version instanceof ScmTag) {
url = SvnTagBranchUtils.resolveTagUrl(repository, (ScmTag) version);
} else if (version instanceof ScmBranch) {
url = SvnTagBranchUtils.resolveBranchUrl(repository, (ScmBranch) version);
}
}
url = SvnCommandUtils.fixUrl(url, repository.getUser());
Commandline cl = createCommandLine((SvnScmProviderRepository) repo, fileSet.getBasedir(), version, url, outputDirectory);
SvnUpdateConsumer consumer = new SvnUpdateConsumer(getLogger(), fileSet.getBasedir());
CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
if (getLogger().isInfoEnabled()) {
getLogger().info("Executing: " + SvnCommandLineUtils.cryptPassword(cl));
if (cl.getWorkingDirectory() != null && 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 command.", ex);
}
if (exitCode != 0) {
return new ExportScmResult(cl.toString(), "The svn command failed.", stderr.getOutput(), false);
}
return new ExportScmResultWithRevision(cl.toString(), consumer.getUpdatedFiles(), String.valueOf(consumer.getRevision()));
}
use of org.codehaus.plexus.util.cli.CommandLineException in project maven-scm by apache.
the class SvnMkdirCommand method executeMkdirCommand.
/**
* {@inheritDoc}
*/
protected MkdirScmResult executeMkdirCommand(ScmProviderRepository repository, ScmFileSet fileSet, String message, boolean createInLocal) throws ScmException {
File messageFile = FileUtils.createTempFile("maven-scm-", ".commit", null);
try {
FileUtils.fileWrite(messageFile.getAbsolutePath(), message);
} catch (IOException ex) {
return new MkdirScmResult(null, "Error while making a temporary file for the mkdir message: " + ex.getMessage(), null, false);
}
Commandline cl = createCommandLine((SvnScmProviderRepository) repository, fileSet, messageFile, createInLocal);
SvnMkdirConsumer consumer = new SvnMkdirConsumer(getLogger());
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 command.", ex);
} finally {
try {
FileUtils.forceDelete(messageFile);
} catch (IOException ex) {
// ignore
}
}
if (exitCode != 0) {
return new MkdirScmResult(cl.toString(), "The svn command failed.", stderr.getOutput(), false);
}
if (createInLocal) {
return new MkdirScmResult(cl.toString(), consumer.getCreatedDirs());
} else {
return new MkdirScmResult(cl.toString(), Integer.toString(consumer.getRevision()));
}
}
use of org.codehaus.plexus.util.cli.CommandLineException in project maven-scm by apache.
the class SvnRemoteInfoCommand method executeRemoteInfoCommand.
@Override
public RemoteInfoScmResult executeRemoteInfoCommand(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
String url = ((SvnScmProviderRepository) repository).getUrl();
// use a default svn layout, url is here http://svn.apache.org/repos/asf/maven/maven-3/trunk
// so as we presume we have good users using standard svn layout, we calculate tags and branches url
String baseUrl = StringUtils.endsWith(url, "/") ? StringUtils.substringAfter(StringUtils.removeEnd(url, "/"), "/") : StringUtils.substringBeforeLast(url, "/");
Commandline cl = SvnCommandLineUtils.getBaseSvnCommandLine(fileSet == null ? null : fileSet.getBasedir(), (SvnScmProviderRepository) repository);
cl.createArg().setValue("ls");
cl.createArg().setValue(baseUrl + "/tags");
CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
LsConsumer consumer = new LsConsumer(getLogger(), baseUrl);
int exitCode = 0;
Map<String, String> tagsInfos = null;
try {
exitCode = SvnCommandLineUtils.execute(cl, consumer, stderr, getLogger());
tagsInfos = consumer.infos;
} catch (CommandLineException ex) {
throw new ScmException("Error while executing svn command.", ex);
}
if (exitCode != 0) {
return new RemoteInfoScmResult(cl.toString(), "The svn command failed.", stderr.getOutput(), false);
}
cl = SvnCommandLineUtils.getBaseSvnCommandLine(fileSet == null ? null : fileSet.getBasedir(), (SvnScmProviderRepository) repository);
cl.createArg().setValue("ls");
cl.createArg().setValue(baseUrl + "/tags");
stderr = new CommandLineUtils.StringStreamConsumer();
consumer = new LsConsumer(getLogger(), baseUrl);
Map<String, String> branchesInfos = null;
try {
exitCode = SvnCommandLineUtils.execute(cl, consumer, stderr, getLogger());
branchesInfos = consumer.infos;
} catch (CommandLineException ex) {
throw new ScmException("Error while executing svn command.", ex);
}
if (exitCode != 0) {
return new RemoteInfoScmResult(cl.toString(), "The svn command failed.", stderr.getOutput(), false);
}
return new RemoteInfoScmResult(cl.toString(), branchesInfos, tagsInfos);
}
use of org.codehaus.plexus.util.cli.CommandLineException in project maven-scm by apache.
the class PerforceCheckOutCommand method getLastChangelist.
private int getLastChangelist(PerforceScmProviderRepository repo, File workingDirectory, String specname) {
int lastChangelist = 0;
try {
Commandline command = PerforceScmProvider.createP4Command(repo, workingDirectory);
command.createArg().setValue("-c" + specname);
command.createArg().setValue("changes");
command.createArg().setValue("-m1");
command.createArg().setValue("-ssubmitted");
command.createArg().setValue("//" + specname + "/...");
getLogger().debug("Executing: " + PerforceScmProvider.clean(command.toString()));
Process proc = command.execute();
BufferedReader br = new BufferedReader(new InputStreamReader(proc.getInputStream()));
String line;
String lastChangelistStr = "";
while ((line = br.readLine()) != null) {
getLogger().debug("Consuming: " + line);
Pattern changeRegexp = Pattern.compile("Change (\\d+)");
Matcher matcher = changeRegexp.matcher(line);
if (matcher.find()) {
lastChangelistStr = matcher.group(1);
}
}
br.close();
try {
lastChangelist = Integer.parseInt(lastChangelistStr);
} catch (NumberFormatException nfe) {
getLogger().debug("Could not parse changelist from line " + line);
}
} catch (IOException e) {
getLogger().error(e);
} catch (CommandLineException e) {
getLogger().error(e);
}
return lastChangelist;
}
Aggregations