Search in sources :

Example 6 with SVNException

use of org.tigris.subversion.subclipse.core.SVNException in project subclipse by subclipse.

the class FileModificationManager method resourceChanged.

/**
 * Listen for file modifications and fire modification state changes
 *
 * @see
 *     org.eclipse.core.resources.IResourceChangeListener#resourceChanged(org.eclipse.core.resources.IResourceChangeEvent)
 */
public void resourceChanged(IResourceChangeEvent event) {
    try {
        final List<IResource> modifiedResources = new ArrayList<IResource>();
        final List<IResource> modifiedInfiniteDepthResources = new ArrayList<IResource>();
        event.getDelta().accept(new IResourceDeltaVisitor() {

            public boolean visit(IResourceDelta delta) {
                IResource resource = delta.getResource();
                if (resource.isDerived()) {
                    LocalResourceStatus aStatus = null;
                    try {
                        aStatus = SVNProviderPlugin.getPlugin().getStatusCacheManager().getStatusFromCache(resource);
                    } catch (SVNException e) {
                        SVNProviderPlugin.log(IStatus.ERROR, e.getMessage(), e);
                    }
                    if ((aStatus == null) || !aStatus.isManaged()) {
                        return false;
                    }
                    if (ignoreManagedDerivedResources) {
                        return false;
                    }
                }
                if (resource.getType() == IResource.FILE) {
                    if (delta.getKind() == IResourceDelta.CHANGED && resource.exists()) {
                        if ((delta.getFlags() & INTERESTING_CHANGES) != 0) {
                            modifiedResources.add(resource);
                            return true;
                        }
                    } else if (delta.getKind() == IResourceDelta.ADDED) {
                        modifiedResources.add(resource);
                        return true;
                    } else if (delta.getKind() == IResourceDelta.REMOVED) {
                        // provide notifications for deletions since they may not have been managed
                        // The move/delete hook would have updated the parent counts properly
                        modifiedResources.add(resource);
                        return true;
                    }
                } else if (resource.getType() == IResource.FOLDER) {
                    // FIXME: Why a different processing for add and delete?
                    if (delta.getKind() == IResourceDelta.ADDED) {
                        if (resource.getParent() != null && !modifiedInfiniteDepthResources.contains(resource.getParent())) {
                            modifiedInfiniteDepthResources.add(resource.getParent());
                        } else {
                            modifiedInfiniteDepthResources.add(resource);
                        }
                        return false;
                    } else if (delta.getKind() == IResourceDelta.REMOVED) {
                        modifiedInfiniteDepthResources.add(resource);
                        // No need to add the complete resource tree
                        return false;
                    }
                    return true;
                } else if (resource.getType() == IResource.PROJECT) {
                    IProject project = (IProject) resource;
                    if ((delta.getKind() & IResourceDelta.REMOVED) != 0) {
                        SVNWorkspaceRoot.unsetManagedBySubclipse(project);
                        return false;
                    }
                    if (!project.isAccessible()) {
                        return false;
                    }
                    if (delta.getKind() != IResourceDelta.ADDED && (delta.getFlags() & IResourceDelta.OPEN) != 0) {
                        return false;
                    }
                    if (!SVNWorkspaceRoot.isManagedBySubclipse(project)) {
                        if (delta.getKind() == IResourceDelta.ADDED) {
                            autoShareProjectIfSVNWorkingCopy(project);
                        }
                        // not a svn handled project
                        return false;
                    }
                    if (delta.getKind() == IResourceDelta.ADDED) {
                        modifiedInfiniteDepthResources.add(resource);
                        return false;
                    } else if (delta.getKind() == IResourceDelta.REMOVED) {
                        modifiedInfiniteDepthResources.add(resource);
                        return false;
                    }
                }
                return true;
            }
        });
        if (!ignoreRefreshSvnStatusCache && (!modifiedResources.isEmpty() || !modifiedInfiniteDepthResources.isEmpty())) {
            List<IProject> projects = new ArrayList<IProject>();
            if (!modifiedResources.isEmpty()) {
                IResource[] resources = (IResource[]) modifiedResources.toArray(new IResource[modifiedResources.size()]);
                for (IResource resource : resources) {
                    IProject project = resource.getProject();
                    if (project != null && !projects.contains(project)) {
                        projects.add(project);
                    }
                }
            }
            if (!modifiedInfiniteDepthResources.isEmpty()) {
                IResource[] resources = (IResource[]) modifiedInfiniteDepthResources.toArray(new IResource[modifiedInfiniteDepthResources.size()]);
                for (IResource resource : resources) {
                    IProject project = resource.getProject();
                    if (project != null && !projects.contains(project)) {
                        projects.add(project);
                    }
                }
            }
            IProject[] projectArray = new IProject[projects.size()];
            projects.toArray(projectArray);
            JobUtility.scheduleJob("Refresh SVN status cache", new Runnable() {

                public void run() {
                    // SVNLightweightDecorator)
                    if (!modifiedResources.isEmpty()) {
                        IResource[] resources = (IResource[]) modifiedResources.toArray(new IResource[modifiedResources.size()]);
                        refreshStatus(resources);
                        SVNProviderPlugin.broadcastModificationStateChanges(resources);
                    }
                    if (!modifiedInfiniteDepthResources.isEmpty()) {
                        refreshStatusInfinite(modifiedInfiniteDepthResources);
                        IResource[] resources = (IResource[]) modifiedInfiniteDepthResources.toArray(new IResource[modifiedInfiniteDepthResources.size()]);
                        SVNProviderPlugin.broadcastModificationStateChanges(resources);
                    }
                }
            }, new RefreshStatusCacheSchedulingRule(MultiRule.combine(projectArray)), false);
        }
    } catch (CoreException e) {
        SVNProviderPlugin.log(e.getStatus());
    }
}
Also used : ArrayList(java.util.ArrayList) SVNException(org.tigris.subversion.subclipse.core.SVNException) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) IResourceDeltaVisitor(org.eclipse.core.resources.IResourceDeltaVisitor) LocalResourceStatus(org.tigris.subversion.subclipse.core.resources.LocalResourceStatus) IResource(org.eclipse.core.resources.IResource) IResourceDelta(org.eclipse.core.resources.IResourceDelta)

Example 7 with SVNException

use of org.tigris.subversion.subclipse.core.SVNException in project subclipse by subclipse.

the class SyncFileChangeListener method resourceChanged.

/*
   * When a resource changes this method will detect if
   * the changed resources is a meta file that has changed
   *
   * @see IResourceChangeListener#resourceChanged(IResourceChangeEvent)
   */
public void resourceChanged(IResourceChangeEvent event) {
    try {
        final StatusCacheManager cacheManager = SVNProviderPlugin.getPlugin().getStatusCacheManager();
        // final ChangesCollector changesCollector = new ChangesCollector();
        event.getDelta().accept(new IResourceDeltaVisitor() {

            public boolean visit(IResourceDelta delta) {
                IResource resource = delta.getResource();
                if (resource.getType() == IResource.ROOT) {
                    // continue with the delta
                    return true;
                }
                if (resource.getType() == IResource.PROJECT) {
                    // If the project is not accessible, don't process it
                    if (!resource.isAccessible())
                        return false;
                    // If the Project is not managed by subclipse, don't process it
                    if (!SVNWorkspaceRoot.isManagedBySubclipse((IProject) resource))
                        return false;
                }
                String name = resource.getName();
                int kind = delta.getKind();
                // already have the statuses
                try {
                    if ((resource.getType() == IResource.FOLDER) && (kind == IResourceDelta.ADDED) && (cacheManager.hasCachedStatus(resource)) && (cacheManager.getStatus(resource).isManaged())) {
                        if (Policy.DEBUG_METAFILE_CHANGES) {
                            System.out.println("[svn] duplicte ADD change event registered in SyncFileChangeListener: " + // $NON-NLS-1$
                            resource);
                        }
                        return false;
                    }
                } catch (SVNException e) {
                    // The get status failed, so just proceed deeper as normal.
                    return true;
                }
                // then ignore the change (e.g. marker changes to files).
                if (kind == IResourceDelta.CHANGED && (delta.getFlags() & INTERESTING_CHANGES) == 0) {
                    return true;
                }
                if (SVNProviderPlugin.getPlugin().isAdminDirectory(name)) {
                    handleSVNDir((IContainer) resource, kind);
                }
                return true;
            }
        }, IContainer.INCLUDE_TEAM_PRIVATE_MEMBERS);
    // changesCollector.refreshChangedResources();
    } catch (CoreException e) {
        SVNProviderPlugin.log(e.getStatus());
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IResourceDeltaVisitor(org.eclipse.core.resources.IResourceDeltaVisitor) SVNException(org.tigris.subversion.subclipse.core.SVNException) StatusCacheManager(org.tigris.subversion.subclipse.core.status.StatusCacheManager) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource) IResourceDelta(org.eclipse.core.resources.IResourceDelta)

Example 8 with SVNException

use of org.tigris.subversion.subclipse.core.SVNException in project subclipse by subclipse.

the class GraphBackgroundTask method execute.

protected void execute(IProgressMonitor monitor) throws SVNException, InterruptedException {
    boolean error = false;
    Cache cache = null;
    monitor.beginTask("Calculating graph information", TOTAL_STEPS);
    monitor.worked(SHORT_TASK_STEPS);
    ISVNClientAdapter client = null;
    try {
        client = SVNProviderPlugin.getPlugin().getSVNClient();
        ISVNInfo info;
        if (resource == null)
            info = client.getInfo(remoteResource.getUrl());
        else {
            if (resource.getRawLocation() == null)
                info = client.getInfoFromWorkingCopy(resource.getLocation().toFile());
            else
                info = client.getInfoFromWorkingCopy(resource.getRawLocation().toFile());
            if (info.getUuid() == null) {
                info = client.getInfo(info.getUrl());
            }
        }
        if (editor != null)
            ((RevisionGraphEditorInput) editor.getEditorInput()).setInfo(info);
        long revision = info.getRevision().getNumber();
        String path = info.getUrl().toString().substring(info.getRepository().toString().length());
        monitor.setTaskName("Initializating cache");
        cache = getCache(info.getUuid());
        monitor.worked(SHORT_TASK_STEPS);
        // update the cache
        long latestRevisionStored = cache.getLatestRevision();
        SVNRevision latest = null;
        SVNRevision endRevision = null;
        monitor.setTaskName("Connecting to the repository");
        // TODO: try-catch this line and make it work off-line
        long latestRevisionInRepository = client.getInfo(info.getRepository()).getLastChangedRevision().getNumber();
        monitor.worked(SHORT_TASK_STEPS);
        if (refreshRevision != null || refreshRevisions != null || latestRevisionInRepository > latestRevisionStored) {
            if (refreshRevision == null) {
                if (latestRevisionStored >= latestRevisionInRepository)
                    latest = new SVNRevision.Number(latestRevisionInRepository);
                else
                    latest = new SVNRevision.Number(latestRevisionStored + 1);
            } else {
                latest = refreshRevision;
            }
            if (refreshRevision == null)
                endRevision = SVNRevision.HEAD;
            else
                endRevision = refreshRevision;
            try {
                monitor.setTaskName("Retrieving revision history");
                int unitWork;
                if (refreshRevision == null && refreshRevisions == null)
                    unitWork = VERY_LONG_TASK / (int) (latestRevisionInRepository - latestRevisionStored);
                else if (refreshRevisions != null)
                    unitWork = VERY_LONG_TASK / refreshRevisions.length;
                else
                    unitWork = VERY_LONG_TASK;
                if (refreshRevisions != null) {
                    if (monitor.isCanceled())
                        return;
                    monitor.setTaskName("Refreshing cache");
                    List refreshedNodes = new ArrayList();
                    for (int i = 0; i < refreshNodes.length; i++) {
                        if (refreshNodes[i].getAction() != 'D')
                            refreshedNodes.add(refreshNodes[i]);
                    }
                    cache.refresh(refreshedNodes, info, monitor, unitWork);
                } else if (refreshRevision != null) {
                    if (monitor.isCanceled())
                        return;
                    monitor.setTaskName("Refreshing cache");
                    revision = refreshNode.getRevision();
                    path = refreshNode.getPath();
                    List refreshedNodes = new ArrayList();
                    refreshedNodes.add(refreshNode);
                    cache.refresh(refreshedNodes, info, monitor, unitWork);
                }
                if (getNewRevisions) {
                    CallbackUpdater callbackUpdater = new CallbackUpdater(cache, monitor, unitWork, client);
                    cache.startUpdate();
                    client.getLogMessages(info.getRepository(), latest, latest, endRevision, false, true, 0, includeMergedRevisions, ISVNClientAdapter.DEFAULT_LOG_PROPERTIES, callbackUpdater);
                    cache.finishUpdate();
                }
            } catch (Exception e) {
                Activator.handleError(e);
                error = true;
                Activator.showErrorDialog("Calculate Revision Graph Information", e, false);
            }
        } else {
            monitor.worked(VERY_LONG_TASK);
        }
        if (editor != null) {
            if (error == true || monitor.isCanceled()) {
                if (refreshRevision == null && refreshRevisions == null) {
                    Display.getDefault().syncExec(new Runnable() {

                        public void run() {
                            IWorkbenchWindow window = editor.getEditorSite().getWorkbenchWindow();
                            IWorkbenchPage page = window.getActivePage();
                            page.activate(editor);
                            page.closeEditor(editor, false);
                        }
                    });
                }
            } else {
                updateView(monitor, cache, path, revision);
            }
        }
        monitor.done();
    } catch (Exception e) {
        Activator.handleError(e);
        Activator.showErrorDialog("Calculate Revision Graph Information", e, false);
        return;
    } finally {
        if (cache != null)
            cache.close();
        SVNProviderPlugin.getPlugin().getSVNClientManager().returnSVNClient(client);
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ArrayList(java.util.ArrayList) SVNException(org.tigris.subversion.subclipse.core.SVNException) ISVNInfo(org.tigris.subversion.svnclientadapter.ISVNInfo) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ArrayList(java.util.ArrayList) List(java.util.List) SVNRevision(org.tigris.subversion.svnclientadapter.SVNRevision) Cache(org.tigris.subversion.subclipse.graph.cache.Cache) ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter)

Example 9 with SVNException

use of org.tigris.subversion.subclipse.core.SVNException in project subclipse by subclipse.

the class StatusCacheManager method getURL.

// getStatuses returns null URL for svn:externals folder.  This will
// get the URL using svn info command on the local resource
private String getURL(ISVNStatus status) {
    String url = status.getUrlString();
    if (url == null && !(status.getTextStatus() == SVNStatusKind.UNVERSIONED) && !(status.getTextStatus() == SVNStatusKind.IGNORED)) {
        ISVNClientAdapter svnClient = null;
        try {
            svnClient = SVNProviderPlugin.getPlugin().getSVNClient();
            SVNProviderPlugin.disableConsoleLogging();
            ISVNInfo info = svnClient.getInfoFromWorkingCopy(status.getFile());
            SVNUrl svnurl = info.getUrl();
            url = (svnurl != null) ? svnurl.toString() : null;
        } catch (SVNException e) {
        } catch (SVNClientException e) {
        } finally {
            SVNProviderPlugin.enableConsoleLogging();
            SVNProviderPlugin.getPlugin().getSVNClientManager().returnSVNClient(svnClient);
        }
    }
    return url;
}
Also used : SVNUrl(org.tigris.subversion.svnclientadapter.SVNUrl) SVNClientException(org.tigris.subversion.svnclientadapter.SVNClientException) ISVNInfo(org.tigris.subversion.svnclientadapter.ISVNInfo) SVNException(org.tigris.subversion.subclipse.core.SVNException) ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter)

Example 10 with SVNException

use of org.tigris.subversion.subclipse.core.SVNException in project subclipse by subclipse.

the class SVNWorkspaceSubscriber method findChanges.

private IResource[] findChanges(IResource resource, int depth, IProgressMonitor monitor) throws TeamException {
    try {
        monitor.beginTask("", 100);
        remoteSyncStateStore.flushBytes(resource, depth);
        // ISVNClientAdapter client = SVNProviderPlugin.getPlugin().createSVNClient();
        boolean descend = (depth == IResource.DEPTH_INFINITE) ? true : false;
        boolean showOutOfDate = SVNProviderPlugin.getPlugin().getPluginPreferences().getBoolean(ISVNCoreConstants.PREF_SHOW_OUT_OF_DATE_FOLDERS);
        StatusAndInfoCommand cmd = new StatusAndInfoCommand(SVNWorkspaceRoot.getSVNResourceFor(resource), descend, showOutOfDate, true);
        cmd.setCallback(new CancelableSVNStatusCallback(monitor));
        cmd.run(monitor);
        if (monitor.isCanceled()) {
            return new IResource[0];
        }
        monitor.worked(70);
        RemoteResourceStatus[] statuses = cmd.getRemoteResourceStatuses();
        List<IResource> result = new ArrayList<IResource>(statuses.length);
        for (RemoteResourceStatus status : statuses) {
            IResource changedResource = SVNWorkspaceRoot.getResourceFor(resource, status);
            if (changedResource == null)
                continue;
            if (isSupervised(changedResource) || (status.getTextStatus() != SVNStatusKind.NONE)) {
                if (!ignoreHiddenChanges || !Util.isHidden(changedResource)) {
                    result.add(changedResource);
                    remoteSyncStateStore.setBytes(changedResource, status.getBytes());
                    registerChangedResourceParent(changedResource);
                }
            }
        }
        // Ensure that the local sync state is also updated
        IContainer container = resource.getType() == IResource.FILE ? resource.getParent() : (IContainer) resource;
        SVNProviderPlugin.getPlugin().getStatusCacheManager().refreshStatus(container, true);
        monitor.worked(30);
        return (IResource[]) result.toArray(new IResource[result.size()]);
    } catch (SVNException e) {
        if (e.getMessage().contains("Operation cancelled")) {
            return new IResource[0];
        } else {
            throw new TeamException("Error getting status for resource " + resource + " " + e.getMessage(), e);
        }
    } finally {
        monitor.done();
    }
}
Also used : RemoteResourceStatus(org.tigris.subversion.subclipse.core.resources.RemoteResourceStatus) TeamException(org.eclipse.team.core.TeamException) CancelableSVNStatusCallback(org.tigris.subversion.subclipse.core.CancelableSVNStatusCallback) ArrayList(java.util.ArrayList) StatusAndInfoCommand(org.tigris.subversion.subclipse.core.client.StatusAndInfoCommand) SVNException(org.tigris.subversion.subclipse.core.SVNException) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource)

Aggregations

SVNException (org.tigris.subversion.subclipse.core.SVNException)162 IResource (org.eclipse.core.resources.IResource)68 ISVNLocalResource (org.tigris.subversion.subclipse.core.ISVNLocalResource)68 ArrayList (java.util.ArrayList)39 CoreException (org.eclipse.core.runtime.CoreException)25 ISVNClientAdapter (org.tigris.subversion.svnclientadapter.ISVNClientAdapter)25 SVNClientException (org.tigris.subversion.svnclientadapter.SVNClientException)23 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)21 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)19 Iterator (java.util.Iterator)18 TeamException (org.eclipse.team.core.TeamException)18 InvocationTargetException (java.lang.reflect.InvocationTargetException)17 IContainer (org.eclipse.core.resources.IContainer)16 SVNUrl (org.tigris.subversion.svnclientadapter.SVNUrl)16 File (java.io.File)15 IProject (org.eclipse.core.resources.IProject)15 ISynchronizeModelElement (org.eclipse.team.ui.synchronize.ISynchronizeModelElement)14 IFile (org.eclipse.core.resources.IFile)13 GridData (org.eclipse.swt.layout.GridData)13 ISVNRemoteResource (org.tigris.subversion.subclipse.core.ISVNRemoteResource)13