Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2000, 2010 IBM Corporation and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: IBM Corporation - initial API and implementation /
 
 package org.eclipse.team.internal.ccvs.ui.operations;
 
 import java.util.*;
 
Performs a CVS operation on multiple repository providers
 
 public abstract class RepositoryProviderOperation extends CVSOperation {

Flag to indicate whether models are to be consulted when building the scope. This is provided for testing purposes and is not expected to be used otherwise.
 
 	public static boolean consultModelsWhenBuildingScope = true;
 	
 	private final ResourceMapping[] selectedMappings;

    
Interface that is available to subclasses which identifies the depth for various resources. The files will be included in whichever group (deep or shallow) has resources.
 
     public interface ICVSTraversal {
         IResource[] getShallowResources();
         IResource[] getDeepResources();
         IResource[] getNontraversedFolders();
     }
     
 	/*
 	 * A map entry for a provider that divides the traversals to be performed by depth.
 	 * There are really only 
 	 */
 	private static class TraversalMapEntry implements ICVSTraversal {
 	    // The provider for this entry
 	    // Files are always shallow
 	    List files = new ArrayList();
 	    // Not sure what to do with zero depth folders but we'll record them
 	    List zeroFolders = new ArrayList();
 	    // Non-recursive folder (-l)
 	    List shallowFolders = new ArrayList();
 	    // Recursive folders (-R)
 	    List deepFolders = new ArrayList();
         public TraversalMapEntry(RepositoryProvider provider) {
             this. = provider;
         }
        
Add the resources from the traversals to the entry

Parameters:
traversals the traversals
 
         public void add(ResourceTraversal[] traversals) {
             for (int i = 0; i < traversals.lengthi++) {
                 ResourceTraversal traversal = traversals[i];
                 add(traversal);
             }
         }
    
Add the resources from the traversal to the entry

Parameters:
traversal the traversal
 
 	    public void add(ResourceTraversal traversal) {
 	        IResource[] resources = traversal.getResources();
 	        for (int i = 0; i < resources.lengthi++) {
                 IResource resource = resources[i];
                if (resource.getProject().equals(.getProject())) {
	                if (resource.getType() == .) {
	                    .add(resource);
	                } else {
				        switch (traversal.getDepth()) {
			            case .:
			                .add(resource);
			                break;
			            case .:
			                .add(resource);
			                break;
			            case .:
			                .add(resource);
			                break;
			            default:
			                .add(resource);
			            }
	                }
                }
            }
	    }
    
Return the resources that can be included in a shallow operation. Include files with the shallow resources if there are shallow folders or if there are no shallow or deep folders.

Returns:
the resources that can be included in a shallow operation
	    public IResource[] getShallowResources() {
	        if (.isEmpty() && .isEmpty() && !.isEmpty()) {
	            return (IResource[]) .toArray(new IResource[.size()]);
	        }
	        if (!.isEmpty()) {
	            if (.isEmpty()) {
	                return (IResource[]) .toArray(new IResource[.size()]);
	            }
	            List result = new ArrayList();
	            result.addAll();
	            result.addAll();
	            return (IResource[]) result.toArray(new IResource[result.size()]);
	        }
	        return new IResource[0];
	    }
    
Return the resources to be included in a deep operation. If there are no shallow folders, this will include any files.

Returns:
	    public IResource[] getDeepResources() {
	        if (.isEmpty())
	            return new IResource[0];
	        if (!.isEmpty())
	            return (IResource[]) .toArray(new IResource[.size()]);
            List result = new ArrayList();
            result.addAll();
            result.addAll();
            return (IResource[]) result.toArray(new IResource[result.size()]);
	    }
    
Return the folders that are depth zero
	    public IResource[] getNontraversedFolders() {
	        return (IResource[]) .toArray(new IResource[.size()]);
	    }
	}

    
    
Convert the provided resources to one or more resource mappers that traverse the elements deeply. The model element of the resource mappers will be an IStructuredSelection.

Parameters:
resources the resources
Returns:
a resource mappers that traverses the resources
    public static ResourceMapping[] asResourceMappers(final IResource[] resources) {
        return asResourceMappers(resources.);
    }
    
    
Convert the provided resources to one or more resource mappers that traverse the elements deeply. The model element of the resource mappers will be an IStructuredSelection.

Parameters:
resources the resources
Returns:
a resource mappers that traverses the resources
    public static ResourceMapping[] asResourceMappers(final IResource[] resourcesint depth) {
        return WorkspaceResourceMapper.asResourceMappers(resourcesdepth);
    }
    
	public RepositoryProviderOperation(IWorkbenchPart partfinal IResource[] resources) {
		this(partasResourceMappers(resources));
	}
    public RepositoryProviderOperation(IWorkbenchPart partResourceMapping[] selectedMappings) {
        super(part);
		this. = selectedMappings;
    }
    /* (non-Javadoc)
	 * @see org.eclipse.team.internal.ccvs.ui.operations.CVSOperation#execute(org.eclipse.core.runtime.IProgressMonitor)
	 */
	public void execute(IProgressMonitor monitorthrows CVSExceptionInterruptedException {
		try {
            monitor.beginTask(null, 100);
            buildScope(monitor);
            Map table = getProviderTraversalMapping(Policy.subMonitorFor(monitor, 30));
            execute(table, Policy.subMonitorFor(monitor, 30));
        } catch (CoreException e) {
            throw CVSException.wrapException(e);
        } finally {
            monitor.done();
        }
	}
	protected void endOperation() throws CVSException {
    	if ( != null) {
    		.dispose();
    		 = null;
    	}
		super.endOperation();
	}
    	if ( == null) {
			try {
				op.run(monitor);
catch (InvocationTargetException e) {
				throw CVSException.wrapException(e);
			}
    	}
    	return .getScope();
	}

    
Create the scope manager to be used by this operation.

Parameters:
consultModels whether models should be consulted to include additional mappings
Returns:
a scope manager
	protected SynchronizationScopeManager createScopeManager(boolean consultModels) {
	}
	private void execute(Map providerTraversalIProgressMonitor monitorthrows CVSExceptionInterruptedException {
        Set keySet = providerTraversal.keySet();
        monitor.beginTask(nullkeySet.size() * 1000);
        Iterator iterator = keySet.iterator();
        while (iterator.hasNext()) {
        	CVSTeamProvider provider = (CVSTeamProvider)iterator.next();
        	monitor.setTaskName(getTaskName(provider));
        	TraversalMapEntry entry = (TraversalMapEntry)providerTraversal.get(provider);
        	execute(providerentry, Policy.subMonitorFor(monitor, 1000));
        }
    }

    
Execute the operation on the given set of traversals

    protected void execute(CVSTeamProvider providerICVSTraversal entryIProgressMonitor monitorthrows CVSExceptionInterruptedException {
        IResource[] deepResources = entry.getDeepResources();
        IResource[] shallowResources = entry.getShallowResources();
        IResource[] nontraversedFolders = entry.getNontraversedFolders();
        try {
	        monitor.beginTask(getTaskName(provider), (deepResources.length > 0 ? 100 : 0) + (shallowResources.length > 0 ? 100 : 0) + (nontraversedFolders.length > 0 ? 10 : 0));
	        if (deepResources.length == 0 && shallowResources.length == 0 && nontraversedFolders.length == 0)
	        	return;
	        final ISchedulingRule rule = getSchedulingRule(provider);
	        try {
	        	Job.getJobManager().beginRule(rulemonitor);
	            if (deepResources.length > 0)
	                execute(providerdeepResourcestrue /* recurse */, Policy.subMonitorFor(monitor, 100));
	            if (shallowResources.length > 0)
	                execute(providershallowResourcesfalse /* recurse */, Policy.subMonitorFor(monitor, 100));
	            if (nontraversedFolders.length > 0) {
	                handleNontraversedFolders(providernontraversedFolders, Policy.subMonitorFor(monitor, 10));
	            }
	        } finally {
	        	Job.getJobManager().endRule(rule);
	        }
        } finally {
            monitor.done();
        }
    }

Handle any non-traversed (depth-zero) folders that were in the logical modle that primed this operation.

Parameters:
provider the repository provider associated with the project containing the folders
nontraversedFolders the folders
monitor a progress monitor
    protected void handleNontraversedFolders(CVSTeamProvider providerIResource[] nontraversedFoldersIProgressMonitor monitorthrows CVSException {
        // Default is do nothing
    }

    
Return the taskname to be shown in the progress monitor while operating on the given provider.

Parameters:
provider the provider being processed
Returns:
the taskname to be shown in the progress monitor
	protected abstract String getTaskName(CVSTeamProvider provider);

Retgurn the scheduling rule to be obtained before work begins on the given provider. By default, it is the provider's project. This can be changed by subclasses.

Parameters:
provider
Returns:
		return provider.getProject();
	}
	/*
	 * Helper method. Return a Map mapping provider to a list of resources
	 * shared with that provider.
	 */
		Map result = new HashMap();
        for (int j = 0; j < mappings.lengthj++) {
            ResourceMapping mapping = mappings[j];
            IProject[] projects = mapping.getProjects();
            ResourceTraversal[] traversals = getScope().getTraversals(mapping);
            for (int k = 0; k < projects.lengthk++) {
                IProject project = projects[k];
                RepositoryProvider provider = RepositoryProvider.getProvider(project, CVSProviderPlugin.getTypeId());
                if (provider != null) {
                    TraversalMapEntry entry = (TraversalMapEntry)result.get(provider);
                    if (entry == null) {
                        entry = new TraversalMapEntry(provider);
                        result.put(providerentry);
                    }
                    entry.add(traversals);
                } 
            }
        }
		return result;
	}

    
Return the resource mapping context that is to be used by this operation. By default, null is returned but subclasses may override to provide a specific context.

Returns:
the resource mapping context for this operation
        return .;
    }

    
Execute the operation on the resources for the given provider.

Parameters:
provider the provider for the project that contains the resources
resources the resources to be operated on
recurse whether the operation is deep or shallow
monitor a progress monitor
Throws:
org.eclipse.team.internal.ccvs.core.CVSException
java.lang.InterruptedException
	protected abstract void execute(CVSTeamProvider providerIResource[] resourcesboolean recurseIProgressMonitor monitorthrows CVSExceptionInterruptedException;

    
Return the local options for this operation including the option to provide the requested traversal.

Parameters:
recurse deep or shallow
Returns:
the local options for the operation
    protected LocalOption[] getLocalOptions(boolean recurse) {
        if (!recurse) {
            return new LocalOption[] { . };
        }
        return .;
    }
    
	protected ICVSResource[] getCVSArguments(IResource[] resources) {
		ICVSResource[] cvsResources = new ICVSResource[resources.length];
		for (int i = 0; i < cvsResources.lengthi++) {
			cvsResources[i] = CVSWorkspaceRoot.getCVSResourceFor(resources[i]);
		}
		return cvsResources;
	}
	/*
	 * Get the arguments to be passed to a commit or update
	 */
	protected String[] getStringArguments(IResource[] resourcesthrows CVSException {
		List arguments = new ArrayList(resources.length);
		for (int i=0;i<resources.length;i++) {
			IPath cvsPath = resources[i].getFullPath().removeFirstSegments(1);
			if (cvsPath.segmentCount() == 0) {
else {
				arguments.add(cvsPath.toString());
			}
		}
		return (String[])arguments.toArray(new String[arguments.size()]);
	}
		CVSWorkspaceRoot workspaceRoot = provider.getCVSWorkspaceRoot();
		return workspaceRoot.getRemoteLocation();
	}
	protected ICVSFolder getLocalRoot(CVSTeamProvider providerthrows CVSException {
		CVSWorkspaceRoot workspaceRoot = provider.getCVSWorkspaceRoot();
		return workspaceRoot.getLocalRoot();
	}

Update the workspace subscriber for an update operation performed on the given resources. After an update, the remote tree is flushed in order to ensure that stale incoming additions are removed. This need only be done for folders. At the time of writing, all update operations are deep so the flush is deep as well.

Parameters:
provider the provider (project) for all the given resources
resources the resources that were updated
recurse
monitor a progress monitor
	protected void updateWorkspaceSubscriber(CVSTeamProvider providerICVSResource[] resourcesboolean recurseIProgressMonitor monitor) {
		monitor.beginTask(null, 100 * resources.length);
		for (int i = 0; i < resources.lengthi++) {
			ICVSResource resource = resources[i];
			if (resource.isFolder()) {
				try {
					s.updateRemote(provider, (ICVSFolder)resourcerecurse, Policy.subMonitorFor(monitor, 100));
catch (TeamException e) {
					// Just log the error and continue
					CVSUIPlugin.log(e);
				}
else {
				monitor.worked(100);
			}
		}
	}
	/* (non-Javadoc)
     * @see org.eclipse.team.ui.TeamOperation#isKeepOneProgressServiceEntry()
     */
    public boolean isKeepOneProgressServiceEntry() {
        // Keep the last repository provider operation in the progress service
        return true;
    }
    
    /* (non-Javadoc)
     * @see org.eclipse.team.ui.TeamOperation#getGotoAction()
     */
    protected IAction getGotoAction() {
        return getShowConsoleAction();
    }
    
    
Return the root resources for all the traversals of this operation. This method may only be invoked after .

Returns:
the root resources for all the traversals of this operation
Throws:
org.eclipse.core.runtime.CoreException
    protected IResource[] getTraversalRoots() {
        List result = new ArrayList();
        ResourceTraversal[] traversals = getTraversals();
        for (int i = 0; i < traversals.lengthi++) {
            ResourceTraversal traversal = traversals[i];
            result.addAll(Arrays.asList(traversal.getResources()));
        }
        return (IResource[]) result.toArray(new IResource[result.size()]);
    }
    
    
Return the traversals that will be used by this operation. This method can only be called after .

Returns:
the traversals that will be used by this operation
Throws:
org.eclipse.core.runtime.CoreException
    public ResourceTraversal[] getTraversals() {
        return getScope().getTraversals();
    }
    
    public boolean consultModelsForMappings() {
    	return true;
    }
	}
		return .getScope();
	}
		return ;
	}
New to GrepCode? Check out our FAQ X