Search in sources :

Example 1 with SVNNodeKind

use of org.tigris.subversion.svnclientadapter.SVNNodeKind in project subclipse by subclipse.

the class CheckinResourcesCommand method run.

/* (non-Javadoc)
   * @see org.tigris.subversion.subclipse.core.commands.ISVNCommand#run(org.eclipse.core.runtime.IProgressMonitor)
   */
public void run(IProgressMonitor monitor) throws SVNException {
    commitError = false;
    postCommitError = null;
    final ISVNClientAdapter svnClient = root.getRepository().getSVNClient();
    OperationManager.getInstance().beginOperation(svnClient, new OperationProgressNotifyListener(monitor, svnClient));
    try {
        // Prepare the parents list
        // we will Auto-commit parents if they are not already commited
        List<IContainer> parentsList = new ArrayList<IContainer>();
        List<IProject> projectList = new ArrayList<IProject>();
        for (IResource currentResource : resources) {
            IProject project = currentResource.getProject();
            if (!projectList.contains(project)) {
                projectList.add(project);
            }
            IContainer parent = currentResource.getParent();
            ISVNLocalResource svnParentResource = SVNWorkspaceRoot.getSVNResourceFor(parent);
            while (parent.getType() != IResource.ROOT && parent.getType() != IResource.PROJECT && !svnParentResource.hasRemote()) {
                if (!inCommitList(parent))
                    parentsList.add(parent);
                parent = parent.getParent();
                svnParentResource = svnParentResource.getParent();
            }
        }
        // convert parents and resources to an array of File
        int parents = parentsList.size();
        // change commit to non-recursive!!
        if (parents > 0)
            depth = IResource.DEPTH_ZERO;
        final File[] resourceFiles = new File[parents + resources.length];
        for (int i = 0; i < parents; i++) {
            resourceFiles[i] = ((IResource) parentsList.get(i)).getLocation().toFile();
        }
        for (int i = 0, j = parents; i < resources.length; i++, j++) {
            resourceFiles[j] = resources[i].getLocation().toFile();
        }
        IProject[] projects = new IProject[projectList.size()];
        projectList.toArray(projects);
        ISchedulingRule rule = MultiRule.combine(projects);
        SVNProviderPlugin.run(new ISVNRunnable() {

            public void run(final IProgressMonitor pm) throws SVNException {
                try {
                    notifyListener = new ISVNNotifyListener() {

                        public void logCommandLine(String commandLine) {
                        }

                        public void logCompleted(String message) {
                        }

                        public void logError(String message) {
                        }

                        public void logMessage(String message) {
                            if (message.startsWith("Transmitting file data"))
                                pm.subTask(message);
                        }

                        public void logRevision(long revision, String path) {
                        }

                        public void onNotify(File path, SVNNodeKind kind) {
                        }

                        public void setCommand(int command) {
                        }
                    };
                    pm.beginTask(null, resourceFiles.length);
                    pm.setTaskName("Checking in...");
                    svnClient.addNotifyListener(operationResourceCollector);
                    svnClient.addNotifyListener(notifyListener);
                    // then the resources the user has requested to commit
                    if (svnClient.canCommitAcrossWC())
                        svnClient.commitAcrossWC(resourceFiles, message, depth == IResource.DEPTH_INFINITE, keepLocks, true);
                    else
                        svnClient.commit(resourceFiles, message, depth == IResource.DEPTH_INFINITE, keepLocks);
                    postCommitError = svnClient.getPostCommitError();
                } catch (SVNClientException e) {
                    commitError = true;
                    throw SVNException.wrapException(e);
                } finally {
                    pm.done();
                    if (svnClient != null) {
                        svnClient.removeNotifyListener(operationResourceCollector);
                        svnClient.removeNotifyListener(notifyListener);
                        root.getRepository().returnSVNClient(svnClient);
                    }
                }
            }
        }, rule, Policy.monitorFor(monitor));
    } finally {
        OperationManager.getInstance().endOperation(true, operationResourceCollector.getOperationResources(), !commitError);
    }
}
Also used : ISVNRunnable(org.tigris.subversion.subclipse.core.ISVNRunnable) ArrayList(java.util.ArrayList) SVNException(org.tigris.subversion.subclipse.core.SVNException) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource) IProject(org.eclipse.core.resources.IProject) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) SVNNodeKind(org.tigris.subversion.svnclientadapter.SVNNodeKind) ISVNNotifyListener(org.tigris.subversion.svnclientadapter.ISVNNotifyListener) SVNClientException(org.tigris.subversion.svnclientadapter.SVNClientException) IContainer(org.eclipse.core.resources.IContainer) File(java.io.File) IResource(org.eclipse.core.resources.IResource) ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter) OperationProgressNotifyListener(org.tigris.subversion.subclipse.core.client.OperationProgressNotifyListener)

Example 2 with SVNNodeKind

use of org.tigris.subversion.svnclientadapter.SVNNodeKind in project subclipse by subclipse.

the class PeekStatusCommand method execute.

public void execute() throws SVNException {
    ISVNClientAdapter client = null;
    ISVNNotifyListener revisionListener = new ISVNNotifyListener() {

        public void setCommand(int command) {
        }

        public void logCommandLine(String commandLine) {
        }

        public void logMessage(String message) {
        }

        public void logError(String message) {
        }

        public void logRevision(long aRevision, String path) {
            PeekStatusCommand.this.revision = new SVNRevision.Number(aRevision);
        }

        public void logCompleted(String message) {
        }

        public void onNotify(File path, SVNNodeKind kind) {
        }
    };
    try {
        client = SVNProviderPlugin.getPlugin().getSVNClientManager().getSVNClient();
        client.addNotifyListener(revisionListener);
        File file;
        if (resource != null)
            file = resource.getLocation().toFile();
        else
            file = path.toFile();
        status = null;
        ISVNStatus[] statuses = client.getStatus(file, false, true, false);
        for (int i = 0; i < statuses.length; i++) {
            if (file.equals(statuses[i].getFile())) {
                status = statuses[i];
                if (status.getUrl() == null && !(status.getTextStatus() == SVNStatusKind.UNVERSIONED))
                    info = client.getInfo(status.getFile());
                break;
            }
        }
    } catch (SVNClientException e) {
        throw SVNException.wrapException(e);
    } finally {
        if (client != null) {
            client.removeNotifyListener(revisionListener);
            SVNProviderPlugin.getPlugin().getSVNClientManager().returnSVNClient(client);
        }
    }
}
Also used : SVNNodeKind(org.tigris.subversion.svnclientadapter.SVNNodeKind) ISVNNotifyListener(org.tigris.subversion.svnclientadapter.ISVNNotifyListener) SVNClientException(org.tigris.subversion.svnclientadapter.SVNClientException) ISVNStatus(org.tigris.subversion.svnclientadapter.ISVNStatus) SVNRevision(org.tigris.subversion.svnclientadapter.SVNRevision) File(java.io.File) ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter)

Example 3 with SVNNodeKind

use of org.tigris.subversion.svnclientadapter.SVNNodeKind in project subclipse by subclipse.

the class StatusCommand method execute.

protected void execute(final ISVNClientAdapter client, final IProgressMonitor monitor) throws SVNClientException {
    ISVNNotifyListener revisionListener = new ISVNNotifyListener() {

        public void setCommand(int command) {
        }

        public void logCommandLine(String commandLine) {
        }

        public void logMessage(String message) {
        }

        public void logError(String message) {
        }

        public void logRevision(long aRevision, String path) {
            StatusCommand.this.revisions.add(new RevisionsCache(aRevision, path));
            if (StatusCommand.this.revisions.size() > 1) {
                Collections.sort(StatusCommand.this.revisions);
            }
        }

        public void logCompleted(String message) {
        }

        public void onNotify(File path, SVNNodeKind kind) {
        }
    };
    try {
        client.addNotifyListener(revisionListener);
        if (callback != null && callback instanceof CancelableSVNStatusCallback) {
            ((CancelableSVNStatusCallback) callback).setSvnClient(client);
        }
        statuses = client.getStatus(file, descend, getAll, contactServer, false, callback);
    } finally {
        client.removeNotifyListener(revisionListener);
    }
}
Also used : SVNNodeKind(org.tigris.subversion.svnclientadapter.SVNNodeKind) CancelableSVNStatusCallback(org.tigris.subversion.subclipse.core.CancelableSVNStatusCallback) ISVNNotifyListener(org.tigris.subversion.svnclientadapter.ISVNNotifyListener) File(java.io.File)

Example 4 with SVNNodeKind

use of org.tigris.subversion.svnclientadapter.SVNNodeKind in project subclipse by subclipse.

the class ShowDifferencesAsUnifiedDiffDialogWC method okPressed.

protected void okPressed() {
    success = true;
    BusyIndicator.showWhile(Display.getCurrent(), new Runnable() {

        public void run() {
            ISVNRepositoryLocation repository = null;
            ISVNClientAdapter svnClient = null;
            try {
                if (toHeadButton.getSelection())
                    toRevision = SVNRevision.HEAD;
                else {
                    int toRevisionInt = Integer.parseInt(toRevisionText.getText().trim());
                    long toRevisionLong = toRevisionInt;
                    toRevision = new SVNRevision.Number(toRevisionLong);
                }
                toUrl = new SVNUrl(toUrlText.getText().trim());
                File path = new File(resource.getLocation().toString());
                svnResource = SVNWorkspaceRoot.getSVNResourceFor(resource);
                pegRevision = null;
                if (toUrlText.getText().equals(selectedResourceUrl)) {
                    ISVNRemoteResource baseResource = svnResource.getBaseResource();
                    if (baseResource != null) {
                        pegRevision = baseResource.getLastChangedRevision();
                    }
                }
                if (pegRevision == null) {
                    pegRevision = toRevision;
                }
                repository = svnResource.getRepository();
                svnClient = repository.getSVNClient();
                ISVNInfo svnInfo = svnClient.getInfo(toUrl, toRevision, pegRevision);
                SVNNodeKind nodeKind = svnInfo.getNodeKind();
                if (resource instanceof IContainer) {
                    if (nodeKind.toInt() == SVNNodeKind.FILE.toInt()) {
                        MessageDialog.openError(getShell(), Policy.bind("ShowDifferencesAsUnifiedDiffDialog.branchTag"), Policy.bind("ShowDifferencesAsUnifiedDiffDialog.fileToFolder"));
                        success = false;
                        return;
                    }
                } else {
                    if (nodeKind.toInt() == SVNNodeKind.DIR.toInt()) {
                        MessageDialog.openError(getShell(), Policy.bind("ShowDifferencesAsUnifiedDiffDialog.branchTag"), Policy.bind("ShowDifferencesAsUnifiedDiffDialog.fileToFolder"));
                        success = false;
                        return;
                    }
                }
                if (diffButton.getSelection()) {
                    diffToOutputFile = true;
                    file = new File(fileText.getText().trim());
                    if (file.exists()) {
                        if (!MessageDialog.openQuestion(getShell(), Policy.bind("HistoryView.showDifferences"), Policy.bind("HistoryView.overwriteOutfile", file.getName())))
                            return;
                    }
                    operation = new ShowDifferencesAsUnifiedDiffOperationWC(targetPart, path, toUrl, toRevision, file);
                    operation.setGraphicalCompare(true);
                } else {
                    diffToOutputFile = false;
                    success = true;
                }
            } catch (Exception e) {
                MessageDialog.openError(getShell(), Policy.bind("HistoryView.showDifferences"), e.getMessage());
                success = false;
            } finally {
                if (repository != null) {
                    repository.returnSVNClient(svnClient);
                }
            }
        }
    });
    if (!success)
        return;
    toUrlText.saveUrl();
    super.okPressed();
}
Also used : ISVNRepositoryLocation(org.tigris.subversion.subclipse.core.ISVNRepositoryLocation) SVNNodeKind(org.tigris.subversion.svnclientadapter.SVNNodeKind) ShowDifferencesAsUnifiedDiffOperationWC(org.tigris.subversion.subclipse.ui.operations.ShowDifferencesAsUnifiedDiffOperationWC) SVNUrl(org.tigris.subversion.svnclientadapter.SVNUrl) ISVNInfo(org.tigris.subversion.svnclientadapter.ISVNInfo) ISVNRemoteResource(org.tigris.subversion.subclipse.core.ISVNRemoteResource) IContainer(org.eclipse.core.resources.IContainer) File(java.io.File) ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter)

Aggregations

File (java.io.File)4 SVNNodeKind (org.tigris.subversion.svnclientadapter.SVNNodeKind)4 ISVNClientAdapter (org.tigris.subversion.svnclientadapter.ISVNClientAdapter)3 ISVNNotifyListener (org.tigris.subversion.svnclientadapter.ISVNNotifyListener)3 IContainer (org.eclipse.core.resources.IContainer)2 SVNClientException (org.tigris.subversion.svnclientadapter.SVNClientException)2 ArrayList (java.util.ArrayList)1 IProject (org.eclipse.core.resources.IProject)1 IResource (org.eclipse.core.resources.IResource)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 ISchedulingRule (org.eclipse.core.runtime.jobs.ISchedulingRule)1 CancelableSVNStatusCallback (org.tigris.subversion.subclipse.core.CancelableSVNStatusCallback)1 ISVNLocalResource (org.tigris.subversion.subclipse.core.ISVNLocalResource)1 ISVNRemoteResource (org.tigris.subversion.subclipse.core.ISVNRemoteResource)1 ISVNRepositoryLocation (org.tigris.subversion.subclipse.core.ISVNRepositoryLocation)1 ISVNRunnable (org.tigris.subversion.subclipse.core.ISVNRunnable)1 SVNException (org.tigris.subversion.subclipse.core.SVNException)1 OperationProgressNotifyListener (org.tigris.subversion.subclipse.core.client.OperationProgressNotifyListener)1 ShowDifferencesAsUnifiedDiffOperationWC (org.tigris.subversion.subclipse.ui.operations.ShowDifferencesAsUnifiedDiffOperationWC)1 ISVNInfo (org.tigris.subversion.svnclientadapter.ISVNInfo)1