use of org.codehaus.plexus.util.cli.Commandline 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.Commandline 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.Commandline in project maven-scm by apache.
the class SvnMkdirCommand method createCommandLine.
protected static Commandline createCommandLine(SvnScmProviderRepository repository, ScmFileSet fileSet, File messageFile, boolean createInLocal) {
if (!fileSet.getBasedir().exists() && !createInLocal) {
fileSet.getBasedir().mkdirs();
}
Commandline cl = SvnCommandLineUtils.getBaseSvnCommandLine(fileSet.getBasedir(), repository);
cl.createArg().setValue("mkdir");
cl.createArg().setValue("--parents");
Iterator<File> it = fileSet.getFileList().iterator();
String dirPath = it.next().getPath();
// replacing \ with / for windauze
if (dirPath != null && Os.isFamily(Os.FAMILY_DOS)) {
dirPath = StringUtils.replace(dirPath, "\\", "/");
}
if (!createInLocal) {
cl.createArg().setValue(repository.getUrl() + "/" + dirPath);
if (messageFile != null) {
cl.createArg().setValue("--file");
cl.createArg().setValue(messageFile.getAbsolutePath());
}
} else {
cl.createArg().setValue(dirPath);
}
return cl;
}
use of org.codehaus.plexus.util.cli.Commandline 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.Commandline in project maven-scm by apache.
the class SvnScmTestUtils method loadSvnDump.
private static void loadSvnDump(File repositoryRoot, InputStream dumpStream) throws Exception {
Commandline cl = new Commandline();
cl.setExecutable(SVNADMIN_COMMAND_LINE);
cl.setWorkingDirectory(repositoryRoot.getParentFile().getAbsolutePath());
cl.createArg().setValue("load");
cl.createArg().setValue(repositoryRoot.getAbsolutePath());
CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
int exitValue = CommandLineUtils.executeCommandLine(cl, dumpStream, stdout, stderr);
if (exitValue != 0) {
System.err.println("-----------------------------------------");
System.err.println("Command line: " + cl);
System.err.println("Working directory: " + cl.getWorkingDirectory());
System.err.println("-----------------------------------------");
System.err.println("Standard output: ");
System.err.println("-----------------------------------------");
System.err.println(stdout.getOutput());
System.err.println("-----------------------------------------");
System.err.println("Standard error: ");
System.err.println("-----------------------------------------");
System.err.println(stderr.getOutput());
System.err.println("-----------------------------------------");
}
if (exitValue != 0) {
Assert.fail("Exit value wasn't 0, was:" + exitValue);
}
}
Aggregations