Search in sources :

Example 1 with SubversionItem

use of org.eclipse.che.plugin.svn.shared.SubversionItem 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 2 with SubversionItem

use of org.eclipse.che.plugin.svn.shared.SubversionItem in project che by eclipse.

the class SwitchPresenter method showWindow.

public void showWindow() {
    final Project project = appContext.getRootProject();
    checkState(project != null);
    switchView.showWindow();
    switchView.setSwitchButtonEnabled(false);
    invalidateLoadedData();
    performOperationWithCredentialsRequestIfNeeded(new RemoteSubversionOperation<InfoResponse>() {

        @Override
        public Promise<InfoResponse> perform(Credentials credentials) {
            return service.info(appContext.getRootProject().getLocation(), ".", "HEAD", false, credentials);
        }
    }, null).then(new Operation<InfoResponse>() {

        @Override
        public void apply(InfoResponse response) throws OperationException {
            if (!response.getItems().isEmpty()) {
                SubversionItem subversionItem = response.getItems().get(0);
                projectUri = subversionItem.getProjectUri();
            }
            defaultViewInitialization();
            handleSwitchButton();
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError error) throws OperationException {
            projectUri = "^";
            Path location = appContext.getRootProject().getLocation();
            notificationManager.notify(constants.infoRequestError(location.toString()), error.getMessage(), FAIL, EMERGE_MODE);
            defaultViewInitialization();
            handleSwitchButton();
        }
    });
}
Also used : Path(org.eclipse.che.ide.resource.Path) Project(org.eclipse.che.ide.api.resources.Project) Promise(org.eclipse.che.api.promises.client.Promise) InfoResponse(org.eclipse.che.plugin.svn.shared.InfoResponse) SubversionItem(org.eclipse.che.plugin.svn.shared.SubversionItem) PromiseError(org.eclipse.che.api.promises.client.PromiseError) Operation(org.eclipse.che.api.promises.client.Operation) Credentials(org.eclipse.che.ide.api.subversion.Credentials) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 3 with SubversionItem

use of org.eclipse.che.plugin.svn.shared.SubversionItem in project che by eclipse.

the class ShowLogPresenter method showLog.

/**
     * Fetches the count of revisions and opens the popup.
     */
public void showLog() {
    final Project project = appContext.getRootProject();
    checkState(project != null);
    final Resource[] resources = appContext.getResources();
    checkState(!Arrays.isNullOrEmpty(resources));
    checkState(resources.length == 1);
    performOperationWithCredentialsRequestIfNeeded(new RemoteSubversionOperation<InfoResponse>() {

        @Override
        public Promise<InfoResponse> perform(Credentials credentials) {
            return service.info(project.getLocation(), toRelative(project, resources[0]).toString(), "HEAD", false, credentials);
        }
    }, null).then(new Operation<InfoResponse>() {

        @Override
        public void apply(InfoResponse response) throws OperationException {
            if (response.getErrorOutput() != null && !response.getErrorOutput().isEmpty()) {
                printErrors(response.getErrorOutput(), constants.commandInfo());
                notificationManager.notify("Unable to execute subversion command", FAIL, FLOAT_MODE);
                return;
            }
            SubversionItem subversionItem = response.getItems().get(0);
            view.setRevisionCount(subversionItem.getRevision());
            view.rangeField().setValue("1:" + subversionItem.getRevision());
            view.show();
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError error) throws OperationException {
            notificationManager.notify(error.getMessage(), FAIL, FLOAT_MODE);
        }
    });
}
Also used : InfoResponse(org.eclipse.che.plugin.svn.shared.InfoResponse) Resource(org.eclipse.che.ide.api.resources.Resource) Operation(org.eclipse.che.api.promises.client.Operation) Project(org.eclipse.che.ide.api.resources.Project) Promise(org.eclipse.che.api.promises.client.Promise) SubversionItem(org.eclipse.che.plugin.svn.shared.SubversionItem) PromiseError(org.eclipse.che.api.promises.client.PromiseError) Credentials(org.eclipse.che.ide.api.subversion.Credentials) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 4 with SubversionItem

use of org.eclipse.che.plugin.svn.shared.SubversionItem in project che by eclipse.

the class MergePresenter method merge.

/**
     * Prepares to merging and opens Merge dialog.
     */
public void merge() {
    view.enableMergeButton(false);
    view.sourceCheckBox().setValue(false);
    final Project project = appContext.getRootProject();
    checkState(project != null);
    final Resource[] resources = appContext.getResources();
    checkState(resources != null && resources.length == 1);
    performOperationWithCredentialsRequestIfNeeded(new RemoteSubversionOperation<InfoResponse>() {

        @Override
        public Promise<InfoResponse> perform(Credentials credentials) {
            return service.info(project.getLocation(), toRelative(project, resources[0]).toString(), "HEAD", false, credentials);
        }
    }, null).then(new Operation<InfoResponse>() {

        @Override
        public void apply(InfoResponse response) throws OperationException {
            if (response.getErrorOutput() != null && !response.getErrorOutput().isEmpty()) {
                printErrors(response.getErrorOutput(), constants.commandInfo());
                notificationManager.notify("Unable to execute subversion command", FAIL, FLOAT_MODE);
                return;
            }
            mergeTarget = response.getItems().get(0);
            view.targetTextBox().setValue(mergeTarget.getRelativeURL());
            String repositoryRoot = mergeTarget.getRepositoryRoot();
            service.info(project.getLocation(), repositoryRoot, "HEAD", true).then(new Operation<InfoResponse>() {

                @Override
                public void apply(InfoResponse response) throws OperationException {
                    if (!response.getErrorOutput().isEmpty()) {
                        printErrors(response.getErrorOutput(), constants.commandInfo());
                        notificationManager.notify("Unable to execute subversion command", FAIL, FLOAT_MODE);
                        return;
                    }
                    sourceURL = response.getItems().get(0).getURL();
                    SubversionItemNode subversionTreeNode = new SubversionItemNode(response.getItems().get(0));
                    List<Node> children = new ArrayList<>();
                    if (response.getItems().size() > 1) {
                        for (int i = 1; i < response.getItems().size(); i++) {
                            SubversionItem item = response.getItems().get(i);
                            if (!"file".equals(item.getNodeKind())) {
                                children.add(new SubversionItemNode(item));
                            }
                        }
                    }
                    subversionTreeNode.setChildren(children);
                    view.setRootNode(subversionTreeNode);
                    view.show();
                    validateSourceURL();
                }
            }).catchError(new Operation<PromiseError>() {

                @Override
                public void apply(PromiseError error) throws OperationException {
                    notificationManager.notify(error.getMessage(), FAIL, FLOAT_MODE);
                }
            });
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError error) throws OperationException {
            notificationManager.notify(error.getMessage(), FAIL, FLOAT_MODE);
        }
    });
}
Also used : InfoResponse(org.eclipse.che.plugin.svn.shared.InfoResponse) Node(org.eclipse.che.ide.api.data.tree.Node) AbstractTreeNode(org.eclipse.che.ide.api.data.tree.AbstractTreeNode) Resource(org.eclipse.che.ide.api.resources.Resource) ArrayList(java.util.ArrayList) Operation(org.eclipse.che.api.promises.client.Operation) Project(org.eclipse.che.ide.api.resources.Project) Promise(org.eclipse.che.api.promises.client.Promise) SubversionItem(org.eclipse.che.plugin.svn.shared.SubversionItem) PromiseError(org.eclipse.che.api.promises.client.PromiseError) Credentials(org.eclipse.che.ide.api.subversion.Credentials) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 5 with SubversionItem

use of org.eclipse.che.plugin.svn.shared.SubversionItem in project che by eclipse.

the class SubversionApiITest method testInfo.

@Test
public void testInfo() throws Exception {
    subversionApi.checkout(DtoFactory.getInstance().createDto(CheckoutRequest.class).withProjectPath(tmpDir.toFile().getAbsolutePath()).withUrl(repoUrl).withDepth("immediates"));
    InfoResponse response = subversionApi.info(DtoFactory.getInstance().createDto(InfoRequest.class).withProjectPath(tmpDir.toFile().getAbsolutePath()).withTarget(".").withRevision("HEAD"));
    assertEquals(response.getItems().size(), 1);
    SubversionItem subversionItem = response.getItems().get(0);
    assertEquals(subversionItem.getProjectUri(), repoUrl.substring(0, repoUrl.length() - 1));
}
Also used : InfoResponse(org.eclipse.che.plugin.svn.shared.InfoResponse) SubversionItem(org.eclipse.che.plugin.svn.shared.SubversionItem) Test(org.junit.Test)

Aggregations

InfoResponse (org.eclipse.che.plugin.svn.shared.InfoResponse)5 SubversionItem (org.eclipse.che.plugin.svn.shared.SubversionItem)5 Operation (org.eclipse.che.api.promises.client.Operation)3 OperationException (org.eclipse.che.api.promises.client.OperationException)3 Promise (org.eclipse.che.api.promises.client.Promise)3 PromiseError (org.eclipse.che.api.promises.client.PromiseError)3 Project (org.eclipse.che.ide.api.resources.Project)3 Credentials (org.eclipse.che.ide.api.subversion.Credentials)3 ArrayList (java.util.ArrayList)2 Resource (org.eclipse.che.ide.api.resources.Resource)2 File (java.io.File)1 AbstractTreeNode (org.eclipse.che.ide.api.data.tree.AbstractTreeNode)1 Node (org.eclipse.che.ide.api.data.tree.Node)1 Path (org.eclipse.che.ide.resource.Path)1 CommandLineResult (org.eclipse.che.plugin.svn.server.upstream.CommandLineResult)1 Test (org.junit.Test)1