Skip to main content
summaryrefslogtreecommitdiffstats
blob: c332b88811c5a4a78f9939703ed35975b58a3025 (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
/*******************************************************************************
 * Copyright (c) 2000, 2005 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.tests.ccvs.core.mappings;

import java.util.*;

import org.eclipse.core.internal.resources.mapping.RemoteResourceMappingContext;
import org.eclipse.core.internal.resources.mapping.ResourceTraversal;
import org.eclipse.core.resources.*;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.team.core.synchronize.*;
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);
    }
    
    /* (non-Javadoc)
     * @see org.eclipse.core.resources.mapping.ITraversalContext#contentDiffers(org.eclipse.core.resources.IFile, org.eclipse.core.runtime.IProgressMonitor)
     */
    public boolean contentDiffers(IFile file, IProgressMonitor monitor) throws CoreException {
        return getSyncInfo(file) != null;
    }

    /* (non-Javadoc)
     * @see org.eclipse.core.resources.mapping.ITraversalContext#fetchContents(org.eclipse.core.resources.IFile, org.eclipse.core.runtime.IProgressMonitor)
     */
    public IStorage fetchContents(IFile file, IProgressMonitor monitor) throws CoreException {
        SyncInfo info = getSyncInfo(file);
        //TODO: Speced to throw an exception when remote doesn't exist
        if (info == null)
            return file;
        IResourceVariant remote = info.getRemote();
        if (remote == null)
            return null;
        return remote.getStorage(monitor);
    }

    /* (non-Javadoc)
     * @see org.eclipse.core.resources.mapping.ITraversalContext#fetchMembers(org.eclipse.core.resources.IContainer, org.eclipse.core.runtime.IProgressMonitor)
     */
    public IResource[] fetchMembers(IContainer container, IProgressMonitor monitor) throws CoreException {
        Set members = new HashSet();
        members.addAll(Arrays.asList(container.members(false)));
        members.addAll(Arrays.asList(set.members(container)));
        return (IResource[]) members.toArray(new IResource[members.size()]);
    }

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

}

Back to the top