Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Valenta2006-01-07 18:26:30 +0000
committerMichael Valenta2006-01-07 18:26:30 +0000
commit69a475f6bf0cc009e0720ea69bce2b6693f804b0 (patch)
tree213818e01d25dfd6f9af0e306564b287726daf22
parent7381fa85567bc2dc597907ab4c05ab008d3c29e2 (diff)
downloadeclipse.platform.team-69a475f6bf0cc009e0720ea69bce2b6693f804b0.tar.gz
eclipse.platform.team-69a475f6bf0cc009e0720ea69bce2b6693f804b0.tar.xz
eclipse.platform.team-69a475f6bf0cc009e0720ea69bce2b6693f804b0.zip
Bug 119921 [Mapping] Improve heterogeneous input promting
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/operations/ResourceMappingOperation.java48
-rw-r--r--tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/TeamTest.java36
-rw-r--r--tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/mapping/ScopeBuildingTests.java139
-rw-r--r--tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/ui/synchronize/TestDiffNodePresentationModel.java17
4 files changed, 210 insertions, 30 deletions
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/operations/ResourceMappingOperation.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/operations/ResourceMappingOperation.java
index b2d30a0be..ce297516f 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/operations/ResourceMappingOperation.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/operations/ResourceMappingOperation.java
@@ -105,18 +105,22 @@ public abstract class ResourceMappingOperation extends ModelProviderOperation {
scope = getScopeGenerator().prepareScope(selectedMappings, context, monitor);
IResourceMappingScope inputScope = getScopeGenerator().asInputScope(scope);
if (scope.hasAdditionalMappings()) {
+ boolean prompt = false;
// There are additional mappings so we may need to prompt
ModelProvider[] inputModelProviders = inputScope.getModelProviders();
- if (scope.hasAdditonalResources()) {
+ 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
- promptForInputChange(monitor);
+ 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();
- boolean prompt = false;
for (int i = 0; i < mappings.length; i++) {
ResourceMapping mapping = mappings[i];
if (inputScope.getTraversals(mapping) == null) {
@@ -131,12 +135,9 @@ public abstract class ResourceMappingOperation extends ModelProviderOperation {
}
}
}
- if (prompt)
- promptForInputChange(monitor);
} else {
// We need to prompt if there are additional mappings from an input
// provider whose traversals overlap those of the input mappings.
- boolean prompt = false;
for (int i = 0; i < inputModelProviders.length; i++) {
ModelProvider provider = inputModelProviders[i];
String id = provider.getDescriptor().getId();
@@ -163,16 +164,45 @@ public abstract class ResourceMappingOperation extends ModelProviderOperation {
}
}
}
-
- if (prompt)
- promptForInputChange(monitor);
}
+ if (prompt)
+ promptForInputChange(monitor);
}
} catch (CoreException e) {
throw new InvocationTargetException(e);
}
}
+ private boolean hasAdditionalMappingsFromIndependantModel(ModelProvider[] inputModelProviders, ModelProvider[] modelProviders) {
+ ModelProvider[] additionalProviders = getAdditionalProviders(inputModelProviders, modelProviders);
+ for (int i = 0; i < additionalProviders.length; i++) {
+ ModelProvider additionalProvider = additionalProviders[i];
+ boolean independant = true;
+ // Return true if the new provider is independant of all input providers
+ for (int j = 0; j < inputModelProviders.length; j++) {
+ ModelProvider inputProvider = inputModelProviders[j];
+ if (!isIndependantModel(additionalProvider.getDescriptor().getId(), inputProvider.getDescriptor().getId())) {
+ independant = false;
+ }
+ }
+ if (independant)
+ return true;
+ }
+ return false;
+ }
+
+ private ModelProvider[] getAdditionalProviders(ModelProvider[] inputModelProviders, ModelProvider[] modelProviders) {
+ Set input = new HashSet();
+ List result = new ArrayList();
+ input.addAll(Arrays.asList(inputModelProviders));
+ for (int i = 0; i < modelProviders.length; i++) {
+ ModelProvider provider = modelProviders[i];
+ if (!input.contains(provider))
+ result.add(provider);
+ }
+ return (ModelProvider[]) result.toArray(new ModelProvider[result.size()]);
+ }
+
private boolean overlaps(ResourceTraversal[] scopeTraversals, ResourceTraversal[] inputModelTraversals) {
for (int i = 0; i < inputModelTraversals.length; i++) {
ResourceTraversal inputTraversal = inputModelTraversals[i];
diff --git a/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/TeamTest.java b/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/TeamTest.java
index 5df1b9385..2ac783a68 100644
--- a/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/TeamTest.java
+++ b/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/TeamTest.java
@@ -10,14 +10,26 @@
*******************************************************************************/
package org.eclipse.team.tests.core;
-import java.io.*;
-import java.util.*;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
import junit.framework.Test;
import junit.framework.TestSuite;
-import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.*;
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Status;
import org.eclipse.core.tests.resources.ResourceTest;
public class TeamTest extends ResourceTest {
@@ -62,6 +74,22 @@ public class TeamTest extends ResourceTest {
return getNamedTestProject(prefix + "-" + Long.toString(System.currentTimeMillis()));
}
+ /*
+ * This method creates a project with the given resources
+ */
+ protected IProject createProject(String prefix, String[] resources) throws CoreException {
+ IProject project = getUniqueTestProject(prefix);
+ buildResources(project, resources, true);
+ return project;
+ }
+
+ /*
+ * Create a test project using the currently running test case as the project name prefix
+ */
+ protected IProject createProject(String[] resources) throws CoreException {
+ return createProject(getName(), resources);
+ }
+
protected IStatus getTeamTestStatus(int severity) {
return new Status(severity, "org.eclipse.team.tests.core", 0, "team status", 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
new file mode 100644
index 000000000..0c681dfd9
--- /dev/null
+++ b/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/mapping/ScopeBuildingTests.java
@@ -0,0 +1,139 @@
+/*******************************************************************************
+ * Copyright (c) 2005 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.tests.core.mapping;
+
+import java.lang.reflect.InvocationTargetException;
+
+import junit.framework.Test;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.mapping.ResourceMapping;
+import org.eclipse.core.resources.mapping.ResourceMappingContext;
+import org.eclipse.core.resources.mapping.ResourceTraversal;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.team.core.mapping.IResourceMappingScope;
+import org.eclipse.team.core.mapping.provider.ScopeGenerator;
+import org.eclipse.team.internal.core.mapping.ResourceMappingScope;
+import org.eclipse.team.tests.core.TeamTest;
+import org.eclipse.team.ui.operations.ResourceMappingOperation;
+
+public class ScopeBuildingTests extends TeamTest {
+
+ private static final RuntimeException PROMPT_EXCEPTION = new RuntimeException();
+ protected static final String TEST_MODEL_PROVIDER_ID = "id1";
+
+ private class TestResourceMappingOperation extends ResourceMappingOperation {
+
+ private ResourceMapping[] additionalMappings;
+
+ protected TestResourceMappingOperation(ResourceMapping[] selectedMappings, ResourceMapping[] additionalMappings) {
+ super(null, selectedMappings, ResourceMappingContext.LOCAL_CONTEXT);
+ this.additionalMappings = additionalMappings;
+ }
+
+ protected void execute(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
+ // Do nothing since we're just testing the scope build
+ }
+
+ protected void promptForInputChange(IProgressMonitor monitor) {
+ // Throw an exception to indicate that a prompt was requested
+ throw PROMPT_EXCEPTION;
+ }
+
+ protected ScopeGenerator getScopeGenerator() {
+ return new ScopeGenerator() {
+ public IResourceMappingScope prepareScope(
+ ResourceMapping[] selectedMappings, ResourceMappingContext context,
+ IProgressMonitor monitor) throws CoreException {
+
+ IResourceMappingScope resourceMappingScope = super.prepareScope(selectedMappings, context, monitor);
+ // Add the additional test mappings to the scope
+ for (int i = 0; i < additionalMappings.length; i++) {
+ ResourceMapping mapping = additionalMappings[i];
+ ResourceTraversal[] traversals = mapping.getTraversals(context, monitor);
+ ((ResourceMappingScope)resourceMappingScope).addMapping(mapping, traversals);
+ // TODO: The additional mappings and additional resources boolean will not be set
+ // TODO: This may bring in mappings from the resources modle provider
+ }
+ return resourceMappingScope;
+ }
+
+ };
+ }
+
+ }
+ public static Test suite() {
+ return suite(ScopeBuildingTests.class);
+ }
+
+ public ScopeBuildingTests() {
+ super();
+ }
+
+ public ScopeBuildingTests(String name) {
+ super(name);
+ }
+
+ private void expectPrompt(TestResourceMappingOperation op) {
+ try {
+ op.run(new NullProgressMonitor());
+ } catch (InvocationTargetException e) {
+ fail("Unexpected exception: " + e.getTargetException().getMessage());
+ } catch (InterruptedException e) {
+ fail("Unexpected interupt");
+ } catch (RuntimeException e) {
+ if (e == PROMPT_EXCEPTION)
+ return;
+ throw e;
+ }
+ fail("Expected prompt did not occur");
+ }
+
+ private ResourceMapping getMapping(final IProject project, final IResource[] resources, final int depth) {
+ return new ResourceMapping() {
+
+ public ResourceTraversal[] getTraversals(ResourceMappingContext context,
+ IProgressMonitor monitor) throws CoreException {
+ return new ResourceTraversal[] { new ResourceTraversal(resources, depth, IResource.NONE)};
+ }
+
+ public IProject[] getProjects() {
+ return new IProject[] { project };
+ }
+
+ public Object getModelObject() {
+ return new Object();
+ }
+
+ public String getModelProviderId() {
+ return TEST_MODEL_PROVIDER_ID;
+ }
+
+ };
+ }
+
+ public void testAdditionalResources() throws CoreException {
+ IProject project = createProject(new String[]{"file.txt", "folder1/file2.txt", "folder1/folder2/file3.txt", "folder3/"});
+ ResourceMapping[] mappings = new ResourceMapping[] {
+ getMapping(project, new IResource[] { project.getFolder("folder1") }, IResource.DEPTH_INFINITE)
+ };
+ ResourceMapping[] additionalMappings = new ResourceMapping[] {
+ getMapping(project, new IResource[] { project.getFile("file.txt")}, IResource.DEPTH_INFINITE)
+ };
+ TestResourceMappingOperation op = new TestResourceMappingOperation(mappings, additionalMappings);
+ expectPrompt(op);
+ }
+
+
+}
diff --git a/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/ui/synchronize/TestDiffNodePresentationModel.java b/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/ui/synchronize/TestDiffNodePresentationModel.java
index ce20af7df..02535edc1 100644
--- a/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/ui/synchronize/TestDiffNodePresentationModel.java
+++ b/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/ui/synchronize/TestDiffNodePresentationModel.java
@@ -83,23 +83,6 @@ public class TestDiffNodePresentationModel extends TeamTest {
//return new HierarchicalModelProvider(set);
return null;
}
-
- /*
- * This method creates a project with the given resources, imports
- * it to CVS and checks it out
- */
- protected IProject createProject(String prefix, String[] resources) throws CoreException {
- IProject project = getUniqueTestProject(prefix);
- buildResources(project, resources, true);
- return project;
- }
-
- /*
- * Create a test project using the currently running test case as the project name prefix
- */
- protected IProject createProject(String[] resources) throws CoreException {
- return createProject(getName(), resources);
- }
private void adjustSet(SyncInfoSet set, IProject project, String[] resourceStrings, int[] syncKind) throws TeamException {
IResource[] resources = buildResources(project, resourceStrings);

Back to the top