Search in sources :

Example 51 with ISVNLocalResource

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

the class ShowDifferencesAsUnifiedDiffActionWC method execute.

protected void execute(IAction action) throws InvocationTargetException, InterruptedException {
    IResource[] resources = getSelectedResources();
    boolean refreshFile = false;
    for (int i = 0; i < resources.length; i++) {
        if (resources[i] instanceof IFile && !resources[i].isSynchronized(Depth.immediates)) {
            if (refreshFile || MessageDialog.openQuestion(getShell(), Policy.bind("DifferencesDialog.compare"), Policy.bind("CompareWithRemoteAction.fileChanged"))) {
                refreshFile = true;
                try {
                    resources[i].refreshLocal(Depth.immediates, new NullProgressMonitor());
                } catch (CoreException e) {
                    throw new InvocationTargetException(e);
                }
            } else {
                break;
            }
        }
    }
    if (resources.length > 1) {
        SvnWizardCompareMultipleResourcesWithBranchTagPage comparePage = new SvnWizardCompareMultipleResourcesWithBranchTagPage(resources);
        SvnWizard wizard = new SvnWizard(comparePage);
        SvnWizardDialog dialog = new SvnWizardDialog(getShell(), wizard);
        if (dialog.open() == SvnWizardDialog.OK) {
            ISVNLocalResource[] localResources = new ISVNLocalResource[resources.length];
            for (int i = 0; i < resources.length; i++) {
                localResources[i] = SVNWorkspaceRoot.getSVNResourceFor(resources[i]);
            }
            try {
                SVNLocalBranchTagCompareInput compareInput = new SVNLocalBranchTagCompareInput(localResources, comparePage.getUrls(), comparePage.getRevision(), getTargetPart());
                CompareUI.openCompareEditorOnPage(compareInput, getTargetPage());
            } catch (SVNException e) {
                MessageDialog.openError(getShell(), Policy.bind("ShowDifferencesAsUnifiedDiffDialog.branchTag"), e.getMessage());
            }
        }
        return;
    }
    ShowDifferencesAsUnifiedDiffDialogWC dialog = new ShowDifferencesAsUnifiedDiffDialogWC(getShell(), resources[0], getTargetPart());
    if (dialog.open() == ShowDifferencesAsUnifiedDiffDialogWC.OK) {
        try {
            if (dialog.isDiffToOutputFile())
                dialog.getOperation().run();
            if (!dialog.isDiffToOutputFile()) {
                SVNRevision pegRevision = dialog.getPegRevision();
                if (pegRevision == null) {
                    pegRevision = SVNRevision.HEAD;
                }
                if (resources[0] instanceof IContainer) {
                    ISVNRemoteFolder remoteFolder = new RemoteFolder(dialog.getSvnResource().getRepository(), dialog.getToUrl(), dialog.getToRevision());
                    ((RemoteFolder) remoteFolder).setPegRevision(pegRevision);
                    SVNLocalCompareInput compareInput = new SVNLocalCompareInput(dialog.getSvnResource(), remoteFolder, pegRevision);
                    compareInput.setDiffOperation(dialog.getOperation());
                    CompareUI.openCompareEditorOnPage(compareInput, getTargetPage());
                } else {
                    ISVNRemoteFile remoteFile = new RemoteFile(dialog.getSvnResource().getRepository(), dialog.getToUrl(), dialog.getToRevision());
                    ((RemoteFile) remoteFile).setPegRevision(pegRevision);
                    SVNLocalCompareInput compareInput = new SVNLocalCompareInput(dialog.getSvnResource(), remoteFile, pegRevision);
                    CompareUI.openCompareEditorOnPage(compareInput, getTargetPage());
                }
            }
        } catch (SVNException e) {
            MessageDialog.openError(getShell(), Policy.bind("ShowDifferencesAsUnifiedDiffDialog.branchTag"), e.getMessage());
        }
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) SVNLocalCompareInput(org.tigris.subversion.subclipse.ui.compare.SVNLocalCompareInput) IFile(org.eclipse.core.resources.IFile) RemoteFolder(org.tigris.subversion.subclipse.core.resources.RemoteFolder) ISVNRemoteFolder(org.tigris.subversion.subclipse.core.ISVNRemoteFolder) SvnWizardDialog(org.tigris.subversion.subclipse.ui.wizards.dialogs.SvnWizardDialog) SvnWizard(org.tigris.subversion.subclipse.ui.wizards.dialogs.SvnWizard) ShowDifferencesAsUnifiedDiffDialogWC(org.tigris.subversion.subclipse.ui.dialogs.ShowDifferencesAsUnifiedDiffDialogWC) SVNException(org.tigris.subversion.subclipse.core.SVNException) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource) ISVNRemoteFolder(org.tigris.subversion.subclipse.core.ISVNRemoteFolder) InvocationTargetException(java.lang.reflect.InvocationTargetException) SVNLocalBranchTagCompareInput(org.tigris.subversion.subclipse.ui.compare.SVNLocalBranchTagCompareInput) CoreException(org.eclipse.core.runtime.CoreException) ISVNRemoteFile(org.tigris.subversion.subclipse.core.ISVNRemoteFile) SvnWizardCompareMultipleResourcesWithBranchTagPage(org.tigris.subversion.subclipse.ui.wizards.dialogs.SvnWizardCompareMultipleResourcesWithBranchTagPage) SVNRevision(org.tigris.subversion.svnclientadapter.SVNRevision) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource) ISVNRemoteFile(org.tigris.subversion.subclipse.core.ISVNRemoteFile) RemoteFile(org.tigris.subversion.subclipse.core.resources.RemoteFile)

Example 52 with ISVNLocalResource

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

the class CommitAction method execute.

/*
   * get non added resources and prompts for resources to be added
   * prompts for comments
   * add non added files
   * commit selected files
   * @see SVNAction#execute(IAction)
   */
public void execute(IAction action) throws InvocationTargetException, InterruptedException {
    statusMap = new HashMap();
    final IResource[] resources = getSelectedResources();
    final List resourcesToBeAdded = new ArrayList();
    final List resourcesToBeDeleted = new ArrayList();
    if (action != null && !action.isEnabled()) {
        action.setEnabled(true);
    } else {
        run(new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException {
                try {
                    // search for modified or added, non-ignored resources in the selection.
                    IResource[] modified = getChangeSetResources(getModifiedResources(resources, monitor));
                    // if no changes since last commit, do not show commit dialog.
                    if (modified.length == 0) {
                        MessageDialog.openInformation(getShell(), Policy.bind("CommitDialog.title"), // $NON-NLS-1$ //$NON-NLS-2$
                        Policy.bind("CommitDialog.noChanges"));
                        commit = false;
                    } else {
                        ProjectProperties projectProperties = ProjectProperties.getProjectProperties(modified[0]);
                        commit = confirmCommit(modified, projectProperties);
                    }
                    // resources that were selected.
                    if (commit) {
                        for (int i = 0; i < resourcesToCommit.length; i++) {
                            IResource resource = resourcesToCommit[i];
                            ISVNLocalResource svnResource = SVNWorkspaceRoot.getSVNResourceFor(resource);
                            if (svnResource.exists() && !svnResource.isManaged())
                                resourcesToBeAdded.add(resource);
                            if (svnResource.getStatus().isMissing())
                                resourcesToBeDeleted.add(resource);
                        }
                    }
                } catch (TeamException e) {
                    throw new InvocationTargetException(e);
                }
            }
        }, true, /* cancelable */
        PROGRESS_BUSYCURSOR);
        if (!commit) {
            // user canceled
            return;
        }
        CommitOperation commitOperation = new CommitOperation(getTargetPart(), resources, (IResource[]) resourcesToBeAdded.toArray(new IResource[resourcesToBeAdded.size()]), (IResource[]) resourcesToBeDeleted.toArray(new IResource[resourcesToBeDeleted.size()]), resourcesToCommit, commitComment, keepLocks);
        commitOperation.setCanRunAsJob(canRunAsJob);
        commitOperation.run();
    }
}
Also used : TeamException(org.eclipse.team.core.TeamException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) HashMap(java.util.HashMap) CommitOperation(org.tigris.subversion.subclipse.ui.operations.CommitOperation) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ProjectProperties(org.tigris.subversion.subclipse.ui.settings.ProjectProperties) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource) IResource(org.eclipse.core.resources.IResource) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 53 with ISVNLocalResource

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

the class CommitAction method getModifiedResources.

/**
 * get the modified and unadded resources in resources parameter
 */
protected IResource[] getModifiedResources(IResource[] resources, IProgressMonitor iProgressMonitor) throws SVNException {
    boolean ignoreHiddenChanges = SVNProviderPlugin.getPlugin().getPluginPreferences().getBoolean(ISVNCoreConstants.PREF_IGNORE_HIDDEN_CHANGES);
    IResource[] allResources = getSelectedResources(true);
    List allSelections = new ArrayList();
    for (int i = 0; i < allResources.length; i++) allSelections.add(allResources[i]);
    List conflictFiles = new ArrayList();
    final List modified = new ArrayList();
    List unversionedFolders = new ArrayList();
    hasUnaddedResources = false;
    for (int i = 0; i < resources.length; i++) {
        IResource resource = resources[i];
        ISVNLocalResource svnResource = SVNWorkspaceRoot.getSVNResourceFor(resource);
        // This check is for when the action is called with unmanaged resources
        if (svnResource.getRepository() == null) {
            continue;
        }
        // if only one resource selected, get url.  Commit dialog displays this.
        if (resources.length == 1) {
            url = svnResource.getStatus().getUrlString();
            if ((url == null) || (resource.getType() == IResource.FILE))
                url = Util.getParentUrl(svnResource);
        }
        boolean descend = true;
        if (resource instanceof IContainer) {
            outer: for (int j = 0; j < allResources.length; j++) {
                if (allResources[j] == resource)
                    continue;
                IContainer parent = allResources[j].getParent();
                while (parent != null) {
                    if (parent.equals(resource)) {
                        descend = false;
                        break outer;
                    }
                    parent = parent.getParent();
                }
            }
        }
        // get adds, deletes, updates and property updates.
        GetStatusCommand command = new GetStatusCommand(svnResource, descend, false);
        command.run(iProgressMonitor);
        ISVNStatus[] statuses = command.getStatuses();
        boolean switched = false;
        for (int j = 0; j < statuses.length; j++) {
            if (SVNStatusUtils.isReadyForCommit(statuses[j]) || SVNStatusUtils.isMissing(statuses[j])) {
                IResource currentResource = SVNWorkspaceRoot.getResourceFor(resource, statuses[j]);
                if (currentResource != null && (descend == true || allSelections.contains(currentResource))) {
                    SVNProviderPlugin.getPlugin().getStatusCacheManager().updateCache(currentResource, statuses[j]);
                    ISVNLocalResource localResource = SVNWorkspaceRoot.getSVNResourceFor(currentResource);
                    if (!localResource.isIgnored()) {
                        if (!SVNStatusUtils.isManaged(statuses[j])) {
                            if (!Util.isHidden(currentResource)) {
                                hasUnaddedResources = true;
                                if ((currentResource.getType() != IResource.FILE) && !isSymLink(currentResource))
                                    unversionedFolders.add(currentResource);
                                else {
                                    if (!modified.contains(currentResource)) {
                                        modified.add(currentResource);
                                        if (currentResource instanceof IContainer)
                                            statusMap.put(currentResource, statuses[j].getPropStatus());
                                        else
                                            statusMap.put(currentResource, statuses[j].getTextStatus());
                                    }
                                }
                            }
                        } else if (!ignoreHiddenChanges || !Util.isHidden(currentResource)) {
                            if (!modified.contains(currentResource)) {
                                if (statuses[j].isSwitched()) {
                                    switched = true;
                                    url = statuses[j].getUrlString();
                                }
                                modified.add(currentResource);
                                if (currentResource instanceof IContainer)
                                    statusMap.put(currentResource, statuses[j].getPropStatus());
                                else {
                                    statusMap.put(currentResource, statuses[j].getTextStatus());
                                    if (SVNStatusUtils.isTextConflicted(statuses[j])) {
                                        IFile conflictNewFile = (IFile) File2Resource.getResource(statuses[j].getConflictNew());
                                        if (conflictNewFile != null)
                                            conflictFiles.add(conflictNewFile);
                                        IFile conflictOldFile = (IFile) File2Resource.getResource(statuses[j].getConflictOld());
                                        if (conflictOldFile != null)
                                            conflictFiles.add(conflictOldFile);
                                        IFile conflictWorkingFile = (IFile) File2Resource.getResource(statuses[j].getConflictWorking());
                                        if (conflictWorkingFile != null)
                                            conflictFiles.add(conflictWorkingFile);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        if (switched && modified.size() > 1) {
            url = null;
        }
    }
    IResource[] unaddedResources = getUnaddedResources(unversionedFolders, iProgressMonitor);
    for (int i = 0; i < unaddedResources.length; i++) if (!modified.contains(unaddedResources[i]))
        modified.add(unaddedResources[i]);
    Iterator iter = conflictFiles.iterator();
    while (iter.hasNext()) {
        IFile conflictFile = (IFile) iter.next();
        modified.remove(conflictFile);
        statusMap.remove(conflictFile);
    }
    return (IResource[]) modified.toArray(new IResource[modified.size()]);
}
Also used : IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) ISVNStatus(org.tigris.subversion.svnclientadapter.ISVNStatus) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource) Iterator(java.util.Iterator) GetStatusCommand(org.tigris.subversion.subclipse.core.commands.GetStatusCommand) ArrayList(java.util.ArrayList) List(java.util.List) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource)

Example 54 with ISVNLocalResource

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

the class CompareWithRemoteAction method execute.

public void execute(IAction action) {
    refresh = false;
    fileSelected = false;
    final IResource[] resources = getSelectedResources();
    if (resources.length != 1 && !SVNRevision.BASE.equals(revision) && !SVNRevision.HEAD.equals(revision)) {
        return;
    }
    for (int i = 0; i < resources.length; i++) {
        if (resources[i] instanceof IFile) {
            fileSelected = true;
            if (!resources[i].isSynchronized(Depth.immediates)) {
                refresh = MessageDialog.openQuestion(getShell(), Policy.bind("DifferencesDialog.compare"), Policy.bind("CompareWithRemoteAction.fileChanged"));
                break;
            }
        }
    }
    try {
        final ISVNLocalResource[] localResources = new ISVNLocalResource[resources.length];
        for (int i = 0; i < resources.length; i++) {
            localResources[i] = SVNWorkspaceRoot.getSVNResourceFor(resources[i]);
        }
        final ISVNLocalResource localResource = localResources[0];
        run(new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) {
                try {
                    if (refresh) {
                        for (int i = 0; i < localResources.length; i++) {
                            if (resources[i] instanceof IFile) {
                                localResources[i].getResource().refreshLocal(Depth.immediates, monitor);
                            }
                        }
                    }
                    if (SVNRevision.BASE.equals(revision)) {
                        if (localResources.length == 1 && localResource.getResource() instanceof IFile) {
                            SVNLocalCompareInput compareInput = new SVNLocalCompareInput(localResource, revision);
                            CompareUI.openCompareEditorOnPage(compareInput, getTargetPage());
                        } else {
                            SVNLocalBaseCompareInput compareInput = new SVNLocalBaseCompareInput(localResources, revision);
                            CompareUI.openCompareEditorOnPage(compareInput, getTargetPage());
                        }
                    } else {
                        if (!fileSelected) {
                            SVNLocalCompareSummaryInput compareInput = new SVNLocalCompareSummaryInput(localResources, revision);
                            CompareUI.openCompareEditorOnPage(compareInput, getTargetPage());
                        } else {
                            ISVNRemoteFile remoteFile = new RemoteFile(localResource.getRepository(), localResource.getUrl(), revision);
                            ((RemoteFile) remoteFile).setPegRevision(revision);
                            SVNLocalCompareInput compareInput = new SVNLocalCompareInput(localResource, remoteFile);
                            ShowDifferencesAsUnifiedDiffOperationWC operation = null;
                            if (SVNRevision.HEAD.equals(revision)) {
                                File file = File.createTempFile("revision", ".diff");
                                file.deleteOnExit();
                                operation = new ShowDifferencesAsUnifiedDiffOperationWC(getTargetPart(), localResource.getFile(), localResource.getUrl(), SVNRevision.HEAD, file);
                                operation.setGraphicalCompare(true);
                                operation.run();
                            }
                            compareInput.setDiffOperation(operation);
                            CompareUI.openCompareEditorOnPage(compareInput, getTargetPage());
                        }
                    }
                } catch (Exception e) {
                    handle(e, null, null);
                }
            }
        }, false, /* cancelable */
        PROGRESS_BUSYCURSOR);
    } catch (Exception e) {
        handle(e, null, null);
    }
}
Also used : SVNLocalCompareInput(org.tigris.subversion.subclipse.ui.compare.SVNLocalCompareInput) IFile(org.eclipse.core.resources.IFile) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource) SVNException(org.tigris.subversion.subclipse.core.SVNException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ShowDifferencesAsUnifiedDiffOperationWC(org.tigris.subversion.subclipse.ui.operations.ShowDifferencesAsUnifiedDiffOperationWC) ISVNRemoteFile(org.tigris.subversion.subclipse.core.ISVNRemoteFile) SVNLocalBaseCompareInput(org.tigris.subversion.subclipse.ui.compare.SVNLocalBaseCompareInput) SVNLocalCompareSummaryInput(org.tigris.subversion.subclipse.ui.compare.SVNLocalCompareSummaryInput) ISVNRemoteFile(org.tigris.subversion.subclipse.core.ISVNRemoteFile) File(java.io.File) RemoteFile(org.tigris.subversion.subclipse.core.resources.RemoteFile) IFile(org.eclipse.core.resources.IFile) IResource(org.eclipse.core.resources.IResource) ISVNRemoteFile(org.tigris.subversion.subclipse.core.ISVNRemoteFile) RemoteFile(org.tigris.subversion.subclipse.core.resources.RemoteFile)

Example 55 with ISVNLocalResource

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

the class ConfigureTagsAction method execute.

protected void execute(IAction action) throws InvocationTargetException, InterruptedException {
    IResource[] resources = getSelectedResources();
    ISVNLocalResource[] svnResources = new ISVNLocalResource[resources.length];
    ISVNProperty lastProperty = null;
    for (int i = 0; i < resources.length; i++) {
        svnResources[i] = SVNWorkspaceRoot.getSVNResourceFor(resources[i]);
        try {
            // $NON-NLS-1$
            ISVNProperty property = svnResources[i].getSvnProperty("subclipse:tags");
            if (i > 0 && !propertiesEqual(property, lastProperty)) {
                MessageDialog.openError(getShell(), Messages.ConfigureTagsAction_1, Messages.ConfigureTagsAction_2);
                return;
            }
            lastProperty = property;
        } catch (SVNException e) {
        }
    }
    SvnWizardConfigureTagsPage configureTagsPage = new SvnWizardConfigureTagsPage(svnResources);
    SvnWizard wizard = new SvnWizard(configureTagsPage);
    SvnWizardDialog dialog = new SvnWizardDialog(getShell(), wizard);
    wizard.setParentDialog(dialog);
    dialog.open();
}
Also used : SvnWizardDialog(org.tigris.subversion.subclipse.ui.wizards.dialogs.SvnWizardDialog) SvnWizard(org.tigris.subversion.subclipse.ui.wizards.dialogs.SvnWizard) ISVNProperty(org.tigris.subversion.svnclientadapter.ISVNProperty) SVNException(org.tigris.subversion.subclipse.core.SVNException) SvnWizardConfigureTagsPage(org.tigris.subversion.subclipse.ui.wizards.dialogs.SvnWizardConfigureTagsPage) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource) IResource(org.eclipse.core.resources.IResource)

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