use of org.codehaus.plexus.util.cli.CommandLineException in project maven-scm by apache.
the class SvnTagCommand method executeTagCommand.
/**
* {@inheritDoc}
*/
public ScmResult executeTagCommand(ScmProviderRepository repo, ScmFileSet fileSet, String tag, ScmTagParameters scmTagParameters) throws ScmException {
// NPE free
if (scmTagParameters == null) {
getLogger().debug("SvnTagCommand :: scmTagParameters is null create an empty one");
scmTagParameters = new ScmTagParameters();
scmTagParameters.setRemoteTagging(false);
} else {
getLogger().debug("SvnTagCommand :: scmTagParameters.remoteTagging : " + scmTagParameters.isRemoteTagging());
}
if (tag == null || StringUtils.isEmpty(tag.trim())) {
throw new ScmException("tag must be specified");
}
if (!fileSet.getFileList().isEmpty()) {
throw new ScmException("This provider doesn't support tagging subsets of a directory");
}
SvnScmProviderRepository repository = (SvnScmProviderRepository) repo;
File messageFile = FileUtils.createTempFile("maven-scm-", ".commit", null);
try {
FileUtils.fileWrite(messageFile.getAbsolutePath(), scmTagParameters == null ? "" : scmTagParameters.getMessage());
} catch (IOException ex) {
return new TagScmResult(null, "Error while making a temporary file for the commit message: " + ex.getMessage(), null, false);
}
Commandline cl = createCommandLine(repository, fileSet.getBasedir(), tag, messageFile, scmTagParameters);
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) {
// TODO: Improve this error message
return new TagScmResult(cl.toString(), "The svn tag command failed.", stderr.getOutput(), false);
}
List<ScmFile> fileList = new ArrayList<ScmFile>();
List<File> files = null;
try {
if (StringUtils.isNotEmpty(fileSet.getExcludes())) {
@SuppressWarnings("unchecked") List<File> list = FileUtils.getFiles(fileSet.getBasedir(), (StringUtils.isEmpty(fileSet.getIncludes()) ? "**" : fileSet.getIncludes()), fileSet.getExcludes() + ",**/.svn/**", false);
files = list;
} else {
@SuppressWarnings("unchecked") List<File> list = FileUtils.getFiles(fileSet.getBasedir(), (StringUtils.isEmpty(fileSet.getIncludes()) ? "**" : fileSet.getIncludes()), "**/.svn/**", false);
files = list;
}
} catch (IOException e) {
throw new ScmException("Error while executing command.", e);
}
for (Iterator<File> i = files.iterator(); i.hasNext(); ) {
File f = i.next();
fileList.add(new ScmFile(f.getPath(), ScmFileStatus.TAGGED));
}
return new TagScmResult(cl.toString(), fileList);
}
use of org.codehaus.plexus.util.cli.CommandLineException in project maven-scm by apache.
the class SvnRemoteInfoCommand method remoteUrlExist.
public boolean remoteUrlExist(ScmProviderRepository repository, CommandParameters parameters) throws ScmException {
String url = ((SvnScmProviderRepository) repository).getUrl();
Commandline cl = SvnCommandLineUtils.getBaseSvnCommandLine(null, (SvnScmProviderRepository) repository);
cl.createArg().setValue("ls");
cl.createArg().setValue(url);
CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
LsConsumer consumer = new LsConsumer(getLogger(), url);
int exitCode = 0;
try {
exitCode = SvnCommandLineUtils.execute(cl, consumer, stderr, getLogger());
} catch (CommandLineException ex) {
throw new ScmException("Error while executing svn command.", ex);
}
if (exitCode != 0) {
String output = stderr.getOutput();
// trying to parse error from svn cli which indicate no remote path
if (output.indexOf("W160013") >= 0 || output.indexOf("svn: URL") >= 0) {
return false;
}
throw new ScmException(cl.toString() + ".The svn command failed:" + stderr.getOutput());
}
return true;
}
use of org.codehaus.plexus.util.cli.CommandLineException in project maven-scm by apache.
the class SvnUpdateCommand method executeUpdateCommand.
/**
* {@inheritDoc}
*/
protected UpdateScmResult executeUpdateCommand(ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion version) throws ScmException {
Commandline cl = createCommandLine((SvnScmProviderRepository) repo, fileSet.getBasedir(), version);
SvnUpdateConsumer consumer = new SvnUpdateConsumer(getLogger(), fileSet.getBasedir());
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 UpdateScmResult(cl.toString(), "The svn command failed.", stderr.getOutput(), false);
}
UpdateScmResultWithRevision result = new UpdateScmResultWithRevision(cl.toString(), consumer.getUpdatedFiles(), String.valueOf(consumer.getRevision()));
result.setChanges(consumer.getChangeSets());
if (getLogger().isDebugEnabled()) {
getLogger().debug("changeSets " + consumer.getChangeSets());
}
return result;
}
use of org.codehaus.plexus.util.cli.CommandLineException in project maven-scm by apache.
the class SvnScmTestUtils method getScmUrl.
public static String getScmUrl(File repositoryRootFile) throws CommandLineException {
String repositoryRoot = repositoryRootFile.getAbsolutePath();
// TODO: some way without a custom cygwin sys property?
if ("true".equals(System.getProperty("cygwin"))) {
Commandline cl = new Commandline();
cl.setExecutable("cygpath");
cl.createArg().setValue("--unix");
cl.createArg().setValue(repositoryRoot);
CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
int exitValue = CommandLineUtils.executeCommandLine(cl, stdout, null);
if (exitValue != 0) {
throw new CommandLineException("Unable to convert cygwin path, exit code = " + exitValue);
}
repositoryRoot = stdout.getOutput().trim();
} else if (Os.isFamily("windows")) {
repositoryRoot = "/" + StringUtils.replace(repositoryRoot, "\\", "/");
}
return "scm:svn:file://" + repositoryRoot;
}
use of org.codehaus.plexus.util.cli.CommandLineException in project maven-scm by apache.
the class AccuRevCommandLine method executeCommandLine.
private int executeCommandLine(InputStream stdin, StreamConsumer stdout) throws AccuRevException {
commandLines.append(cl.toString());
commandLines.append(';');
if (getLogger().isDebugEnabled()) {
getLogger().debug(cl.toString());
}
try {
int result = executeCommandLine(cl, stdin, new CommandOutputConsumer(getLogger(), stdout), systemErr);
if (result != 0) {
getLogger().debug("Non zero result - " + result);
}
return result;
} catch (CommandLineException ex) {
throw new AccuRevException("Error executing command " + cl.toString(), ex);
}
}
Aggregations