Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Zarna2011-11-18 12:21:27 +0000
committerTomasz Zarna2011-11-18 12:21:27 +0000
commit951477fe0d9d1aa4bbfcabd936d0d7641c6f712a (patch)
tree952b09572474681f93c2570abf2fa478062b5910 /bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui
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
Diffstat (limited to 'bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui')
-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
4 files changed, 211 insertions, 3 deletions
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