Search in sources :

Example 1 with ISVNNotifyListener

use of org.tigris.subversion.svnclientadapter.ISVNNotifyListener 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 ISVNNotifyListener

use of org.tigris.subversion.svnclientadapter.ISVNNotifyListener 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 ISVNNotifyListener

use of org.tigris.subversion.svnclientadapter.ISVNNotifyListener 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)

Aggregations

File (java.io.File)3 ISVNNotifyListener (org.tigris.subversion.svnclientadapter.ISVNNotifyListener)3 SVNNodeKind (org.tigris.subversion.svnclientadapter.SVNNodeKind)3 ISVNClientAdapter (org.tigris.subversion.svnclientadapter.ISVNClientAdapter)2 SVNClientException (org.tigris.subversion.svnclientadapter.SVNClientException)2 ArrayList (java.util.ArrayList)1 IContainer (org.eclipse.core.resources.IContainer)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 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 ISVNStatus (org.tigris.subversion.svnclientadapter.ISVNStatus)1 SVNRevision (org.tigris.subversion.svnclientadapter.SVNRevision)1