Search in sources :

Example 81 with ISVNLocalResource

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

the class MergeCommand method run.

public void run(IProgressMonitor monitor) throws SVNException {
    mergeAborted = false;
    MergeListener mergeListener = null;
    ISVNClientAdapter svnClient = null;
    ISVNRepositoryLocation repository = null;
    try {
        monitor.beginTask(null, 100);
        ISVNLocalResource svnResource = SVNWorkspaceRoot.getSVNResourceFor(resource);
        repository = svnResource.getRepository();
        svnClient = repository.getSVNClient();
        SVNConflictResolver conflictResolver = new SVNConflictResolver(resource, textConflictHandling, binaryConflictHandling, propertyConflictHandling, treeConflictHandling);
        conflictResolver.setPart(part);
        svnClient.addConflictResolutionCallback(conflictResolver);
        MergeOptions mergeOptions = new MergeOptions();
        mergeOptions.setFromUrl(svnUrl1);
        mergeOptions.setFromRevision(svnRevision1);
        mergeOptions.setToUrl(svnUrl2);
        mergeOptions.setToRevision(svnRevision2);
        mergeOptions.setRevisions(revisions);
        mergeOptions.setForce(force);
        mergeOptions.setIgnoreAncestry(ignoreAncestry);
        mergeOptions.setDepth(depth);
        mergeListener = new MergeListener(resource, mergeOptions, conflictResolver, mergeOutput);
        svnClient.addNotifyListener(mergeListener);
        svnClient.addNotifyListener(operationResourceCollector);
        OperationManager.getInstance().beginOperation(svnClient, new OperationProgressNotifyListener(monitor));
        monitor.subTask(resource.getName());
        File file = resource.getLocation().toFile();
        if (revisions == null) {
            svnClient.merge(svnUrl1, svnRevision1, svnUrl2, svnRevision2, file, force, depth, false, ignoreAncestry, recordOnly);
        } else {
            SVNUrlWithPegRevision svnUrlWithPegRevision = new SVNUrlWithPegRevision(svnUrl1);
            SVNRevision pegRevision = svnUrlWithPegRevision.getPegRevision();
            if (pegRevision == null)
                pegRevision = SVNRevision.HEAD;
            svnClient.merge(svnUrlWithPegRevision.getUrl(), pegRevision, revisions, file, force, depth, ignoreAncestry, false, recordOnly);
        }
        monitor.worked(100);
    } catch (SVNClientException e) {
        if (e.getAprError() == SVNClientException.MERGE_CONFLICT) {
            mergeAborted = true;
            errorMessage = // $NON-NLS-1$ //$NON-NLS-2$
            e.getCause().getLocalizedMessage().replaceAll("\n", " ");
        } else
            throw SVNException.wrapException(e);
    } finally {
        if (mergeListener != null)
            mergeOutput = mergeListener.getMergeOutput();
        Set<IResource> operationResources = operationResourceCollector.getOperationResources();
        OperationManager.getInstance().endOperation(true, operationResources);
        monitor.done();
        svnClient.removeNotifyListener(mergeListener);
        svnClient.removeNotifyListener(operationResourceCollector);
        svnClient.addConflictResolutionCallback(null);
        if (repository != null) {
            repository.returnSVNClient(svnClient);
        }
    }
}
Also used : ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource) ISVNRepositoryLocation(org.tigris.subversion.subclipse.core.ISVNRepositoryLocation) SVNClientException(org.tigris.subversion.svnclientadapter.SVNClientException) SVNUrlWithPegRevision(org.tigris.subversion.subclipse.core.util.SVNUrlWithPegRevision) SVNRevision(org.tigris.subversion.svnclientadapter.SVNRevision) File(java.io.File) IResource(org.eclipse.core.resources.IResource) ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter) OperationProgressNotifyListener(org.tigris.subversion.subclipse.core.client.OperationProgressNotifyListener)

Example 82 with ISVNLocalResource

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

the class MergeOperation method execute.

protected void execute(IProgressMonitor monitor) throws SVNException, InterruptedException {
    monitor.beginTask(getTaskName(), mergedResources.length);
    ArrayList mergeOutputs = new ArrayList();
    for (int i = 0; i < mergedResources.length; i++) {
        try {
            monitor.subTask(mergedResources[i].getName());
            incompleteOutput = null;
            if (mergeOutput == null) {
                incompleteOutput = MergeOutput.getIncompleteMerge(mergedResources[i], svnUrls1[i].toString(), svnUrls2[i].toString());
            }
            if (incompleteOutput == null)
                command = new MergeCommand(mergedResources[i], svnUrls1[i], svnRevision1, svnUrls2[i], svnRevision2, revisions, mergeOutput);
            else {
                if (incompleteOutput.hasUnresolvedConflicts()) {
                    unresolvedConflicts = true;
                    break;
                }
                command = new MergeCommand(mergedResources[i], svnUrls1[i], svnRevision1, svnUrls2[i], svnRevision2, revisions, incompleteOutput);
            }
            command.setPart(getPart());
            command.setForce(force);
            command.setIgnoreAncestry(ignoreAncestry);
            command.setDepth(depth);
            command.setTextConflictHandling(textConflictHandling);
            command.setBinaryConflictHandling(binaryConflictHandling);
            command.setPropertyConflictHandling(propertyConflictHandling);
            command.setTreeConflictHandling(treeConflictHandling);
            command.setRecordOnly(recordOnly);
            command.run(Policy.subMonitorFor(monitor, 1000));
            monitor.worked(1);
            if (recordOnly) {
                MergeOutput mergeOutput = command.getMergeOutput();
                MergeSummaryResult[] summaryResults = { new MergeSummaryResult(MergeSummaryResult.PROPERTY, "Updated", "1") };
                // $NON-NLS-1$ //$NON-NLS-2$
                mergeOutput.setMergeSummaryResults(summaryResults);
                MergeResult[] mergeResults = { new AdaptableMergeResult(" ", "U", " ", mergedResources[i].getLocation().toString(), false) };
                // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                mergeOutput.setMergeResults(mergeResults);
                ISVNLocalResource svnResource = SVNWorkspaceRoot.getSVNResourceFor(mergedResources[i]);
                if (svnResource != null) {
                    svnResource.refreshStatus();
                }
            }
        } catch (SVNException e) {
            if (e.operationInterrupted()) {
                showCancelledMessage();
            } else {
                collectStatus(e.getStatus());
            }
            abnormalEnd = true;
        }
        MergeOutput mergeOutput = command.getMergeOutput();
        mergeOutputs.add(mergeOutput);
        if (command.isMergeAborted()) {
            mergeOutput.setIncomplete(true);
            mergeOutput.setNormalEnd(true);
            mergeOutput.store();
            abortedMergeOutput = mergeOutput;
            MergeResultsView view = MergeResultsView.getView();
            if (view != null)
                view.refreshAsync(mergeOutput);
            break;
        } else {
            mergeOutput.setIncomplete(false);
            if (!recordOnly && !abnormalEnd) {
                mergeOutput.setNormalEnd(true);
                mergeOutput.store();
                MergeResultsView view = MergeResultsView.getView();
                if (view != null)
                    view.refreshAsync(mergeOutput);
            }
        }
    }
    if (recordOnly) {
        Display.getDefault().syncExec(new Runnable() {

            public void run() {
                DialogWizard dialogWizard = new DialogWizard(DialogWizard.COMMIT_MERGEINFO_PROPERTY);
                dialogWizard.setUnblock(unblock);
                MergeWizardDialog dialog = new MergeWizardDialog(Display.getDefault().getActiveShell(), dialogWizard, true);
                if (dialog.open() == MergeWizardDialog.CANCEL)
                    return;
                CommitAction commitAction = new CommitAction();
                commitAction.setSelectedResources(mergedResources);
                commitAction.run(null);
            }
        });
    } else {
        final MergeOutput[] mergeOutputArray = new MergeOutput[mergeOutputs.size()];
        mergeOutputs.toArray(mergeOutputArray);
        Display.getDefault().syncExec(new Runnable() {

            public void run() {
                if (unresolvedConflicts) {
                    DialogWizard dialogWizard = new DialogWizard(DialogWizard.UNRESOLVED_CONFLICTS);
                    dialogWizard.setMergeOutput(incompleteOutput);
                    MergeWizardDialog dialog = new MergeWizardDialog(Display.getDefault().getActiveShell(), dialogWizard);
                    dialog.open();
                } else {
                    if (command.isMergeAborted()) {
                        DialogWizard dialogWizard = new DialogWizard(DialogWizard.MERGE_ABORTED);
                        dialogWizard.setMergeOutput(abortedMergeOutput);
                        dialogWizard.setErrorMessage(command.getErrorMessage());
                        MergeWizardDialog dialog = new MergeWizardDialog(Display.getDefault().getActiveShell(), dialogWizard);
                        dialog.open();
                    }
                }
                if (mergeOutputArray.length > 0 && !abnormalEnd) {
                    DialogWizard dialogWizard = new DialogWizard(DialogWizard.SUMMARY);
                    dialogWizard.setMergeOutputs(mergeOutputArray);
                    dialogWizard.setResumed(resumed);
                    MergeWizardDialog dialog = new MergeWizardDialog(Display.getDefault().getActiveShell(), dialogWizard);
                    dialog.open();
                }
            }
        });
    }
    monitor.done();
}
Also used : ArrayList(java.util.ArrayList) SVNException(org.tigris.subversion.subclipse.core.SVNException) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource) MergeResultsView(com.collabnet.subversion.merge.views.MergeResultsView) DialogWizard(com.collabnet.subversion.merge.wizards.DialogWizard) MergeWizardDialog(com.collabnet.subversion.merge.wizards.MergeWizardDialog) CommitAction(org.tigris.subversion.subclipse.ui.actions.CommitAction)

Example 83 with ISVNLocalResource

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

the class CopyFromMergeSourceAction method execute.

protected void execute(IAction action) throws InvocationTargetException, InterruptedException {
    Iterator iter = selection.iterator();
    while (iter.hasNext()) {
        Object object = iter.next();
        if (object instanceof ISkippedMergeResult) {
            SVNRevision svnRevision = null;
            IResource resource = null;
            SVNUrl srcUrl = null;
            MergeResult mergeResult = null;
            if (object instanceof SkippedMergeResult) {
                SkippedMergeResult skippedMergeResult = (SkippedMergeResult) object;
                mergeResult = skippedMergeResult;
                MergeOptions mergeOptions = skippedMergeResult.getMergeOutput().getMergeOptions();
                svnRevision = mergeOptions.getToRevision();
                SVNUrl svnUrl = mergeOptions.getFromUrl();
                resource = skippedMergeResult.getResource();
                if (!resource.exists()) {
                    ISVNLocalResource svnResource = SVNWorkspaceRoot.getSVNResourceFor(resource);
                    String resourceSubString = resource.getFullPath().toOSString().substring(skippedMergeResult.getMergeOutput().getTarget().length() + 1);
                    if (!resourceSubString.startsWith("/"))
                        // $NON-NLS-1$ //$NON-NLS-2$
                        resourceSubString = "/" + resourceSubString;
                    try {
                        srcUrl = new SVNUrl(svnUrl.toString() + // $NON-NLS-1$ //$NON-NLS-2$
                        resourceSubString.replaceAll("\\\\", "/"));
                    } catch (MalformedURLException e) {
                        Activator.handleError(Messages.CopyFromMergeSourceAction_error, e);
                        MessageDialog.openError(getShell(), Messages.CopyFromMergeSourceAction_title, e.getLocalizedMessage());
                        return;
                    }
                }
            }
            if (object instanceof SkippedMergeResultsFolder) {
                SkippedMergeResultsFolder skippedMergeResultsFolder = (SkippedMergeResultsFolder) object;
                mergeResult = skippedMergeResultsFolder.getMergeResult();
                MergeOptions mergeOptions = skippedMergeResultsFolder.getMergeOutput().getMergeOptions();
                svnRevision = mergeOptions.getToRevision();
                SVNUrl svnUrl = mergeOptions.getFromUrl();
                resource = skippedMergeResultsFolder.getFolder();
                if (!resource.exists()) {
                    ISVNLocalResource svnResource = SVNWorkspaceRoot.getSVNResourceFor(resource);
                    String resourceSubString = resource.getFullPath().toOSString().substring(skippedMergeResultsFolder.getMergeOutput().getTarget().length() + 1);
                    if (!resourceSubString.startsWith("/"))
                        // $NON-NLS-1$ //$NON-NLS-2$
                        resourceSubString = "/" + resourceSubString;
                    try {
                        srcUrl = new SVNUrl(svnUrl.toString() + // $NON-NLS-1$ //$NON-NLS-2$
                        resourceSubString.replaceAll("\\\\", "/"));
                    } catch (MalformedURLException e) {
                        Activator.handleError(Messages.CopyFromMergeSourceAction_error2, e);
                        MessageDialog.openError(getShell(), Messages.CopyFromMergeSourceAction_title, e.getLocalizedMessage());
                        return;
                    }
                }
            }
            if (resource.exists()) {
                MessageDialog.openError(getShell(), Messages.CopyFromMergeSourceAction_title, resource.getName() + Messages.CopyFromMergeSourceAction_alreadyExists);
                return;
            }
            if (svnRevision == null)
                svnRevision = SVNRevision.HEAD;
            IResource[] resources = { resource };
            File destPath = new File(resource.getLocation().toOSString());
            CopyOperation copyOperation = new CopyOperation(getTargetPart(), resources, srcUrl, destPath, svnRevision, mergeResult);
            copyOperation.run();
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) SVNUrl(org.tigris.subversion.svnclientadapter.SVNUrl) SkippedMergeResult(com.collabnet.subversion.merge.SkippedMergeResult) MergeResult(com.collabnet.subversion.merge.MergeResult) ISkippedMergeResult(com.collabnet.subversion.merge.ISkippedMergeResult) SkippedMergeResultsFolder(com.collabnet.subversion.merge.SkippedMergeResultsFolder) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource) CopyOperation(com.collabnet.subversion.merge.CopyOperation) Iterator(java.util.Iterator) MergeOptions(com.collabnet.subversion.merge.MergeOptions) SVNRevision(org.tigris.subversion.svnclientadapter.SVNRevision) File(java.io.File) ISkippedMergeResult(com.collabnet.subversion.merge.ISkippedMergeResult) IResource(org.eclipse.core.resources.IResource) SkippedMergeResult(com.collabnet.subversion.merge.SkippedMergeResult) ISkippedMergeResult(com.collabnet.subversion.merge.ISkippedMergeResult)

Example 84 with ISVNLocalResource

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

the class ResourceSelectionTree method dedupeResources.

public static IResource[] dedupeResources(IResource[] resources) {
    if (resources == null) {
        return null;
    }
    List<String> locations = new ArrayList<String>();
    List<IResource> uniqueResources = new ArrayList<IResource>();
    for (IResource resource : resources) {
        boolean parentDeleted = false;
        if (resource.getParent() != null && !resource.getParent().exists()) {
            ISVNLocalResource svnResource = SVNWorkspaceRoot.getSVNResourceFor(resource.getParent());
            try {
                if (svnResource != null && (svnResource.getStatus().isDeleted() || svnResource.getStatus().isMissing())) {
                    parentDeleted = true;
                }
            } catch (SVNException e) {
            }
        }
        if (parentDeleted || resource.getParent() == null || resource.getParent().exists()) {
            if (resource.getLocation() == null || !locations.contains(resource.getLocation().toString())) {
                uniqueResources.add(resource);
                locations.add(resource.getLocation().toString());
            }
        }
    }
    IResource[] uniqueResourceArray = new IResource[uniqueResources.size()];
    uniqueResources.toArray(uniqueResourceArray);
    return uniqueResourceArray;
}
Also used : 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 85 with ISVNLocalResource

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

the class ShowPropertiesSynchronizeAction method getSyncInfoFilter.

protected FastSyncInfoFilter getSyncInfoFilter() {
    return new FastSyncInfoFilter() {

        public boolean select(SyncInfo info) {
            SyncInfoDirectionFilter outgoingFilter = new SyncInfoDirectionFilter(new int[] { SyncInfo.OUTGOING });
            if (!outgoingFilter.select(info))
                return false;
            IStructuredSelection selection = getStructuredSelection();
            if (selection.size() != 1)
                return false;
            ISynchronizeModelElement element = (ISynchronizeModelElement) selection.getFirstElement();
            IResource resource = element.getResource();
            if (resource == null)
                return false;
            ISVNLocalResource svnResource = SVNWorkspaceRoot.getSVNResourceFor(resource);
            try {
                return !svnResource.getStatus().isDeleted() && svnResource.getStatus().isManaged() && resource.exists();
            } catch (SVNException e) {
                return false;
            }
        }
    };
}
Also used : SyncInfo(org.eclipse.team.core.synchronize.SyncInfo) ISynchronizeModelElement(org.eclipse.team.ui.synchronize.ISynchronizeModelElement) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SVNException(org.tigris.subversion.subclipse.core.SVNException) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource) IResource(org.eclipse.core.resources.IResource) FastSyncInfoFilter(org.eclipse.team.core.synchronize.FastSyncInfoFilter)

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