Search in sources :

Example 1 with OperationManager

use of org.tigris.subversion.subclipse.core.client.OperationManager in project subclipse by subclipse.

the class RevertResourcesCommand 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 {
    final Set<IResource> propertiesOnlyFolders = new LinkedHashSet<IResource>();
    // sort first, so that all children of a folder directly follow it in the array
    Arrays.sort(resources, resourceComparator);
    ISVNClientAdapter svnClient = root.getRepository().getSVNClient();
    try {
        final OperationManager operationManager = OperationManager.getInstance();
        operationManager.beginOperation(svnClient);
        // local history first.  Also remove unversioned resources.
        if (recurse && resourcesToRevert != null) {
            for (int i = 0; i < resourcesToRevert.length; i++) {
                if (project == null || resourcesToRevert[i].getProject().equals(project)) {
                    try {
                        Util.saveLocalHistory(resourcesToRevert[i]);
                    } catch (CoreException e) {
                        SVNProviderPlugin.log(IStatus.ERROR, e.getMessage(), e);
                    }
                    LocalResourceStatus status = SVNWorkspaceRoot.getSVNResourceFor(resourcesToRevert[i]).getStatus();
                    if (!(resourcesToRevert[i].getType() == IResource.FOLDER) || !status.isAdded()) {
                        if (!status.isManaged()) {
                            try {
                                resourcesToRevert[i].delete(true, monitor);
                            } catch (CoreException ex) {
                                throw SVNException.wrapException(ex);
                            }
                        }
                    }
                }
            }
        }
        for (int i = 0; i < resources.length; i++) {
            LocalResourceStatus status = SVNWorkspaceRoot.getSVNResourceFor(resources[i]).getStatus();
            // current as a base path.
            if (resources[i].getType() == IResource.FOLDER && status.isAdded()) {
                svnClient.revert(resources[i].getLocation().toFile(), true);
                propertiesOnlyFolders.add(resources[i]);
                monitor.worked(100);
                // be refreshed.
                try {
                    resources[i].accept(new IResourceVisitor() {

                        public boolean visit(IResource aResource) {
                            if (aResource.getType() == IResource.FOLDER) {
                                operationManager.onNotify(aResource.getLocation().toFile(), SVNNodeKind.UNKNOWN);
                                // This is necessary for folders, that are ignored after the revert
                                propertiesOnlyFolders.add(aResource);
                            }
                            return true;
                        }
                    }, IResource.DEPTH_INFINITE, false);
                } catch (CoreException e) {
                    SVNProviderPlugin.log(Status.WARNING, "", e);
                }
                // If folder path has no ending / we can have problem where dir foobar will look like
                // subdir of foo
                String baseFullPath = resources[i].getFullPath().addTrailingSeparator().toString();
                while (i < resources.length - 1 && resources[i + 1].getFullPath().toString().startsWith(baseFullPath)) {
                    monitor.worked(100);
                    i++;
                }
            } else {
                if (!status.isManaged()) {
                    try {
                        resources[i].delete(true, monitor);
                    } catch (CoreException ex) {
                        throw SVNException.wrapException(ex);
                    }
                } else {
                    if (!recurse) {
                        try {
                            Util.saveLocalHistory(resources[i]);
                        } catch (CoreException e) {
                            SVNProviderPlugin.log(IStatus.ERROR, e.getMessage(), e);
                        }
                    }
                    File path = resources[i].getLocation().toFile();
                    svnClient.revert(path, recurse);
                    // notify the change. As workaround, do it manually.
                    if (resources[i].getType() != IResource.FILE) {
                        operationManager.onNotify(path, SVNNodeKind.UNKNOWN);
                        propertiesOnlyFolders.add(resources[i]);
                    }
                    monitor.worked(100);
                }
            }
        }
    } catch (SVNClientException e) {
        throw SVNException.wrapException(e);
    } finally {
        root.getRepository().returnSVNClient(svnClient);
        if (propertiesOnlyFolders.size() > 0) {
            OperationManager.getInstance().endOperation(true, propertiesOnlyFolders);
        } else {
            OperationManager.getInstance().endOperation();
        }
        monitor.done();
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) IResourceVisitor(org.eclipse.core.resources.IResourceVisitor) CoreException(org.eclipse.core.runtime.CoreException) SVNClientException(org.tigris.subversion.svnclientadapter.SVNClientException) OperationManager(org.tigris.subversion.subclipse.core.client.OperationManager) LocalResourceStatus(org.tigris.subversion.subclipse.core.resources.LocalResourceStatus) File(java.io.File) IResource(org.eclipse.core.resources.IResource) ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter)

Example 2 with OperationManager

use of org.tigris.subversion.subclipse.core.client.OperationManager in project subclipse by subclipse.

the class UndoMergeCommand method run.

public void run(IProgressMonitor monitor) throws SVNException {
    ISVNClientAdapter svnClient = null;
    ISVNRepositoryLocation repository = null;
    try {
        final OperationManager operationManager = OperationManager.getInstance();
        ISVNLocalResource svnResource = SVNWorkspaceRoot.getSVNResourceFor(resource);
        repository = svnResource.getRepository();
        svnClient = repository.getSVNClient();
        svnClient.addNotifyListener(operationResourceCollector);
        operationManager.beginOperation(svnClient);
        LocalResourceStatus status = SVNWorkspaceRoot.getSVNResourceFor(resource).getStatus();
        if (!status.isManaged()) {
            try {
                resource.delete(true, monitor);
            } catch (CoreException ex) {
                throw SVNException.wrapException(ex);
            }
        } else {
            File path = resource.getLocation().toFile();
            svnClient.revert(path, true);
            if (resource.getType() != IResource.FILE)
                operationManager.onNotify(path, SVNNodeKind.UNKNOWN);
            monitor.worked(100);
        }
    } catch (SVNClientException e) {
        throw SVNException.wrapException(e);
    } finally {
        if (repository != null) {
            repository.returnSVNClient(svnClient);
        }
        OperationManager.getInstance().endOperation(true, operationResourceCollector.getOperationResources());
        monitor.done();
    }
}
Also used : ISVNRepositoryLocation(org.tigris.subversion.subclipse.core.ISVNRepositoryLocation) CoreException(org.eclipse.core.runtime.CoreException) SVNClientException(org.tigris.subversion.svnclientadapter.SVNClientException) OperationManager(org.tigris.subversion.subclipse.core.client.OperationManager) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource) LocalResourceStatus(org.tigris.subversion.subclipse.core.resources.LocalResourceStatus) File(java.io.File) ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter)

Aggregations

File (java.io.File)2 CoreException (org.eclipse.core.runtime.CoreException)2 OperationManager (org.tigris.subversion.subclipse.core.client.OperationManager)2 LocalResourceStatus (org.tigris.subversion.subclipse.core.resources.LocalResourceStatus)2 ISVNClientAdapter (org.tigris.subversion.svnclientadapter.ISVNClientAdapter)2 SVNClientException (org.tigris.subversion.svnclientadapter.SVNClientException)2 LinkedHashSet (java.util.LinkedHashSet)1 IResource (org.eclipse.core.resources.IResource)1 IResourceVisitor (org.eclipse.core.resources.IResourceVisitor)1 ISVNLocalResource (org.tigris.subversion.subclipse.core.ISVNLocalResource)1 ISVNRepositoryLocation (org.tigris.subversion.subclipse.core.ISVNRepositoryLocation)1