Search in sources :

Example 26 with SVNRevision

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

the class RevisionDetailsAction method run.

public void run() {
    remoteResource = null;
    logEntry = null;
    includeTags = SVNUIPlugin.getPlugin().getPreferenceStore().getBoolean(ISVNUIConstants.PREF_SHOW_TAGS_IN_REMOTE);
    BusyIndicator.showWhile(Display.getDefault(), new Runnable() {

        public void run() {
            try {
                RevisionGraphEditorInput input = (RevisionGraphEditorInput) editor.getEditorInput();
                ISVNInfo info = input.getInfo();
                ISVNRepositoryLocation repository = SVNProviderPlugin.getPlugin().getRepository(info.getRepository().toString());
                remoteResource = new RemoteFile(repository, new SVNUrl(repository.getLocation() + node.getPath()), new SVNRevision.Number(node.getRevision()));
                AliasManager tagManager = null;
                if (includeTags)
                    tagManager = new AliasManager(remoteResource.getUrl());
                SVNRevision pegRevision = new SVNRevision.Number(node.getRevision());
                SVNRevision revisionStart = new SVNRevision.Number(node.getRevision());
                SVNRevision revisionEnd = new SVNRevision.Number(node.getRevision());
                GetLogsCommand logCmd = new GetLogsCommand(remoteResource, pegRevision, revisionStart, revisionEnd, false, 0, tagManager, true);
                logCmd.run(null);
                ILogEntry[] logEntries = logCmd.getLogEntries();
                if (logEntries != null && logEntries.length > 0) {
                    logEntry = logEntries[0];
                }
            } catch (Exception e) {
                MessageDialog.openError(Display.getDefault().getActiveShell(), "Revision Info", e.getMessage());
            }
        }
    });
    if (logEntry != null) {
        ShowRevisionsDialog dialog = new ShowRevisionsDialog(Display.getDefault().getActiveShell(), logEntry, remoteResource, includeTags, null);
        dialog.setTitle("Revision Info");
        dialog.setSelectFirst(true);
        dialog.open();
    }
}
Also used : AliasManager(org.tigris.subversion.subclipse.core.history.AliasManager) ISVNRepositoryLocation(org.tigris.subversion.subclipse.core.ISVNRepositoryLocation) RevisionGraphEditorInput(org.tigris.subversion.subclipse.graph.editors.RevisionGraphEditorInput) SVNUrl(org.tigris.subversion.svnclientadapter.SVNUrl) ShowRevisionsDialog(org.tigris.subversion.subclipse.ui.dialogs.ShowRevisionsDialog) GetLogsCommand(org.tigris.subversion.subclipse.core.commands.GetLogsCommand) ISVNInfo(org.tigris.subversion.svnclientadapter.ISVNInfo) SVNRevision(org.tigris.subversion.svnclientadapter.SVNRevision) RemoteFile(org.tigris.subversion.subclipse.core.resources.RemoteFile)

Example 27 with SVNRevision

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

the class Cache method refresh.

public void refresh(List refreshedNodes, ISVNInfo info, IProgressMonitor monitor, int unitWorked) {
    ISVNLogMessageCallback callback = new ISVNLogMessageCallback() {

        public void singleMessage(ISVNLogMessage message) {
            update(message, true);
        }
    };
    revisionsTempFile = new File(root, "revisionsTemp");
    logMessagesTempFile = new File(root, "logMessagesTemp");
    revisionsTempFile.delete();
    logMessagesTempFile.delete();
    try {
        revisionsTempFile.createNewFile();
        logMessagesTempFile.createNewFile();
    } catch (IOException e) {
        Activator.handleError(e);
    }
    List revisions = new ArrayList();
    Iterator iter = refreshedNodes.iterator();
    while (iter.hasNext()) {
        Node node = (Node) iter.next();
        revisions.add(Long.toString(node.getRevision()));
    }
    startTempUpdate();
    RandomAccessFile file = null;
    ISVNClientAdapter client = null;
    try {
        client = SVNProviderPlugin.getPlugin().getSVNClient();
        file = new RandomAccessFile(logMessagesFile, "r");
        int revInt = new Long(getLatestRevision()).intValue();
        while (file.getFilePointer() < file.length()) {
            ISVNLogMessage lm = readNext(file, true);
            level = 0;
            int index = revisions.indexOf(lm.getRevision().toString());
            if (index == -1) {
                update(lm, true);
                if (lm.hasChildren() && lm.getChildMessages() != null) {
                    updateChildren(lm, true);
                }
                monitor.worked(unitWorked / revInt);
            } else {
                Node updateNode = (Node) refreshedNodes.get(index);
                SVNRevision updateRevision = new SVNRevision.Number(updateNode.getRevision());
                client.getLogMessages(new SVNUrl(info.getRepository() + updateNode.getPath()), updateRevision, updateRevision, updateRevision, false, true, 0, true, ISVNClientAdapter.DEFAULT_LOG_PROPERTIES, callback);
                monitor.worked(unitWorked);
            // updateRevision = (ISVNLogMessage)refreshedMessages.get(index);
            // monitor.worked(unitWorked);
            }
            if (monitor.isCanceled()) {
                break;
            }
        }
    } catch (Exception e) {
    } finally {
        closeFile(file);
        SVNProviderPlugin.getPlugin().getSVNClientManager().returnSVNClient(client);
    }
    finishTempUpdate();
    if (monitor.isCanceled()) {
        revisionsTempFile.delete();
        logMessagesTempFile.delete();
        return;
    }
    revisionsFile.delete();
    logMessagesFile.delete();
    revisionsTempFile.renameTo(revisionsFile);
    logMessagesTempFile.renameTo(logMessagesFile);
}
Also used : SVNUrl(org.tigris.subversion.svnclientadapter.SVNUrl) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ISVNLogMessage(org.tigris.subversion.svnclientadapter.ISVNLogMessage) IOException(java.io.IOException) ISVNLogMessageCallback(org.tigris.subversion.svnclientadapter.ISVNLogMessageCallback) RandomAccessFile(java.io.RandomAccessFile) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) SVNRevision(org.tigris.subversion.svnclientadapter.SVNRevision) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter)

Example 28 with SVNRevision

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

the class Util method getUrlForRevision.

public static SVNUrl getUrlForRevision(ISVNRemoteResource resource, SVNRevision.Number revision, IProgressMonitor pm) throws SVNException {
    SVNUrl url = resource.getUrl();
    SVNRevision revisionStart = new SVNRevision.Number(revision.getNumber());
    GetLogsCommand getLogsCommand = new GetLogsCommand(resource, SVNRevision.HEAD, revisionStart, SVNRevision.HEAD, false, 0, null, true);
    getLogsCommand.run(pm);
    ILogEntry[] logEntries = getLogsCommand.getLogEntries();
    String path = resource.getRepositoryRelativePath().replaceAll("%20", " ");
    for (int i = logEntries.length - 1; i > -1; i--) {
        ILogEntry logEntry = logEntries[i];
        if (!logEntry.getRevision().equals(revision)) {
            LogEntryChangePath[] changePaths = logEntry.getLogEntryChangePaths();
            for (LogEntryChangePath changePath : changePaths) {
                if (changePath.getPath().equals(path) && changePath.getCopySrcPath() != null) {
                    try {
                        path = changePath.getCopySrcPath();
                        url = new SVNUrl(resource.getRepository().getRepositoryRoot().toString() + changePath.getCopySrcPath());
                    } catch (MalformedURLException e) {
                    }
                }
            }
        }
    }
    return url;
}
Also used : MalformedURLException(java.net.MalformedURLException) ILogEntry(org.tigris.subversion.subclipse.core.history.ILogEntry) LogEntryChangePath(org.tigris.subversion.subclipse.core.history.LogEntryChangePath) SVNUrl(org.tigris.subversion.svnclientadapter.SVNUrl) GetLogsCommand(org.tigris.subversion.subclipse.core.commands.GetLogsCommand) SVNRevision(org.tigris.subversion.svnclientadapter.SVNRevision)

Example 29 with SVNRevision

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

the class ResolveTreeConflictWizard method performFinish.

public boolean performFinish() {
    if (mainPage.getReplace()) {
        mergeException = null;
        try {
            BusyIndicator.showWhile(Display.getDefault(), new Runnable() {

                public void run() {
                    try {
                        svnClient = svnResource.getRepository().getSVNClient();
                        File file = svnResource.getResource().getLocation().toFile();
                        svnClient.remove(new File[] { file }, true);
                        SVNUrl url = new SVNUrl(treeConflict.getConflictDescriptor().getSrcRightVersion().getReposURL() + "/" + treeConflict.getConflictDescriptor().getSrcRightVersion().getPathInRepos());
                        SVNRevision revision;
                        int index = treeConflict.getConflictDescriptor().getSrcRightVersion().toString().lastIndexOf(// $NON-NLS-1$
                        "@");
                        if (index == -1) {
                            revision = SVNRevision.HEAD;
                        } else {
                            long number = Long.parseLong(treeConflict.getConflictDescriptor().getSrcRightVersion().toString().substring(index + 1));
                            revision = new SVNRevision.Number(number);
                        }
                        svnClient.copy(url, file, revision);
                    } catch (Exception e) {
                        mergeException = e;
                    }
                }
            });
            if (mergeException != null) {
                SVNUIPlugin.log(IStatus.ERROR, mergeException.getMessage(), mergeException);
                MessageDialog.openError(getShell(), Messages.ResolveTreeConflictWizard_2, mergeException.getMessage());
                return false;
            }
            svnResource.getResource().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
        } catch (Exception e) {
            SVNUIPlugin.log(IStatus.ERROR, e.getMessage(), e);
            MessageDialog.openError(getShell(), Messages.ResolveTreeConflictWizard_2, e.getMessage());
            return false;
        }
        return true;
    }
    compare = mainPage.getCompare();
    if (mainPage.getMergeFromRepository()) {
        try {
            final SVNUrl url = new SVNUrl(mainPage.getMergeFromUrl());
            SVNRevision revision1;
            if (treeConflict.getConflictDescriptor().getSrcLeftVersion().getPegRevision() == treeConflict.getConflictDescriptor().getSrcRightVersion().getPegRevision())
                revision1 = new SVNRevision.Number(treeConflict.getConflictDescriptor().getSrcLeftVersion().getPegRevision() - 1);
            else
                revision1 = new SVNRevision.Number(treeConflict.getConflictDescriptor().getSrcLeftVersion().getPegRevision());
            final SVNRevision revision2 = new SVNRevision.Number(treeConflict.getConflictDescriptor().getSrcRightVersion().getPegRevision());
            if (treeConflict.getConflictDescriptor().getSrcLeftVersion().getPegRevision() == treeConflict.getConflictDescriptor().getSrcRightVersion().getPegRevision())
                revision1 = new SVNRevision.Number(treeConflict.getConflictDescriptor().getSrcLeftVersion().getPegRevision() - 1);
            final IResource mergeTarget = mainPage.getMergeTarget();
            final SVNRevision rev1 = revision1;
            svnClient = svnResource.getRepository().getSVNClient();
            mergeException = null;
            BusyIndicator.showWhile(Display.getDefault(), new Runnable() {

                public void run() {
                    try {
                        mergePath = mergeTarget.getLocation().toFile();
                        svnClient.merge(url, rev1, url, revision2, mergePath, true, false, false, true);
                        try {
                            // Refresh the resource after merge
                            if (mergeTarget.getParent() != null)
                                mergeTarget.getParent().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
                            else
                                mergeTarget.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
                        } catch (CoreException e1) {
                        }
                    } catch (Exception e) {
                        mergeException = e;
                    }
                }
            });
            if (mergeException != null) {
                SVNUIPlugin.log(IStatus.ERROR, mergeException.getMessage(), mergeException);
                MessageDialog.openError(getShell(), Messages.ResolveTreeConflictWizard_mergeError, mergeException.getMessage());
                return false;
            }
        } catch (Exception e) {
            SVNUIPlugin.log(IStatus.ERROR, e.getMessage(), e);
            MessageDialog.openError(getShell(), Messages.ResolveTreeConflictWizard_mergeError, e.getMessage());
            return false;
        } finally {
            svnResource.getRepository().returnSVNClient(svnClient);
        }
    }
    if (mainPage.getCompare()) {
        if (mainPage.getCompareResource2() == null) {
            ISVNLocalResource svnCompareResource = mainPage.getSvnCompareResource();
            if (svnCompareResource == null)
                svnCompareResource = svnResource;
            ISVNRemoteResource remoteResource = mainPage.getRemoteResource();
            try {
                // $NON-NLS-1$ //$NON-NLS-2$
                File file = File.createTempFile("revision", ".diff");
                file.deleteOnExit();
                File path = new File(svnCompareResource.getResource().getLocation().toString());
                SVNUrl toUrl = remoteResource.getUrl();
                SVNRevision toRevision = remoteResource.getRevision();
                ShowDifferencesAsUnifiedDiffOperationWC operation = new ShowDifferencesAsUnifiedDiffOperationWC(targetPart, path, toUrl, toRevision, file);
                SVNLocalCompareInput compareInput = new SVNLocalCompareInput(svnCompareResource, remoteResource);
                compareInput.setDiffOperation(operation);
                CompareUI.openCompareEditorOnPage(compareInput, targetPart.getSite().getPage());
                CompareCloseListener closeListener = new CompareCloseListener(Messages.ResolveTreeConflictWizard_compare + svnCompareResource.getName() + // $NON-NLS-1$
                " <workspace>");
                targetPart.getSite().getPage().addPartListener(closeListener);
            } catch (Exception e) {
                SVNUIPlugin.log(IStatus.ERROR, e.getMessage(), e);
                MessageDialog.openError(getShell(), Messages.ResolveTreeConflictWizard_compareError, e.getMessage());
                return false;
            }
        } else {
            ISelection selection = new IStructuredSelection() {

                public Object getFirstElement() {
                    return mainPage.getCompareResource1();
                }

                public Iterator iterator() {
                    return toList().iterator();
                }

                public int size() {
                    return 2;
                }

                public Object[] toArray() {
                    IResource[] compareResources = { mainPage.getCompareResource1(), mainPage.getCompareResource2() };
                    return compareResources;
                }

                public List toList() {
                    List compareList = new ArrayList();
                    compareList.add(mainPage.getCompareResource1());
                    compareList.add(mainPage.getCompareResource2());
                    return compareList;
                }

                public boolean isEmpty() {
                    return false;
                }
            };
            CompareAction compareAction = new CompareAction();
            compareAction.setActivePart(null, targetPart);
            IAction action = new Action() {
            };
            compareAction.selectionChanged(action, selection);
            compareAction.run(selection);
            CompareCloseListener closeListener = new CompareCloseListener(Messages.ResolveTreeConflictWizard_compare2 + mainPage.getCompareResource1().getName() + "' - '" + mainPage.getCompareResource2().getName() + // $NON-NLS-1$ //$NON-NLS-2$
            "')");
            targetPart.getSite().getPage().addPartListener(closeListener);
        }
    }
    if (mainPage.getRevertResource() != null) {
        revertException = null;
        BusyIndicator.showWhile(Display.getCurrent(), new Runnable() {

            public void run() {
                try {
                    IResource[] revertResources = { mainPage.getRevertResource() };
                    RevertResourcesCommand revertCommand = new RevertResourcesCommand(svnResource.getWorkspaceRoot(), revertResources);
                    revertCommand.run(new NullProgressMonitor());
                } catch (Exception e) {
                    revertException = e;
                }
            }
        });
        if (revertException != null) {
            SVNUIPlugin.log(IStatus.ERROR, revertException.getMessage(), revertException);
            MessageDialog.openError(getShell(), Messages.ResolveTreeConflictWizard_revertError, revertException.getMessage());
            return false;
        }
    }
    if (mainPage.getDeleteResource() != null) {
        try {
            mainPage.getDeleteResource().delete(true, new NullProgressMonitor());
        } catch (CoreException e) {
            SVNUIPlugin.log(IStatus.ERROR, e.getMessage(), e);
            MessageDialog.openError(getShell(), Messages.ResolveTreeConflictWizard_deleteError, e.getMessage());
            return false;
        }
    }
    if (mainPage.getMarkResolved() || mainPage.refreshConflicts()) {
        try {
            if (mainPage.getMarkResolved()) {
                IResource[] resolvedResources = { treeConflict.getResource() };
                ResolveOperation resolveOperation = new ResolveOperation(targetPart, resolvedResources, ISVNConflictResolver.Choice.chooseMerged) {

                    protected boolean canRunAsJob() {
                        return false;
                    }
                };
                resolveOperation.run();
            }
            if (mainPage.refreshConflicts()) {
                IResource[] refreshResources = { svnResource.getResource() };
                TreeConflictsView.refresh(refreshResources);
            }
        } catch (Exception e) {
            SVNUIPlugin.log(IStatus.ERROR, e.getMessage(), e);
            MessageDialog.openError(getShell(), Messages.ResolveTreeConflictWizard_markResolvedError, e.getMessage());
            return false;
        }
    }
    return true;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) CompareAction(org.eclipse.compare.internal.CompareAction) IAction(org.eclipse.jface.action.IAction) Action(org.eclipse.jface.action.Action) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource) ShowDifferencesAsUnifiedDiffOperationWC(org.tigris.subversion.subclipse.ui.operations.ShowDifferencesAsUnifiedDiffOperationWC) RevertResourcesCommand(org.tigris.subversion.subclipse.core.commands.RevertResourcesCommand) ISelection(org.eclipse.jface.viewers.ISelection) ArrayList(java.util.ArrayList) List(java.util.List) SVNLocalCompareInput(org.tigris.subversion.subclipse.ui.compare.SVNLocalCompareInput) IAction(org.eclipse.jface.action.IAction) ResolveOperation(org.tigris.subversion.subclipse.ui.operations.ResolveOperation) SVNUrl(org.tigris.subversion.svnclientadapter.SVNUrl) ISVNRemoteResource(org.tigris.subversion.subclipse.core.ISVNRemoteResource) CompareAction(org.eclipse.compare.internal.CompareAction) CoreException(org.eclipse.core.runtime.CoreException) SVNException(org.tigris.subversion.subclipse.core.SVNException) SVNClientException(org.tigris.subversion.svnclientadapter.SVNClientException) CoreException(org.eclipse.core.runtime.CoreException) SVNRevision(org.tigris.subversion.svnclientadapter.SVNRevision) File(java.io.File) IResource(org.eclipse.core.resources.IResource)

Example 30 with SVNRevision

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

the class ResolveTreeConflictWizardMainPage method getRemoteResource.

private void getRemoteResource(ResolveTreeConflictWizard wizard, final SVNTreeConflict treeConflict) {
    ISVNRepositoryLocation repository = wizard.getSvnResource().getRepository();
    SVNRevision revision = new SVNRevision.Number(treeConflict.getConflictDescriptor().getSrcRightVersion().getPegRevision());
    try {
        SVNUrl url = new SVNUrl(treeConflict.getConflictDescriptor().getSrcRightVersion().getReposURL() + "/" + treeConflict.getConflictDescriptor().getSrcRightVersion().getPathInRepos());
        GetRemoteResourceCommand command = new GetRemoteResourceCommand(repository, url, revision);
        command.run(new NullProgressMonitor());
        remoteResource = command.getRemoteResource();
    } catch (Exception e) {
        SVNUIPlugin.log(IStatus.ERROR, e.getMessage(), e);
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ISVNRepositoryLocation(org.tigris.subversion.subclipse.core.ISVNRepositoryLocation) GetRemoteResourceCommand(org.tigris.subversion.subclipse.core.commands.GetRemoteResourceCommand) SVNUrl(org.tigris.subversion.svnclientadapter.SVNUrl) SVNRevision(org.tigris.subversion.svnclientadapter.SVNRevision) SVNException(org.tigris.subversion.subclipse.core.SVNException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

SVNRevision (org.tigris.subversion.svnclientadapter.SVNRevision)48 SVNUrl (org.tigris.subversion.svnclientadapter.SVNUrl)22 ISVNClientAdapter (org.tigris.subversion.svnclientadapter.ISVNClientAdapter)17 IResource (org.eclipse.core.resources.IResource)15 TeamException (org.eclipse.team.core.TeamException)15 SVNException (org.tigris.subversion.subclipse.core.SVNException)14 InvocationTargetException (java.lang.reflect.InvocationTargetException)12 ISVNRemoteResource (org.tigris.subversion.subclipse.core.ISVNRemoteResource)12 File (java.io.File)9 CoreException (org.eclipse.core.runtime.CoreException)9 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)9 ISVNLocalResource (org.tigris.subversion.subclipse.core.ISVNLocalResource)9 ArrayList (java.util.ArrayList)8 ISelection (org.eclipse.jface.viewers.ISelection)8 ILogEntry (org.tigris.subversion.subclipse.core.history.ILogEntry)8 PartInitException (org.eclipse.ui.PartInitException)7 ISVNRepositoryLocation (org.tigris.subversion.subclipse.core.ISVNRepositoryLocation)7 RemoteFile (org.tigris.subversion.subclipse.core.resources.RemoteFile)7 ParseException (java.text.ParseException)6 Action (org.eclipse.jface.action.Action)6