Search in sources :

Example 46 with SVNUrl

use of org.tigris.subversion.svnclientadapter.SVNUrl 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 47 with SVNUrl

use of org.tigris.subversion.svnclientadapter.SVNUrl 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)

Example 48 with SVNUrl

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

the class SummaryEditionNode method getRoots.

private SummaryEditionNode[] getRoots() throws Exception {
    List<String> rootPaths = new ArrayList<String>();
    ArrayList roots = new ArrayList();
    for (int i = 0; i < diffSummary.length; i++) {
        if (include(diffSummary[i])) {
            File file = new File(diffSummary[i].getPath());
            if (file.getParent() == null) {
                if (diffSummary[i].getNodeKind() == SVNNodeKind.DIR.toInt()) {
                    RemoteFolder remoteFolder = null;
                    if (resource.getRevision() instanceof SVNRevision.Number)
                        remoteFolder = new RemoteFolder(null, resource.getRepository(), new SVNUrl(resource.getUrl().toString() + "/" + diffSummary[i].getPath()), resource.getRevision(), (SVNRevision.Number) resource.getRevision(), null, null);
                    else
                        remoteFolder = new RemoteFolder(resource.getRepository(), new SVNUrl(resource.getUrl().toString() + "/" + diffSummary[i].getPath()), resource.getRevision());
                    remoteFolder.setPegRevision(pegRevision);
                    SummaryEditionNode node = new SummaryEditionNode(remoteFolder, pegRevision);
                    node.setDiffSummary(diffSummary);
                    node.setRootFolder((RemoteFolder) resource);
                    node.setNodeType(nodeType);
                    roots.add(node);
                } else {
                    RemoteFile remoteFile = null;
                    if (resource.getRevision() instanceof SVNRevision.Number)
                        remoteFile = new RemoteFile(null, resource.getRepository(), new SVNUrl(resource.getUrl().toString() + "/" + diffSummary[i].getPath()), resource.getRevision(), (SVNRevision.Number) resource.getRevision(), null, null);
                    else
                        remoteFile = new RemoteFile(resource.getRepository(), new SVNUrl(resource.getUrl().toString() + "/" + diffSummary[i].getPath()), resource.getRevision());
                    remoteFile.setPegRevision(pegRevision);
                    SummaryEditionNode node = new SummaryEditionNode(remoteFile, pegRevision);
                    node.setDiffSummary(diffSummary);
                    node.setRootFolder((RemoteFolder) resource);
                    node.setNodeType(nodeType);
                    roots.add(node);
                }
            } else {
                while (file.getParent() != null) {
                    file = file.getParentFile();
                }
                String path = file.getPath();
                if (!rootPaths.contains(path)) {
                    rootPaths.add(path);
                    RemoteFolder remoteFolder = null;
                    if (resource.getRevision() instanceof SVNRevision.Number)
                        remoteFolder = new RemoteFolder(null, resource.getRepository(), new SVNUrl(resource.getUrl().toString() + "/" + path), resource.getRevision(), (SVNRevision.Number) resource.getRevision(), null, null);
                    else
                        remoteFolder = new RemoteFolder(resource.getRepository(), new SVNUrl(resource.getUrl().toString() + "/" + path), resource.getRevision());
                    SummaryEditionNode node = new SummaryEditionNode(remoteFolder, pegRevision);
                    node.setDiffSummary(diffSummary);
                    node.setRootFolder((RemoteFolder) resource);
                    node.setNodeType(nodeType);
                    roots.add(node);
                }
            }
        }
    }
    SummaryEditionNode[] rootArray = new SummaryEditionNode[roots.size()];
    roots.toArray(rootArray);
    Arrays.sort(rootArray);
    return rootArray;
}
Also used : RemoteFolder(org.tigris.subversion.subclipse.core.resources.RemoteFolder) SVNUrl(org.tigris.subversion.svnclientadapter.SVNUrl) ArrayList(java.util.ArrayList) SVNRevision(org.tigris.subversion.svnclientadapter.SVNRevision) File(java.io.File) RemoteFile(org.tigris.subversion.subclipse.core.resources.RemoteFile) RemoteFile(org.tigris.subversion.subclipse.core.resources.RemoteFile)

Example 49 with SVNUrl

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

the class SummaryEditionNode method getChildNodes.

private SummaryEditionNode[] getChildNodes() throws Exception {
    ArrayList childNodes = new ArrayList();
    for (int i = 0; i < diffSummary.length; i++) {
        if (include(diffSummary[i])) {
            if (diffSummary[i].getNodeKind() == SVNNodeKind.DIR.toInt()) {
                RemoteFolder remoteFolder = null;
                if (resource.getRevision() instanceof SVNRevision.Number)
                    remoteFolder = new RemoteFolder(null, resource.getRepository(), new SVNUrl(rootFolder.getUrl().toString() + "/" + diffSummary[i].getPath()), resource.getRevision(), (SVNRevision.Number) resource.getRevision(), null, null);
                else
                    remoteFolder = new RemoteFolder(resource.getRepository(), new SVNUrl(rootFolder.getUrl().toString() + "/" + diffSummary[i].getPath()), resource.getRevision());
                remoteFolder.setPegRevision(pegRevision);
                if (isChild(remoteFolder)) {
                    SummaryEditionNode node = new SummaryEditionNode(remoteFolder, pegRevision);
                    node.setDiffSummary(diffSummary);
                    node.setRootFolder(rootFolder);
                    node.setNodeType(nodeType);
                    childNodes.add(node);
                }
            } else {
                RemoteFile remoteFile = null;
                if (resource.getRevision() instanceof SVNRevision.Number)
                    remoteFile = new RemoteFile(null, resource.getRepository(), new SVNUrl(rootFolder.getUrl().toString() + "/" + diffSummary[i].getPath()), resource.getRevision(), (SVNRevision.Number) resource.getRevision(), null, null);
                else
                    remoteFile = new RemoteFile(resource.getRepository(), new SVNUrl(rootFolder.getUrl().toString() + "/" + diffSummary[i].getPath()), resource.getRevision());
                remoteFile.setPegRevision(pegRevision);
                if (isChild(remoteFile)) {
                    SummaryEditionNode node = new SummaryEditionNode(remoteFile, pegRevision);
                    node.setDiffSummary(diffSummary);
                    node.setRootFolder(rootFolder);
                    node.setNodeType(nodeType);
                    childNodes.add(node);
                }
            }
        }
    }
    SummaryEditionNode[] childNodeArray = new SummaryEditionNode[childNodes.size()];
    childNodes.toArray(childNodeArray);
    Arrays.sort(childNodeArray);
    return childNodeArray;
}
Also used : RemoteFolder(org.tigris.subversion.subclipse.core.resources.RemoteFolder) SVNUrl(org.tigris.subversion.svnclientadapter.SVNUrl) ArrayList(java.util.ArrayList) SVNRevision(org.tigris.subversion.svnclientadapter.SVNRevision) RemoteFile(org.tigris.subversion.subclipse.core.resources.RemoteFile)

Example 50 with SVNUrl

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

the class SvnWizardSwitchPage method showLog.

protected void showLog() {
    ISVNRemoteResource remoteResource = null;
    try {
        remoteResource = SVNWorkspaceRoot.getSVNResourceFor(resources[0]).getRepository().getRemoteFile(new SVNUrl(urlCombo.getText()));
    } catch (Exception e) {
        MessageDialog.openError(getShell(), Policy.bind("MergeDialog.showLog"), // $NON-NLS-1$
        e.toString());
        return;
    }
    if (remoteResource == null) {
        MessageDialog.openError(getShell(), Policy.bind("MergeDialog.showLog"), Policy.bind("MergeDialog.urlError") + " " + // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        urlCombo.getText());
        return;
    }
    HistoryDialog dialog = new HistoryDialog(getShell(), remoteResource);
    if (dialog.open() == HistoryDialog.CANCEL)
        return;
    ILogEntry[] selectedEntries = dialog.getSelectedLogEntries();
    if (selectedEntries.length == 0)
        return;
    revisionText.setText(Long.toString(selectedEntries[selectedEntries.length - 1].getRevision().getNumber()));
    setPageComplete(canFinish());
}
Also used : HistoryDialog(org.tigris.subversion.subclipse.ui.dialogs.HistoryDialog) ILogEntry(org.tigris.subversion.subclipse.core.history.ILogEntry) SVNUrl(org.tigris.subversion.svnclientadapter.SVNUrl) ISVNRemoteResource(org.tigris.subversion.subclipse.core.ISVNRemoteResource) SVNException(org.tigris.subversion.subclipse.core.SVNException) ParseException(java.text.ParseException) MalformedURLException(java.net.MalformedURLException)

Aggregations

SVNUrl (org.tigris.subversion.svnclientadapter.SVNUrl)83 SVNException (org.tigris.subversion.subclipse.core.SVNException)29 SVNRevision (org.tigris.subversion.svnclientadapter.SVNRevision)26 MalformedURLException (java.net.MalformedURLException)25 ISVNRemoteResource (org.tigris.subversion.subclipse.core.ISVNRemoteResource)21 ISVNClientAdapter (org.tigris.subversion.svnclientadapter.ISVNClientAdapter)19 ParseException (java.text.ParseException)18 ILogEntry (org.tigris.subversion.subclipse.core.history.ILogEntry)17 IResource (org.eclipse.core.resources.IResource)16 InvocationTargetException (java.lang.reflect.InvocationTargetException)14 ISVNRepositoryLocation (org.tigris.subversion.subclipse.core.ISVNRepositoryLocation)14 TeamException (org.eclipse.team.core.TeamException)13 SVNClientException (org.tigris.subversion.svnclientadapter.SVNClientException)13 ArrayList (java.util.ArrayList)12 ISVNInfo (org.tigris.subversion.svnclientadapter.ISVNInfo)12 File (java.io.File)11 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)10 RemoteFile (org.tigris.subversion.subclipse.core.resources.RemoteFile)10 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)8 RemoteFolder (org.tigris.subversion.subclipse.core.resources.RemoteFolder)8