1
// Copyright (c) 2004-2006 by Leif Frenzel - see http://leiffrenzel.de
2
package org.vcs.bazaar.eclipse.core.subscriber;
4
import java.io.BufferedInputStream;
6
import java.io.FileInputStream;
7
import java.io.FileNotFoundException;
8
import java.io.IOException;
9
import java.io.InputStream;
10
import java.util.Date;
12
import org.eclipse.core.runtime.IProgressMonitor;
13
import org.eclipse.core.runtime.IStatus;
14
import org.eclipse.core.runtime.Status;
15
import org.eclipse.team.core.TeamException;
16
import org.eclipse.team.core.variants.CachedResourceVariant;
17
import org.vcs.bazaar.eclipse.BazaarEclipsePlugin;
19
/** <p>A resource variant for a local Darcs repository is the corresponding
20
* resource in the pristine tree.</p>
22
* @author Leif Frenzel
24
public class BzrResourceVariant extends CachedResourceVariant {
29
public BzrResourceVariant( final File file ) {
33
public BzrResourceVariant( final File file, final byte[] bytes ) {
38
public BzrResourceVariant[] members() {
39
BzrResourceVariant[] result = new BzrResourceVariant[ 0 ];
41
File[] members = ioFile.listFiles();
42
result = new BzrResourceVariant[ members.length ];
43
for( int i = 0; i < members.length; i++ ) {
44
result[ i ] = new BzrResourceVariant( members[ i ] );
50
public InputStream getContents() throws TeamException {
52
return new BufferedInputStream( new FileInputStream( ioFile ) );
53
} catch( FileNotFoundException fnfex ) {
54
String msg = "Couldn't fetch contents for " + getFilePath(); //$NON-NLS-1$
55
throw new TeamException( msg, fnfex );
60
// interface methods of CachedResourceVariant
61
/////////////////////////////////////////////
64
protected void fetchContents( final IProgressMonitor monitor )
65
throws TeamException {
66
setContents( getContents(), monitor );
70
protected String getCachePath() {
71
// append the timestamp to the file path to give each variant a unique path
72
return getFilePath() + " " + ioFile.lastModified(); //$NON-NLS-1$
76
protected String getCacheId() {
77
return BazaarEclipsePlugin.getPluginId();
80
public String getName() {
81
return ioFile.getName();
84
public boolean isContainer() {
85
return ioFile.isDirectory();
88
public String getContentIdentifier() {
89
// Use the modification timestamp as the content identifier
90
return new Date( ioFile.lastModified() ).toString();
93
public byte[] asBytes() {
95
// For simplicity, convert the timestamp to its string representation.
96
// A more optimal storage format would be the 8 bytes that make up the
98
bytes = Long.toString( ioFile.lastModified() ).getBytes();
107
private String getFilePath() {
110
result = ioFile.getCanonicalPath();
111
} catch( final IOException ioex ) {
112
// Failed for some reason. Try the absolute path.
113
String pluginId = BazaarEclipsePlugin.getPluginId();
114
String msg = "Failed to obtain canonical path for " //$NON-NLS-1$
115
+ ioFile.getAbsolutePath();
116
IStatus status = new Status( IStatus.ERROR, pluginId, 0, msg, ioex );
117
BazaarEclipsePlugin.getDefault().getLog().log( status );
118
result = ioFile.getAbsolutePath();