Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 4addda20ecea251b6776faab42d493d0be2cd87f (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) 2013 Obeo.
 * 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:
 *     Laurent Goubet <laurent.goubet@obeo.fr> - initial API and implementation
 *******************************************************************************/
package org.eclipse.egit.core.synchronize;

import java.io.UnsupportedEncodingException;
import java.util.Date;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IStorage;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.team.core.TeamException;
import org.eclipse.team.core.variants.IResourceVariant;

/**
 * Used by the GitSourceVariantTree when it needs to include local changes.
 * <p>
 * Mimics Team's LocalResourceVariant.
 * </p>
 */
class GitLocalResourceVariant implements IResourceVariant {
	private final IResource resource;

	GitLocalResourceVariant(IResource resource) {
		this.resource = resource;
	}

	@Override
	public byte[] asBytes() {
		try {
			return getContentIdentifier().getBytes("UTF-8"); //$NON-NLS-1$
		} catch (UnsupportedEncodingException e) {
			throw new RuntimeException(e);
		}
	}

	@Override
	public String getContentIdentifier() {
		return new Date(resource.getLocalTimeStamp()).toString();
	}

	@Override
	public IStorage getStorage(IProgressMonitor monitor) throws TeamException {
		if (resource.getType() == IResource.FILE)
			return (IFile) resource;
		return null;
	}

	@Override
	public boolean isContainer() {
		return resource.getType() != IResource.FILE;
	}

	@Override
	public String getName() {
		return resource.getName();
	}

	IResource getResource() {
		return resource;
	}
}

Back to the top