Search in sources :

Example 1 with ShowDifferencesAsUnifiedDiffOperationWC

use of org.tigris.subversion.subclipse.ui.operations.ShowDifferencesAsUnifiedDiffOperationWC in project subclipse by subclipse.

the class ShowDifferencesAsUnifiedDiffDialogWC method okPressed.

protected void okPressed() {
    success = true;
    BusyIndicator.showWhile(Display.getCurrent(), new Runnable() {

        public void run() {
            ISVNRepositoryLocation repository = null;
            ISVNClientAdapter svnClient = null;
            try {
                if (toHeadButton.getSelection())
                    toRevision = SVNRevision.HEAD;
                else {
                    int toRevisionInt = Integer.parseInt(toRevisionText.getText().trim());
                    long toRevisionLong = toRevisionInt;
                    toRevision = new SVNRevision.Number(toRevisionLong);
                }
                toUrl = new SVNUrl(toUrlText.getText().trim());
                File path = new File(resource.getLocation().toString());
                svnResource = SVNWorkspaceRoot.getSVNResourceFor(resource);
                pegRevision = null;
                if (toUrlText.getText().equals(selectedResourceUrl)) {
                    ISVNRemoteResource baseResource = svnResource.getBaseResource();
                    if (baseResource != null) {
                        pegRevision = baseResource.getLastChangedRevision();
                    }
                }
                if (pegRevision == null) {
                    pegRevision = toRevision;
                }
                repository = svnResource.getRepository();
                svnClient = repository.getSVNClient();
                ISVNInfo svnInfo = svnClient.getInfo(toUrl, toRevision, pegRevision);
                SVNNodeKind nodeKind = svnInfo.getNodeKind();
                if (resource instanceof IContainer) {
                    if (nodeKind.toInt() == SVNNodeKind.FILE.toInt()) {
                        MessageDialog.openError(getShell(), Policy.bind("ShowDifferencesAsUnifiedDiffDialog.branchTag"), Policy.bind("ShowDifferencesAsUnifiedDiffDialog.fileToFolder"));
                        success = false;
                        return;
                    }
                } else {
                    if (nodeKind.toInt() == SVNNodeKind.DIR.toInt()) {
                        MessageDialog.openError(getShell(), Policy.bind("ShowDifferencesAsUnifiedDiffDialog.branchTag"), Policy.bind("ShowDifferencesAsUnifiedDiffDialog.fileToFolder"));
                        success = false;
                        return;
                    }
                }
                if (diffButton.getSelection()) {
                    diffToOutputFile = true;
                    file = new File(fileText.getText().trim());
                    if (file.exists()) {
                        if (!MessageDialog.openQuestion(getShell(), Policy.bind("HistoryView.showDifferences"), Policy.bind("HistoryView.overwriteOutfile", file.getName())))
                            return;
                    }
                    operation = new ShowDifferencesAsUnifiedDiffOperationWC(targetPart, path, toUrl, toRevision, file);
                    operation.setGraphicalCompare(true);
                } else {
                    diffToOutputFile = false;
                    success = true;
                }
            } catch (Exception e) {
                MessageDialog.openError(getShell(), Policy.bind("HistoryView.showDifferences"), e.getMessage());
                success = false;
            } finally {
                if (repository != null) {
                    repository.returnSVNClient(svnClient);
                }
            }
        }
    });
    if (!success)
        return;
    toUrlText.saveUrl();
    super.okPressed();
}
Also used : ISVNRepositoryLocation(org.tigris.subversion.subclipse.core.ISVNRepositoryLocation) SVNNodeKind(org.tigris.subversion.svnclientadapter.SVNNodeKind) ShowDifferencesAsUnifiedDiffOperationWC(org.tigris.subversion.subclipse.ui.operations.ShowDifferencesAsUnifiedDiffOperationWC) SVNUrl(org.tigris.subversion.svnclientadapter.SVNUrl) ISVNInfo(org.tigris.subversion.svnclientadapter.ISVNInfo) ISVNRemoteResource(org.tigris.subversion.subclipse.core.ISVNRemoteResource) IContainer(org.eclipse.core.resources.IContainer) File(java.io.File) ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter)

Example 2 with ShowDifferencesAsUnifiedDiffOperationWC

use of org.tigris.subversion.subclipse.ui.operations.ShowDifferencesAsUnifiedDiffOperationWC in project subclipse by subclipse.

the class SVNLocalBranchTagCompareInput method prepareInput.

protected Object prepareInput(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
    initLabels();
    File[] diffFiles = new File[localResourceNodes.length];
    try {
        for (int i = 0; i < localResourceNodes.length; i++) {
            File file = File.createTempFile("revision", ".diff");
            file.deleteOnExit();
            final ShowDifferencesAsUnifiedDiffOperationWC operation = new ShowDifferencesAsUnifiedDiffOperationWC(targetPart, localResourceNodes[i].getLocalResource().getFile(), remoteResourceNodes[i].getRemoteResource().getUrl(), remoteRevision, file);
            operation.setGraphicalCompare(true);
            Display.getDefault().syncExec(new Runnable() {

                public void run() {
                    try {
                        operation.run();
                    } catch (Exception e) {
                    }
                }
            });
            diffFiles[i] = operation.getFile();
        }
    } catch (Exception e) {
    }
    MultipleSelectionNode left = new MultipleSelectionNode(localResourceNodes);
    MultipleSelectionNode right = new MultipleSelectionNode(remoteResourceNodes);
    Object differences = new RevisionAwareDifferencer(diffFiles).findDifferences(false, monitor, null, null, left, right);
    if (differences instanceof DiffNode) {
        DiffNode diffNode = (DiffNode) differences;
        if (!diffNode.hasChildren()) {
            return null;
        }
    }
    return differences;
}
Also used : ShowDifferencesAsUnifiedDiffOperationWC(org.tigris.subversion.subclipse.ui.operations.ShowDifferencesAsUnifiedDiffOperationWC) DiffNode(org.eclipse.compare.structuremergeviewer.DiffNode) File(java.io.File) RemoteFile(org.tigris.subversion.subclipse.core.resources.RemoteFile) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SVNException(org.tigris.subversion.subclipse.core.SVNException)

Example 3 with ShowDifferencesAsUnifiedDiffOperationWC

use of org.tigris.subversion.subclipse.ui.operations.ShowDifferencesAsUnifiedDiffOperationWC in project subclipse by subclipse.

the class CompareWithRemoteAction method execute.

public void execute(IAction action) {
    refresh = false;
    fileSelected = false;
    final IResource[] resources = getSelectedResources();
    if (resources.length != 1 && !SVNRevision.BASE.equals(revision) && !SVNRevision.HEAD.equals(revision)) {
        return;
    }
    for (int i = 0; i < resources.length; i++) {
        if (resources[i] instanceof IFile) {
            fileSelected = true;
            if (!resources[i].isSynchronized(Depth.immediates)) {
                refresh = MessageDialog.openQuestion(getShell(), Policy.bind("DifferencesDialog.compare"), Policy.bind("CompareWithRemoteAction.fileChanged"));
                break;
            }
        }
    }
    try {
        final ISVNLocalResource[] localResources = new ISVNLocalResource[resources.length];
        for (int i = 0; i < resources.length; i++) {
            localResources[i] = SVNWorkspaceRoot.getSVNResourceFor(resources[i]);
        }
        final ISVNLocalResource localResource = localResources[0];
        run(new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) {
                try {
                    if (refresh) {
                        for (int i = 0; i < localResources.length; i++) {
                            if (resources[i] instanceof IFile) {
                                localResources[i].getResource().refreshLocal(Depth.immediates, monitor);
                            }
                        }
                    }
                    if (SVNRevision.BASE.equals(revision)) {
                        if (localResources.length == 1 && localResource.getResource() instanceof IFile) {
                            SVNLocalCompareInput compareInput = new SVNLocalCompareInput(localResource, revision);
                            CompareUI.openCompareEditorOnPage(compareInput, getTargetPage());
                        } else {
                            SVNLocalBaseCompareInput compareInput = new SVNLocalBaseCompareInput(localResources, revision);
                            CompareUI.openCompareEditorOnPage(compareInput, getTargetPage());
                        }
                    } else {
                        if (!fileSelected) {
                            SVNLocalCompareSummaryInput compareInput = new SVNLocalCompareSummaryInput(localResources, revision);
                            CompareUI.openCompareEditorOnPage(compareInput, getTargetPage());
                        } else {
                            ISVNRemoteFile remoteFile = new RemoteFile(localResource.getRepository(), localResource.getUrl(), revision);
                            ((RemoteFile) remoteFile).setPegRevision(revision);
                            SVNLocalCompareInput compareInput = new SVNLocalCompareInput(localResource, remoteFile);
                            ShowDifferencesAsUnifiedDiffOperationWC operation = null;
                            if (SVNRevision.HEAD.equals(revision)) {
                                File file = File.createTempFile("revision", ".diff");
                                file.deleteOnExit();
                                operation = new ShowDifferencesAsUnifiedDiffOperationWC(getTargetPart(), localResource.getFile(), localResource.getUrl(), SVNRevision.HEAD, file);
                                operation.setGraphicalCompare(true);
                                operation.run();
                            }
                            compareInput.setDiffOperation(operation);
                            CompareUI.openCompareEditorOnPage(compareInput, getTargetPage());
                        }
                    }
                } catch (Exception e) {
                    handle(e, null, null);
                }
            }
        }, false, /* cancelable */
        PROGRESS_BUSYCURSOR);
    } catch (Exception e) {
        handle(e, null, null);
    }
}
Also used : SVNLocalCompareInput(org.tigris.subversion.subclipse.ui.compare.SVNLocalCompareInput) IFile(org.eclipse.core.resources.IFile) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource) SVNException(org.tigris.subversion.subclipse.core.SVNException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ShowDifferencesAsUnifiedDiffOperationWC(org.tigris.subversion.subclipse.ui.operations.ShowDifferencesAsUnifiedDiffOperationWC) ISVNRemoteFile(org.tigris.subversion.subclipse.core.ISVNRemoteFile) SVNLocalBaseCompareInput(org.tigris.subversion.subclipse.ui.compare.SVNLocalBaseCompareInput) SVNLocalCompareSummaryInput(org.tigris.subversion.subclipse.ui.compare.SVNLocalCompareSummaryInput) ISVNRemoteFile(org.tigris.subversion.subclipse.core.ISVNRemoteFile) File(java.io.File) RemoteFile(org.tigris.subversion.subclipse.core.resources.RemoteFile) IFile(org.eclipse.core.resources.IFile) IResource(org.eclipse.core.resources.IResource) ISVNRemoteFile(org.tigris.subversion.subclipse.core.ISVNRemoteFile) RemoteFile(org.tigris.subversion.subclipse.core.resources.RemoteFile)

Example 4 with ShowDifferencesAsUnifiedDiffOperationWC

use of org.tigris.subversion.subclipse.ui.operations.ShowDifferencesAsUnifiedDiffOperationWC 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)

Aggregations

File (java.io.File)4 ShowDifferencesAsUnifiedDiffOperationWC (org.tigris.subversion.subclipse.ui.operations.ShowDifferencesAsUnifiedDiffOperationWC)4 SVNException (org.tigris.subversion.subclipse.core.SVNException)3 IResource (org.eclipse.core.resources.IResource)2 CoreException (org.eclipse.core.runtime.CoreException)2 ISVNLocalResource (org.tigris.subversion.subclipse.core.ISVNLocalResource)2 ISVNRemoteResource (org.tigris.subversion.subclipse.core.ISVNRemoteResource)2 RemoteFile (org.tigris.subversion.subclipse.core.resources.RemoteFile)2 SVNLocalCompareInput (org.tigris.subversion.subclipse.ui.compare.SVNLocalCompareInput)2 SVNUrl (org.tigris.subversion.svnclientadapter.SVNUrl)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 CompareAction (org.eclipse.compare.internal.CompareAction)1 DiffNode (org.eclipse.compare.structuremergeviewer.DiffNode)1 IContainer (org.eclipse.core.resources.IContainer)1 IFile (org.eclipse.core.resources.IFile)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 Action (org.eclipse.jface.action.Action)1