1 11 package org.eclipse.team.core.mapping; 12 13 import java.util.HashSet ; 14 import java.util.Set ; 15 16 import org.eclipse.core.resources.IProject; 17 import org.eclipse.core.resources.mapping.*; 18 import org.eclipse.core.runtime.*; 19 import org.eclipse.core.runtime.jobs.ISchedulingRule; 20 import org.eclipse.core.runtime.jobs.MultiRule; 21 import org.eclipse.team.core.diff.IDiff; 22 import org.eclipse.team.core.mapping.provider.MergeStatus; 23 24 38 public abstract class ResourceMappingMerger implements IResourceMappingMerger { 39 40 43 public IStatus validateMerge(IMergeContext mergeContext, IProgressMonitor monitor) { 44 return Status.OK_STATUS; 45 } 46 47 51 protected abstract ModelProvider getModelProvider(); 52 53 64 public ISchedulingRule getMergeRule(IMergeContext context) { 65 ResourceMapping[] mappings = context.getScope().getMappings(getModelProvider().getId()); 66 ISchedulingRule rule = null; 67 for (int i = 0; i < mappings.length; i++) { 68 ResourceMapping mapping = mappings[i]; 69 IProject[] mappingProjects = mapping.getProjects(); 70 for (int j = 0; j < mappingProjects.length; j++) { 71 IProject project = mappingProjects[j]; 72 if (rule == null) { 73 rule = project; 74 } else { 75 rule = MultiRule.combine(rule, project); 76 } 77 } 78 } 79 return rule; 80 } 81 82 91 public IStatus merge(IMergeContext mergeContext, IProgressMonitor monitor) throws CoreException { 92 IDiff[] deltas = getSetToMerge(mergeContext); 93 IStatus status = mergeContext.merge(deltas, false , monitor); 94 return covertFilesToMappings(status, mergeContext); 95 } 96 97 private IDiff[] getSetToMerge(IMergeContext mergeContext) { 98 ResourceMapping[] mappings = mergeContext.getScope().getMappings(getModelProvider().getDescriptor().getId()); 99 Set result = new HashSet (); 100 for (int i = 0; i < mappings.length; i++) { 101 ResourceMapping mapping = mappings[i]; 102 ResourceTraversal[] traversals = mergeContext.getScope().getTraversals(mapping); 103 IDiff[] deltas = mergeContext.getDiffTree().getDiffs(traversals); 104 for (int j = 0; j < deltas.length; j++) { 105 IDiff delta = deltas[j]; 106 result.add(delta); 107 } 108 } 109 return (IDiff[]) result.toArray(new IDiff[result.size()]); 110 } 111 112 private IStatus covertFilesToMappings(IStatus status, IMergeContext mergeContext) { 113 if (status.getCode() == IMergeStatus.CONFLICTS) { 114 return new MergeStatus(status.getPlugin(), status.getMessage(), mergeContext.getScope().getMappings(getModelProvider().getDescriptor().getId())); 116 } 117 return status; 118 } 119 } 120 | Popular Tags |