Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Valenta2006-04-03 14:35:36 +0000
committerMichael Valenta2006-04-03 14:35:36 +0000
commitd536c14bc4b1ddafcdaecd05186d40b6ad9e2311 (patch)
tree7285af67d17ced3a0c7aed7652c64cab0e05e52b /bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core
parent5d52e3f08a64c4d5618d86c59526dd4c49a19643 (diff)
downloadeclipse.platform.team-d536c14bc4b1ddafcdaecd05186d40b6ad9e2311.tar.gz
eclipse.platform.team-d536c14bc4b1ddafcdaecd05186d40b6ad9e2311.tar.xz
eclipse.platform.team-d536c14bc4b1ddafcdaecd05186d40b6ad9e2311.zip
Refactoring change set support
Diffstat (limited to 'bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core')
-rw-r--r--bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/ChangeTracker.java288
-rw-r--r--bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/ActiveChangeSet.java49
-rw-r--r--bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/ActiveChangeSetManager.java282
-rw-r--r--bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/BatchingChangeSetManager.java (renamed from bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/BatchedChangeSetCollector.java)11
-rw-r--r--bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/ChangeSetManager.java (renamed from bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/ChangeSetCollector.java)8
-rw-r--r--bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/DiffTreeChangeSetCollector.java56
-rw-r--r--bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/SubscriberChangeSetManager.java (renamed from bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/SubscriberChangeSetCollector.java)211
7 files changed, 625 insertions, 280 deletions
diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/ChangeTracker.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/ChangeTracker.java
new file mode 100644
index 000000000..612bc1192
--- /dev/null
+++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/ChangeTracker.java
@@ -0,0 +1,288 @@
+/*******************************************************************************
+ * 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.internal.core;
+
+import java.util.*;
+
+import org.eclipse.core.resources.*;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.team.core.RepositoryProvider;
+import org.eclipse.team.core.RepositoryProviderType;
+import org.eclipse.team.internal.core.subscribers.ActiveChangeSet;
+import org.eclipse.team.internal.core.subscribers.ActiveChangeSetManager;
+
+/**
+ * Track changes to plugin projects so that changes to any of the manifest files
+ * will be grouped together for the purposes of committing.
+ *
+ * @since 3.2
+ */
+public abstract class ChangeTracker implements IResourceChangeListener, IRepositoryProviderListener {
+
+ private Map trackedProjects = new HashMap(); // Map IProject->SubscriberChanegSetCollector
+ private boolean disposed;
+
+ /**
+ * Create a change tracker
+ */
+ public ChangeTracker() {
+ super();
+ }
+
+ /**
+ * Start tracking changes. This registers listeners with the workspace
+ * and team.
+ */
+ public void start() {
+ ResourcesPlugin.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.POST_CHANGE);
+ RepositoryProviderManager.getInstance().addListener(this);
+ IProject[] allProjects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
+ for (int i = 0; i < allProjects.length; i++) {
+ IProject project = allProjects[i];
+ if (isProjectOfInterest(project))
+ trackProject(project);
+ }
+ }
+
+ /**
+ * Remove any listeners for this tracker. Subclasses
+ * may extend this method but must call this method if they do.
+ */
+ public void dispose() {
+ disposed = true;
+ ResourcesPlugin.getWorkspace().removeResourceChangeListener(this);
+ RepositoryProviderManager.getInstance().removeListener(this);
+ }
+
+ /**
+ * Handle a resource change event.
+ * Update the set of projects for which we can track changes
+ * by listening for project changes and project description changes.
+ * @param event the change event
+ */
+ public void resourceChanged(IResourceChangeEvent event) {
+ if (disposed) return;
+ IResourceDelta delta = event.getDelta();
+ IResourceDelta[] projectDeltas = delta.getAffectedChildren(IResourceDelta.ADDED | IResourceDelta.CHANGED | IResourceDelta.REMOVED);
+ for (int i = 0; i < projectDeltas.length; i++) {
+ IResourceDelta projectDelta = projectDeltas[i];
+ IResource resource = projectDelta.getResource();
+ if (resource.getType() == IResource.PROJECT) {
+ IProject project = (IProject)resource;
+ if (isProjectOfInterest(project)) {
+ if (isProjectTracked(project)) {
+ IResource[] resources = getProjectChanges(project, projectDelta);
+ if (resources.length > 0)
+ handleChanges(project, resources);
+ } else {
+ trackProject(project);
+ }
+ } else {
+ stopTrackingProject(project);
+ }
+ }
+ }
+ }
+
+ private IResource[] getProjectChanges(IProject project, IResourceDelta projectDelta) {
+ final List result = new ArrayList();
+ try {
+ projectDelta.accept(new IResourceDeltaVisitor() {
+ public boolean visit(IResourceDelta delta) throws CoreException {
+ if (isResourceOfInterest(delta.getResource()) & isChangeOfInterest(delta)) {
+ result.add(delta.getResource());
+ }
+ return true;
+ }
+ });
+ } catch (CoreException e) {
+ TeamPlugin.log(e);
+ }
+ return (IResource[]) result.toArray(new IResource[result.size()]);
+ }
+
+ /**
+ * Return whether the given delta represents a change of interest.
+ * @param delta the delta
+ * @return whether the given delta represents a change of interest
+ */
+ protected boolean isChangeOfInterest(IResourceDelta delta) {
+ return (delta.getKind() & (IResourceDelta.ADDED | IResourceDelta.REMOVED | IResourceDelta.CHANGED)) > 0;
+ }
+
+ /**
+ * Stop tracking changes for the given project. Subclasses
+ * may extend but must call this method.
+ * @param project the project
+ */
+ protected void stopTrackingProject(IProject project) {
+ trackedProjects.remove(project);
+ }
+
+ /**
+ * Return whether the given project is being tracked.
+ * @param project the project
+ * @return whether the given project is being tracked
+ */
+ protected final boolean isProjectTracked(IProject project) {
+ return trackedProjects.containsKey(project);
+ }
+
+ /**
+ * Return whether the given project is of interest to this
+ * tracker. By default, <code>true</code> is returned if the
+ * project is accessible. Subclasses may extend but should
+ * still check for project accessibility either by calling
+ * {@link IResource#isAccessible()} or by invoking the
+ * overridden method.
+ * @param project the project
+ * @return whether the given project is of interest to this
+ * tracker
+ */
+ protected boolean isProjectOfInterest(IProject project) {
+ return project.isAccessible();
+ }
+
+ /**
+ * When a project is shared, start tracking it if it is of interest.
+ * @param provider the repository provider
+ */
+ public void providerMapped(RepositoryProvider provider) {
+ if (disposed) return;
+ if (isProjectOfInterest(provider.getProject())) {
+ trackProject(provider.getProject());
+ }
+ }
+
+ /**
+ * When a project is no longer shared, stop tracking the project.
+ * @param project the project
+ */
+ public void providerUnmapped(IProject project) {
+ if (disposed) return;
+ stopTrackingProject(project);
+ }
+
+ /**
+ * Return whether the given resource is of interest to the tracker.
+ * @param resource the resource
+ * @return whether the given resource is of interest to the tracker
+ */
+ protected abstract boolean isResourceOfInterest(IResource resource);
+
+ /**
+ * The given resources of interest have changed in the given project.
+ * @param project the project
+ * @param resources the resources
+ */
+ protected abstract void handleChanges(IProject project, IResource[] resources);
+
+ /**
+ * Resources of interest in the given project have changed but the
+ * specific changes are not known. Implementors must search the project for
+ * changes of interest.
+ * @param project the project
+ */
+ protected abstract void handleProjectChange(IProject project);
+
+ /**
+ * Track the given project if it has a change set collector. If the project
+ * does not have a collector, the project is not tracked.
+ * @param project the project
+ * @return whether the project is being tracked
+ */
+ protected final boolean trackProject(IProject project) {
+ if (RepositoryProvider.isShared(project)) {
+ try {
+ String currentId = project.getPersistentProperty(TeamPlugin.PROVIDER_PROP_KEY);
+ if (currentId != null) {
+ RepositoryProviderType type = RepositoryProviderType.getProviderType(currentId);
+ if (type != null) {
+ ActiveChangeSetManager collector = getCollector(type);
+ if (collector != null) {
+ trackedProjects.put(project, collector);
+ // Ensure that an appropriate change set exists if needed
+ // We can do this here because we know that the number of files
+ // to test is small.
+ projectTracked(project);
+ return true;
+ }
+ }
+ }
+ } catch (CoreException e) {
+ TeamPlugin.log(e);
+ }
+ }
+ return false;
+ }
+
+ private ActiveChangeSetManager getCollector(RepositoryProviderType type) {
+ if (type instanceof IAdaptable) {
+ IAdaptable adaptable = (IAdaptable) type;
+ Object o = adaptable.getAdapter(ActiveChangeSetManager.class);
+ if (o instanceof ActiveChangeSetManager) {
+ return (ActiveChangeSetManager) o;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Callback made from {@link #trackProject(IProject)} when a project is tracked.
+ * By default, {@link #handleProjectChange(IProject)} is called by subclasses may override.
+ * @param project the project
+ */
+ protected void projectTracked(IProject project) {
+ handleProjectChange(project);
+ }
+
+ /**
+ * Group the given modified file into a change set with the given name.
+ * @param project the project
+ * @param name the unique name used to identify the change set
+ * @param files the change files to be grouped
+ * @throws CoreException
+ */
+ protected void groupAsSet(IProject project, String name, IFile[] files) throws CoreException {
+ ActiveChangeSetManager collector = getCollector(project);
+ if (collector != null) {
+ ActiveChangeSet set = collector.getSet(name);
+ if (set == null) {
+ set = collector.createSet(name, files);
+ set.setUserCreated(false);
+ collector.add(set);
+ } else {
+ set.setUserCreated(false);
+ set.add(files);
+ }
+ }
+ }
+
+ private ActiveChangeSetManager getCollector(IProject project) {
+ return (ActiveChangeSetManager)trackedProjects.get(project);
+ }
+
+ /**
+ * Return whether the given file is modified with respect to the
+ * repository provider associated with the file's project.
+ * @param file the file
+ * @return whether the given file is modified
+ * @throws CoreException
+ */
+ protected boolean isModified(IFile file) throws CoreException {
+ ActiveChangeSetManager collector = getCollector(file.getProject());
+ if (collector != null)
+ return collector.isModified(file);
+ return false;
+ }
+
+}
diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/ActiveChangeSet.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/ActiveChangeSet.java
index a2566339c..b80d345b2 100644
--- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/ActiveChangeSet.java
+++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/ActiveChangeSet.java
@@ -14,10 +14,8 @@ import java.util.*;
import org.eclipse.core.resources.*;
import org.eclipse.core.runtime.*;
-import org.eclipse.team.core.TeamException;
import org.eclipse.team.core.diff.IDiff;
import org.eclipse.team.core.mapping.provider.ResourceDiffTree;
-import org.eclipse.team.core.subscribers.Subscriber;
import org.eclipse.team.internal.core.TeamPlugin;
import org.osgi.service.prefs.Preferences;
@@ -32,15 +30,16 @@ public class ActiveChangeSet extends DiffChangeSet {
private static final String CTX_COMMENT = "comment"; //$NON-NLS-1$
private static final String CTX_RESOURCES = "resources"; //$NON-NLS-1$
+ private final ActiveChangeSetManager manager;
private String comment;
- private final SubscriberChangeSetCollector manager;
+ private boolean userCreated;
/**
* Create a change set with the given title
* @param manager the manager that owns this set
* @param title the title of the set
*/
- public ActiveChangeSet(SubscriberChangeSetCollector manager, String title) {
+ public ActiveChangeSet(ActiveChangeSetManager manager, String title) {
super(title);
this.manager = manager;
}
@@ -101,14 +100,13 @@ public class ActiveChangeSet extends DiffChangeSet {
}
private void addResource(IResource resource) throws CoreException {
- Subscriber subscriber = getManager().getSubscriber();
- IDiff diff = subscriber.getDiff(resource);
+ IDiff diff = getManager().getDiff(resource);
if (diff != null) {
add(diff);
}
}
- private SubscriberChangeSetCollector getManager() {
+ private ActiveChangeSetManager getManager() {
return manager;
}
@@ -151,19 +149,14 @@ public class ActiveChangeSet extends DiffChangeSet {
String next = tokenizer.nextToken();
if (next.trim().length() > 0) {
IResource resource = getResource(root, next);
- try {
- // Only include the resource if it is out-of-sync
- if (resource != null && manager.getSubscriber().getSyncInfo(resource) != null) {
- try {
- addResource(resource);
- } catch (CoreException e) {
- TeamPlugin.log(e);
- }
- }
- } catch (TeamException e) {
- // Log and continue
- TeamPlugin.log(e);
- }
+ // Only include the resource if it is out-of-sync
+ try {
+ if (resource != null && getManager().getDiff(resource) != null) {
+ addResource(resource);
+ }
+ } catch (CoreException e) {
+ TeamPlugin.log(e);
+ }
}
}
} finally {
@@ -211,4 +204,20 @@ public class ActiveChangeSet extends DiffChangeSet {
add((IDiff[]) toAdd.toArray(new IDiff[toAdd.size()]));
}
}
+
+ /**
+ * Set whether this set was created by the user.
+ * @param userCreated whether this set was created by the user
+ */
+ public void setUserCreated(boolean userCreated) {
+ this.userCreated = userCreated;
+ }
+
+ /**
+ * Return whether this set was created by the user.
+ * @return whether this set was created by the user
+ */
+ public boolean isUserCreated() {
+ return userCreated;
+ }
}
diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/ActiveChangeSetManager.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/ActiveChangeSetManager.java
new file mode 100644
index 000000000..a74e7fb47
--- /dev/null
+++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/ActiveChangeSetManager.java
@@ -0,0 +1,282 @@
+/*******************************************************************************
+ * Copyright (c) 2006 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.core.subscribers;
+
+import java.util.*;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.*;
+import org.eclipse.team.core.diff.*;
+import org.eclipse.team.core.mapping.IResourceDiffTree;
+
+/**
+ * A change set manager that contains sets that represent collections of
+ * related local changes.
+ */
+public abstract class ActiveChangeSetManager extends ChangeSetManager implements IDiffChangeListener {
+
+ private ActiveChangeSet defaultSet;
+
+ /**
+ * Return the Change Set whose sync info set is the
+ * one given.
+ * @param tree a diff tree
+ * @return the change set for the given diff tree
+ */
+ protected ChangeSet getChangeSet(IResourceDiffTree tree) {
+ ChangeSet[] sets = getSets();
+ for (int i = 0; i < sets.length; i++) {
+ ChangeSet changeSet = sets[i];
+ if (((DiffChangeSet)changeSet).getDiffTree() == tree) {
+ return changeSet;
+ }
+ }
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.core.subscribers.ChangeSetManager#add(org.eclipse.team.internal.core.subscribers.ChangeSet)
+ */
+ public void add(ChangeSet set) {
+ Assert.isTrue(set instanceof ActiveChangeSet);
+ super.add(set);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.core.subscribers.AbstractChangeSetCollector#handleSetAdded(org.eclipse.team.internal.core.subscribers.ChangeSet)
+ */
+ protected void handleSetAdded(ChangeSet set) {
+ Assert.isTrue(set instanceof ActiveChangeSet);
+ ((DiffChangeSet)set).getDiffTree().addDiffChangeListener(getDiffTreeListener());
+ super.handleSetAdded(set);
+ handleAddedResources(set, ((ActiveChangeSet)set).internalGetDiffTree().getDiffs());
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.core.subscribers.AbstractChangeSetCollector#handleSetRemoved(org.eclipse.team.internal.core.subscribers.ChangeSet)
+ */
+ protected void handleSetRemoved(ChangeSet set) {
+ ((DiffChangeSet)set).getDiffTree().removeDiffChangeListener(getDiffTreeListener());
+ super.handleSetRemoved(set);
+ }
+
+ /**
+ * Return the listener that is registered with the diff trees associated with
+ * the sets for this manager.
+ * @return the listener that is registered with the diff trees associated with
+ * the sets for this manager
+ */
+ protected IDiffChangeListener getDiffTreeListener() {
+ return this;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.core.diff.IDiffChangeListener#diffsChanged(org.eclipse.team.core.diff.IDiffChangeEvent, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public void diffsChanged(IDiffChangeEvent event, IProgressMonitor monitor) {
+ IResourceDiffTree tree = (IResourceDiffTree)event.getTree();
+ handleSyncSetChange(tree, event.getAdditions(), getAllResources(event));
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.core.diff.IDiffChangeListener#propertyChanged(org.eclipse.team.core.diff.IDiffTree, int, org.eclipse.core.runtime.IPath[])
+ */
+ public void propertyChanged(IDiffTree tree, int property, IPath[] paths) {
+ // ignore
+ }
+
+ public boolean isModified(IFile file) throws CoreException {
+ IDiff diff = getDiff(file);
+ if (diff != null)
+ return isModified(diff);
+ return false;
+ }
+
+ /**
+ * Return whether the given diff represents a local change.
+ * @param diff the diff
+ * @return whether the given diff represents a local change
+ */
+ public boolean isModified(IDiff diff) {
+ if (diff != null) {
+ if (diff instanceof IThreeWayDiff) {
+ IThreeWayDiff twd = (IThreeWayDiff) diff;
+ int dir = twd.getDirection();
+ return dir == IThreeWayDiff.OUTGOING || dir == IThreeWayDiff.CONFLICTING;
+ } else {
+ return diff.getKind() != IDiff.NO_CHANGE;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Return the set with the given name.
+ * @param name the name of the set
+ * @return the set with the given name
+ */
+ public ActiveChangeSet getSet(String name) {
+ ChangeSet[] sets = getSets();
+ for (int i = 0; i < sets.length; i++) {
+ ChangeSet set = sets[i];
+ if (set.getName().equals(name) && set instanceof ActiveChangeSet) {
+ return (ActiveChangeSet)set;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Create a change set containing the given files if
+ * they have been modified locally.
+ * @param title the title of the commit set
+ * @param files the files contained in the set
+ * @return the created set
+ * @throws CoreException
+ */
+ public ActiveChangeSet createSet(String title, IFile[] files) throws CoreException {
+ List infos = new ArrayList();
+ for (int i = 0; i < files.length; i++) {
+ IFile file = files[i];
+ IDiff diff = getDiff(file);
+ if (diff != null) {
+ infos.add(diff);
+ }
+ }
+ return createSet(title, (IDiff[]) infos.toArray(new IDiff[infos.size()]));
+ }
+
+ /**
+ * Create a commit set with the given title and files. The created
+ * set is not added to the control of the commit set manager
+ * so no events are fired. The set can be added using the
+ * <code>add</code> method.
+ * @param title the title of the commit set
+ * @param diffs the files contained in the set
+ * @return the created set
+ */
+ public ActiveChangeSet createSet(String title, IDiff[] diffs) {
+ ActiveChangeSet commitSet = doCreateSet(title);
+ if (diffs != null && diffs.length > 0) {
+ commitSet.add(diffs);
+ }
+ return commitSet;
+ }
+
+ /**
+ * Create a change set with the given name.
+ * @param name the name of the change set
+ * @return the created change set
+ */
+ protected ActiveChangeSet doCreateSet(String name) {
+ return new ActiveChangeSet(this, name);
+ }
+
+ public abstract IDiff getDiff(IResource resource) throws CoreException;
+
+ /**
+ * Return whether the manager allows a resource to
+ * be in multiple sets. By default, a resource
+ * may only be in one set.
+ * @return whether the manager allows a resource to
+ * be in multiple sets.
+ */
+ protected boolean isSingleSetPerResource() {
+ return true;
+ }
+
+ private IPath[] getAllResources(IDiffChangeEvent event) {
+ Set allResources = new HashSet();
+ IDiff[] addedResources = event.getAdditions();
+ for (int i = 0; i < addedResources.length; i++) {
+ IDiff diff = addedResources[i];
+ allResources.add(diff.getPath());
+ }
+ IDiff[] changedResources = event.getChanges();
+ for (int i = 0; i < changedResources.length; i++) {
+ IDiff diff = changedResources[i];
+ allResources.add(diff.getPath());
+ }
+ IPath[] removals = event.getRemovals();
+ for (int i = 0; i < removals.length; i++) {
+ IPath path = removals[i];
+ allResources.add(path);
+ }
+ return (IPath[]) allResources.toArray(new IPath[allResources.size()]);
+ }
+
+ /**
+ * React to the given diffs being added to the given set.
+ * @param set the set
+ * @param diffs the diffs
+ */
+ protected void handleAddedResources(ChangeSet set, IDiff[] diffs) {
+ if (isSingleSetPerResource() && ((ActiveChangeSet)set).isUserCreated()) {
+ IResource[] resources = new IResource[diffs.length];
+ for (int i = 0; i < resources.length; i++) {
+ resources[i] = ((DiffChangeSet)set).getDiffTree().getResource(diffs[i]);
+ }
+ // Remove the added files from any other set that contains them
+ ChangeSet[] sets = getSets();
+ for (int i = 0; i < sets.length; i++) {
+ ChangeSet otherSet = sets[i];
+ if (otherSet != set && ((ActiveChangeSet)otherSet).isUserCreated()) {
+ otherSet.remove(resources);
+ }
+ }
+ }
+ }
+
+ private void handleSyncSetChange(IResourceDiffTree tree, IDiff[] addedDiffs, IPath[] allAffectedResources) {
+ ChangeSet changeSet = getChangeSet(tree);
+ if (tree.isEmpty() && changeSet != null) {
+ remove(changeSet);
+ }
+ fireResourcesChangedEvent(changeSet, allAffectedResources);
+ handleAddedResources(changeSet, addedDiffs);
+ }
+
+ /**
+ * Make the given set the default set into which all new modifications
+ * that are not already in another set go.
+ * @param set the set which is to become the default set
+ */
+ public void makeDefault(ActiveChangeSet set) {
+ // The default set must be an active set
+ if (!contains(set)) {
+ add(set);
+ }
+ ActiveChangeSet oldSet = defaultSet;
+ defaultSet = set;
+ fireDefaultChangedEvent(oldSet, defaultSet);
+ }
+
+ /**
+ * Return whether the given set is the default set into which all
+ * new modifications will be placed.
+ * @param set the set to test
+ * @return whether the set is the default set
+ */
+ public boolean isDefault(ActiveChangeSet set) {
+ return set == defaultSet;
+ }
+
+ /**
+ * Return the set which is currently the default or
+ * <code>null</code> if there is no default set.
+ * @return the default change set
+ */
+ public ActiveChangeSet getDefaultSet() {
+ return defaultSet;
+ }
+
+}
diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/BatchedChangeSetCollector.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/BatchingChangeSetManager.java
index 7d57c0e71..7282bf042 100644
--- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/BatchedChangeSetCollector.java
+++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/BatchingChangeSetManager.java
@@ -16,7 +16,10 @@ import org.eclipse.core.runtime.*;
import org.eclipse.core.runtime.jobs.ILock;
import org.eclipse.team.internal.core.Policy;
-public class BatchedChangeSetCollector extends ChangeSetCollector {
+/**
+ * A change set manager that batches change event notification.
+ */
+public class BatchingChangeSetManager extends ChangeSetManager {
private ILock lock = Platform.getJobManager().newLock();
@@ -25,9 +28,9 @@ public class BatchedChangeSetCollector extends ChangeSetCollector {
Set added = new HashSet();
Set removed = new HashSet();
Map changed = new HashMap();
- private final BatchedChangeSetCollector collector;
+ private final BatchingChangeSetManager collector;
- public CollectorChangeEvent(BatchedChangeSetCollector collector) {
+ public CollectorChangeEvent(BatchingChangeSetManager collector) {
this.collector = collector;
}
@@ -83,7 +86,7 @@ public class BatchedChangeSetCollector extends ChangeSetCollector {
return (IPath[])changed.get(set);
}
- public BatchedChangeSetCollector getSource() {
+ public BatchingChangeSetManager getSource() {
return collector;
}
}
diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/ChangeSetCollector.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/ChangeSetManager.java
index 952aba5e6..9a1ce1407 100644
--- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/ChangeSetCollector.java
+++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/ChangeSetManager.java
@@ -16,13 +16,17 @@ import java.util.Set;
import org.eclipse.core.runtime.*;
/**
- * An abstract change set collector that is not tied to a particular type of change set.
+ * An abstract class that managers a collection of change sets.
*/
-public abstract class ChangeSetCollector {
+public abstract class ChangeSetManager {
private ListenerList listeners = new ListenerList(ListenerList.IDENTITY);
private Set sets = new HashSet();
+ /**
+ * Return the list of listeners registered with this change set manager.
+ * @return the list of listeners registered with this change set manager
+ */
protected Object[] getListeners() {
return listeners.getListeners();
}
diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/DiffTreeChangeSetCollector.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/DiffTreeChangeSetCollector.java
deleted file mode 100644
index 29e00a6d5..000000000
--- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/DiffTreeChangeSetCollector.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2006 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.core.subscribers;
-
-import org.eclipse.team.core.diff.IDiffChangeListener;
-import org.eclipse.team.core.mapping.IResourceDiffTree;
-
-/**
- * A change set collector for change sets whose underlying representation is a diff tree
- */
-public abstract class DiffTreeChangeSetCollector extends ChangeSetCollector {
-
- /**
- * Return the Change Set whose sync info set is the
- * one given.
- * @param tree a diff tree
- * @return the change set for the given diff tree
- */
- protected ChangeSet getChangeSet(IResourceDiffTree tree) {
- ChangeSet[] sets = getSets();
- for (int i = 0; i < sets.length; i++) {
- ChangeSet changeSet = sets[i];
- if (((DiffChangeSet)changeSet).getDiffTree() == tree) {
- return changeSet;
- }
- }
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.team.internal.core.subscribers.AbstractChangeSetCollector#handleSetAdded(org.eclipse.team.internal.core.subscribers.ChangeSet)
- */
- protected void handleSetAdded(ChangeSet set) {
- ((DiffChangeSet)set).getDiffTree().addDiffChangeListener(getDiffTreeListener());
- super.handleSetAdded(set);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.team.internal.core.subscribers.AbstractChangeSetCollector#handleSetRemoved(org.eclipse.team.internal.core.subscribers.ChangeSet)
- */
- protected void handleSetRemoved(ChangeSet set) {
- ((DiffChangeSet)set).getDiffTree().removeDiffChangeListener(getDiffTreeListener());
- super.handleSetRemoved(set);
- }
-
- protected abstract IDiffChangeListener getDiffTreeListener();
-
-}
diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/SubscriberChangeSetCollector.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/SubscriberChangeSetManager.java
index 85eaf8355..1770eb8a9 100644
--- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/SubscriberChangeSetCollector.java
+++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/SubscriberChangeSetManager.java
@@ -12,15 +12,13 @@ package org.eclipse.team.internal.core.subscribers;
import java.util.*;
-import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.*;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.osgi.util.NLS;
import org.eclipse.team.core.TeamException;
-import org.eclipse.team.core.diff.*;
-import org.eclipse.team.core.mapping.IResourceDiffTree;
+import org.eclipse.team.core.diff.IDiff;
import org.eclipse.team.core.mapping.provider.ResourceDiffTree;
import org.eclipse.team.core.subscribers.Subscriber;
import org.eclipse.team.internal.core.*;
@@ -30,7 +28,7 @@ import org.osgi.service.prefs.Preferences;
/**
* This class manages the active change sets associated with a subscriber.
*/
-public class SubscriberChangeSetCollector extends DiffTreeChangeSetCollector implements IDiffChangeListener {
+public class SubscriberChangeSetManager extends ActiveChangeSetManager {
private static final String PREF_CHANGE_SETS = "changeSets"; //$NON-NLS-1$
private static final String CTX_DEFAULT_SET = "defaultSet"; //$NON-NLS-1$
@@ -38,7 +36,6 @@ public class SubscriberChangeSetCollector extends DiffTreeChangeSetCollector imp
private static final int RESOURCE_REMOVAL = 1;
private static final int RESOURCE_CHANGE = 2;
- private ActiveChangeSet defaultSet;
private EventHandler handler;
private ResourceCollector collector;
@@ -191,8 +188,8 @@ public class SubscriberChangeSetCollector extends DiffTreeChangeSetCollector imp
if (containingSets.length == 0) {
// Consider for inclusion in the default set
// if the resource is not already a member of another set
- if (defaultSet != null) {
- defaultSet.add(diff);
+ if (getDefaultSet() != null) {
+ getDefaultSet().add(diff);
}
} else {
for (int i = 0; i < containingSets.length; i++) {
@@ -265,11 +262,11 @@ public class SubscriberChangeSetCollector extends DiffTreeChangeSetCollector imp
}
protected boolean hasMembers(IResource resource) {
- return SubscriberChangeSetCollector.this.hasMembers(resource);
+ return SubscriberChangeSetManager.this.hasMembers(resource);
}
}
- public SubscriberChangeSetCollector(Subscriber subscriber) {
+ public SubscriberChangeSetManager(Subscriber subscriber) {
collector = new ResourceCollector(subscriber);
load();
handler = new EventHandler(NLS.bind(Messages.SubscriberChangeSetCollector_1, new String[] { subscriber.getName() }), NLS.bind(Messages.SubscriberChangeSetCollector_2, new String[] { subscriber.getName() })); //
@@ -282,118 +279,11 @@ public class SubscriberChangeSetCollector extends DiffTreeChangeSetCollector imp
if (set.getDiffTree().getChildren(resource.getFullPath()).length > 0)
return true;
}
- if (defaultSet != null)
- return (defaultSet.getDiffTree().getChildren(resource.getFullPath()).length > 0);
+ if (getDefaultSet() != null)
+ return (getDefaultSet().getDiffTree().getChildren(resource.getFullPath()).length > 0);
return false;
}
- /* (non-Javadoc)
- * @see org.eclipse.team.internal.core.subscribers.ChangeSetCollector#add(org.eclipse.team.internal.core.subscribers.ChangeSet)
- */
- public void add(ChangeSet set) {
- Assert.isTrue(set instanceof ActiveChangeSet);
- super.add(set);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.team.internal.core.subscribers.DiffTreeChangeSetCollector#handleSetAdded(org.eclipse.team.internal.core.subscribers.ChangeSet)
- */
- protected void handleSetAdded(ChangeSet set) {
- Assert.isTrue(set instanceof ActiveChangeSet);
- super.handleSetAdded(set);
- handleAddedResources(set, ((ActiveChangeSet)set).internalGetDiffTree().getDiffs());
- }
-
- /**
- * Return whether the manager allows a resource to
- * be in multiple sets. By default, a resource
- * may only be in one set.
- * @return whether the manager allows a resource to
- * be in multiple sets.
- */
- protected boolean isSingleSetPerResource() {
- return true;
- }
-
- /**
- * Create a commit set with the given title and files. The created
- * set is not added to the control of the commit set manager
- * so no events are fired. The set can be added using the
- * <code>add</code> method.
- * @param title the title of the commit set
- * @param diffs the files contained in the set
- * @return the created set
- */
- public ActiveChangeSet createSet(String title, IDiff[] diffs) {
- ActiveChangeSet commitSet = doCreateSet(title);
- if (diffs != null && diffs.length > 0) {
- commitSet.add(diffs);
- }
- return commitSet;
- }
-
- /**
- * Create a change set with the given name.
- * @param name the name of the change set
- * @return the created change set
- */
- protected ActiveChangeSet doCreateSet(String name) {
- return new ActiveChangeSet(this, name);
- }
-
- /**
- * Create a change set containing the given files if
- * they have been modified locally.
- * @param title the title of the commit set
- * @param files the files contained in the set
- * @return the created set
- * @throws CoreException
- */
- public ActiveChangeSet createSet(String title, IFile[] files) throws CoreException {
- List infos = new ArrayList();
- for (int i = 0; i < files.length; i++) {
- IFile file = files[i];
- IDiff diff = getDiff(file);
- if (diff != null) {
- infos.add(diff);
- }
- }
- return createSet(title, (IDiff[]) infos.toArray(new IDiff[infos.size()]));
- }
-
- /**
- * Make the given set the default set into which all new modifications
- * that are not already in another set go.
- * @param set the set which is to become the default set
- */
- public void makeDefault(ActiveChangeSet set) {
- // The default set must be an active set
- if (!contains(set)) {
- add(set);
- }
- ActiveChangeSet oldSet = defaultSet;
- defaultSet = set;
- fireDefaultChangedEvent(oldSet, defaultSet);
- }
-
- /**
- * Return the set which is currently the default or
- * <code>null</code> if there is no default set.
- * @return the default change set
- */
- public ActiveChangeSet getDefaultSet() {
- return defaultSet;
- }
- /**
- * Return whether the given set is the default set into which all
- * new modifications will be placed.
- * @param set the set to test
- * @return whether the set is the default set
- */
- public boolean isDefault(ActiveChangeSet set) {
- return set == defaultSet;
- }
-
/**
* Return the sync info for the given resource obtained
* from the subscriber.
@@ -401,7 +291,7 @@ public class SubscriberChangeSetCollector extends DiffTreeChangeSetCollector imp
* @return the sync info for the resource
* @throws CoreException
*/
- protected IDiff getDiff(IResource resource) throws CoreException {
+ public IDiff getDiff(IResource resource) throws CoreException {
Subscriber subscriber = getSubscriber();
return subscriber.getDiff(resource);
}
@@ -414,19 +304,6 @@ public class SubscriberChangeSetCollector extends DiffTreeChangeSetCollector imp
return collector.getSubscriber();
}
- protected boolean isModified(IDiff diff) {
- if (diff != null) {
- if (diff instanceof IThreeWayDiff) {
- IThreeWayDiff twd = (IThreeWayDiff) diff;
- int dir = twd.getDirection();
- return dir == IThreeWayDiff.OUTGOING || dir == IThreeWayDiff.CONFLICTING;
- } else {
- return diff.getKind() != IDiff.NO_CHANGE;
- }
- }
- return false;
- }
-
/* (non-Javadoc)
* @see org.eclipse.team.internal.core.subscribers.SubscriberResourceCollector#dispose()
*/
@@ -457,8 +334,8 @@ public class SubscriberChangeSetCollector extends DiffTreeChangeSetCollector imp
((ActiveChangeSet)set).save(child);
}
}
- if (defaultSet != null) {
- prefs.put(CTX_DEFAULT_SET, defaultSet.getTitle());
+ if (getDefaultSet() != null) {
+ prefs.put(CTX_DEFAULT_SET, getDefaultSet().getTitle());
}
try {
prefs.flush();
@@ -477,8 +354,8 @@ public class SubscriberChangeSetCollector extends DiffTreeChangeSetCollector imp
Preferences childPrefs = prefs.node(string);
ActiveChangeSet set = createSet(string, childPrefs);
if (!set.isEmpty()) {
- if (defaultSet == null && defaultSetTitle != null && set.getTitle().equals(defaultSetTitle)) {
- defaultSet = set;
+ if (getDefaultSet() == null && defaultSetTitle != null && set.getTitle().equals(defaultSetTitle)) {
+ makeDefault(set);
}
add(set);
}
@@ -521,59 +398,6 @@ public class SubscriberChangeSetCollector extends DiffTreeChangeSetCollector imp
return getSubscriber().getName();
}
- private IPath[] getAllResources(IDiffChangeEvent event) {
- Set allResources = new HashSet();
- IDiff[] addedResources = event.getAdditions();
- for (int i = 0; i < addedResources.length; i++) {
- IDiff diff = addedResources[i];
- allResources.add(diff.getPath());
- }
- IDiff[] changedResources = event.getChanges();
- for (int i = 0; i < changedResources.length; i++) {
- IDiff diff = changedResources[i];
- allResources.add(diff.getPath());
- }
- IPath[] removals = event.getRemovals();
- for (int i = 0; i < removals.length; i++) {
- IPath path = removals[i];
- allResources.add(path);
- }
- return (IPath[]) allResources.toArray(new IPath[allResources.size()]);
- }
-
- private void handleAddedResources(ChangeSet set, IDiff[] diffs) {
- if (isSingleSetPerResource()) {
- IResource[] resources = new IResource[diffs.length];
- for (int i = 0; i < resources.length; i++) {
- resources[i] = ((DiffChangeSet)set).getDiffTree().getResource(diffs[i]);
- }
- // Remove the added files from any other set that contains them
- ChangeSet[] sets = getSets();
- for (int i = 0; i < sets.length; i++) {
- ChangeSet otherSet = sets[i];
- if (otherSet != set) {
- otherSet.remove(resources);
- }
- }
- }
- }
-
- private void handleSyncSetChange(IResourceDiffTree tree, IDiff[] addedDiffs, IPath[] allAffectedResources) {
- ChangeSet changeSet = getChangeSet(tree);
- if (tree.isEmpty() && changeSet != null) {
- remove(changeSet);
- }
- fireResourcesChangedEvent(changeSet, allAffectedResources);
- handleAddedResources(changeSet, addedDiffs);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.team.core.subscribers.ChangeSetCollector#getChangeSetSyncSetChangeListener()
- */
- protected IDiffChangeListener getDiffTreeListener() {
- return this;
- }
-
/**
* Wait until the collector is done processing any events.
* This method is for testing purposes only.
@@ -592,13 +416,4 @@ public class SubscriberChangeSetCollector extends DiffTreeChangeSetCollector imp
}
monitor.worked(1);
}
-
- public void diffsChanged(IDiffChangeEvent event, IProgressMonitor monitor) {
- IResourceDiffTree tree = (IResourceDiffTree)event.getTree();
- handleSyncSetChange(tree, event.getAdditions(), getAllResources(event));
- }
-
- public void propertyChanged(IDiffTree tree, int property, IPath[] paths) {
- // ignore
- }
}

Back to the top