Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Valenta2006-01-26 22:16:35 +0000
committerMichael Valenta2006-01-26 22:16:35 +0000
commit15a3c0a41e7bcf9fe290652d129ef1eeb06f26f8 (patch)
treeca889c90411b14414058917a3086ab051f6a9745
parent9496a3ddc06b52f00164373930001f325b69edb0 (diff)
downloadeclipse.platform.team-15a3c0a41e7bcf9fe290652d129ef1eeb06f26f8.tar.gz
eclipse.platform.team-15a3c0a41e7bcf9fe290652d129ef1eeb06f26f8.tar.xz
eclipse.platform.team-15a3c0a41e7bcf9fe290652d129ef1eeb06f26f8.zip
Added persistence of CVS model sync
-rw-r--r--bundles/org.eclipse.team.core/src/org/eclipse/team/core/mapping/provider/ScopeGenerator.java103
-rw-r--r--bundles/org.eclipse.team.core/src/org/eclipse/team/core/subscribers/SubscriberMergeContext.java2
-rw-r--r--bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/mapping/ResourceMappingScope.java2
-rw-r--r--bundles/org.eclipse.team.cvs.ui/plugin.xml2
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/mappings/ModelUpdateOperation.java2
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/mappings/WorkspaceModelParticipant.java (renamed from bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/mappings/CVSResourceMappingParticipant.java)67
-rw-r--r--bundles/org.eclipse.team.ui/plugin.xml7
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/operations/ModelOperation.java163
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/operations/ModelSynchronizeParticipant.java104
-rw-r--r--tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/mapping/ScopeBuildingTests.java3
10 files changed, 331 insertions, 124 deletions
diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/mapping/provider/ScopeGenerator.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/mapping/provider/ScopeGenerator.java
index 2288a0077..6e9b52438 100644
--- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/mapping/provider/ScopeGenerator.java
+++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/mapping/provider/ScopeGenerator.java
@@ -62,6 +62,50 @@ public class ScopeGenerator {
private final ResourceMappingContext context;
private final boolean consultModels;
+ /**
+ * Convenience method for obtaining the set of resource
+ * mappings from all model providers that overlap
+ * with the given resources.
+ * @param resources the resources
+ * @param context the resource mapping context
+ * @param monitor a progress monitor
+ * @return the resource mappings
+ * @throws CoreException
+ */
+ public static ResourceMapping[] getMappingsFromProviders(IResource[] resources,
+ ResourceMappingContext context,
+ IProgressMonitor monitor) throws CoreException {
+ Set result = new HashSet();
+ IModelProviderDescriptor[] descriptors = ModelProvider
+ .getModelProviderDescriptors();
+ for (int i = 0; i < descriptors.length; i++) {
+ IModelProviderDescriptor descriptor = descriptors[i];
+ ResourceMapping[] mappings = getMappings(descriptor, resources,
+ context, monitor);
+ result.addAll(Arrays.asList(mappings));
+ }
+ return (ResourceMapping[]) result.toArray(new ResourceMapping[result.size()]);
+ }
+
+ private static ResourceMapping[] getMappings(IModelProviderDescriptor descriptor,
+ IResource[] resources,
+ ResourceMappingContext context, IProgressMonitor monitor)
+ throws CoreException {
+ IResource[] matchingResources = descriptor.getMatchingResources(
+ resources);
+ return descriptor.getModelProvider().getMappings(matchingResources,
+ context, monitor);
+ }
+
+ /**
+ * Create a sope generator that uses the given context to
+ * determine what resources should be included in the scope.
+ * If <code>consultModels</code> is <code>true</code> then
+ * the moel providers will be queried in order to determine if
+ * additional mappings should be included in the scope
+ * @param resourceMappingContext a resource mapping context
+ * @param consultModels whether modle providers should be consulted
+ */
public ScopeGenerator(ResourceMappingContext resourceMappingContext, boolean consultModels) {
this.context = resourceMappingContext;
this.consultModels = consultModels;
@@ -70,8 +114,14 @@ public class ScopeGenerator {
/**
* Build the scope that is used to determine the complete set of resource
* mappings, and hence resources, that an operation should be performed on.
+ * If <code>useLocalContext</code> is <code>true</code> then the
+ * {@link ResourceMappingContext#LOCAL_CONTEXT} is used to prepare the scope instead
+ * of the context associatd with the generator. Clients may wish to do this
+ * when long running operations should not occur.
*
* @param selectedMappings the selected set of resource mappings
+ * @param useLocalContext indicates that the localcontext should be used
+ * when building the scope
* @param monitor a progress monitor
* @return a scope that defines the complete set of resources to be operated
* on
@@ -79,6 +129,7 @@ public class ScopeGenerator {
*/
public IResourceMappingScope prepareScope(
ResourceMapping[] selectedMappings,
+ boolean useLocalContext,
IProgressMonitor monitor) throws CoreException {
monitor.beginTask(null, IProgressMonitor.UNKNOWN);
@@ -87,21 +138,17 @@ public class ScopeGenerator {
IResourceMappingScope scope = createScope(selectedMappings);
// Accumulate the initial set of mappings we need traversals for
- Set targetMappings = new HashSet();
- for (int i = 0; i < selectedMappings.length; i++) {
- ResourceMapping mapping = selectedMappings[i];
- targetMappings.add(mapping);
- }
+ ResourceMapping[] targetMappings = selectedMappings;
IResource[] newResources;
boolean firstTime = true;
boolean hasAdditionalResources = false;
int count = 0;
do {
- newResources = addMappingsToScope(scope, targetMappings,
+ newResources = addMappingsToScope(scope, targetMappings, useLocalContext,
Policy.subMonitorFor(monitor, IProgressMonitor.UNKNOWN));
if (consultModels) {
IResource[] adjusted = adjustInputResources(newResources);
- targetMappings = internalGetMappingsFromProviders(adjusted,
+ targetMappings = getMappingsFromProviders(adjusted,
context,
Policy.subMonitorFor(monitor, IProgressMonitor.UNKNOWN));
if (firstTime) {
@@ -201,13 +248,13 @@ public class ScopeGenerator {
private void addResourcesToScope(IResourceMappingScope scope, IResource[] newResources, IProgressMonitor monitor) throws CoreException {
if (!consultModels)
return;
- Set targetMappings;
+ ResourceMapping[] targetMappings;
int count = 0;
do {
IResource[] adjusted = adjustInputResources(newResources);
- targetMappings = internalGetMappingsFromProviders(adjusted,
+ targetMappings = getMappingsFromProviders(adjusted,
context, Policy.subMonitorFor(monitor, IProgressMonitor.UNKNOWN));
- newResources = addMappingsToScope(scope, targetMappings,
+ newResources = addMappingsToScope(scope, targetMappings, false,
Policy.subMonitorFor(monitor, IProgressMonitor.UNKNOWN));
} while (newResources.length != 0 && count++ < MAX_ITERATION);
if (!scope.hasAdditionalMappings()) {
@@ -294,11 +341,14 @@ public class ScopeGenerator {
}
private IResource[] addMappingsToScope(IResourceMappingScope scope,
- Set targetMappings,
- IProgressMonitor monitor) throws CoreException {
+ ResourceMapping[] targetMappings,
+ boolean useLocalContext, IProgressMonitor monitor) throws CoreException {
Set newResources = new HashSet();
- for (Iterator iter = targetMappings.iterator(); iter.hasNext();) {
- ResourceMapping mapping = (ResourceMapping) iter.next();
+ ResourceMappingContext context = this.context;
+ if (useLocalContext)
+ context = ResourceMappingContext.LOCAL_CONTEXT;
+ for (int i = 0; i < targetMappings.length; i++) {
+ ResourceMapping mapping = targetMappings[i];
if (scope.getTraversals(mapping) == null) {
ResourceTraversal[] traversals = mapping.getTraversals(context,
Policy.subMonitorFor(monitor, 100));
@@ -324,31 +374,6 @@ public class ScopeGenerator {
return ((ResourceMappingScope)scope).addMapping(mapping, traversals);
}
- private Set internalGetMappingsFromProviders(IResource[] resources,
- ResourceMappingContext context,
- IProgressMonitor monitor) throws CoreException {
- Set result = new HashSet();
- IModelProviderDescriptor[] descriptors = ModelProvider
- .getModelProviderDescriptors();
- for (int i = 0; i < descriptors.length; i++) {
- IModelProviderDescriptor descriptor = descriptors[i];
- ResourceMapping[] mappings = getMappings(descriptor, resources,
- context, monitor);
- result.addAll(Arrays.asList(mappings));
- }
- return result;
- }
-
- private ResourceMapping[] getMappings(IModelProviderDescriptor descriptor,
- IResource[] resources,
- ResourceMappingContext context, IProgressMonitor monitor)
- throws CoreException {
- IResource[] matchingResources = descriptor.getMatchingResources(
- resources);
- return descriptor.getModelProvider().getMappings(matchingResources,
- context, monitor);
- }
-
private boolean hasAdditionalMappings(IResourceMappingScope scope) {
ResourceMapping[] inputMappings = scope.getInputMappings();
ResourceMapping[] mappings = scope.getMappings();
diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/subscribers/SubscriberMergeContext.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/subscribers/SubscriberMergeContext.java
index e3fe260a8..04b034bbe 100644
--- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/subscribers/SubscriberMergeContext.java
+++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/subscribers/SubscriberMergeContext.java
@@ -65,8 +65,6 @@ public abstract class SubscriberMergeContext extends MergeContext {
handler.start();
if (refresh) {
refresh(getScope().getTraversals(), IResource.NONE, monitor);
- } else {
- handler.waitUntilIdle(monitor);
}
}
diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/mapping/ResourceMappingScope.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/mapping/ResourceMappingScope.java
index add1a91a8..cd570d336 100644
--- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/mapping/ResourceMappingScope.java
+++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/mapping/ResourceMappingScope.java
@@ -44,7 +44,7 @@ public class ResourceMappingScope extends AbstractResourceMappingScope {
private boolean hasAdditionalResources;
private final ScopeGenerator generator;
private final CompoundResourceTraversal compoundTraversal = new CompoundResourceTraversal();
-
+
public static ResourceTraversal[] combineTraversals(ResourceTraversal[] allTraversals) {
Set zero = new HashSet();
Set shallow = new HashSet();
diff --git a/bundles/org.eclipse.team.cvs.ui/plugin.xml b/bundles/org.eclipse.team.cvs.ui/plugin.xml
index 750e40c80..d59151745 100644
--- a/bundles/org.eclipse.team.cvs.ui/plugin.xml
+++ b/bundles/org.eclipse.team.cvs.ui/plugin.xml
@@ -45,7 +45,7 @@
<participant
name="%CVSResourceMappingParticipant"
icon="$nl$/icons/full/eview16/cvs_persp.gif"
- class="org.eclipse.team.internal.ccvs.ui.mappings.CVSResourceMappingParticipant"
+ class="org.eclipse.team.internal.ccvs.ui.mappings.WorkspaceModelParticipant"
id="org.eclipse.team.cvs.ui.workspace-participant">
</participant>
<participant
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/mappings/ModelUpdateOperation.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/mappings/ModelUpdateOperation.java
index b5fa18742..8a558614f 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/mappings/ModelUpdateOperation.java
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/mappings/ModelUpdateOperation.java
@@ -66,6 +66,6 @@ public class ModelUpdateOperation extends AbstractModelMergeOperation {
* @see org.eclipse.team.ui.operations.ResourceMappingMergeOperation#createParticipant()
*/
protected ModelSynchronizeParticipant createParticipant() {
- return new CVSResourceMappingParticipant(getContext(), getJobName());
+ return new WorkspaceModelParticipant(getContext(), getJobName());
}
}
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/mappings/CVSResourceMappingParticipant.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/mappings/WorkspaceModelParticipant.java
index fac7fabda..0e20c6895 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/mappings/CVSResourceMappingParticipant.java
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/mappings/WorkspaceModelParticipant.java
@@ -10,21 +10,29 @@
*******************************************************************************/
package org.eclipse.team.internal.ccvs.ui.mappings;
-import org.eclipse.core.runtime.CoreException;
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.core.resources.mapping.*;
+import org.eclipse.core.runtime.*;
import org.eclipse.jface.action.*;
-import org.eclipse.team.core.mapping.ISynchronizationContext;
+import org.eclipse.team.core.mapping.*;
+import org.eclipse.team.core.mapping.provider.ScopeGenerator;
+import org.eclipse.team.core.subscribers.SubscriberResourceMappingContext;
+import org.eclipse.team.internal.ccvs.core.CVSProviderPlugin;
+import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin;
import org.eclipse.team.internal.ccvs.ui.Policy;
import org.eclipse.team.internal.ccvs.ui.actions.*;
-import org.eclipse.team.internal.ccvs.ui.subscriber.*;
+import org.eclipse.team.internal.ccvs.ui.subscriber.CVSActionDelegateWrapper;
+import org.eclipse.team.internal.core.mapping.CompoundResourceTraversal;
import org.eclipse.team.internal.ui.TeamUIPlugin;
import org.eclipse.team.internal.ui.Utils;
import org.eclipse.team.ui.TeamUI;
import org.eclipse.team.ui.mapping.SynchronizationActionProvider;
-import org.eclipse.team.ui.operations.MergeActionGroup;
-import org.eclipse.team.ui.operations.ModelSynchronizeParticipant;
+import org.eclipse.team.ui.operations.*;
import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;
+import org.eclipse.ui.PartInitException;
-public class CVSResourceMappingParticipant extends
+public class WorkspaceModelParticipant extends
ModelSynchronizeParticipant {
public static final String VIEWER_ID = "org.eclipse.team.cvs.ui.workspaceSynchronization"; //$NON-NLS-1$
@@ -130,7 +138,10 @@ public class CVSResourceMappingParticipant extends
}
}
- public CVSResourceMappingParticipant(ISynchronizationContext context, String name) {
+ public WorkspaceModelParticipant() {
+ }
+
+ public WorkspaceModelParticipant(ISynchronizationContext context, String name) {
super(context);
try {
setInitializationData(TeamUI.getSynchronizeManager().getParticipantDescriptor("org.eclipse.team.cvs.ui.workspace-participant")); //$NON-NLS-1$
@@ -151,5 +162,47 @@ public class CVSResourceMappingParticipant extends
protected MergeActionGroup createMergeActionGroup() {
return new WorkspaceMergeActionGroup();
}
+
+ protected void initializeContext(ResourceTraversal[] traversals) throws PartInitException {
+ CompoundResourceTraversal traversal = new CompoundResourceTraversal();
+ traversal.addTraversals(traversals);
+ try {
+ // When restoring, we can't do anything long running so we'll need to use the local content for everything
+ NullProgressMonitor monitor = new NullProgressMonitor();
+ ResourceMapping[] mappings = ScopeGenerator.getMappingsFromProviders(traversal.getRoots(), ResourceMappingContext.LOCAL_CONTEXT, monitor);
+ IResourceMappingScope scope = createScope(mappings, monitor);
+ IMergeContext context = WorkspaceSubscriberContext.createContext(scope, false /* refresh */, ISynchronizationContext.THREE_WAY, monitor);
+ initializeContext(context);
+ } catch (CoreException e) {
+ CVSUIPlugin.log(e);
+ throw new PartInitException(e.getStatus());
+ }
+ }
+ private IResourceMappingScope createScope(ResourceMapping[] mappings, IProgressMonitor monitor) throws PartInitException {
+ ModelOperation op = new ModelOperation(null, mappings) {
+ protected void execute(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
+ // Do nothing, we just want to build the scope
+ }
+ protected void promptIfInputChange(IProgressMonitor monitor) {
+ // Don't prompt
+ }
+ protected boolean isUseLocalContext() {
+ return true;
+ }
+ protected ResourceMappingContext getResourceMappingContext() {
+ return new SubscriberResourceMappingContext(CVSProviderPlugin.getPlugin().getCVSWorkspaceSubscriber(), true);
+ }
+ };
+ // Run the operatin in order to build the scope
+ try {
+ op.run(monitor);
+ } catch (InvocationTargetException e) {
+ CVSUIPlugin.log(IStatus.ERROR, "An error occurred", e.getTargetException());
+ throw new PartInitException("Unexpected error during participant restore");
+ } catch (InterruptedException e) {
+ throw new PartInitException("Unexpected interrupt during participant restore");
+ }
+ return op.getScope();
+ }
}
diff --git a/bundles/org.eclipse.team.ui/plugin.xml b/bundles/org.eclipse.team.ui/plugin.xml
index eced9f677..6d059c1df 100644
--- a/bundles/org.eclipse.team.ui/plugin.xml
+++ b/bundles/org.eclipse.team.ui/plugin.xml
@@ -404,10 +404,11 @@
<extension
point="org.eclipse.team.ui.synchronizeParticipants">
<participant
- name="%ModelSyncParticipant"
- icon="$nl$/icons/full/eview16/synch_synch.gif"
class="org.eclipse.team.ui.operations.ModelSynchronizeParticipant"
- id="org.eclipse.team.ui.synchronization_context_synchronize_participant">
+ icon="$nl$/icons/full/eview16/synch_synch.gif"
+ id="org.eclipse.team.ui.synchronization_context_synchronize_participant"
+ name="%ModelSyncParticipant"
+ persistent="false">
</participant>
</extension>
<extension
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/operations/ModelOperation.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/operations/ModelOperation.java
index 8ba35974e..8144b248c 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/operations/ModelOperation.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/operations/ModelOperation.java
@@ -60,14 +60,14 @@ public abstract class ModelOperation extends TeamOperation {
/**
* Run the operation. This method first ensures that the scope is built
- * by calling {@link #buildScope(IProgressMonitor)} and then invokes the
+ * by calling {@link #prepareScope(IProgressMonitor)} and then invokes the
* {@link #execute(IProgressMonitor)} method.
* @param monitor a progress monitor
* @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor)
*/
public void run(IProgressMonitor monitor) throws InvocationTargetException,
InterruptedException {
- buildScope(monitor);
+ prepareScope(monitor);
execute(monitor);
}
@@ -82,83 +82,114 @@ public abstract class ModelOperation extends TeamOperation {
* </ol>
* @param monitor a progress monitor
*/
- protected void buildScope(IProgressMonitor monitor) throws InvocationTargetException {
+ protected void prepareScope(IProgressMonitor monitor) throws InvocationTargetException {
try {
ScopeGenerator scopeGenerator = getScopeGenerator();
- scope = scopeGenerator.prepareScope(selectedMappings, monitor);
- IResourceMappingScope inputScope = scopeGenerator.asInputScope(scope);
- if (scope.hasAdditionalMappings()) {
- boolean prompt = false;
- // There are additional mappings so we may need to prompt
- ModelProvider[] inputModelProviders = inputScope.getModelProviders();
- if (hasAdditionalMappingsFromIndependantModel(inputModelProviders, scope.getModelProviders())) {
- // Prompt if the is a new model provider in the scope that is independant
- // of any of the input mappings
- prompt = true;
- } else if (scope.hasAdditonalResources()) {
- // We definitely need to prompt to indicate that additional resources
- prompt = true;
- } else if (inputModelProviders.length == 1) {
- // We may need to prompt depending on the nature of the additional mappings
- // We need to prompt if the additional mappings are from the same model as
- // the input or if they are from a model that has no relationship to the input model
- String modelProviderId = inputModelProviders[0].getDescriptor().getId();
- ResourceMapping[] mappings = scope.getMappings();
- for (int i = 0; i < mappings.length; i++) {
- ResourceMapping mapping = mappings[i];
- if (inputScope.getTraversals(mapping) == null) {
- // This mapping was not in the input
- String id = mapping.getModelProviderId();
- if (id.equals(modelProviderId)) {
- prompt = true;
- break;
- } else if (isIndependantModel(modelProviderId, id)) {
- prompt = true;
- break;
- }
+ scope = scopeGenerator.prepareScope(selectedMappings, isUseLocalContext(), monitor);
+ promptIfInputChange(monitor);
+ } catch (CoreException e) {
+ throw new InvocationTargetException(e);
+ }
+ }
+
+ /**
+ * Prompt the user by calling {@link #promptForInputChange(String, IProgressMonitor)}
+ * if the scope of the operation was expanded.
+ * @param monitor a progress monitor
+ */
+ protected void promptIfInputChange(IProgressMonitor monitor) {
+ IResourceMappingScope inputScope = getInputScope();
+ if (scope.hasAdditionalMappings()) {
+ boolean prompt = false;
+ // There are additional mappings so we may need to prompt
+ ModelProvider[] inputModelProviders = inputScope.getModelProviders();
+ if (hasAdditionalMappingsFromIndependantModel(inputModelProviders, scope.getModelProviders())) {
+ // Prompt if the is a new model provider in the scope that is independant
+ // of any of the input mappings
+ prompt = true;
+ } else if (scope.hasAdditonalResources()) {
+ // We definitely need to prompt to indicate that additional resources
+ prompt = true;
+ } else if (inputModelProviders.length == 1) {
+ // We may need to prompt depending on the nature of the additional mappings
+ // We need to prompt if the additional mappings are from the same model as
+ // the input or if they are from a model that has no relationship to the input model
+ String modelProviderId = inputModelProviders[0].getDescriptor().getId();
+ ResourceMapping[] mappings = scope.getMappings();
+ for (int i = 0; i < mappings.length; i++) {
+ ResourceMapping mapping = mappings[i];
+ if (inputScope.getTraversals(mapping) == null) {
+ // This mapping was not in the input
+ String id = mapping.getModelProviderId();
+ if (id.equals(modelProviderId)) {
+ prompt = true;
+ break;
+ } else if (isIndependantModel(modelProviderId, id)) {
+ prompt = true;
+ break;
}
}
- } else {
- // We need to prompt if there are additional mappings from an input
- // provider whose traversals overlap those of the input mappings.
- for (int i = 0; i < inputModelProviders.length; i++) {
- ModelProvider provider = inputModelProviders[i];
- String id = provider.getDescriptor().getId();
- ResourceMapping[] inputMappings = inputScope.getMappings(id);
- ResourceMapping[] scopeMappings = scope.getMappings(id);
- if (inputMappings.length != scopeMappings.length) {
- // There are more mappings for this provider.
- // We need to see if any of the new ones overlap the old ones.
- for (int j = 0; j < scopeMappings.length; j++) {
- ResourceMapping mapping = scopeMappings[j];
- ResourceTraversal[] inputTraversals = inputScope.getTraversals(mapping);
- if (inputTraversals == null) {
- // This mapping was not in the input.
- // We need to prompt if the traversal for this mapping overlaps with
- // the input mappings for the model provider
- // TODO could check for project overlap first
- ResourceTraversal[] scopeTraversals = scope.getTraversals(mapping);
- ResourceTraversal[] inputModelTraversals = getTraversals(inputScope, inputMappings);
- if (overlaps(scopeTraversals, inputModelTraversals)) {
- prompt = true;
- break;
- }
+ }
+ } else {
+ // We need to prompt if there are additional mappings from an input
+ // provider whose traversals overlap those of the input mappings.
+ for (int i = 0; i < inputModelProviders.length; i++) {
+ ModelProvider provider = inputModelProviders[i];
+ String id = provider.getDescriptor().getId();
+ ResourceMapping[] inputMappings = inputScope.getMappings(id);
+ ResourceMapping[] scopeMappings = scope.getMappings(id);
+ if (inputMappings.length != scopeMappings.length) {
+ // There are more mappings for this provider.
+ // We need to see if any of the new ones overlap the old ones.
+ for (int j = 0; j < scopeMappings.length; j++) {
+ ResourceMapping mapping = scopeMappings[j];
+ ResourceTraversal[] inputTraversals = inputScope.getTraversals(mapping);
+ if (inputTraversals == null) {
+ // This mapping was not in the input.
+ // We need to prompt if the traversal for this mapping overlaps with
+ // the input mappings for the model provider
+ // TODO could check for project overlap first
+ ResourceTraversal[] scopeTraversals = scope.getTraversals(mapping);
+ ResourceTraversal[] inputModelTraversals = getTraversals(inputScope, inputMappings);
+ if (overlaps(scopeTraversals, inputModelTraversals)) {
+ prompt = true;
+ break;
}
}
}
}
}
- if (prompt) {
- String previewMessage = getPreviewRequestMessage();
- previewRequested = promptForInputChange(previewMessage, monitor);
- }
}
- } catch (CoreException e) {
- throw new InvocationTargetException(e);
+ if (prompt) {
+ String previewMessage = getPreviewRequestMessage();
+ previewRequested = promptForInputChange(previewMessage, monitor);
+ }
}
}
/**
+ * Return a scope that represents the input to the operation
+ * before the scope was expanded to include any additional models.
+ * @return a scope that represents the input to the operation
+ */
+ protected IResourceMappingScope getInputScope() {
+ ScopeGenerator scopeGenerator = getScopeGenerator();
+ IResourceMappingScope inputScope = scopeGenerator.asInputScope(scope);
+ return inputScope;
+ }
+
+ /**
+ * Indicate whether the local context should be used when preparing the scope.
+ * Subclasses may wish to do this when initial creation of the
+ * scope cannot be log running but they will perform future refreshes on the
+ * scope that can be.
+ * @return whether the local context should be used when preparing the scope
+ */
+ protected boolean isUseLocalContext() {
+ return false;
+ }
+
+ /**
* Return a string to be used in the preview request on the scope prompt
* or <code>null</code> if a preview of the operation results is not possible.
* By default, <code>null</code> is returned but subclasses may override.
@@ -295,6 +326,8 @@ public abstract class ModelOperation extends TeamOperation {
* operation from the input mappings.
*/
protected ScopeGenerator getScopeGenerator() {
+ if (scope != null)
+ return ((ResourceMappingScope)scope).getGenerator();
return new ScopeGenerator(getResourceMappingContext(), consultModelsWhenGeneratingScope());
}
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/operations/ModelSynchronizeParticipant.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/operations/ModelSynchronizeParticipant.java
index 90034f99f..b4ef6b295 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/operations/ModelSynchronizeParticipant.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/operations/ModelSynchronizeParticipant.java
@@ -10,13 +10,19 @@
*******************************************************************************/
package org.eclipse.team.ui.operations;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.compare.structuremergeviewer.ICompareInput;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.resources.mapping.ResourceMapping;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.resources.mapping.ResourceTraversal;
+import org.eclipse.core.runtime.*;
import org.eclipse.osgi.util.NLS;
import org.eclipse.team.core.mapping.IMergeContext;
import org.eclipse.team.core.mapping.ISynchronizationContext;
+import org.eclipse.team.internal.core.mapping.CompoundResourceTraversal;
import org.eclipse.team.internal.ui.*;
import org.eclipse.team.internal.ui.mapping.ModelSynchronizePage;
import org.eclipse.team.internal.ui.synchronize.*;
@@ -50,6 +56,11 @@ public class ModelSynchronizeParticipant extends
private static final String CTX_PARTICIPANT_SETTINGS = TeamUIPlugin.ID + ".MODEL_PARTICIPANT_SETTINGS"; //$NON-NLS-1$
/*
+ * Key for traversals in memento
+ */
+ private static final String CTX_PARTICIPANT_TRAVERSALS = TeamUIPlugin.ID + ".MODEL_PARTICIPANT_TRAVERSALS"; //$NON-NLS-1$
+
+ /*
* Key for schedule in memento
*/
private static final String CTX_REFRESH_SCHEDULE_SETTINGS = TeamUIPlugin.ID + ".MODEL_PARTICIPANT_REFRESH_SCHEDULE"; //$NON-NLS-1$
@@ -59,6 +70,14 @@ public class ModelSynchronizeParticipant extends
*/
private static final String CTX_DESCRIPTION = TeamUIPlugin.ID + ".MODEL_PARTICIPANT_DESCRIPTION"; //$NON-NLS-1$
+ /*
+ * Constants used to save and restore this scope
+ */
+ private final static String CTX_TRAVERSAL = "traversals"; //$NON-NLS-1$
+ private final static String CTX_DEPTH = "depth"; //$NON-NLS-1$
+ private final static String CTX_RESOURCE= "resources"; //$NON-NLS-1$
+ private final static String CTX_RESOURCE_PATH = "resource_path"; //$NON-NLS-1$
+
private ISynchronizationContext context;
private boolean mergingEnabled = true;
protected SubscriberRefreshSchedule refreshSchedule;
@@ -87,7 +106,6 @@ public class ModelSynchronizeParticipant extends
}
setSecondaryId(Long.toString(System.currentTimeMillis()));
setName(name);
- mergingEnabled = context instanceof IMergeContext;
refreshSchedule = new SubscriberRefreshSchedule(createRefreshable());
}
@@ -97,9 +115,14 @@ public class ModelSynchronizeParticipant extends
*/
public ModelSynchronizeParticipant(ISynchronizationContext context) {
initializeContext(context);
- mergingEnabled = context instanceof IMergeContext;
refreshSchedule = new SubscriberRefreshSchedule(createRefreshable());
}
+
+ /**
+ * Create a participant in order to restore it from saved state.
+ */
+ public ModelSynchronizeParticipant() {
+ }
/* (non-Javadoc)
* @see org.eclipse.team.ui.synchronize.AbstractSynchronizeParticipant#getName()
@@ -195,6 +218,7 @@ public class ModelSynchronizeParticipant extends
*/
protected void initializeContext(ISynchronizationContext context) {
this.context = context;
+ mergingEnabled = context instanceof IMergeContext;
}
/**
@@ -347,8 +371,62 @@ public class ModelSynchronizeParticipant extends
if (description != null)
settings.putString(CTX_DESCRIPTION, description);
refreshSchedule.saveState(settings.createChild(CTX_REFRESH_SCHEDULE_SETTINGS));
+ CompoundResourceTraversal traversal = new CompoundResourceTraversal();
+ traversal.addTraversals(getContext().getScope().getTraversals());
+ saveTraversals(settings.createChild(CTX_PARTICIPANT_TRAVERSALS), traversal.asTraversals());
}
+ private void saveTraversals(IMemento memento, ResourceTraversal[] traversals) {
+ for (int i = 0; i < traversals.length; i++) {
+ ResourceTraversal traversal = traversals[i];
+ IMemento traversalNode = memento.createChild(CTX_TRAVERSAL);
+ traversalNode.putInteger(CTX_DEPTH, traversal.getDepth());
+ IResource[] resources = traversal.getResources();
+ for (int j = 0; j < resources.length; j++) {
+ IResource resource = resources[j];
+ IMemento resourceNode = traversalNode.createChild(CTX_RESOURCE);
+ resourceNode.putString(CTX_RESOURCE_PATH, resource.getFullPath().toString());
+ }
+ }
+ }
+
+ private ResourceTraversal[] loadTraversals(IMemento memento) {
+ if (memento == null)
+ return null;
+ IMemento[] traversalNodes = memento.getChildren(CTX_TRAVERSAL);
+ if (traversalNodes == null)
+ return null;
+ List traversals = new ArrayList();
+ for (int i = 0; i < traversalNodes.length; i++) {
+ IMemento traversalNode = traversalNodes[i];
+ Integer depthInt = traversalNode.getInteger(CTX_DEPTH);
+ int depth;
+ if (depthInt == null) {
+ depth = IResource.DEPTH_INFINITE;
+ } else {
+ depth = depthInt.intValue();
+ }
+ IMemento[] resourceNodes = traversalNode.getChildren(CTX_RESOURCE);
+ List resources = new ArrayList();
+ if(resourceNodes != null) {
+ for (int j = 0; j < resourceNodes.length; j++) {
+ IMemento rootNode = resourceNodes[j];
+ IPath path = new Path(rootNode.getString(CTX_RESOURCE_PATH));
+ IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(path, true /* include phantoms */);
+ if(resource != null) {
+ resources.add(resource);
+ }
+ }
+ }
+ if (!resources.isEmpty()) {
+ traversals.add(new ResourceTraversal((IResource[]) resources.toArray(new IResource[resources.size()]), depth, IResource.NONE));
+ }
+ }
+ if (traversals.size() == 0)
+ return null;
+ return (ResourceTraversal[]) traversals.toArray(new ResourceTraversal[traversals.size()]);
+ }
+
/* (non-Javadoc)
* @see org.eclipse.team.ui.synchronize.ISynchronizeParticipant#init(org.eclipse.ui.IMemento)
*/
@@ -356,6 +434,10 @@ public class ModelSynchronizeParticipant extends
super.init(secondaryId, memento);
if(memento != null) {
IMemento settings = memento.getChild(CTX_PARTICIPANT_SETTINGS);
+ ResourceTraversal[] traversals = loadTraversals(settings.getChild(CTX_PARTICIPANT_TRAVERSALS));
+ if (traversals == null)
+ throw new PartInitException("An error occurred");
+ initializeContext(traversals);
if(settings != null) {
SubscriberRefreshSchedule schedule = SubscriberRefreshSchedule.init(settings.getChild(CTX_REFRESH_SCHEDULE_SETTINGS), createRefreshable());
description = settings.getString(CTX_DESCRIPTION);
@@ -364,6 +446,20 @@ public class ModelSynchronizeParticipant extends
}
}
+ /**
+ * Initialize the content of this participant based on the provided traversals.
+ * This method is invoked when a persisted participant is restored. By default,
+ * a <code>PartInitException</code> si thrown. Subclasses that have indicated that
+ * they are persistable must override this methd to recreate the context of the
+ * participant and can call {@link #initializeContext(ISynchronizationContext)}
+ * to set it.
+ * @param traversals the saved traversals
+ * @throws PartInitException
+ */
+ protected void initializeContext(ResourceTraversal[] traversals) throws PartInitException {
+ throw new PartInitException(NLS.bind("Participant {0} could not initialize its context from its persisted state", getId()));
+ }
+
/* private */ void setRefreshSchedule(SubscriberRefreshSchedule schedule) {
if (refreshSchedule != schedule) {
if (refreshSchedule != null) {
diff --git a/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/mapping/ScopeBuildingTests.java b/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/mapping/ScopeBuildingTests.java
index ad3bef9ae..5902aa4c8 100644
--- a/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/mapping/ScopeBuildingTests.java
+++ b/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/mapping/ScopeBuildingTests.java
@@ -55,9 +55,10 @@ public class ScopeBuildingTests extends TeamTest {
return new ScopeGenerator(getResourceMappingContext(), false) {
public IResourceMappingScope prepareScope(
ResourceMapping[] selectedMappings,
+ boolean useLocalContext,
IProgressMonitor monitor) throws CoreException {
- IResourceMappingScope resourceMappingScope = super.prepareScope(selectedMappings, monitor);
+ IResourceMappingScope resourceMappingScope = super.prepareScope(selectedMappings, useLocalContext, monitor);
// Add the additional test mappings to the scope
for (int i = 0; i < additionalMappings.length; i++) {
ResourceMapping mapping = additionalMappings[i];

Back to the top