use of org.eclipse.che.plugin.svn.server.upstream.CommandLineResult in project che by eclipse.
the class SubversionApi method update.
/**
* Perform an "svn checkout" based on the request.
*
* @param request
* the request
* @return the response
* @throws IOException
* if there is a problem executing the command
* @throws SubversionException
* if there is a Subversion issue
*/
public CLIOutputWithRevisionResponse update(final UpdateRequest request) throws IOException, SubversionException, UnauthorizedException {
final File projectPath = new File(request.getProjectPath());
final List<String> uArgs = defaultArgs();
// Flags
addFlag(uArgs, "--ignore-externals", request.isIgnoreExternals());
// Options
addOption(uArgs, "--depth", request.getDepth());
addOption(uArgs, "--revision", request.getRevision());
// Command Name
uArgs.add("update");
final CommandLineResult result = runCommand(null, uArgs, projectPath, addWorkingCopyPathIfNecessary(request.getPaths()), request.getUsername(), request.getPassword());
return DtoFactory.getInstance().createDto(CLIOutputWithRevisionResponse.class).withCommand(result.getCommandLine().toString()).withRevision(SubversionUtils.getUpdateRevision(result.getStdout())).withOutput(result.getStdout()).withErrOutput(result.getStderr());
}
use of org.eclipse.che.plugin.svn.server.upstream.CommandLineResult in project che by eclipse.
the class SubversionApi method propset.
/**
* Perform an "svn propset" based on the request.
*
* @param request
* the request
* @return the response
* @throws IOException
* if there is a problem executing the command
* @throws ServerException
* if there is a Subversion issue
*/
public CLIOutputResponse propset(final PropertySetRequest request) throws IOException, ServerException, UnauthorizedException {
final File projectPath = new File(request.getProjectPath());
final List<String> uArgs = defaultArgs();
if (request.isForce()) {
uArgs.add("--force");
}
addDepth(uArgs, request.getDepth().getValue());
uArgs.add("propset");
uArgs.add(request.getName());
String value = request.getValue();
Path valueFile = null;
if (value.contains("\n")) {
try {
valueFile = java.nio.file.Files.createTempFile("svn-propset-value-", null);
java.nio.file.Files.write(valueFile, value.getBytes());
uArgs.add("-F");
uArgs.add(valueFile.toString());
} catch (IOException e) {
uArgs.add(value);
}
} else {
uArgs.add(value);
}
final CommandLineResult result = runCommand(null, uArgs, projectPath, Arrays.asList(request.getPath()));
return DtoFactory.getInstance().createDto(CLIOutputResponse.class).withCommand(result.getCommandLine().toString()).withOutput(result.getStdout()).withErrOutput(result.getStderr());
}
use of org.eclipse.che.plugin.svn.server.upstream.CommandLineResult in project che by eclipse.
the class SubversionApi method lockUnlock.
public CLIOutputResponse lockUnlock(final LockRequest request, final boolean lock) throws IOException, SubversionException, UnauthorizedException {
final File projectPath = new File(request.getProjectPath());
final List<String> args = defaultArgs();
addFlag(args, "--force", request.isForce());
// command
if (lock) {
args.add("lock");
} else {
args.add("unlock");
}
final CommandLineResult result = runCommand(null, args, projectPath, request.getTargets(), request.getUsername(), request.getPassword());
return DtoFactory.getInstance().createDto(CLIOutputResponse.class).withCommand(result.getCommandLine().toString()).withOutput(result.getStdout()).withErrOutput(result.getStderr());
}
use of org.eclipse.che.plugin.svn.server.upstream.CommandLineResult in project che by eclipse.
the class SubversionApi method showLog.
/**
* Perform an "svn log" based on the request.
*
* @param request
* the request
* @return the response
* @throws IOException
* if there is a problem executing the command
* @throws SubversionException
* if there is a Subversion issue
*/
public CLIOutputResponse showLog(final ShowLogRequest request) throws IOException, SubversionException, UnauthorizedException {
final File projectPath = new File(request.getProjectPath());
final List<String> uArgs = defaultArgs();
addOption(uArgs, "--revision", request.getRevision());
uArgs.add("log");
final CommandLineResult result = runCommand(null, uArgs, projectPath, request.getPaths());
return DtoFactory.getInstance().createDto(CLIOutputResponse.class).withCommand(result.getCommandLine().toString()).withOutput(result.getStdout()).withErrOutput(result.getStderr());
}
use of org.eclipse.che.plugin.svn.server.upstream.CommandLineResult in project che by eclipse.
the class SubversionApi method runCommand.
private CommandLineResult runCommand(@Nullable Map<String, String> env, List<String> args, File projectPath, List<String> paths, @Nullable String username, @Nullable String password, String repoUrl) throws SubversionException, UnauthorizedException {
final List<String> lines = new ArrayList<>();
final CommandLineResult result;
final StringBuffer buffer;
boolean isWarning = false;
// Add paths to the end of the list of arguments
for (final String path : paths) {
args.add(path);
}
String[] credentialsArgs;
if (!isNullOrEmpty(username) && !isNullOrEmpty(password)) {
credentialsArgs = new String[] { "--username", username, "--password", password };
} else {
credentialsArgs = null;
}
SshEnvironment sshEnvironment = null;
if (SshEnvironment.isSSH(repoUrl)) {
sshEnvironment = new SshEnvironment(sshScriptProvider, repoUrl);
if (env == null) {
env = new HashMap<>();
}
env.putAll(sshEnvironment.get());
}
try {
result = UpstreamUtils.executeCommandLine(env, "svn", args.toArray(new String[args.size()]), credentialsArgs, -1, projectPath, svnOutputPublisherFactory);
} catch (IOException e) {
throw new SubversionException(e);
} finally {
if (sshEnvironment != null) {
sshEnvironment.cleanUp();
}
}
if (result.getExitCode() != 0) {
buffer = new StringBuffer();
lines.addAll(result.getStdout());
lines.addAll(result.getStderr());
for (final String line : lines) {
// Subversion returns an error code of 1 even when the "error" is just a warning
if (line.startsWith("svn: warning: ")) {
isWarning = true;
}
buffer.append(line);
buffer.append("\n");
}
if (!isWarning) {
String errorMessage = buffer.toString();
if (errorMessage.endsWith("Authentication failed\n")) {
throw new UnauthorizedException("Authentication failed", ErrorCodes.UNAUTHORIZED_SVN_OPERATION);
} else {
throw new SubversionException(errorMessage);
}
}
}
return result;
}
Aggregations