Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean Michel-Lemieux2002-02-28 08:59:06 -0500
committerJean Michel-Lemieux2002-02-28 08:59:06 -0500
commite117819dad8a376fb891f1355bb30dd9069035ae (patch)
tree858d47e69b99d89ec1c2123ad066f153e8df79a8
parent7469e36b2a3a34588b3f4e69781aa3d3684d7c84 (diff)
downloadeclipse.platform.team-e117819dad8a376fb891f1355bb30dd9069035ae.tar.gz
eclipse.platform.team-e117819dad8a376fb891f1355bb30dd9069035ae.tar.xz
eclipse.platform.team-e117819dad8a376fb891f1355bb30dd9069035ae.zip
resource refactoring for IResource compatibility
-rw-r--r--bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/CVSLocalSyncElement.java7
-rw-r--r--bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/EclipseFile.java175
-rw-r--r--bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/EclipseFolder.java228
-rw-r--r--bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/EclipseResource.java228
-rw-r--r--bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/ICVSFile.java2
5 files changed, 635 insertions, 5 deletions
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/CVSLocalSyncElement.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/CVSLocalSyncElement.java
index 368de9183..f804e2f0b 100644
--- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/CVSLocalSyncElement.java
+++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/CVSLocalSyncElement.java
@@ -29,12 +29,11 @@ public class CVSLocalSyncElement extends LocalSyncElement {
this.local = local;
this.base = base;
-
- File file = new File(local.getLocation().toOSString());
+
if(local.getType() != IResource.FILE) {
- this.cvsResource = new LocalFolder(file);
+ this.cvsResource = new EclipseFolder(local);
} else {
- this.cvsResource = new LocalFile(file);
+ this.cvsResource = new EclipseFile(local);
}
}
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/EclipseFile.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/EclipseFile.java
new file mode 100644
index 000000000..15313538e
--- /dev/null
+++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/EclipseFile.java
@@ -0,0 +1,175 @@
+package org.eclipse.team.internal.ccvs.core.resources;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.text.ParseException;
+import java.util.Date;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.team.ccvs.core.CVSProviderPlugin;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.Policy;
+import org.eclipse.team.internal.ccvs.core.syncinfo.*;
+import org.eclipse.team.internal.ccvs.core.util.EntryFileDateFormat;
+import org.eclipse.team.internal.ccvs.core.util.Util;
+
+/**
+ * Represents handles to CVS resource on the local file system. Synchronization
+ * information is taken from the CVS subdirectories.
+ *
+ * @see LocalFolder
+ * @see LocalFile
+ */
+public class EclipseFile extends EclipseResource implements ICVSFile {
+
+ /**
+ * Create a handle based on the given local resource.
+ */
+ public EclipseFile(IFile file) {
+ super(file);
+ }
+
+ public long getSize() {
+ }
+
+ public InputStream getInputStream() throws CVSException {
+ try {
+ return getIFile().getContents();
+ } catch (CoreException e) {
+ throw CVSException.wrapException(e);
+ }
+ }
+
+ public OutputStream getOutputStream() throws CVSException {
+ }
+
+ /*
+ * @see ICVSFile#getTimeStamp()
+ */
+ public String getTimeStamp() throws CVSFileNotFoundException {
+ EntryFileDateFormat timestamp = new EntryFileDateFormat();
+ return timestamp.format(new Date(getIOFile().lastModified()));
+ }
+
+ /*
+ * @see ICVSFile#setTimeStamp(String)
+ */
+ public void setTimeStamp(String date) throws CVSException {
+ long millSec;
+ if (date==null) {
+ // get the current time
+ millSec = new Date().getTime();
+ } else {
+ try {
+ EntryFileDateFormat timestamp = new EntryFileDateFormat();
+ millSec = timestamp.toDate(date).getTime();
+ } catch (ParseException e) {
+ throw new CVSException(Policy.bind("LocalFile.invalidDateFormat", date), e); //$NON-NLS-1$
+ }
+ }
+ getIOFile().setLastModified(millSec);
+ }
+
+ /*
+ * @see ICVSResource#isFolder()
+ */
+ public boolean isFolder() {
+ return false;
+ }
+
+ /*
+ * @see ICVSFile#isDirty()
+ */
+ public boolean isDirty() throws CVSException {
+ if (!exists() || !isManaged()) {
+ return true;
+ } else {
+ ResourceSyncInfo info = getSyncInfo();
+ if (info.isAdded()) return false;
+ if (info.isDeleted()) return true;
+ return !getTimeStamp().equals(info.getTimeStamp());
+ }
+ }
+
+ /*
+ * @see ICVSFile#isModified()
+ */
+ public boolean isModified() throws CVSException {
+ if (!exists() || !isManaged()) {
+ return true;
+ } else {
+ ResourceSyncInfo info = getSyncInfo();
+ return !getTimeStamp().equals(info.getTimeStamp());
+ }
+ }
+
+ /*
+ * @see ICVSResource#accept(ICVSResourceVisitor)
+ */
+ public void accept(ICVSResourceVisitor visitor) throws CVSException {
+ visitor.visitFile(this);
+ }
+
+ /*
+ * This is to be used by the Copy handler. The filename of the form .#filename
+ */
+ public void moveTo(String filename) throws CVSException {
+ getIFile().m
+
+ // Move the file to newFile (we know we do not need the
+ // original any more anyway)
+ // If this file exists then overwrite it
+ LocalFile file;
+ try {
+ file = (LocalFile)getParent().getFile(filename);
+ } catch(ClassCastException e) {
+ throw CVSException.wrapException(e);
+ }
+
+ // We are deleting the old .#filename if it exists
+ if (file.exists()) {
+ file.delete();
+ }
+
+ boolean success = ioResource.renameTo(file.getFile());
+
+ if (!success) {
+ throw new CVSException(Policy.bind("LocalFile.moveFailed", ioResource.toString(), file.toString())); //$NON-NLS-1$
+ }
+ }
+
+ /*
+ * @see ICVSResource#getRemoteLocation()
+ */
+ public String getRemoteLocation(ICVSFolder stopSearching) throws CVSException {
+ return getParent().getRemoteLocation(stopSearching) + SEPARATOR + getName();
+ }
+
+ /*
+ * @see ICVSResource#unmanage()
+ */
+ public void unmanage() throws CVSException {
+ CVSProviderPlugin.getSynchronizer().deleteResourceSync(getIOFile());
+ }
+
+ private IFile getIFile() {
+ return (IFile)resource;
+ }
+ /*
+ * @see ICVSFile#setReadOnly()
+ */
+ public void setReadOnly(boolean readOnly) throws CVSException {
+ getIFile().setReadOnly(readOnly);
+ }
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/EclipseFolder.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/EclipseFolder.java
new file mode 100644
index 000000000..1280928b6
--- /dev/null
+++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/EclipseFolder.java
@@ -0,0 +1,228 @@
+package org.eclipse.team.internal.ccvs.core.resources;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2002.
+ * All Rights Reserved.
+ */
+
+import java.io.File;
+import java.io.FileFilter;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.team.ccvs.core.CVSProviderPlugin;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.Policy;
+import org.eclipse.team.internal.ccvs.core.syncinfo.FolderSyncInfo;
+import org.eclipse.team.internal.ccvs.core.syncinfo.ResourceSyncInfo;
+
+/**
+ * Implements the ICVSFolder interface on top of an
+ * instance of the ICVSFolder interface
+ *
+ * @see ICVSFolder
+ */
+public class EclipseFolder extends EclipseResource implements ICVSFolder {
+
+ public EclipseFolder(IContainer container) {
+ super(container);
+ }
+
+ /**
+ *
+ * @see ICVSFolder#getFolders()
+ */
+ public ICVSFolder[] getFolders() throws CVSException {
+
+ IContainer folder = (IContainer)resource;
+
+ if(!resource.exists()) {
+ return new ICVSFolder[0];
+ }
+
+ final List folders = new ArrayList();
+
+ ResourceSyncInfo[] syncDirs = CVSProviderPlugin.getSynchronizer().members(getIOFile());
+ for (int i = 0; i < syncDirs.length; i++) {
+ if(syncDirs[i].isDirectory()) {
+ folders.add(new EclipseFolder(folder.getFolder(new Path(syncDirs[i].getName()))));
+ }
+ }
+
+ IResource[] members = folder.members();
+ for (int i = 0; i < members.length; i++) {
+ IResource child = members[i];
+ if(child.getType()!=IResource.FILE) {
+ EclipseFolder childFolder = new EclipseFolder(child);
+ if(!childFolder.isIgnored() && !folders.contains(childFolder)) {
+ folders.add(childFolder);
+ }
+ }
+ }
+ return (ICVSFolder[]) folders.toArray(new ICVSFolder[folders.size()]);
+ }
+
+ /**
+ * @see ICVSFolder#getFiles()
+ */
+ public ICVSFile[] getFiles() throws CVSException {
+
+ IContainer folder = (IContainer)resource;
+
+ if(!resource.exists()) {
+ return new ICVSFolder[0];
+ }
+
+ final List files = new ArrayList();
+
+ ResourceSyncInfo[] syncFiles = CVSProviderPlugin.getSynchronizer().members(getIOFile());
+ for (int i = 0; i < syncFiles.length; i++) {
+ if(!syncFiles[i].isDirectory()) {
+ files.add(new EclipseFolder(folder.getFile(new Path(syncFiles[i].getName()))));
+ }
+ }
+
+ IResource[] members = folder.members();
+ for (int i = 0; i < members.length; i++) {
+ IResource child = members[i];
+ if(child.getType()==IResource.FILE) {
+ EclipseFolder childFile = new EclipseFile(child);
+ if(!childFile.isIgnored() && !files.contains(childFile)) {
+ files.add(childFile);
+ }
+ }
+ }
+ return (ICVSFile[]) files.toArray(new ICVSFile[files.size()]);
+ }
+
+ /**
+ * @see ICVSFolder#createFolder(String)
+ */
+ public ICVSFolder getFolder(String name) throws CVSException {
+ if ((CURRENT_LOCAL_FOLDER.equals(name)) || ((CURRENT_LOCAL_FOLDER + SEPARATOR).equals(name)))
+ return this;
+ return new EclipseFolder(((IContainer)resource).getFolder(new Path(name)));
+ }
+
+ /**
+ * @see ICVSFolder#createFile(String)
+ */
+ public ICVSFile getFile(String name) throws CVSException {
+ return new EclipseFile(((IContainer)resource).getFile(new Path(name)));
+ }
+
+ /**
+ * @see ICVSFolder#mkdir()
+ */
+ public void mkdir() throws CVSException {
+ if(resource.getType()==IResource.PROJECT) {
+ ((IProject)resource).create(null);
+ } else {
+ ((IFolder)resource).create(false /*don't force*/, true /*make local*/, null);
+ }
+ }
+
+ /**
+ * @see ICVSResource#isFolder()
+ */
+ public boolean isFolder() {
+ return true;
+ }
+
+ /**
+ * @see ICVSFolder#acceptChildren(ICVSResourceVisitor)
+ */
+ public void acceptChildren(ICVSResourceVisitor visitor) throws CVSException {
+
+ ICVSResource[] subFiles;
+ ICVSResource[] subFolders;
+
+ subFiles = getFiles();
+ subFolders = getFolders();
+
+ for (int i=0; i<subFiles.length; i++) {
+ subFiles[i].accept(visitor);
+ }
+
+ for (int i=0; i<subFolders.length; i++) {
+ subFolders[i].accept(visitor);
+ }
+ }
+
+ /**
+ * @see ICVSResource#accept(ICVSResourceVisitor)
+ */
+ public void accept(ICVSResourceVisitor visitor) throws CVSException {
+ visitor.visitFolder(this);
+ }
+
+ /**
+ * @see ICVSResource#getRemoteLocation(ICVSFolder)
+ */
+ public String getRemoteLocation(ICVSFolder stopSearching) throws CVSException {
+
+ String parentLocation;
+
+ if (getFolderSyncInfo() != null) {
+ return getFolderSyncInfo().getRemoteLocation();
+ }
+
+ if (equals(stopSearching)) {
+ return null;
+ }
+
+ parentLocation = getParent().getRemoteLocation(stopSearching);
+ if (parentLocation == null) {
+ return null;
+ } else {
+ return parentLocation + SEPARATOR + getName();
+ }
+ }
+
+ /*
+ * @see ICVSFolder#getFolderInfo()
+ */
+ public FolderSyncInfo getFolderSyncInfo() throws CVSException {
+ return CVSProviderPlugin.getSynchronizer().getFolderSync(getIOFile());
+ }
+
+ /*
+ * @see ICVSFolder#setFolderInfo(FolderSyncInfo)
+ */
+ public void setFolderSyncInfo(FolderSyncInfo folderInfo) throws CVSException {
+ CVSProviderPlugin.getSynchronizer().setFolderSync(getIOFile(), folderInfo);
+ }
+
+ /*
+ * @see ICVSFolder#isCVSFolder()
+ */
+ public boolean isCVSFolder() {
+ try {
+ return CVSProviderPlugin.getSynchronizer().getFolderSync(getIOFile()) != null;
+ } catch(CVSException e) {
+ return false;
+ }
+ }
+
+ /*
+ * @see ICVSResource#unmanage()
+ */
+ public void unmanage() throws CVSException {
+ CVSProviderPlugin.getSynchronizer().deleteFolderSync(getIOFile(), new NullProgressMonitor());
+ }
+
+ /*
+ * @see ICVSResource#isIgnored()
+ */
+ public boolean isIgnored() {
+ if(isCVSFolder()) {
+ return false;
+ }
+ return super.isIgnored();
+ }
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/EclipseResource.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/EclipseResource.java
new file mode 100644
index 000000000..8cb648ed2
--- /dev/null
+++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/EclipseResource.java
@@ -0,0 +1,228 @@
+package org.eclipse.team.internal.ccvs.core.resources;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2002.
+ * All Rights Reserved.
+ */
+
+import java.io.File;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.team.ccvs.core.CVSProviderPlugin;
+import org.eclipse.team.core.IIgnoreInfo;
+import org.eclipse.team.core.TeamPlugin;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.Policy;
+import org.eclipse.team.internal.ccvs.core.client.Session;
+import org.eclipse.team.internal.ccvs.core.syncinfo.ResourceSyncInfo;
+import org.eclipse.team.internal.ccvs.core.util.Assert;
+import org.eclipse.team.internal.ccvs.core.util.FileNameMatcher;
+import org.eclipse.team.internal.ccvs.core.util.FileUtil;
+import org.eclipse.team.internal.ccvs.core.util.SyncFileUtil;
+import org.eclipse.team.internal.ccvs.core.util.Util;
+
+/**
+ * Represents handles to CVS resource on the local file system. Synchronization
+ * information is taken from the CVS subdirectories.
+ *
+ * @see LocalFolder
+ * @see LocalFile
+ */
+public abstract class EclipseResource implements ICVSResource {
+
+ // The seperator that must be used when creating CVS resource paths. Never use
+ // the platform default seperator since it is not compatible with CVS resources.
+ protected static final String SEPARATOR = Session.SERVER_SEPARATOR;
+ protected static final String CURRENT_LOCAL_FOLDER = Session.CURRENT_LOCAL_FOLDER;
+
+ /*
+ * The local resource represented by this handle
+ */
+ IResource resource;
+
+ /*
+ * Creates a CVS handle to the provided resource
+ */
+ public EclipseResource(IResource resource) {
+ Assert.isNotNull(resource);
+ this.resource = resource;
+ }
+
+ /*
+ * 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 {
+ try {
+ LocalResource rootFolder;
+ String result;
+ rootFolder = (EclipseResource)root;
+ result = Util.getRelativePath(rootFolder.getPath(), getPath());
+ return result;
+ } catch (ClassCastException e) {
+ throw new CVSException(Policy.bind("LocalResource.invalidResourceClass"), e); //$NON-NLS-1$
+ }
+ }
+
+ /*
+ * @see ICVSResource#delete()
+ */
+ public void delete() {
+ resource.delete(true /*force*/, null);
+ }
+
+ /*
+ * @see ICVSResource#exists()
+ */
+ public boolean exists() {
+ return resource.exists();
+ }
+
+ /*
+ * Returns the parent folder of this resource of <code>null</code> if resource
+ * the resource.
+ *
+ * @see ICVSResource#getParent()
+ */
+ public ICVSFolder getParent() {
+ IContainer parent = resource.getParent();
+ if (parent == null || parent.getType() == IResource.ROOT) {
+ return null;
+ }
+ return new EclipseFolder(parent);
+ }
+
+ /*
+ * @see ICVSResource#getName()
+ */
+ public String getName() {
+ return resource.getName();
+ }
+
+ /*
+ * @see ICVSResource#isIgnored()
+ */
+ public boolean isIgnored() {
+ // a managed resource is never ignored
+ if(isManaged()) {
+ return false;
+ }
+
+ // initialize matcher with global ignores and basic CVS ignore patterns
+ IIgnoreInfo[] ignorePatterns = TeamPlugin.getManager().getGlobalIgnore();
+ FileNameMatcher matcher = new FileNameMatcher(SyncFileUtil.BASIC_IGNORE_PATTERNS);
+ for (int i = 0; i < ignorePatterns.length; i++) {
+ IIgnoreInfo info = ignorePatterns[i];
+ if(info.getEnabled()) {
+ matcher.register(info.getPattern(), "true"); //$NON-NLS-1$
+ }
+ }
+
+ // 1. check CVS default patterns and global ignores
+ boolean ignored = matcher.match(getName());
+
+ // 2. check .cvsignore file
+ if(!ignored) {
+ ignored = CVSProviderPlugin.getSynchronizer().isIgnored(getIOFile());
+ }
+
+ // 3. check the parent
+ if(!ignored) {
+ ICVSFolder parent = getParent();
+ if(parent==null) return false;
+ return parent.isIgnored();
+ } else {
+ return ignored;
+ }
+ }
+
+ /*
+ * @see ICVSResource#setIgnored()
+ */
+ public void setIgnored() throws CVSException {
+ CVSProviderPlugin.getSynchronizer().setIgnored(getIOFile(), null);
+ }
+
+ /*
+ * @see ICVSResource#setIgnoredAs(String)
+ */
+ public void setIgnoredAs(String pattern) throws CVSException {
+ CVSProviderPlugin.getSynchronizer().setIgnored(getIOFile(), pattern);
+ }
+
+ /*
+ * @see ICVSResource#isManaged()
+ */
+ public boolean isManaged() {
+ try {
+ return getSyncInfo() != null;
+ } catch(CVSException e) {
+ return false;
+ }
+ }
+
+ /**
+ * 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 EclipseResource)) {
+ return false;
+ } else {
+ return getPath().equals(((EclipseResource) obj).getPath());
+ }
+ }
+
+ /*
+ * @see ICVSResource#getPath()
+ */
+ public String getPath() {
+ return resource.getFullPath();
+ }
+
+ /*
+ * @see ICVSResource#isFolder()
+ */
+ public boolean isFolder() {
+ return false;
+ }
+
+ /*
+ * @see ICVSResource#getSyncInfo()
+ */
+ public ResourceSyncInfo getSyncInfo() throws CVSException {
+ return CVSProviderPlugin.getSynchronizer().getResourceSync(getIOFile());
+ }
+
+ /*
+ * @see ICVSResource#setSyncInfo(ResourceSyncInfo)
+ */
+ public void setSyncInfo(ResourceSyncInfo info) throws CVSException {
+ CVSProviderPlugin.getSynchronizer().setResourceSync(getIOFile(), info);
+ }
+
+ /*
+ * Implement the hashcode on the underlying strings, like it is done in the equals.
+ */
+ public int hashCode() {
+ return getPath().hashCode();
+ }
+
+ /*
+ * Give the pathname back
+ */
+ public String toString() {
+ return getPath();
+ }
+
+ /*
+ * REFACTOR Temporary helper for accessing the underlying file associated with this
+ * eclipse resource. Must be removed when the refactoring is complete.
+ */
+ protected File getIOFile() {
+ return resource.getLocation().toFile();
+ }
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/ICVSFile.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/ICVSFile.java
index bb4d3aed6..995f59d81 100644
--- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/ICVSFile.java
+++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/ICVSFile.java
@@ -40,7 +40,7 @@ public interface ICVSFile extends ICVSResource {
/**
* Sets the file's read-only permission.
*/
- void setReadOnly() throws CVSException;
+ void setReadOnly(boolean readOnly) throws CVSException;
/**
* Move the resource to another location. Does overwrite without

Back to the top