Search in sources :

Example 6 with CommandLineResult

use of org.eclipse.che.plugin.svn.server.upstream.CommandLineResult in project che by eclipse.

the class SubversionApi method info.

/**
     * Returns information about specified target.
     *
     * @param request
     *         request
     * @return response containing list of subversion items
     * @throws SubversionException
     */
public InfoResponse info(final InfoRequest request) throws SubversionException, UnauthorizedException {
    final List<String> args = defaultArgs();
    if (request.getRevision() != null && !request.getRevision().trim().isEmpty()) {
        addOption(args, "--revision", request.getRevision());
    }
    if (request.getChildren()) {
        addOption(args, "--depth", "immediates");
    }
    args.add("info");
    List<String> paths = new ArrayList<>();
    paths.add(request.getTarget());
    final CommandLineResult result = runCommand(null, args, new File(request.getProjectPath()), addWorkingCopyPathIfNecessary(paths), request.getUsername(), request.getPassword());
    final InfoResponse response = DtoFactory.getInstance().createDto(InfoResponse.class).withCommand(result.getCommandLine().toString()).withOutput(result.getStdout()).withErrorOutput(result.getStderr());
    if (result.getExitCode() == 0) {
        List<SubversionItem> items = new ArrayList<>();
        response.withItems(items);
        Iterator<String> iterator = result.getStdout().iterator();
        List<String> itemProperties = new ArrayList<>();
        while (iterator.hasNext()) {
            String propertyLine = iterator.next();
            if (propertyLine.isEmpty()) {
                // create Subversion item filling properties from the list
                String repositoryRoot = getRepositoryRoot(itemProperties);
                String relativeUrl = getRelativeUrl(itemProperties);
                final SubversionItem item = DtoFactory.getInstance().createDto(SubversionItem.class).withPath(InfoUtils.getPath(itemProperties)).withName(InfoUtils.getName(itemProperties)).withURL(InfoUtils.getUrl(itemProperties)).withRelativeURL(relativeUrl).withRepositoryRoot(repositoryRoot).withRepositoryUUID(InfoUtils.getRepositoryUUID(itemProperties)).withRevision(InfoUtils.getRevision(itemProperties)).withNodeKind(InfoUtils.getNodeKind(itemProperties)).withSchedule(InfoUtils.getSchedule(itemProperties)).withLastChangedRev(InfoUtils.getLastChangedRev(itemProperties)).withLastChangedDate(InfoUtils.getLastChangedDate(itemProperties)).withProjectUri(recognizeProjectUri(repositoryRoot, relativeUrl));
                items.add(item);
                // clear item properties
                itemProperties.clear();
            } else {
                // add property line to property list
                itemProperties.add(propertyLine);
            }
        }
    } else {
        response.withErrorOutput(result.getStderr());
    }
    return response;
}
Also used : InfoResponse(org.eclipse.che.plugin.svn.shared.InfoResponse) SubversionItem(org.eclipse.che.plugin.svn.shared.SubversionItem) CommandLineResult(org.eclipse.che.plugin.svn.server.upstream.CommandLineResult) ArrayList(java.util.ArrayList) File(java.io.File)

Example 7 with CommandLineResult

use of org.eclipse.che.plugin.svn.server.upstream.CommandLineResult in project che by eclipse.

the class SubversionApi method revert.

/**
     * Perform an "svn revert" 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 revert(RevertRequest request) throws IOException, SubversionException, UnauthorizedException {
    final File projectPath = new File(request.getProjectPath());
    final List<String> cliArgs = defaultArgs();
    addOption(cliArgs, "--depth", request.getDepth());
    cliArgs.add("revert");
    final CommandLineResult result = runCommand(null, cliArgs, projectPath, addWorkingCopyPathIfNecessary(request.getPaths()));
    return DtoFactory.getInstance().createDto(CLIOutputResponse.class).withCommand(result.getCommandLine().toString()).withOutput(result.getStdout()).withErrOutput(result.getStderr());
}
Also used : CommandLineResult(org.eclipse.che.plugin.svn.server.upstream.CommandLineResult) CLIOutputResponse(org.eclipse.che.plugin.svn.shared.CLIOutputResponse) File(java.io.File)

Example 8 with CommandLineResult

use of org.eclipse.che.plugin.svn.server.upstream.CommandLineResult in project che by eclipse.

the class SubversionApi method proplist.

/**
     * Perform an "svn proplist" 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 proplist(final PropertyListRequest request) throws IOException, ServerException, UnauthorizedException {
    final File projectPath = new File(request.getProjectPath());
    final List<String> uArgs = defaultArgs();
    uArgs.add("proplist");
    final CommandLineResult result = runCommand(null, uArgs, projectPath, Arrays.asList(request.getPath()));
    List<String> output;
    if (result.getStdout() != null && result.getStdout().size() > 0) {
        output = result.getStdout().subList(1, result.getStdout().size());
    } else {
        output = result.getStdout();
    }
    return DtoFactory.getInstance().createDto(CLIOutputResponse.class).withCommand(result.getCommandLine().toString()).withOutput(output);
}
Also used : CommandLineResult(org.eclipse.che.plugin.svn.server.upstream.CommandLineResult) File(java.io.File)

Example 9 with CommandLineResult

use of org.eclipse.che.plugin.svn.server.upstream.CommandLineResult in project che by eclipse.

the class SubversionApi method remove.

/**
     * Perform an "svn remove" 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 remove(final RemoveRequest request) throws IOException, SubversionException, UnauthorizedException {
    final File projectPath = new File(request.getProjectPath());
    final List<String> cliArgs = defaultArgs();
    // Command Name
    cliArgs.add("remove");
    final CommandLineResult result = runCommand(null, cliArgs, projectPath, request.getPaths());
    return DtoFactory.getInstance().createDto(CLIOutputResponse.class).withCommand(result.getCommandLine().toString()).withOutput(result.getStdout()).withErrOutput(result.getStderr());
}
Also used : CommandLineResult(org.eclipse.che.plugin.svn.server.upstream.CommandLineResult) CLIOutputResponse(org.eclipse.che.plugin.svn.shared.CLIOutputResponse) File(java.io.File)

Example 10 with CommandLineResult

use of org.eclipse.che.plugin.svn.server.upstream.CommandLineResult in project che by eclipse.

the class SubversionApi method doSwitch.

/**
     * Perform a "svn switch" based on the request.
     *
     * @param request
     *         the switch request
     * @return the response
     * @throws ApiException
     *         if there is a Subversion issue
     */
public CLIOutputWithRevisionResponse doSwitch(final SwitchRequest request) throws ApiException {
    final File projectPath = new File(request.getProjectPath());
    final List<String> cliArgs = defaultArgs();
    // Flags
    addFlag(cliArgs, "--ignore-externals", request.isIgnoreExternals());
    addFlag(cliArgs, "--ignore-ancestry", request.isIgnoreAncestry());
    addFlag(cliArgs, "--relocate", request.isRelocate());
    addFlag(cliArgs, "--force", request.isForce());
    // Options
    addOption(cliArgs, "--depth", request.getDepth());
    addOption(cliArgs, "--set-depth", request.getSetDepth());
    addOption(cliArgs, "--revision", request.getRevision());
    addOption(cliArgs, "--accept", request.getAccept());
    // Command Name
    cliArgs.add("switch");
    CommandLineResult result = runCommand(null, cliArgs, projectPath, singletonList(request.getLocation()), request.getUsername(), request.getPassword());
    return newDto(CLIOutputWithRevisionResponse.class).withCommand(result.getCommandLine().toString()).withOutput(result.getStdout()).withErrOutput(result.getStderr()).withRevision(SubversionUtils.getUpdateRevision(result.getStdout()));
}
Also used : CommandLineResult(org.eclipse.che.plugin.svn.server.upstream.CommandLineResult) File(java.io.File)

Aggregations

CommandLineResult (org.eclipse.che.plugin.svn.server.upstream.CommandLineResult)28 File (java.io.File)27 CLIOutputResponse (org.eclipse.che.plugin.svn.shared.CLIOutputResponse)18 ArrayList (java.util.ArrayList)9 IOException (java.io.IOException)5 InfoResponse (org.eclipse.che.plugin.svn.shared.InfoResponse)5 ListResponse (org.eclipse.che.plugin.svn.shared.ListResponse)5 Predicate (com.google.common.base.Predicate)4 Path (java.nio.file.Path)4 Date (java.util.Date)4 Response (javax.ws.rs.core.Response)4 ServerException (org.eclipse.che.api.core.ServerException)4 UnauthorizedException (org.eclipse.che.api.core.UnauthorizedException)4 DeleteOnCloseFileInputStream (org.eclipse.che.api.vfs.util.DeleteOnCloseFileInputStream)4 SubversionItem (org.eclipse.che.plugin.svn.shared.SubversionItem)4 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)3 Iterables (com.google.common.collect.Iterables)3 Files (com.google.common.io.Files)3 MediaType (com.google.common.net.MediaType)3 Singleton (com.google.inject.Singleton)3