Search in sources :

Example 21 with CommandLineResult

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

the class SubversionApi method exportPath.

/**
     * Perform an "svn export" based on the request.
     *
     * @param projectPath
     *         project path
     * @param path
     *         exported path
     * @param revision
     *         specified revision to export
     * @return Response which contains hyperlink with download url
     * @throws IOException
     *         if there is a problem executing the command
     * @throws ServerException
     *         if there is an exporting issue
     */
public Response exportPath(@NotNull final String projectPath, @NotNull final String path, String revision) throws IOException, ServerException, UnauthorizedException {
    final File project = new File(projectPath);
    final List<String> uArgs = defaultArgs();
    if (!isNullOrEmpty(revision)) {
        addOption(uArgs, "--revision", revision);
    }
    uArgs.add("--force");
    uArgs.add("export");
    File tempDir = null;
    File zip = null;
    try {
        tempDir = Files.createTempDir();
        final CommandLineResult result = runCommand(null, uArgs, project, Arrays.asList(path, tempDir.getAbsolutePath()));
        if (result.getExitCode() != 0) {
            LOG.warn("Svn export process finished with exit status {}", result.getExitCode());
            throw new ServerException("Export failed");
        }
        zip = new File(Files.createTempDir(), "export.zip");
        ZipUtils.zipDir(tempDir.getPath(), tempDir, zip, IoUtil.ANY_FILTER);
    } finally {
        if (tempDir != null) {
            IoUtil.deleteRecursive(tempDir);
        }
    }
    final Response.ResponseBuilder responseBuilder = Response.ok(new DeleteOnCloseFileInputStream(zip), MediaType.ZIP.toString()).lastModified(new Date(zip.lastModified())).header(HttpHeaders.CONTENT_LENGTH, Long.toString(zip.length())).header("Content-Disposition", "attachment; filename=\"export.zip\"");
    return responseBuilder.build();
}
Also used : ListResponse(org.eclipse.che.plugin.svn.shared.ListResponse) CLIOutputResponse(org.eclipse.che.plugin.svn.shared.CLIOutputResponse) Response(javax.ws.rs.core.Response) InfoResponse(org.eclipse.che.plugin.svn.shared.InfoResponse) CLIOutputWithRevisionResponse(org.eclipse.che.plugin.svn.shared.CLIOutputWithRevisionResponse) GetRevisionsResponse(org.eclipse.che.plugin.svn.shared.GetRevisionsResponse) ServerException(org.eclipse.che.api.core.ServerException) CommandLineResult(org.eclipse.che.plugin.svn.server.upstream.CommandLineResult) DeleteOnCloseFileInputStream(org.eclipse.che.api.vfs.util.DeleteOnCloseFileInputStream) File(java.io.File) Date(java.util.Date)

Example 22 with CommandLineResult

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

the class SubversionApi method copy.

/**
     * Perform an "svn copy" 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 copy(final CopyRequest request) throws IOException, SubversionException, UnauthorizedException {
    //for security reason we should forbid file protocol
    if (request.getSource().startsWith("file://") || request.getDestination().startsWith("file://")) {
        throw new SubversionException("Url is not acceptable");
    }
    final File projectPath = new File(request.getProjectPath());
    final List<String> cliArgs = defaultArgs();
    if (!isNullOrEmpty(request.getComment())) {
        addOption(cliArgs, "--message", "\"" + request.getComment() + "\"");
    }
    // Command Name
    cliArgs.add("copy");
    final CommandLineResult result = runCommand(null, cliArgs, projectPath, Arrays.asList(request.getSource(), request.getDestination()), request.getUsername(), request.getPassword());
    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 23 with CommandLineResult

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

the class SubversionApi method showDiff.

/**
     * Perform an "svn diff" 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 showDiff(final ShowDiffRequest request) throws IOException, SubversionException, UnauthorizedException {
    final File projectPath = new File(request.getProjectPath());
    final List<String> uArgs = defaultArgs();
    addOption(uArgs, "--revision", request.getRevision());
    uArgs.add("diff");
    final CommandLineResult result = runCommand(null, uArgs, projectPath, request.getPaths(), request.getUsername(), request.getPassword());
    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 24 with CommandLineResult

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

the class SubversionApi method status.

/**
     * Perform an "svn status" 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 status(final StatusRequest request) throws IOException, SubversionException, UnauthorizedException {
    final File projectPath = new File(request.getProjectPath());
    final List<String> cliArgs = defaultArgs();
    // Flags
    addFlag(cliArgs, "--ignore-externals", request.isIgnoreExternals());
    addFlag(cliArgs, "--no-ignore", request.isShowIgnored());
    addFlag(cliArgs, "--quiet", !request.isShowUnversioned());
    addFlag(cliArgs, "--show-updates", request.isShowUpdates());
    addFlag(cliArgs, "--verbose", request.isVerbose());
    // Options
    addOptionList(cliArgs, "--changelist", request.getChangeLists());
    addOption(cliArgs, "--depth", request.getDepth());
    // Command Name
    cliArgs.add("status");
    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 25 with CommandLineResult

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

the class SubversionApi method merge.

/**
     * Merges target with specified URL.
     *
     * @param request
     *         merge request
     * @return merge response
     * @throws IOException
     * @throws SubversionException
     */
public CLIOutputResponse merge(final MergeRequest request) throws IOException, SubversionException, UnauthorizedException {
    final File projectPath = new File(request.getProjectPath());
    final List<String> cliArgs = defaultArgs();
    // Command Name
    cliArgs.add("merge");
    cliArgs.add(request.getSourceURL());
    List<String> paths = new ArrayList<String>();
    paths.add(request.getTarget());
    final CommandLineResult result = runCommand(null, cliArgs, projectPath, paths);
    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) ArrayList(java.util.ArrayList) CLIOutputResponse(org.eclipse.che.plugin.svn.shared.CLIOutputResponse) 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