Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 1fe9a8e0f3d9e53ed07ff1c0a09a3471e1e3e000 (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
/*******************************************************************************
 * Copyright (C) 2014 Obeo and others.
 *
 * All rights reserved. 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
 *******************************************************************************/
package org.eclipse.egit.core.test.models;

import java.util.LinkedHashSet;
import java.util.Set;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.mapping.ResourceMapping;
import org.eclipse.core.resources.mapping.ResourceMappingContext;
import org.eclipse.core.resources.mapping.ResourceTraversal;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;

/**
 * This resource mapping will consider all files of extension
 * {@link SampleModelProvider#SAMPLE_FILE_EXTENSION} in a given folder to be
 * part of the same model.
 */
public class SampleResourceMapping extends ResourceMapping {
	private final IFile file;

	private final String providerId;

	public SampleResourceMapping(IFile file, String providerId) {
		this.file = file;
		this.providerId = providerId;
	}

	@Override
	public Object getModelObject() {
		return file;
	}

	@Override
	public String getModelProviderId() {
		return providerId;
	}

	@Override
	public ResourceTraversal[] getTraversals(
			ResourceMappingContext context, IProgressMonitor monitor)
			throws CoreException {
		Set<IFile> sampleSiblings = new LinkedHashSet<IFile>();
		for (IResource res : file.getParent().members()) {
			if (res instanceof IFile && SampleModelProvider.SAMPLE_FILE_EXTENSION.equals(res.getFileExtension())) {
				sampleSiblings.add((IFile) res);
			}
		}
		final IResource[] resourceArray = sampleSiblings
				.toArray(new IResource[0]);
		return new ResourceTraversal[] { new ResourceTraversal(
				resourceArray, IResource.DEPTH_ONE, IResource.NONE), };
	}

	@Override
	public IProject[] getProjects() {
		return new IProject[] { file.getProject(), };
	}
}

Back to the top