Search in sources :

Example 41 with ISVNLocalResource

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

the class SVNLocalCompareInput method prepareCompareInput.

/**
 * Runs the compare operation and returns the compare result.
 *
 * @throws InterruptedException
 */
protected ICompareInput prepareCompareInput(IProgressMonitor monitor) throws InterruptedException {
    initLabels();
    if (resource instanceof LocalFolder) {
        try {
            if (monitor == null) {
                monitor = new NullProgressMonitor();
            }
            // $NON-NLS-1$
            monitor.beginTask(Policy.bind("SVNCompareEditorInput.comparing"), 30);
            IProgressMonitor sub = new SubProgressMonitor(monitor, 30);
            // $NON-NLS-1$
            sub.beginTask(Policy.bind("SVNCompareEditorInput.comparing"), 100);
            Object[] result = new Object[] { null };
            ArrayList resourceSummaryNodeList = new ArrayList();
            ArrayList summaryEditionNodeList = new ArrayList();
            ISVNClientAdapter client = null;
            if (resources == null) {
                resources = new ISVNLocalResource[] { resource };
            }
            if (remoteFolders == null) {
                remoteFolders = new ISVNRemoteFolder[] { (ISVNRemoteFolder) remoteResource };
            }
            try {
                for (int i = 0; i < resources.length; i++) {
                    ISVNLocalResource resource = resources[i];
                    ISVNRemoteFolder remoteFolder = remoteFolders[i];
                    SVNDiffSummary[] diffSummary = null;
                    client = SVNProviderPlugin.getPlugin().getSVNClientManager().getSVNClient();
                    File file = new File(resource.getResource().getLocation().toString());
                    getUnadded(client, resource, file);
                    IResource[] unaddedResources = new IResource[unaddedList.size()];
                    unaddedList.toArray(unaddedResources);
                    SVNWorkspaceRoot workspaceRoot = new SVNWorkspaceRoot(resource.getResource().getProject());
                    AddResourcesCommand command = new AddResourcesCommand(workspaceRoot, unaddedResources, IResource.DEPTH_INFINITE);
                    command.run(monitor);
                    diffSummary = client.diffSummarize(file, remoteFolder.getUrl(), remoteFolder.getRevision(), true);
                    for (IResource unaddedResource : unaddedResources) {
                        try {
                            SVNWorkspaceRoot.getSVNResourceFor(unaddedResource).revert();
                        } catch (Exception e) {
                        }
                    }
                    SVNProviderPlugin.getPlugin().getSVNClientManager().returnSVNClient(client);
                    client = null;
                    if (diffSummary != null && diffSummary.length > 0) {
                        diffSummary = getDiffSummaryWithSubfolders(diffSummary);
                        ITypedElement left = new SVNLocalResourceSummaryNode(resource, diffSummary, resource.getResource().getLocation().toString());
                        SummaryEditionNode right = new SummaryEditionNode(remoteFolder);
                        right.setName(resource.getFile().getName());
                        right.setRootFolder((RemoteFolder) remoteFolder);
                        right.setNodeType(SummaryEditionNode.RIGHT);
                        right.setRoot(true);
                        right.setDiffSummary(diffSummary);
                        String localCharset = Utilities.getCharset(resource.getIResource());
                        try {
                            right.setCharset(localCharset);
                        } catch (CoreException e) {
                            SVNUIPlugin.log(IStatus.ERROR, e.getMessage(), e);
                        }
                        resourceSummaryNodeList.add(left);
                        summaryEditionNodeList.add(right);
                    }
                }
                if (resourceSummaryNodeList.size() == 0) {
                    result[0] = null;
                } else {
                    Object[] resourceSummaryNodes = new Object[resourceSummaryNodeList.size()];
                    resourceSummaryNodeList.toArray(resourceSummaryNodes);
                    Object[] summaryEditionNodes = new Object[summaryEditionNodeList.size()];
                    summaryEditionNodeList.toArray(summaryEditionNodes);
                    MultipleSelectionNode left = new MultipleSelectionNode(resourceSummaryNodes);
                    MultipleSelectionNode right = new MultipleSelectionNode(summaryEditionNodes);
                    result[0] = new SummaryDifferencer().findDifferences(false, monitor, null, null, left, right);
                    fRoot = result[0];
                }
            } finally {
                sub.done();
                if (client != null) {
                    SVNProviderPlugin.getPlugin().getSVNClientManager().returnSVNClient(client);
                }
            }
            if (result[0] instanceof DiffNode) {
                DiffNode diffNode = (DiffNode) result[0];
                if (!diffNode.hasChildren()) {
                    return null;
                }
            }
            return (ICompareInput) result[0];
        } catch (OperationCanceledException e) {
            throw new InterruptedException(e.getMessage());
        } catch (Exception e) {
            SVNUIPlugin.log(IStatus.ERROR, e.getMessage(), e);
            return null;
        } finally {
            monitor.done();
        }
    } else {
        ITypedElement left = new SVNLocalResourceNode(resource);
        ResourceEditionNode right = new ResourceEditionNode(remoteResource, pegRevision);
        if (left.getType() == ITypedElement.FOLDER_TYPE) {
            right.setLocalResource((SVNLocalResourceNode) left);
        }
        if (right.getType() == ITypedElement.FOLDER_TYPE) {
            ((SVNLocalResourceNode) left).setRemoteResource((ResourceEditionNode) right);
        }
        String localCharset = Utilities.getCharset(resource.getIResource());
        try {
            right.setCharset(localCharset);
        } catch (CoreException e) {
            SVNUIPlugin.log(IStatus.ERROR, e.getMessage(), e);
        }
        ICompareInput compareInput;
        if (SVNRevision.BASE.equals(remoteRevision)) {
            compareInput = (ICompareInput) new StatusAwareDifferencer().findDifferences(false, monitor, null, null, left, right);
        } else {
            compareInput = (ICompareInput) new RevisionAwareDifferencer((SVNLocalResourceNode) left, right, diffFile, pegRevision).findDifferences(false, monitor, null, null, left, right);
        }
        return compareInput;
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) SVNWorkspaceRoot(org.tigris.subversion.subclipse.core.resources.SVNWorkspaceRoot) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ArrayList(java.util.ArrayList) DiffNode(org.eclipse.compare.structuremergeviewer.DiffNode) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource) ISVNRemoteFolder(org.tigris.subversion.subclipse.core.ISVNRemoteFolder) AddResourcesCommand(org.tigris.subversion.subclipse.core.commands.AddResourcesCommand) ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter) ITypedElement(org.eclipse.compare.ITypedElement) ICompareInput(org.eclipse.compare.structuremergeviewer.ICompareInput) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) SVNException(org.tigris.subversion.subclipse.core.SVNException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) SVNClientException(org.tigris.subversion.svnclientadapter.SVNClientException) IOException(java.io.IOException) LocalFolder(org.tigris.subversion.subclipse.core.resources.LocalFolder) SVNDiffSummary(org.tigris.subversion.svnclientadapter.SVNDiffSummary) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) File(java.io.File) IResource(org.eclipse.core.resources.IResource)

Example 42 with ISVNLocalResource

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

the class SVNLocalCompareInput method getUnaddedResources.

private IResource[] getUnaddedResources(List resources) throws SVNException {
    final List unadded = new ArrayList();
    final SVNException[] exception = new SVNException[] { null };
    for (Iterator iter = resources.iterator(); iter.hasNext(); ) {
        IResource resource = (IResource) iter.next();
        if (resource.exists()) {
            // visit each resource deeply
            try {
                resource.accept(new IResourceVisitor() {

                    public boolean visit(IResource aResource) {
                        ISVNLocalResource svnResource = SVNWorkspaceRoot.getSVNResourceFor(aResource);
                        // skip ignored resources and their children
                        try {
                            if (svnResource.isIgnored())
                                return false;
                            // visit the children of shared resources
                            if (svnResource.isManaged())
                                return true;
                            if ((aResource.getType() == IResource.FOLDER) && // don't traverse into symlink folders
                            isSymLink(aResource))
                                return false;
                        } catch (SVNException e) {
                            exception[0] = e;
                        }
                        // file/folder is unshared so record it
                        unadded.add(aResource);
                        return aResource.getType() == IResource.FOLDER;
                    }
                }, IResource.DEPTH_INFINITE, false);
            } catch (CoreException e) {
                throw SVNException.wrapException(e);
            }
            if (exception[0] != null)
                throw exception[0];
        }
    }
    return (IResource[]) unadded.toArray(new IResource[unadded.size()]);
}
Also used : IResourceVisitor(org.eclipse.core.resources.IResourceVisitor) CoreException(org.eclipse.core.runtime.CoreException) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) SVNException(org.tigris.subversion.subclipse.core.SVNException) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource) IResource(org.eclipse.core.resources.IResource)

Example 43 with ISVNLocalResource

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

the class SVNLocalCompareInput method getUnadded.

private void getUnadded(ISVNClientAdapter client, ISVNLocalResource resource, File file) throws SVNClientException, SVNException {
    ISVNStatus[] statuses = client.getStatus(file, true, true);
    for (ISVNStatus status : statuses) {
        IResource currentResource = SVNWorkspaceRoot.getResourceFor(resource.getResource(), status);
        if (currentResource != null) {
            ISVNLocalResource localResource = SVNWorkspaceRoot.getSVNResourceFor(currentResource);
            if (!localResource.isIgnored()) {
                if (!SVNStatusUtils.isManaged(status)) {
                    if (!isSymLink(currentResource)) {
                        if (currentResource.getType() != IResource.FILE) {
                            unversionedFolders.add(currentResource);
                        } else {
                            if (addToUnadded(currentResource))
                                unaddedList.add(currentResource);
                        }
                    }
                }
            }
        }
    }
    IResource[] unaddedResources = getUnaddedResources(unversionedFolders);
    for (IResource unaddedResource : unaddedResources) {
        unaddedList.add(unaddedResource);
    }
}
Also used : ISVNStatus(org.tigris.subversion.svnclientadapter.ISVNStatus) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource) IResource(org.eclipse.core.resources.IResource)

Example 44 with ISVNLocalResource

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

the class SVNLocalCompareSummaryInput method prepareInput.

/**
 * Runs the compare operation and returns the compare result.
 */
protected Object prepareInput(IProgressMonitor monitor) throws InterruptedException {
    initLabels();
    try {
        // $NON-NLS-1$
        monitor.beginTask(Policy.bind("SVNCompareEditorInput.comparing"), 30);
        IProgressMonitor sub = new SubProgressMonitor(monitor, 30);
        // $NON-NLS-1$
        sub.beginTask(Policy.bind("SVNCompareEditorInput.comparing"), 100);
        Object[] result = new Object[] { null };
        ArrayList resourceSummaryNodeList = new ArrayList();
        ArrayList summaryEditionNodeList = new ArrayList();
        ISVNClientAdapter client = null;
        try {
            for (int i = 0; i < resources.length; i++) {
                ISVNLocalResource resource = resources[i];
                ISVNRemoteFolder remoteFolder = remoteFolders[i];
                SVNDiffSummary[] diffSummary = null;
                client = SVNProviderPlugin.getPlugin().getSVNClientManager().getSVNClient();
                diffSummary = client.diffSummarize(new File(resource.getResource().getLocation().toString()), remoteFolder.getUrl(), remoteFolder.getRevision(), true);
                SVNProviderPlugin.getPlugin().getSVNClientManager().returnSVNClient(client);
                client = null;
                if (diffSummary != null && diffSummary.length > 0) {
                    diffSummary = getDiffSummaryWithSubfolders(diffSummary);
                    ITypedElement left = new SVNLocalResourceSummaryNode(resource, diffSummary, resource.getResource().getLocation().toString());
                    SummaryEditionNode right = new SummaryEditionNode(remoteFolder);
                    right.setName(resource.getFile().getName());
                    right.setRootFolder((RemoteFolder) remoteFolder);
                    right.setNodeType(SummaryEditionNode.RIGHT);
                    right.setRoot(true);
                    right.setDiffSummary(diffSummary);
                    String localCharset = Utilities.getCharset(resource.getIResource());
                    try {
                        right.setCharset(localCharset);
                    } catch (CoreException e) {
                        SVNUIPlugin.log(IStatus.ERROR, e.getMessage(), e);
                    }
                    resourceSummaryNodeList.add(left);
                    summaryEditionNodeList.add(right);
                }
            }
            if (resourceSummaryNodeList.size() == 0) {
                result[0] = null;
            } else {
                Object[] resourceSummaryNodes = new Object[resourceSummaryNodeList.size()];
                resourceSummaryNodeList.toArray(resourceSummaryNodes);
                Object[] summaryEditionNodes = new Object[summaryEditionNodeList.size()];
                summaryEditionNodeList.toArray(summaryEditionNodes);
                MultipleSelectionNode left = new MultipleSelectionNode(resourceSummaryNodes);
                MultipleSelectionNode right = new MultipleSelectionNode(summaryEditionNodes);
                result[0] = new SummaryDifferencer().findDifferences(false, monitor, null, null, left, right);
                fRoot = result[0];
            }
        } finally {
            sub.done();
            if (client != null) {
                SVNProviderPlugin.getPlugin().getSVNClientManager().returnSVNClient(client);
            }
        }
        if (result[0] instanceof DiffNode) {
            DiffNode diffNode = (DiffNode) result[0];
            if (!diffNode.hasChildren()) {
                return null;
            }
        }
        return result[0];
    } catch (OperationCanceledException e) {
        throw new InterruptedException(e.getMessage());
    } catch (Exception e) {
        return e.getMessage();
    } finally {
        monitor.done();
    }
}
Also used : OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ArrayList(java.util.ArrayList) DiffNode(org.eclipse.compare.structuremergeviewer.DiffNode) ITypedElement(org.eclipse.compare.ITypedElement) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource) ISVNRemoteFolder(org.tigris.subversion.subclipse.core.ISVNRemoteFolder) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) SVNException(org.tigris.subversion.subclipse.core.SVNException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) SVNDiffSummary(org.tigris.subversion.svnclientadapter.SVNDiffSummary) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IFile(org.eclipse.core.resources.IFile) File(java.io.File) ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter)

Example 45 with ISVNLocalResource

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

the class MergeResultsView method editConflicts.

private void editConflicts(MergeResult mergeResult) {
    IFile resource = (IFile) mergeResult.getResource();
    ISVNLocalResource svnResource = SVNWorkspaceRoot.getSVNResourceFor(resource);
    try {
        File conflictNewFile = svnResource.getStatus().getConflictNew();
        File conflictOldFile = svnResource.getStatus().getConflictOld();
        File conflictWorkingFile = svnResource.getStatus().getConflictWorking();
        File mergedFile = new File(resource.getLocation().toString());
        if (conflictWorkingFile == null) {
            EditConflictsAction editConflictsAction = new EditConflictsAction(resource);
            editConflictsAction.run(null);
        } else {
            MergeEditConflictsAction editConflictsAction = new MergeEditConflictsAction(conflictNewFile, conflictOldFile, conflictWorkingFile, mergedFile, resource.getName(), null);
            editConflictsAction.setMergeResult(mergeResult);
            editConflictsAction.run(null);
        }
    } catch (Exception e) {
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) MergeEditConflictsAction(com.collabnet.subversion.merge.actions.MergeEditConflictsAction) EditConflictsAction(org.tigris.subversion.subclipse.ui.actions.EditConflictsAction) MergeEditConflictsAction(com.collabnet.subversion.merge.actions.MergeEditConflictsAction) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource) RemoteFile(org.tigris.subversion.subclipse.core.resources.RemoteFile) ISVNRemoteFile(org.tigris.subversion.subclipse.core.ISVNRemoteFile) IFile(org.eclipse.core.resources.IFile) File(java.io.File) SVNException(org.tigris.subversion.subclipse.core.SVNException) SVNClientException(org.tigris.subversion.svnclientadapter.SVNClientException)

Aggregations

ISVNLocalResource (org.tigris.subversion.subclipse.core.ISVNLocalResource)120 IResource (org.eclipse.core.resources.IResource)77 SVNException (org.tigris.subversion.subclipse.core.SVNException)76 ArrayList (java.util.ArrayList)39 CoreException (org.eclipse.core.runtime.CoreException)24 Iterator (java.util.Iterator)20 IFile (org.eclipse.core.resources.IFile)20 ISVNClientAdapter (org.tigris.subversion.svnclientadapter.ISVNClientAdapter)20 InvocationTargetException (java.lang.reflect.InvocationTargetException)18 List (java.util.List)18 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)18 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)17 LocalResourceStatus (org.tigris.subversion.subclipse.core.resources.LocalResourceStatus)17 SVNClientException (org.tigris.subversion.svnclientadapter.SVNClientException)17 File (java.io.File)16 TeamException (org.eclipse.team.core.TeamException)16 ISVNRepositoryLocation (org.tigris.subversion.subclipse.core.ISVNRepositoryLocation)15 ISynchronizeModelElement (org.eclipse.team.ui.synchronize.ISynchronizeModelElement)14 IContainer (org.eclipse.core.resources.IContainer)13 SyncInfo (org.eclipse.team.core.synchronize.SyncInfo)11