Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 593db8f85323a9952d06b7c1e07cbd4394dd669e (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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
package org.eclipse.team.internal.ccvs.core.resources;

/*
 * (c) Copyright IBM Corp. 2000, 2001.
 * All Rights Reserved.
 */

import java.io.File;

import org.eclipse.core.resources.IResource;
import org.eclipse.team.internal.ccvs.core.CVSException;
import org.eclipse.team.internal.ccvs.core.commands.FileNameMatcher;
import org.eclipse.team.internal.ccvs.core.util.FileUtil;
import org.eclipse.team.internal.ccvs.core.util.Util;

/**
 * Implements the ICVSResource interface on top of an 
 * instance of the ICVSResource interface
 * 
 * @see ICVSResource
 */
public abstract class LocalResource implements ICVSResource {

	static final String PLATFORM_NEWLINE = FileUtil.PLATFORM_NEWLINE;
	static final String SERVER_NEWLINE = "\n";
	
	static final byte[] PLATFORM_NEWBYTE = PLATFORM_NEWLINE.getBytes();
	static final byte[] SERVER_NEWBYTE = SERVER_NEWLINE.getBytes();
	
	File ioResource;
	
	public LocalResource(File ioResource) {
		this.ioResource = ioResource;
	}
	
	/**
	 * Get the extention of the path of resource
	 * relative to the path of root
	 * 
	 * @throws CVSException if root is not a root-folder of resource
	 */
	public String getRelativePath(ICVSFolder root) 
		throws CVSException {
		
		LocalResource rootFolder;
		String result;
		
		try {
			rootFolder = (LocalResource)root;
		} catch (ClassCastException e) {
			throw new CVSException(0,0,"two different implementations of ICVSResource used",e);
		}
		
		result = Util.getRelativePath(rootFolder.getPath(),getPath()); 
		return result.replace('\\', '/');	
	}

	/**
	 * Do a DEEP delete.
	 * @see ICVSResource#delete()
	 */
	public void delete() {
		FileUtil.deepDelete(ioResource);
	}

	/**
	 * @see ICVSResource#exists()
	 */
	public boolean exists() {
		return ioResource.exists();
	}

	/**
	 * @see ICVSResource#getParent()
	 */
	public ICVSFolder getParent() {
		return new LocalFolder(ioResource.getParentFile());
	}

	/**
	 * @see ICVSResource#getName()
	 */
	public String getName() {
		return ioResource.getName();
	}

	/**
	 * @see ICVSResource#isIgnored()
	 */
	public boolean isIgnored() throws CVSException {
		FileNameMatcher matcher = FileNameMatcher.getIgnoreMatcherFor(ioResource.getParentFile());
		return (!isManaged() && matcher.match(getName()));
	}

	/**
	 * @see ICVSResource#isManaged()
	 */
	public boolean isManaged() throws CVSException {
		return getSyncInfo() != null;
	}
			
	/**
	 * Two ManagedResources are equal, if there cvsResources are
	 * equal (and that is, if the point to the same file)
	 */
	public boolean equals(Object obj) {
		
		if (!(obj instanceof LocalResource)) {
			return false;
		} else {
			return getPath().equals(((LocalResource) obj).getPath());
		}
	}
			
	/**
	 * Implement the hashcode on the underlying strings, like it
	 * is done in the equals.
	 */
	public int hashCode() {
		return getPath().hashCode();
	}	
	
	/**
	 * @see ICVSResource#getPath()
	 */
	public String getPath() {
		return ioResource.getAbsolutePath();
	}	
	
	/**
	 * Give the pathname back
	 */
	public String toString() {
		return getPath();
	}

	/**
	 * @see ICVSResource#isFolder()
	 */
	public boolean isFolder() {
		return false;
	}
	
	/*
	 * @see ICVSResource#getSyncInfo()
	 */
	public ResourceSyncInfo getSyncInfo() throws CVSException {
		return Synchronizer.getInstance().getSyncInfo(ioResource);
	}

	/*
	 * @see ICVSResource#setSyncInfo(ResourceSyncInfo)
	 */
	public void setSyncInfo(ResourceSyncInfo info) throws CVSException {
		Synchronizer.getInstance().setSyncInfo(ioResource, info);		
	}
	
	/**
	 * @see ICVSResource#unmanage()
	 */
	public void unmanage() throws CVSException {
		Synchronizer.getInstance().flushSyncInfo(ioResource, IResource.DEPTH_INFINITE);
	}			
}

Back to the top