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 Matt McCutchen <hashproduct+eclipse@gmail.com> - Bug 179174 CVS client sets timestamps back when replacing /
 
 package org.eclipse.team.internal.ccvs.ui.operations;
 
 import java.util.*;
 
This operation replaces the local resources with their remote contents
 
 public class ReplaceOperation extends UpdateOperation {
 
 	public ReplaceOperation(IWorkbenchPart partIResource[] resourcesCVSTag tagboolean recurse) {
 		super(partasResourceMappers(resourcesrecurse ? . : .), new LocalOption[] { . }, tag);
 	}
 
 	public ReplaceOperation(IWorkbenchPart partResourceMapping[] mappingsCVSTag tag) {
         super(partmappingsnew LocalOption[] { . }, tag);
     }
 
     /* (non-Javadoc)
 	 * @see org.eclipse.team.internal.ccvs.ui.operations.CVSOperation#getTaskName()
 	 */
 	protected String getTaskName() {
 	}
 
 	/* (non-Javadoc)
 	 * @see org.eclipse.team.internal.ccvs.ui.operations.SingleCommandOperation#executeCommand(org.eclipse.team.internal.ccvs.core.client.Session, org.eclipse.team.internal.ccvs.core.CVSTeamProvider, org.eclipse.core.resources.IResource[], org.eclipse.core.runtime.IProgressMonitor)
 	 */
 	protected IStatus executeCommand(
 		final Session session,
 		final CVSTeamProvider provider,
 		final ICVSResource[] resources,
 		final boolean recurseIProgressMonitor monitor)
 		
         final IStatus[] status = new IStatus[] { . };
         try {
             ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
                 public void run(IProgressMonitor monitorthrows CoreException {
                     try {
                         status[0] = internalExecuteCommand(sessionproviderresourcesrecursemonitor);
                     } catch (InterruptedException e) {
                         throw new OperationCanceledException();
                     }
                 }
             
             }, null.monitor);
         } catch (CoreException e) {
             throw CVSException.wrapException(e);
         }
 		return status[0];
 	}
 
 	// Files deleted by the PrepareForReplaceVisitor.
 	private Set/*<ICVSFile>*/ prepDeletedFiles;

Tells whether resources for which the given tag does not exists, are ignored by the replace operation.
 
 
 
     private IStatus internalExecuteCommand(Session sessionCVSTeamProvider providerICVSResource[] resourcesboolean recurseIProgressMonitor monitorthrows CVSExceptionInterruptedException {
         monitor.beginTask(null, 100);
         ICVSResource[] managedResources = getResourcesToUpdate(resources, Policy.subMonitorFor(monitor, 5));
 		if ( && managedResources.length == 0)
 			return ;
 
         try {
         	// Purge any unmanaged or added files
         	PrepareForReplaceVisitor pfrv = new PrepareForReplaceVisitor(sessiongetTag());
        	pfrv.visitResources(
        		provider.getProject(), 
        		resources
        		recurse ? . : .
        		Policy.subMonitorFor(monitor, 25));
        	 = pfrv.getDeletedFiles();
        	
        	// Only perform the remote command if some of the resources being replaced were managed
        	IStatus status = ;
        	if (managedResources.length > 0) {
        		// Perform an update, ignoring any local file modifications
        		status = super.executeCommand(sessionprovidermanagedResourcesrecurse, Policy.subMonitorFor(monitor, 70));
        	}
        	
        	// Prune any empty folders left after the resources were purged.
        	// This is done to prune any empty folders that contained only unmanaged resources
        	if (status.isOK() && CVSProviderPlugin.getPlugin().getPruneEmptyDirectories()) {
        		new PruneFolderVisitor().visit(sessionresources);
        	}
        	
        	return status;
        } finally {
        	monitor.done();
        }
    }

Return the resources that need to be updated from the server. By default, this is all resources that are managed.

Parameters:
resources all resources being replaced
Returns:
resources that are to be updated from the server
Throws:
org.eclipse.team.internal.ccvs.core.CVSException
	protected ICVSResource[] getResourcesToUpdate(ICVSResource[] resourcesIProgressMonitor monitorthrows CVSException {
		// Accumulate the managed resources from the list of provided resources
		List managedResources = new ArrayList();
		monitor.beginTask(nullresources.length * 100);
		for (int i = 0; i < resources.lengthi++) {
			ICVSResource resource = resources[i];
			if ((resource.isFolder() && ((ICVSFolder)resource).isCVSFolder())) {
				addResourceIfTagExists(managedResourcesresource, Policy.subMonitorFor(monitor, 100));
else if (!resource.isFolder()){
				byte[] syncBytes = ((ICVSFile)resource).getSyncBytes();
				if (syncBytes != null && !ResourceSyncInfo.isAddition(syncBytes)) {
					addResourceIfTagExists(managedResourcesresource, Policy.subMonitorFor(monitor, 100));
				}
			}
		}
		monitor.done();
		return (ICVSResource[]) managedResources.toArray(new ICVSResource[managedResources.size()]);
	}
	private void addResourceIfTagExists(List managedResourcesICVSResource resourceIProgressMonitor monitor) {
		CVSTag tag = getTag();
		if (tag == null || tag.getType() == . || tag.isHeadTag() || tag.isBaseTag()) {
			// No need to check for date, head or base tags
			managedResources.add(resource);
else {
			TagSource tagSource= TagSource.create(new ICVSResource[] { resource });
			if (isTagPresent(tagSourcetag)) {
				managedResources.add(resource);
else {
				// If the tag usn't present, lets refresh just to make sure
				try {
					tagSource.refresh(falsemonitor);
					if (isTagPresent(tagSourcetag)) {
						managedResources.add(resource);
else {
						tagSource.refresh(truemonitor);
						if (isTagPresent(tagSourcetag)) {
							managedResources.add(resource);
						}
					}
catch (TeamException e) {
					CVSUIPlugin.log(e);
				}
			}
		}
	}
	private boolean isTagPresent(TagSource tagSourceCVSTag tag) {
		return Arrays.asList(tags).contains(tag);
	}
	/* (non-Javadoc)
	 * @see org.eclipse.team.internal.ccvs.ui.operations.UpdateOperation#getUpdateCommand()
	 */
	protected Update getUpdateCommand() {
		// Use a special replace command that doesn't set back the timestamps
		// of files in the passed set if it recreates them.
	}
	/* (non-Javadoc)
	 * @see org.eclipse.team.internal.ccvs.ui.operations.RepositoryProviderOperation#getTaskName(org.eclipse.team.internal.ccvs.core.CVSTeamProvider)
	 */
	protected String getTaskName(CVSTeamProvider provider) {
		return NLS.bind(.new String[] { provider.getProject().getName() }); 
	}

Tells to ignore resources for which the given tag does not exists.
	}
New to GrepCode? Check out our FAQ X