Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: ffe405acc8d1dd9683be56616f82299f7c2a23fa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*******************************************************************************
 * Copyright (c) 2000, 2017 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.core.synchronize;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.team.core.variants.IResourceVariant;
import org.eclipse.team.internal.core.subscribers.ContentComparator;

/**
 * A <code>SyncInfoFilter</code> tests a <code>SyncInfo</code> for inclusion,
 * typically in a <code>SyncInfoSet</code>.
 *
 * @see SyncInfo
 * @see SyncInfoSet
 *
 * @since 3.0
 */
public abstract class SyncInfoFilter {

	/**
	 * Selects <code>SyncInfo</code> whose local and remote contents match.
	 * 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>.
	 */
	public static class ContentComparisonSyncInfoFilter extends SyncInfoFilter {
		ContentComparator criteria = new ContentComparator(false);
		/**
		 * Create a filter that does not ignore whitespace.
		 */
		public ContentComparisonSyncInfoFilter() {
			this(false);
		}
		/**
		 * Create a filter and configure how whitespace is handled.
		 * @param ignoreWhitespace whether whitespace should be ignored
		 */
		public ContentComparisonSyncInfoFilter(boolean ignoreWhitespace) {
			criteria = new ContentComparator(ignoreWhitespace);
		}

		@Override
		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 compareContents((IFile)local, remote, monitor);
		}

		/**
		 * Compare the contents of the local file and its variant.
		 * This is used by the <code>select</code> method to compare the
		 * contents of two non-null files.
		 * @param local a local file
		 * @param remote a resource variant of the file
		 * @param monitor a progress monitor
		 * @return whether the contents of the two files are equal
		 */
		public boolean compareContents(IFile local, IResourceVariant remote, IProgressMonitor monitor) {
			Assert.isNotNull(local);
			Assert.isNotNull(remote);
			return criteria.compare(local, remote, monitor);
		}
	}

	/**
	 * Return <code>true</code> if the provided <code>SyncInfo</code> matches the filter.
	 *
	 * @param info the <code>SyncInfo</code> to be tested
	 * @param monitor a progress monitor
	 * @return <code>true</code> if the <code>SyncInfo</code> matches the filter
	 */
	public abstract boolean select(SyncInfo info, IProgressMonitor monitor);

}

Back to the top