Skip to main content
summaryrefslogtreecommitdiffstats
blob: 8ca792e840c6ec31a85e73f71c2c73c3b6bb43f9 (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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*******************************************************************************
 * Copyright (c) 2000, 2006 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.team.tests.ccvs.core.mappings;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IStorage;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.resources.mapping.RemoteResourceMappingContext;
import org.eclipse.core.resources.mapping.ResourceTraversal;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.team.core.synchronize.SyncInfo;
import org.eclipse.team.core.synchronize.SyncInfoSet;
import org.eclipse.team.core.synchronize.SyncInfoTree;
import org.eclipse.team.core.variants.IResourceVariant;

/**
 * A traversal context that traverses the local workspace but also
 * adds resources that exist in the given sync info set but do not exist
 * locally.
 */
public class SyncInfoSetTraveralContext extends RemoteResourceMappingContext {
	
	SyncInfoTree set;
	
	public SyncInfoSetTraveralContext(SyncInfoSet set) {
		this.set = new SyncInfoTree();
		this.set.addAll(set);
	}

	protected SyncInfo getSyncInfo(IFile file) {
		return set.getSyncInfo(file);
	}
	
	public boolean contentDiffers(IFile file, IProgressMonitor monitor) {
		return getSyncInfo(file) != null;
	}

	@Override
	public IStorage fetchRemoteContents(IFile file, IProgressMonitor monitor) throws CoreException {
		SyncInfo info = getSyncInfo(file);
		if (info == null)
			return null;
		IResourceVariant remote = info.getRemote();
		if (remote == null)
			return null;
		return remote.getStorage(monitor);
	}

	@Override
	public IResource[] fetchMembers(IContainer container, IProgressMonitor monitor) throws CoreException {
		Set<IResource> members = new HashSet<>();
		members.addAll(Arrays.asList(container.members(false)));
		members.addAll(Arrays.asList(set.members(container)));
		return members.toArray(new IResource[members.size()]);
	}

	@Override
	public void refresh(ResourceTraversal[] traversals, int flags, IProgressMonitor monitor) throws CoreException {
		// Do nothing
	}

	@Override
	public boolean isThreeWay() {
		for (Iterator<SyncInfo> iter = set.iterator(); iter.hasNext();) {
			SyncInfo info = iter.next();
			return info.getComparator().isThreeWay();
		}
		return true;
	}

	@Override
	public boolean hasRemoteChange(IResource resource, IProgressMonitor monitor) throws CoreException {
		SyncInfo info = set.getSyncInfo(resource);
		int direction = SyncInfo.getDirection(info.getKind());
		return direction == SyncInfo.INCOMING || direction == SyncInfo.CONFLICTING;
	}

	@Override
	public boolean hasLocalChange(IResource resource, IProgressMonitor monitor) throws CoreException {
		SyncInfo info = set.getSyncInfo(resource);
		int direction = SyncInfo.getDirection(info.getKind());
		return direction == SyncInfo.OUTGOING || direction == SyncInfo.CONFLICTING;

	}

	@Override
	public IStorage fetchBaseContents(IFile file, IProgressMonitor monitor) throws CoreException {
		SyncInfo info = getSyncInfo(file);
		if (info == null)
			return null;
		IResourceVariant base = info.getBase();
		if (base == null)
			return null;
		return base.getStorage(monitor);
	}

	@Override
	public IProject[] getProjects() {
		return ResourcesPlugin.getWorkspace().getRoot().getProjects();
	}

}

Back to the top