Search in sources :

Example 1 with Cache

use of org.tigris.subversion.subclipse.graph.cache.Cache 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)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1 SVNException (org.tigris.subversion.subclipse.core.SVNException)1 Cache (org.tigris.subversion.subclipse.graph.cache.Cache)1 ISVNClientAdapter (org.tigris.subversion.svnclientadapter.ISVNClientAdapter)1 ISVNInfo (org.tigris.subversion.svnclientadapter.ISVNInfo)1 SVNRevision (org.tigris.subversion.svnclientadapter.SVNRevision)1