Search in sources :

Example 1 with SVNDiffSummary

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

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

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

the class SVNFolderCompareEditorInput method prepareInput.

protected Object prepareInput(IProgressMonitor monitor) throws InterruptedException {
    final boolean threeWay = ancestor != null;
    if (right == null || left == null) {
        // $NON-NLS-1$
        setMessage(Policy.bind("SVNCompareEditorInput.different"));
        return null;
    }
    initLabels();
    final Object[] result = new Object[] { null };
    ISVNClientAdapter svnClient = null;
    try {
        // do the diff
        // $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);
        try {
            svnClient = folder1.getRepository().getSVNClient();
            SVNDiffSummary[] diffSummary = null;
            if (folder1.getRepositoryRelativePath().equals(folder2.getRepositoryRelativePath()) && localResource1 != null) {
                IResource resource1 = localResource1.getResource();
                if (resource1 != null) {
                    ISVNLocalResource svnResource1 = SVNWorkspaceRoot.getSVNResourceFor(resource1);
                    if (svnResource1 != null) {
                        SVNRevision pegRevision = svnResource1.getRevision();
                        if (pegRevision != null) {
                            diffSummary = svnClient.diffSummarize(folder1.getUrl(), pegRevision, folder2.getRevision(), folder1.getRevision(), Depth.infinity, true);
                        }
                    }
                } else {
                    diffSummary = svnClient.diffSummarize(folder1.getUrl(), SVNRevision.HEAD, folder2.getRevision(), folder1.getRevision(), Depth.infinity, true);
                }
            }
            if (diffSummary == null)
                diffSummary = svnClient.diffSummarize(folder1.getUrl(), folder1.getRevision(), folder2.getUrl(), folder2.getRevision(), Depth.infinity, true);
            diffSummary = getDiffSummaryWithSubfolders(diffSummary);
            left.setDiffSummary(diffSummary);
            right.setDiffSummary(diffSummary);
            left.setRoot(true);
            right.setRoot(true);
            result[0] = new SummaryDifferencer().findDifferences(threeWay, sub, null, ancestor, left, right);
        } finally {
            sub.done();
        }
        if (result[0] instanceof DiffNode) {
            IDiffElement[] diffs = ((DiffNode) result[0]).getChildren();
            if (diffs == null || diffs.length == 0) {
                result[0] = null;
            }
        }
        return result[0];
    } catch (OperationCanceledException e) {
        throw new InterruptedException(e.getMessage());
    } catch (Exception e) {
        return e.getMessage();
    } finally {
        folder1.getRepository().returnSVNClient(svnClient);
        monitor.done();
    }
}
Also used : OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) DiffNode(org.eclipse.compare.structuremergeviewer.DiffNode) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IDiffElement(org.eclipse.compare.structuremergeviewer.IDiffElement) SVNDiffSummary(org.tigris.subversion.svnclientadapter.SVNDiffSummary) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) SVNRevision(org.tigris.subversion.svnclientadapter.SVNRevision) IResource(org.eclipse.core.resources.IResource) ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter)

Example 4 with SVNDiffSummary

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

the class SVNFolderCompareEditorInput method getDiffSummaryWithSubfolders.

private SVNDiffSummary[] getDiffSummaryWithSubfolders(SVNDiffSummary[] diffSummary) {
    ArrayList paths = new ArrayList();
    ArrayList diffs = new ArrayList();
    for (int i = 0; i < diffSummary.length; i++) {
        paths.add(diffSummary[i].getPath());
        diffs.add(diffSummary[i]);
    }
    for (int i = 0; i < diffSummary.length; i++) {
        File file = new File(diffSummary[i].getPath());
        while (file.getParentFile() != null) {
            file = file.getParentFile();
            String path = file.getPath();
            path = path.replaceAll("\\\\", "/");
            if (!paths.contains(path)) {
                paths.add(path);
                SVNDiffSummary folder = new SVNDiffSummary(path, SVNDiffKind.NORMAL, false, SVNNodeKind.DIR.toInt());
                diffs.add(folder);
            }
        }
    }
    diffSummary = new SVNDiffSummary[diffs.size()];
    diffs.toArray(diffSummary);
    return diffSummary;
}
Also used : SVNDiffSummary(org.tigris.subversion.svnclientadapter.SVNDiffSummary) ArrayList(java.util.ArrayList) File(java.io.File)

Example 5 with SVNDiffSummary

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

the class SVNLocalCompareInput method getDiffSummaryWithSubfolders.

private SVNDiffSummary[] getDiffSummaryWithSubfolders(SVNDiffSummary[] diffSummary) {
    ArrayList paths = new ArrayList();
    ArrayList diffs = new ArrayList();
    String rootPath = resource == null ? null : resource.getIResource().getProjectRelativePath().toString() + "/";
    for (int i = 0; i < diffSummary.length; i++) {
        if (rootPath != null && diffSummary[i].getPath().startsWith(rootPath)) {
            diffSummary[i] = new SVNDiffSummary(diffSummary[i].getPath().substring(rootPath.length()), SVNDiffKind.NORMAL, false, diffSummary[i].getNodeKind());
        }
        paths.add(diffSummary[i].getPath());
        diffs.add(diffSummary[i]);
    }
    for (int i = 0; i < diffSummary.length; i++) {
        File file = new File(diffSummary[i].getPath());
        while (file.getParentFile() != null) {
            file = file.getParentFile();
            String path = file.getPath();
            // $NON-NLS-1$ //$NON-NLS-2$
            path = path.replaceAll("\\\\", "/");
            if (!paths.contains(path)) {
                paths.add(path);
                SVNDiffSummary folder = new SVNDiffSummary(path, SVNDiffKind.NORMAL, false, SVNNodeKind.DIR.toInt());
                diffs.add(folder);
            }
        }
    }
    diffSummary = new SVNDiffSummary[diffs.size()];
    diffs.toArray(diffSummary);
    return diffSummary;
}
Also used : SVNDiffSummary(org.tigris.subversion.svnclientadapter.SVNDiffSummary) ArrayList(java.util.ArrayList) File(java.io.File)

Aggregations

SVNDiffSummary (org.tigris.subversion.svnclientadapter.SVNDiffSummary)7 ArrayList (java.util.ArrayList)6 File (java.io.File)5 ISVNLocalResource (org.tigris.subversion.subclipse.core.ISVNLocalResource)4 DiffNode (org.eclipse.compare.structuremergeviewer.DiffNode)3 IFile (org.eclipse.core.resources.IFile)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)3 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)3 SVNException (org.tigris.subversion.subclipse.core.SVNException)3 ISVNClientAdapter (org.tigris.subversion.svnclientadapter.ISVNClientAdapter)3 ITypedElement (org.eclipse.compare.ITypedElement)2 IResource (org.eclipse.core.resources.IResource)2 CoreException (org.eclipse.core.runtime.CoreException)2 ISVNRemoteFolder (org.tigris.subversion.subclipse.core.ISVNRemoteFolder)2 IOException (java.io.IOException)1 List (java.util.List)1 ICompareInput (org.eclipse.compare.structuremergeviewer.ICompareInput)1 IDiffElement (org.eclipse.compare.structuremergeviewer.IDiffElement)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1