Search in sources :

Example 71 with ISVNLocalResource

use of org.tigris.subversion.subclipse.core.ISVNLocalResource 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 72 with ISVNLocalResource

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

the class SVNLocalCompareSummaryInput method getDiffSummary.

private SVNDiffSummary[] getDiffSummary(RemoteResourceStatus[] statuses, ISVNLocalResource resource) {
    List diffSummaryList = new ArrayList();
    int rootPathLength = resource.getResource().getLocation().toString().length() + 1;
    for (int i = 0; i < statuses.length; i++) {
        if (statuses[i].getFile() != null && !statuses[i].getNodeKind().equals(SVNNodeKind.DIR)) {
            SVNStatusKind textStatus = statuses[i].getTextStatus();
            boolean propertyChanges = !statuses[i].getPropStatus().equals(SVNStatusKind.NORMAL) && !statuses[i].getPropStatus().equals(SVNStatusKind.NONE);
            boolean localChanges = false;
            if (textStatus.equals(SVNStatusKind.NONE) && propertyChanges && statuses[i].getNodeKind().equals(SVNNodeKind.FILE)) {
                IFile file = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(new Path(statuses[i].getPath()));
                if (file != null) {
                    ISVNLocalResource svnResource = SVNWorkspaceRoot.getSVNResourceFor(file);
                    try {
                        LocalResourceStatus localStatus = svnResource.getStatus();
                        if (localStatus != null) {
                            localChanges = localStatus.isAdded() || localStatus.isDirty();
                        }
                    } catch (SVNException e) {
                    }
                }
            }
            if (!textStatus.equals(SVNStatusKind.NONE) || !propertyChanges || localChanges) {
                SVNDiffKind diffKind = null;
                if (statuses[i].getTextStatus().equals(SVNStatusKind.ADDED))
                    diffKind = SVNDiffKind.ADDED;
                else if (statuses[i].getTextStatus().equals(SVNStatusKind.DELETED))
                    diffKind = SVNDiffKind.DELETED;
                else
                    diffKind = SVNDiffKind.MODIFIED;
                SVNDiffSummary diffSummary = new SVNDiffSummary(statuses[i].getPath().substring(rootPathLength).replaceAll("\\\\", "/"), diffKind, propertyChanges, // $NON-NLS-1$ //$NON-NLS-2$
                statuses[i].getNodeKind().toInt());
                diffSummaryList.add(diffSummary);
            }
        }
    }
    SVNDiffSummary[] diffSummaries = new SVNDiffSummary[diffSummaryList.size()];
    diffSummaryList.toArray(diffSummaries);
    return diffSummaries;
}
Also used : Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) SVNException(org.tigris.subversion.subclipse.core.SVNException) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource) SVNDiffSummary(org.tigris.subversion.svnclientadapter.SVNDiffSummary) ArrayList(java.util.ArrayList) List(java.util.List) SVNStatusKind(org.tigris.subversion.svnclientadapter.SVNStatusKind) LocalResourceStatus(org.tigris.subversion.subclipse.core.resources.LocalResourceStatus) SVNDiffKind(org.tigris.subversion.svnclientadapter.SVNDiffSummary.SVNDiffKind)

Example 73 with ISVNLocalResource

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

the class WorkspaceAction method isEnabled.

/**
 * The action is enabled for the appropriate resources. This method checks that:
 *
 * <ol>
 *   <li>there is no overlap between a selected file and folder (overlapping folders is allowed
 *       because of logical vs. physical mapping problem in views)
 *   <li>the state of the resources match the conditions provided by:
 *       <ul>
 *         <li>isEnabledForIgnoredResources()
 *         <li>isEnabledForManagedResources()
 *         <li>isEnabledForUnManagedResources() (i.e. not ignored and not managed)
 *       </ul>
 * </ol>
 *
 * @see TeamAction#isEnabled()
 */
protected boolean isEnabled() throws TeamException {
    // invoke the inherited method so that overlaps are maintained
    IResource[] resources = super.getSelectedResources();
    // disable if no resources are selected
    if (resources.length == 0)
        return false;
    // disable properly for single resource enablement
    if (!isEnabledForMultipleResources() && resources.length != 1)
        return false;
    // validate enabled for each resource in the selection
    List folderPaths = new ArrayList();
    List filePaths = new ArrayList();
    for (int i = 0; i < resources.length; i++) {
        IResource resource = resources[i];
        // only enable for accessible resources
        if ((!resource.isAccessible()) && (!isEnabledForInaccessibleResources()))
            return false;
        // no SVN actions are enabled if the selection contains a linked resource
        if (SVNWorkspaceRoot.isLinkedResource(resource))
            return false;
        // only enable for resources in a project shared with SVN
        if (RepositoryProvider.getProvider(resource.getProject(), SVNProviderPlugin.getTypeId()) == null) {
            return false;
        }
        // collect files and folders separately to check for overlap later
        IPath resourceFullPath = resource.getFullPath();
        if (resource.getType() == IResource.FILE) {
            filePaths.add(resourceFullPath);
        } else {
            folderPaths.add(resourceFullPath);
        }
        // ensure that resource management state matches what the action requires
        ISVNLocalResource svnResource = SVNWorkspaceRoot.getSVNResourceFor(resource);
        if (!isEnabledForSVNResource(svnResource)) {
            return false;
        }
    }
    // NOTE: folder overlap must be allowed because of logical vs. physical
    if (!folderPaths.isEmpty()) {
        for (Iterator fileIter = filePaths.iterator(); fileIter.hasNext(); ) {
            IPath resourcePath = (IPath) fileIter.next();
            for (Iterator it = folderPaths.iterator(); it.hasNext(); ) {
                IPath folderPath = (IPath) it.next();
                if (folderPath.isPrefixOf(resourcePath)) {
                    return false;
                }
            }
        }
    }
    return true;
}
Also used : IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource) IResource(org.eclipse.core.resources.IResource)

Example 74 with ISVNLocalResource

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

the class SvnWizardUpdatePage method getCommonRoot.

private String getCommonRoot() {
    ArrayList<String> urlList = new ArrayList<String>();
    for (int i = 0; i < resources.length; i++) {
        ISVNLocalResource svnResource = SVNWorkspaceRoot.getSVNResourceFor(resources[i]);
        try {
            String anUrl = svnResource.getStatus().getUrlString();
            if (anUrl != null)
                urlList.add(anUrl);
        } catch (SVNException e1) {
        }
    }
    urlStrings = new String[urlList.size()];
    urlList.toArray(urlStrings);
    if (urlStrings.length == 0)
        return null;
    String urlString = urlStrings[0];
    if (urlStrings.length == 1)
        return urlString;
    String commonRoot = null;
    tag1: for (int i = 0; i < urlString.length(); i++) {
        String partialPath = urlString.substring(0, i + 1);
        if (partialPath.endsWith("/")) {
            // $NON-NLS-1$
            for (int j = 1; j < urlStrings.length; j++) {
                if (!urlStrings[j].startsWith(partialPath))
                    break tag1;
            }
            commonRoot = partialPath.substring(0, i);
        }
    }
    return commonRoot;
}
Also used : ArrayList(java.util.ArrayList) SVNException(org.tigris.subversion.subclipse.core.SVNException) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource)

Example 75 with ISVNLocalResource

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

the class GenerateDiffFileOperation method run.

/**
 * @see IRunnableWithProgress#run(IProgressMonitor)
 */
public void run(IProgressMonitor monitor) throws InvocationTargetException {
    ISVNClientAdapter svnClient = null;
    ISVNRepositoryLocation repository = null;
    try {
        // $NON-NLS-1$
        monitor.beginTask("", 500);
        // $NON-NLS-1$
        monitor.setTaskName(Policy.bind("GenerateSVNDiff.working"));
        OutputStream os;
        if (toClipboard) {
            os = new ByteArrayOutputStream();
        } else {
            os = new FileOutputStream(outputFile);
        }
        // $NON-NLS-1$ //$NON-NLS-2$
        File tmpFile = File.createTempFile("sub", "");
        tmpFile.deleteOnExit();
        ISVNLocalResource svnResource = SVNWorkspaceRoot.getSVNResourceFor(resources[0]);
        newFiles = new ArrayList();
        if (unaddedResources.length > 0) {
            // });
            for (int i = 0; i < unaddedResources.length; i++) newFiles.add(unaddedResources[i]);
            if (newFiles.size() > 0) {
                try {
                    // associate the resources with their respective RepositoryProvider
                    Hashtable table = getProviderMapping((IResource[]) newFiles.toArray(new IResource[newFiles.size()]));
                    Set keySet = table.keySet();
                    Iterator iterator = keySet.iterator();
                    while (iterator.hasNext()) {
                        IProgressMonitor subMonitor = Policy.subMonitorFor(monitor, 100);
                        SVNTeamProvider provider = (SVNTeamProvider) iterator.next();
                        List list = (List) table.get(provider);
                        IResource[] providerResources = (IResource[]) list.toArray(new IResource[list.size()]);
                        provider.add(providerResources, IResource.DEPTH_INFINITE, subMonitor);
                    }
                } catch (TeamException e) {
                    throw new InvocationTargetException(e);
                }
            }
        }
        repository = svnResource.getRepository();
        svnClient = repository.getSVNClient();
        try {
            monitor.worked(100);
            File[] files = getVersionedFiles();
            if (selectedResources == null)
                svnClient.diff(files, tmpFile, recursive);
            else {
                if (eclipseFormat) {
                    HashSet includedResources = new HashSet();
                    includedResources.addAll(Arrays.asList(unaddedResources));
                    includedResources.addAll(Arrays.asList(resources));
                    createEclipsePatch((IResource[]) includedResources.toArray(new IResource[0]), tmpFile, recursive);
                } else {
                    File relativeToPath = null;
                    if (projectRelative) {
                        relativeToPath = selectedResources[0].getProject().getLocation().toFile();
                    } else {
                        relativeToPath = getRelativeToPath();
                        if (relativeToPath.isFile()) {
                            relativeToPath = relativeToPath.getParentFile();
                        }
                    }
                    svnClient.createPatch(files, relativeToPath, tmpFile, recursive);
                }
            }
            monitor.worked(300);
            InputStream is = new FileInputStream(tmpFile);
            byte[] buffer = new byte[30000];
            int length;
            while ((length = is.read(buffer)) != -1) {
                os.write(buffer, 0, length);
            }
            is.close();
        } finally {
            os.close();
        }
        if (newFiles.size() > 0) {
            for (int i = 0; i < newFiles.size(); i++) {
                IResource resource = (IResource) newFiles.get(i);
                try {
                    SVNWorkspaceRoot.getSVNResourceFor(resource).revert();
                } catch (Exception e) {
                }
            }
        }
        boolean emptyDiff = false;
        if (toClipboard) {
            final ByteArrayOutputStream baos = (ByteArrayOutputStream) os;
            if (baos.size() == 0) {
                emptyDiff = true;
            } else {
                Display.getDefault().syncExec(new Runnable() {

                    public void run() {
                        TextTransfer plainTextTransfer = TextTransfer.getInstance();
                        Clipboard clipboard = new Clipboard(shell.getDisplay());
                        clipboard.setContents(new String[] { baos.toString() }, new Transfer[] { plainTextTransfer });
                        clipboard.dispose();
                    }
                });
            }
        } else {
            if (outputFile.length() == 0) {
                emptyDiff = true;
                outputFile.delete();
            }
        }
        // check for empty diff and report
        if (emptyDiff) {
            Display.getDefault().syncExec(new Runnable() {

                public void run() {
                    MessageDialog.openInformation(shell, // $NON-NLS-1$
                    Policy.bind("GenerateSVNDiff.noDiffsFoundTitle"), // $NON-NLS-1$
                    Policy.bind("GenerateSVNDiff.noDiffsFoundMsg"));
                }
            });
        }
    } catch (Exception e) {
        throw new InvocationTargetException(e);
    } finally {
        if (repository != null) {
            repository.returnSVNClient(svnClient);
        }
        monitor.done();
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource) TeamException(org.eclipse.team.core.TeamException) ISVNRepositoryLocation(org.tigris.subversion.subclipse.core.ISVNRepositoryLocation) SVNTeamProvider(org.tigris.subversion.subclipse.core.SVNTeamProvider) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter) HashSet(java.util.HashSet) Hashtable(java.util.Hashtable) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) InvocationTargetException(java.lang.reflect.InvocationTargetException) FileInputStream(java.io.FileInputStream) SVNClientException(org.tigris.subversion.svnclientadapter.SVNClientException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) TeamException(org.eclipse.team.core.TeamException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) FileOutputStream(java.io.FileOutputStream) TextTransfer(org.eclipse.swt.dnd.TextTransfer) Transfer(org.eclipse.swt.dnd.Transfer) Clipboard(org.eclipse.swt.dnd.Clipboard) File(java.io.File) IResource(org.eclipse.core.resources.IResource) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

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