Search in sources :

Example 11 with SVNTeamProvider

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

the class SVNSynchronizeOperation method run.

/* (non-Javadoc)
   * @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor)
   */
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
    // First, ask the user if they want to include conflicts
    SyncInfoSet syncSet = getSyncInfoSet();
    if (!promptForConflictHandling(getShell(), syncSet))
        return;
    // Divide the sync info by project
    final Map projectSyncInfos = getProjectSyncInfoSetMap(syncSet);
    monitor.beginTask(null, projectSyncInfos.size() * 100);
    for (Iterator iter = projectSyncInfos.keySet().iterator(); iter.hasNext(); ) {
        final IProject project = (IProject) iter.next();
        // Pass the scheduling rule to the synchronizer so that sync change events
        // and cache commits to disk are batched
        SVNTeamProvider provider = (SVNTeamProvider) RepositoryProvider.getProvider(project, SVNUIPlugin.PROVIDER_ID);
        if (provider != null) {
            run(provider, (SyncInfoSet) projectSyncInfos.get(project), Policy.subMonitorFor(monitor, 100));
        }
    }
    monitor.done();
}
Also used : SVNTeamProvider(org.tigris.subversion.subclipse.core.SVNTeamProvider) Iterator(java.util.Iterator) SyncInfoSet(org.eclipse.team.core.synchronize.SyncInfoSet) HashMap(java.util.HashMap) Map(java.util.Map) IProject(org.eclipse.core.resources.IProject)

Example 12 with SVNTeamProvider

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

the class UnmanageAction method getOperation.

/**
 * get the WorkspaceModifyOperation. The operation will : - delete svn directories if this option
 * has been chosen - unmap the project
 *
 * @return
 */
private IRunnableWithProgress getOperation() {
    return new WorkspaceModifyOperation() {

        public void execute(IProgressMonitor monitor) throws InvocationTargetException {
            try {
                // maps the selected resources (projects) to their providers
                Hashtable table = getProviderMapping(getSelectedResources());
                Set keySet = table.keySet();
                // $NON-NLS-1$
                monitor.beginTask("", keySet.size() * 1000);
                // $NON-NLS-1$
                monitor.setTaskName(Policy.bind("Unmanage.unmanaging"));
                Iterator iterator = keySet.iterator();
                while (iterator.hasNext()) {
                    IProgressMonitor subMonitor = new InfiniteSubProgressMonitor(monitor, 1000);
                    subMonitor.beginTask(null, 100);
                    SVNTeamProvider provider = (SVNTeamProvider) iterator.next();
                    // get the resources (projects) to unmanage for the given provider
                    List list = (List) table.get(provider);
                    IResource[] providerResources = (IResource[]) list.toArray(new IResource[list.size()]);
                    for (int i = 0; i < providerResources.length; i++) {
                        // get the folder for the project
                        IResource resource = providerResources[i];
                        ISVNLocalFolder folder = SVNWorkspaceRoot.getSVNFolderFor((IContainer) resource);
                        try {
                            if (deleteContent) {
                                folder.unmanage(Policy.subMonitorFor(subMonitor, 10));
                            }
                        } finally {
                            // We want to remove the nature even if the unmanage operation fails
                            RepositoryProvider.unmap((IProject) resource);
                        }
                    }
                }
            } catch (TeamException e) {
                throw new InvocationTargetException(e);
            } finally {
                monitor.done();
            }
        }
    };
}
Also used : Set(java.util.Set) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) Hashtable(java.util.Hashtable) InvocationTargetException(java.lang.reflect.InvocationTargetException) ISVNLocalFolder(org.tigris.subversion.subclipse.core.ISVNLocalFolder) TeamException(org.eclipse.team.core.TeamException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) SVNTeamProvider(org.tigris.subversion.subclipse.core.SVNTeamProvider) InfiniteSubProgressMonitor(org.tigris.subversion.subclipse.core.internal.InfiniteSubProgressMonitor) Iterator(java.util.Iterator) List(java.util.List) IResource(org.eclipse.core.resources.IResource)

Example 13 with SVNTeamProvider

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

the class UnlockAction method execute.

protected void execute(IAction action) throws InvocationTargetException, InterruptedException {
    if (action != null && !action.isEnabled()) {
        action.setEnabled(true);
    } else {
        if (getSelectedResources() != null && getSelectedResources().length > 0) {
            final IResource[] resources = getSelectedResources();
            run(new WorkspaceModifyOperation() {

                protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
                    try {
                        Hashtable table = getProviderMapping(getSelectedResources());
                        Set keySet = table.keySet();
                        Iterator iterator = keySet.iterator();
                        while (iterator.hasNext()) {
                            SVNTeamProvider provider = (SVNTeamProvider) iterator.next();
                            UnlockResourcesCommand command = new UnlockResourcesCommand(provider.getSVNWorkspaceRoot(), resources, false);
                            command.run(Policy.subMonitorFor(monitor, 1000));
                        }
                    } catch (TeamException e) {
                        throw new InvocationTargetException(e);
                    } finally {
                        monitor.done();
                    }
                }
            }, true, /* cancelable */
            PROGRESS_DIALOG);
        }
    }
}
Also used : Set(java.util.Set) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) Hashtable(java.util.Hashtable) UnlockResourcesCommand(org.tigris.subversion.subclipse.core.commands.UnlockResourcesCommand) InvocationTargetException(java.lang.reflect.InvocationTargetException) TeamException(org.eclipse.team.core.TeamException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) SVNTeamProvider(org.tigris.subversion.subclipse.core.SVNTeamProvider) CoreException(org.eclipse.core.runtime.CoreException) Iterator(java.util.Iterator) IResource(org.eclipse.core.resources.IResource)

Example 14 with SVNTeamProvider

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

the class SVNFileModificationValidator method validateEdit.

public IStatus validateEdit(IFile[] files, Object context) {
    String comment = "";
    boolean stealLock = false;
    // reduce the array to just read only files
    ReadOnlyFiles readOnlyFiles = processFileArray(files);
    if (readOnlyFiles.size() == 0)
        return Status.OK_STATUS;
    // of the read-only files, get array of ones which are versioned
    IFile[] managedFiles = readOnlyFiles.getManaged();
    if (managedFiles.length > 0) {
        // Prompt user to lock files
        if (context != null) {
            ISVNFileModificationValidatorPrompt svnFileModificationValidatorPrompt = SVNProviderPlugin.getPlugin().getSvnFileModificationValidatorPrompt();
            if (svnFileModificationValidatorPrompt != null) {
                if (!svnFileModificationValidatorPrompt.prompt(managedFiles, context))
                    return Status.CANCEL_STATUS;
                comment = svnFileModificationValidatorPrompt.getComment();
                stealLock = svnFileModificationValidatorPrompt.isStealLock();
            }
        }
        // Run the svn lock command
        RepositoryProvider provider = RepositoryProvider.getProvider(managedFiles[0].getProject());
        if ((provider != null) && (provider instanceof SVNTeamProvider)) {
            SVNTeamProvider svnTeamProvider = (SVNTeamProvider) provider;
            LockResourcesCommand command = new LockResourcesCommand(svnTeamProvider.getSVNWorkspaceRoot(), managedFiles, stealLock, comment, false);
            try {
                command.run(new NullProgressMonitor());
            } catch (SVNException e) {
                SVNProviderPlugin.log(IStatus.ERROR, e.getMessage(), e);
                return Status.CANCEL_STATUS;
            }
        }
    }
    // Process any unmanaged but read-only files.  For
    // those we need to prompt the user to flip the read only bit
    IFile[] unManagedFiles = readOnlyFiles.getUnManaged();
    if (unManagedFiles.length > 0) {
        synchronized (this) {
            if (uiValidator == null)
                uiValidator = loadUIValidator();
        }
        if (uiValidator != null) {
            return uiValidator.validateEdit(unManagedFiles, context);
        }
        // There was no plugged in validator so fail gracefully
        return getStatus(unManagedFiles);
    }
    return Status.OK_STATUS;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) SVNTeamProvider(org.tigris.subversion.subclipse.core.SVNTeamProvider) IFile(org.eclipse.core.resources.IFile) LockResourcesCommand(org.tigris.subversion.subclipse.core.commands.LockResourcesCommand) SVNException(org.tigris.subversion.subclipse.core.SVNException) RepositoryProvider(org.eclipse.team.core.RepositoryProvider)

Example 15 with SVNTeamProvider

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

the class SVNMoveDeleteHook method moveFile.

/*
   * (non-Javadoc)
   *
   * @see org.eclipse.core.resources.team.IMoveDeleteHook#moveFile(org.eclipse.core.resources.team.IResourceTree,
   *      org.eclipse.core.resources.IFile, org.eclipse.core.resources.IFile,
   *      int, org.eclipse.core.runtime.IProgressMonitor)
   */
public boolean moveFile(IResourceTree tree, IFile source, IFile destination, int updateFlags, IProgressMonitor monitor) {
    if (SVNWorkspaceRoot.isLinkedResource(source))
        return false;
    try {
        RepositoryProvider repositoryProvider = RepositoryProvider.getProvider(destination.getProject());
        if (repositoryProvider == null || // target is not SVN project
        !(repositoryProvider instanceof SVNTeamProvider))
            return false;
        ISVNLocalFile resource = new LocalFile(source);
        // pass
        if (!resource.isManaged())
            return false;
        ISVNRepositoryLocation sourceRepository = resource.getRepository();
        ISVNClientAdapter svnClient = sourceRepository.getSVNClient();
        ISVNLocalResource parent = SVNWorkspaceRoot.getSVNResourceFor(destination.getParent());
        ISVNRepositoryLocation targetRepository = parent.getRepository();
        if (!sourceRepository.equals(targetRepository)) {
            return false;
        }
        monitor.beginTask(null, 1000);
        try {
            OperationManager.getInstance().beginOperation(svnClient);
            // see bug #15
            if (!SVNWorkspaceRoot.getSVNFolderFor(destination.getParent()).isManaged()) {
                SVNTeamProvider provider = (SVNTeamProvider) repositoryProvider;
                provider.add(new IResource[] { destination.getParent() }, IResource.DEPTH_ZERO, new NullProgressMonitor());
                if (parent != null)
                    parent.refreshStatus();
            }
            // force is set to true because when we rename (refactor) a
            // java class, the file is modified before being moved
            // A modified file cannot be moved without force
            svnClient.move(source.getLocation().toFile(), destination.getLocation().toFile(), true);
            // movedFile must be done before endOperation because
            // destination file must not already exist in the workspace
            // resource tree.
            tree.movedFile(source, destination);
            destination.refreshLocal(IResource.DEPTH_ZERO, monitor);
        } catch (SVNClientException e) {
            throw SVNException.wrapException(e);
        } catch (TeamException e) {
            throw SVNException.wrapException(e);
        } catch (CoreException e) {
            throw SVNException.wrapException(e);
        } finally {
            resource.getRepository().returnSVNClient(svnClient);
            OperationManager.getInstance().endOperation(false, null, false);
        }
    } catch (SVNException e) {
        tree.failed(e.getStatus());
    } finally {
        monitor.done();
    }
    return true;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) TeamException(org.eclipse.team.core.TeamException) SVNTeamProvider(org.tigris.subversion.subclipse.core.SVNTeamProvider) ISVNLocalFile(org.tigris.subversion.subclipse.core.ISVNLocalFile) ISVNRepositoryLocation(org.tigris.subversion.subclipse.core.ISVNRepositoryLocation) CoreException(org.eclipse.core.runtime.CoreException) SVNClientException(org.tigris.subversion.svnclientadapter.SVNClientException) ISVNLocalFile(org.tigris.subversion.subclipse.core.ISVNLocalFile) SVNException(org.tigris.subversion.subclipse.core.SVNException) RepositoryProvider(org.eclipse.team.core.RepositoryProvider) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource) ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter)

Aggregations

SVNTeamProvider (org.tigris.subversion.subclipse.core.SVNTeamProvider)24 IResource (org.eclipse.core.resources.IResource)14 Iterator (java.util.Iterator)12 ArrayList (java.util.ArrayList)11 List (java.util.List)9 TeamException (org.eclipse.team.core.TeamException)9 HashMap (java.util.HashMap)8 Set (java.util.Set)8 IProject (org.eclipse.core.resources.IProject)8 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)8 SVNException (org.tigris.subversion.subclipse.core.SVNException)8 Map (java.util.Map)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 Hashtable (java.util.Hashtable)5 CoreException (org.eclipse.core.runtime.CoreException)5 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)5 RepositoryProvider (org.eclipse.team.core.RepositoryProvider)5 SyncInfoSet (org.eclipse.team.core.synchronize.SyncInfoSet)5 ISVNLocalResource (org.tigris.subversion.subclipse.core.ISVNLocalResource)5 ISVNRepositoryLocation (org.tigris.subversion.subclipse.core.ISVNRepositoryLocation)5