Search in sources :

Example 16 with LocalResourceStatus

use of org.tigris.subversion.subclipse.core.resources.LocalResourceStatus in project subclipse by subclipse.

the class RevisionAwareDifferencer method compareStatusAndRevisions.

/**
 * Compares two nodes to determine if they are equal. Returns NODE_EQUAL of they are the same,
 * NODE_NOT_EQUAL if they are different, and NODE_UNKNOWN if comparison was not possible.
 */
protected int compareStatusAndRevisions(Object left, Object right) {
    ISVNLocalResource localResource = null;
    if (left instanceof SVNLocalResourceNode) {
        localResource = ((SVNLocalResourceNode) left).getLocalResource();
    }
    ISVNRemoteResource edition = null;
    if (right instanceof ResourceEditionNode)
        edition = ((ResourceEditionNode) right).getRemoteResource();
    if (localResource == null || edition == null) {
        return NODE_UNKNOWN;
    }
    // if they're both non-files, they're the same
    if (localResource.isFolder() && edition.isContainer()) {
        return NODE_EQUAL;
    }
    // if they have different types, they're different
    if (localResource.isFolder() != edition.isContainer()) {
        return NODE_NOT_EQUAL;
    }
    String leftLocation = localResource.getRepository().getLocation();
    String rightLocation = edition.getRepository().getLocation();
    if (!leftLocation.equals(rightLocation)) {
        return NODE_UNKNOWN;
    }
    LocalResourceStatus localStatus = null;
    try {
        localStatus = localResource.getStatus();
        if (localStatus == null) {
            return NODE_UNKNOWN;
        }
        if (!localResource.isDirty() && localResource.getResource().getProjectRelativePath().toString().equals(edition.getProjectRelativePath()) && localStatus.getLastChangedRevision().equals(edition.getLastChangedRevision())) {
            return NODE_EQUAL;
        }
        if (!localResource.isDirty() && !localResource.isFolder()) {
            if (changedResources == null && diffFiles != null) {
                parseDiffs();
            }
            if (changedResources == null) {
                for (int i = 0; i < diffSummary.length; i++) {
                    if (localResource.getResource().getProjectRelativePath().toString().equals(projectRelativePath) || localResource.getResource().getProjectRelativePath().toString().equals(projectRelativePath + diffSummary[i].getPath())) {
                        return NODE_NOT_EQUAL;
                    }
                }
                return NODE_EQUAL;
            }
            if (changedResources.contains(localResource.getResource().getLocation().toString())) {
                return NODE_NOT_EQUAL;
            }
            return NODE_EQUAL;
        }
    } catch (SVNException e) {
        return NODE_UNKNOWN;
    }
    return NODE_UNKNOWN;
}
Also used : ISVNRemoteResource(org.tigris.subversion.subclipse.core.ISVNRemoteResource) SVNException(org.tigris.subversion.subclipse.core.SVNException) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource) LocalResourceStatus(org.tigris.subversion.subclipse.core.resources.LocalResourceStatus)

Example 17 with LocalResourceStatus

use of org.tigris.subversion.subclipse.core.resources.LocalResourceStatus 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 18 with LocalResourceStatus

use of org.tigris.subversion.subclipse.core.resources.LocalResourceStatus in project subclipse by subclipse.

the class SubclipseSubscriberResourceCollector method processDelta.

/**
 * Process the resource delta and posts all necessary events to the background event handler.
 *
 * @param delta the resource delta to analyze
 */
protected void processDelta(IResourceDelta delta, IResource[] roots) {
    IResource resource = delta.getResource();
    int kind = delta.getKind();
    // Skip derived resources: <<  PATCH >>
    if (resource.isDerived()) {
        LocalResourceStatus aStatus = null;
        try {
            aStatus = SVNProviderPlugin.getPlugin().getStatusCacheManager().getStatusFromCache(resource);
        } catch (SVNException e) {
            SVNProviderPlugin.log(IStatus.ERROR, e.getMessage(), e);
        }
        if ((aStatus == null) || !aStatus.isManaged()) {
            return;
        }
        if (ignoreManagedDerivedResources) {
            return;
        }
    }
    if (resource.getType() == IResource.PROJECT) {
        // Handle projects that should be removed from the collector
        if (((kind & IResourceDelta.REMOVED) != 0) || /* deleted project */
        (delta.getFlags() & IResourceDelta.OPEN) != 0 && !((IProject) resource).isOpen() || /* closed project */
        !isAncestorOfRoot(resource, roots)) /* not within subscriber roots */
        {
            // If the project has any entries in the sync set, remove them
            if (hasMembers(resource)) {
                remove(resource);
            }
        }
    }
    boolean visitChildren = false;
    if (isDescendantOfRoot(resource, roots)) {
        visitChildren = true;
        // and add the new one
        if ((delta.getFlags() & IResourceDelta.TYPE) != 0) {
            remove(resource);
            change(resource, IResource.DEPTH_INFINITE);
        }
        // Check the flags for changes the SyncSet cares about.
        // Notice we don't care about MARKERS currently.
        int changeFlags = delta.getFlags();
        if ((changeFlags & (IResourceDelta.OPEN | IResourceDelta.CONTENT)) != 0) {
            change(resource, IResource.DEPTH_ZERO);
        }
        // Check the kind and deal with those we care about
        if ((delta.getKind() & (IResourceDelta.REMOVED | IResourceDelta.ADDED)) != 0) {
            change(resource, IResource.DEPTH_ZERO);
        }
    }
    if (resource.getType() == IFolder.FOLDER) {
        visitChildren = false;
    }
    // Handle changed children
    if (visitChildren || isAncestorOfRoot(resource, roots)) {
        IResourceDelta[] affectedChildren = delta.getAffectedChildren(IResourceDelta.CHANGED | IResourceDelta.REMOVED | IResourceDelta.ADDED);
        for (int i = 0; i < affectedChildren.length; i++) {
            processDelta(affectedChildren[i], roots);
        }
    }
}
Also used : SVNException(org.tigris.subversion.subclipse.core.SVNException) LocalResourceStatus(org.tigris.subversion.subclipse.core.resources.LocalResourceStatus)

Example 19 with LocalResourceStatus

use of org.tigris.subversion.subclipse.core.resources.LocalResourceStatus in project subclipse by subclipse.

the class MergeViewResolveAction method execute.

protected void execute(IAction action) throws InvocationTargetException, InterruptedException {
    boolean treeConflictDialogShown = false;
    boolean compare = false;
    mergePath = null;
    if (showDialog) {
        List resources = new ArrayList();
        Iterator iter = fSelection.iterator();
        boolean folderSelected = false;
        boolean textConflicts = false;
        boolean propertyConflicts = false;
        boolean treeConflicts = false;
        while (iter.hasNext()) {
            MergeResult mergeResult = null;
            Object selectedObject = iter.next();
            if (selectedObject instanceof MergeResult)
                mergeResult = (MergeResult) selectedObject;
            if (selectedObject instanceof MergeResultsFolder) {
                folderSelected = true;
                MergeResultsFolder mergeResultsFolder = (MergeResultsFolder) selectedObject;
                resources.add(mergeResultsFolder.getFolder());
                mergeResult = mergeResultsFolder.getMergeResult();
            }
            if (mergeResult != null && (mergeResult.hasTreeConflict() || mergeResult.isConflicted() || mergeResult.isPropertyConflicted())) {
                if (mergeResult.isConflicted())
                    textConflicts = true;
                if (mergeResult.isPropertyConflicted())
                    propertyConflicts = true;
                if (mergeResult.hasTreeConflict())
                    treeConflicts = true;
                if (!(selectedObject instanceof MergeResultsFolder)) {
                    resources.add(mergeResult.getResource());
                }
            }
        }
        if (resources.size() > 1) {
            if (!MessageDialog.openConfirm(getShell(), Messages.MergeViewResolveAction_confirm, Messages.MergeViewResolveAction_confirmMultiple))
                return;
            setResolution(ISVNConflictResolver.Choice.chooseMerged);
        } else if (treeConflicts) {
            IResource resource = (IResource) resources.get(0);
            treeConflict = getTreeConflict(resource);
            if (treeConflict == null) {
                String message = Messages.MergeViewResolveAction_confirmTreeConflict + resource.getName() + // $NON-NLS-1$
                "?";
                if (!MessageDialog.openConfirm(getShell(), Messages.MergeViewResolveAction_confirm, message))
                    return;
                setResolution(ISVNConflictResolver.Choice.chooseMerged);
            } else {
                ResolveTreeConflictWizard wizard = new ResolveTreeConflictWizard(treeConflict, getTargetPart());
                WizardDialog dialog = new SizePersistedWizardDialog(Display.getDefault().getActiveShell(), wizard, // $NON-NLS-1$
                "ResolveTreeConflict");
                if (dialog.open() != WizardDialog.OK)
                    return;
                treeConflictDialogShown = true;
                compare = wizard.isCompare();
                mergePath = wizard.getMergePath();
            }
        } else if (folderSelected) {
            IResource resource = (IResource) resources.get(0);
            String message = Messages.MergeViewResolveAction_confirmProperty + resource.getFullPath() + // $NON-NLS-1$
            "?";
            if (!MessageDialog.openConfirm(getShell(), Messages.MergeViewResolveAction_confirm, message))
                return;
            selectedResolution = ISVNConflictResolver.Choice.chooseMerged;
            setResolution(selectedResolution);
        } else {
            IResource[] resourceArray = new IResource[resources.size()];
            resources.toArray(resourceArray);
            DialogWizard dialogResolveWizard = new DialogWizard(DialogWizard.MARK_RESOLVED);
            dialogResolveWizard.setResources(resourceArray);
            dialogResolveWizard.setTextConflicts(textConflicts);
            dialogResolveWizard.setPropertyConflicts(propertyConflicts);
            dialogResolveWizard.setTreeConflicts(treeConflicts);
            MergeWizardDialog resolveDialog = new MergeWizardDialog(Display.getDefault().getActiveShell(), dialogResolveWizard);
            if (resolveDialog.open() == MergeWizardDialog.CANCEL)
                return;
            selectedResolution = dialogResolveWizard.getResolution();
            setResolution(selectedResolution);
        }
    }
    if (!treeConflictDialogShown)
        super.execute(action);
    ArrayList mergeOutputs = new ArrayList();
    Iterator iter = fSelection.iterator();
    while (iter.hasNext()) {
        MergeResult mergeResult = null;
        Object selectedObject = iter.next();
        if (selectedObject instanceof MergeResult)
            mergeResult = (MergeResult) selectedObject;
        if (selectedObject instanceof MergeResultsFolder) {
            MergeResultsFolder mergeResultsFolder = (MergeResultsFolder) selectedObject;
            mergeResult = mergeResultsFolder.getMergeResult();
        }
        if (mergeResult != null && (mergeResult.hasTreeConflict() || mergeResult.isConflicted() || mergeResult.isPropertyConflicted())) {
            if (!compare) {
                String conflictResolution = Integer.toString(selectedResolution);
                mergeResult.setConflictResolution(conflictResolution);
                mergeResult.setPropertyResolution(conflictResolution);
                mergeResult.setTreeConflictResolution(conflictResolution);
                if (mergePath != null) {
                    MergeResult[] allResults = mergeResult.getMergeOutput().getMergeResults();
                    for (MergeResult checkResult : allResults) {
                        if (checkResult.getResource().getLocation().toFile().equals(mergePath)) {
                            try {
                                LocalResourceStatus status = SVNProviderPlugin.getPlugin().getStatusCacheManager().getStatus(checkResult.getResource());
                                if (status.isTextConflicted()) {
                                    checkResult.setAction(MergeResult.ACTION_CONFLICT);
                                    checkResult.setConflictResolution(" ");
                                    checkResult.setError(true);
                                }
                            } catch (SVNException e) {
                            }
                            break;
                        }
                    }
                }
            }
            if (!mergeOutputs.contains(mergeResult.getMergeOutput()))
                mergeOutputs.add(mergeResult.getMergeOutput());
        }
    }
    iter = mergeOutputs.iterator();
    while (iter.hasNext()) {
        MergeOutput mergeOutput = (MergeOutput) iter.next();
        mergeOutput.store();
    }
    MergeResultsView.getView().refresh();
    iter = mergeOutputs.iterator();
    while (iter.hasNext()) {
        MergeOutput mergeOutput = (MergeOutput) iter.next();
        if (!mergeOutput.hasUnresolvedConflicts()) {
            DialogWizard dialogWizard = new DialogWizard(DialogWizard.CONFLICTS_RESOLVED);
            dialogWizard.setMergeOutput(mergeOutput);
            MergeWizardDialog dialog = new MergeWizardDialog(Display.getDefault().getActiveShell(), dialogWizard, true);
            if (dialog.open() != MergeWizardDialog.CANCEL)
                MergeResultsView.getView().refresh();
        }
    }
}
Also used : ArrayList(java.util.ArrayList) MergeResult(com.collabnet.subversion.merge.MergeResult) ResolveTreeConflictWizard(org.tigris.subversion.subclipse.ui.conflicts.ResolveTreeConflictWizard) SVNException(org.tigris.subversion.subclipse.core.SVNException) Iterator(java.util.Iterator) SizePersistedWizardDialog(org.tigris.subversion.subclipse.ui.wizards.SizePersistedWizardDialog) MergeOutput(com.collabnet.subversion.merge.MergeOutput) DialogWizard(com.collabnet.subversion.merge.wizards.DialogWizard) ArrayList(java.util.ArrayList) List(java.util.List) MergeWizardDialog(com.collabnet.subversion.merge.wizards.MergeWizardDialog) WizardDialog(org.eclipse.jface.wizard.WizardDialog) SizePersistedWizardDialog(org.tigris.subversion.subclipse.ui.wizards.SizePersistedWizardDialog) LocalResourceStatus(org.tigris.subversion.subclipse.core.resources.LocalResourceStatus) IResource(org.eclipse.core.resources.IResource) MergeWizardDialog(com.collabnet.subversion.merge.wizards.MergeWizardDialog) MergeResultsFolder(com.collabnet.subversion.merge.MergeResultsFolder)

Example 20 with LocalResourceStatus

use of org.tigris.subversion.subclipse.core.resources.LocalResourceStatus in project subclipse by subclipse.

the class MergeOutput method loadMergeResults.

private MergeResult[] loadMergeResults() {
    ArrayList results = new ArrayList();
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(mergeDate);
    File mergeOutputFile = new File(Activator.getMergeResultsLocation() + File.separator + "m" + // $NON-NLS-1$
    calendar.getTimeInMillis());
    BufferedReader input = null;
    try {
        input = new BufferedReader(new InputStreamReader(new FileInputStream(mergeOutputFile), "UTF8"));
        String line = null;
        while ((line = input.readLine()) != null) {
            if (line.startsWith("Message: ") || line.startsWith("Error:   ")) {
                // $NON-NLS-1$ //$NON-NLS-2$
                if (line.length() < 24) {
                    Activator.handleError(new Exception("Unexpected error while loading merge results from " + mergeOutputFile.getName() + ".  line: " + line));
                } else {
                    String action = null;
                    String propertyAction = null;
                    String treeConflictAction = null;
                    String conflictResolution = null;
                    String propertyResolution = null;
                    String treeConflictResolution = null;
                    String path = null;
                    int type = MergeResult.FILE;
                    // $NON-NLS-1$
                    boolean error = line.startsWith("Error: ");
                    type = Integer.parseInt(line.substring(9, 10));
                    action = line.substring(11, 12);
                    propertyAction = line.substring(13, 14);
                    conflictResolution = line.substring(15, 16);
                    propertyResolution = line.substring(17, 18);
                    treeConflictAction = line.substring(19, 20);
                    treeConflictResolution = line.substring(21, 22);
                    path = line.substring(23);
                    MergeResult result = null;
                    if (action.equals(MergeResult.ACTION_SKIP))
                        result = new SkippedMergeResult(action, propertyAction, treeConflictAction, path, error);
                    else
                        result = new AdaptableMergeResult(action, propertyAction, treeConflictAction, path, error);
                    result.setType(type);
                    result.setMergeOutput(this);
                    IResource resource = null;
                    // String resourcePath = path.substring(root.length());
                    if (this.resource.getLocation().toString().equals(path))
                        resource = this.resource;
                    else
                        // if (this.resource.getFullPath().toString().equals(resourcePath)) resource =
                        // this.resource;
                        // else if (type == MergeResult.FOLDER) resource =
                        // ResourcesPlugin.getWorkspace().getRoot().getFolder(new Path(resourcePath));
                        // else resource = ResourcesPlugin.getWorkspace().getRoot().getFile(new
                        // Path(resourcePath));
                        resource = SVNWorkspaceRoot.getResourceFor(this.resource, new Path(path));
                    result.setResource(resource);
                    if (error) {
                        result.setConflictResolution(conflictResolution);
                        result.setPropertyResolution(propertyResolution);
                        result.setTreeConflictResolution(treeConflictResolution);
                        if (resource != null && !inProgress) {
                            LocalResourceStatus status = SVNWorkspaceRoot.getSVNResourceFor(resource).getStatus();
                            if (conflictResolution.trim().length() == 0 && !status.isTextConflicted())
                                // $NON-NLS-1$
                                result.setConflictResolution("X");
                            if (propertyResolution.trim().length() == 0 && !status.isPropConflicted())
                                // $NON-NLS-1$
                                result.setPropertyResolution("X");
                            if (treeConflictResolution.trim().length() == 0 && !status.hasTreeConflict())
                                // $NON-NLS-1$
                                result.setTreeConflictResolution("X");
                        }
                    }
                    results.add(result);
                }
            }
        }
    } catch (Exception e) {
        Activator.handleError(e);
    } finally {
        try {
            if (input != null) {
                input.close();
            }
        } catch (IOException e) {
            Activator.handleError(e);
        }
    }
    MergeResult[] mergeResultArray = new MergeResult[results.size()];
    results.toArray(mergeResultArray);
    Arrays.sort(mergeResultArray);
    return mergeResultArray;
}
Also used : Path(org.eclipse.core.runtime.Path) InputStreamReader(java.io.InputStreamReader) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) BufferedReader(java.io.BufferedReader) IFile(org.eclipse.core.resources.IFile) File(java.io.File) LocalResourceStatus(org.tigris.subversion.subclipse.core.resources.LocalResourceStatus) IResource(org.eclipse.core.resources.IResource)

Aggregations

LocalResourceStatus (org.tigris.subversion.subclipse.core.resources.LocalResourceStatus)26 ISVNLocalResource (org.tigris.subversion.subclipse.core.ISVNLocalResource)17 IResource (org.eclipse.core.resources.IResource)12 SVNException (org.tigris.subversion.subclipse.core.SVNException)12 ISVNRepositoryLocation (org.tigris.subversion.subclipse.core.ISVNRepositoryLocation)7 CoreException (org.eclipse.core.runtime.CoreException)6 TeamException (org.eclipse.team.core.TeamException)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 ArrayList (java.util.ArrayList)4 ISVNClientAdapter (org.tigris.subversion.svnclientadapter.ISVNClientAdapter)4 File (java.io.File)3 List (java.util.List)2 IContainer (org.eclipse.core.resources.IContainer)2 IFile (org.eclipse.core.resources.IFile)2 IProject (org.eclipse.core.resources.IProject)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 Path (org.eclipse.core.runtime.Path)2 WizardDialog (org.eclipse.jface.wizard.WizardDialog)2 OperationManager (org.tigris.subversion.subclipse.core.client.OperationManager)2 SVNClientException (org.tigris.subversion.svnclientadapter.SVNClientException)2