Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Zarna2011-11-18 12:21:27 +0000
committerTomasz Zarna2011-11-18 12:21:27 +0000
commit951477fe0d9d1aa4bbfcabd936d0d7641c6f712a (patch)
tree952b09572474681f93c2570abf2fa478062b5910
parentcfa9a16b8044938883a013f0f31a1919520603be (diff)
downloadeclipse.platform.team-951477fe0d9d1aa4bbfcabd936d0d7641c6f712a.tar.gz
eclipse.platform.team-951477fe0d9d1aa4bbfcabd936d0d7641c6f712a.tar.xz
eclipse.platform.team-951477fe0d9d1aa4bbfcabd936d0d7641c6f712a.zip
bug 352016: [Sync View] Team synchronization filteringv20111118-1221
-rw-r--r--bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/AbstractContentComparator.java106
-rw-r--r--bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/ContentComparator.java94
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIMessages.java5
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIPlugin.java8
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/ComparePreferencePage.java38
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/ICVSUIConstants.java6
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/mappings/CompareSubscriberContext.java66
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/mappings/WorkspaceSubscriberContext.java94
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/messages.properties1
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/CompareParticipant.java68
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/RegexSyncInfoFilter.java67
-rw-r--r--bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/WorkspaceSynchronizeParticipant.java83
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/preferences/SyncViewerPreferencePage.java7
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/RangeDifferenceComparator.java72
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/RegexDiffComparator.java71
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/RegexDiffFilter.java64
16 files changed, 725 insertions, 125 deletions
diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/AbstractContentComparator.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/AbstractContentComparator.java
new file mode 100644
index 000000000..9a0cf1fe2
--- /dev/null
+++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/AbstractContentComparator.java
@@ -0,0 +1,106 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.io.*;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.team.core.TeamException;
+import org.eclipse.team.core.history.IFileRevision;
+import org.eclipse.team.core.variants.IResourceVariant;
+import org.eclipse.team.internal.core.Policy;
+import org.eclipse.team.internal.core.TeamPlugin;
+
+/**
+ * Compare local and remote contents.
+ *
+ * This comparator makes use of the <code>IStorage</code> provided by
+ * an <code>IResourceVariant</code> or an <code>IFileRevision</code>to obtain the remote contents.
+ * This means that the comparison may contact the server unless the contents
+ * were cached locally by a previous operation. The caching of remote
+ * contents is subscriber specific.
+ */
+public abstract class AbstractContentComparator {
+ private boolean ignoreWhitespace = false;
+
+ public AbstractContentComparator(boolean ignoreWhitespace) {
+ this.ignoreWhitespace = ignoreWhitespace;
+ }
+
+ public boolean compare(IResource e1, IResourceVariant e2, IProgressMonitor monitor) {
+ return compareObjects(e1, e2, monitor);
+ }
+
+ public boolean compare(IResource e1, IFileRevision e2, IProgressMonitor monitor) {
+ return compareObjects(e1, e2, monitor);
+ }
+
+ private boolean compareObjects(Object e1, Object e2, IProgressMonitor monitor) {
+ InputStream is1 = null;
+ InputStream is2 = null;
+ try {
+ monitor.beginTask(null, 100);
+ is1 = getContents(e1, Policy.subMonitorFor(monitor, 30));
+ is2 = getContents(e2, Policy.subMonitorFor(monitor, 30));
+ return contentsEqual(Policy.subMonitorFor(monitor, 40), is1, is2, shouldIgnoreWhitespace());
+ } catch (TeamException e) {
+ TeamPlugin.log(e);
+ return false;
+ } finally {
+ try {
+ try {
+ if (is1 != null) {
+ is1.close();
+ }
+ } finally {
+ if (is2 != null) {
+ is2.close();
+ }
+ }
+ } catch (IOException e) {
+ // Ignore
+ }
+ monitor.done();
+ }
+ }
+
+ protected boolean shouldIgnoreWhitespace() {
+ return ignoreWhitespace;
+ }
+
+ abstract protected boolean contentsEqual(IProgressMonitor monitor, InputStream is1, InputStream is2,
+ boolean ignoreWhitespace);
+
+ private InputStream getContents(Object resource, IProgressMonitor monitor)
+ throws TeamException {
+ try {
+ if (resource instanceof IFile) {
+ return new BufferedInputStream(((IFile) resource).getContents());
+ } else if (resource instanceof IResourceVariant) {
+ IResourceVariant remote = (IResourceVariant) resource;
+ if (!remote.isContainer()) {
+ return new BufferedInputStream(remote.getStorage(monitor)
+ .getContents());
+ }
+ } else if (resource instanceof IFileRevision) {
+ IFileRevision remote = (IFileRevision) resource;
+ return new BufferedInputStream(remote.getStorage(monitor)
+ .getContents());
+ }
+ return null;
+ } catch (CoreException e) {
+ throw TeamException.asTeamException(e);
+ }
+ }
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/ContentComparator.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/ContentComparator.java
index 210f25bd7..9e2e05bca 100644
--- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/ContentComparator.java
+++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/subscribers/ContentComparator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * Copyright (c) 2000, 2011 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
@@ -10,81 +10,43 @@
*******************************************************************************/
package org.eclipse.team.internal.core.subscribers;
-import java.io.*;
+import java.io.IOException;
+import java.io.InputStream;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.*;
-import org.eclipse.team.core.TeamException;
-import org.eclipse.team.core.history.IFileRevision;
-import org.eclipse.team.core.variants.IResourceVariant;
-import org.eclipse.team.internal.core.Policy;
-import org.eclipse.team.internal.core.TeamPlugin;
+import org.eclipse.core.runtime.IProgressMonitor;
/**
- * This is an internal class that is used by the <code>ContentComparisonSyncInfoFilter</code>
- * to compare the contents of the local and remote resources
+ * This is an internal class that is used by the
+ * {@link org.eclipse.team.core.synchronize.SyncInfoFilter.ContentComparisonSyncInfoFilter}
+ * and {@link ContentComparisonDiffFilter} to compare the contents of the local
+ * and remote resources.
*/
-public class ContentComparator {
-
- private boolean ignoreWhitespace = false;
+public class ContentComparator extends AbstractContentComparator{
public ContentComparator(boolean ignoreWhitespace) {
- this.ignoreWhitespace = ignoreWhitespace;
- }
-
- public boolean compare(Object e1, Object e2, IProgressMonitor monitor) {
- InputStream is1 = null;
- InputStream is2 = null;
- try {
- monitor.beginTask(null, 100);
- is1 = getContents(e1, Policy.subMonitorFor(monitor, 50));
- is2 = getContents(e2, Policy.subMonitorFor(monitor, 50));
- return contentsEqual(is1, is2, shouldIgnoreWhitespace());
- } catch(TeamException e) {
- TeamPlugin.log(e);
- return false;
- } finally {
- try {
- try {
- if (is1 != null) {
- is1.close();
- }
- } finally {
- if (is2 != null) {
- is2.close();
- }
- }
- } catch (IOException e) {
- // Ignore
- }
- monitor.done();
- }
- }
-
- protected boolean shouldIgnoreWhitespace() {
- return ignoreWhitespace;
+ super(ignoreWhitespace);
}
/**
* Returns <code>true</code> if both input streams byte contents is
* identical.
*
- * @param input1
+ * @param is1
* first input to contents compare
- * @param input2
+ * @param is2
* second input to contents compare
* @return <code>true</code> if content is equal
*/
- private boolean contentsEqual(InputStream is1, InputStream is2, boolean ignoreWhitespace) {
+ protected boolean contentsEqual(IProgressMonitor monitor, InputStream is1,
+ InputStream is2, boolean ignoreWhitespace) {
try {
if (is1 == is2)
return true;
-
- if (is1 == null && is2 == null) // no byte contents
+ // no byte contents
+ if (is1 == null && is2 == null)
return true;
-
- if (is1 == null || is2 == null) // only one has
- // contents
+ // only one has contents
+ if (is1 == null || is2 == null)
return false;
while (true) {
@@ -98,7 +60,6 @@ public class ContentComparator {
return true;
if (c1 != c2)
break;
-
}
} catch (IOException ex) {
} finally {
@@ -124,23 +85,4 @@ public class ContentComparator {
return false;
return Character.isWhitespace((char) c);
}
-
- private InputStream getContents(Object resource, IProgressMonitor monitor) throws TeamException {
- try {
- if (resource instanceof IFile) {
- return new BufferedInputStream(((IFile) resource).getContents());
- } else if(resource instanceof IResourceVariant) {
- IResourceVariant remote = (IResourceVariant)resource;
- if (!remote.isContainer()) {
- return new BufferedInputStream(remote.getStorage(monitor).getContents());
- }
- } else if(resource instanceof IFileRevision) {
- IFileRevision remote = (IFileRevision)resource;
- return new BufferedInputStream(remote.getStorage(monitor).getContents());
- }
- return null;
- } catch (CoreException e) {
- throw TeamException.asTeamException(e);
- }
- }
}
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIMessages.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIMessages.java
index a49af0f10..78ce9d49b 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIMessages.java
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIMessages.java
@@ -48,7 +48,6 @@ public class CVSUIMessages extends NLS {
public static String CommitWizard_13;
public static String CommitWizard_8;
public static String CommitWizard_9;
- public static String ComparePreferencePage_8;
public static String CreatePatchAction_0;
public static String CreatePatchAction_1;
public static String CVSHistoryPage_CollapseAllAction;
@@ -1011,7 +1010,10 @@ public class CVSUIMessages extends NLS {
public static String ComparePreferencePage_2;
public static String ComparePreferencePage_3;
public static String ComparePreferencePage_4;
+ public static String ComparePreferencePage_5;
public static String ComparePreferencePage_6;
+ public static String ComparePreferencePage_7;
+ public static String ComparePreferencePage_8;
public static String FileModificationValidator_3;
public static String FileModificationValidator_4;
@@ -1152,7 +1154,6 @@ public class CVSUIMessages extends NLS {
public static String CVSHistoryFilterDialog_showLocalRevisions;
public static String CVSHistoryTableProvider_base;
public static String CVSHistoryTableProvider_currentVersion;
- public static String ComparePreferencePage_7;
public static String WorkspaceTraversalAction_0;
public static String OutgoingChangesDialog_0;
public static String OutgoingChangesDialog_1;
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIPlugin.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIPlugin.java
index 6d1896b0d..0112f1453 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIPlugin.java
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIPlugin.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
+ * Copyright (c) 2000, 2011 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
@@ -21,6 +21,7 @@ import java.util.*;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceStatus;
import org.eclipse.core.runtime.*;
+import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.jface.dialogs.*;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.preference.IPreferenceStore;
@@ -578,6 +579,7 @@ public class CVSUIPlugin extends AbstractUIPlugin {
store.setDefault(ICVSUIConstants.PREF_PRUNE_EMPTY_DIRECTORIES, CVSProviderPlugin.DEFAULT_PRUNE);
store.setDefault(ICVSUIConstants.PREF_TIMEOUT, CVSProviderPlugin.DEFAULT_TIMEOUT);
store.setDefault(ICVSUIConstants.PREF_CONSIDER_CONTENTS, true);
+ store.setDefault(ICVSUIConstants.PREF_SYNCVIEW_REGEX_FILTER_PATTERN, ""); //default pattern is empty string //$NON-NLS-1$
store.setDefault(ICVSUIConstants.PREF_COMPRESSION_LEVEL, CVSProviderPlugin.DEFAULT_COMPRESSION_LEVEL);
store.setDefault(ICVSUIConstants.PREF_TEXT_KSUBST, CVSProviderPlugin.DEFAULT_TEXT_KSUBST_OPTION.toMode());
store.setDefault(ICVSUIConstants.PREF_USE_PLATFORM_LINEEND, true);
@@ -755,4 +757,8 @@ public class CVSUIPlugin extends AbstractUIPlugin {
public ActiveChangeSetManager getChangeSetManager() {
return CVSProviderPlugin.getPlugin().getChangeSetManager();
}
+
+ public org.osgi.service.prefs.Preferences getInstancePreferences() {
+ return InstanceScope.INSTANCE.getNode(getBundle().getSymbolicName());
+ }
}
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/ComparePreferencePage.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/ComparePreferencePage.java
index fb199d292..7f67d0611 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/ComparePreferencePage.java
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/ComparePreferencePage.java
@@ -11,8 +11,11 @@
package org.eclipse.team.internal.ccvs.ui;
import org.eclipse.compare.CompareUI;
-import org.eclipse.jface.preference.BooleanFieldEditor;
-import org.eclipse.jface.preference.IPreferencePageContainer;
+import org.eclipse.jface.preference.*;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Event;
import org.eclipse.team.internal.ui.SWTUtils;
import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer;
@@ -20,6 +23,8 @@ import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer;
* Preference page for configuring CVS comparisons
*/
public class ComparePreferencePage extends CVSFieldEditorPreferencePage {
+ private BooleanFieldEditor contents;
+ private StringFieldEditor regex;
/* (non-Javadoc)
* @see org.eclipse.team.internal.ccvs.ui.CVSFieldEditorPreferencePage#getPageHelpContextId()
@@ -39,22 +44,43 @@ public class ComparePreferencePage extends CVSFieldEditorPreferencePage {
* @see org.eclipse.jface.preference.FieldEditorPreferencePage#createFieldEditors()
*/
protected void createFieldEditors() {
- addField(new BooleanFieldEditor(ICVSUIConstants.PREF_CONSIDER_CONTENTS,
+ IPreferenceStore store = getPreferenceStore();
+
+ contents = new BooleanFieldEditor(ICVSUIConstants.PREF_CONSIDER_CONTENTS,
CVSUIMessages.ComparePreferencePage_4,
BooleanFieldEditor.DEFAULT, getFieldEditorParent()) {
+ private Event selectionEvent = createSelectionEvent();
+ private Event createSelectionEvent() {
+ Event event = new Event();
+ event.type = SWT.Selection;
+ return event;
+ }
// invert the UI
protected void doLoad() {
super.doLoad();
getChangeControl(getFieldEditorParent()).setSelection(!getBooleanValue());
+ getChangeControl(getFieldEditorParent()).notifyListeners(SWT.Selection,
+ selectionEvent);
}
protected void doLoadDefault() {
super.doLoadDefault();
getChangeControl(getFieldEditorParent()).setSelection(!getBooleanValue());
+ getChangeControl(getFieldEditorParent()).notifyListeners(SWT.Selection,
+ selectionEvent);
}
protected void doStore() {
getPreferenceStore().setValue(getPreferenceName(), !getBooleanValue());
}
- });
+ };
+ addField(contents);
+ regex = new StringFieldEditor(ICVSUIConstants.PREF_SYNCVIEW_REGEX_FILTER_PATTERN,
+ CVSUIMessages.ComparePreferencePage_5,
+ getFieldEditorParent());
+ addField(regex);
+ GridData data = new GridData();
+ data.horizontalIndent = 20;
+ regex.getLabelControl(getFieldEditorParent()).setLayoutData(data);
+ regex.setEnabled(store.getBoolean(ICVSUIConstants.PREF_CONSIDER_CONTENTS), getFieldEditorParent());
addField(new BooleanFieldEditor(
ICVSUIConstants.PREF_SHOW_COMPARE_REVISION_IN_DIALOG,
CVSUIMessages.ComparePreferencePage_3,
@@ -84,4 +110,8 @@ public class ComparePreferencePage extends CVSFieldEditorPreferencePage {
}
}
+ public void propertyChange(PropertyChangeEvent event) {
+ super.propertyChange(event);
+ regex.setEnabled(!contents.getBooleanValue(), getFieldEditorParent());
+ }
}
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/ICVSUIConstants.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/ICVSUIConstants.java
index 35917d6a4..b5f1355ea 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/ICVSUIConstants.java
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/ICVSUIConstants.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * Copyright (c) 2000, 2011 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
@@ -93,6 +93,10 @@ public interface ICVSUIConstants {
public final String PREF_CVS_RSH_PARAMETERS = "pref_cvs_rsh_parameters"; //$NON-NLS-1$
public final String PREF_CVS_SERVER = "pref_cvs_server"; //$NON-NLS-1$
public final String PREF_CONSIDER_CONTENTS = "pref_consider_contents"; //$NON-NLS-1$
+ /**
+ * Preference to save the pattern for the regex filter used in the Synchronize View.
+ */
+ public final String PREF_SYNCVIEW_REGEX_FILTER_PATTERN = "pref_syncview_regex_filter_pattern"; //$NON-NLS-1$
public final String PREF_REPLACE_UNMANAGED = "pref_replace_unmanaged"; //$NON-NLS-1$
public final String PREF_COMPRESSION_LEVEL = "pref_compression_level"; //$NON-NLS-1$
public final String PREF_TEXT_KSUBST = "pref_text_ksubst"; //$NON-NLS-1$
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/mappings/CompareSubscriberContext.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/mappings/CompareSubscriberContext.java
index f5a0631b4..fa871781d 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/mappings/CompareSubscriberContext.java
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/mappings/CompareSubscriberContext.java
@@ -10,9 +10,11 @@
*******************************************************************************/
package org.eclipse.team.internal.ccvs.ui.mappings;
-import org.eclipse.core.runtime.*;
-import org.eclipse.core.runtime.Preferences.IPropertyChangeListener;
-import org.eclipse.core.runtime.Preferences.PropertyChangeEvent;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.preferences.*;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
import org.eclipse.team.core.diff.DiffFilter;
import org.eclipse.team.core.diff.IDiff;
import org.eclipse.team.core.mapping.ISynchronizationScopeManager;
@@ -23,8 +25,9 @@ import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin;
import org.eclipse.team.internal.ccvs.ui.ICVSUIConstants;
import org.eclipse.team.internal.core.subscribers.ContentComparisonDiffFilter;
import org.eclipse.team.internal.core.subscribers.SubscriberDiffTreeEventHandler;
+import org.eclipse.team.internal.ui.synchronize.RegexDiffFilter;
-public class CompareSubscriberContext extends CVSSubscriberMergeContext implements IPropertyChangeListener {
+public class CompareSubscriberContext extends CVSSubscriberMergeContext implements IPreferenceChangeListener {
public static SynchronizationContext createContext(ISynchronizationScopeManager manager, CVSCompareSubscriber subscriber) {
CompareSubscriberContext mergeContext = new CompareSubscriberContext(subscriber, manager);
@@ -34,7 +37,7 @@ public class CompareSubscriberContext extends CVSSubscriberMergeContext implemen
protected CompareSubscriberContext(Subscriber subscriber, ISynchronizationScopeManager manager) {
super(subscriber, manager);
- CVSUIPlugin.getPlugin().getPluginPreferences().addPropertyChangeListener(this);
+ ((IEclipsePreferences) CVSUIPlugin.getPlugin().getInstancePreferences().node("")).addPreferenceChangeListener(this); //$NON-NLS-1$
}
/* (non-Javadoc)
@@ -42,7 +45,7 @@ public class CompareSubscriberContext extends CVSSubscriberMergeContext implemen
*/
public void dispose() {
super.dispose();
- CVSUIPlugin.getPlugin().getPluginPreferences().removePropertyChangeListener(this);
+ ((IEclipsePreferences) CVSUIPlugin.getPlugin().getInstancePreferences().node("")).removePreferenceChangeListener(this); //$NON-NLS-1$
}
/* (non-Javadoc)
@@ -57,20 +60,59 @@ public class CompareSubscriberContext extends CVSSubscriberMergeContext implemen
* @see org.eclipse.team.core.subscribers.SubscriberMergeContext#getDiffFilter()
*/
protected DiffFilter getDiffFilter() {
- if (CVSUIPlugin.getPlugin().getPluginPreferences().getBoolean(ICVSUIConstants.PREF_CONSIDER_CONTENTS)) {
- // Return a filter that selects any diffs whose contents are not equal
- final DiffFilter contentsEqual = new ContentComparisonDiffFilter(false);
+ final DiffFilter contentFilter = createContentFilter();
+ final DiffFilter regexFilter = createRegexFilter();
+ if (contentFilter != null && regexFilter != null) {
+ return new DiffFilter() {
+ public boolean select(IDiff diff, IProgressMonitor monitor) {
+ return !contentFilter.select(diff, monitor)
+ && !regexFilter.select(diff, monitor);
+ }
+ };
+ } else if (contentFilter != null) {
+ return new DiffFilter() {
+ public boolean select(IDiff diff, IProgressMonitor monitor) {
+ return !contentFilter.select(diff, monitor);
+ }
+ };
+ } else if (regexFilter != null) {
return new DiffFilter() {
public boolean select(IDiff diff, IProgressMonitor monitor) {
- return !contentsEqual.select(diff, monitor);
+ return !regexFilter.select(diff, monitor);
}
};
}
return null;
}
- public void propertyChange(PropertyChangeEvent event) {
- if (event.getProperty().equals(ICVSUIConstants.PREF_CONSIDER_CONTENTS)) {
+ private boolean isConsiderContents() {
+ return CVSUIPlugin.getPlugin().getPreferenceStore().getBoolean(ICVSUIConstants.PREF_CONSIDER_CONTENTS);
+ }
+
+ private DiffFilter createContentFilter() {
+ if (isConsiderContents()) {
+ // Return a filter that selects any diffs whose contents are not equal
+ return new ContentComparisonDiffFilter(false);
+ }
+ return null;
+ }
+
+ private DiffFilter createRegexFilter() {
+ if (isConsiderContents()) {
+ String pattern = CVSUIPlugin.getPlugin().getPreferenceStore().getString(
+ ICVSUIConstants.PREF_SYNCVIEW_REGEX_FILTER_PATTERN);
+ if (pattern != null && !pattern.equals("")) { //$NON-NLS-1$
+ return new RegexDiffFilter(pattern);
+ }
+ }
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener#preferenceChange(org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent)
+ */
+ public void preferenceChange(PreferenceChangeEvent event) {
+ if (event.getKey().equals(ICVSUIConstants.PREF_CONSIDER_CONTENTS) || event.getKey().equals(ICVSUIConstants.PREF_SYNCVIEW_REGEX_FILTER_PATTERN)) {
SubscriberDiffTreeEventHandler handler = getHandler();
if (handler != null) {
handler.setFilter(getDiffFilter());
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/mappings/WorkspaceSubscriberContext.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/mappings/WorkspaceSubscriberContext.java
index e8f8e6350..3c83216fb 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/mappings/WorkspaceSubscriberContext.java
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/mappings/WorkspaceSubscriberContext.java
@@ -17,18 +17,19 @@ import java.util.List;
import org.eclipse.core.resources.*;
import org.eclipse.core.resources.mapping.*;
import org.eclipse.core.runtime.*;
+import org.eclipse.core.runtime.preferences.*;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
import org.eclipse.osgi.util.NLS;
import org.eclipse.team.core.RepositoryProvider;
-import org.eclipse.team.core.diff.IDiff;
-import org.eclipse.team.core.diff.IThreeWayDiff;
+import org.eclipse.team.core.diff.*;
import org.eclipse.team.core.diff.provider.DiffTree;
import org.eclipse.team.core.history.IFileRevision;
import org.eclipse.team.core.mapping.*;
import org.eclipse.team.core.mapping.provider.ResourceDiffTree;
import org.eclipse.team.core.subscribers.Subscriber;
import org.eclipse.team.core.subscribers.SubscriberScopeManager;
-import org.eclipse.team.core.synchronize.SyncInfo;
-import org.eclipse.team.core.synchronize.SyncInfoFilter;
+import org.eclipse.team.core.synchronize.*;
import org.eclipse.team.core.synchronize.SyncInfoFilter.ContentComparisonSyncInfoFilter;
import org.eclipse.team.core.variants.IResourceVariant;
import org.eclipse.team.internal.ccvs.core.*;
@@ -38,11 +39,14 @@ import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot;
import org.eclipse.team.internal.ccvs.core.resources.RemoteFile;
import org.eclipse.team.internal.ccvs.ui.*;
import org.eclipse.team.internal.ccvs.ui.Policy;
-import org.eclipse.team.internal.ccvs.ui.operations.*;
+import org.eclipse.team.internal.ccvs.ui.operations.CacheBaseContentsOperation;
+import org.eclipse.team.internal.ccvs.ui.operations.CacheRemoteContentsOperation;
import org.eclipse.team.internal.core.mapping.GroupProgressMonitor;
+import org.eclipse.team.internal.core.subscribers.ContentComparisonDiffFilter;
import org.eclipse.team.internal.core.subscribers.SubscriberDiffTreeEventHandler;
+import org.eclipse.team.internal.ui.synchronize.RegexDiffFilter;
-public class WorkspaceSubscriberContext extends CVSSubscriberMergeContext {
+public class WorkspaceSubscriberContext extends CVSSubscriberMergeContext implements IPreferenceChangeListener {
public static final class ChangeSetSubscriberScopeManager extends SubscriberScopeManager {
private final boolean consultSets;
@@ -79,10 +83,84 @@ public class WorkspaceSubscriberContext extends CVSSubscriberMergeContext {
mergeContext.initialize();
return mergeContext;
}
-
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.core.subscribers.SubscriberMergeContext#getDiffFilter()
+ */
+ protected DiffFilter getDiffFilter() {
+ final DiffFilter contentFilter = createContentFilter();
+ final DiffFilter regexFilter = createRegexFilter();
+ if (contentFilter != null && regexFilter != null) {
+ return new DiffFilter() {
+ public boolean select(IDiff diff, IProgressMonitor monitor) {
+ return !contentFilter.select(diff, monitor)
+ && !regexFilter.select(diff, monitor);
+ }
+ };
+ } else if (contentFilter != null) {
+ return new DiffFilter() {
+ public boolean select(IDiff diff, IProgressMonitor monitor) {
+ return !contentFilter.select(diff, monitor);
+ }
+ };
+ } else if (regexFilter != null) {
+ return new DiffFilter() {
+ public boolean select(IDiff diff, IProgressMonitor monitor) {
+ return !regexFilter.select(diff, monitor);
+ }
+ };
+ }
+ return null;
+ }
+
protected WorkspaceSubscriberContext(CVSWorkspaceSubscriber subscriber, ISynchronizationScopeManager manager, int type) {
super(subscriber, manager);
this.type = type;
+ ((IEclipsePreferences) CVSUIPlugin.getPlugin().getInstancePreferences().node("")).addPreferenceChangeListener(this); //$NON-NLS-1$
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.team.core.subscribers.SubscriberMergeContext#dispose()
+ */
+ public void dispose() {
+ super.dispose();
+ ((IEclipsePreferences) CVSUIPlugin.getPlugin().getInstancePreferences().node("")).removePreferenceChangeListener(this); //$NON-NLS-1$
+ }
+
+ private boolean isConsiderContents() {
+ return CVSUIPlugin.getPlugin().getPreferenceStore().getBoolean(ICVSUIConstants.PREF_CONSIDER_CONTENTS);
+ }
+
+ private DiffFilter createContentFilter() {
+ if (isConsiderContents()) {
+ // Return a filter that selects any diffs whose contents are not equal
+ return new ContentComparisonDiffFilter(false);
+ }
+ return null;
+ }
+
+ private DiffFilter createRegexFilter() {
+ if (isConsiderContents()) {
+ String pattern = CVSUIPlugin.getPlugin().getPreferenceStore().getString(
+ ICVSUIConstants.PREF_SYNCVIEW_REGEX_FILTER_PATTERN);
+ if (pattern != null && !pattern.equals("")) { //$NON-NLS-1$
+ return new RegexDiffFilter(pattern);
+ }
+ }
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener#preferenceChange(org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent)
+ */
+ public void preferenceChange(PreferenceChangeEvent event) {
+ if (event.getKey().equals(ICVSUIConstants.PREF_CONSIDER_CONTENTS) || event.getKey().equals(ICVSUIConstants.PREF_SYNCVIEW_REGEX_FILTER_PATTERN)) {
+ SubscriberDiffTreeEventHandler handler = getHandler();
+ if (handler != null) {
+ handler.setFilter(getDiffFilter());
+ handler.reset();
+ }
+ }
}
public void markAsMerged(IDiff[] nodes, boolean inSyncHint, IProgressMonitor monitor) throws CoreException {
@@ -211,7 +289,7 @@ public class WorkspaceSubscriberContext extends CVSSubscriberMergeContext {
IFileRevision remote = getRemote(node);
if (variant != null && remote != null && remote instanceof IFileRevision) {
String ci1 = variant.getContentIdentifier();
- String ci2 = ((IFileRevision)remote).getContentIdentifier();
+ String ci2 = remote.getContentIdentifier();
if (!ci1.equals(ci2)) {
throw new CVSException(NLS.bind(CVSUIMessages.WorkspaceSubscriberContext_0, resource.getFullPath().toString()));
}
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/messages.properties b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/messages.properties
index c2c0ef5d6..d7a161817 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/messages.properties
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/messages.properties
@@ -1028,6 +1028,7 @@ ComparePreferencePage_1=Show the &file author in compare editors
ComparePreferencePage_2=Automatically enable chan&ge set grouping in CVS synchronizations
ComparePreferencePage_3=Show revision &comparisons in a dialog
ComparePreferencePage_4=Only look at time&stamps to detect changes
+ComparePreferencePage_5=Re&gular expression to ignore changes in synchronizations:
ComparePreferencePage_6=See <a>''{0}''</a> for compare editor preferences.
ComparePreferencePage_7=Allow &models (e.g. Java) to participate in synchronizations
ComparePreferencePage_8=&Open a compare editor when comparing a single file
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/CompareParticipant.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/CompareParticipant.java
index 13f425e0d..e337f044b 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/CompareParticipant.java
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/CompareParticipant.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * Copyright (c) 2000, 2011 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
@@ -15,8 +15,9 @@ import java.util.Arrays;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.Preferences.IPropertyChangeListener;
-import org.eclipse.core.runtime.Preferences.PropertyChangeEvent;
+import org.eclipse.core.runtime.preferences.*;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
import org.eclipse.osgi.util.NLS;
import org.eclipse.team.core.TeamException;
import org.eclipse.team.core.subscribers.Subscriber;
@@ -31,7 +32,7 @@ import org.eclipse.team.internal.ui.Utils;
import org.eclipse.team.ui.TeamUI;
import org.eclipse.team.ui.synchronize.*;
-public class CompareParticipant extends CVSParticipant implements IPropertyChangeListener {
+public class CompareParticipant extends CVSParticipant implements IPreferenceChangeListener {
public static final String CONTEXT_MENU_CONTRIBUTION_GROUP = "context_group_1"; //$NON-NLS-1$
public static final String NON_MODAL_CONTEXT_MENU_CONTRIBUTION_GROUP = "context_group_2"; //$NON-NLS-1$
@@ -70,18 +71,56 @@ public class CompareParticipant extends CVSParticipant implements IPropertyChang
}
};
+ private SyncInfoFilter createSyncInfoFilter() {
+ final SyncInfoFilter regexFilter = createRegexFilter();
+ if (isConsiderContents() && regexFilter != null) {
+ return new SyncInfoFilter() {
+ public boolean select(SyncInfo info, IProgressMonitor monitor) {
+ return contentComparison.select(info, monitor)
+ && !regexFilter.select(info, monitor);
+ }
+ };
+ } else if (isConsiderContents()) {
+ return new SyncInfoFilter() {
+ public boolean select(SyncInfo info, IProgressMonitor monitor) {
+ return contentComparison.select(info, monitor);
+ }
+ };
+ } else if (regexFilter != null) {
+ return new SyncInfoFilter() {
+ public boolean select(SyncInfo info, IProgressMonitor monitor) {
+ // want to select infos which contain at least one unmatched difference
+ return !regexFilter.select(info, monitor);
+ }
+ };
+ }
+ return null;
+ }
+
+ private boolean isConsiderContents() {
+ return CVSUIPlugin.getPlugin().getPreferenceStore().getBoolean(ICVSUIConstants.PREF_CONSIDER_CONTENTS);
+ }
+
+ private SyncInfoFilter createRegexFilter() {
+ if (isConsiderContents()) {
+ String pattern = CVSUIPlugin.getPlugin().getPreferenceStore().getString(ICVSUIConstants.PREF_SYNCVIEW_REGEX_FILTER_PATTERN);
+ if (pattern != null && !pattern.equals("")) { //$NON-NLS-1$
+ return new RegexSyncInfoFilter(pattern);
+ }
+ }
+ return null;
+ }
+
public CompareParticipant(CVSCompareSubscriber subscriber) {
setSubscriber(subscriber);
}
-
+
/* (non-Javadoc)
* @see org.eclipse.team.ui.synchronize.subscriber.SubscriberParticipant#setSubscriber(org.eclipse.team.core.subscribers.Subscriber)
*/
protected void setSubscriber(Subscriber subscriber) {
super.setSubscriber(subscriber);
- if (CVSUIPlugin.getPlugin().getPluginPreferences().getBoolean(ICVSUIConstants.PREF_CONSIDER_CONTENTS)) {
- setSyncInfoFilter(contentComparison);
- }
+ setSyncInfoFilter(createSyncInfoFilter());
try {
ISynchronizeParticipantDescriptor descriptor = TeamUI.getSynchronizeManager().getParticipantDescriptor(CVSCompareSubscriber.ID);
setInitializationData(descriptor);
@@ -90,7 +129,7 @@ public class CompareParticipant extends CVSParticipant implements IPropertyChang
} catch (CoreException e) {
CVSUIPlugin.log(e);
}
- CVSUIPlugin.getPlugin().getPluginPreferences().addPropertyChangeListener(this);
+ ((IEclipsePreferences) CVSUIPlugin.getPlugin().getInstancePreferences().node("")).addPreferenceChangeListener(this); //$NON-NLS-1$
}
/* (non-Javadoc)
@@ -170,17 +209,18 @@ public class CompareParticipant extends CVSParticipant implements IPropertyChang
*/
public void dispose() {
super.dispose();
- CVSUIPlugin.getPlugin().getPluginPreferences().removePropertyChangeListener(this);
+ ((IEclipsePreferences) CVSUIPlugin.getPlugin().getInstancePreferences().node("")).removePreferenceChangeListener(this); //$NON-NLS-1$
getCVSCompareSubscriber().dispose();
}
/* (non-Javadoc)
* @see org.eclipse.core.runtime.Preferences.IPropertyChangeListener#propertyChange(org.eclipse.core.runtime.Preferences.PropertyChangeEvent)
*/
- public void propertyChange(PropertyChangeEvent event) {
- if (event.getProperty().equals(ICVSUIConstants.PREF_CONSIDER_CONTENTS)) {
- if (CVSUIPlugin.getPlugin().getPluginPreferences().getBoolean(ICVSUIConstants.PREF_CONSIDER_CONTENTS)) {
- setSyncInfoFilter(contentComparison);
+ public void preferenceChange(PreferenceChangeEvent event) {
+ if (event.getKey().equals(ICVSUIConstants.PREF_CONSIDER_CONTENTS) || event.getKey().equals(ICVSUIConstants.PREF_SYNCVIEW_REGEX_FILTER_PATTERN)) {
+ SyncInfoFilter filter = createSyncInfoFilter();
+ if (filter != null) {
+ setSyncInfoFilter(filter);
} else {
setSyncInfoFilter(new FastSyncInfoFilter());
}
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/RegexSyncInfoFilter.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/RegexSyncInfoFilter.java
new file mode 100644
index 000000000..118562ce7
--- /dev/null
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/RegexSyncInfoFilter.java
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.ccvs.ui.subscriber;
+
+import java.util.regex.Pattern;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.team.core.synchronize.SyncInfo;
+import org.eclipse.team.core.synchronize.SyncInfoFilter;
+import org.eclipse.team.core.variants.IResourceVariant;
+import org.eclipse.team.internal.core.subscribers.AbstractContentComparator;
+import org.eclipse.team.internal.ui.synchronize.RegexDiffComparator;
+
+/**
+ * Selects <code>SyncInfo</code> whose all diffs match the given pattern.
+ * This filter makes use of the <code>IStorage</code> provided by
+ * an <code>IResourceVariant</code> to obtain the remote contents.
+ * This means that the comparison may contact the server unless the contents
+ * were cached locally by a previous operation. The caching of remote
+ * contents is subscriber specific.
+ * <p>
+ * For folders, the comparison always returns <code>true</code>.
+ *
+ * @since 3.6
+ */
+public class RegexSyncInfoFilter extends SyncInfoFilter {
+
+ AbstractContentComparator criteria;
+
+ boolean ignoreWhiteSpace;
+
+ /**
+ * Create a filter that does not ignore whitespace.
+ *
+ * @param pattern
+ * regex pattern
+ */
+ public RegexSyncInfoFilter(String pattern) {
+ this(false, pattern);
+ }
+
+ public RegexSyncInfoFilter(boolean ignoreWhitespace, String pattern) {
+ criteria = new RegexDiffComparator(Pattern.compile(pattern,
+ Pattern.DOTALL), ignoreWhitespace);
+ }
+
+ public boolean select(SyncInfo info, IProgressMonitor monitor) {
+ IResourceVariant remote = info.getRemote();
+ IResource local = info.getLocal();
+ if (local.getType() != IResource.FILE)
+ return true;
+ if (remote == null)
+ return !local.exists();
+ if (!local.exists())
+ return false;
+ return criteria.compare(local, remote, monitor);
+ }
+}
diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/WorkspaceSynchronizeParticipant.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/WorkspaceSynchronizeParticipant.java
index 5f8757612..b5c219103 100644
--- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/WorkspaceSynchronizeParticipant.java
+++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/subscriber/WorkspaceSynchronizeParticipant.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * Copyright (c) 2000, 2011 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
@@ -17,12 +17,16 @@ import java.util.Set;
import org.eclipse.compare.CompareConfiguration;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.preferences.*;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.jface.viewers.ILabelDecorator;
import org.eclipse.jface.window.Window;
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.synchronize.*;
import org.eclipse.team.internal.ccvs.core.CVSProviderPlugin;
import org.eclipse.team.internal.ccvs.ui.*;
import org.eclipse.team.internal.ccvs.ui.actions.*;
@@ -33,7 +37,7 @@ import org.eclipse.team.ui.TeamUI;
import org.eclipse.team.ui.synchronize.*;
import org.eclipse.ui.*;
-public class WorkspaceSynchronizeParticipant extends ScopableSubscriberParticipant implements IChangeSetProvider {
+public class WorkspaceSynchronizeParticipant extends ScopableSubscriberParticipant implements IChangeSetProvider, IPreferenceChangeListener {
public static final String ID = "org.eclipse.team.cvs.ui.cvsworkspace-participant"; //$NON-NLS-1$
@@ -188,8 +192,61 @@ public class WorkspaceSynchronizeParticipant extends ScopableSubscriberParticipa
public WorkspaceSynchronizeParticipant(ISynchronizeScope scope) {
super(scope);
setSubscriber(CVSProviderPlugin.getPlugin().getCVSWorkspaceSubscriber());
+ SyncInfoFilter filter = createSyncInfoFilter();
+ if (filter != null) {
+ setSyncInfoFilter(filter);
+ }
+ ((IEclipsePreferences) CVSUIPlugin.getPlugin().getInstancePreferences().node("")).addPreferenceChangeListener(this); //$NON-NLS-1$
}
-
+
+ private boolean isConsiderContents() {
+ return CVSUIPlugin.getPlugin().getPreferenceStore().getBoolean(ICVSUIConstants.PREF_CONSIDER_CONTENTS);
+ }
+
+ private SyncInfoFilter contentComparison = new SyncInfoFilter() {
+ private SyncInfoFilter contentCompare = new SyncInfoFilter.ContentComparisonSyncInfoFilter();
+ public boolean select(SyncInfo info, IProgressMonitor monitor) {
+ // Want to select infos whose contents do not match
+ return !contentCompare.select(info, monitor);
+ }
+ };
+
+ private SyncInfoFilter createSyncInfoFilter() {
+ final SyncInfoFilter regexFilter = createRegexFilter();
+ if (isConsiderContents() && regexFilter != null) {
+ return new SyncInfoFilter() {
+ public boolean select(SyncInfo info, IProgressMonitor monitor) {
+ return contentComparison.select(info, monitor)
+ && !regexFilter.select(info, monitor);
+ }
+ };
+ } else if (isConsiderContents()) {
+ return new SyncInfoFilter() {
+ public boolean select(SyncInfo info, IProgressMonitor monitor) {
+ return contentComparison.select(info, monitor);
+ }
+ };
+ } else if (regexFilter != null) {
+ return new SyncInfoFilter() {
+ public boolean select(SyncInfo info, IProgressMonitor monitor) {
+ // want to select infos which contain at least one unmatched difference
+ return !regexFilter.select(info, monitor);
+ }
+ };
+ }
+ return null;
+ }
+
+ private SyncInfoFilter createRegexFilter() {
+ if (isConsiderContents()) {
+ String pattern = CVSUIPlugin.getPlugin().getPreferenceStore().getString(ICVSUIConstants.PREF_SYNCVIEW_REGEX_FILTER_PATTERN);
+ if (pattern != null && !pattern.equals("")) { //$NON-NLS-1$
+ return new RegexSyncInfoFilter(pattern);
+ }
+ }
+ return null;
+ }
+
/* (non-Javadoc)
* @see org.eclipse.team.ui.synchronize.ISynchronizeParticipant#init(org.eclipse.ui.IMemento)
*/
@@ -272,5 +329,23 @@ public class WorkspaceSynchronizeParticipant extends ScopableSubscriberParticipa
public void refresh(IResource[] resources, IWorkbenchPartSite site) {
refresh(resources, getShortTaskName(), getLongTaskName(resources), site);
}
-
+
+ public void dispose() {
+ super.dispose();
+ ((IEclipsePreferences) CVSUIPlugin.getPlugin().getInstancePreferences().node("")).removePreferenceChangeListener(this); //$NON-NLS-1$
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener#preferenceChange(org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent)
+ */
+ public void preferenceChange(PreferenceChangeEvent event) {
+ if (event.getKey().equals(ICVSUIConstants.PREF_CONSIDER_CONTENTS) || event.getKey().equals(ICVSUIConstants.PREF_SYNCVIEW_REGEX_FILTER_PATTERN)) {
+ SyncInfoFilter filter = createSyncInfoFilter();
+ if (filter != null) {
+ setSyncInfoFilter(filter);
+ } else {
+ setSyncInfoFilter(new FastSyncInfoFilter());
+ }
+ }
+ }
}
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/preferences/SyncViewerPreferencePage.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/preferences/SyncViewerPreferencePage.java
index 5c52ec805..663928ae4 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/preferences/SyncViewerPreferencePage.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/preferences/SyncViewerPreferencePage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2010 IBM Corporation and others.
+ * Copyright (c) 2000, 2011 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
@@ -10,7 +10,6 @@
*******************************************************************************/
package org.eclipse.team.internal.ui.preferences;
-import com.ibm.icu.text.Collator;
import java.util.Arrays;
import java.util.Comparator;
@@ -25,8 +24,10 @@ import org.eclipse.swt.widgets.*;
import org.eclipse.team.internal.ui.*;
import org.eclipse.ui.*;
+import com.ibm.icu.text.Collator;
+
/**
- * This area provides the widgets for providing the CVS commit comment
+ * This preference page allows to configure various aspects of the Synchronize View.
*/
public class SyncViewerPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage, IPreferenceIds {
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/RangeDifferenceComparator.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/RangeDifferenceComparator.java
new file mode 100644
index 000000000..63839174d
--- /dev/null
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/RangeDifferenceComparator.java
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.ui.synchronize;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.eclipse.compare.internal.DocLineComparator;
+import org.eclipse.compare.internal.Utilities;
+import org.eclipse.compare.rangedifferencer.RangeDifference;
+import org.eclipse.compare.rangedifferencer.RangeDifferencer;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.text.*;
+import org.eclipse.team.internal.core.subscribers.AbstractContentComparator;
+
+/**
+ * Compare differences between local and remote contents.
+ * <p>
+ * Subclass to specify a criterion for comparison.
+ */
+public abstract class RangeDifferenceComparator extends
+ AbstractContentComparator {
+
+ public RangeDifferenceComparator(boolean ignoreWhitespace) {
+ super(ignoreWhitespace);
+ }
+
+ /**
+ * Return <code>true</code> if the provided differences match a criterion.
+ *
+ * @param ranges the differences found
+ * @param lDoc the left document
+ * @param rDoc the right document
+ * @return <code>true</code> if all differences match a criterion
+ */
+ abstract protected boolean compareRangeDifferences(RangeDifference[] ranges,
+ IDocument lDoc, IDocument rDoc);
+
+ protected boolean contentsEqual(IProgressMonitor monitor, InputStream is1,
+ InputStream is2, boolean ignoreWhitespace) {
+ try {
+ final String left = Utilities.readString(is1, ResourcesPlugin.getEncoding());
+ final String right = Utilities.readString(is2, ResourcesPlugin.getEncoding());
+ return compareStrings(left, right, monitor);
+ } catch (IOException e) {
+ // ignore
+ }
+ return false;
+ }
+
+ private boolean compareStrings(String left, String right,
+ IProgressMonitor monitor) {
+ IDocument lDoc = new Document(left);
+ IDocument rDoc = new Document(right);
+ DocLineComparator sleft = new DocLineComparator(lDoc, new Region(0,
+ lDoc.getLength()), shouldIgnoreWhitespace());
+ DocLineComparator sright = new DocLineComparator(rDoc, new Region(0,
+ rDoc.getLength()), shouldIgnoreWhitespace());
+ final DocLineComparator sl = sleft, sr = sright;
+ RangeDifference[] ranges = RangeDifferencer.findRanges(monitor, sl, sr);
+ return compareRangeDifferences(ranges, lDoc, rDoc);
+ }
+}
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/RegexDiffComparator.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/RegexDiffComparator.java
new file mode 100644
index 000000000..333b9afa1
--- /dev/null
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/RegexDiffComparator.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.ui.synchronize;
+
+import java.util.regex.Pattern;
+
+import org.eclipse.compare.internal.DocLineComparator;
+import org.eclipse.compare.rangedifferencer.RangeDifference;
+import org.eclipse.jface.text.*;
+
+/**
+ * Compute differences between local and remote contents and checks if all match
+ * the given regex pattern. If there is at least one diff whose either left or
+ * right side don't match the pattern
+ * <code>{@link #compareRangeDifferences(RangeDifference[], IDocument, IDocument)}</code>
+ * returns <code>false</code>.
+ */
+public class RegexDiffComparator extends RangeDifferenceComparator {
+
+ private Pattern pattern;
+
+ public RegexDiffComparator(Pattern pattern, boolean ignoreWhitespace) {
+ super(ignoreWhitespace);
+ this.pattern = pattern;
+ }
+
+ protected boolean compareRangeDifferences(RangeDifference[] ranges,
+ IDocument lDoc, IDocument rDoc) {
+ try {
+ for (int i = 0; i < ranges.length; i++) {
+ RangeDifference diff = ranges[i];
+ if (diff.kind() == RangeDifference.NOCHANGE)
+ continue;
+
+ DocLineComparator sleft = new DocLineComparator(lDoc, null,
+ shouldIgnoreWhitespace());
+ DocLineComparator sright = new DocLineComparator(rDoc, null,
+ shouldIgnoreWhitespace());
+
+ IRegion lRegion = lDoc.getLineInformation(diff.leftStart());
+ int leftEnd = sleft.getTokenStart(diff.leftStart()
+ + diff.leftLength());
+ String left = lDoc.get(lRegion.getOffset(),
+ leftEnd - lRegion.getOffset());
+ IRegion rRegion = rDoc.getLineInformation(diff.rightStart());
+ int rightEnd = sright.getTokenStart(diff.rightStart()
+ + diff.rightLength());
+ String right = rDoc.get(rRegion.getOffset(),
+ rightEnd - rRegion.getOffset());
+
+ boolean m1 = pattern.matcher(left).matches();
+ boolean m2 = pattern.matcher(right).matches();
+
+ if (!m1 && !m2)
+ // it's false that all diffs match the pattern
+ return false;
+ }
+ } catch (BadLocationException e) {
+ // ignore
+ }
+ return true;
+ }
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/RegexDiffFilter.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/RegexDiffFilter.java
new file mode 100644
index 000000000..dce36567b
--- /dev/null
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/RegexDiffFilter.java
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.ui.synchronize;
+
+import java.util.regex.Pattern;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.team.core.diff.DiffFilter;
+import org.eclipse.team.core.diff.IDiff;
+import org.eclipse.team.core.history.IFileRevision;
+import org.eclipse.team.core.mapping.provider.ResourceDiffTree;
+import org.eclipse.team.internal.core.mapping.SyncInfoToDiffConverter;
+import org.eclipse.team.internal.core.subscribers.AbstractContentComparator;
+
+public class RegexDiffFilter extends DiffFilter {
+
+ AbstractContentComparator criteria;
+
+ boolean ignoreWhiteSpace;
+
+ /**
+ * Create a filter that does not ignore whitespace.
+ *
+ * @param pattern
+ * regex pattern
+ */
+ public RegexDiffFilter(String pattern) {
+ this(false, pattern);
+ }
+
+ /**
+ * Create a filter and configure how whitespace is handled.
+ *
+ * @param ignoreWhitespace
+ * whether whitespace should be ignored
+ * @param pattern
+ * regex pattern
+ */
+ public RegexDiffFilter(boolean ignoreWhitespace, String pattern) {
+ criteria = new RegexDiffComparator(Pattern.compile(pattern,
+ Pattern.DOTALL), ignoreWhitespace);
+ }
+
+ public boolean select(IDiff diff, IProgressMonitor monitor) {
+ IFileRevision remote = SyncInfoToDiffConverter.getRemote(diff);
+ IResource local = ResourceDiffTree.getResourceFor(diff);
+ if (local == null || local.getType() != IResource.FILE)
+ return true;
+ if (remote == null)
+ return !local.exists();
+ if (!local.exists())
+ return false;
+ return criteria.compare(local, remote, monitor);
+ }
+} \ No newline at end of file

Back to the top