1 /******************************************************************************* 2 * Copyright (c) 2011 IBM Corporation and others. 3 * 4 * This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License 2.0 6 * which accompanies this distribution, and is available at 7 * https://www.eclipse.org/legal/epl-2.0/ 8 * 9 * SPDX-License-Identifier: EPL-2.0 10 * 11 * Contributors: 12 * IBM Corporation - initial API and implementation 13 *******************************************************************************/ 14 package org.eclipse.team.internal.ccvs.ui.subscriber; 15 16 import java.util.regex.Pattern; 17 18 import org.eclipse.core.resources.IResource; 19 import org.eclipse.core.runtime.IProgressMonitor; 20 import org.eclipse.team.core.synchronize.SyncInfo; 21 import org.eclipse.team.core.synchronize.SyncInfoFilter; 22 import org.eclipse.team.core.variants.IResourceVariant; 23 import org.eclipse.team.internal.core.subscribers.AbstractContentComparator; 24 import org.eclipse.team.internal.ui.synchronize.RegexDiffComparator; 25 26 /** 27 * Selects <code>SyncInfo</code> whose all diffs match the given pattern. 28 * This filter makes use of the <code>IStorage</code> provided by 29 * an <code>IResourceVariant</code> to obtain the remote contents. 30 * This means that the comparison may contact the server unless the contents 31 * were cached locally by a previous operation. The caching of remote 32 * contents is subscriber specific. 33 * <p> 34 * For folders, the comparison always returns <code>true</code>. 35 * 36 * @since 3.6 37 */ 38 public class RegexSyncInfoFilter extends SyncInfoFilter { 39 40 AbstractContentComparator criteria; 41 42 boolean ignoreWhiteSpace; 43 44 /** 45 * Create a filter that does not ignore whitespace. 46 * 47 * @param pattern 48 * regex pattern 49 */ RegexSyncInfoFilter(String pattern)50 public RegexSyncInfoFilter(String pattern) { 51 this(false, pattern); 52 } 53 RegexSyncInfoFilter(boolean ignoreWhitespace, String pattern)54 public RegexSyncInfoFilter(boolean ignoreWhitespace, String pattern) { 55 criteria = new RegexDiffComparator(Pattern.compile(pattern, 56 Pattern.DOTALL), ignoreWhitespace); 57 } 58 select(SyncInfo info, IProgressMonitor monitor)59 public boolean select(SyncInfo info, IProgressMonitor monitor) { 60 IResourceVariant remote = info.getRemote(); 61 IResource local = info.getLocal(); 62 if (local.getType() != IResource.FILE) 63 return true; 64 if (remote == null) 65 return !local.exists(); 66 if (!local.exists()) 67 return false; 68 return criteria.compare(local, remote, monitor); 69 } 70 } 71