Search in sources :

Example 26 with CommandLineResult

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

the class SubversionApi method checkout.

/**
     * 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 checkout(final CheckoutRequest request) throws IOException, SubversionException, UnauthorizedException {
    final File projectPath = new File(request.getProjectPath());
    final List<String> cliArgs = defaultArgs();
    // Flags
    addFlag(cliArgs, "--ignore-externals", request.isIgnoreExternals());
    // Options
    addOption(cliArgs, "--depth", request.getDepth());
    addOption(cliArgs, "--revision", request.getRevision());
    // Command Name
    cliArgs.add("checkout");
    // Command Arguments
    cliArgs.add(request.getUrl());
    cliArgs.add(projectPath.getAbsolutePath());
    CommandLineResult result = runCommand(null, cliArgs, projectPath, request.getPaths(), request.getUsername(), request.getPassword(), request.getUrl());
    return DtoFactory.getInstance().createDto(CLIOutputWithRevisionResponse.class).withCommand(result.getCommandLine().toString()).withOutput(result.getStdout()).withErrOutput(result.getStderr()).withRevision(SubversionUtils.getCheckoutRevision(result.getStdout()));
}
Also used : CommandLineResult(org.eclipse.che.plugin.svn.server.upstream.CommandLineResult) File(java.io.File)

Example 27 with CommandLineResult

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

the class SubversionApi method cleanup.

public CLIOutputResponse cleanup(final CleanupRequest request) throws SubversionException, IOException, UnauthorizedException {
    final File projectPath = new File(request.getProjectPath());
    final List<String> cliArgs = defaultArgs();
    // Command Name
    cliArgs.add("cleanup");
    final CommandLineResult result = runCommand(null, cliArgs, projectPath, addWorkingCopyPathIfNecessary(request.getPaths()));
    return DtoFactory.getInstance().createDto(CLIOutputResponse.class).withCommand(result.getCommandLine().toString()).withOutput(result.getStdout());
}
Also used : CommandLineResult(org.eclipse.che.plugin.svn.server.upstream.CommandLineResult) File(java.io.File)

Example 28 with CommandLineResult

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

the class TestUtils method createGreekTreeRepository.

/**
     * Creates a new Subversion repository in a temporary location with the Greek Tree structure within it.
     *
     * @return the path to the repository root
     * @throws Exception
     *         if anything goes wrong
     */
public static File createGreekTreeRepository() throws Exception {
    final File repoRoot = Files.createTempDir();
    final File wcRoot = Files.createTempDir();
    // Clean up after execution
    repoRoot.deleteOnExit();
    wcRoot.deleteOnExit();
    // Create the repository
    final CommandLineResult result = UpstreamUtils.executeCommandLine(null, "svnadmin", new String[] { "create", repoRoot.getAbsolutePath() }, -1, repoRoot);
    // Make sure the result is fine
    handleCLIResult(result);
    // Checkout the repository
    final CLIOutputWithRevisionResponse coResponse = subversionApi.checkout(dtoFactory.createDto(CheckoutRequest.class).withProjectPath(wcRoot.getAbsolutePath()).withUrl("file:///" + repoRoot.getAbsolutePath()));
    assertTrue(coResponse.getRevision() > -1);
    final List<String> pathsToAdd = new ArrayList<>();
    // Create the directory structure
    for (final String path : GREEK_TREE) {
        final File fileForPath = new File(wcRoot, path);
        final String[] pathParts = path.split("/");
        // Create parent directories (Probably not necessary)
        Files.createParentDirs(fileForPath);
        if (!path.endsWith("/") && fileForPath.createNewFile()) {
            Files.write(("This is the file '" + pathParts[pathParts.length - 1] + "'.").getBytes(), fileForPath);
            pathsToAdd.add(path.substring(1));
        }
    }
    // Add the files in the working copy to version control
    subversionApi.add(dtoFactory.createDto(AddRequest.class).withProjectPath(wcRoot.getAbsolutePath()).withPaths(pathsToAdd).withAddParents(true));
    //Add properties
    final CLIOutputResponse propResponse = subversionApi.propset(dtoFactory.createDto(PropertySetRequest.class).withValue("user").withProjectPath(wcRoot.getAbsolutePath()).withPath(".").withForce(true).withDepth(Depth.FULLY_RECURSIVE).withName("owner"));
    assertTrue(propResponse.getOutput().size() > 0);
    // Commit the changes
    final CLIOutputWithRevisionResponse cResponse = subversionApi.commit(dtoFactory.createDto(CommitRequest.class).withProjectPath(wcRoot.getAbsolutePath()).withMessage("Initial commit."));
    assertEquals(1L, cResponse.getRevision());
    return repoRoot;
}
Also used : CommitRequest(org.eclipse.che.plugin.svn.shared.CommitRequest) CommandLineResult(org.eclipse.che.plugin.svn.server.upstream.CommandLineResult) ArrayList(java.util.ArrayList) CLIOutputWithRevisionResponse(org.eclipse.che.plugin.svn.shared.CLIOutputWithRevisionResponse) CheckoutRequest(org.eclipse.che.plugin.svn.shared.CheckoutRequest) CLIOutputResponse(org.eclipse.che.plugin.svn.shared.CLIOutputResponse) PropertySetRequest(org.eclipse.che.plugin.svn.shared.PropertySetRequest) 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