1 /******************************************************************************* 2 * Copyright (c) 2000, 2006 IBM Corporation and others. 3 * 4 * This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License 2.0 6 * which accompanies this distribution, and is available at 7 * https://www.eclipse.org/legal/epl-2.0/ 8 * 9 * SPDX-License-Identifier: EPL-2.0 10 * 11 * Contributors: 12 * IBM Corporation - initial API and implementation 13 *******************************************************************************/ 14 package org.eclipse.team.internal.ccvs.core.resources; 15 16 17 import org.eclipse.core.resources.IResource; 18 import org.eclipse.core.runtime.*; 19 import org.eclipse.team.core.TeamException; 20 import org.eclipse.team.core.variants.CachedResourceVariant; 21 import org.eclipse.team.internal.ccvs.core.*; 22 import org.eclipse.team.internal.ccvs.core.client.Update; 23 import org.eclipse.team.internal.ccvs.core.syncinfo.ResourceSyncInfo; 24 import org.eclipse.team.internal.ccvs.core.util.Util; 25 26 /** 27 * The purpose of this class and its subclasses is to implement the corresponding 28 * ICVSRemoteResource interfaces for the purpose of communicating information about 29 * resources that reside in a CVS repository but have not necessarily been loaded 30 * locally. 31 */ 32 public abstract class RemoteResource extends CachedResourceVariant implements ICVSRemoteResource { 33 34 protected RemoteFolder parent; 35 protected String name; 36 37 // relative synchronization state calculated by server of this remote file compare to the current local 38 // workspace copy. 39 private int workspaceSyncState = Update.STATE_NONE; 40 41 /** 42 * Constructor for RemoteResource. 43 */ RemoteResource(RemoteFolder parent, String name)44 public RemoteResource(RemoteFolder parent, String name) { 45 this.parent = parent; 46 this.name = name; 47 } 48 getName()49 public String getName() { 50 return name; 51 } 52 getRelativePath(ICVSFolder ancestor)53 public String getRelativePath(ICVSFolder ancestor) throws CVSException { 54 return Util.appendPath(parent.getRelativePath(ancestor), getName()); 55 } 56 getRemoteParent()57 public ICVSRemoteResource getRemoteParent() { 58 return parent; 59 } 60 getRepositoryRelativePath()61 public abstract String getRepositoryRelativePath(); 62 getRepository()63 public abstract ICVSRepositoryLocation getRepository(); 64 getWorkspaceSyncState()65 public int getWorkspaceSyncState() { 66 return workspaceSyncState; 67 } 68 setWorkspaceSyncState(int workspaceSyncState)69 public void setWorkspaceSyncState(int workspaceSyncState) { 70 this.workspaceSyncState = workspaceSyncState; 71 } 72 delete()73 public void delete() { 74 // For now, do nothing but we could provide this in the future. 75 } 76 77 /* 78 * @see ICVSResource#exists() 79 * 80 * This method is used by the Command framework so it must return true so that 81 * the proper information gets sent to the server. (i.e. it is used to fake that 82 * the file exists locally so cvs commands can be used to retrieve information about 83 * the remote resource from the server) 84 */ exists()85 public boolean exists() { 86 return true; 87 } 88 exists(IProgressMonitor monitor)89 public boolean exists(IProgressMonitor monitor) throws TeamException { 90 return parent.exists(this, monitor); 91 } 92 getParent()93 public ICVSFolder getParent() { 94 return parent; 95 } 96 isIgnored()97 public boolean isIgnored() { 98 return false; 99 } 100 isManaged()101 public boolean isManaged() { 102 return parent != null; 103 } 104 isModified(IProgressMonitor monitor)105 public boolean isModified(IProgressMonitor monitor) throws CVSException { 106 // it is safe to always consider a remote file handle as modified. This will cause any 107 // CVS command to fetch new contents from the server. 108 return true; 109 } 110 unmanage(IProgressMonitor monitor)111 public void unmanage(IProgressMonitor monitor) throws CVSException { 112 // do nothing 113 } 114 getSyncInfo()115 public abstract ResourceSyncInfo getSyncInfo(); 116 equals(Object target)117 public boolean equals(Object target) { 118 if (this == target) 119 return true; 120 if (!(target instanceof RemoteResource)) 121 return false; 122 RemoteResource remote = (RemoteResource) target; 123 return remote.isContainer() == isContainer() 124 && remote.getRepository().equals(getRepository()) 125 && remote.getRepositoryRelativePath().equals(getRepositoryRelativePath()); 126 } 127 setIgnoredAs(String pattern)128 public void setIgnoredAs(String pattern) throws CVSException { 129 // ensure that clients are not trying to set sync info on remote handles. 130 Assert.isTrue(false); 131 } 132 getIResource()133 public IResource getIResource() { 134 return null; 135 } 136 137 /** 138 * Return a copy of the receiver that is associated with the given tag. The parent 139 * should be a copy of the receiver's parent which has been copied to the same tag. 140 * 141 * @param parent 142 * @param tagName 143 * @return ICVSRemoteFolder 144 */ forTag(ICVSRemoteFolder parent, CVSTag tagName)145 public abstract ICVSRemoteResource forTag(ICVSRemoteFolder parent, CVSTag tagName); 146 hashCode()147 public int hashCode() { 148 return getRepositoryRelativePath().hashCode(); 149 } 150 151 /** 152 * Method which returns an array of bytes that can be used to recreate the remote handle. 153 * To recreate the remote handle, invoke the <code>fromBytes</code> method on either 154 * RemoteFolder or RemoteFile. 155 * 156 * TODO: It would be nice to have a method on RmeoteResource to recreate the handles 157 * but the file requires the bytes for the parent folder since this folder may not 158 * exist locally. 159 * 160 * @return 161 */ getSyncBytes()162 abstract public byte[] getSyncBytes(); 163 toString()164 public String toString() { 165 return "Remote " + (isContainer() ? "Folder: " : "File: ") + getName(); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ 166 } 167 168 @Override getCachePath()169 public String getCachePath() { 170 ICVSRepositoryLocation location = getRepository(); 171 IPath path = new Path(null, location.getHost()); 172 path = path.append(location.getRootDirectory()); 173 path = path.append(parent.getRepositoryRelativePath()); 174 path = path.append(getName() + ' ' + getContentIdentifier()); 175 return path.toString(); 176 } 177 178 @Override getCacheId()179 protected String getCacheId() { 180 return CVSProviderPlugin.ID; 181 } 182 183 @Override asBytes()184 public byte[] asBytes() { 185 return getSyncBytes(); 186 } 187 } 188