diff options
author | Jean Michel-Lemieux | 2001-12-07 18:47:05 +0000 |
---|---|---|
committer | Jean Michel-Lemieux | 2001-12-07 18:47:05 +0000 |
commit | d24be616c6ce22e0d684f1ce834729db7d328b0d (patch) | |
tree | 0dcbef00865c424de983442732552eff59017229 /bundles/org.eclipse.team.cvs.core/src/org/eclipse | |
parent | ed63c10085cd878fc189a438360fcfabfb4d0deb (diff) | |
download | eclipse.platform.team-d24be616c6ce22e0d684f1ce834729db7d328b0d.tar.gz eclipse.platform.team-d24be616c6ce22e0d684f1ce834729db7d328b0d.tar.xz eclipse.platform.team-d24be616c6ce22e0d684f1ce834729db7d328b0d.zip |
CVS resources refactoring - removed api package and property classes
Diffstat (limited to 'bundles/org.eclipse.team.cvs.core/src/org/eclipse')
112 files changed, 10458 insertions, 12971 deletions
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/ccvs/core/ICVSTag.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/ccvs/core/ICVSTag.java deleted file mode 100644 index dfc7ce716..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/ccvs/core/ICVSTag.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.eclipse.team.ccvs.core; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -/** - * The ICVSTag interface is used to proivde information about - * a tag that exists on a file in CVS. - */ -public interface ICVSTag { - - /** - * Get the name of the tag - */ - public String getName(); - - /** - * Return true if the tag is a branch tag - */ - public boolean isBranch(); - - /** - * Return true if the tag is a version tag - */ - public boolean isVersion(); -} - diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSException.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSException.java index 461cf8901..e603ab20a 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSException.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSException.java @@ -12,9 +12,9 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
+import org.eclipse.team.ccvs.core.CVSProviderPlugin;
import org.eclipse.team.core.TeamException;
import org.eclipse.team.internal.ccvs.core.connection.ResourceStatus;
-import org.eclipse.team.ccvs.core.CVSProviderPlugin;
/**
* This is an exception that is thrown by the cvs-adaptor
@@ -112,4 +112,15 @@ public class CVSException extends TeamException { message,
e));
}
+ /*
+ * Static helper methods for creating exceptions
+ */
+ public static CVSException wrapException(Exception e) {
+ return new CVSException(new Status(
+ IStatus.ERROR,
+ CVSProviderPlugin.ID,
+ UNABLE,
+ e.getMessage(),
+ e));
+ }
}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSProvider.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSProvider.java index 9fa5d912c..94298cbc6 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSProvider.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSProvider.java @@ -1,342 +1,340 @@ -package org.eclipse.team.internal.ccvs.core; - -import java.io.PrintStream; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.Set; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceVisitor; -import org.eclipse.core.resources.IWorkspaceRunnable; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Status; -import org.eclipse.team.ccvs.core.CVSProviderPlugin; -import org.eclipse.team.ccvs.core.CVSTeamProvider; -import org.eclipse.team.ccvs.core.ICVSProvider; -import org.eclipse.team.ccvs.core.ICVSRepositoryLocation; -import org.eclipse.team.ccvs.core.IConnectionMethod; -import org.eclipse.team.ccvs.core.ICVSRemoteFolder; -import org.eclipse.team.ccvs.core.ICVSRemoteResource; -import org.eclipse.team.core.IFileTypeRegistry; -import org.eclipse.team.core.TeamException; -import org.eclipse.team.core.TeamPlugin; -import org.eclipse.team.internal.ccvs.core.connection.CVSRepositoryLocation; -import org.eclipse.team.internal.ccvs.core.resources.RemoteFolder; -import org.eclipse.team.internal.ccvs.core.resources.RemoteResource; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFolder; -import org.eclipse.team.internal.ccvs.core.util.ProjectDescriptionManager; - -public class CVSProvider implements ICVSProvider { - - private static CVSProvider instance; - private PrintStream printStream; - private Map repositories; - - private CVSProvider() { - repositories = new HashMap(); - } - - /* - * Build the repository instance from the given properties. - * The supported properties are: - * - * connection The connection method to be used - * user The username for the connection - * password The password used for the connection (optional) - * host The host where the repository resides - * port The port to connect to (optional) - * root The server directory where the repository is located - */ - private CVSRepositoryLocation buildRepository(Properties configuration, boolean cachePassword) throws CVSException { - // We build a string to allow validation of the components that are provided to us - // NOTE: This is a bit strange. We should call the constrructor directly - StringBuffer repository = new StringBuffer(":"); - String connection = configuration.getProperty("connection"); - if (connection == null) - repository.append("pserver"); - else - repository.append(connection); - repository.append(":"); - String user = configuration.getProperty("user"); - if (user == null) - throw new CVSException(new Status(IStatus.ERROR, CVSProviderPlugin.ID, TeamException.UNABLE, Policy.bind("CVSProvider.noUser"), null)); - else - repository.append(user); - repository.append("@"); - String host = configuration.getProperty("host"); - if (host == null) - throw new CVSException(new Status(IStatus.ERROR, CVSProviderPlugin.ID, TeamException.UNABLE, Policy.bind("CVSProvider.noHost"), null)); - else - repository.append(host); - String port = configuration.getProperty("port"); - if (port != null) { - repository.append("#"); - repository.append(port); - } - repository.append(":"); - String root = configuration.getProperty("root"); - if (root == null) - throw new CVSException(new Status(IStatus.ERROR, CVSProviderPlugin.ID, TeamException.UNABLE, Policy.bind("CVSProvider.noRoot"), null)); - else - repository.append(root); - - // NOTE: Check the cache to see if the instance already exists - - CVSRepositoryLocation location = CVSRepositoryLocation.fromString(repository.toString()); - - String password = configuration.getProperty("password"); - if (password != null) { - if (cachePassword) - location.storePassword(password); - else - location.setPassword(password); - } - - return location; - } - - /* - * Add the repository location to the cahced locations - */ - private void addToCache(ICVSRepositoryLocation repository) { - repositories.put(repository.getLocation(), repository); - } - - /** - * @see ICVSProvider#checkout(ICVSRepositoryLocation, IProject, String, String, IProgressMonitor) - */ - public void checkout( - ICVSRepositoryLocation repository, - IProject project, - String sourceModule, - String tag, - IProgressMonitor monitor) - throws TeamException { - - try { - - // Create the project if one wasn't passed. - // NOTE: This will need to be fixed for module alias support - if (project == null) - project = ResourcesPlugin.getWorkspace().getRoot().getProject(new Path(sourceModule).lastSegment()); - - // Get the location of the workspace root - IManagedFolder root = Client.getManagedFolder(ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile()); - - // Build the local options - List localOptions = new ArrayList(); - String module = project.getName(); - if (sourceModule != null) { - localOptions.add(Client.DEEP_OPTION); - localOptions.add(module); - module = sourceModule; - } - if (tag != null) { - localOptions.add(Client.TAG_OPTION ); - localOptions.add(tag); - } - - // Perform a checkout - Client.execute( - Client.CHECKOUT, - new String[0], - (String[])localOptions.toArray(new String[localOptions.size()]), - new String[]{module}, - root, - monitor, - getPrintStream(), - (CVSRepositoryLocation)repository, - null); - - // Create, open and/or refresh the project - if (!project.exists()) - project.create(monitor); - if (!project.isOpen()) - project.open(monitor); - else - project.refreshLocal(IResource.DEPTH_INFINITE, monitor); - - // Get the meta file - // NOTE: This is related to project meta-information and is subject to change - ProjectDescriptionManager.updateProjectIfNecessary(project, monitor); - - // Register the project with Team - TeamPlugin.getManager().setProvider(project, CVSProviderPlugin.NATURE_ID, null, monitor); - - } catch (CoreException e) { - throw wrapException(e); - } - } - - /** - * @see ICVSProvider#checkout(IProject, Properties, IProgressMonitor) - */ - public void checkout( - IProject project, - Properties configuration, - IProgressMonitor monitor) - throws TeamException { - - CVSRepositoryLocation location = buildRepository(configuration, false); - try { - checkout(location, project, configuration.getProperty("module"), configuration.getProperty("tag"), monitor); - } catch (TeamException e) { - // The checkout may have triggered password caching - // Therefore, if this is a newly created location, we want to clear its cache - if (!isCached(location)) - location.dispose(); - throw e; - } - // We succeeded so we should cache the password and the location - location.updateCache(); - addToCache(location); - } - - /** - * @see ICVSProvider#checkout(ICVSRemoteResource[], IProject[], IProgressMonitor) - */ - public void checkout( - final ICVSRemoteResource[] resources, - final IProject[] projects, - final IProgressMonitor monitor) - throws TeamException { - - final TeamException[] eHolder = new TeamException[1]; - try { - IWorkspaceRunnable workspaceRunnable = new IWorkspaceRunnable() { - public void run(IProgressMonitor pm) throws CoreException { - try { - for (int i=0;i<resources.length;i++) { - IProject project = null; - RemoteResource resource = (RemoteResource)resources[i]; - if (projects != null) - project = projects[i]; - checkout(resource.getRepository(), project, resource.getRemotePath(), null, monitor); - } - } - catch (TeamException e) { - // Pass it outside the workspace runnable - eHolder[0] = e; - } - // CoreException and OperationCanceledException are propagated - } - }; - ResourcesPlugin.getWorkspace().run(workspaceRunnable, monitor); - } catch (CoreException e) { - throw wrapException(e); - } - - // Re-throw the TeamException, if one occurred - if (eHolder[0] != null) { - throw eHolder[0]; - } - - } - - /** - * @see ICVSProvider#createRepository(Properties) - */ - public ICVSRepositoryLocation createRepository(Properties configuration) throws CVSException { - ICVSRepositoryLocation repository = buildRepository(configuration, true); - addToCache(repository); - return repository; - } - - /** - * @see ICVSProvider#disposeRepository(ICVSRepositoryLocation) - */ - public void disposeRepository(ICVSRepositoryLocation repository) throws CVSException { - ((CVSRepositoryLocation)repository).dispose(); - removeFromCache(repository); - } - - /* - * Returns all patterns in the given project that should be treated as binary - */ - private String[] getBinaryFilePatterns(IProject project) throws TeamException { - final IFileTypeRegistry registry = TeamPlugin.getFileTypeRegistry(); - final Set result = new HashSet(); - try { - project.accept(new IResourceVisitor() { - public boolean visit(IResource resource) { - if (resource.getType() == IResource.FILE) { - String extension = resource.getFileExtension(); - if (extension == null) { - result.add(resource.getName()); - } else if (!("true".equals(registry.getValue(extension, "isAscii")))) { - result.add("*." + extension); - } - } - // Always return true and let the depth determine if children are visited - return true; - } - }, IResource.DEPTH_INFINITE, false); - } catch (CoreException e) { - throw wrapException(e); - } - return (String[])result.toArray(new String[result.size()]); - } - - /** - * Return the singleton instance of CVSProvider - */ - public static CVSProvider getInstance() { - return instance; - } - - /** - * @see ICVSProvider#getKnownRepositories() - */ - public ICVSRepositoryLocation[] getKnownRepositories() { - return (ICVSRepositoryLocation[])repositories.entrySet().toArray(new ICVSRepositoryLocation[repositories.size()]); - } - - - /** - * Get the print stream to which information from CVS commands - * is sent. - */ - public PrintStream getPrintStream() { - if (printStream == null) - return System.out; - else - return printStream; - } - - /** - * @see ICVSProvider#getSupportedConnectionMethods() - */ - public String[] getSupportedConnectionMethods() { - IConnectionMethod[] methods = CVSRepositoryLocation.getPluggedInConnectionMethods(); - String[] result = new String[methods.length]; - for (int i=0;i<methods.length;i++) - result[i] = methods[i].getName(); - return result; - } - - /* - * @see ICVSProvider#importAndCheckout(IProject, Properties, IProgressMonitor) - */ - public void importAndCheckout( - IProject project, - Properties configuration, - IProgressMonitor monitor) - throws TeamException { - - CVSRepositoryLocation location = buildRepository(configuration, false); +package org.eclipse.team.internal.ccvs.core;
+
+import java.io.PrintStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceVisitor;
+import org.eclipse.core.resources.IWorkspaceRunnable;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.team.ccvs.core.CVSProviderPlugin;
+import org.eclipse.team.ccvs.core.CVSTag;
+import org.eclipse.team.ccvs.core.ICVSProvider;
+import org.eclipse.team.ccvs.core.ICVSRemoteResource;
+import org.eclipse.team.ccvs.core.ICVSRepositoryLocation;
+import org.eclipse.team.ccvs.core.IConnectionMethod;
+import org.eclipse.team.core.IFileTypeRegistry;
+import org.eclipse.team.core.TeamException;
+import org.eclipse.team.core.TeamPlugin;
+import org.eclipse.team.internal.ccvs.core.connection.CVSRepositoryLocation;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFolder;
+import org.eclipse.team.internal.ccvs.core.resources.RemoteResource;
+import org.eclipse.team.internal.ccvs.core.util.ProjectDescriptionManager;
+
+public class CVSProvider implements ICVSProvider {
+
+ private static CVSProvider instance;
+ private PrintStream printStream;
+ private Map repositories;
+
+ private CVSProvider() {
+ repositories = new HashMap();
+ }
+
+ /*
+ * Build the repository instance from the given properties.
+ * The supported properties are:
+ *
+ * connection The connection method to be used
+ * user The username for the connection
+ * password The password used for the connection (optional)
+ * host The host where the repository resides
+ * port The port to connect to (optional)
+ * root The server directory where the repository is located
+ */
+ private CVSRepositoryLocation buildRepository(Properties configuration, boolean cachePassword) throws CVSException {
+ // We build a string to allow validation of the components that are provided to us
+ // NOTE: This is a bit strange. We should call the constrructor directly
+ StringBuffer repository = new StringBuffer(":");
+ String connection = configuration.getProperty("connection");
+ if (connection == null)
+ repository.append("pserver");
+ else
+ repository.append(connection);
+ repository.append(":");
+ String user = configuration.getProperty("user");
+ if (user == null)
+ throw new CVSException(new Status(IStatus.ERROR, CVSProviderPlugin.ID, TeamException.UNABLE, Policy.bind("CVSTeamProvider.noUser"), null));
+ else
+ repository.append(user);
+ repository.append("@");
+ String host = configuration.getProperty("host");
+ if (host == null)
+ throw new CVSException(new Status(IStatus.ERROR, CVSProviderPlugin.ID, TeamException.UNABLE, Policy.bind("CVSTeamProvider.noHost"), null));
+ else
+ repository.append(host);
+ String port = configuration.getProperty("port");
+ if (port != null) {
+ repository.append("#");
+ repository.append(port);
+ }
+ repository.append(":");
+ String root = configuration.getProperty("root");
+ if (root == null)
+ throw new CVSException(new Status(IStatus.ERROR, CVSProviderPlugin.ID, TeamException.UNABLE, Policy.bind("CVSTeamProvider.noRoot"), null));
+ else
+ repository.append(root);
+
+ // NOTE: Check the cache to see if the instance already exists
+
+ CVSRepositoryLocation location = CVSRepositoryLocation.fromString(repository.toString());
+
+ String password = configuration.getProperty("password");
+ if (password != null) {
+ if (cachePassword)
+ location.storePassword(password);
+ else
+ location.setPassword(password);
+ }
+
+ return location;
+ }
+
+ /*
+ * Add the repository location to the cahced locations
+ */
+ private void addToCache(ICVSRepositoryLocation repository) {
+ repositories.put(repository.getLocation(), repository);
+ }
+
+ /**
+ * @see ICVSProvider#checkout(ICVSRepositoryLocation, IProject, String, String, IProgressMonitor)
+ */
+ public void checkout(
+ ICVSRepositoryLocation repository,
+ IProject project,
+ String sourceModule,
+ CVSTag tag,
+ IProgressMonitor monitor)
+ throws TeamException {
+
+ try {
+
+ // Create the project if one wasn't passed.
+ // NOTE: This will need to be fixed for module alias support
+ if (project == null)
+ project = ResourcesPlugin.getWorkspace().getRoot().getProject(new Path(sourceModule).lastSegment());
+
+ // Get the location of the workspace root
+ ICVSFolder root = Client.getManagedFolder(ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile());
+
+ // Build the local options
+ List localOptions = new ArrayList();
+ String module = project.getName();
+ if (sourceModule != null) {
+ localOptions.add(Client.DEEP_OPTION);
+ localOptions.add(module);
+ module = sourceModule;
+ }
+ // XXX Needs to be updated for date tags
+ if (tag != null) {
+ localOptions.add(Client.TAG_OPTION );
+ localOptions.add(tag.getName());
+ }
+
+ // Perform a checkout
+ Client.execute(
+ Client.CHECKOUT,
+ new String[0],
+ (String[])localOptions.toArray(new String[localOptions.size()]),
+ new String[]{module},
+ root,
+ monitor,
+ getPrintStream(),
+ (CVSRepositoryLocation)repository,
+ null);
+
+ // Create, open and/or refresh the project
+ if (!project.exists())
+ project.create(monitor);
+ if (!project.isOpen())
+ project.open(monitor);
+ else
+ project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
+
+ // Get the meta file
+ // NOTE: This is related to project meta-information and is subject to change
+ ProjectDescriptionManager.updateProjectIfNecessary(project, monitor);
+
+ // Register the project with Team
+ TeamPlugin.getManager().setProvider(project, CVSProviderPlugin.NATURE_ID, null, monitor);
+
+ } catch (CoreException e) {
+ throw wrapException(e);
+ }
+ }
+
+ /**
+ * @see ICVSProvider#checkout(IProject, Properties, IProgressMonitor)
+ */
+ public void checkout(
+ IProject project,
+ Properties configuration,
+ IProgressMonitor monitor)
+ throws TeamException {
+
+ CVSRepositoryLocation location = buildRepository(configuration, false);
+ try {
+ checkout(location, project, configuration.getProperty("module"), getTagFromProperties(configuration), monitor);
+ } catch (TeamException e) {
+ // The checkout may have triggered password caching
+ // Therefore, if this is a newly created location, we want to clear its cache
+ if (!isCached(location))
+ location.dispose();
+ throw e;
+ }
+ // We succeeded so we should cache the password and the location
+ location.updateCache();
+ addToCache(location);
+ }
+
+ /**
+ * @see ICVSProvider#checkout(ICVSRemoteResource[], IProject[], IProgressMonitor)
+ */
+ public void checkout(
+ final ICVSRemoteResource[] resources,
+ final IProject[] projects,
+ final IProgressMonitor monitor)
+ throws TeamException {
+
+ final TeamException[] eHolder = new TeamException[1];
+ try {
+ IWorkspaceRunnable workspaceRunnable = new IWorkspaceRunnable() {
+ public void run(IProgressMonitor pm) throws CoreException {
+ try {
+ for (int i=0;i<resources.length;i++) {
+ IProject project = null;
+ RemoteResource resource = (RemoteResource)resources[i];
+ if (projects != null)
+ project = projects[i];
+ checkout(resource.getRepository(), project, resource.getRemotePath(), null, monitor);
+ }
+ }
+ catch (TeamException e) {
+ // Pass it outside the workspace runnable
+ eHolder[0] = e;
+ }
+ // CoreException and OperationCanceledException are propagated
+ }
+ };
+ ResourcesPlugin.getWorkspace().run(workspaceRunnable, monitor);
+ } catch (CoreException e) {
+ throw wrapException(e);
+ }
+
+ // Re-throw the TeamException, if one occurred
+ if (eHolder[0] != null) {
+ throw eHolder[0];
+ }
+
+ }
+
+ /**
+ * @see ICVSProvider#createRepository(Properties)
+ */
+ public ICVSRepositoryLocation createRepository(Properties configuration) throws CVSException {
+ ICVSRepositoryLocation repository = buildRepository(configuration, true);
+ addToCache(repository);
+ return repository;
+ }
+
+ /**
+ * @see ICVSProvider#disposeRepository(ICVSRepositoryLocation)
+ */
+ public void disposeRepository(ICVSRepositoryLocation repository) throws CVSException {
+ ((CVSRepositoryLocation)repository).dispose();
+ removeFromCache(repository);
+ }
+
+ /*
+ * Returns all patterns in the given project that should be treated as binary
+ */
+ private String[] getBinaryFilePatterns(IProject project) throws TeamException {
+ final IFileTypeRegistry registry = TeamPlugin.getFileTypeRegistry();
+ final Set result = new HashSet();
+ try {
+ project.accept(new IResourceVisitor() {
+ public boolean visit(IResource resource) {
+ if (resource.getType() == IResource.FILE) {
+ String extension = resource.getFileExtension();
+ if (extension == null) {
+ result.add(resource.getName());
+ } else if (!("true".equals(registry.getValue(extension, "isAscii")))) {
+ result.add("*." + extension);
+ }
+ }
+ // Always return true and let the depth determine if children are visited
+ return true;
+ }
+ }, IResource.DEPTH_INFINITE, false);
+ } catch (CoreException e) {
+ throw wrapException(e);
+ }
+ return (String[])result.toArray(new String[result.size()]);
+ }
+
+ /**
+ * Return the singleton instance of CVSProvider
+ */
+ public static CVSProvider getInstance() {
+ return instance;
+ }
+
+ /**
+ * @see ICVSProvider#getKnownRepositories()
+ */
+ public ICVSRepositoryLocation[] getKnownRepositories() {
+ return (ICVSRepositoryLocation[])repositories.entrySet().toArray(new ICVSRepositoryLocation[repositories.size()]);
+ }
+
+
+ /**
+ * Get the print stream to which information from CVS commands
+ * is sent.
+ */
+ public PrintStream getPrintStream() {
+ if (printStream == null)
+ return System.out;
+ else
+ return printStream;
+ }
+
+ /**
+ * @see ICVSProvider#getSupportedConnectionMethods()
+ */
+ public String[] getSupportedConnectionMethods() {
+ IConnectionMethod[] methods = CVSRepositoryLocation.getPluggedInConnectionMethods();
+ String[] result = new String[methods.length];
+ for (int i=0;i<methods.length;i++)
+ result[i] = methods[i].getName();
+ return result;
+ }
+
+ /*
+ * @see ICVSProvider#importAndCheckout(IProject, Properties, IProgressMonitor)
+ */
+ public void importAndCheckout(
+ IProject project,
+ Properties configuration,
+ IProgressMonitor monitor)
+ throws TeamException {
+
+ CVSRepositoryLocation location = buildRepository(configuration, false);
try { importProject(location, project, configuration, monitor); - checkout(location, project, configuration.getProperty("module"), configuration.getProperty("tag"), monitor); + checkout(location, project, configuration.getProperty("module"), getTagFromProperties(configuration), monitor); } catch (TeamException e) { // The checkout may have triggered password caching // Therefore, if this is a newly created location, we want to clear its cache @@ -348,7 +346,16 @@ public class CVSProvider implements ICVSProvider { location.updateCache(); addToCache(location); } - +
+ private CVSTag getTagFromProperties(Properties configuration) {
+ String date = configuration.getProperty("date");
+ String tagName = configuration.getProperty("tag");
+ if (tagName == null)
+ tagName = configuration.getProperty("branch");
+ if (tagName == null)
+ return CVSTag.DEFAULT;
+ return new CVSTag(tagName, CVSTag.BRANCH);
+ }
public void importProject( ICVSRepositoryLocation location, IProject project, @@ -356,92 +363,92 @@ public class CVSProvider implements ICVSProvider { IProgressMonitor monitor) throws TeamException { - // Get the location of the workspace root - IManagedFolder root = Client.getManagedFolder(project.getLocation().toFile()); - - // Create the meta-file - ProjectDescriptionManager.writeProjectDescription(project, monitor); - - // Get the message - String message = configuration.getProperty("message"); - if (message == null) + // Get the location of the workspace root
+ ICVSFolder root = Client.getManagedFolder(project.getLocation().toFile());
+
+ // Create the meta-file
+ ProjectDescriptionManager.writeProjectDescription(project, monitor);
+
+ // Get the message
+ String message = configuration.getProperty("message");
+ if (message == null)
message = Policy.bind("CVSProvider.initialImport"); - - // Get the vendor - String vendor = configuration.getProperty("vendor"); - if (vendor == null) - vendor = location.getUsername(); - - // Get the vendor - String tag = configuration.getProperty("tag"); - if (tag == null) - tag = "start"; - +
+ // Get the vendor
+ String vendor = configuration.getProperty("vendor");
+ if (vendor == null)
+ vendor = location.getUsername();
+
+ // Get the vendor
+ String tag = configuration.getProperty("tag");
+ if (tag == null)
+ tag = "start";
+
// Get the module name String module = configuration.getProperty("module"); if (module == null) module = project.getName(); - // Build the local options - List localOptions = new ArrayList(); - localOptions.add(Client.MESSAGE_OPTION); - localOptions.add(message); - // Create filters for all known text files - String[] patterns = getBinaryFilePatterns(project); - for (int i=0;i<patterns.length;i++) { - localOptions.add(Client.WRAPPER_OPTION); - localOptions.add(patterns[i] + " -k 'b'"); - } - - // Perform a import - Client.execute( - Client.IMPORT, - new String[] {}, - (String[])localOptions.toArray(new String[localOptions.size()]), + // Build the local options
+ List localOptions = new ArrayList();
+ localOptions.add(Client.MESSAGE_OPTION);
+ localOptions.add(message);
+ // Create filters for all known text files
+ String[] patterns = getBinaryFilePatterns(project);
+ for (int i=0;i<patterns.length;i++) {
+ localOptions.add(Client.WRAPPER_OPTION);
+ localOptions.add(patterns[i] + " -k 'b'");
+ }
+
+ // Perform a import
+ Client.execute(
+ Client.IMPORT,
+ new String[] {},
+ (String[])localOptions.toArray(new String[localOptions.size()]),
new String[]{module, vendor, tag}, - root, - monitor, - getPrintStream(), + root,
+ monitor,
+ getPrintStream(),
(CVSRepositoryLocation)location, - null); - - // NOTE: we should check to see the results of the import - } - - public static void initialize() { - if (instance == null) - instance = new CVSProvider(); - } - - private boolean isCached(ICVSRepositoryLocation repository) { - return repositories.containsKey(repository.getLocation()); - } - - private void removeFromCache(ICVSRepositoryLocation repository) { - repositories.remove(repository.getLocation()); - } - - /** - * Set the stream to which CVS command output is sent - */ - public void setPrintStream(PrintStream out) { - printStream = out; - } - - private IStatus statusFor(CoreException e) { - return new Status(IStatus.ERROR, CVSProviderPlugin.ID, CVSException.UNABLE, getMessageFor(e), e); - } - - private CVSException wrapException(CoreException e) { - return new CVSException(statusFor(e)); - } - - private String getMessageFor(Exception e) { - String message = Policy.bind(e.getClass().getName(), new Object[] {e.getMessage()}); - if (message.equals(e.getClass().getName())) - message = Policy.bind("CVSProvider.exception", new Object[] {e.toString()}); - return message; - } - -} - + null);
+
+ // NOTE: we should check to see the results of the import
+ }
+
+ public static void initialize() {
+ if (instance == null)
+ instance = new CVSProvider();
+ }
+
+ private boolean isCached(ICVSRepositoryLocation repository) {
+ return repositories.containsKey(repository.getLocation());
+ }
+
+ private void removeFromCache(ICVSRepositoryLocation repository) {
+ repositories.remove(repository.getLocation());
+ }
+
+ /**
+ * Set the stream to which CVS command output is sent
+ */
+ public void setPrintStream(PrintStream out) {
+ printStream = out;
+ }
+
+ private IStatus statusFor(CoreException e) {
+ return new Status(IStatus.ERROR, CVSProviderPlugin.ID, CVSException.UNABLE, getMessageFor(e), e);
+ }
+
+ private CVSException wrapException(CoreException e) {
+ return new CVSException(statusFor(e));
+ }
+
+ private String getMessageFor(Exception e) {
+ String message = Policy.bind(e.getClass().getName(), new Object[] {e.getMessage()});
+ if (message.equals(e.getClass().getName()))
+ message = Policy.bind("CVSProvider.exception", new Object[] {e.toString()});
+ return message;
+ }
+
+}
+
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSProviderPlugin.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSProviderPlugin.java index 368da5049..16b0db77b 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSProviderPlugin.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSProviderPlugin.java @@ -1,148 +1,148 @@ -package org.eclipse.team.ccvs.core; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceChangeEvent; -import org.eclipse.core.resources.IResourceChangeListener; -import org.eclipse.core.resources.IResourceDelta; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPluginDescriptor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Plugin; -import org.eclipse.team.core.ITeamProvider; -import org.eclipse.team.core.TeamException; -import org.eclipse.team.core.TeamPlugin; -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.CVSProvider; -import org.eclipse.team.internal.ccvs.core.Policy; -import org.eclipse.team.internal.ccvs.core.util.DirtyDeltaVisitor; -import org.eclipse.team.internal.ccvs.core.util.ProjectDescriptionManager; -import org.eclipse.team.internal.ccvs.core.util.Util; - -public class CVSProviderPlugin extends Plugin { - - private static CVSProviderPlugin instance; - /** - * Int used for the communications timeout on server connections (in seconds) - */ - public static final int DEFAULT_TIMEOUT = 60; - private int communicationsTimeout = DEFAULT_TIMEOUT; - - public static final String ID = "org.eclipse.team.cvs.core"; - public static final String PT_AUTHENTICATOR = "authenticator"; - public static final String PT_CONNECTIONMETHODS = "connectionmethods"; - - /** - * The identifier for the CVS nature - * (value <code>"org.eclipse.team.cvs.core.nature"</code>). - * The presence of this nature on a project indicates that it is - * CVS-capable. - * - * @see org.eclipse.core.resources.IProject#hasNature - */ - public static final String NATURE_ID = ID + ".cvsnature" ; - - /** - * Constructor for CVSProviderPlugin. - * @param descriptor - */ - public CVSProviderPlugin(IPluginDescriptor descriptor) { - super(descriptor); - instance = this; - } - - /** - * Convenience method for logging CVSExceptiuons to the plugin log - */ - public static void log(TeamException e) { - // For now, we'll log the status. However we should do more - instance.getLog().log(e.getStatus()); - } - public static void log(IStatus status) { - // For now, we'll log the status. However we should do more - instance.getLog().log(status); - } - - /** - * Get the ICVSProvider - */ - public static ICVSProvider getProvider() { - return CVSProvider.getInstance(); - } - - /** - * Get the communications timeout value in seconds - */ - public int getTimeout() { - return communicationsTimeout; - } - /** - * Set the timeout value for communications to a value in seconds. - * The value must be greater than or equal 0. If is it 0, there is no timeout. - */ - public void setTimeout(int timeout) { - this.communicationsTimeout = Math.max(0, timeout); - } - - /** - * @see Plugin#startup() - */ - public void startup() throws CoreException { - Policy.localize("org.eclipse.team.internal.ccvs.core.messages"); - DirtyDeltaVisitor visitor = new DirtyDeltaVisitor(); - visitor.register(); - CVSProvider.initialize(); - } - - /* - * Add a resource change listener to the workspace in order to respond to - * resource deletions and moves and to ensure or project desription file is up to date. - */ - private void initializeChangeListener() { - - // Build a change listener for changes to thr project meta-information - IResourceChangeListener projectChangeListener = new IResourceChangeListener() { - public void resourceChanged(IResourceChangeEvent event) { - try { - IResourceDelta root = event.getDelta(); - IResourceDelta[] projectDeltas = root.getAffectedChildren(IResourceDelta.CHANGED); - for (int i = 0; i < projectDeltas.length; i++) { - IResourceDelta delta = projectDeltas[i]; - IResource resource = delta.getResource(); - if (resource.getType() == IResource.PROJECT) { - IProject project = (IProject)resource; - // Get the team provider for the project and - ITeamProvider provider = TeamPlugin.getManager().getProvider(project); - if (!(provider instanceof CVSTeamProvider)) continue; - /* Check if the project description changed. */ - if ((delta.getFlags() & IResourceDelta.DESCRIPTION) != 0) { - /* The project description changed. Write the file. */ - ProjectDescriptionManager.writeProjectDescriptionIfNecessary((CVSTeamProvider)provider, project, Policy.monitorFor(null)); - } - - /* Check if the .vcm_meta file for the project is in the delta. */ - IResourceDelta[] children = delta.getAffectedChildren(IResourceDelta.REMOVED); - for (int j = 0; j < children.length; j++) { - IResourceDelta childDelta = children[j]; - IResource childResource = childDelta.getResource(); - if (ProjectDescriptionManager.isProjectDescription(childResource)) { - ProjectDescriptionManager.writeProjectDescriptionIfNecessary((CVSTeamProvider)provider, project, Policy.monitorFor(null)); - } - } - } - } - } catch (CVSException ex) { - Util.logError(Policy.bind("CVSProviderPlugin.cannotUpdateDescription"), ex); - } - } - }; - ResourcesPlugin.getWorkspace().addResourceChangeListener(projectChangeListener, IResourceChangeEvent.POST_AUTO_BUILD); - } -} - +package org.eclipse.team.ccvs.core;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceChangeEvent;
+import org.eclipse.core.resources.IResourceChangeListener;
+import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPluginDescriptor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Plugin;
+import org.eclipse.team.core.ITeamProvider;
+import org.eclipse.team.core.TeamException;
+import org.eclipse.team.core.TeamPlugin;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.CVSProvider;
+import org.eclipse.team.internal.ccvs.core.Policy;
+import org.eclipse.team.internal.ccvs.core.util.DirtyDeltaVisitor;
+import org.eclipse.team.internal.ccvs.core.util.ProjectDescriptionManager;
+import org.eclipse.team.internal.ccvs.core.util.Util;
+
+public class CVSProviderPlugin extends Plugin {
+
+ private static CVSProviderPlugin instance;
+ /**
+ * Int used for the communications timeout on server connections (in seconds)
+ */
+ public static final int DEFAULT_TIMEOUT = 60;
+ private int communicationsTimeout = DEFAULT_TIMEOUT;
+
+ public static final String ID = "org.eclipse.team.cvs.core";
+ public static final String PT_AUTHENTICATOR = "authenticator";
+ public static final String PT_CONNECTIONMETHODS = "connectionmethods";
+
+ /**
+ * The identifier for the CVS nature
+ * (value <code>"org.eclipse.team.cvs.core.nature"</code>).
+ * The presence of this nature on a project indicates that it is
+ * CVS-capable.
+ *
+ * @see org.eclipse.core.resources.IProject#hasNature
+ */
+ public static final String NATURE_ID = ID + ".cvsnature" ;
+
+ /**
+ * Constructor for CVSProviderPlugin.
+ * @param descriptor
+ */
+ public CVSProviderPlugin(IPluginDescriptor descriptor) {
+ super(descriptor);
+ instance = this;
+ }
+
+ /**
+ * Convenience method for logging CVSExceptiuons to the plugin log
+ */
+ public static void log(TeamException e) {
+ // For now, we'll log the status. However we should do more
+ instance.getLog().log(e.getStatus());
+ }
+ public static void log(IStatus status) {
+ // For now, we'll log the status. However we should do more
+ instance.getLog().log(status);
+ }
+
+ /**
+ * Get the ICVSProvider
+ */
+ public static ICVSProvider getProvider() {
+ return CVSProvider.getInstance();
+ }
+
+ /**
+ * Get the communications timeout value in seconds
+ */
+ public int getTimeout() {
+ return communicationsTimeout;
+ }
+ /**
+ * Set the timeout value for communications to a value in seconds.
+ * The value must be greater than or equal 0. If is it 0, there is no timeout.
+ */
+ public void setTimeout(int timeout) {
+ this.communicationsTimeout = Math.max(0, timeout);
+ }
+
+ /**
+ * @see Plugin#startup()
+ */
+ public void startup() throws CoreException {
+ Policy.localize("org.eclipse.team.internal.ccvs.core.messages");
+ DirtyDeltaVisitor visitor = new DirtyDeltaVisitor();
+ visitor.register();
+ CVSProvider.initialize();
+ }
+
+ /*
+ * Add a resource change listener to the workspace in order to respond to
+ * resource deletions and moves and to ensure or project desription file is up to date.
+ */
+ private void initializeChangeListener() {
+
+ // Build a change listener for changes to thr project meta-information
+ IResourceChangeListener projectChangeListener = new IResourceChangeListener() {
+ public void resourceChanged(IResourceChangeEvent event) {
+ try {
+ IResourceDelta root = event.getDelta();
+ IResourceDelta[] projectDeltas = root.getAffectedChildren(IResourceDelta.CHANGED);
+ for (int i = 0; i < projectDeltas.length; i++) {
+ IResourceDelta delta = projectDeltas[i];
+ IResource resource = delta.getResource();
+ if (resource.getType() == IResource.PROJECT) {
+ IProject project = (IProject)resource;
+ // Get the team provider for the project and
+ ITeamProvider provider = TeamPlugin.getManager().getProvider(project);
+ if (!(provider instanceof CVSTeamProvider)) continue;
+ /* Check if the project description changed. */
+ if ((delta.getFlags() & IResourceDelta.DESCRIPTION) != 0) {
+ /* The project description changed. Write the file. */
+ ProjectDescriptionManager.writeProjectDescriptionIfNecessary((CVSTeamProvider)provider, project, Policy.monitorFor(null));
+ }
+
+ /* Check if the .vcm_meta file for the project is in the delta. */
+ IResourceDelta[] children = delta.getAffectedChildren(IResourceDelta.REMOVED);
+ for (int j = 0; j < children.length; j++) {
+ IResourceDelta childDelta = children[j];
+ IResource childResource = childDelta.getResource();
+ if (ProjectDescriptionManager.isProjectDescription(childResource)) {
+ ProjectDescriptionManager.writeProjectDescriptionIfNecessary((CVSTeamProvider)provider, project, Policy.monitorFor(null));
+ }
+ }
+ }
+ }
+ } catch (CVSException ex) {
+ Util.logError(Policy.bind("CVSProviderPlugin.cannotUpdateDescription"), ex);
+ }
+ }
+ };
+ ResourcesPlugin.getWorkspace().addResourceChangeListener(projectChangeListener, IResourceChangeEvent.POST_AUTO_BUILD);
+ }
+}
+
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSTag.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSTag.java new file mode 100644 index 000000000..c42eeb921 --- /dev/null +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSTag.java @@ -0,0 +1,45 @@ +package org.eclipse.team.ccvs.core;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+public class CVSTag {
+
+ public final static int HEAD = 0;
+ public final static int BRANCH = 1;
+ public final static int VERSION = 2;
+ public final static int DATE = 3;
+
+ public static final CVSTag DEFAULT = new CVSTag();
+
+ protected String name;
+ protected int type;
+
+ public CVSTag() {
+ this("HEAD", HEAD);
+ }
+
+ public CVSTag(String name, int type) {
+ this.name = name;
+ this.type = type;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public int getType() {
+ return type;
+ }
+
+ public int hashCode() {
+ return name.hashCode();
+ }
+
+ public int compareTo(CVSTag other) {
+ // XXX include type in comparison?
+ return getName().compareTo(other.getName());
+ }
+}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSTeamProvider.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSTeamProvider.java index d0f3258a3..79f004e06 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSTeamProvider.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSTeamProvider.java @@ -1,1086 +1,1092 @@ -package org.eclipse.team.ccvs.core; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.io.PrintStream; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Properties; -import java.util.Set; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceVisitor; -import org.eclipse.core.resources.IWorkspaceRunnable; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.QualifiedName; -import org.eclipse.core.runtime.Status; -import org.eclipse.team.core.IFileTypeRegistry; -import org.eclipse.team.core.ITeamNature; -import org.eclipse.team.core.ITeamProvider; -import org.eclipse.team.core.TeamException; -import org.eclipse.team.core.TeamPlugin; -import org.eclipse.team.core.sync.IRemoteResource; -import org.eclipse.team.core.sync.IRemoteSyncElement; -import org.eclipse.team.internal.ccvs.core.CVSDiffException; -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.CVSRemoteSyncElement; -import org.eclipse.team.internal.ccvs.core.Client; -import org.eclipse.team.internal.ccvs.core.Policy; -import org.eclipse.team.internal.ccvs.core.connection.CVSRepositoryLocation; -import org.eclipse.team.internal.ccvs.core.resources.RemoteFile; -import org.eclipse.team.internal.ccvs.core.resources.RemoteFolder; -import org.eclipse.team.internal.ccvs.core.resources.RemoteResource; -import org.eclipse.team.internal.ccvs.core.resources.api.FolderProperties; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFile; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFolder; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedResource; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedVisitor; -import org.eclipse.team.internal.ccvs.core.response.IResponseHandler; -import org.eclipse.team.internal.ccvs.core.response.custom.DiffErrorHandler; -import org.eclipse.team.internal.ccvs.core.response.custom.DiffMessageHandler; -import org.eclipse.team.internal.ccvs.core.util.Assert; -import org.eclipse.team.internal.ccvs.core.util.ProjectDescriptionManager; - -/** - * This class acts as both the ITeamNature and the ITeamProvider instances - * required by the Team core. - * - * The current stat of this class and it's plugin is EXPERIMENTAL. - * As such, it is subject to change except in it's conformance to the - * TEAM API which it implements. - * - * Questions: - * - * How should a project/reource rename/move effect the provider? - * - * Currently we always update with -P. Is this OK? - * - A way to allow customizable options would be nice - * - * Is the -l option valid for commit and does it work properly for update and commit? - * - * Do we need an IUserInteractionProvider in the CVS core - * - prompt for user info (caching could be separate) - * - get release comments - * - prompt for overwrite of unmanaged files - * - * Need a mechanism for communicating meta-information (provided by Team?) - * - * Should pass null when there are no options for a cvs command - * - * We currently write the files to disk and do a refreshLocal to - * have them appear in Eclipse. This may be changed in the future. - */ -public class CVSTeamProvider implements ITeamNature, ITeamProvider { - - // Instance variables - private IManagedFolder managedProject; - private IProject project; - private String comment = ""; - - private static PrintStream printStream; - - private static String[] DEFAULT_GLOBAL_OPTIONS = new String[] {"-q"}; - - private static final CoreException CORE_EXCEPTION = new CoreException(new Status(IStatus.OK, CVSProviderPlugin.ID, TeamException.UNABLE, "", null)); - - /** - * No-arg Constructor for IProjectNature conformance - */ - public CVSTeamProvider() { - } - - /** - * @see IProjectNature#configure() - */ - public void configure() throws CoreException { - // Do nothing - } - - /** - * @see IProjectNature#deconfigure() - */ - public void deconfigure() throws CoreException { - // unmanage() removes any traces of CVS from the project - try { - managedProject.unmanage(); - } catch (CVSException e) { - throw new CoreException(new Status(IStatus.ERROR, CVSProviderPlugin.ID, 0, Policy.bind("CVSTeamProvider.deconfigureProblem", new Object[] {project.getName()}), e)); - } - project.refreshLocal(IResource.DEPTH_INFINITE, null); - } - - /** - * @see IProjectNature#getProject() - */ - public IProject getProject() { - return project; - } - - /** - * @see IProjectNature#setProject(IProject) - */ - public void setProject(IProject project) { - this.project = project; - try { - this.managedProject = Client.getManagedFolder(project.getLocation().toFile()); - } catch (CVSException e) { - // Log any problems creating the CVS managed resource - CVSProviderPlugin.log(e); - } - } - - /** - * @see ITeamNature#getProvider() - */ - public ITeamProvider getProvider() throws TeamException { - if (managedProject == null) { - // An error must have occured when we were configured - throw new TeamException(new Status(IStatus.ERROR, CVSProviderPlugin.ID, TeamException.UNABLE, Policy.bind("CVSTeamProvider.initializationFailed", new Object[]{project.getName()}), null)); - } - return this; - } - - /** - * @see ITeamNature#configureProvider(Properties) - */ - public void configureProvider(Properties configuration) throws TeamException { - // For now, perform an import and checkout. - // NOTE: We'll need to revisit this once we start using the Team test framework - CVSProviderPlugin.getProvider().importAndCheckout(project, configuration, Policy.monitorFor(null)); - } - - /* - * Build the repository instance from the given properties. - * The supported properties are: - * - * connection The connection method to be used - * user The username for the connection - * password The password used for the connection (optional) - * host The host where the repository resides - * port The port to connect to (optional) - * root The server directory where the repository is located - */ - private static CVSRepositoryLocation buildRepository(Properties configuration) throws TeamException { - StringBuffer repository = new StringBuffer(":"); - String connection = configuration.getProperty("connection"); - if (connection == null) - repository.append("pserver"); - else - repository.append(connection); - repository.append(":"); - String user = configuration.getProperty("user"); - if (user == null) - throw new TeamException(new Status(IStatus.ERROR, CVSProviderPlugin.ID, TeamException.UNABLE, Policy.bind("CVSTeamProvider.noUser"), null)); - else - repository.append(user); - repository.append("@"); - String host = configuration.getProperty("host"); - if (host == null) - throw new TeamException(new Status(IStatus.ERROR, CVSProviderPlugin.ID, TeamException.UNABLE, Policy.bind("CVSTeamProvider.noHost"), null)); - else - repository.append(host); - String port = configuration.getProperty("port"); - if (port != null) { - repository.append("#"); - repository.append(port); - } - repository.append(":"); - String root = configuration.getProperty("root"); - if (root == null) - throw new TeamException(new Status(IStatus.ERROR, CVSProviderPlugin.ID, TeamException.UNABLE, Policy.bind("CVSTeamProvider.noRoot"), null)); - else - repository.append(root); - - CVSRepositoryLocation location = CVSRepositoryLocation.fromString(repository.toString()); - - String password = configuration.getProperty("password"); - if (password != null) { - location.setPassword(password); - } - - return location; - } - - /** - * Add the given resources to the project. - * <p> - * The sematics follow that of CVS in the sense that any folders - * being added are created remotely as a result of this operation - * while files are created remotely on the next commit. - * </p> - * <p> - * This method uses the team file type registry to determine the type - * of added files. If the extension of the file is not in the registry, - * the file is assumed to be binary. - * </p> - * <p> - * NOTE: for now we do three operations: one each for folders, text files and binary files. - * We should optimize this when time permits to either use one operations or defer server - * contact until the next commit. - * </p> - */ - public void add(IResource[] resources, int depth, IProgressMonitor progress) throws TeamException { - - // Visit the children of the resources using the depth in order to - // determine which folders, text files and binary files need to be added - final List folders = new ArrayList(resources.length); - final List textfiles = new ArrayList(resources.length); - final List binaryfiles = new ArrayList(resources.length); - final IFileTypeRegistry registry = TeamPlugin.getFileTypeRegistry(); - final TeamException[] eHolder = new TeamException[1]; - for (int i=0;i<resources.length;i++) { - - // Throw an exception if the resource is not a child of the receiver - checkIsChild(resources[i]); - - try { - // Auto-add parents if they are not already managed - IResource parent = resources[i].getParent(); - List parentFolders = new ArrayList(); - while (!isManaged(parent)) { - parentFolders.add(parent.getFullPath().removeFirstSegments(1).toString()); - parent = parent.getParent(); - } - for (int j=parentFolders.size()-1;j>=0;j--) - folders.add(parentFolders.get(j)); - - // Auto-add children - resources[i].accept(new IResourceVisitor() { - public boolean visit(IResource resource) { - try { - if (!isManaged(resource)) { - String name = resource.getFullPath().removeFirstSegments(1).toString(); - if (resource.getType() == IResource.FILE) { - String extension = resource.getFileExtension(); - if ((extension != null) && ("true".equals(registry.getValue(extension, "isAscii")))) - textfiles.add(name); - else - binaryfiles.add(name); - } else - folders.add(name); - } - } catch (TeamException e) { - // Record the exception to be thrown again later - eHolder[0] = e; - return false; - } - // Always return true and let the depth determine if children are visited - return true; - } - }, depth, false); - } catch (CoreException e) { - throw new CVSException(new Status(IStatus.ERROR, CVSProviderPlugin.ID, TeamException.UNABLE, Policy.bind("CVSTeamProvider.visitError", new Object[] {resources[i].getFullPath()}), e)); - } - } - // If an exception occured during the visit, throw it here - if (eHolder[0] != null) - throw eHolder[0]; - - // It looks like we need to add folders first, followed by files! - try { - if (!folders.isEmpty()) - Client.execute( - Client.ADD, - new String[0], - new String[0], - (String[])folders.toArray(new String[folders.size()]), - managedProject, - progress, - getPrintStream()); - if (!textfiles.isEmpty()) - Client.execute( - Client.ADD, - new String[0], - new String[0], - (String[])textfiles.toArray(new String[textfiles.size()]), - managedProject, - progress, - getPrintStream()); - if (!binaryfiles.isEmpty()) { - // Build the local options - List localOptions = new ArrayList(); - localOptions.add(Client.KB_OPTION); - // We should check if files are text or not! - Client.execute( - Client.ADD, - new String[0], - (String[])localOptions.toArray(new String[localOptions.size()]), - (String[])binaryfiles.toArray(new String[binaryfiles.size()]), - managedProject, - progress, - getPrintStream()); - } - } catch (CVSException e) { - // Refresh and throw the exception again - refreshResources(resources, depth, e, progress); - } - refreshResources(resources, depth, null, progress); - } - - /** - * Checkin any local changes using "cvs commit ...". - * - * @see ITeamProvider#checkin(IResource[], int, IProgressMonitor) - */ - public void checkin(IResource[] resources, int depth, IProgressMonitor progress) throws TeamException { - - // Build the arguments list - String[] arguments = getValidArguments(resources, depth, progress); - - // Build the local options - List localOptions = new ArrayList(); - localOptions.add(Client.MESSAGE_OPTION); - localOptions.add(comment); - // If the depth is not infinite, we want the -l option - if (depth != IResource.DEPTH_INFINITE) - localOptions.add(Client.LOCAL_OPTION); - - // Commit the resources - try { - Client.execute( - Client.COMMIT, - DEFAULT_GLOBAL_OPTIONS, - (String[])localOptions.toArray(new String[localOptions.size()]), - arguments, - managedProject, - progress, - getPrintStream()); - } catch(CVSException e) { - refreshResources(resources, depth, e, progress); - } - refreshResources(resources, depth, null, progress); - } - - /** - * Checkout the provided resources so they can be modified locally and committed. - * - * Currently, we support only the optimistic model so checkout dores nothing. - * - * @see ITeamProvider#checkout(IResource[], int, IProgressMonitor) - */ - public void checkout(IResource[] resources, int depth, IProgressMonitor progress) throws TeamException { - } - - /* - * Generate an exception if the resource is not a child of the project - */ - private void checkIsChild(IResource resource) throws CVSException { - if (!isChildResource(resource)) - throw new CVSException(new Status(IStatus.ERROR, CVSProviderPlugin.ID, TeamException.UNABLE, Policy.bind("CVSTeamProvider.invalidResource", new Object[] {resource.getFullPath().toString(), project.getName()}), null)); - } - - /** - * @see ITeamProvider#delete(IResource[], int, IProgressMonitor) - */ - public void delete(IResource[] resources, final IProgressMonitor progress) throws TeamException { - - // Why does the API state that the file must become unmanaged! - // CVS requires the file to be deleted before it can be removed! - - // Concern: I suspect that the file must be deleted but the files parent - // must exist for this to work. We may need to modify how Remove works. - - // Could implement a CVSProvider.DELETE!!! - - // Delete any files locally and record the names. - // Use a resource visitor to ensure the proper depth is obtained - final List files = new ArrayList(resources.length); - final Set parents = new HashSet(); - final TeamException[] eHolder = new TeamException[1]; - for (int i=0;i<resources.length;i++) { - checkIsChild(resources[i]); - try { - resources[i].accept(new IResourceVisitor() { - public boolean visit(IResource resource) { - try { - if (isManaged(resource)) { - String name = resource.getFullPath().removeFirstSegments(1).toString(); - if (resource.getType() == IResource.FILE) { - parents.add(resource.getParent()); - files.add(name); - ((IFile)resource).delete(false, true, progress); - // NOTE: Should we broadcast Team change events? - } - } - } catch (TeamException e) { - eHolder[0] = e; - // If there was a problem, don't visit the children - return false; - } catch (CoreException e) { - eHolder[0] = wrapException(e); - // If there was a problem, don't visit the children - return false; - } - // Always return true and let the depth determine if children are visited - return true; - } - }, IResource.DEPTH_INFINITE, false); - } catch (CoreException e) { - throw wrapException(e); - } - } - // If an exception occured during the visit, throw it here - if (eHolder[0] != null) - throw eHolder[0]; - - // Remove the files remotely - try { - Client.execute( - Client.REMOVE, - new String[0], - new String[0], - (String[])files.toArray(new String[files.size()]), - managedProject, - progress, - getPrintStream()); - } catch(CVSException e) { - refreshResources((IResource[])parents.toArray(new IResource[parents.size()]), IResource.DEPTH_INFINITE, e, progress); - } - refreshResources((IResource[])parents.toArray(new IResource[parents.size()]), IResource.DEPTH_INFINITE, null, progress); - } - - /** - * Diff the resources against the repository - */ - public void diff(IResource[] resources, int depth, IProgressMonitor progress) throws TeamException { - // Build the arguments list - String[] arguments = getValidArguments(resources, depth, progress); - - // Build the local options - List localOptions = new ArrayList(); - // Perform a context diff - localOptions.add("-c"); - // If the depth is not infinite, we want the -l option - if (depth != IResource.DEPTH_INFINITE) - localOptions.add(Client.LOCAL_OPTION); - - try { - Client.execute( - Client.DIFF, - DEFAULT_GLOBAL_OPTIONS, - (String[])localOptions.toArray(new String[localOptions.size()]), - arguments, - managedProject, - progress, - getPrintStream()); - } catch(CVSDiffException e) { - // Ignore this for now - } - } - - /** - * Diff the resources against the repository and write the - * output to the provided PrintStream in a form that is usable - * as a patch - */ - public void diff(IResource[] resources, int depth, PrintStream stream, IProgressMonitor progress) throws TeamException { - - // Build the arguments list - String[] arguments = getValidArguments(resources, depth, progress); - - // Build the local options - List localOptions = new ArrayList(); - // Perform a context diff - localOptions.add("-N"); // include diffs for added and removed files - localOptions.add("-u"); // use unified output format - // If the depth is not infinite, we want the -l option - if (depth != IResource.DEPTH_INFINITE) - localOptions.add(Client.LOCAL_OPTION); - - final List errors = new ArrayList(); - try { - Client.execute( - Client.DIFF, - Client.EMPTY_ARGS_LIST, - (String[])localOptions.toArray(new String[localOptions.size()]), - arguments, - managedProject, - progress, - stream, - null, - new IResponseHandler[] {new DiffMessageHandler(), new DiffErrorHandler(errors)}); - } catch(CVSDiffException e) { - // Ignore this for now - } catch (CVSException e) { - if (!errors.isEmpty()) { - PrintStream out = getPrintStream(); - for (int i=0;i<errors.size();i++) - out.println(errors.get(i)); - } - throw e; - } - } - /** - * Temporary method to allow fixing a resources types - */ - public void fixFileType(IResource[] resources,int depth, IProgressMonitor progress) throws TeamException { - - // Build the arguments list and record any errors. - // We need to visit children resources depending on the depth. - final TeamException[] eHolder = new TeamException[1]; final List textfiles = new ArrayList(resources.length); - final List binaryfiles = new ArrayList(resources.length); - final IFileTypeRegistry registry = TeamPlugin.getFileTypeRegistry(); - for (int i=0;i<resources.length;i++) { - checkIsChild(resources[i]); - try { - resources[i].accept(new IResourceVisitor() { - public boolean visit(IResource resource) { - try { - if ((resource.getType() == IResource.FILE) && (isManaged(resource))) { - String name = resource.getFullPath().removeFirstSegments(1).toString(); - String extension = resource.getFileExtension(); - if ((extension != null) && ("true".equals(registry.getValue(extension, "isAscii")))) - textfiles.add(name); - else - binaryfiles.add(name); - } - } catch (TeamException e) { - eHolder[0] = e; - // If there was a problem, don't visit the children - return false; - } - // Always return true and let the depth determine if children are visited - return true; - } - }, depth, false); - } catch (CoreException e) { - throw wrapException(e); - } - } - // If an exception occured during the visit, throw it here - if (eHolder[0] != null) - throw eHolder[0]; - - if (!textfiles.isEmpty()) { - List localOptions = new ArrayList(); - localOptions.add(Client.KO_OPTION); // disable keyword substitution - Client.execute( - Client.ADMIN, - new String[0], - (String[])localOptions.toArray(new String[localOptions.size()]), - (String[])textfiles.toArray(new String[textfiles.size()]), - managedProject, - progress, - getPrintStream()); - } - if (!binaryfiles.isEmpty()) { - // Build the local options - List localOptions = new ArrayList(); - localOptions.add(Client.KB_OPTION); // disable keyword substitution - Client.execute( - Client.ADMIN, - new String[0], - (String[])localOptions.toArray(new String[localOptions.size()]), - (String[])binaryfiles.toArray(new String[binaryfiles.size()]), - managedProject, - progress, - getPrintStream()); - } - - // Update the options on the local files - List localOptions = new ArrayList(); - if (depth != IResource.DEPTH_INFINITE) - // If depth = zero or 1, use -l - localOptions.add(Client.LOCAL_OPTION); - localOptions.add("-A"); - update(resources, depth, (String[])localOptions.toArray(new String[localOptions.size()]), progress); - } - - /** - * Replace the local version of the provided resources with the remote using "cvs update -C ..." - * - * @see ITeamProvider#get(IResource[], int, IProgressMonitor) - */ - public void get(IResource[] resources, int depth, IProgressMonitor progress) throws TeamException { - - // Build the arguments list - String[] arguments = getValidArguments(resources, depth, progress); - - // Build the local options - List localOptions = new ArrayList(); - localOptions.add("-C"); // Ignore any local changes - if (depth == IResource.DEPTH_INFINITE) - // if depth = infinite, look for new directories - localOptions.add(Client.DEEP_OPTION); - else - // If depth = zero or 1, use -l - localOptions.add(Client.LOCAL_OPTION); - - try { - Client.execute( - Client.UPDATE, - new String[0], - (String[])localOptions.toArray(new String[localOptions.size()]), - arguments, - managedProject, - progress, - getPrintStream()); - } catch(CVSException e) { - refreshResources(resources, depth, e, progress); - } - refreshResources(resources, depth, null, progress); - } - - /* - * Get the corresponding managed child for the given resource. - */ - private IManagedResource getChild(IResource resource) throws CVSException { - if (resource.equals(project)) - return managedProject; - return managedProject.getChild(resource.getFullPath().removeFirstSegments(1).toString()); - } - - /** - * Answer the name of the connection method for the given resource's - * project. - */ - public String getConnectionMethod(IResource resource) throws TeamException { - checkIsChild(resource); - return CVSRepositoryLocation.fromString(managedProject.getFolderInfo().getRoot()).getMethod().getName(); - } - - /** - * Get the print stream to which information from CVS commands - * is sent. - */ - private PrintStream getPrintStream() { - return CVSProviderPlugin.getProvider().getPrintStream(); - } - - /** - * Get the remote resource corresponding to the base of the local resource - */ - public ICVSRemoteResource getRemoteResource(IResource resource) throws TeamException { - checkIsChild(resource); - IManagedResource managed = getChild(resource); - if (managed.isFolder()) { - IManagedFolder folder = (IManagedFolder)managed; - return new RemoteFolder(CVSRepositoryLocation.fromString(folder.getFolderInfo().getRoot()), new Path(folder.getFolderInfo().getRepository()), folder.getFolderInfo().getTag()); - } else { - // NOTE: This may not provide a proper parent! - return new RemoteFile((RemoteFolder)getRemoteResource(resource.getParent()), managed.getName(), ((IManagedFile)managed).getFileInfo().getVersion()); - } - } - - public IRemoteSyncElement getRemoteSyncTree(IResource resource, String tag, IProgressMonitor progress) throws TeamException { - checkIsChild(resource); - IManagedResource managed = getChild(resource); - - // XXX: there must be a quicker way of determining is a folder/file has a remote (e.g. in one round trip - // at the time of this call). - ICVSRemoteResource remote; - try { - if(resource.getType()!=IResource.PROJECT) { - RemoteFolder remoteParent = (RemoteFolder)getRemoteResource(resource.getParent()); - remoteParent.getMembers(progress); - // if an exception is thrown then just ignore - remote = (ICVSRemoteResource)remoteParent.getChild(resource.getName()); - } else { - remote = (RemoteFolder)getRemoteResource(resource); - } - } catch(CVSException e) { - remote = null; - } - - IManagedFolder localParent = managed.isFolder() ? (IManagedFolder)managed : managed.getParent(); - return new CVSRemoteSyncElement(resource, null, remote, localParent); - } - - /** - * Returns an IUserInfo instance that can be used to access and set the - * user name and set the password. To have changes take place, the user must - * invoke the setUserInfo() method. - */ - public IUserInfo getUserInfo(IResource resource) throws TeamException { - checkIsChild(resource); - CVSRepositoryLocation location = CVSRepositoryLocation.fromString(managedProject.getFolderInfo().getRoot()); - location.setUserMuteable(true); - return location; - } - - /* - * Get the arguments to be passed to a commit or update - */ - private String[] getValidArguments(IResource[] resources, int depth, IProgressMonitor progress) throws CVSException { - List arguments = new ArrayList(resources.length); - for (int i=0;i<resources.length;i++) { - checkIsChild(resources[i]); - // A depth of zero is only valid for files - if ((depth != IResource.DEPTH_ZERO) || (resources[i].getType() == IResource.FILE)) { - IPath cvsPath = resources[i].getFullPath().removeFirstSegments(1); - if (cvsPath.segmentCount() == 0) - arguments.add("."); - else - arguments.add(cvsPath.toString()); - } - } - return (String[])arguments.toArray(new String[arguments.size()]); - } - - /** - * @see ITeamProvider#hasRemote(IResource) - * XXX to be removed when sync methods are removed from ITeamProvider - */ - public boolean hasRemote(IResource resource) { - try { - // This assumes that all projects associated with a provider exists remotely - // which is the case presently - if (resource.equals(project)) - return isManaged(resource); - - IManagedResource child = getChild(resource); - if (!child.showManaged()) - return false; - if (resource.getType() == IResource.FOLDER) { - // if it's managed and its a folder than it exists remotely - return true; - } else { - // NOTE: This seems rather adhoc! - return !((IManagedFile)child).getFileInfo().getVersion().equals("0"); - } - } catch (TeamException e) { - // Shouldn't have got an exception. Since we did, log it and return false - CVSProviderPlugin.log(e); - return false; - } - - } - - /** - * @see ITeamProvider#isLocallyCheckedOut(IResource) - * XXX to be removed when sync methods are removed from ITeamProvider - */ - public boolean isCheckedOut(IResource resource) { - // check to see if the resource exists and has an entry - try { - return isManaged(resource); - } catch (TeamException e) { - // Something went wrong. Log it and say the file is not checked out - CVSProviderPlugin.log(e); - return false; - } - } - - /* - * Helper to indicate if the resource is a child of the receiver's project - */ - private boolean isChildResource(IResource resource) { - return resource.getProject().getName().equals(managedProject.getName()); - } - - /** - * @see ITeamSynch#isDirty(IResource) - * XXX to be removed when sync methods are removed from ITeamProvider - */ - public boolean isDirty(IResource resource) { - try { - IManagedResource r = getChild(resource); - return r.showDirty(); - } catch (CVSException e) { - Assert.isTrue(false); - return true; - } - } - - /** - * Return whether the given resource is managed. - * - * From a CVS standpoint, this means that we have a CVS entry - * for the resource and that uodates and commits may effect the - * resource or its children. - */ - public boolean isManaged(IResource resource) throws TeamException { - - if (resource.equals(project)) - return true; - - // Ensure that the resource is a child of our project - if (!isChildResource(resource)) - // Is returning false enough or should we throw an exception - return false; - - // Get the IManagedResource corresponding to the resource and check if its managed - return getChild(resource).showManaged(); - } - - /** - * @see ITeamProvider#move(IResource, IPath, IProgressMonitor) - */ - public void moved(IPath source, IResource resource, IProgressMonitor progress) - throws TeamException { - - // this translates to a delete and an add - - // How is this managed? Do we do the move or is that done after? - // It becomes complicated if the local and remote operations - // are independant as this is not the way CVS works! - - // Could implement a CVSProvider.MOVE!!! - - Client.execute( - Client.REMOVE, - new String[0], - new String[0], - new String[] {source.removeFirstSegments(1).toString()}, - managedProject, - progress, - getPrintStream()); - Client.execute( - Client.ADD, - new String[0], - new String[0], // We'll need to copy options from old entry - new String[] {resource.getFullPath().removeFirstSegments(1).toString()}, - managedProject, - progress, - getPrintStream()); - } - - /** - * Set the comment to be used on the next checkin - */ - public void setComment(String comment) { - this.comment = comment; - } - - /** - * Set the connection method for the given resource's - * project. If the conection method name is invalid (i.e. - * no corresponding registered connection method), false is returned. - */ - public boolean setConnectionInfo(IResource resource, String methodName, IUserInfo userInfo) throws TeamException { - checkIsChild(resource); - if (!CVSRepositoryLocation.validateConnectionMethod(methodName)) - return false; - CVSRepositoryLocation location; - try { - location = ((CVSRepositoryLocation)userInfo); - } catch (ClassCastException e) { - throw new TeamException(new Status(IStatus.ERROR, CVSProviderPlugin.ID, TeamException.UNABLE, Policy.bind("CVSTeamProvider.invalidUserInfo"), null)); - } - location.setUserMuteable(false); - location.updateCache(); - location.setMethod(methodName); - final String root = location.getLocation(); - managedProject.accept(new IManagedVisitor() { - public void visitFile(IManagedFile file) throws CVSException {}; - public void visitFolder(IManagedFolder folder) throws CVSException { - FolderProperties info = folder.getFolderInfo(); - info.setRoot(root); - folder.setFolderInfo(info); - folder.acceptChildren(this); - }; - }); - return true; - } - - /** - * Sets the userinfo (username and password) for the resource's project. - */ - public void setUserInfo(IResource resource, IUserInfo userinfo) throws TeamException { - checkIsChild(resource); - try { - ((CVSRepositoryLocation)userinfo).updateCache(); - } catch (ClassCastException e) { - throw new TeamException(new Status(IStatus.ERROR, CVSProviderPlugin.ID, TeamException.UNABLE, Policy.bind("CVSTeamProvider.invalidUserInfo"), null)); - } - } - - /** - * @see ITeamProvider#refreshState(IResource[], int, IProgressMonitor) - */ - public void refreshState( - IResource[] resources, - int depth, - IProgressMonitor progress) - throws TeamException { - - // How does this translate to CVS? - // NIK: maybe an simple update ? - } - - /* - * Refresh the affected resources after a CVSException occured. - * Initially we'll ignore any CoreException and throw the CVSException - * after the refresh - */ - private void refreshResources(IResource[] resources, int depth, CVSException e, IProgressMonitor progress) throws CVSException { - CVSException newException = e; - try { - refreshResources(resources, depth, progress); - } catch (CoreException coreException) { - // Only use the new exception if there was no old one - if (newException == null) - newException = new CVSException(new Status(IStatus.ERROR, CVSProviderPlugin.ID, TeamException.UNABLE, Policy.bind("CVSTeamProvider.refreshError", new Object[] {project.getFullPath().toString()}), coreException)); - } - if (newException != null) - throw newException; - } - private IResource[] allChildrenOf(IResource[] resources, int depth, IProgressMonitor progress) throws CoreException { - final List allResources = new ArrayList(); - for (int i=0;i<resources.length;i++) { - resources[i].accept(new IResourceVisitor() { - public boolean visit(IResource resource) { - allResources.add(resource); - return true; - } - }, depth, false); - } - return (IResource[])allResources.toArray(new IResource[allResources.size()]); - } - private void refreshResources(IResource[] resources, int depth, IProgressMonitor progress) throws CoreException { - // NOTE: We may not catch all resources changes in this way - for (int i = 0; i < resources.length; i++) { - IResource r = resources[i]; - r.refreshLocal(depth, progress); - } - // NOTE: We need to refresh based on the depth - // We should try to be smart by getting the results from the command - TeamPlugin.getManager().broadcastResourceStateChanges(resources); - } - - /** - * Tag the resources in the CVS repository with the given tag. - */ - public void tag(IResource[] resources, int depth, String tag, boolean isBranch, IProgressMonitor progress) throws TeamException { - - // Build the arguments list - String[] arguments = getValidArguments(resources, depth, progress); - - // Build the local options - List localOptions = new ArrayList(); - // If the depth is not infinite, we want the -l option - if (depth != IResource.DEPTH_INFINITE) - localOptions.add(Client.LOCAL_OPTION); - if (isBranch) - localOptions.add(Client.BRANCH_OPTION); - - // The tag name is supposed to be the first argument - ArrayList args = new ArrayList(); - args.add(tag); - args.addAll(Arrays.asList(arguments)); - arguments = (String[])args.toArray(new String[args.size()]); - - Client.execute( - Client.TAG, - new String[] {}, - (String[])localOptions.toArray(new String[localOptions.size()]), - arguments, - managedProject, - progress, - getPrintStream()); - } - - /** - * Currently, we support only the optimistic model so uncheckout dores nothing. - * - * @see ITeamProvider#uncheckout(IResource[], int, IProgressMonitor) - */ - public void uncheckout(IResource[] resources, int depth, IProgressMonitor progress) throws TeamException { - } - - /** - * Generally usefull update - */ - public void update(IResource[] resources, int depth, IProgressMonitor progress) throws TeamException { - // Build the local options - List localOptions = new ArrayList(); - if (depth == IResource.DEPTH_INFINITE) { - // if depth = infinite, look for new directories - localOptions.add(Client.DEEP_OPTION); - // For now, prune empty directories - // This must be done by the client! (not the server) - localOptions.add(Client.PRUNE_OPTION); - } - else - // If depth = zero or 1, use -l - localOptions.add(Client.LOCAL_OPTION); - update(resources, depth, (String[])localOptions.toArray(new String[localOptions.size()]), progress); - - } - /* - * CVS specific update - */ - private void update(IResource[] resources, int depth, String[] localOptions, IProgressMonitor progress) throws TeamException { - - // Build the arguments list - String[] arguments = getValidArguments(resources, depth, progress); - - try { - Client.execute( - Client.UPDATE, - DEFAULT_GLOBAL_OPTIONS, - localOptions, - arguments, - managedProject, - progress, - getPrintStream()); - } catch(CVSException e) { - refreshResources(resources, depth, e, progress); - } - refreshResources(resources, depth, null, progress); - } - - private static TeamException wrapException(CoreException e) { - return new TeamException(statusFor(e)); - } - - public static TeamException wrapException(CVSException e, List errors) { - // NOTE: Need to find out how to pass MultiStatus. Is it up to me to subclass? - return e; - } - - private static IStatus statusFor(CoreException e) { - // We should be taking out any status from the CVSException - // and creating an array of IStatus! - return new Status(IStatus.ERROR, CVSProviderPlugin.ID, TeamException.UNABLE, getMessageFor(e), e); - } - - public static String getMessageFor(Exception e) { - String message = Policy.bind(e.getClass().getName(), new Object[] {e.getMessage()}); - if (message.equals(e.getClass().getName())) - message = Policy.bind("CVSTeamProvider.exception", new Object[] {e.toString()}); - return message; - } - - /** - * Cause a snapshot (this saves the sync info to disk) - */ - static void snapshot(IProgressMonitor monitor) throws CoreException { - monitor = Policy.monitorFor(monitor); - monitor.subTask(Policy.bind("CVSTeamProvider.snapshot")); - ResourcesPlugin.getWorkspace().save(false, monitor); - } - /* - * @see ITeamProvider#isOutOfDate(IResource) - * XXX to be removed when sync methods are removed from ITeamProvider - */ - public boolean isOutOfDate(IResource resource) { - return false; - } - - /* - * @see IFileModificationValidator#validateEdit(IFile[], Object) - */ - public IStatus validateEdit(IFile[] files, Object context) { - return new Status(Status.OK, TeamPlugin.ID, Status.OK, "OK", null); - } - /* - * @see IFileModificationValidator#validateSave(IFile) - */ - public IStatus validateSave(IFile file) { - return new Status(Status.OK, TeamPlugin.ID, Status.OK, "OK", null); - } -} - +package org.eclipse.team.ccvs.core;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.io.PrintStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceVisitor;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.team.core.IFileTypeRegistry;
+import org.eclipse.team.core.ITeamNature;
+import org.eclipse.team.core.ITeamProvider;
+import org.eclipse.team.core.TeamException;
+import org.eclipse.team.core.TeamPlugin;
+import org.eclipse.team.core.sync.IRemoteSyncElement;
+import org.eclipse.team.internal.ccvs.core.CVSDiffException;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.CVSStatus;
+import org.eclipse.team.internal.ccvs.core.Client;
+import org.eclipse.team.internal.ccvs.core.Policy;
+import org.eclipse.team.internal.ccvs.core.connection.CVSRepositoryLocation;
+import org.eclipse.team.internal.ccvs.core.resources.CVSRemoteSyncElement;
+import org.eclipse.team.internal.ccvs.core.resources.FolderSyncInfo;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFile;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFolder;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSResource;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSResourceVisitor;
+import org.eclipse.team.internal.ccvs.core.resources.RemoteFile;
+import org.eclipse.team.internal.ccvs.core.resources.RemoteFolder;
+import org.eclipse.team.internal.ccvs.core.resources.ResourceSyncInfo;
+import org.eclipse.team.internal.ccvs.core.response.IResponseHandler;
+import org.eclipse.team.internal.ccvs.core.response.custom.DiffErrorHandler;
+import org.eclipse.team.internal.ccvs.core.response.custom.DiffMessageHandler;
+import org.eclipse.team.internal.ccvs.core.util.Assert;
+import org.eclipse.team.internal.ccvs.core.util.RemoteFolderTreeBuilder;
+
+/**
+ * This class acts as both the ITeamNature and the ITeamProvider instances
+ * required by the Team core.
+ *
+ * The current stat of this class and it's plugin is EXPERIMENTAL.
+ * As such, it is subject to change except in it's conformance to the
+ * TEAM API which it implements.
+ *
+ * Questions:
+ *
+ * How should a project/reource rename/move effect the provider?
+ *
+ * Currently we always update with -P. Is this OK?
+ * - A way to allow customizable options would be nice
+ *
+ * Is the -l option valid for commit and does it work properly for update and commit?
+ *
+ * Do we need an IUserInteractionProvider in the CVS core
+ * - prompt for user info (caching could be separate)
+ * - get release comments
+ * - prompt for overwrite of unmanaged files
+ *
+ * Need a mechanism for communicating meta-information (provided by Team?)
+ *
+ * Should pass null when there are no options for a cvs command
+ *
+ * We currently write the files to disk and do a refreshLocal to
+ * have them appear in Eclipse. This may be changed in the future.
+ */
+public class CVSTeamProvider implements ITeamNature, ITeamProvider {
+
+ // Instance variables
+ private ICVSFolder managedProject;
+ private IProject project;
+ private String comment = "";
+
+ private static PrintStream printStream;
+
+ private static String[] DEFAULT_GLOBAL_OPTIONS = new String[] {"-q"};
+
+ private static final CoreException CORE_EXCEPTION = new CoreException(new Status(IStatus.OK, CVSProviderPlugin.ID, TeamException.UNABLE, "", null));
+
+ /**
+ * No-arg Constructor for IProjectNature conformance
+ */
+ public CVSTeamProvider() {
+ }
+
+ /**
+ * @see IProjectNature#configure()
+ */
+ public void configure() throws CoreException {
+ // Do nothing
+ }
+
+ /**
+ * @see IProjectNature#deconfigure()
+ */
+ public void deconfigure() throws CoreException {
+ // unmanage() removes any traces of CVS from the project
+ try {
+ managedProject.unmanage();
+ } catch (CVSException e) {
+ throw new CoreException(new Status(IStatus.ERROR, CVSProviderPlugin.ID, 0, Policy.bind("CVSTeamProvider.deconfigureProblem", new Object[] {project.getName()}), e));
+ }
+ project.refreshLocal(IResource.DEPTH_INFINITE, null);
+ }
+
+ /**
+ * @see IProjectNature#getProject()
+ */
+ public IProject getProject() {
+ return project;
+ }
+
+ /**
+ * @see IProjectNature#setProject(IProject)
+ */
+ public void setProject(IProject project) {
+ this.project = project;
+ try {
+ this.managedProject = Client.getManagedFolder(project.getLocation().toFile());
+ } catch (CVSException e) {
+ // Log any problems creating the CVS managed resource
+ CVSProviderPlugin.log(e);
+ }
+ }
+
+ /**
+ * @see ITeamNature#getProvider()
+ */
+ public ITeamProvider getProvider() throws TeamException {
+ if (managedProject == null) {
+ // An error must have occured when we were configured
+ throw new TeamException(new Status(IStatus.ERROR, CVSProviderPlugin.ID, TeamException.UNABLE, Policy.bind("CVSTeamProvider.initializationFailed", new Object[]{project.getName()}), null));
+ }
+ return this;
+ }
+
+ /**
+ * @see ITeamNature#configureProvider(Properties)
+ */
+ public void configureProvider(Properties configuration) throws TeamException {
+ // For now, perform an import and checkout.
+ // NOTE: We'll need to revisit this once we start using the Team test framework
+ CVSProviderPlugin.getProvider().importAndCheckout(project, configuration, Policy.monitorFor(null));
+ }
+
+ /*
+ * Build the repository instance from the given properties.
+ * The supported properties are:
+ *
+ * connection The connection method to be used
+ * user The username for the connection
+ * password The password used for the connection (optional)
+ * host The host where the repository resides
+ * port The port to connect to (optional)
+ * root The server directory where the repository is located
+ */
+ private static CVSRepositoryLocation buildRepository(Properties configuration) throws TeamException {
+ StringBuffer repository = new StringBuffer(":");
+ String connection = configuration.getProperty("connection");
+ if (connection == null)
+ repository.append("pserver");
+ else
+ repository.append(connection);
+ repository.append(":");
+ String user = configuration.getProperty("user");
+ if (user == null)
+ throw new TeamException(new Status(IStatus.ERROR, CVSProviderPlugin.ID, TeamException.UNABLE, Policy.bind("CVSTeamProvider.noUser"), null));
+ else
+ repository.append(user);
+ repository.append("@");
+ String host = configuration.getProperty("host");
+ if (host == null)
+ throw new TeamException(new Status(IStatus.ERROR, CVSProviderPlugin.ID, TeamException.UNABLE, Policy.bind("CVSTeamProvider.noHost"), null));
+ else
+ repository.append(host);
+ String port = configuration.getProperty("port");
+ if (port != null) {
+ repository.append("#");
+ repository.append(port);
+ }
+ repository.append(":");
+ String root = configuration.getProperty("root");
+ if (root == null)
+ throw new TeamException(new Status(IStatus.ERROR, CVSProviderPlugin.ID, TeamException.UNABLE, Policy.bind("CVSTeamProvider.noRoot"), null));
+ else
+ repository.append(root);
+
+ CVSRepositoryLocation location = CVSRepositoryLocation.fromString(repository.toString());
+
+ String password = configuration.getProperty("password");
+ if (password != null) {
+ location.setPassword(password);
+ }
+
+ return location;
+ }
+
+ /**
+ * Add the given resources to the project.
+ * <p>
+ * The sematics follow that of CVS in the sense that any folders
+ * being added are created remotely as a result of this operation
+ * while files are created remotely on the next commit.
+ * </p>
+ * <p>
+ * This method uses the team file type registry to determine the type
+ * of added files. If the extension of the file is not in the registry,
+ * the file is assumed to be binary.
+ * </p>
+ * <p>
+ * NOTE: for now we do three operations: one each for folders, text files and binary files.
+ * We should optimize this when time permits to either use one operations or defer server
+ * contact until the next commit.
+ * </p>
+ */
+ public void add(IResource[] resources, int depth, IProgressMonitor progress) throws TeamException {
+
+ // Visit the children of the resources using the depth in order to
+ // determine which folders, text files and binary files need to be added
+ final Set folders = new HashSet(resources.length);
+ final List textfiles = new ArrayList(resources.length);
+ final List binaryfiles = new ArrayList(resources.length);
+ final IFileTypeRegistry registry = TeamPlugin.getFileTypeRegistry();
+ final TeamException[] eHolder = new TeamException[1];
+ for (int i=0;i<resources.length;i++) {
+
+ // Throw an exception if the resource is not a child of the receiver
+ checkIsChild(resources[i]);
+
+ try {
+ // Auto-add parents if they are not already managed
+ IResource parent = resources[i].getParent();
+ List parentFolders = new ArrayList();
+ while (!isManaged(parent)) {
+ parentFolders.add(parent.getFullPath().removeFirstSegments(1).toString());
+ parent = parent.getParent();
+ }
+ for (int j=parentFolders.size()-1;j>=0;j--)
+ folders.add(parentFolders.get(j));
+
+ // Auto-add children
+ resources[i].accept(new IResourceVisitor() {
+ public boolean visit(IResource resource) {
+ try {
+ if (!isManaged(resource)) {
+ String name = resource.getFullPath().removeFirstSegments(1).toString();
+ if (resource.getType() == IResource.FILE) {
+ String extension = resource.getFileExtension();
+ if ((extension != null) && ("true".equals(registry.getValue(extension, "isAscii"))))
+ textfiles.add(name);
+ else
+ binaryfiles.add(name);
+ } else
+ folders.add(name);
+ }
+ } catch (TeamException e) {
+ // Record the exception to be thrown again later
+ eHolder[0] = e;
+ return false;
+ }
+ // Always return true and let the depth determine if children are visited
+ return true;
+ }
+ }, depth, false);
+ } catch (CoreException e) {
+ throw new CVSException(new Status(IStatus.ERROR, CVSProviderPlugin.ID, TeamException.UNABLE, Policy.bind("CVSTeamProvider.visitError", new Object[] {resources[i].getFullPath()}), e));
+ }
+ }
+ // If an exception occured during the visit, throw it here
+ if (eHolder[0] != null)
+ throw eHolder[0];
+
+ // It looks like we need to add folders first, followed by files!
+ try {
+ if (!folders.isEmpty())
+ Client.execute(
+ Client.ADD,
+ new String[0],
+ new String[0],
+ (String[])folders.toArray(new String[folders.size()]),
+ managedProject,
+ progress,
+ getPrintStream());
+ if (!textfiles.isEmpty())
+ Client.execute(
+ Client.ADD,
+ new String[0],
+ new String[0],
+ (String[])textfiles.toArray(new String[textfiles.size()]),
+ managedProject,
+ progress,
+ getPrintStream());
+ if (!binaryfiles.isEmpty()) {
+ // Build the local options
+ List localOptions = new ArrayList();
+ localOptions.add(Client.KB_OPTION);
+ // We should check if files are text or not!
+ Client.execute(
+ Client.ADD,
+ new String[0],
+ (String[])localOptions.toArray(new String[localOptions.size()]),
+ (String[])binaryfiles.toArray(new String[binaryfiles.size()]),
+ managedProject,
+ progress,
+ getPrintStream());
+ }
+ } catch (CVSException e) {
+ // Refresh and throw the exception again
+ refreshResources(resources, depth, e, progress);
+ }
+ refreshResources(resources, depth, null, progress);
+ }
+
+ /**
+ * Checkin any local changes using "cvs commit ...".
+ *
+ * @see ITeamProvider#checkin(IResource[], int, IProgressMonitor)
+ */
+ public void checkin(IResource[] resources, int depth, IProgressMonitor progress) throws TeamException {
+
+ // Build the arguments list
+ String[] arguments = getValidArguments(resources, depth, progress);
+
+ // Build the local options
+ List localOptions = new ArrayList();
+ localOptions.add(Client.MESSAGE_OPTION);
+ localOptions.add(comment);
+ // If the depth is not infinite, we want the -l option
+ if (depth != IResource.DEPTH_INFINITE)
+ localOptions.add(Client.LOCAL_OPTION);
+
+ // Commit the resources
+ try {
+ Client.execute(
+ Client.COMMIT,
+ DEFAULT_GLOBAL_OPTIONS,
+ (String[])localOptions.toArray(new String[localOptions.size()]),
+ arguments,
+ managedProject,
+ progress,
+ getPrintStream());
+ } catch(CVSException e) {
+ refreshResources(resources, depth, e, progress);
+ }
+ refreshResources(resources, depth, null, progress);
+ }
+
+ /**
+ * Checkout the provided resources so they can be modified locally and committed.
+ *
+ * Currently, we support only the optimistic model so checkout dores nothing.
+ *
+ * @see ITeamProvider#checkout(IResource[], int, IProgressMonitor)
+ */
+ public void checkout(IResource[] resources, int depth, IProgressMonitor progress) throws TeamException {
+ }
+
+ /*
+ * Generate an exception if the resource is not a child of the project
+ */
+ private void checkIsChild(IResource resource) throws CVSException {
+ if (!isChildResource(resource))
+ throw new CVSException(new Status(IStatus.ERROR, CVSProviderPlugin.ID, TeamException.UNABLE, Policy.bind("CVSTeamProvider.invalidResource", new Object[] {resource.getFullPath().toString(), project.getName()}), null));
+ }
+
+ /**
+ * @see ITeamProvider#delete(IResource[], int, IProgressMonitor)
+ */
+ public void delete(IResource[] resources, final IProgressMonitor progress) throws TeamException {
+
+ // Why does the API state that the file must become unmanaged!
+ // CVS requires the file to be deleted before it can be removed!
+
+ // Concern: I suspect that the file must be deleted but the files parent
+ // must exist for this to work. We may need to modify how Remove works.
+
+ // Could implement a CVSProvider.DELETE!!!
+
+ // Delete any files locally and record the names.
+ // Use a resource visitor to ensure the proper depth is obtained
+ final List files = new ArrayList(resources.length);
+ final Set parents = new HashSet();
+ final TeamException[] eHolder = new TeamException[1];
+ for (int i=0;i<resources.length;i++) {
+ checkIsChild(resources[i]);
+ try {
+ resources[i].accept(new IResourceVisitor() {
+ public boolean visit(IResource resource) {
+ try {
+ if (isManaged(resource)) {
+ String name = resource.getFullPath().removeFirstSegments(1).toString();
+ if (resource.getType() == IResource.FILE) {
+ parents.add(resource.getParent());
+ files.add(name);
+ ((IFile)resource).delete(false, true, progress);
+ // NOTE: Should we broadcast Team change events?
+ }
+ }
+ } catch (TeamException e) {
+ eHolder[0] = e;
+ // If there was a problem, don't visit the children
+ return false;
+ } catch (CoreException e) {
+ eHolder[0] = wrapException(e);
+ // If there was a problem, don't visit the children
+ return false;
+ }
+ // Always return true and let the depth determine if children are visited
+ return true;
+ }
+ }, IResource.DEPTH_INFINITE, false);
+ } catch (CoreException e) {
+ throw wrapException(e);
+ }
+ }
+ // If an exception occured during the visit, throw it here
+ if (eHolder[0] != null)
+ throw eHolder[0];
+
+ // Remove the files remotely
+ try {
+ Client.execute(
+ Client.REMOVE,
+ new String[0],
+ new String[0],
+ (String[])files.toArray(new String[files.size()]),
+ managedProject,
+ progress,
+ getPrintStream());
+ } catch(CVSException e) {
+ refreshResources((IResource[])parents.toArray(new IResource[parents.size()]), IResource.DEPTH_INFINITE, e, progress);
+ }
+ refreshResources((IResource[])parents.toArray(new IResource[parents.size()]), IResource.DEPTH_INFINITE, null, progress);
+ }
+
+ /**
+ * Diff the resources against the repository
+ */
+ public void diff(IResource[] resources, int depth, IProgressMonitor progress) throws TeamException {
+ // Build the arguments list
+ String[] arguments = getValidArguments(resources, depth, progress);
+
+ // Build the local options
+ List localOptions = new ArrayList();
+ // Perform a context diff
+ localOptions.add("-c");
+ // If the depth is not infinite, we want the -l option
+ if (depth != IResource.DEPTH_INFINITE)
+ localOptions.add(Client.LOCAL_OPTION);
+
+ try {
+ Client.execute(
+ Client.DIFF,
+ DEFAULT_GLOBAL_OPTIONS,
+ (String[])localOptions.toArray(new String[localOptions.size()]),
+ arguments,
+ managedProject,
+ progress,
+ getPrintStream());
+ } catch(CVSDiffException e) {
+ // Ignore this for now
+ }
+ }
+
+ /**
+ * Diff the resources against the repository and write the
+ * output to the provided PrintStream in a form that is usable
+ * as a patch
+ */
+ public void diff(IResource[] resources, int depth, PrintStream stream, IProgressMonitor progress) throws TeamException {
+
+ // Build the arguments list
+ String[] arguments = getValidArguments(resources, depth, progress);
+
+ // Build the local options
+ List localOptions = new ArrayList();
+ // Perform a context diff
+ localOptions.add("-N"); // include diffs for added and removed files
+ localOptions.add("-u"); // use unified output format
+ // If the depth is not infinite, we want the -l option
+ if (depth != IResource.DEPTH_INFINITE)
+ localOptions.add(Client.LOCAL_OPTION);
+
+ final List errors = new ArrayList();
+ try {
+ Client.execute(
+ Client.DIFF,
+ Client.EMPTY_ARGS_LIST,
+ (String[])localOptions.toArray(new String[localOptions.size()]),
+ arguments,
+ managedProject,
+ progress,
+ stream,
+ null,
+ new IResponseHandler[] {new DiffMessageHandler(), new DiffErrorHandler(errors)});
+ } catch(CVSDiffException e) {
+ // Ignore this for now
+ } catch (CVSException e) {
+ if (!errors.isEmpty()) {
+ PrintStream out = getPrintStream();
+ for (int i=0;i<errors.size();i++)
+ out.println(errors.get(i));
+ }
+ throw e;
+ }
+ }
+ /**
+ * Temporary method to allow fixing a resources types
+ */
+ public void fixFileType(IResource[] resources,int depth, IProgressMonitor progress) throws TeamException {
+
+ // Build the arguments list and record any errors.
+ // We need to visit children resources depending on the depth.
+ final TeamException[] eHolder = new TeamException[1]; final List textfiles = new ArrayList(resources.length);
+ final List binaryfiles = new ArrayList(resources.length);
+ final IFileTypeRegistry registry = TeamPlugin.getFileTypeRegistry();
+ for (int i=0;i<resources.length;i++) {
+ checkIsChild(resources[i]);
+ try {
+ resources[i].accept(new IResourceVisitor() {
+ public boolean visit(IResource resource) {
+ try {
+ if ((resource.getType() == IResource.FILE) && (isManaged(resource))) {
+ String name = resource.getFullPath().removeFirstSegments(1).toString();
+ String extension = resource.getFileExtension();
+ if ((extension != null) && ("true".equals(registry.getValue(extension, "isAscii"))))
+ textfiles.add(name);
+ else
+ binaryfiles.add(name);
+ }
+ } catch (TeamException e) {
+ eHolder[0] = e;
+ // If there was a problem, don't visit the children
+ return false;
+ }
+ // Always return true and let the depth determine if children are visited
+ return true;
+ }
+ }, depth, false);
+ } catch (CoreException e) {
+ throw wrapException(e);
+ }
+ }
+ // If an exception occured during the visit, throw it here
+ if (eHolder[0] != null)
+ throw eHolder[0];
+
+ if (!textfiles.isEmpty()) {
+ List localOptions = new ArrayList();
+ localOptions.add(Client.KO_OPTION); // disable keyword substitution
+ Client.execute(
+ Client.ADMIN,
+ new String[0],
+ (String[])localOptions.toArray(new String[localOptions.size()]),
+ (String[])textfiles.toArray(new String[textfiles.size()]),
+ managedProject,
+ progress,
+ getPrintStream());
+ }
+ if (!binaryfiles.isEmpty()) {
+ // Build the local options
+ List localOptions = new ArrayList();
+ localOptions.add(Client.KB_OPTION); // disable keyword substitution
+ Client.execute(
+ Client.ADMIN,
+ new String[0],
+ (String[])localOptions.toArray(new String[localOptions.size()]),
+ (String[])binaryfiles.toArray(new String[binaryfiles.size()]),
+ managedProject,
+ progress,
+ getPrintStream());
+ }
+
+ // Update the options on the local files
+ List localOptions = new ArrayList();
+ if (depth != IResource.DEPTH_INFINITE)
+ // If depth = zero or 1, use -l
+ localOptions.add(Client.LOCAL_OPTION);
+ localOptions.add("-A");
+ update(resources, depth, (String[])localOptions.toArray(new String[localOptions.size()]), progress);
+ }
+
+ /**
+ * Replace the local version of the provided resources with the remote using "cvs update -C ..."
+ *
+ * @see ITeamProvider#get(IResource[], int, IProgressMonitor)
+ */
+ public void get(IResource[] resources, int depth, IProgressMonitor progress) throws TeamException {
+
+ // Build the arguments list
+ String[] arguments = getValidArguments(resources, depth, progress);
+
+ // Build the local options
+ List localOptions = new ArrayList();
+ localOptions.add("-C"); // Ignore any local changes
+ if (depth == IResource.DEPTH_INFINITE)
+ // if depth = infinite, look for new directories
+ localOptions.add(Client.DEEP_OPTION);
+ else
+ // If depth = zero or 1, use -l
+ localOptions.add(Client.LOCAL_OPTION);
+
+ try {
+ Client.execute(
+ Client.UPDATE,
+ new String[0],
+ (String[])localOptions.toArray(new String[localOptions.size()]),
+ arguments,
+ managedProject,
+ progress,
+ getPrintStream());
+ } catch(CVSException e) {
+ refreshResources(resources, depth, e, progress);
+ }
+ refreshResources(resources, depth, null, progress);
+ }
+
+ /*
+ * Get the corresponding managed child for the given resource.
+ */
+ private ICVSResource getChild(IResource resource) throws CVSException {
+ if (resource.equals(project))
+ return managedProject;
+ return managedProject.getChild(resource.getFullPath().removeFirstSegments(1).toString());
+ }
+
+ /**
+ * Answer the name of the connection method for the given resource's
+ * project.
+ */
+ public String getConnectionMethod(IResource resource) throws TeamException {
+ checkIsChild(resource);
+ return CVSRepositoryLocation.fromString(managedProject.getFolderSyncInfo().getRoot()).getMethod().getName();
+ }
+
+ /**
+ * Get the print stream to which information from CVS commands
+ * is sent.
+ */
+ private PrintStream getPrintStream() {
+ return CVSProviderPlugin.getProvider().getPrintStream();
+ }
+
+ /**
+ * Get the remote resource corresponding to the base of the local resource
+ */
+ public ICVSRemoteResource getRemoteResource(IResource resource) throws TeamException {
+ checkIsChild(resource);
+ ICVSResource managed = getChild(resource);
+ if (managed.isFolder()) {
+ ICVSFolder folder = (ICVSFolder)managed;
+ FolderSyncInfo syncInfo = folder.getFolderSyncInfo();
+ return new RemoteFolder(null, CVSRepositoryLocation.fromString(syncInfo.getRoot()), new Path(syncInfo.getRepository()), syncInfo.getTag());
+ } else {
+ // NOTE: This may not provide a proper parent!
+ return new RemoteFile((RemoteFolder)getRemoteResource(resource.getParent()), managed.getName(), ((ICVSFile)managed).getSyncInfo().getRevision(), new CVSTag());
+ }
+ }
+
+ public IRemoteSyncElement getRemoteSyncTree(IResource resource, CVSTag tag, IProgressMonitor progress) throws TeamException {
+ checkIsChild(resource);
+ ICVSResource managed = getChild(resource);
+
+ ICVSRemoteResource remote;
+
+ if(resource.getType()!=IResource.FILE) {
+ remote = getRemoteResource(resource);
+ try {
+ ICVSRepositoryLocation location = remote.getRepository();
+ remote = RemoteFolderTreeBuilder.buildRemoteTree((CVSRepositoryLocation)location, (ICVSFolder)managed, tag, progress);
+ } catch(CVSException e) {
+ throw new TeamException(new CVSStatus(IStatus.ERROR, 0, resource.getProjectRelativePath(), "Error retreiving remote resource tree", e));
+ }
+
+ } else {
+ // XXX
+ remote = getRemoteResource(resource);
+ if(!remote.exists()) {
+ remote = null;
+ }
+ }
+ return new CVSRemoteSyncElement(resource, null, remote);
+ }
+
+ /**
+ * Returns an IUserInfo instance that can be used to access and set the
+ * user name and set the password. To have changes take place, the user must
+ * invoke the setUserInfo() method.
+ */
+ public IUserInfo getUserInfo(IResource resource) throws TeamException {
+ checkIsChild(resource);
+ CVSRepositoryLocation location = CVSRepositoryLocation.fromString(managedProject.getFolderSyncInfo().getRoot());
+ location.setUserMuteable(true);
+ return location;
+ }
+
+ /*
+ * Get the arguments to be passed to a commit or update
+ */
+ private String[] getValidArguments(IResource[] resources, int depth, IProgressMonitor progress) throws CVSException {
+ List arguments = new ArrayList(resources.length);
+ for (int i=0;i<resources.length;i++) {
+ checkIsChild(resources[i]);
+ // A depth of zero is only valid for files
+ if ((depth != IResource.DEPTH_ZERO) || (resources[i].getType() == IResource.FILE)) {
+ IPath cvsPath = resources[i].getFullPath().removeFirstSegments(1);
+ if (cvsPath.segmentCount() == 0) {
+ arguments.add(".");
+ }
+ else
+ arguments.add(cvsPath.toString());
+ }
+ }
+ return (String[])arguments.toArray(new String[arguments.size()]);
+ }
+
+ /**
+ * @see ITeamProvider#hasRemote(IResource)
+ * XXX to be removed when sync methods are removed from ITeamProvider
+ */
+ public boolean hasRemote(IResource resource) {
+ try {
+ // This assumes that all projects associated with a provider exists remotely
+ // which is the case presently
+ if (resource.equals(project))
+ return isManaged(resource);
+
+ ICVSResource child = getChild(resource);
+ if(child.isManaged()) {
+ if(child.isFolder()) {
+ return true;
+ } else {
+ ResourceSyncInfo info = child.getSyncInfo();
+ if(info.getRevision().equals("0")) {
+ return false;
+ } else {
+ return true;
+ }
+ }
+ }
+ return false;
+ } catch (TeamException e) {
+ // Shouldn't have got an exception. Since we did, log it and return false
+ CVSProviderPlugin.log(e);
+ return false;
+ }
+
+ }
+
+ /**
+ * @see ITeamProvider#isLocallyCheckedOut(IResource)
+ * XXX to be removed when sync methods are removed from ITeamProvider
+ */
+ public boolean isCheckedOut(IResource resource) {
+ // check to see if the resource exists and has an entry
+ try {
+ return isManaged(resource);
+ } catch (TeamException e) {
+ // Something went wrong. Log it and say the file is not checked out
+ CVSProviderPlugin.log(e);
+ return false;
+ }
+ }
+
+ /*
+ * Helper to indicate if the resource is a child of the receiver's project
+ */
+ private boolean isChildResource(IResource resource) {
+ return resource.getProject().getName().equals(managedProject.getName());
+ }
+
+ /**
+ * Return whether the given resource is managed.
+ *
+ * From a CVS standpoint, this means that we have a CVS entry
+ * for the resource and that uodates and commits may effect the
+ * resource or its children.
+ */
+ public boolean isManaged(IResource resource) throws TeamException {
+
+ if (resource.equals(project))
+ return true;
+
+ // Ensure that the resource is a child of our project
+ if (!isChildResource(resource))
+ // Is returning false enough or should we throw an exception
+ return false;
+
+ // Get the ICVSResource corresponding to the resource and check if its managed
+ return getChild(resource).isManaged();
+ }
+
+ /**
+ * @see ITeamProvider#move(IResource, IPath, IProgressMonitor)
+ */
+ public void moved(IPath source, IResource resource, IProgressMonitor progress)
+ throws TeamException {
+
+ // this translates to a delete and an add
+
+ // How is this managed? Do we do the move or is that done after?
+ // It becomes complicated if the local and remote operations
+ // are independant as this is not the way CVS works!
+
+ // Could implement a CVSProvider.MOVE!!!
+
+ Client.execute(
+ Client.REMOVE,
+ new String[0],
+ new String[0],
+ new String[] {source.removeFirstSegments(1).toString()},
+ managedProject,
+ progress,
+ getPrintStream());
+ Client.execute(
+ Client.ADD,
+ new String[0],
+ new String[0], // We'll need to copy options from old entry
+ new String[] {resource.getFullPath().removeFirstSegments(1).toString()},
+ managedProject,
+ progress,
+ getPrintStream());
+ }
+
+ /**
+ * Set the comment to be used on the next checkin
+ */
+ public void setComment(String comment) {
+ this.comment = comment;
+ }
+
+ /**
+ * Set the connection method for the given resource's
+ * project. If the conection method name is invalid (i.e.
+ * no corresponding registered connection method), false is returned.
+ */
+ public boolean setConnectionInfo(IResource resource, String methodName, IUserInfo userInfo) throws TeamException {
+ checkIsChild(resource);
+ if (!CVSRepositoryLocation.validateConnectionMethod(methodName))
+ return false;
+ CVSRepositoryLocation location;
+ try {
+ location = ((CVSRepositoryLocation)userInfo);
+ } catch (ClassCastException e) {
+ throw new TeamException(new Status(IStatus.ERROR, CVSProviderPlugin.ID, TeamException.UNABLE, Policy.bind("CVSTeamProvider.invalidUserInfo"), null));
+ }
+ location.setUserMuteable(false);
+ location.updateCache();
+ location.setMethod(methodName);
+ final String root = location.getLocation();
+ managedProject.accept(new ICVSResourceVisitor() {
+ public void visitFile(ICVSFile file) throws CVSException {};
+ public void visitFolder(ICVSFolder folder) throws CVSException {
+ FolderSyncInfo info = folder.getFolderSyncInfo();
+ info.setRoot(root);
+ folder.setFolderSyncInfo(info);
+ folder.acceptChildren(this);
+ };
+ });
+ return true;
+ }
+
+ /**
+ * Sets the userinfo (username and password) for the resource's project.
+ */
+ public void setUserInfo(IResource resource, IUserInfo userinfo) throws TeamException {
+ checkIsChild(resource);
+ try {
+ ((CVSRepositoryLocation)userinfo).updateCache();
+ } catch (ClassCastException e) {
+ throw new TeamException(new Status(IStatus.ERROR, CVSProviderPlugin.ID, TeamException.UNABLE, Policy.bind("CVSTeamProvider.invalidUserInfo"), null));
+ }
+ }
+
+ /**
+ * @see ITeamProvider#refreshState(IResource[], int, IProgressMonitor)
+ */
+ public void refreshState(
+ IResource[] resources,
+ int depth,
+ IProgressMonitor progress)
+ throws TeamException {
+
+ // How does this translate to CVS?
+ // NIK: maybe an simple update ?
+ }
+
+ /*
+ * Refresh the affected resources after a CVSException occured.
+ * Initially we'll ignore any CoreException and throw the CVSException
+ * after the refresh
+ */
+ private void refreshResources(IResource[] resources, int depth, CVSException e, IProgressMonitor progress) throws CVSException {
+ CVSException newException = e;
+ try {
+ refreshResources(resources, depth, progress);
+ } catch (CoreException coreException) {
+ // Only use the new exception if there was no old one
+ if (newException == null)
+ newException = new CVSException(new Status(IStatus.ERROR, CVSProviderPlugin.ID, TeamException.UNABLE, Policy.bind("CVSTeamProvider.refreshError", new Object[] {project.getFullPath().toString()}), coreException));
+ }
+ if (newException != null)
+ throw newException;
+ }
+ private IResource[] allChildrenOf(IResource[] resources, int depth, IProgressMonitor progress) throws CoreException {
+ final List allResources = new ArrayList();
+ for (int i=0;i<resources.length;i++) {
+ resources[i].accept(new IResourceVisitor() {
+ public boolean visit(IResource resource) {
+ allResources.add(resource);
+ return true;
+ }
+ }, depth, false);
+ }
+ return (IResource[])allResources.toArray(new IResource[allResources.size()]);
+ }
+ private void refreshResources(IResource[] resources, int depth, IProgressMonitor progress) throws CoreException {
+ // NOTE: We may not catch all resources changes in this way
+ for (int i = 0; i < resources.length; i++) {
+ IResource r = resources[i];
+ r.refreshLocal(depth, progress);
+ }
+ // NOTE: We need to refresh based on the depth
+ // We should try to be smart by getting the results from the command
+ TeamPlugin.getManager().broadcastResourceStateChanges(resources);
+ }
+
+ /**
+ * Tag the resources in the CVS repository with the given tag.
+ */
+ public void tag(IResource[] resources, int depth, String tag, boolean isBranch, IProgressMonitor progress) throws TeamException {
+
+ // Build the arguments list
+ String[] arguments = getValidArguments(resources, depth, progress);
+
+ // Build the local options
+ List localOptions = new ArrayList();
+ // If the depth is not infinite, we want the -l option
+ if (depth != IResource.DEPTH_INFINITE)
+ localOptions.add(Client.LOCAL_OPTION);
+ if (isBranch)
+ localOptions.add(Client.BRANCH_OPTION);
+
+ // The tag name is supposed to be the first argument
+ ArrayList args = new ArrayList();
+ args.add(tag);
+ args.addAll(Arrays.asList(arguments));
+ arguments = (String[])args.toArray(new String[args.size()]);
+
+ Client.execute(
+ Client.TAG,
+ new String[] {},
+ (String[])localOptions.toArray(new String[localOptions.size()]),
+ arguments,
+ managedProject,
+ progress,
+ getPrintStream());
+ }
+
+ /**
+ * Currently, we support only the optimistic model so uncheckout dores nothing.
+ *
+ * @see ITeamProvider#uncheckout(IResource[], int, IProgressMonitor)
+ */
+ public void uncheckout(IResource[] resources, int depth, IProgressMonitor progress) throws TeamException {
+ }
+
+ /**
+ * Generally usefull update
+ */
+ public void update(IResource[] resources, int depth, IProgressMonitor progress) throws TeamException {
+ // Build the local options
+ List localOptions = new ArrayList();
+ if (depth == IResource.DEPTH_INFINITE) {
+ // if depth = infinite, look for new directories
+ localOptions.add(Client.DEEP_OPTION);
+ // For now, prune empty directories
+ // This must be done by the client! (not the server)
+ localOptions.add(Client.PRUNE_OPTION);
+ }
+ else
+ // If depth = zero or 1, use -l
+ localOptions.add(Client.LOCAL_OPTION);
+ update(resources, depth, (String[])localOptions.toArray(new String[localOptions.size()]), progress);
+
+ }
+ /*
+ * CVS specific update
+ */
+ private void update(IResource[] resources, int depth, String[] localOptions, IProgressMonitor progress) throws TeamException {
+
+ // Build the arguments list
+ String[] arguments = getValidArguments(resources, depth, progress);
+
+ try {
+ Client.execute(
+ Client.UPDATE,
+ DEFAULT_GLOBAL_OPTIONS,
+ localOptions,
+ arguments,
+ managedProject,
+ progress,
+ getPrintStream());
+ } catch(CVSException e) {
+ refreshResources(resources, depth, e, progress);
+ }
+ refreshResources(resources, depth, null, progress);
+ }
+
+ private static TeamException wrapException(CoreException e) {
+ return new TeamException(statusFor(e));
+ }
+
+ public static TeamException wrapException(CVSException e, List errors) {
+ // NOTE: Need to find out how to pass MultiStatus. Is it up to me to subclass?
+ return e;
+ }
+
+ private static IStatus statusFor(CoreException e) {
+ // We should be taking out any status from the CVSException
+ // and creating an array of IStatus!
+ return new Status(IStatus.ERROR, CVSProviderPlugin.ID, TeamException.UNABLE, getMessageFor(e), e);
+ }
+
+ public static String getMessageFor(Exception e) {
+ String message = Policy.bind(e.getClass().getName(), new Object[] {e.getMessage()});
+ if (message.equals(e.getClass().getName()))
+ message = Policy.bind("CVSTeamProvider.exception", new Object[] {e.toString()});
+ return message;
+ }
+
+ /**
+ * Cause a snapshot (this saves the sync info to disk)
+ */
+ static void snapshot(IProgressMonitor monitor) throws CoreException {
+ monitor = Policy.monitorFor(monitor);
+ monitor.subTask(Policy.bind("CVSTeamProvider.snapshot"));
+ ResourcesPlugin.getWorkspace().save(false, monitor);
+ }
+ /*
+ * @see ITeamProvider#isOutOfDate(IResource)
+ * XXX to be removed when sync methods are removed from ITeamProvider
+ */
+ public boolean isOutOfDate(IResource resource) {
+ Assert.isTrue(false);
+ return false;
+ }
+ /*
+ * @see ITeamProvider#isDirty(IResource)
+ */
+ public boolean isDirty(IResource resource) {
+ try {
+ ICVSResource cvsResource = getChild(resource);
+ if(cvsResource.isFolder()) {
+ return false;
+ } else {
+ return ((ICVSFile)cvsResource).isDirty();
+ }
+ } catch(CVSException e) {
+ return true;
+ }
+ }
+ /*
+ * @see ITeamProvider#validateEdit(IFile[], Object)
+ */
+ public IStatus validateEdit(IFile[] files, Object context) {
+ return new CVSStatus(IStatus.OK, "");
+ }
+
+ /*
+ * @see ITeamProvider#validateSave(IFile)
+ */
+ public IStatus validateSave(IFile file) {
+ return new CVSStatus(IStatus.OK, "");
+ }
+}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/Client.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/Client.java index 4bb8ed208..a2b172298 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/Client.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/Client.java @@ -1,381 +1,313 @@ -package org.eclipse.team.internal.ccvs.core; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.io.File; -import java.io.PrintStream; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.ccvs.core.ICVSRepositoryLocation; -import org.eclipse.team.internal.ccvs.core.commands.CommandDispatcher; -import org.eclipse.team.internal.ccvs.core.connection.CVSRepositoryLocation; -import org.eclipse.team.internal.ccvs.core.connection.Connection; -import org.eclipse.team.internal.ccvs.core.requests.RequestSender; -import org.eclipse.team.internal.ccvs.core.resources.ResourceFactory; -import org.eclipse.team.internal.ccvs.core.resources.api.ICVSFolder; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFile; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFolder; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedResource; -import org.eclipse.team.internal.ccvs.core.response.IResponseHandler; -import org.eclipse.team.internal.ccvs.core.response.ResponseDispatcher; -import org.eclipse.team.internal.ccvs.core.util.Assert; -import org.eclipse.team.internal.ccvs.core.util.Util; - -/** - * An generic cvs client that can execute a request and can handle - * responses. It is called like the according to the specification - * of cvs-command line clients. You have to give the execute method - * the command, all the parameters, a stream to pipe the messages from - * the server to and a monitor.<br> - * After the client has established a connection to a server it - * uses the client / server negotiation protcol to tell the server - * which response can be handled by the client. Additionally the - * server tells the client which requests can the handle by the - * server. The list of responses that can be handled by the client - * is determined by the registered handlers.<br> - * <p> - * Although not documented, the client must have a handler for at - * least the following responses: "ok", "error", "Checked-in", - * "Updated", "Merged", "Removed", "M" text and "E" text. - * <p> - * The client installs handlers for all must responses. - */ -public class Client { - - public static final String CURRENT_LOCAL_FOLDER = "."; - public static final String CURRENT_REMOTE_FOLDER = ""; - public static final String SERVER_SEPARATOR = "/"; - - // Supported Commands - public static final String CHECKOUT = "co"; - public static final String UPDATE = "update"; - public static final String COMMIT = "ci"; - public static final String ADD = "add"; - public static final String REMOVE = "remove"; - public static final String IMPORT = "import"; - public static final String TAG = "tag"; - public static final String DIFF = "diff"; - public static final String ADMIN = "admin"; - public static final String STATUS = "status"; - public static final String LOG = "log"; - - // Global Options - public static final String REPO_OPTION = "-d"; - public static final String NOCHANGE_OPTION = "-n"; - - // Local Options - public static final String IGNORE_OPTION = "-I"; - public static final String WRAPPER_OPTION = "-W"; - public static final String KB_OPTION = "-kb"; - public static final String KO_OPTION = "-ko"; - public static final String PRUNE_OPTION = "-P"; - public static final String TAG_OPTION = "-r"; - public static final String BRANCH_OPTION = "-b"; - public static final String DEEP_OPTION = "-d"; - public static final String IGNORE_LOCAL_OPTION = "-d"; - public static final String LOCAL_OPTION = "-l"; - public static final String MESSAGE_OPTION = "-m"; - - public static final String[] EMPTY_ARGS_LIST = new String[0]; - - /** - * Executes the given command, with all the parameter. It works like a - * cvs-client in terms of different parameter. - * Sets up the three main objects of the program: - * - * commandDispatcher => Knows about commands (update, commit ...) - * responseDispatcher => Reacts on input from the server - * requestSender => Knows how to send requests to the server - * - * @param request the cvs-command to run, not-null - * @param globalOptions the cvs-options null possible - * @param localOptions the cvs-options null possible - * @param arguments the cvs-arguments null possible - * @param mRoot the fileSystem the command is executed on, not-null - * @param monitor the progress-monitor null possible - * @param messageOut PrintStream that the Messages and Error of the server - * are piped to - * @param connection the connection to the cvs-server - * @param customHandlers handlers for responseTypes of the server. It is - * dangerous to register MessageHandler and ErrorHandler. It is not - * recomended to try to register ANY other hander. - * @param FirstTime if you work over an opened connection you have to set - * the first-time parameter to true, the first time you execute a - * requst. After the first time you can (but you do not have to) set - * this parameter to false in order to save the overhead of the - * intialisation with the server - * @see commandDispatcher - * @see RequestSender - * @see responseDispatcher - */ - public static void execute(String request, - String[] globalOptions, - String[] localOptions, - String[] arguments, - IManagedFolder mRoot, - IProgressMonitor monitor, - PrintStream messageOut, - Connection connection, - IResponseHandler[] customHandlers, - boolean firstTime) - throws CVSException { - - Assert.isNotNull(request); - Assert.isNotNull(connection); - Assert.isNotNull(mRoot); - globalOptions = notNull(globalOptions); - localOptions = notNull(localOptions); - arguments = notNull(arguments); - monitor = Policy.monitorFor(monitor); - customHandlers = notNull(customHandlers); - - // We might remove certain options and arguments when - // we looked at them and they do not need our attention - // any more. This changes should not affect the caller. - globalOptions = (String[])globalOptions.clone(); - localOptions = (String[])localOptions.clone(); - arguments = (String[])arguments.clone(); - - ResponseDispatcher responseDispatcher = new ResponseDispatcher(connection, customHandlers); - RequestSender requestSender = new RequestSender(connection); - CommandDispatcher commandDispatcher = new CommandDispatcher(responseDispatcher, requestSender); - - if (firstTime) { - initialize(responseDispatcher, requestSender, connection, mRoot, monitor, messageOut); - } - - commandDispatcher.execute(request, - globalOptions, - localOptions, - arguments, - mRoot, - monitor, - messageOut); - } - - /** - * Executes the given request. Give the client a CVSRepositoryLocation - * that the server is going to open and close the connection from. - * - * @param repository represents an abstract cvs-repository. If it is null - * connection-infrmation is searced in the globalOptions and in the - * filesystem - * @see Client#execute(String,String[],String[],String[],IManagedFolder,IProgressMonitor,PrintStream,Connection,IResponseHandler[],boolean) - */ - public static void execute(String request, - String[] globalOptions, - String[] localOptions, - String[] arguments, - IManagedFolder mRoot, - IProgressMonitor monitor, - PrintStream messageOut, - CVSRepositoryLocation repository, - IResponseHandler[] customHandlers) - throws CVSException { - - Assert.isNotNull(mRoot); - globalOptions = notNull(globalOptions); - - // We might remove certain global options. - // This should not affect the caller - globalOptions = (String[])globalOptions.clone(); - - if (repository == null) { - repository = getRepository(globalOptions, mRoot); - } - - Connection connection = repository.openConnection(); - try { - execute(request, - globalOptions, - localOptions, - arguments, - mRoot, - monitor, - messageOut, - connection, - customHandlers, - true); - } finally { - connection.close(); - } - } - - /** - * Executes the given request in the standard cvs-way. This is the preferred - * way to call the client. It is equal to the call:<br> - * execute(request,globalOptions,localOptions,arguments,mRoot,monitor,messageOut,null,null);<br> - * - * @see Client#execute(String,String[],String[],String[],IManagedFolder,IProgressMonitor,PrintStream,CVSRepositoryLocation,IResponseHandler[]) - * @see Client#execute(String,String[],String[],String[],IManagedFolder,IProgressMonitor,PrintStream,Connection,IResponseHandler[],boolean) - */ - public static void execute(String request, - String[] globalOptions, - String[] localOptions, - String[] arguments, - IManagedFolder mRoot, - IProgressMonitor monitor, - PrintStream messageOut) - throws CVSException { - - execute(request, - globalOptions, - localOptions, - arguments, - mRoot, - monitor, - messageOut, - null, - null); - } - - /** - * @see Client#(String,String[],String[],String[],ICVSFolder,IProgressMonitor,OutputStream,Connection) - */ - public static void execute(String request, - String[] globalOptions, - String[] localOptions, - String[] arguments, - ICVSFolder root, - IProgressMonitor monitor, - PrintStream messageOut) - throws CVSException { - execute(request, - globalOptions, - localOptions, - arguments, - ResourceFactory.getManaged(root), - monitor, - messageOut); - } - - - /** - * @see Client#(String,String[],String[],String[],ICVSFolder,IProgressMonitor,OutputStream,Connection) - */ - public static void execute(String request, - String[] globalOptions, - String[] localOptions, - String[] arguments, - File root, - IProgressMonitor monitor, - PrintStream messageOut) - throws CVSException { - execute(request, - globalOptions, - localOptions, - arguments, - ResourceFactory.getManagedFolder(root), - monitor, - messageOut); - } - - /** - * Gives you an ManagedFolder for a absolut path in - * platform dependend style - * - * @throws CVSException on path.indexOf("CVS") != -1 - * @throws CVSException on internal IOExeption - */ - public static IManagedFolder getManagedFolder(String folder) throws CVSException { - return ResourceFactory.getManagedFolder(folder); - } - public static IManagedFolder getManagedFolder(File folder) throws CVSException { - return ResourceFactory.getManagedFolder(folder); - } - public static IManagedResource getManagedResource(File file) throws CVSException { - return ResourceFactory.getManaged(file); - } - public static IManagedFile getManagedFile(File file) throws CVSException { - return ResourceFactory.getManagedFile(file); - } - - /** - * Intializes the client. - * - * Gets the valid-requsts form the server, and puts them into the - * request sender. - */ - private static void initialize(ResponseDispatcher responseDispatcher, - RequestSender requestSender, - Connection connection, - IManagedFolder mRoot, - IProgressMonitor monitor, - PrintStream messageOut) - throws CVSException { - - // Tell the server our response handlers. - connection.writeLine(requestSender.VALID_RESPONSES, responseDispatcher.makeResponseList()); - - // Get all valid requests from the server - connection.writeLine(requestSender.VALID_REQUESTS); - - // Get the responseHandler that does put the valid-requests - // into the requestSender - IResponseHandler validRequestHandler = requestSender.getValidRequestHandler(); - - // Register the responseHandler, process the server-reply - // unregister it afterwards ... we are not going to get - // another response of this kind - responseDispatcher.registerResponseHandler(validRequestHandler); - responseDispatcher.manageResponse(monitor,mRoot,messageOut); - responseDispatcher.unregisterResponseHandler(validRequestHandler); - - // Set the root. - // we just send it. If we do not send it we have got - // a problem anyway ... so we do not bother checking if it - // is allowed (we could do so with "requestSender.isValidRequest(ROOT)" - connection.writeLine(requestSender.ROOT, connection.getRootDirectory()); - } - - /** - * This give you a new repo either from the global "-d" option - * or form the root-property in the folder. - * - * This has to be rewritten in a nicer style. - */ - private static CVSRepositoryLocation getRepository(String[] globalOptions, - IManagedFolder mFolder) - throws CVSException { - - String repoName = null; - - Assert.isNotNull(mFolder); - - // look if the repo is specified in the global Options - // this delets the option as well which is not so beatyful, but - // we have got a copy and we do not want this option to appear - // any more - repoName = Util.getOption(globalOptions,REPO_OPTION,true); - - // look if we have got an root-entrie in the root-folder - if (repoName == null && mFolder.exists() && mFolder.isCVSFolder()) { - repoName = mFolder.getFolderInfo().getRoot(); - } - - if (repoName == null) { - throw new CVSException("CVSROOT is not specified"); - } - - return CVSRepositoryLocation.fromString(repoName); - } - - private static String[] notNull(String[] arg) { - if (arg == null) { - return new String[0]; - } else { - return arg; - } - } - - private static IResponseHandler[] notNull(IResponseHandler[] arg) { - if (arg == null) { - return new IResponseHandler[0]; - } else { - return arg; - } - } -} +package org.eclipse.team.internal.ccvs.core;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.io.File;
+import java.io.PrintStream;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.team.internal.ccvs.core.commands.CommandDispatcher;
+import org.eclipse.team.internal.ccvs.core.connection.CVSRepositoryLocation;
+import org.eclipse.team.internal.ccvs.core.connection.Connection;
+import org.eclipse.team.internal.ccvs.core.requests.RequestSender;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFile;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFolder;
+import org.eclipse.team.internal.ccvs.core.resources.LocalFile;
+import org.eclipse.team.internal.ccvs.core.resources.LocalFolder;
+import org.eclipse.team.internal.ccvs.core.response.IResponseHandler;
+import org.eclipse.team.internal.ccvs.core.response.ResponseDispatcher;
+import org.eclipse.team.internal.ccvs.core.util.Assert;
+import org.eclipse.team.internal.ccvs.core.util.Util;
+
+public class Client {
+
+ public static final String CURRENT_LOCAL_FOLDER = ".";
+ public static final String CURRENT_REMOTE_FOLDER = "";
+ public static final String SERVER_SEPARATOR = "/";
+
+ // Supported Commands
+ public static final String CHECKOUT = "co";
+ public static final String UPDATE = "update";
+ public static final String COMMIT = "ci";
+ public static final String ADD = "add";
+ public static final String REMOVE = "remove";
+ public static final String IMPORT = "import";
+ public static final String TAG = "tag";
+ public static final String DIFF = "diff";
+ public static final String ADMIN = "admin";
+ public static final String STATUS = "status";
+ public static final String LOG = "log";
+
+ // Global Options
+ public static final String REPO_OPTION = "-d";
+ public static final String NOCHANGE_OPTION = "-n";
+
+ // Local Options
+ public static final String IGNORE_OPTION = "-I";
+ public static final String WRAPPER_OPTION = "-W";
+ public static final String KB_OPTION = "-kb";
+ public static final String KO_OPTION = "-ko";
+ public static final String PRUNE_OPTION = "-P";
+ public static final String TAG_OPTION = "-r";
+ public static final String BRANCH_OPTION = "-b";
+ public static final String DEEP_OPTION = "-d";
+ public static final String IGNORE_LOCAL_OPTION = "-d";
+ public static final String LOCAL_OPTION = "-l";
+ public static final String MESSAGE_OPTION = "-m";
+
+ public static final String[] EMPTY_ARGS_LIST = new String[0];
+
+ /**
+ * Executes the given command, with all the parameter. It works like a
+ * cvs-client in terms of different parameter.
+ * Sets up the three main objects of the program:
+ *
+ * commandDispatcher => Knows about commands (update, commit ...)
+ * responseDispatcher => Reacts on input from the server
+ * requestSender => Knows how to send requests to the server
+ *
+ * @param request the cvs-command to run, not-null
+ * @param globalOptions the cvs-options null possible
+ * @param localOptions the cvs-options null possible
+ * @param arguments the cvs-arguments null possible
+ * @param mRoot the fileSystem the command is executed on, not-null
+ * @param monitor the progress-monitor null possible
+ * @param messageOut PrintStream that the Messages and Error of the server
+ * are piped to
+ * @param connection the connection to the cvs-server
+ * @param customHandlers handlers for responseTypes of the server. It is
+ * dangerous to register MessageHandler and ErrorHandler. It is not
+ * recomended to try to register ANY other hander.
+ * @param FirstTime if you work over an opened connection you have to set
+ * the first-time parameter to true, the first time you execute a
+ * requst. After the first time you can (but you do not have to) set
+ * this parameter to false in order to save the overhead of the
+ * intialisation with the server
+ * @see commandDispatcher
+ * @see RequestSender
+ * @see responseDispatcher
+ */
+ public static void execute(String request,
+ String[] globalOptions,
+ String[] localOptions,
+ String[] arguments,
+ ICVSFolder mRoot,
+ IProgressMonitor monitor,
+ PrintStream messageOut,
+ Connection connection,
+ IResponseHandler[] customHandlers,
+ boolean firstTime)
+ throws CVSException {
+
+ Assert.isNotNull(request);
+ Assert.isNotNull(connection);
+ Assert.isNotNull(mRoot);
+ globalOptions = notNull(globalOptions);
+ localOptions = notNull(localOptions);
+ arguments = notNull(arguments);
+ monitor = Policy.monitorFor(monitor);
+ customHandlers = notNull(customHandlers);
+
+ // We might remove certain options and arguments when
+ // we looked at them and they do not need our attention
+ // any more. This changes should not affect the caller.
+ globalOptions = (String[])globalOptions.clone();
+ localOptions = (String[])localOptions.clone();
+ arguments = (String[])arguments.clone();
+
+ ResponseDispatcher responseDispatcher = new ResponseDispatcher(connection, customHandlers);
+ RequestSender requestSender = new RequestSender(connection);
+ CommandDispatcher commandDispatcher = new CommandDispatcher(responseDispatcher, requestSender);
+
+ if (firstTime) {
+ initialize(responseDispatcher, requestSender, connection, mRoot, monitor, messageOut);
+ }
+
+ commandDispatcher.execute(request,
+ globalOptions,
+ localOptions,
+ arguments,
+ mRoot,
+ monitor,
+ messageOut);
+ }
+
+ /**
+ * Executes the given request. Give the client a CVSRepositoryLocation
+ * that the server is going to open and close the connection from.
+ *
+ * @param repository represents an abstract cvs-repository. If it is null
+ * connection-infrmation is searced in the globalOptions and in the
+ * filesystem
+ * @see Client#execute(String,String[],String[],String[],ICVSFolder,IProgressMonitor,PrintStream,Connection,IResponseHandler[],boolean)
+ */
+ public static void execute(String request,
+ String[] globalOptions,
+ String[] localOptions,
+ String[] arguments,
+ ICVSFolder mRoot,
+ IProgressMonitor monitor,
+ PrintStream messageOut,
+ CVSRepositoryLocation repository,
+ IResponseHandler[] customHandlers)
+ throws CVSException {
+
+ Assert.isNotNull(mRoot);
+ globalOptions = notNull(globalOptions);
+
+ // We might remove certain global options.
+ // This should not affect the caller
+ globalOptions = (String[])globalOptions.clone();
+
+ if (repository == null) {
+ repository = getRepository(globalOptions, mRoot);
+ }
+
+ Connection connection = repository.openConnection();
+ try {
+ execute(request,
+ globalOptions,
+ localOptions,
+ arguments,
+ mRoot,
+ monitor,
+ messageOut,
+ connection,
+ customHandlers,
+ true);
+ } finally {
+ connection.close();
+ }
+ }
+
+ /**
+ * Executes the given request in the standard cvs-way. This is the preferred
+ * way to call the client. It is equal to the call:<br>
+ * execute(request,globalOptions,localOptions,arguments,mRoot,monitor,messageOut,null,null);<br>
+ *
+ * @see Client#execute(String,String[],String[],String[],ICVSFolder,IProgressMonitor,PrintStream,CVSRepositoryLocation,IResponseHandler[])
+ * @see Client#execute(String,String[],String[],String[],ICVSFolder,IProgressMonitor,PrintStream,Connection,IResponseHandler[],boolean)
+ */
+ public static void execute(String request,
+ String[] globalOptions,
+ String[] localOptions,
+ String[] arguments,
+ ICVSFolder mRoot,
+ IProgressMonitor monitor,
+ PrintStream messageOut)
+ throws CVSException {
+
+ execute(request,
+ globalOptions,
+ localOptions,
+ arguments,
+ mRoot,
+ monitor,
+ messageOut,
+ null,
+ null);
+ }
+
+ /**
+ * Gives you an LocalFolder for a absolute path in
+ * platform dependend style.
+ *
+ * @throws CVSException on path.indexOf("CVS") != -1
+ * @throws CVSException on internal IOExeption
+ */
+ public static ICVSFolder getManagedFolder(File folder) throws CVSException {
+ return new LocalFolder(folder);
+ }
+ public static ICVSFile getManagedFile(File file) throws CVSException {
+ return new LocalFile(file);
+ }
+
+ /**
+ * Intializes the client.
+ *
+ * Gets the valid-requsts form the server, and puts them into the
+ * request sender.
+ */
+ private static void initialize(ResponseDispatcher responseDispatcher,
+ RequestSender requestSender,
+ Connection connection,
+ ICVSFolder mRoot,
+ IProgressMonitor monitor,
+ PrintStream messageOut)
+ throws CVSException {
+
+ // Tell the server our response handlers.
+ connection.writeLine(requestSender.VALID_RESPONSES, responseDispatcher.makeResponseList());
+
+ // Get all valid requests from the server
+ connection.writeLine(requestSender.VALID_REQUESTS);
+
+ // Get the responseHandler that does put the valid-requests
+ // into the requestSender
+ IResponseHandler validRequestHandler = requestSender.getValidRequestHandler();
+
+ // Register the responseHandler, process the server-reply
+ // unregister it afterwards ... we are not going to get
+ // another response of this kind
+ responseDispatcher.registerResponseHandler(validRequestHandler);
+ responseDispatcher.manageResponse(monitor,mRoot,messageOut);
+ responseDispatcher.unregisterResponseHandler(validRequestHandler);
+
+ // Set the root.
+ // we just send it. If we do not send it we have got
+ // a problem anyway ... so we do not bother checking if it
+ // is allowed (we could do so with "requestSender.isValidRequest(ROOT)"
+ connection.writeLine(requestSender.ROOT, connection.getRootDirectory());
+ }
+
+ /**
+ * This give you a new repo either from the global "-d" option
+ * or form the root-property in the folder.
+ *
+ * This has to be rewritten in a nicer style.
+ */
+ private static CVSRepositoryLocation getRepository(String[] globalOptions,
+ ICVSFolder mFolder)
+ throws CVSException {
+
+ String repoName = null;
+
+ Assert.isNotNull(mFolder);
+
+ // look if the repo is specified in the global Options
+ // this delets the option as well which is not so beatyful, but
+ // we have got a copy and we do not want this option to appear
+ // any more
+ repoName = Util.getOption(globalOptions,REPO_OPTION,true);
+
+ // look if we have got an root-entrie in the root-folder
+ if (repoName == null && mFolder.exists() && mFolder.isCVSFolder()) {
+ repoName = mFolder.getFolderSyncInfo().getRoot();
+ }
+
+ if (repoName == null) {
+ throw new CVSException("CVSROOT is not specified");
+ }
+
+ return CVSRepositoryLocation.fromString(repoName);
+ }
+
+ private static String[] notNull(String[] arg) {
+ if (arg == null) {
+ return new String[0];
+ } else {
+ return arg;
+ }
+ }
+
+ private static IResponseHandler[] notNull(IResponseHandler[] arg) {
+ if (arg == null) {
+ return new IResponseHandler[0];
+ } else {
+ return arg;
+ }
+ }
+}
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/ICVSProvider.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/ICVSProvider.java index b5e2ea7af..bea6a33ee 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/ICVSProvider.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/ICVSProvider.java @@ -1,134 +1,134 @@ -package org.eclipse.team.ccvs.core; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.io.PrintStream; -import java.util.Properties; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.core.TeamException; -import org.eclipse.team.internal.ccvs.core.CVSException; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - - -/** - * The ICVSProvider interface provides access to CVS operations that create repository locations, - * support retrieval of repository information and import and checkout CVS modules - */ -public interface ICVSProvider { - - /** - * Checkout a CVS module. - * - * The provided project represents the target project. Any existing contents - * may or may not get overwritten. If project is <code>null</code> then a project - * will be created based on the provided sourceModule. If soureModule is null, - * then the project name will be used as the module to - * check out. If both are absent, an exception is thrown. - * - * After the successful completion of this method, the project will exist - * and be open. - */ - public void checkout(ICVSRepositoryLocation repository, IProject project, String sourceModule, String tag, IProgressMonitor monitor) throws TeamException; - - /** - * Checkout a CVS module. - * - * The provided project represents the target project. Any existing contents - * may or may not get overwritten. If project is <code>null</code> then a project - * will be created based on the provided "module" property. If there is no - * "module" property, then the project name will be used as the module to - * check out. If both are absent, an exception is thrown. - * - * After the successful completion of this method, the project will exist - * and be open. - * - * The supported properties are: - * connection The connection method to be used - * user The username for the connection - * password The password used for the connection (optional) - * host The host where the repository resides - * port The port to connect to (optional) - * root The server directory where the repository is located - * module The name of the module to be checked out (optional) - * tag The tag to be used in the checkout request (optional) - */ - public void checkout(IProject project, Properties configuration, IProgressMonitor monitor) throws TeamException; - - /** - * Checkout the remote resources into the local workspace. Each resource will - * be checked out into the corresponding project. If teh corresponding project is - * null or if projects is null, the name of the remote resource is used as the name of the project. - */ - public void checkout(ICVSRemoteResource[] resources, IProject[] projects, IProgressMonitor monitor) throws TeamException; - - /** - * Create a repository instance from the given properties. - * The supported properties are: - * - * connection The connection method to be used - * user The username for the connection - * password The password used for the connection (optional) - * host The host where the repository resides - * port The port to connect to (optional) - * root The server directory where the repository is located - * - * The created instance will be cached with the provider as a result of the - * invokation of this method. When the client is done with the instance, disposeRepository - * should be called - */ - public ICVSRepositoryLocation createRepository(Properties configuration) throws CVSException; - - /** - * Dispose of the repository location - * - * Removes any cached information about the repository such as a remembered password. - */ - public void disposeRepository(ICVSRepositoryLocation repository) throws CVSException; - - /** Return a list of the know repository locations - */ - public ICVSRepositoryLocation[] getKnownRepositories(); - - /** - * Get the stream to which command message and error output is sent - */ - public PrintStream getPrintStream(); - - /** - * Get the names of the registered connection methods. - */ - public String[] getSupportedConnectionMethods(); - - /** - * Import a project into a CVS repository and then check out a local copy. - * - * Consideration: What if the project already exists? - * - * The supported properties are: - * connection The connection method to be used - * user The username for the connection - * password The password used for the connection (optional) - * host The host where the repository resides - * port The port to connect to (optional) - * root The server directory where the repository is located - * message The message to be attached (optional) - * vendor The vendor tag (optional) - * tag The version tag (optional) - */ - public void importAndCheckout(IProject project, Properties configuration, IProgressMonitor monitor) throws TeamException; - - /** - * Set the print stream to which command message and error output is sent - */ - public void setPrintStream(PrintStream out); -} - +package org.eclipse.team.ccvs.core;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.io.PrintStream;
+import java.util.Properties;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.team.core.TeamException;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+
+/**
+ * The ICVSProvider interface provides access to CVS operations that create repository locations,
+ * support retrieval of repository information and import and checkout CVS modules
+ */
+public interface ICVSProvider {
+
+ /**
+ * Checkout a CVS module.
+ *
+ * The provided project represents the target project. Any existing contents
+ * may or may not get overwritten. If project is <code>null</code> then a project
+ * will be created based on the provided sourceModule. If soureModule is null,
+ * then the project name will be used as the module to
+ * check out. If both are absent, an exception is thrown.
+ *
+ * After the successful completion of this method, the project will exist
+ * and be open.
+ */
+ public void checkout(ICVSRepositoryLocation repository, IProject project, String sourceModule, CVSTag tag, IProgressMonitor monitor) throws TeamException;
+
+ /**
+ * Checkout a CVS module.
+ *
+ * The provided project represents the target project. Any existing contents
+ * may or may not get overwritten. If project is <code>null</code> then a project
+ * will be created based on the provided "module" property. If there is no
+ * "module" property, then the project name will be used as the module to
+ * check out. If both are absent, an exception is thrown.
+ *
+ * After the successful completion of this method, the project will exist
+ * and be open.
+ *
+ * The supported properties are:
+ * connection The connection method to be used
+ * user The username for the connection
+ * password The password used for the connection (optional)
+ * host The host where the repository resides
+ * port The port to connect to (optional)
+ * root The server directory where the repository is located
+ * module The name of the module to be checked out (optional)
+ * tag The tag to be used in the checkout request (optional)
+ */
+ public void checkout(IProject project, Properties configuration, IProgressMonitor monitor) throws TeamException;
+
+ /**
+ * Checkout the remote resources into the local workspace. Each resource will
+ * be checked out into the corresponding project. If teh corresponding project is
+ * null or if projects is null, the name of the remote resource is used as the name of the project.
+ */
+ public void checkout(ICVSRemoteResource[] resources, IProject[] projects, IProgressMonitor monitor) throws TeamException;
+
+ /**
+ * Create a repository instance from the given properties.
+ * The supported properties are:
+ *
+ * connection The connection method to be used
+ * user The username for the connection
+ * password The password used for the connection (optional)
+ * host The host where the repository resides
+ * port The port to connect to (optional)
+ * root The server directory where the repository is located
+ *
+ * The created instance will be cached with the provider as a result of the
+ * invokation of this method. When the client is done with the instance, disposeRepository
+ * should be called
+ */
+ public ICVSRepositoryLocation createRepository(Properties configuration) throws CVSException;
+
+ /**
+ * Dispose of the repository location
+ *
+ * Removes any cached information about the repository such as a remembered password.
+ */
+ public void disposeRepository(ICVSRepositoryLocation repository) throws CVSException;
+
+ /** Return a list of the know repository locations
+ */
+ public ICVSRepositoryLocation[] getKnownRepositories();
+
+ /**
+ * Get the stream to which command message and error output is sent
+ */
+ public PrintStream getPrintStream();
+
+ /**
+ * Get the names of the registered connection methods.
+ */
+ public String[] getSupportedConnectionMethods();
+
+ /**
+ * Import a project into a CVS repository and then check out a local copy.
+ *
+ * Consideration: What if the project already exists?
+ *
+ * The supported properties are:
+ * connection The connection method to be used
+ * user The username for the connection
+ * password The password used for the connection (optional)
+ * host The host where the repository resides
+ * port The port to connect to (optional)
+ * root The server directory where the repository is located
+ * message The message to be attached (optional)
+ * vendor The vendor tag (optional)
+ * tag The version tag (optional)
+ */
+ public void importAndCheckout(IProject project, Properties configuration, IProgressMonitor monitor) throws TeamException;
+
+ /**
+ * Set the print stream to which command message and error output is sent
+ */
+ public void setPrintStream(PrintStream out);
+}
+
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/ICVSRemoteFile.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/ICVSRemoteFile.java index a150af4e2..3f815061e 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/ICVSRemoteFile.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/ICVSRemoteFile.java @@ -1,37 +1,37 @@ -package org.eclipse.team.ccvs.core; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.io.InputStream; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.core.TeamException; - - /** - * This interface represents a file in a repository. - * Instances of this interface can be used to fetch the contents - * of the remote file. - * - * In the future, additional information should be available (tags, revisions, etc.) - * - * Clients are not expected to implement this interface. - */ -public interface ICVSRemoteFile extends ICVSRemoteResource { - - /** - * Get the log entries of the remote file - */ - public ILogEntry[] getLogEntries(IProgressMonitor monitor) throws TeamException; - - /** - * Get the revision of the remote file (e.g. 1.1) - * - * The revision depends on any tagging associated with the remote parent used - * to access the file. - */ - public String getRevision() throws TeamException; -} - +package org.eclipse.team.ccvs.core;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.io.InputStream;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.team.core.TeamException;
+
+ /**
+ * This interface represents a file in a repository.
+ * Instances of this interface can be used to fetch the contents
+ * of the remote file.
+ *
+ * In the future, additional information should be available (tags, revisions, etc.)
+ *
+ * Clients are not expected to implement this interface.
+ */
+public interface ICVSRemoteFile extends ICVSRemoteResource {
+
+ /**
+ * Get the log entries of the remote file
+ */
+ public ILogEntry[] getLogEntries(IProgressMonitor monitor) throws TeamException;
+
+ /**
+ * Get the revision of the remote file (e.g. 1.1)
+ *
+ * The revision depends on any tagging associated with the remote parent used
+ * to access the file.
+ */
+ public String getRevision() throws TeamException;
+}
+
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/ICVSRemoteFolder.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/ICVSRemoteFolder.java index c013c70d5..6bef6eca6 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/ICVSRemoteFolder.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/ICVSRemoteFolder.java @@ -1,32 +1,32 @@ -package org.eclipse.team.ccvs.core; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.core.TeamException; - - /** - * This interface represents a remote folder in a repository. It provides - * access to the members (remote files and folders) of a remote folder - * - * Clients are not expected to implement this interface. - */ -public interface ICVSRemoteFolder extends ICVSRemoteResource { - - /** - * Allows a client to change the context of a remote folder handle. For - * example, if a remote folder was created with the HEAD context (e.g. can - * be used to browse the main branch) use this method to change the - * context to another branch tag or to a version tag. - */ - public void setTag(String tagName); - - /** - * Return the context of this handle. The returned tag can be a branch or - * version tag. - */ - public String getTag(); +package org.eclipse.team.ccvs.core;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.team.core.TeamException;
+
+ /**
+ * This interface represents a remote folder in a repository. It provides
+ * access to the members (remote files and folders) of a remote folder
+ *
+ * Clients are not expected to implement this interface.
+ */
+public interface ICVSRemoteFolder extends ICVSRemoteResource {
+
+ /**
+ * Allows a client to change the context of a remote folder handle. For
+ * example, if a remote folder was created with the HEAD context (e.g. can
+ * be used to browse the main branch) use this method to change the
+ * context to another branch tag or to a version tag.
+ */
+ public void setTag(CVSTag tagName);
+
+ /**
+ * Return the context of this handle. The returned tag can be a branch or
+ * version tag.
+ */
+ public CVSTag getTag();
}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/ICVSRemoteResource.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/ICVSRemoteResource.java index 260372cf4..65d06ed1d 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/ICVSRemoteResource.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/ICVSRemoteResource.java @@ -1,26 +1,38 @@ -package org.eclipse.team.ccvs.core; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.team.core.sync.IRemoteResource; - -/** - * The interface represents a resource that exists in a CVS repository. - * It purpose is to provide information about the remote resource from - * the repository. - * - * Clients are not expected to implement this interface. - */ -public interface ICVSRemoteResource extends IRemoteResource { - - /** - * Return the repository - */ - public ICVSRepositoryLocation getRepository(); -} - +package org.eclipse.team.ccvs.core;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.team.core.sync.IRemoteResource;
+
+/**
+ * The interface represents a resource that exists in a CVS repository.
+ * It purpose is to provide information about the remote resource from
+ * the repository.
+ *
+ * Clients are not expected to implement this interface.
+ */
+public interface ICVSRemoteResource extends IRemoteResource {
+
+ /**
+ * Return the repository
+ */
+ public ICVSRepositoryLocation getRepository();
+
+ /**
+ * Returns the parent of this remote resource or <code>null</code> if the
+ * remote resource does not have a parent.
+ */
+ public ICVSRemoteResource getRemoteParent();
+
+ /**
+ * Does the remote resource represented by this handle exist on the server. This
+ * method may contact the server and be long running.
+ */
+ public boolean exists();
+}
+
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/ICVSRepositoryLocation.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/ICVSRepositoryLocation.java index 8cbbcfe8a..cdc49dc48 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/ICVSRepositoryLocation.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/ICVSRepositoryLocation.java @@ -1,84 +1,84 @@ -package org.eclipse.team.ccvs.core; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.core.sync.IRemoteResource; -import org.eclipse.team.internal.ccvs.core.CVSException; - -/** - * This interface provides access to the specific portions of - * the repository location string for use by connection methods - * and the user authenticator. - * - * It is not intended to implemented by clients. - * - * @see IUserAuthenticator - * @see IConnectionMethod - */ -public interface ICVSRepositoryLocation extends IAdaptable { - - /** - * port value which indicates to a connection method to use the default port - */ - public static int USE_DEFAULT_PORT = 0; - - /** - * Return the connection method for making the connection - */ - public IConnectionMethod getMethod(); - - /** - * Returns the host where the repository is located - */ - public String getHost(); - - /** - * Returns the port to connect to or USE_DEFAULT_PORT if - * the connection method is to use its default port. - */ - public int getPort(); - - /** - * Returns the root directory of the repository. - */ - public String getRootDirectory(); - - /** - * Returns the string representing the receiver. This string - * should contain enough information to recreate the receiver. - */ - public String getLocation(); - - /** - * Returns the immediate children of this location. If tag is <code>null</code> the - * HEAD branch is assumed. - * - * @param tag the context in which to return the members (e.g. branch or version). - */ - public ICVSRemoteResource[] members(String tag, IProgressMonitor progress) throws CVSException; - - /** - * Return the conection timeout value in milliseconds. - * A value of 0 means there is no timeout value. - */ - public int getTimeout(); - - /** - * Return the information about the user as an IUserInfo. - * - * This allows the querying of the user name and the setting - * of the username and password. - */ - public IUserInfo getUserInfo(); - - /** - * Return the username - */ - public String getUsername(); -} - +package org.eclipse.team.ccvs.core;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.team.core.sync.IRemoteResource;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+
+/**
+ * This interface provides access to the specific portions of
+ * the repository location string for use by connection methods
+ * and the user authenticator.
+ *
+ * It is not intended to implemented by clients.
+ *
+ * @see IUserAuthenticator
+ * @see IConnectionMethod
+ */
+public interface ICVSRepositoryLocation extends IAdaptable {
+
+ /**
+ * port value which indicates to a connection method to use the default port
+ */
+ public static int USE_DEFAULT_PORT = 0;
+
+ /**
+ * Return the connection method for making the connection
+ */
+ public IConnectionMethod getMethod();
+
+ /**
+ * Returns the host where the repository is located
+ */
+ public String getHost();
+
+ /**
+ * Returns the port to connect to or USE_DEFAULT_PORT if
+ * the connection method is to use its default port.
+ */
+ public int getPort();
+
+ /**
+ * Returns the root directory of the repository.
+ */
+ public String getRootDirectory();
+
+ /**
+ * Returns the string representing the receiver. This string
+ * should contain enough information to recreate the receiver.
+ */
+ public String getLocation();
+
+ /**
+ * Returns the immediate children of this location. If tag is <code>null</code> the
+ * HEAD branch is assumed.
+ *
+ * @param tag the context in which to return the members (e.g. branch or version).
+ */
+ public ICVSRemoteResource[] members(CVSTag tag, IProgressMonitor progress) throws CVSException;
+
+ /**
+ * Return the conection timeout value in milliseconds.
+ * A value of 0 means there is no timeout value.
+ */
+ public int getTimeout();
+
+ /**
+ * Return the information about the user as an IUserInfo.
+ *
+ * This allows the querying of the user name and the setting
+ * of the username and password.
+ */
+ public IUserInfo getUserInfo();
+
+ /**
+ * Return the username
+ */
+ public String getUsername();
+}
+
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/IConnectionMethod.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/IConnectionMethod.java index 81d122db8..f2346ddf9 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/IConnectionMethod.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/IConnectionMethod.java @@ -1,31 +1,31 @@ -package org.eclipse.team.ccvs.core; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -/** - * Implementators of this class can act as factories for creating connections to a CVS server - * with the desired custom communication protocol. Providers of CVS connection methods must implement - * this interface and register the implementation with the extension point: - * - * org.eclipse.team.cvs.core.connectionmethods - * - * The <code>createConnection()</code> method will be invoked by the CVS client when the user - * is attempting to make a connection to the server using the connection name which matches - * the <code>String</code> returned by <code>getName()</code> (e.g. "pserver", "ext", etc.). - */ -public interface IConnectionMethod { - - /** - * Returns the name of this connection method (e.g."local", "ext"). - */ - public String getName(); - - /** - * Creates a new server connection using the given repository root - * (which includes the user name) and the given password. - */ - public IServerConnection createConnection(ICVSRepositoryLocation location, String password); -} +package org.eclipse.team.ccvs.core;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+/**
+ * Implementators of this class can act as factories for creating connections to a CVS server
+ * with the desired custom communication protocol. Providers of CVS connection methods must implement
+ * this interface and register the implementation with the extension point:
+ *
+ * org.eclipse.team.cvs.core.connectionmethods
+ *
+ * The <code>createConnection()</code> method will be invoked by the CVS client when the user
+ * is attempting to make a connection to the server using the connection name which matches
+ * the <code>String</code> returned by <code>getName()</code> (e.g. "pserver", "ext", etc.).
+ */
+public interface IConnectionMethod {
+
+ /**
+ * Returns the name of this connection method (e.g."local", "ext").
+ */
+ public String getName();
+
+ /**
+ * Creates a new server connection using the given repository root
+ * (which includes the user name) and the given password.
+ */
+ public IServerConnection createConnection(ICVSRepositoryLocation location, String password);
+}
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/ILogEntry.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/ILogEntry.java index 3eaa9cd6c..c80938b13 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/ILogEntry.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/ILogEntry.java @@ -1,53 +1,53 @@ -package org.eclipse.team.ccvs.core; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.core.runtime.IAdaptable; - -/** - * Instances of ILogEntry represent an entry for a CVS file that results - * from the cvs log command. - * - * Clients are not expected to implement this interface - */ -public interface ILogEntry extends IAdaptable { - - /** - * Get the revision for the entry - */ - public String getRevision(); - - /** - * Get the author of the revision - */ - public String getAuthor(); - - /** - * Get the date the revision was committed - */ - public String getDate(); - - /** - * Get the comment for the revision - */ - public String getComment(); - - /** - * Get the state - */ - public String getState(); - - /** - * Get the tags associated with the revision - */ - public ICVSTag[] getTags(); - - /** - * Get the remote file for this entry - */ - public ICVSRemoteFile getRemoteFile(); -} - +package org.eclipse.team.ccvs.core;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.core.runtime.IAdaptable;
+
+/**
+ * Instances of ILogEntry represent an entry for a CVS file that results
+ * from the cvs log command.
+ *
+ * Clients are not expected to implement this interface
+ */
+public interface ILogEntry extends IAdaptable {
+
+ /**
+ * Get the revision for the entry
+ */
+ public String getRevision();
+
+ /**
+ * Get the author of the revision
+ */
+ public String getAuthor();
+
+ /**
+ * Get the date the revision was committed
+ */
+ public String getDate();
+
+ /**
+ * Get the comment for the revision
+ */
+ public String getComment();
+
+ /**
+ * Get the state
+ */
+ public String getState();
+
+ /**
+ * Get the tags associated with the revision
+ */
+ public CVSTag[] getTags();
+
+ /**
+ * Get the remote file for this entry
+ */
+ public ICVSRemoteFile getRemoteFile();
+}
+
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/Policy.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/Policy.java index cfd9b2cdb..baedaa11f 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/Policy.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/Policy.java @@ -1,98 +1,98 @@ -package org.eclipse.team.internal.ccvs.core; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.text.MessageFormat; -import java.util.MissingResourceException; -import java.util.ResourceBundle; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.OperationCanceledException; -import org.eclipse.core.runtime.SubProgressMonitor; - -public class Policy { - protected static ResourceBundle bundle = null; - - /** - * Creates a NLS catalog for the given locale. - */ - public static void localize(String bundleName) { - bundle = ResourceBundle.getBundle(bundleName); - } - - /** - * Lookup the message with the given ID in this catalog and bind its - * substitution locations with the given string. - */ - public static String bind(String id, String binding) { - return bind(id, new String[] { binding }); - } - - /** - * Lookup the message with the given ID in this catalog and bind its - * substitution locations with the given strings. - */ - public static String bind(String id, String binding1, String binding2) { - return bind(id, new String[] { binding1, binding2 }); - } - - /** - * Gets a string from the resource bundle. We don't want to crash because of a missing String. - * Returns the key if not found. - */ - public static String bind(String key) { - try { - return bundle.getString(key); - } catch (MissingResourceException e) { - return key; - } catch (NullPointerException e) { - return "!" + key + "!"; - } - } - - /** - * Gets a string from the resource bundle and binds it with the given arguments. If the key is - * not found, return the key. - */ - public static String bind(String key, Object[] args) { - try { - return MessageFormat.format(bind(key), args); - } catch (MissingResourceException e) { - return key; - } catch (NullPointerException e) { - return "!" + key + "!"; - } - } - - /** - * Progress monitor helpers - */ - public static void checkCanceled(IProgressMonitor monitor) { - if (monitor.isCanceled()) - throw new OperationCanceledException(); - } - public static IProgressMonitor monitorFor(IProgressMonitor monitor) { - if (monitor == null) - return new NullProgressMonitor(); - return monitor; - } - - public static IProgressMonitor subMonitorFor(IProgressMonitor monitor, int ticks) { - if (monitor == null) - return new NullProgressMonitor(); - if (monitor instanceof NullProgressMonitor) - return monitor; - return new SubProgressMonitor(monitor, ticks); - } - public static IProgressMonitor subMonitorFor(IProgressMonitor monitor, int ticks, int style) { - if (monitor == null) - return new NullProgressMonitor(); - if (monitor instanceof NullProgressMonitor) - return monitor; - return new SubProgressMonitor(monitor, ticks, style); - } +package org.eclipse.team.internal.ccvs.core;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.text.MessageFormat;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.SubProgressMonitor;
+
+public class Policy {
+ protected static ResourceBundle bundle = null;
+
+ /**
+ * Creates a NLS catalog for the given locale.
+ */
+ public static void localize(String bundleName) {
+ bundle = ResourceBundle.getBundle(bundleName);
+ }
+
+ /**
+ * Lookup the message with the given ID in this catalog and bind its
+ * substitution locations with the given string.
+ */
+ public static String bind(String id, String binding) {
+ return bind(id, new String[] { binding });
+ }
+
+ /**
+ * Lookup the message with the given ID in this catalog and bind its
+ * substitution locations with the given strings.
+ */
+ public static String bind(String id, String binding1, String binding2) {
+ return bind(id, new String[] { binding1, binding2 });
+ }
+
+ /**
+ * Gets a string from the resource bundle. We don't want to crash because of a missing String.
+ * Returns the key if not found.
+ */
+ public static String bind(String key) {
+ try {
+ return bundle.getString(key);
+ } catch (MissingResourceException e) {
+ return key;
+ } catch (NullPointerException e) {
+ return "!" + key + "!";
+ }
+ }
+
+ /**
+ * Gets a string from the resource bundle and binds it with the given arguments. If the key is
+ * not found, return the key.
+ */
+ public static String bind(String key, Object[] args) {
+ try {
+ return MessageFormat.format(bind(key), args);
+ } catch (MissingResourceException e) {
+ return key;
+ } catch (NullPointerException e) {
+ return "!" + key + "!";
+ }
+ }
+
+ /**
+ * Progress monitor helpers
+ */
+ public static void checkCanceled(IProgressMonitor monitor) {
+ if (monitor.isCanceled())
+ throw new OperationCanceledException();
+ }
+ public static IProgressMonitor monitorFor(IProgressMonitor monitor) {
+ if (monitor == null)
+ return new NullProgressMonitor();
+ return monitor;
+ }
+
+ public static IProgressMonitor subMonitorFor(IProgressMonitor monitor, int ticks) {
+ if (monitor == null)
+ return new NullProgressMonitor();
+ if (monitor instanceof NullProgressMonitor)
+ return monitor;
+ return new SubProgressMonitor(monitor, ticks);
+ }
+ public static IProgressMonitor subMonitorFor(IProgressMonitor monitor, int ticks, int style) {
+ if (monitor == null)
+ return new NullProgressMonitor();
+ if (monitor instanceof NullProgressMonitor)
+ return monitor;
+ return new SubProgressMonitor(monitor, ticks, style);
+ }
}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/AbstractMessageCommand.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/AbstractMessageCommand.java index 39b75226c..f8b59d1a9 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/AbstractMessageCommand.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/AbstractMessageCommand.java @@ -1,55 +1,51 @@ -package org.eclipse.team.internal.ccvs.core.commands; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.team.internal.ccvs.core.util.Assert; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.requests.RequestSender; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedResource; -import org.eclipse.team.internal.ccvs.core.response.ResponseDispatcher; - -/** - * Superclass for commands that do not change the structure on - * the local working copy (it can change the content of the files).<br> - * Most of the subclasses are asking the server for response in - * message format (log, status) - */ -abstract class AbstractMessageCommand extends Command { - - /** - * Constructor for AbstractMessageCommand. - * @param responseDispatcher - * @param requestSender - */ - public AbstractMessageCommand( - ResponseDispatcher responseDispatcher, - RequestSender requestSender) { - super(responseDispatcher, requestSender); - } - - /** - * @see Command#sendRequestsToServer(IProgressMonitor) - */ - protected void sendRequestsToServer(IProgressMonitor monitor) - throws CVSException { - - IManagedResource[] mWorkResources; - - // NOTE: We could save ourselves a bit if work by getting - // the resources first and passing them as arguments - Assert.isTrue(allResourcesManaged()); - - // Get the folders we want to work on - mWorkResources = getWorkResources(); - - // Send all folders that are already managed to the server - sendFileStructure(mWorkResources,monitor,false,false); - sendHomeFolder(); - } - -} - +package org.eclipse.team.internal.ccvs.core.commands;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.team.internal.ccvs.core.util.Assert;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.requests.RequestSender;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSResource;
+import org.eclipse.team.internal.ccvs.core.response.ResponseDispatcher;
+
+/**
+ * Superclass for commands that do not change the structure on
+ * the local working copy (it can change the content of the files).<br>
+ * Most of the subclasses are asking the server for response in
+ * message format (log, status)
+ */
+abstract class AbstractMessageCommand extends Command {
+
+ /**
+ * Constructor for AbstractMessageCommand.
+ * @param responseDispatcher
+ * @param requestSender
+ */
+ public AbstractMessageCommand(
+ ResponseDispatcher responseDispatcher,
+ RequestSender requestSender) {
+ super(responseDispatcher, requestSender);
+ }
+
+ /**
+ * @see Command#sendRequestsToServer(IProgressMonitor)
+ */
+ protected void sendRequestsToServer(IProgressMonitor monitor)
+ throws CVSException {
+
+ ICVSResource[] mWorkResources;
+
+ // Get the folders we want to work on
+ mWorkResources = getWorkResources();
+
+ // Send all folders that are already managed to the server
+ sendFileStructure(mWorkResources,monitor,false,false);
+ sendHomeFolder();
+ }
+
+}
+
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/AbstractStructureVisitor.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/AbstractStructureVisitor.java index d83bcf4dd..085c69771 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/AbstractStructureVisitor.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/AbstractStructureVisitor.java @@ -1,137 +1,142 @@ -package org.eclipse.team.internal.ccvs.core.commands; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.requests.RequestSender; -import org.eclipse.team.internal.ccvs.core.resources.api.FileProperties; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFile; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFolder; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedVisitor; -import org.eclipse.team.internal.ccvs.core.util.Assert; - -/** - * An IManagedVisitor that is superclass to all IManagedVisitor's used - * by Command and it's subclasses. - * Provides helper methods to send files and folders with modifications - * to the server. - */ -abstract class AbstractStructureVisitor implements IManagedVisitor { - - private final RequestSender requestSender; - private final IManagedFolder mRoot; - private final IProgressMonitor monitor; - //The last folder that has already been sent to the server during this visit - private IManagedFolder lastFolderSend; - - public AbstractStructureVisitor(RequestSender requestSender, - IManagedFolder mRoot, - IProgressMonitor monitor) { - - this.requestSender = requestSender; - this.mRoot = mRoot; - this.monitor = monitor; - } - - /** - * Send the folder relative to the root to the server. Send all - * appropiate modifier like Sticki, Questionable, Static-directory. - * <br> - * If this folder was send last, it is not resend again (there is - * no advantage of doing so). - */ - void sendFolder(IManagedFolder mFolder, - boolean constructFolder, - boolean sendQuestionable) - throws CVSException{ - - String local; - String remote; - String tag; - - // Do not send the same folder twice - if (mFolder.equals(lastFolderSend)) { - return; - } - - local = mFolder.getRelativePath(mRoot); - - if (constructFolder && mFolder.exists()) { - requestSender.sendConstructedDirectory(local,local); - lastFolderSend = mFolder; - return; - } - - if (sendQuestionable && !mFolder.isCVSFolder()) { - // This implies, that the mFolder exists - - // If we have not send the parent-folder of this - // folder we have to send the parent-folder to have - // this questianable below this parent-folder - Assert.isTrue(mFolder.getParent().isCVSFolder()); - sendFolder(mFolder.getParent(),constructFolder,sendQuestionable); - - requestSender.sendQuestionable(mFolder.getName()); - return; - } - - remote = mFolder.getRemoteLocation(mRoot); - - if (remote != null) { - requestSender.sendDirectory(local, remote); - } - - if (mFolder.getFolderInfo() != null) { - - if (mFolder.getFolderInfo().getStaticFolder()) { - requestSender.sendStaticDirectory(); - } - - tag = mFolder.getFolderInfo().getTag(); - - if (tag != null) { - requestSender.sendSticky(tag); - } - } - - // Remember, that we send this folder - lastFolderSend = mFolder; - } - - /** - * Send a file up to the server. - * If it is modified send the content as well. - */ - void sendFile(IManagedFile mFile, - boolean sendQuestionable, - String mode) throws CVSException { - - boolean binary = mode!=null && - mode.indexOf(FileProperties.BINARY_TAG)!=-1; - - if (mFile.isManaged()) { - requestSender.sendEntry(mFile.getFileInfo().getEntryLineForServer()); - } else if (sendQuestionable) { - requestSender.sendQuestionable(mFile.getName()); - return; - // The client does not do it and we do not know whether to do it - // } else if (mode != null && !"".equals(mode)) { - // requestSender.sendKopt(mode); - } - - if (!mFile.exists()) { - return; - } - - if (mFile.isDirty()) { - requestSender.sendModified(mFile,monitor,binary); - } else { - requestSender.sendUnchanged(mFile.getName()); - } - } -} - +package org.eclipse.team.internal.ccvs.core.commands;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.requests.RequestSender;
+import org.eclipse.team.internal.ccvs.core.resources.CVSEntryLineTag;
+import org.eclipse.team.internal.ccvs.core.resources.FolderSyncInfo;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFile;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFolder;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSResourceVisitor;
+import org.eclipse.team.internal.ccvs.core.resources.ResourceSyncInfo;
+import org.eclipse.team.internal.ccvs.core.util.Assert;
+
+/**
+ * An ICVSResourceVisitor that is superclass to all ICVSResourceVisitor's used
+ * by Command and it's subclasses.
+ * Provides helper methods to send files and folders with modifications
+ * to the server.
+ */
+abstract class AbstractStructureVisitor implements ICVSResourceVisitor {
+
+ private final RequestSender requestSender;
+ private final ICVSFolder mRoot;
+ private final IProgressMonitor monitor;
+ //The last folder that has already been sent to the server during this visit
+ private ICVSFolder lastFolderSend;
+
+ public AbstractStructureVisitor(RequestSender requestSender,
+ ICVSFolder mRoot,
+ IProgressMonitor monitor) {
+
+ this.requestSender = requestSender;
+ this.mRoot = mRoot;
+ this.monitor = monitor;
+ }
+
+ /**
+ * Send the folder relative to the root to the server. Send all
+ * appropiate modifier like Sticki, Questionable, Static-directory.
+ * <br>
+ * If this folder was send last, it is not resend again (there is
+ * no advantage of doing so).
+ */
+ void sendFolder(ICVSFolder mFolder,
+ boolean constructFolder,
+ boolean sendQuestionable)
+ throws CVSException{
+
+ String local;
+ String remote;
+ CVSEntryLineTag tag;
+
+ // Do not send the same folder twice
+ if (mFolder.equals(lastFolderSend)) {
+ return;
+ }
+
+ local = mFolder.getRelativePath(mRoot);
+
+ if (constructFolder && mFolder.exists()) {
+ requestSender.sendConstructedDirectory(local,local);
+ lastFolderSend = mFolder;
+ return;
+ }
+
+ if (sendQuestionable && !mFolder.isCVSFolder()) {
+ // This implies, that the mFolder exists
+
+ // If we have not send the parent-folder of this
+ // folder we have to send the parent-folder to have
+ // this questianable below this parent-folder
+ Assert.isTrue(mFolder.getParent().isCVSFolder());
+ sendFolder(mFolder.getParent(),constructFolder,sendQuestionable);
+
+ requestSender.sendQuestionable(mFolder.getName());
+ return;
+ }
+
+ remote = mFolder.getRemoteLocation(mRoot);
+
+ if (remote == null) {
+ return;
+ }
+
+ requestSender.sendDirectory(local, remote);
+
+ FolderSyncInfo info = mFolder.getFolderSyncInfo();
+ if (info != null) {
+
+ if (info.getIsStatic()) {
+ requestSender.sendStaticDirectory();
+ }
+
+ tag = info.getTag();
+
+ if (tag != null) {
+ requestSender.sendSticky(tag.toEntryLineFormat());
+ }
+ }
+
+ // Remember, that we send this folder
+ lastFolderSend = mFolder;
+ }
+
+ /**
+ * Send a file up to the server.
+ * If it is modified send the content as well.
+ */
+ void sendFile(ICVSFile mFile,
+ boolean sendQuestionable,
+ String mode) throws CVSException {
+
+ boolean binary = mode!=null &&
+ mode.indexOf(ResourceSyncInfo.BINARY_TAG)!=-1;
+
+ if (mFile.isManaged()) {
+ requestSender.sendEntry(mFile.getSyncInfo().getEntryLine(false));
+ } else if (sendQuestionable) {
+ requestSender.sendQuestionable(mFile.getName());
+ return;
+ // The client does not do it and we do not know whether to do it
+ // } else if (mode != null && !"".equals(mode)) {
+ // requestSender.sendKopt(mode);
+ }
+
+ if (!mFile.exists()) {
+ return;
+ }
+
+ if (mFile.isDirty()) {
+ requestSender.sendModified(mFile,monitor,binary);
+ } else {
+ requestSender.sendUnchanged(mFile.getName());
+ }
+ }
+}
+
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/Add.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/Add.java index 916ffc7d1..e7e9c1998 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/Add.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/Add.java @@ -1,123 +1,123 @@ -package org.eclipse.team.internal.ccvs.core.commands; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.team.internal.ccvs.core.util.Assert; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.Client; -import org.eclipse.team.internal.ccvs.core.requests.RequestSender; -import org.eclipse.team.internal.ccvs.core.resources.api.FolderProperties; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFolder; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedResource; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedVisitor; -import org.eclipse.team.internal.ccvs.core.response.ResponseDispatcher; - -class Add extends Command { - - /** - * Constructor for Add. - * @param responseDispatcher - * @param requestSender - */ - public Add(ResponseDispatcher responseContainer, RequestSender requestSender) { - super(responseContainer, requestSender); - } - - /** - * @see ICommand#getName() - */ - public String getName() { - return RequestSender.ADD; - } - - /** - * @see ICommand#getRequestName() - */ - public String getRequestName() { - return RequestSender.ADD; - } - - /** - * Checks wether all the arguments (that are meand as Files/Folders) - * to add, can give a remoteLocation (that is needed to add them) - */ - protected boolean canTraverse() { - - IManagedResource[] mWorkResources; - - try { - mWorkResources = getWorkResources(); - - for (int i=0; i<mWorkResources.length; i++) { - Assert.isNotNull(mWorkResources[i].getRemoteLocation(getRoot())); - } - } catch (CVSException e) { - Assert.isTrue(false); - } - - return true; - } - - /** - * @see Command#sendRequestsToServer(IProgressMonitor) - */ - protected void sendRequestsToServer(IProgressMonitor monitor) throws CVSException { - - IManagedResource[] mWorkResources; - IManagedVisitor vistor; - - Assert.isTrue(getArguments().length != 0); - - // Check that all the arguments can give you an - // repo that you will need while traversing the - // file-structure - Assert.isTrue(canTraverse()); - - // Get a vistor and use it on every resource we should - // work on - vistor = new AddStructureVisitor(requestSender,getRoot(),monitor); - mWorkResources = getWorkResources(); - for (int i = 0; i < mWorkResources.length; i++) { - mWorkResources[i].accept(vistor); - } - - sendHomeFolder(); - } - - /** - * If we were successful in adding, then acctually managed - * the folders on disk - */ - protected void finished(boolean succsess) throws CVSException { - - IManagedFolder mFolder; - IManagedResource[] mWorkResources; - FolderProperties folderInfo; - - mWorkResources = getWorkResources(); - - if (!succsess) { - return; - } - - for (int i=0; i<mWorkResources.length; i++) { - if (mWorkResources[i].isFolder()) { - - mFolder = (IManagedFolder) mWorkResources[i]; - - folderInfo = mFolder.getParent().getFolderInfo(); - folderInfo.setRepository(folderInfo.getRepository() + - Client.SERVER_SEPARATOR + mFolder.getName()); - mFolder.setFolderInfo(folderInfo); - - } - } - - } - -} - +package org.eclipse.team.internal.ccvs.core.commands;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.Client;
+import org.eclipse.team.internal.ccvs.core.requests.RequestSender;
+import org.eclipse.team.internal.ccvs.core.resources.FolderSyncInfo;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFolder;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSResource;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSResourceVisitor;
+import org.eclipse.team.internal.ccvs.core.response.ResponseDispatcher;
+import org.eclipse.team.internal.ccvs.core.util.Assert;
+
+class Add extends Command {
+
+ /**
+ * Constructor for Add.
+ * @param responseDispatcher
+ * @param requestSender
+ */
+ public Add(ResponseDispatcher responseContainer, RequestSender requestSender) {
+ super(responseContainer, requestSender);
+ }
+
+ /**
+ * @see ICommand#getName()
+ */
+ public String getName() {
+ return RequestSender.ADD;
+ }
+
+ /**
+ * @see ICommand#getRequestName()
+ */
+ public String getRequestName() {
+ return RequestSender.ADD;
+ }
+
+ /**
+ * Checks wether all the arguments (that are meand as Files/Folders)
+ * to add, can give a remoteLocation (that is needed to add them)
+ */
+ protected boolean canTraverse() {
+
+ ICVSResource[] mWorkResources;
+
+ try {
+ mWorkResources = getWorkResources();
+
+ for (int i=0; i<mWorkResources.length; i++) {
+ Assert.isNotNull(mWorkResources[i].getRemoteLocation(getRoot()));
+ }
+ } catch (CVSException e) {
+ Assert.isTrue(false);
+ }
+
+ return true;
+ }
+
+ /**
+ * @see Command#sendRequestsToServer(IProgressMonitor)
+ */
+ protected void sendRequestsToServer(IProgressMonitor monitor) throws CVSException {
+
+ ICVSResource[] mWorkResources;
+ ICVSResourceVisitor vistor;
+
+ Assert.isTrue(getArguments().length != 0);
+
+ // Check that all the arguments can give you an
+ // repo that you will need while traversing the
+ // file-structure
+ Assert.isTrue(canTraverse());
+
+ // Get a vistor and use it on every resource we should
+ // work on
+ vistor = new AddStructureVisitor(requestSender,getRoot(),monitor);
+ mWorkResources = getWorkResources();
+ for (int i = 0; i < mWorkResources.length; i++) {
+ mWorkResources[i].accept(vistor);
+ }
+
+ sendHomeFolder();
+ }
+
+ /**
+ * If we were successful in adding, then acctually managed
+ * the folders on disk
+ */
+ protected void finished(boolean succsess) throws CVSException {
+
+ ICVSFolder mFolder;
+ ICVSResource[] mWorkResources;
+
+ mWorkResources = getWorkResources();
+
+ if (!succsess) {
+ return;
+ }
+
+ for (int i=0; i<mWorkResources.length; i++) {
+ if (mWorkResources[i].isFolder()) {
+
+ mFolder = (ICVSFolder) mWorkResources[i];
+
+ FolderSyncInfo folderInfo = mFolder.getParent().getFolderSyncInfo();
+
+ folderInfo.setRepository(folderInfo.getRepository() +
+ Client.SERVER_SEPARATOR + mFolder.getName());
+
+ mFolder.setFolderSyncInfo(folderInfo);
+ }
+ }
+
+ }
+
+}
+
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/AddStructureVisitor.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/AddStructureVisitor.java index 95c2c6dae..a6ea774f4 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/AddStructureVisitor.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/AddStructureVisitor.java @@ -1,92 +1,92 @@ -package org.eclipse.team.internal.ccvs.core.commands; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.util.HashSet; -import java.util.Set; - -import org.eclipse.team.internal.ccvs.core.util.Assert; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.requests.RequestSender; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFile; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFolder; - -/** - * This is a visitor that is specially created for the add-command.<br> - * It traverses the file-structure in the other direction, so that - * all the parents are send until a parent is found that should allready - * be known by the to the root are send.<br> - * The visitor remembers the folders it has allready been to and does not - * send them again (if possible). - */ -public class AddStructureVisitor extends AbstractStructureVisitor { - - private boolean forceSend = false; - private Set visitedFolders = new HashSet(); - private IManagedFolder lastVisitedFolder; - private IManagedFolder mRoot; - private RequestSender requestSender; - - /** - * Constructor for AddStructureVisitor. - * @param requestSender - * @param mRoot - * @param monitor - */ - public AddStructureVisitor( - RequestSender requestSender, - IManagedFolder mRoot, - IProgressMonitor monitor) { - super(requestSender, mRoot, monitor); - this.mRoot = mRoot; - this.requestSender = requestSender; - } - - /** - * @see IManagedVisitor#visitFile(IManagedFile) - */ - public void visitFile(IManagedFile mFile) throws CVSException { - - if (!mFile.getParent().equals(lastVisitedFolder)) { - forceSend = true; - mFile.getParent().accept(this); - } - - // We just send the fact, that the file is modified - // not the data, we do not need it. - requestSender.sendIsModified(mFile.getName()); - - } - - /** - * @see IManagedVisitor#visitFolder(IManagedFolder) - */ - public void visitFolder(IManagedFolder mFolder) throws CVSException { - - Assert.isNotNull(mFolder); - - // Save the status wheter we want to send - // this folder in every case - boolean alreadyVisited; - boolean forceSend = this.forceSend; - this.forceSend = false; - - alreadyVisited = visitedFolders.contains(mFolder); - - if (!mFolder.equals(mRoot) && !alreadyVisited) { - mFolder.getParent().accept(this); - } - - if (forceSend || !alreadyVisited) { - visitedFolders.add(mFolder); - lastVisitedFolder = mFolder; - sendFolder(mFolder,false,false); - } - } - -} - +package org.eclipse.team.internal.ccvs.core.commands;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.team.internal.ccvs.core.util.Assert;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.requests.RequestSender;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFile;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFolder;
+
+/**
+ * This is a visitor that is specially created for the add-command.<br>
+ * It traverses the file-structure in the other direction, so that
+ * all the parents are send until a parent is found that should allready
+ * be known by the to the root are send.<br>
+ * The visitor remembers the folders it has allready been to and does not
+ * send them again (if possible).
+ */
+public class AddStructureVisitor extends AbstractStructureVisitor {
+
+ private boolean forceSend = false;
+ private Set visitedFolders = new HashSet();
+ private ICVSFolder lastVisitedFolder;
+ private ICVSFolder mRoot;
+ private RequestSender requestSender;
+
+ /**
+ * Constructor for AddStructureVisitor.
+ * @param requestSender
+ * @param mRoot
+ * @param monitor
+ */
+ public AddStructureVisitor(
+ RequestSender requestSender,
+ ICVSFolder mRoot,
+ IProgressMonitor monitor) {
+ super(requestSender, mRoot, monitor);
+ this.mRoot = mRoot;
+ this.requestSender = requestSender;
+ }
+
+ /**
+ * @see ICVSResourceVisitor#visitFile(IManagedFile)
+ */
+ public void visitFile(ICVSFile mFile) throws CVSException {
+
+ if (!mFile.getParent().equals(lastVisitedFolder)) {
+ forceSend = true;
+ mFile.getParent().accept(this);
+ }
+
+ // We just send the fact, that the file is modified
+ // not the data, we do not need it.
+ requestSender.sendIsModified(mFile.getName());
+
+ }
+
+ /**
+ * @see ICVSResourceVisitor#visitFolder(ICVSFolder)
+ */
+ public void visitFolder(ICVSFolder mFolder) throws CVSException {
+
+ Assert.isNotNull(mFolder);
+
+ // Save the status wheter we want to send
+ // this folder in every case
+ boolean alreadyVisited;
+ boolean forceSend = this.forceSend;
+ this.forceSend = false;
+
+ alreadyVisited = visitedFolders.contains(mFolder);
+
+ if (!mFolder.equals(mRoot) && !alreadyVisited) {
+ mFolder.getParent().accept(this);
+ }
+
+ if (forceSend || !alreadyVisited) {
+ visitedFolders.add(mFolder);
+ lastVisitedFolder = mFolder;
+ sendFolder(mFolder,false,false);
+ }
+ }
+
+}
+
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/Admin.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/Admin.java index 69baa6b7f..6483fef5e 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/Admin.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/Admin.java @@ -1,39 +1,39 @@ -package org.eclipse.team.internal.ccvs.core.commands; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.team.internal.ccvs.core.requests.RequestSender; -import org.eclipse.team.internal.ccvs.core.response.ResponseDispatcher; - -public class Admin extends AbstractMessageCommand { - - /** - * Constructor for Admin. - * @param responseDispatcher - * @param requestSender - */ - public Admin( - ResponseDispatcher responseContainer, - RequestSender requestSender) { - super(responseContainer, requestSender); - } - - /** - * @see ICommand#getName() - */ - public String getName() { - return RequestSender.ADMIN; - } - - /** - * @see ICommand#getRequestName() - */ - public String getRequestName() { - return RequestSender.ADMIN; - } - -} - +package org.eclipse.team.internal.ccvs.core.commands;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.team.internal.ccvs.core.requests.RequestSender;
+import org.eclipse.team.internal.ccvs.core.response.ResponseDispatcher;
+
+public class Admin extends AbstractMessageCommand {
+
+ /**
+ * Constructor for Admin.
+ * @param responseDispatcher
+ * @param requestSender
+ */
+ public Admin(
+ ResponseDispatcher responseContainer,
+ RequestSender requestSender) {
+ super(responseContainer, requestSender);
+ }
+
+ /**
+ * @see ICommand#getName()
+ */
+ public String getName() {
+ return RequestSender.ADMIN;
+ }
+
+ /**
+ * @see ICommand#getRequestName()
+ */
+ public String getRequestName() {
+ return RequestSender.ADMIN;
+ }
+
+}
+
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/Checkout.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/Checkout.java index 30a529ccc..272f62bd0 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/Checkout.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/Checkout.java @@ -1,60 +1,60 @@ -package org.eclipse.team.internal.ccvs.core.commands; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.team.internal.ccvs.core.util.Assert; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.requests.RequestSender; -import org.eclipse.team.internal.ccvs.core.response.ResponseDispatcher; - -class Checkout extends Command { - - /** - * Pipe everything to the superclass - */ - public Checkout(ResponseDispatcher responseDispathcer, - RequestSender requestSender) { - super(responseDispathcer,requestSender); - } - - /** - * @see Request#getName() - */ - public String getName() { - return RequestSender.CHECKOUT; - } - - /** - * @see ICommand#getRequestName() - */ - public String getRequestName() { - return RequestSender.CHECKOUT; - } - - /** - * Start the Checkout command: - * Send the module that is going to be checked-out to the server - * by reading the name of the resource given - * (This has to change to we give it the name of the modul and the - * Checkout creates everything for us) - * - * - * @see Request#setUp(IRequestContext) - */ - protected void sendRequestsToServer(IProgressMonitor monitor) throws CVSException { - - // We need a folder to put the project(s) we checkout into - Assert.isTrue(getRoot().isFolder()); - - // Just send the homefolder, and do not look into - // the CVS-Folder to send it to the server - // (this could be changed to make it compatible) - sendHomeFolder(false); - - } - +package org.eclipse.team.internal.ccvs.core.commands;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.team.internal.ccvs.core.util.Assert;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.requests.RequestSender;
+import org.eclipse.team.internal.ccvs.core.response.ResponseDispatcher;
+
+class Checkout extends Command {
+
+ /**
+ * Pipe everything to the superclass
+ */
+ public Checkout(ResponseDispatcher responseDispathcer,
+ RequestSender requestSender) {
+ super(responseDispathcer,requestSender);
+ }
+
+ /**
+ * @see Request#getName()
+ */
+ public String getName() {
+ return RequestSender.CHECKOUT;
+ }
+
+ /**
+ * @see ICommand#getRequestName()
+ */
+ public String getRequestName() {
+ return RequestSender.CHECKOUT;
+ }
+
+ /**
+ * Start the Checkout command:
+ * Send the module that is going to be checked-out to the server
+ * by reading the name of the resource given
+ * (This has to change to we give it the name of the modul and the
+ * Checkout creates everything for us)
+ *
+ *
+ * @see Request#setUp(IRequestContext)
+ */
+ protected void sendRequestsToServer(IProgressMonitor monitor) throws CVSException {
+
+ // We need a folder to put the project(s) we checkout into
+ Assert.isTrue(getRoot().isFolder());
+
+ // Just send the homefolder, and do not look into
+ // the CVS-Folder to send it to the server
+ // (this could be changed to make it compatible)
+ sendHomeFolder(false);
+
+ }
+
}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/Command.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/Command.java index b48a66c16..e1499a61f 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/Command.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/Command.java @@ -1,378 +1,344 @@ -package org.eclipse.team.internal.ccvs.core.commands; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.io.PrintStream; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.OperationCanceledException; -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.Client; -import org.eclipse.team.internal.ccvs.core.Policy; -import org.eclipse.team.internal.ccvs.core.connection.CVSServerException; -import org.eclipse.team.internal.ccvs.core.requests.RequestSender; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFolder; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedResource; -import org.eclipse.team.internal.ccvs.core.response.ResponseDispatcher; -import org.eclipse.team.internal.ccvs.core.util.Assert; - -/** - * Abstract base class for the commands which implements the ICommand - * interface so subclasses can be added to the CommandDispatcher. - * - * Also you do not need to use this class to implement commands - * because the dispatcher makes use of ICommand only. However, all - * the current command are derived from this class. - */ -abstract class Command implements ICommand { - - private String[] globalOptions; - private String[] localOptions; - private String[] arguments; - - private IManagedFolder mRoot; - - protected final ResponseDispatcher responseDispatcher; - protected final RequestSender requestSender; - - /** - * The CommandDispatcher, the ResponseDispatcher and - * the RequestSender are the three major objects in - * the client. - * - * ResponseDispatcher is used to process the response form the server. - * RequestSender is used to send requests to the server. - */ - public Command(ResponseDispatcher responseDispatcher, - RequestSender requestSender) { - - this.responseDispatcher = responseDispatcher; - this.requestSender = requestSender; - } - - /** - * Execute the given command. Do so by invoking the sendRequestsToServer method. - * Does handle the work with the progress-monitor. - * - * @see ICommand#execute(Connection, String[], String[], ICVSResource, OutputStream) - */ - public void execute ( - String[] globalOptions, - String[] localOptions, - String[] arguments, - IManagedFolder mRoot, - IProgressMonitor monitor, - PrintStream messageOut) - throws CVSException { - - // Record the arguments so subclass can access them using the get methods - this.mRoot = mRoot; - this.globalOptions = globalOptions; - this.localOptions = localOptions; - this.arguments = arguments; - - try { - - monitor = Policy.monitorFor(monitor); - monitor.beginTask(Policy.bind("Command.server"), 100); - Policy.checkCanceled(monitor); - - // Send the options to the server (the command itself has to care - // about the arguments) - // It is questionable if this is going to stay here, because - // NOTE: because why? - sendGlobalOptions(); - sendLocalOptions(); - - // Guess that set up contributes 20% of work. - sendRequestsToServer(Policy.subMonitorFor(monitor, 20)); - Policy.checkCanceled(monitor); - - // Send all arguments to the server - sendArguments(); - // Send the request name to the server - requestSender.writeLine(getRequestName()); - - try { - // Processing responses contributes 70% of work. - responseDispatcher.manageResponse(Policy.subMonitorFor(monitor, 70), mRoot, messageOut); - - } catch (CVSException e) { - finished(false); - throw e; - } - // Finished adds last 10% of work. - finished(true); - monitor.worked(10); - } finally { - monitor.done(); - } - - } - - /** - * Abstract method to send the complete arguments of the command to the server. - * The command itself is not sent here but in the execute method. - */ - protected abstract void sendRequestsToServer(IProgressMonitor monitor) throws CVSException; - - /** - * Called after command has been executed to allow subclasses to cleanup. - * Default is to do nothing. - */ - protected void finished(boolean success) throws CVSException { - } - - /** - * Sends the arguments to the server. - */ - protected void sendArguments() throws CVSException { - if (arguments == null) { - return; - } - for (int i= 0; i < arguments.length; i++) { - requestSender.sendArgument(arguments[i]); - } - } - - /** - * Sends localOptions to the server. - */ - protected void sendLocalOptions() throws CVSException { - if (localOptions == null) - return; - for (int i= 0; i < localOptions.length; i++) { - requestSender.sendArgument(localOptions[i]); - } - } - - /** - * Sends the global options to the server. - * - * It is allowed for the globalOptions to have null-values so this - * method has to cope with null-values in the array. Also, the - * global options may be null at all. - */ - protected void sendGlobalOptions() throws CVSException { - if (globalOptions == null) { - return; - } - for (int i= 0; i < globalOptions.length; i++) { - if (globalOptions[i] != null) { - requestSender.sendGlobalOption(globalOptions[i]); - } - } - } - - /** - * Send the homefolder as last thing before you send (eventually the - * arguments and then) the command. - * - * lookLocal specifies whether the system tries to look into the - * CVS properties for the folder. - */ - protected void sendHomeFolder(boolean lookLocal) throws CVSException { - if (lookLocal && mRoot.isCVSFolder()) { - requestSender.sendDirectory(Client.CURRENT_LOCAL_FOLDER, mRoot.getRemoteLocation(mRoot)); - } else { - requestSender.sendConstructedDirectory(Client.CURRENT_LOCAL_FOLDER, Client.CURRENT_REMOTE_FOLDER); - } - } - - /** - * Send the homefolder as last thing before you send (eventually the - * arguments and then) the command - */ - protected void sendHomeFolder() throws CVSException { - sendHomeFolder(true); - } - - /** - * Gets the getGlobalOptions - * @return Returns a String[] - */ - protected String[] getGlobalOptions() { - return globalOptions; - } - - /** - * Gets the arguments - * @return Returns a String[] - */ - protected String[] getArguments() { - return arguments; - } - - /** - * Gets the localOptions - * @return Returns a String[] - */ - protected String[] getLocalOptions() { - return localOptions; - } - - /** - * getRoot returns the folder the client was called with. - * (Sometimes that is not the folder you want to work with) - * - * @return Returns a ICVSResource - */ - protected IManagedFolder getRoot() throws CVSException { - - if (!mRoot.isFolder()) { - throw new CVSException(Policy.bind("Command.invalidRoot", new Object[] {mRoot.toString()})); - } - - return mRoot; - } - - /** - * Takes all the arguments and gives them back as resources from the - * root. This represents all the resources the client should work on. - * - * If there are no arguments gives the root folder back only. - */ - protected IManagedResource[] getWorkResources() throws CVSException { - return getWorkResources(0); - } - - /** - * Work like getWorkResources() but do not look at the first - * skip elements when creating the resources (this is useful when - * the first skip arguments of a command are not files but something - * else) - * - * @see Command#getWorkResources() - */ - protected IManagedResource[] getWorkResources(int skip) throws CVSException { - - IManagedResource[] result; - - Assert.isTrue(arguments.length >= skip); - - if (arguments.length == skip) { - return new IManagedResource[]{mRoot}; - } - - result = new IManagedResource[arguments.length - skip]; - - for (int i = skip; i<arguments.length; i++) { - result[i - skip] = mRoot.getChild(arguments[i]); - } - - return result; - } - - /** - * Get the resource that you are working with. This is a folder - * most of the time, but could be a file on some operations as - * well. - * - * It does also garantee that the WorkResource is a cvsFolder, - * or (if it is a file) does live in a cvsFolder. - * - * This does not apply to every operation (e.g. would not work on a - * checkout) - * - * @deprecated - */ - protected IManagedResource getWorkResource(String relativeFolderPath) throws CVSException { - - IManagedResource workResource; - IManagedFolder contextFolder; - - workResource = getRoot().getChild(relativeFolderPath); - - if (workResource.isFolder()) { - contextFolder = (IManagedFolder)workResource; - } else { - contextFolder = workResource.getParent(); - } - - if (!contextFolder.isCVSFolder()) { - throw new CVSException(Policy.bind("Command.invalidResource", new Object[] {contextFolder.toString()})); - } - - return workResource; - } - - /** - * If mResource is a folder:<br> - * Send all Directory under mResource as arguments to the server<br> - * If mResource is a file:<br> - * Send the file to the server<br> - * <br> - * Files that are changed are send with the content. - * - * @param modifiedOnly sends files that are modified only to the server - * @param emptyFolders sends the folder-entrie even if there is no file - to send in it - */ - protected void sendFileStructure(IManagedResource mResource, - IProgressMonitor monitor, - boolean modifiedOnly, - boolean emptyFolders) throws CVSException { - - FileStructureVisitor fsVisitor; - - fsVisitor = new FileStructureVisitor(requestSender,mRoot,monitor,modifiedOnly,emptyFolders); - - // FIXME: The accept should have an IProgressMonitor argment, not the above constructor - mResource.accept(fsVisitor); - - } - - /** - * Send an array of Resources. - * - * @see Command#sendFileStructure(IManagedResource,IProgressMonitor,boolean,boolean,boolean) - */ - protected void sendFileStructure(IManagedResource[] mResources, - IProgressMonitor monitor, - boolean modifiedOnly, - boolean emptyFolders) throws CVSException { - - for (int i=0; i<mResources.length; i++) { - sendFileStructure(mResources[i], - monitor, - modifiedOnly, - emptyFolders); - } - } - - /** - * Checks that all the workResources are managed Resources. - * (For folders we check isCVSFolder, because of a project-folder - * that is not managed, because it is not registerd in the - * parent-folder<br> - * To be used this way: Assert.isTrue(allArgumentsManaged()) - * - * @throws AssertionFailedException if not all the arguments are - * managed - */ - protected boolean allResourcesManaged() throws RuntimeException { - - IManagedResource[] mWorkResources; - - try { - mWorkResources = getWorkResources(); - - for (int i=0; i<mWorkResources.length; i++) { - if (mWorkResources[i].isFolder()) { - Assert.isTrue(((IManagedFolder) mWorkResources[i]).isCVSFolder()); - } else { - Assert.isTrue(mWorkResources[i].isManaged()); - } - } - } catch (CVSException e) { - Assert.isTrue(false); - } - - return true; - } - -} - +package org.eclipse.team.internal.ccvs.core.commands;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.io.PrintStream;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.Client;
+import org.eclipse.team.internal.ccvs.core.Policy;
+import org.eclipse.team.internal.ccvs.core.requests.RequestSender;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFolder;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSResource;
+import org.eclipse.team.internal.ccvs.core.response.ResponseDispatcher;
+import org.eclipse.team.internal.ccvs.core.util.Assert;
+
+/**
+ * Abstract base class for the commands which implements the ICommand
+ * interface so subclasses can be added to the CommandDispatcher.
+ *
+ * Also you do not need to use this class to implement commands
+ * because the dispatcher makes use of ICommand only. However, all
+ * the current command are derived from this class.
+ */
+abstract class Command implements ICommand {
+
+ private String[] globalOptions;
+ private String[] localOptions;
+ private String[] arguments;
+
+ private ICVSFolder mRoot;
+
+ protected final ResponseDispatcher responseDispatcher;
+ protected final RequestSender requestSender;
+
+ /**
+ * The CommandDispatcher, the ResponseDispatcher and
+ * the RequestSender are the three major objects in
+ * the client.
+ *
+ * ResponseDispatcher is used to process the response form the server.
+ * RequestSender is used to send requests to the server.
+ */
+ public Command(ResponseDispatcher responseDispatcher,
+ RequestSender requestSender) {
+
+ this.responseDispatcher = responseDispatcher;
+ this.requestSender = requestSender;
+ }
+
+ /**
+ * Execute the given command. Do so by invoking the sendRequestsToServer method.
+ * Does handle the work with the progress-monitor.
+ *
+ * @see ICommand#execute(Connection, String[], String[], ICVSResource, OutputStream)
+ */
+ public void execute (
+ String[] globalOptions,
+ String[] localOptions,
+ String[] arguments,
+ ICVSFolder mRoot,
+ IProgressMonitor monitor,
+ PrintStream messageOut)
+ throws CVSException {
+
+ // Record the arguments so subclass can access them using the get methods
+ this.mRoot = mRoot;
+ this.globalOptions = globalOptions;
+ this.localOptions = localOptions;
+ this.arguments = arguments;
+
+ try {
+
+ monitor = Policy.monitorFor(monitor);
+ monitor.beginTask(Policy.bind("Command.server"), 100);
+ Policy.checkCanceled(monitor);
+
+ // Send the options to the server (the command itself has to care
+ // about the arguments)
+ // It is questionable if this is going to stay here, because
+ // NOTE: because why?
+ sendGlobalOptions();
+ sendLocalOptions();
+
+ // Guess that set up contributes 20% of work.
+ sendRequestsToServer(Policy.subMonitorFor(monitor, 20));
+ Policy.checkCanceled(monitor);
+
+ // Send all arguments to the server
+ sendArguments();
+ // Send the request name to the server
+ requestSender.writeLine(getRequestName());
+
+ try {
+ // Processing responses contributes 70% of work.
+ responseDispatcher.manageResponse(Policy.subMonitorFor(monitor, 70), mRoot, messageOut);
+
+ } catch (CVSException e) {
+ finished(false);
+ throw e;
+ }
+ // Finished adds last 10% of work.
+ finished(true);
+ monitor.worked(10);
+ } finally {
+ monitor.done();
+ }
+
+ }
+
+ /**
+ * Abstract method to send the complete arguments of the command to the server.
+ * The command itself is not sent here but in the execute method.
+ */
+ protected abstract void sendRequestsToServer(IProgressMonitor monitor) throws CVSException;
+
+ /**
+ * Called after command has been executed to allow subclasses to cleanup.
+ * Default is to do nothing.
+ */
+ protected void finished(boolean success) throws CVSException {
+ }
+
+ /**
+ * Sends the arguments to the server.
+ */
+ protected void sendArguments() throws CVSException {
+ if (arguments == null) {
+ return;
+ }
+ for (int i= 0; i < arguments.length; i++) {
+ requestSender.sendArgument(arguments[i]);
+ }
+ }
+
+ /**
+ * Sends localOptions to the server.
+ */
+ protected void sendLocalOptions() throws CVSException {
+ if (localOptions == null)
+ return;
+ for (int i= 0; i < localOptions.length; i++) {
+ requestSender.sendArgument(localOptions[i]);
+ }
+ }
+
+ /**
+ * Sends the global options to the server.
+ *
+ * It is allowed for the globalOptions to have null-values so this
+ * method has to cope with null-values in the array. Also, the
+ * global options may be null at all.
+ */
+ protected void sendGlobalOptions() throws CVSException {
+ if (globalOptions == null) {
+ return;
+ }
+ for (int i= 0; i < globalOptions.length; i++) {
+ if (globalOptions[i] != null) {
+ requestSender.sendGlobalOption(globalOptions[i]);
+ }
+ }
+ }
+
+ /**
+ * Send the homefolder as last thing before you send (eventually the
+ * arguments and then) the command.
+ *
+ * lookLocal specifies whether the system tries to look into the
+ * CVS properties for the folder.
+ */
+ protected void sendHomeFolder(boolean lookLocal) throws CVSException {
+ if (lookLocal && mRoot.isCVSFolder()) {
+ requestSender.sendDirectory(Client.CURRENT_LOCAL_FOLDER, mRoot.getRemoteLocation(mRoot));
+ } else {
+ requestSender.sendConstructedDirectory(Client.CURRENT_LOCAL_FOLDER, Client.CURRENT_REMOTE_FOLDER);
+ }
+ }
+
+ /**
+ * Send the homefolder as last thing before you send (eventually the
+ * arguments and then) the command
+ */
+ protected void sendHomeFolder() throws CVSException {
+ sendHomeFolder(true);
+ }
+
+ /**
+ * Gets the getGlobalOptions
+ * @return Returns a String[]
+ */
+ protected String[] getGlobalOptions() {
+ return globalOptions;
+ }
+
+ /**
+ * Gets the arguments
+ * @return Returns a String[]
+ */
+ protected String[] getArguments() {
+ return arguments;
+ }
+
+ /**
+ * Gets the localOptions
+ * @return Returns a String[]
+ */
+ protected String[] getLocalOptions() {
+ return localOptions;
+ }
+
+ /**
+ * getRoot returns the folder the client was called with.
+ * (Sometimes that is not the folder you want to work with)
+ *
+ * @return Returns a ICVSResource
+ */
+ protected ICVSFolder getRoot() throws CVSException {
+
+ if (!mRoot.isFolder()) {
+ throw new CVSException(Policy.bind("Command.invalidRoot", new Object[] {mRoot.toString()}));
+ }
+
+ return mRoot;
+ }
+
+ /**
+ * Takes all the arguments and gives them back as resources from the
+ * root. This represents all the resources the client should work on.
+ *
+ * If there are no arguments gives the root folder back only.
+ */
+ protected ICVSResource[] getWorkResources() throws CVSException {
+ return getWorkResources(0);
+ }
+
+ /**
+ * Work like getWorkResources() but do not look at the first
+ * skip elements when creating the resources (this is useful when
+ * the first skip arguments of a command are not files but something
+ * else)
+ *
+ * @see Command#getWorkResources()
+ */
+ /**
+ * Work like getWorkResources() but do not look at the first
+ * skip elements when creating the resources (this is useful when
+ * the first skip arguments of a command are not files but something
+ * else)
+ *
+ * @see Command#getWorkResources()
+ */
+ protected ICVSResource[] getWorkResources(int skip) throws CVSException {
+
+ ICVSResource[] result;
+
+ Assert.isTrue(arguments.length >= skip);
+
+ if (arguments.length == skip) {
+ result = new ICVSResource[]{mRoot};
+ } else {
+ result = new ICVSResource[arguments.length - skip];
+ for (int i = skip; i<arguments.length; i++) {
+ result[i - skip] = mRoot.getChild(arguments[i]);
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * If mResource is a folder:<br>
+ * Send all Directory under mResource as arguments to the server<br>
+ * If mResource is a file:<br>
+ * Send the file to the server<br>
+ * <br>
+ * Files that are changed are send with the content.
+ *
+ * @param modifiedOnly sends files that are modified only to the server
+ * @param emptyFolders sends the folder-entrie even if there is no file
+ to send in it
+ */
+ protected void sendFileStructure(ICVSResource mResource,
+ IProgressMonitor monitor,
+ boolean modifiedOnly,
+ boolean emptyFolders) throws CVSException {
+
+ FileStructureVisitor fsVisitor;
+
+ fsVisitor = new FileStructureVisitor(requestSender,mRoot,monitor,modifiedOnly,emptyFolders);
+
+ // FIXME: The accept should have an IProgressMonitor argment, not the above constructor
+ mResource.accept(fsVisitor);
+
+ }
+
+ /**
+ * Send an array of Resources.
+ *
+ * @see Command#sendFileStructure(ICVSResource,IProgressMonitor,boolean,boolean,boolean)
+ */
+ protected void sendFileStructure(ICVSResource[] mResources,
+ IProgressMonitor monitor,
+ boolean modifiedOnly,
+ boolean emptyFolders) throws CVSException {
+
+ checkArgumentsManaged(mResources);
+
+ for (int i=0; i<mResources.length; i++) {
+ sendFileStructure(mResources[i],
+ monitor,
+ modifiedOnly,
+ emptyFolders);
+ }
+ }
+
+ /**
+ * Checks that all the workResources are managed Resources.
+ * (For folders we check isCVSFolder, because of a project-folder
+ * that is not managed, because it is not registerd in the
+ * parent-folder<br>
+ *
+ * @throws CVSException if not all the arguments are
+ * managed
+ */
+ protected void checkArgumentsManaged(ICVSResource[] mWorkResources) throws CVSException {
+
+ for (int i=0; i<mWorkResources.length; i++) {
+ if (mWorkResources[i].isFolder()) {
+ if (!((ICVSFolder) mWorkResources[i]).isCVSFolder()) {
+ throw new CVSException("Argument " + mWorkResources[i].getName() + "is not managed");
+ }
+ } else {
+ if (!mWorkResources[i].isManaged()) {
+ throw new CVSException("Argument " + mWorkResources[i].getName() + "is not managed");
+ }
+ }
+ }
+ }
+}
+
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/CommandDispatcher.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/CommandDispatcher.java index bdd4d1a1f..716a8276c 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/CommandDispatcher.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/CommandDispatcher.java @@ -1,111 +1,111 @@ -package org.eclipse.team.internal.ccvs.core.commands; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.io.PrintStream; -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.requests.RequestSender; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFolder; -import org.eclipse.team.internal.ccvs.core.response.ResponseDispatcher; -import org.eclipse.team.internal.ccvs.core.util.Assert; - -/** - * Class that acctually runs the commands that come form the - * "command-line". It searches the command and runs it with the - * rest of the parameters. - * - * @see CommandExecuter#execute(String command, IConnection, String[], String[], ICvsResource, OutputStream) - */ -public class CommandDispatcher { - - private Map commandPool; - - private ResponseDispatcher responseDispatcher; - private RequestSender requestSender; - - /** - * Puts all the Commands in a container in order to have access - * to them when they are going to be executed - * - * Generic approche to "plug in" new commands just by adding them - * to this constructor - */ - public CommandDispatcher(ResponseDispatcher responseDispatcher, - RequestSender requestSender) { - - commandPool = new HashMap(); - - registerCommand(new Update(responseDispatcher,requestSender)); - registerCommand(new Checkout(responseDispatcher,requestSender)); - registerCommand(new Commit(responseDispatcher,requestSender)); - registerCommand(new Import(responseDispatcher,requestSender)); - registerCommand(new Add(responseDispatcher,requestSender)); - registerCommand(new Remove(responseDispatcher,requestSender)); - registerCommand(new Status(responseDispatcher,requestSender)); - registerCommand(new Log(responseDispatcher,requestSender)); - registerCommand(new Tag(responseDispatcher,requestSender)); - registerCommand(new Admin(responseDispatcher,requestSender)); - registerCommand(new Diff(responseDispatcher,requestSender)); - - } - - /** - * Internal helper-method to put the commands into - * the hashtabe - */ - private void registerCommand(ICommand command) { - - // Do not register commands twice - Assert.isTrue(commandPool.get(command.getName()) == null); - - commandPool.put(command.getName(),command); - } - - /** - * Runs the given command on the cvs server. - * - * The only public method of the commands-package. - * - * Preconditiones: - * - all arguments non-null - * - globalOptions, localOptions arguments can be empty Arrays - * - the connection has to be set up - * - for most commands: - * root.isCVSFolder() = true || - * root.getChild(arguments[0]) = true - * - * This method is not thread safe. In other words, this method is not to be - * invoked concurrently with the same connection or command name. - */ - public void execute(String commandName, - String[] globalOptions, - String[] localOptions, - String[] arguments, - IManagedFolder mRoot, - IProgressMonitor monitor, - PrintStream messageOut) throws CVSException { - - ICommand command; - - Assert.isNotNull(commandPool.get(commandName)); - - command = (ICommand) commandPool.get(commandName); - command.execute(globalOptions, - localOptions, - arguments, - mRoot, - monitor, - messageOut); - - } - -} - - +package org.eclipse.team.internal.ccvs.core.commands;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.io.PrintStream;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.requests.RequestSender;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFolder;
+import org.eclipse.team.internal.ccvs.core.response.ResponseDispatcher;
+import org.eclipse.team.internal.ccvs.core.util.Assert;
+
+/**
+ * Class that acctually runs the commands that come form the
+ * "command-line". It searches the command and runs it with the
+ * rest of the parameters.
+ *
+ * @see CommandExecuter#execute(String command, IConnection, String[], String[], ICvsResource, OutputStream)
+ */
+public class CommandDispatcher {
+
+ private Map commandPool;
+
+ private ResponseDispatcher responseDispatcher;
+ private RequestSender requestSender;
+
+ /**
+ * Puts all the Commands in a container in order to have access
+ * to them when they are going to be executed
+ *
+ * Generic approche to "plug in" new commands just by adding them
+ * to this constructor
+ */
+ public CommandDispatcher(ResponseDispatcher responseDispatcher,
+ RequestSender requestSender) {
+
+ commandPool = new HashMap();
+
+ registerCommand(new Update(responseDispatcher,requestSender));
+ registerCommand(new Checkout(responseDispatcher,requestSender));
+ registerCommand(new Commit(responseDispatcher,requestSender));
+ registerCommand(new Import(responseDispatcher,requestSender));
+ registerCommand(new Add(responseDispatcher,requestSender));
+ registerCommand(new Remove(responseDispatcher,requestSender));
+ registerCommand(new Status(responseDispatcher,requestSender));
+ registerCommand(new Log(responseDispatcher,requestSender));
+ registerCommand(new Tag(responseDispatcher,requestSender));
+ registerCommand(new Admin(responseDispatcher,requestSender));
+ registerCommand(new Diff(responseDispatcher,requestSender));
+
+ }
+
+ /**
+ * Internal helper-method to put the commands into
+ * the hashtabe
+ */
+ private void registerCommand(ICommand command) {
+
+ // Do not register commands twice
+ Assert.isTrue(commandPool.get(command.getName()) == null);
+
+ commandPool.put(command.getName(),command);
+ }
+
+ /**
+ * Runs the given command on the cvs server.
+ *
+ * The only public method of the commands-package.
+ *
+ * Preconditiones:
+ * - all arguments non-null
+ * - globalOptions, localOptions arguments can be empty Arrays
+ * - the connection has to be set up
+ * - for most commands:
+ * root.isCVSFolder() = true ||
+ * root.getChild(arguments[0]) = true
+ *
+ * This method is not thread safe. In other words, this method is not to be
+ * invoked concurrently with the same connection or command name.
+ */
+ public void execute(String commandName,
+ String[] globalOptions,
+ String[] localOptions,
+ String[] arguments,
+ ICVSFolder mRoot,
+ IProgressMonitor monitor,
+ PrintStream messageOut) throws CVSException {
+
+ ICommand command;
+
+ Assert.isNotNull(commandPool.get(commandName));
+
+ command = (ICommand) commandPool.get(commandName);
+ command.execute(globalOptions,
+ localOptions,
+ arguments,
+ mRoot,
+ monitor,
+ messageOut);
+
+ }
+
+}
+
+
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/Commit.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/Commit.java index 10a97b518..dd38b38fe 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/Commit.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/Commit.java @@ -1,82 +1,81 @@ -package org.eclipse.team.internal.ccvs.core.commands; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.requests.RequestSender; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFile; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedResource; -import org.eclipse.team.internal.ccvs.core.response.ResponseDispatcher; -import org.eclipse.team.internal.ccvs.core.util.Assert; - -class Commit extends Command { - - public Commit(ResponseDispatcher responseDispathcer, - RequestSender requestSender) { - - super(responseDispathcer,requestSender); - } - - /** - * @see ICommand#getName() - */ - public String getName() { - return RequestSender.CI; - } - - /** - * @see ICommand#getRequestName() - */ - public String getRequestName() { - return RequestSender.CI; - } - - /** - * Send all files under the workingFolder as changed files to - * the server. - * - * @see Request#sendRequestsToServer(IProgressMonitor) - */ - public void sendRequestsToServer(IProgressMonitor monitor) throws CVSException { - - IManagedResource[] mWorkResources; - FileStructureVisitor visitor; - IManagedFile[] changedFiles; - - Assert.isTrue(allResourcesManaged()); - - visitor = new FileStructureVisitor(requestSender,getRoot(),monitor,true,false); - - // Get the folders we want to work on - mWorkResources = getWorkResources(); - - // Send all changed files to the server - for (int i = 0; i < mWorkResources.length; i++) { - mWorkResources[i].accept(visitor); - } - - sendHomeFolder(); - - // Send the changed files as arguments - changedFiles = visitor.getSentFiles(); - for (int i = 0; i < changedFiles.length; i++) { - requestSender.sendArgument(changedFiles[i].getRelativePath(getRoot())); - } - - } - - /** - * We do not want to send the arguments here, because we send - * them in sendRequestsToServer (special handling). - */ - protected void sendArguments() throws CVSException { - return; - } - -} - +package org.eclipse.team.internal.ccvs.core.commands;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.requests.RequestSender;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFile;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSResource;
+import org.eclipse.team.internal.ccvs.core.response.ResponseDispatcher;
+import org.eclipse.team.internal.ccvs.core.util.Assert;
+
+class Commit extends Command {
+
+ public Commit(ResponseDispatcher responseDispathcer,
+ RequestSender requestSender) {
+
+ super(responseDispathcer,requestSender);
+ }
+
+ /**
+ * @see ICommand#getName()
+ */
+ public String getName() {
+ return RequestSender.CI;
+ }
+
+ /**
+ * @see ICommand#getRequestName()
+ */
+ public String getRequestName() {
+ return RequestSender.CI;
+ }
+
+ /**
+ * Send all files under the workingFolder as changed files to
+ * the server.
+ *
+ * @see Request#sendRequestsToServer(IProgressMonitor)
+ */
+ public void sendRequestsToServer(IProgressMonitor monitor) throws CVSException {
+
+ ICVSResource[] mWorkResources;
+ FileStructureVisitor visitor;
+ ICVSFile[] changedFiles;
+
+ visitor = new FileStructureVisitor(requestSender,getRoot(),monitor,true,false);
+
+ // Get the folders we want to work on
+ mWorkResources = getWorkResources();
+ checkArgumentsManaged(mWorkResources);
+
+ // Send all changed files to the server
+ for (int i = 0; i < mWorkResources.length; i++) {
+ mWorkResources[i].accept(visitor);
+ }
+
+ sendHomeFolder();
+
+ // Send the changed files as arguments
+ changedFiles = visitor.getSentFiles();
+ for (int i = 0; i < changedFiles.length; i++) {
+ requestSender.sendArgument(changedFiles[i].getRelativePath(getRoot()));
+ }
+
+ }
+
+ /**
+ * We do not want to send the arguments here, because we send
+ * them in sendRequestsToServer (special handling).
+ */
+ protected void sendArguments() throws CVSException {
+ return;
+ }
+
+}
+
\ No newline at end of file diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/Diff.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/Diff.java index ab226fdff..db619abd5 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/Diff.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/Diff.java @@ -1,65 +1,65 @@ -package org.eclipse.team.internal.ccvs.core.commands; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.io.PrintStream; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.internal.ccvs.core.CVSDiffException; -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.connection.CVSServerException; -import org.eclipse.team.internal.ccvs.core.requests.RequestSender; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFolder; -import org.eclipse.team.internal.ccvs.core.response.ResponseDispatcher; - -class Diff extends AbstractMessageCommand { - - /** - * Constructor for Diff. - * @param responseDispatcher - * @param requestSender - */ - public Diff(ResponseDispatcher responseDispathcer, RequestSender requestSender) { - super(responseDispathcer, requestSender); - } - - /** - * Overwritten to throw the CVSDiffException if the server returns - * an error, because it just does so when there is a difference between - * the cecked files. - */ - public void execute ( - String[] globalOptions, - String[] localOptions, - String[] arguments, - IManagedFolder mRoot, - IProgressMonitor monitor, - PrintStream messageOut) - throws CVSException { - - try { - super.execute(globalOptions,localOptions,arguments,mRoot,monitor,messageOut); - } catch (CVSServerException e) { - throw new CVSDiffException(); - } - } - - /** - * @see ICommand#getName() - */ - public String getName() { - return RequestSender.DIFF; - } - - /** - * @see ICommand#getRequestName() - */ - public String getRequestName() { - return RequestSender.DIFF; - } - -} - +package org.eclipse.team.internal.ccvs.core.commands;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.io.PrintStream;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.team.internal.ccvs.core.CVSDiffException;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.connection.CVSServerException;
+import org.eclipse.team.internal.ccvs.core.requests.RequestSender;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFolder;
+import org.eclipse.team.internal.ccvs.core.response.ResponseDispatcher;
+
+class Diff extends AbstractMessageCommand {
+
+ /**
+ * Constructor for Diff.
+ * @param responseDispatcher
+ * @param requestSender
+ */
+ public Diff(ResponseDispatcher responseDispathcer, RequestSender requestSender) {
+ super(responseDispathcer, requestSender);
+ }
+
+ /**
+ * Overwritten to throw the CVSDiffException if the server returns
+ * an error, because it just does so when there is a difference between
+ * the cecked files.
+ */
+ public void execute (
+ String[] globalOptions,
+ String[] localOptions,
+ String[] arguments,
+ ICVSFolder mRoot,
+ IProgressMonitor monitor,
+ PrintStream messageOut)
+ throws CVSException {
+
+ try {
+ super.execute(globalOptions,localOptions,arguments,mRoot,monitor,messageOut);
+ } catch (CVSServerException e) {
+ throw new CVSDiffException();
+ }
+ }
+
+ /**
+ * @see ICommand#getName()
+ */
+ public String getName() {
+ return RequestSender.DIFF;
+ }
+
+ /**
+ * @see ICommand#getRequestName()
+ */
+ public String getRequestName() {
+ return RequestSender.DIFF;
+ }
+
+}
+
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/FileNameMatcher.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/FileNameMatcher.java index a01754b5c..ce2533a2f 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/FileNameMatcher.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/FileNameMatcher.java @@ -5,22 +5,22 @@ package org.eclipse.team.internal.ccvs.core.commands; * All Rights Reserved.
*/
-import java.io.BufferedReader;
+import java.io.File;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
-import org.eclipse.team.internal.ccvs.core.util.Assert;
import org.eclipse.team.internal.ccvs.core.CVSException;
-import org.eclipse.team.internal.ccvs.core.resources.api.ICVSFile;
-import org.eclipse.team.internal.ccvs.core.resources.api.ICVSFolder;
+import org.eclipse.team.internal.ccvs.core.util.Assert;
+import org.eclipse.team.internal.ccvs.core.util.FileUtil;
import org.eclipse.team.internal.ccvs.core.util.StringMatcher;
/**
* A FileNameMatcher associates a String with a String pattern
* (e.g. a filename).
+ *
+ * XXX How is this classed used, and is it a general .cvsignore
+ * mechanism or a generic filename matcher?
*/
public class FileNameMatcher {
@@ -41,9 +41,10 @@ public class FileNameMatcher { for (int i = 0; i < patterns.length; i++) {
register(patterns[i],TRUE);
}
+ register("CVS", TRUE);
}
- void register(String pattern, String result) {
+ public void register(String pattern, String result) {
Assert.isTrue(matchers.size() == results.size());
@@ -81,13 +82,12 @@ public class FileNameMatcher { * Return a file name matcher build from the .cvsignore file
* in the provided directory or null if no such file exists
*/
- public static FileNameMatcher getIgnoreMatcherFor(ICVSFolder folder) throws CVSException, IOException {
- ICVSFile cvsignore = folder.createFile(IGNORE_FILE);
- if (!cvsignore.exists())
- return null;
- return new FileNameMatcher(cvsignore.getContent());
-
- }
-
-
+ public static FileNameMatcher getIgnoreMatcherFor(File folder) throws CVSException {
+ File cvsignore = new File(folder, IGNORE_FILE);
+ if (!cvsignore.exists()) {
+ return new FileNameMatcher(new String[0]);
+ } else {
+ return new FileNameMatcher(FileUtil.readLines(cvsignore));
+ }
+ }
}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/FileStructureVisitor.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/FileStructureVisitor.java index 556631766..cfa91f844 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/FileStructureVisitor.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/FileStructureVisitor.java @@ -1,147 +1,147 @@ -package org.eclipse.team.internal.ccvs.core.commands; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.util.HashSet; -import java.util.Set; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.requests.RequestSender; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFile; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFolder; - -/** - * This visitor send the fileStructure to the requestSender. - * - * If accepted by an IManagedResource:<br> - * Send all Directory under mResource as arguments to the server<br> - * If accepted by a file:<br> - * Send the file to the server<br> - * <br> - * Files that are changed are send with the content. - * - * @param modifiedOnly sends files that are modified only to the server - * @param emptyFolders sends the folder-entrie even if there is no file - to send in it - */ - -class FileStructureVisitor extends AbstractStructureVisitor { - - private final boolean modifiedOnly; - private final boolean emptyFolders; - private final Set sentFiles; - - - /** - * Constructor for the visitor - * - * @param modifiedOnly sends files that are modified only to the server - * @param emptyFolders sends the folder-entrie even if there is no file - to send in it - */ - public FileStructureVisitor(RequestSender requestSender, - IManagedFolder mRoot, - IProgressMonitor monitor, - boolean modifiedOnly, - boolean emptyFolders) { - - super(requestSender, mRoot, monitor); - this.modifiedOnly = modifiedOnly; - this.emptyFolders = emptyFolders; - sentFiles = new HashSet(); - - } - - /** - * @see IManagedVisitor#visitFile(IManagedFile) - */ - public void visitFile(IManagedFile mFile) throws CVSException { - - // We assume, that acceptChildren() does call all the files - // and then the folder or first all the folders and then the - // files and does not mix. This is specified as well. - - if (!modifiedOnly || mFile.isDirty()) { - // sendFile sends the folder if it is nessary - sendFile(mFile); - } - } - - /** - * @see IManagedVisitor#visitFolder(IManagedFolder) - */ - public void visitFolder(IManagedFolder mFolder) throws CVSException { - - IManagedFile[] files; - IManagedFolder[] folders; - - if (emptyFolders) { - // If we want to send empty folder, that just send it when - // we come to it - sendFolder(mFolder); - } - - if (!mFolder.isCVSFolder() || !mFolder.exists()) { - return; - } - - // We have to do a manual visit to ensure that the questionable - // folders are send before the normal - - files = mFolder.getFiles(); - - for (int i = 0; i < files.length; i++) { - files[i].accept(this); - } - - folders = mFolder.getFolders(); - - for (int i = 0; i < folders.length; i++) { - if (!folders[i].isCVSFolder()) { - folders[i].accept(this); - folders[i] = null; - } - } - - for (int i = 0; i < folders.length; i++) { - if (folders[i] != null) { - folders[i].accept(this); - } - } - } - - private void sendFile(IManagedFile mFile) throws CVSException { - - // Only if we know about the file, it is added to the - // list of sended files, Questionables do not go into - // the list - if (mFile.isManaged()) { - sentFiles.add(mFile); - } - - // Send the folder if it hasn't been send so far - sendFolder(mFile.getParent()); - - if (mFile.getFileInfo() == null) { - sendFile(mFile,true,null); - } else { - sendFile(mFile,true,mFile.getFileInfo().getKeywordMode()); - } - } - - private void sendFolder(IManagedFolder mFolder) throws CVSException{ - sendFolder(mFolder,false,true); - } - - /** - * Return all the files that have been send to the server - */ - public IManagedFile[] getSentFiles() { - return (IManagedFile[]) sentFiles.toArray(new IManagedFile[sentFiles.size()]); - } -} - +package org.eclipse.team.internal.ccvs.core.commands;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.requests.RequestSender;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFile;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFolder;
+
+/**
+ * This visitor send the fileStructure to the requestSender.
+ *
+ * If accepted by an ICVSResource:<br>
+ * Send all Directory under mResource as arguments to the server<br>
+ * If accepted by a file:<br>
+ * Send the file to the server<br>
+ * <br>
+ * Files that are changed are send with the content.
+ *
+ * @param modifiedOnly sends files that are modified only to the server
+ * @param emptyFolders sends the folder-entrie even if there is no file
+ to send in it
+ */
+
+class FileStructureVisitor extends AbstractStructureVisitor {
+
+ private final boolean modifiedOnly;
+ private final boolean emptyFolders;
+ private final Set sentFiles;
+
+
+ /**
+ * Constructor for the visitor
+ *
+ * @param modifiedOnly sends files that are modified only to the server
+ * @param emptyFolders sends the folder-entrie even if there is no file
+ to send in it
+ */
+ public FileStructureVisitor(RequestSender requestSender,
+ ICVSFolder mRoot,
+ IProgressMonitor monitor,
+ boolean modifiedOnly,
+ boolean emptyFolders) {
+
+ super(requestSender, mRoot, monitor);
+ this.modifiedOnly = modifiedOnly;
+ this.emptyFolders = emptyFolders;
+ sentFiles = new HashSet();
+
+ }
+
+ /**
+ * @see ICVSResourceVisitor#visitFile(IManagedFile)
+ */
+ public void visitFile(ICVSFile mFile) throws CVSException {
+
+ // We assume, that acceptChildren() does call all the files
+ // and then the folder or first all the folders and then the
+ // files and does not mix. This is specified as well.
+
+ if (!modifiedOnly || mFile.isDirty()) {
+ // sendFile sends the folder if it is nessary
+ sendFile(mFile);
+ }
+ }
+
+ /**
+ * @see ICVSResourceVisitor#visitFolder(ICVSFolder)
+ */
+ public void visitFolder(ICVSFolder mFolder) throws CVSException {
+
+ ICVSFile[] files;
+ ICVSFolder[] folders;
+
+ if (emptyFolders) {
+ // If we want to send empty folder, that just send it when
+ // we come to it
+ sendFolder(mFolder);
+ }
+
+ if (!mFolder.isCVSFolder() || !mFolder.exists()) {
+ return;
+ }
+
+ // We have to do a manual visit to ensure that the questionable
+ // folders are send before the normal
+
+ files = mFolder.getFiles();
+
+ for (int i = 0; i < files.length; i++) {
+ files[i].accept(this);
+ }
+
+ folders = mFolder.getFolders();
+
+ for (int i = 0; i < folders.length; i++) {
+ if (!folders[i].isCVSFolder()) {
+ folders[i].accept(this);
+ folders[i] = null;
+ }
+ }
+
+ for (int i = 0; i < folders.length; i++) {
+ if (folders[i] != null) {
+ folders[i].accept(this);
+ }
+ }
+ }
+
+ private void sendFile(ICVSFile mFile) throws CVSException {
+
+ // Only if we know about the file, it is added to the
+ // list of sended files, Questionables do not go into
+ // the list
+ if (mFile.isManaged()) {
+ sentFiles.add(mFile);
+ }
+
+ // Send the folder if it hasn't been send so far
+ sendFolder(mFile.getParent());
+
+ if (mFile.getSyncInfo() == null) {
+ sendFile(mFile,true,null);
+ } else {
+ sendFile(mFile,true,mFile.getSyncInfo().getKeywordMode());
+ }
+ }
+
+ private void sendFolder(ICVSFolder mFolder) throws CVSException{
+ sendFolder(mFolder,false,true);
+ }
+
+ /**
+ * Return all the files that have been send to the server
+ */
+ public ICVSFile[] getSentFiles() {
+ return (ICVSFile[]) sentFiles.toArray(new ICVSFile[sentFiles.size()]);
+ }
+}
+
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/ICommand.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/ICommand.java index 4280c1031..837ea4d33 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/ICommand.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/ICommand.java @@ -9,7 +9,7 @@ import java.io.PrintStream; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.team.internal.ccvs.core.CVSException;
-import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFolder;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFolder;
/**
* Represents a command of the cvs-client.
@@ -34,7 +34,7 @@ interface ICommand { void execute(String[] globalOptions,
String[] localOptions,
String[] arguments,
- IManagedFolder mRoot,
+ ICVSFolder mRoot,
IProgressMonitor monitor,
PrintStream messageOut)
throws CVSException;
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/Import.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/Import.java index 34751a018..c6c648fc0 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/Import.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/Import.java @@ -1,83 +1,83 @@ -package org.eclipse.team.internal.ccvs.core.commands; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.team.internal.ccvs.core.util.Assert; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.Client; -import org.eclipse.team.internal.ccvs.core.requests.RequestSender; -import org.eclipse.team.internal.ccvs.core.resources.api.FileProperties; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedVisitor; -import org.eclipse.team.internal.ccvs.core.response.ResponseDispatcher; -import org.eclipse.team.internal.ccvs.core.util.Util; - -class Import extends Command { - - /** - * Constructor for Import. - * @param responseDispatcher - * @param requestSender - */ - public Import(ResponseDispatcher responseDispatcher, - RequestSender requestSender) { - super(responseDispatcher, requestSender); - } - - /** - * @see Command#sendRequestsToServer(IProgressMonitor) - */ - protected void sendRequestsToServer(IProgressMonitor monitor) - throws CVSException { - - String mode = null; - String[] wrappers; - String[] ignores; - IManagedVisitor visitor; - - // If the arguments are not three, the server is going to - // reject the request - // NOTE: Yes, but at least the user would get better feedback! - // We should be throwing a CVSException! - Assert.isTrue(getArguments().length == 3); - - // At this point we need to know wether we need to send the file - // as a binary. The server will set the mode properly based on the wrapper option. - if (Util.isOption(getLocalOptions(),FileProperties.BINARY_TAG)) { - mode = FileProperties.BINARY_TAG; - } - - ignores = Util.getOptions(getLocalOptions(),Client.IGNORE_OPTION,false); - wrappers = Util.getOptions(getLocalOptions(),Client.WRAPPER_OPTION,false); - - visitor = new ImportStructureVisitor(requestSender, - getRoot(), - monitor, - mode, - ignores, - wrappers); - - getRoot().accept(visitor); - - sendHomeFolder(false); - } - - /** - * @see ICommand#getName() - */ - public String getName() { - return RequestSender.IMPORT; - } - - /** - * @see ICommand#getRequestName() - */ - public String getRequestName() { - return RequestSender.IMPORT; - } - -} - +package org.eclipse.team.internal.ccvs.core.commands;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.team.internal.ccvs.core.util.Assert;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.Client;
+import org.eclipse.team.internal.ccvs.core.requests.RequestSender;
+import org.eclipse.team.internal.ccvs.core.resources.ResourceSyncInfo;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSResourceVisitor;
+import org.eclipse.team.internal.ccvs.core.response.ResponseDispatcher;
+import org.eclipse.team.internal.ccvs.core.util.Util;
+
+class Import extends Command {
+
+ /**
+ * Constructor for Import.
+ * @param responseDispatcher
+ * @param requestSender
+ */
+ public Import(ResponseDispatcher responseDispatcher,
+ RequestSender requestSender) {
+ super(responseDispatcher, requestSender);
+ }
+
+ /**
+ * @see Command#sendRequestsToServer(IProgressMonitor)
+ */
+ protected void sendRequestsToServer(IProgressMonitor monitor)
+ throws CVSException {
+
+ String mode = null;
+ String[] wrappers;
+ String[] ignores;
+ ICVSResourceVisitor visitor;
+
+ // If the arguments are not three, the server is going to
+ // reject the request
+ // NOTE: Yes, but at least the user would get better feedback!
+ // We should be throwing a CVSException!
+ Assert.isTrue(getArguments().length == 3);
+
+ // At this point we need to know wether we need to send the file
+ // as a binary. The server will set the mode properly based on the wrapper option.
+ if (Util.isOption(getLocalOptions(),ResourceSyncInfo.BINARY_TAG)) {
+ mode = ResourceSyncInfo.BINARY_TAG;
+ }
+
+ ignores = Util.getOptions(getLocalOptions(),Client.IGNORE_OPTION,false);
+ wrappers = Util.getOptions(getLocalOptions(),Client.WRAPPER_OPTION,false);
+
+ visitor = new ImportStructureVisitor(requestSender,
+ getRoot(),
+ monitor,
+ mode,
+ ignores,
+ wrappers);
+
+ getRoot().accept(visitor);
+
+ sendHomeFolder(false);
+ }
+
+ /**
+ * @see ICommand#getName()
+ */
+ public String getName() {
+ return RequestSender.IMPORT;
+ }
+
+ /**
+ * @see ICommand#getRequestName()
+ */
+ public String getRequestName() {
+ return RequestSender.IMPORT;
+ }
+
+}
+
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/ImportStructureVisitor.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/ImportStructureVisitor.java index 86a47dd8e..16f27114c 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/ImportStructureVisitor.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/ImportStructureVisitor.java @@ -1,140 +1,140 @@ -package org.eclipse.team.internal.ccvs.core.commands; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.util.ArrayList; -import java.util.List; -import java.util.StringTokenizer; - -import org.eclipse.team.internal.ccvs.core.util.Assert; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.requests.RequestSender; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFile; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFolder; -import org.eclipse.team.internal.ccvs.core.util.StringMatcher; - -/** - * The ImportStructureVisitor sends the content of the folder it is - * used on to the server. It constructs the locations of the resources - * because the resources do not yet have a remote-location.<br> - * Up to that it can ignore certain files and decides wether to send - * a file in binary or text mode due to a specification that is passed - * as a "wrapper" argument. - */ -class ImportStructureVisitor extends AbstractStructureVisitor { - - private static final String KEYWORD_OPTION = "-k"; - private static final String QUOTE = "'"; - - private final String mode; - private final String[] ignores; - private final String[] wrappers; - - private final FileNameMatcher ignoreMatcher; - private final FileNameMatcher wrapMatcher; - - /** - * Constructor for ImportStructureVisitor. - * @param requestSender - * @param mRoot - * @param monitor - */ - public ImportStructureVisitor( - RequestSender requestSender, - IManagedFolder mRoot, - IProgressMonitor monitor, - String mode, - String[] ignores, - String[] wrappers) { - super(requestSender, mRoot, monitor); - - this.mode = mode; - this.ignores = ignores; - ignoreMatcher = new FileNameMatcher(ignores); - - this.wrappers = wrappers; - wrapMatcher = initWrapMatcher(wrappers); - } - - - /** - * Inits the wrapMatcher, that is responsible to find out - * whether a file is to be send as a binary (on an import) - * or not. - * - * Takes wrappers of this format: - * *.class -k 'o' - * - * and inits the FileNameMatcher to give - * -ko back if you call it with match("somename.class") - * - * ignores all wrappers, that do not contain -k - */ - private FileNameMatcher initWrapMatcher(String[] wrappers) { - - FileNameMatcher wrapMatcher; - - if (wrappers == null) { - return null; - } - - wrapMatcher = new FileNameMatcher(); - - for (int i = 0; i < wrappers.length; i++) { - - if (wrappers[i].indexOf(KEYWORD_OPTION) == -1) { - continue; - } - - StringTokenizer st = new StringTokenizer(wrappers[i]); - String pattern = st.nextToken(); - String option = st.nextToken(); - // get rid of the quotes - StringTokenizer quoteSt = - new StringTokenizer(st.nextToken(),QUOTE); - option += quoteSt.nextToken(); - - wrapMatcher.register(pattern,option); - } - - return wrapMatcher; - } - - /** - * @see IManagedVisitor#visitFile(IManagedFile) - */ - public void visitFile(IManagedFile mFile) throws CVSException { - - String mode = this.mode; - - if (ignoreMatcher != null && ignoreMatcher.match(mFile.getName())) { - return; - } - - if (mode == null && wrapMatcher != null) { - mode = wrapMatcher.getMatch(mFile.getName()); - } - - sendFile(mFile,false,mode); - - } - - /** - * @see IManagedVisitor#visitFolder(IManagedFolder) - */ - public void visitFolder(IManagedFolder mFolder) throws CVSException { - - if (ignoreMatcher != null && ignoreMatcher.match(mFolder.getName())) { - return; - } - - sendFolder(mFolder,true,false); - mFolder.acceptChildren(this); - - } - +package org.eclipse.team.internal.ccvs.core.commands;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import org.eclipse.team.internal.ccvs.core.util.Assert;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.requests.RequestSender;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFile;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFolder;
+import org.eclipse.team.internal.ccvs.core.util.StringMatcher;
+
+/**
+ * The ImportStructureVisitor sends the content of the folder it is
+ * used on to the server. It constructs the locations of the resources
+ * because the resources do not yet have a remote-location.<br>
+ * Up to that it can ignore certain files and decides wether to send
+ * a file in binary or text mode due to a specification that is passed
+ * as a "wrapper" argument.
+ */
+class ImportStructureVisitor extends AbstractStructureVisitor {
+
+ private static final String KEYWORD_OPTION = "-k";
+ private static final String QUOTE = "'";
+
+ private final String mode;
+ private final String[] ignores;
+ private final String[] wrappers;
+
+ private final FileNameMatcher ignoreMatcher;
+ private final FileNameMatcher wrapMatcher;
+
+ /**
+ * Constructor for ImportStructureVisitor.
+ * @param requestSender
+ * @param mRoot
+ * @param monitor
+ */
+ public ImportStructureVisitor(
+ RequestSender requestSender,
+ ICVSFolder mRoot,
+ IProgressMonitor monitor,
+ String mode,
+ String[] ignores,
+ String[] wrappers) {
+ super(requestSender, mRoot, monitor);
+
+ this.mode = mode;
+ this.ignores = ignores;
+ ignoreMatcher = new FileNameMatcher(ignores);
+
+ this.wrappers = wrappers;
+ wrapMatcher = initWrapMatcher(wrappers);
+ }
+
+
+ /**
+ * Inits the wrapMatcher, that is responsible to find out
+ * whether a file is to be send as a binary (on an import)
+ * or not.
+ *
+ * Takes wrappers of this format:
+ * *.class -k 'o'
+ *
+ * and inits the FileNameMatcher to give
+ * -ko back if you call it with match("somename.class")
+ *
+ * ignores all wrappers, that do not contain -k
+ */
+ private FileNameMatcher initWrapMatcher(String[] wrappers) {
+
+ FileNameMatcher wrapMatcher;
+
+ if (wrappers == null) {
+ return null;
+ }
+
+ wrapMatcher = new FileNameMatcher();
+
+ for (int i = 0; i < wrappers.length; i++) {
+
+ if (wrappers[i].indexOf(KEYWORD_OPTION) == -1) {
+ continue;
+ }
+
+ StringTokenizer st = new StringTokenizer(wrappers[i]);
+ String pattern = st.nextToken();
+ String option = st.nextToken();
+ // get rid of the quotes
+ StringTokenizer quoteSt =
+ new StringTokenizer(st.nextToken(),QUOTE);
+ option += quoteSt.nextToken();
+
+ wrapMatcher.register(pattern,option);
+ }
+
+ return wrapMatcher;
+ }
+
+ /**
+ * @see ICVSResourceVisitor#visitFile(IManagedFile)
+ */
+ public void visitFile(ICVSFile mFile) throws CVSException {
+
+ String mode = this.mode;
+
+ if (ignoreMatcher != null && ignoreMatcher.match(mFile.getName())) {
+ return;
+ }
+
+ if (mode == null && wrapMatcher != null) {
+ mode = wrapMatcher.getMatch(mFile.getName());
+ }
+
+ sendFile(mFile,false,mode);
+
+ }
+
+ /**
+ * @see ICVSResourceVisitor#visitFolder(ICVSFolder)
+ */
+ public void visitFolder(ICVSFolder mFolder) throws CVSException {
+
+ if (ignoreMatcher != null && ignoreMatcher.match(mFolder.getName())) {
+ return;
+ }
+
+ sendFolder(mFolder,true,false);
+ mFolder.acceptChildren(this);
+
+ }
+
}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/Log.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/Log.java index 40c85eaa9..a55042b3a 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/Log.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/Log.java @@ -1,37 +1,37 @@ -package org.eclipse.team.internal.ccvs.core.commands; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.team.internal.ccvs.core.requests.RequestSender; -import org.eclipse.team.internal.ccvs.core.response.ResponseDispatcher; - -class Log extends AbstractMessageCommand { - - /** - * Constructor for Log. - * @param responseDispatcher - * @param requestSender - */ - public Log(ResponseDispatcher responseContainer, RequestSender requestSender) { - super(responseContainer, requestSender); - } - - /** - * @see ICommand#getName() - */ - public String getName() { - return RequestSender.LOG; - } - - /** - * @see ICommand#getRequestName() - */ - public String getRequestName() { - return RequestSender.LOG; - } - -} - +package org.eclipse.team.internal.ccvs.core.commands;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.team.internal.ccvs.core.requests.RequestSender;
+import org.eclipse.team.internal.ccvs.core.response.ResponseDispatcher;
+
+class Log extends AbstractMessageCommand {
+
+ /**
+ * Constructor for Log.
+ * @param responseDispatcher
+ * @param requestSender
+ */
+ public Log(ResponseDispatcher responseContainer, RequestSender requestSender) {
+ super(responseContainer, requestSender);
+ }
+
+ /**
+ * @see ICommand#getName()
+ */
+ public String getName() {
+ return RequestSender.LOG;
+ }
+
+ /**
+ * @see ICommand#getRequestName()
+ */
+ public String getRequestName() {
+ return RequestSender.LOG;
+ }
+
+}
+
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/PruneFolderVisitor.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/PruneFolderVisitor.java index 44c363987..1f0f6207f 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/PruneFolderVisitor.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/PruneFolderVisitor.java @@ -6,34 +6,32 @@ package org.eclipse.team.internal.ccvs.core.commands; */
import org.eclipse.team.internal.ccvs.core.CVSException;
-import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFile;
-import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFolder;
-import org.eclipse.team.internal.ccvs.core.resources.api.IManagedVisitor;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFile;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFolder;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSResourceVisitor;
/**
* Goes recursivly through the folders checks if they are empyty
* and deletes them. Of course it is starting at the leaves of the
* recusion (the folders that do not have subfolders).
*/
-public class PruneFolderVisitor implements IManagedVisitor {
+public class PruneFolderVisitor implements ICVSResourceVisitor {
/**
- * @see IManagedVisitor#visitFile(IManagedFile)
+ * @see ICVSResourceVisitor#visitFile(IManagedFile)
*/
- public void visitFile(IManagedFile file) throws CVSException {
+ public void visitFile(ICVSFile file) throws CVSException {
}
/**
- * @see IManagedVisitor#visitFolder(IManagedFolder)
+ * @see ICVSResourceVisitor#visitFolder(ICVSFolder)
*/
- public void visitFolder(IManagedFolder folder) throws CVSException {
+ public void visitFolder(ICVSFolder folder) throws CVSException {
folder.acceptChildren(this);
if (folder.getFiles().length == 0 &&
folder.getFolders().length == 0) {
- folder.setFolderInfo(null);
+ folder.unmanage();
folder.delete();
}
}
-
-}
-
+}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/Remove.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/Remove.java index 6d857952a..5b334ded5 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/Remove.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/Remove.java @@ -1,60 +1,58 @@ -package org.eclipse.team.internal.ccvs.core.commands; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.team.internal.ccvs.core.util.Assert; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedResource; -import org.eclipse.team.internal.ccvs.core.requests.RequestSender; -import org.eclipse.team.internal.ccvs.core.response.ResponseDispatcher; - -class Remove extends Command { - - /** - * Constructor for Remove. - * @param responseContainer - * @param requestSender - */ - public Remove( - ResponseDispatcher responseContainer, - RequestSender requestSender) { - super(responseContainer, requestSender); - } - - /** - * @see ICommand#getName() - */ - public String getName() { - return RequestSender.REMOVE; - } - - /** - * @see ICommand#getRequestName() - */ - public String getRequestName() { - return RequestSender.REMOVE; - } - - /** - * @see Command#sendRequestsToServer(IProgressMonitor) - */ - protected void sendRequestsToServer(IProgressMonitor monitor) - throws CVSException { - - IManagedResource[] mWorkResources; - - Assert.isTrue(allResourcesManaged()); - - // Get the folders we want to work on - mWorkResources = getWorkResources(); - - // Send all changed files to the server - sendFileStructure(mWorkResources,monitor,true,false); - sendHomeFolder(); - } -} - +package org.eclipse.team.internal.ccvs.core.commands;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.team.internal.ccvs.core.util.Assert;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSResource;
+import org.eclipse.team.internal.ccvs.core.requests.RequestSender;
+import org.eclipse.team.internal.ccvs.core.response.ResponseDispatcher;
+
+class Remove extends Command {
+
+ /**
+ * Constructor for Remove.
+ * @param responseContainer
+ * @param requestSender
+ */
+ public Remove(
+ ResponseDispatcher responseContainer,
+ RequestSender requestSender) {
+ super(responseContainer, requestSender);
+ }
+
+ /**
+ * @see ICommand#getName()
+ */
+ public String getName() {
+ return RequestSender.REMOVE;
+ }
+
+ /**
+ * @see ICommand#getRequestName()
+ */
+ public String getRequestName() {
+ return RequestSender.REMOVE;
+ }
+
+ /**
+ * @see Command#sendRequestsToServer(IProgressMonitor)
+ */
+ protected void sendRequestsToServer(IProgressMonitor monitor)
+ throws CVSException {
+
+ ICVSResource[] mWorkResources;
+
+ // Get the folders we want to work on
+ mWorkResources = getWorkResources();
+
+ // Send all changed files to the server
+ sendFileStructure(mWorkResources,monitor,true,false);
+ sendHomeFolder();
+ }
+}
+
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/Status.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/Status.java index 8335648ce..6660406a8 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/Status.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/Status.java @@ -1,38 +1,38 @@ -package org.eclipse.team.internal.ccvs.core.commands; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.team.internal.ccvs.core.util.Assert; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.requests.RequestSender; -import org.eclipse.team.internal.ccvs.core.response.ResponseDispatcher; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedResource; - -public class Status extends AbstractMessageCommand { - - public Status(ResponseDispatcher responseContainer, - RequestSender requestSender) { - - super(responseContainer,requestSender); - } - - /** - * @see ICommand#getName() - */ - public String getName() { - return RequestSender.STATUS; - } - - /** - * @see ICommand#getRequestName() - */ - public String getRequestName() { - return RequestSender.STATUS; - } - -} - +package org.eclipse.team.internal.ccvs.core.commands;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.team.internal.ccvs.core.util.Assert;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.requests.RequestSender;
+import org.eclipse.team.internal.ccvs.core.response.ResponseDispatcher;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSResource;
+
+public class Status extends AbstractMessageCommand {
+
+ public Status(ResponseDispatcher responseContainer,
+ RequestSender requestSender) {
+
+ super(responseContainer,requestSender);
+ }
+
+ /**
+ * @see ICommand#getName()
+ */
+ public String getName() {
+ return RequestSender.STATUS;
+ }
+
+ /**
+ * @see ICommand#getRequestName()
+ */
+ public String getRequestName() {
+ return RequestSender.STATUS;
+ }
+
+}
+
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/Tag.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/Tag.java index b2043b42a..820e82262 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/Tag.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/Tag.java @@ -1,58 +1,58 @@ -package org.eclipse.team.internal.ccvs.core.commands; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.requests.RequestSender; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedResource; -import org.eclipse.team.internal.ccvs.core.response.ResponseDispatcher; -import org.eclipse.team.internal.ccvs.core.util.Assert; - -public class Tag extends Command { - - /** - * Constructor for Tag. - * @param responseDispatcher - * @param requestSender - */ - public Tag(ResponseDispatcher responseDispatcher, RequestSender requestSender) { - super(responseDispatcher, requestSender); - } - - /** - * @see ICommand#getName() - */ - public String getName() { - return RequestSender.TAG; - } - - /** - * @see ICommand#getRequestName() - */ - public String getRequestName() { - return RequestSender.TAG; - } - - /** - * @see Command#sendRequestsToServer(IProgressMonitor) - */ - protected void sendRequestsToServer(IProgressMonitor monitor) - throws CVSException { - - // Either we got parameters or the folder we are in is an cvsFolder - Assert.isTrue(getArguments().length > 1 || - getRoot().isCVSFolder()); - - // Get the folders we want to work on, ignoring the first argument - IManagedResource[] mWorkResources = getWorkResources(1); - - // Send all folders that are already managed to the server - sendFileStructure(mWorkResources,monitor,false,false); - sendHomeFolder(); - } -} - +package org.eclipse.team.internal.ccvs.core.commands;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.requests.RequestSender;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSResource;
+import org.eclipse.team.internal.ccvs.core.response.ResponseDispatcher;
+import org.eclipse.team.internal.ccvs.core.util.Assert;
+
+public class Tag extends Command {
+
+ /**
+ * Constructor for Tag.
+ * @param responseDispatcher
+ * @param requestSender
+ */
+ public Tag(ResponseDispatcher responseDispatcher, RequestSender requestSender) {
+ super(responseDispatcher, requestSender);
+ }
+
+ /**
+ * @see ICommand#getName()
+ */
+ public String getName() {
+ return RequestSender.TAG;
+ }
+
+ /**
+ * @see ICommand#getRequestName()
+ */
+ public String getRequestName() {
+ return RequestSender.TAG;
+ }
+
+ /**
+ * @see Command#sendRequestsToServer(IProgressMonitor)
+ */
+ protected void sendRequestsToServer(IProgressMonitor monitor)
+ throws CVSException {
+
+ // Either we got parameters or the folder we are in is an cvsFolder
+ Assert.isTrue(getArguments().length > 1 ||
+ getRoot().isCVSFolder());
+
+ // Get the folders we want to work on, ignoring the first argument
+ ICVSResource[] mWorkResources = getWorkResources(1);
+
+ // Send all folders that are already managed to the server
+ sendFileStructure(mWorkResources,monitor,false,false);
+ sendHomeFolder();
+ }
+}
+
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/Update.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/Update.java index 17ac8d91a..18b0ba847 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/Update.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/commands/Update.java @@ -1,90 +1,88 @@ -package org.eclipse.team.internal.ccvs.core.commands; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.team.internal.ccvs.core.util.Assert; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.Client; -import org.eclipse.team.internal.ccvs.core.requests.RequestSender; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedResource; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedVisitor; -import org.eclipse.team.internal.ccvs.core.response.ResponseDispatcher; -import org.eclipse.team.internal.ccvs.core.util.Util; - -class Update extends Command { - - public Update(ResponseDispatcher responseDispatcher, - RequestSender requestSender) { - - super(responseDispatcher,requestSender); - } - - /** - * @see ICommand#getName() - */ - public String getName() { - return RequestSender.UPDATE; - } - - /** - * @see ICommand#getRequestName() - */ - public String getRequestName() { - return RequestSender.UPDATE; - } - - /** - * MV: Special case handling for the "." argument. - * - */ -// protected IManagedResource[] getWorkResources() throws CVSException { -// // NIK: Do we need this handling ? -// // MV: You tell me! -// if ((getArguments().length == 1) && (getArguments()[0].equals("."))) -// return new IManagedResource[]{getRoot()}; -// return super.getWorkResources(); -// } - - public void sendRequestsToServer(IProgressMonitor monitor) throws CVSException { - - IManagedResource[] mWorkResources; - - Assert.isTrue(allResourcesManaged()); - - // Get the folders we want to work on - mWorkResources = getWorkResources(); - - // FIXME other clients send this (wondering if we should as well): - // requestSender.writeLine("UseUnchanged"); - // requestSender.writeLine("Case"); - // requestSender.sendArgument("-u"); - - // Send all folders that are already managed to the server - // even folders that are empty - sendFileStructure(mWorkResources,monitor,false,true); - sendHomeFolder(); - - } - - /** - * On sucessful finish, prune empty directories if - * the -P option was specified. - */ - protected void finished(boolean success) throws CVSException { - if (success && Util.isOption(getLocalOptions(), Client.PRUNE_OPTION)) { - // Get the folders we want to work on - IManagedResource[] mWorkResources = getWorkResources(); - // Delete empty directories - IManagedVisitor visitor = new PruneFolderVisitor(); - for (int i=0; i<mWorkResources.length; i++) { - mWorkResources[i].accept(visitor); - } - } - } -} - - +package org.eclipse.team.internal.ccvs.core.commands;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.team.internal.ccvs.core.util.Assert;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.Client;
+import org.eclipse.team.internal.ccvs.core.requests.RequestSender;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSResource;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSResourceVisitor;
+import org.eclipse.team.internal.ccvs.core.response.ResponseDispatcher;
+import org.eclipse.team.internal.ccvs.core.util.Util;
+
+class Update extends Command {
+
+ public Update(ResponseDispatcher responseDispatcher,
+ RequestSender requestSender) {
+
+ super(responseDispatcher,requestSender);
+ }
+
+ /**
+ * @see ICommand#getName()
+ */
+ public String getName() {
+ return RequestSender.UPDATE;
+ }
+
+ /**
+ * @see ICommand#getRequestName()
+ */
+ public String getRequestName() {
+ return RequestSender.UPDATE;
+ }
+
+ /**
+ * MV: Special case handling for the "." argument.
+ *
+ */
+// protected ICVSResource[] getWorkResources() throws CVSException {
+// // NIK: Do we need this handling ?
+// // MV: You tell me!
+// if ((getArguments().length == 1) && (getArguments()[0].equals(".")))
+// return new ICVSResource[]{getRoot()};
+// return super.getWorkResources();
+// }
+
+ public void sendRequestsToServer(IProgressMonitor monitor) throws CVSException {
+
+ ICVSResource[] mWorkResources;
+
+ // Get the folders we want to work on
+ mWorkResources = getWorkResources();
+
+ // FIXME other clients send this (wondering if we should as well):
+ // requestSender.writeLine("UseUnchanged");
+ // requestSender.writeLine("Case");
+ // requestSender.sendArgument("-u");
+
+ // Send all folders that are already managed to the server
+ // even folders that are empty
+ sendFileStructure(mWorkResources,monitor,false,true);
+ sendHomeFolder();
+
+ }
+
+ /**
+ * On sucessful finish, prune empty directories if
+ * the -P option was specified.
+ */
+ protected void finished(boolean success) throws CVSException {
+ if (success && Util.isOption(getLocalOptions(), Client.PRUNE_OPTION)) {
+ // Get the folders we want to work on
+ ICVSResource[] mWorkResources = getWorkResources();
+ // Delete empty directories
+ ICVSResourceVisitor visitor = new PruneFolderVisitor();
+ for (int i=0; i<mWorkResources.length; i++) {
+ mWorkResources[i].accept(visitor);
+ }
+ }
+ }
+}
+
+
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/connection/CVSRepositoryLocation.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/connection/CVSRepositoryLocation.java index 811205c8a..66dc76f5f 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/connection/CVSRepositoryLocation.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/connection/CVSRepositoryLocation.java @@ -1,589 +1,590 @@ -package org.eclipse.team.internal.ccvs.core.connection; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExtension; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.MultiStatus; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.PlatformObject; -import org.eclipse.core.runtime.Status; -import org.eclipse.team.ccvs.core.CVSProviderPlugin; -import org.eclipse.team.ccvs.core.ICVSRemoteResource; -import org.eclipse.team.ccvs.core.ICVSRepositoryLocation; -import org.eclipse.team.ccvs.core.IConnectionMethod; -import org.eclipse.team.ccvs.core.IUserAuthenticator; -import org.eclipse.team.ccvs.core.IUserInfo; -import org.eclipse.team.core.TeamException; -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.CVSStatus; -import org.eclipse.team.internal.ccvs.core.Policy; -import org.eclipse.team.internal.ccvs.core.resources.RemoteFolder; - -/** - * This class manages a CVS repository location. - * - * It provides the mapping between connection method name and the - * plugged in ICunnectionMethod. - * - * It parses location strings into instances. - * - * It provides a method to open a connection to the server along - * with a method to validate that connections can be made. - * - * It manages its user info using the plugged in IUserAuthenticator - * (unless a username and password are provided as part of the creation - * string, in which case, no authenticator is used). - * - * Instances must be disposed of when no longer needed in order to - * notify the authenticator so cached properties can be cleared - * - */ -public class CVSRepositoryLocation extends PlatformObject implements ICVSRepositoryLocation, IUserInfo { - - // static variables for extension points - private static IUserAuthenticator authenticator; - private static IConnectionMethod[] pluggedInConnectionMethods = null; - - private IConnectionMethod method; - private String user; - private String password; - private String host; - private int port; - private String root; - private boolean userFixed; - private boolean passwordFixed; - - public static final char COLON = ':'; - public static final char HOST_SEPARATOR = '@'; - public static final char PORT_SEPARATOR = '#'; - public static final boolean STANDALONE_MODE = (System.getProperty("cvs.standalone")==null)?false:(new Boolean(System.getProperty("cvs.standalone")).booleanValue()); - - /* - * Create a CVSRepositoryLocation from its composite parts. - */ - private CVSRepositoryLocation(IConnectionMethod method, String user, String password, String host, int port, String root, boolean userFixed, boolean passwordFixed) { - this.method = method; - this.user = user; - this.password = password; - this.host = host; - this.port = port; - this.root = root; - // The username can be fixed only if one is provided - if (userFixed && (user != null)) - this.userFixed = true; - // The password can only be fixed if the username is and a password is provided - if (userFixed && passwordFixed && (password != null)) - this.passwordFixed = true; -// else { -// // If the password is not fixed, there's no need to fix the username -// this.userFixed = false; -// this.passwordFixed = false; -// } - // Retrieve a password if one was previosuly cached or set it to blank - if (!passwordFixed) { - IUserAuthenticator authenticator = getAuthenticator(); - if (authenticator != null) { - try { - if (!authenticator.retrievePassword(this, this)) - password = ""; - } catch (CVSException e) { - password = ""; - } - } - } - } - - /* - * Create the connection to the remote server. - * If anything fails, an exception will be thrown and must - * be handled by the caller. - */ - private Connection createConnection() throws CVSException { - // Should the open() of Connection be done in the constructor? - // The only reason it should is if connections can be reused (they aren't reused now). - Connection connection = new Connection(this, method.createConnection(this, password)); - connection.open(); - return connection; - } - - /* - * Dispose of the receiver by clearing any cached authorization information. - * This method shold only be invoked when the corresponding adapter is shut - * down or a connection is being validated. - */ - public void dispose() throws CVSException { - IUserAuthenticator authenticator = getAuthenticator(); - if (authenticator != null) { - authenticator.dispose(this); - } - } - - /* - * @see ICVSRepositoryLocation#getHost() - */ - public String getHost() { - return host; - } - - /* - * @see IRepositoryLocation#getLocation() - * - * The username is included if it is fixed. - * The password is never included even if it is fixed. - * The port is included if it is not the default port. - */ - public String getLocation() { - return COLON + method.getName() + COLON + - (userFixed?(user + - (passwordFixed?(COLON + password):"") - + HOST_SEPARATOR):"") + - host + - ((port == USE_DEFAULT_PORT)?"":(PORT_SEPARATOR + new Integer(port).toString())) + - COLON + root; - } - - /* - * @see ICVSRepositoryLocation#getMethod() - */ - public IConnectionMethod getMethod() { - return method; - } - - public boolean setMethod(String methodName) { - IConnectionMethod newMethod = getPluggedInConnectionMethod(methodName); - if (newMethod == null) - return false; - method = newMethod; - return true; - } - - /* - * @see ICVSRepositoryLocation#getPort() - */ - public int getPort() { - return port; - } - - /* - * @see ICVSRepositoryLocation#getRemoteFolder(IPath, String) - */ - public ICVSRemoteResource[] members(String tag, IProgressMonitor progress) throws CVSException { - try { - RemoteFolder root = new RemoteFolder(this, Path.EMPTY, tag); - return (ICVSRemoteResource[])root.members(progress); - } catch(TeamException e) { - throw new CVSException(e.getStatus()); - } - } - - /* - * @see ICVSRepositoryLocation#getRootDirectory() - */ - public String getRootDirectory() { - return root; - } - - /* - * @see ICVSRepositoryLocation#getTimeout() - * - * For the time being, the timeout value is a system wide value - * associated with the CVSPlugin singleton. - */ - public int getTimeout() { - return 60; - } - - /* - * @see ICVSRepositoryLocation#getUserInfo() - */ - public IUserInfo getUserInfo() { - return this; - } - - /* - * @see ICVSRepositoryLocation#getUsername() - * @see IUserInfo#getUsername() - */ - public String getUsername() { - return user; - } - - /* - * @see IUserInfo#isUsernameMutable() - */ - public boolean isUsernameMutable() { - return !userFixed; - } - - /* - * Open a connection to the repository represented by the receiver. - * If the username or password are not fixed, openConnection will - * use the plugged-in authenticator to prompt for the username and/or - * password if one has not previously been provided or if the previously - * supplied username and password are invalid. - */ - public Connection openConnection() throws CVSException { - String message = null; - - // If we have a username and password, don't authenticate unless we fail. - // We would have a username and password if we previously authenticated - // or one was stored using storePassword() - if ((user != null) && (password != null)) - try { - return createConnection(); - } catch (CVSAuthenticationException ex) { - if (userFixed && passwordFixed) - throw ex; - message = ex.getMessage(); - } - - // If we failed above or we didn't have a username or password, authenticate - IUserAuthenticator authenticator = getAuthenticator(); - if (authenticator == null) { - throw new CVSAuthenticationException(this.getLocation(), Policy.bind("Client.noAuthenticator")); - } - - // If we tried above and failed, this is a retry. - boolean retry = (message != null); - while (true) { - try { - if (!authenticator.authenticateUser(this, this, retry, message)) - throw new CVSAuthenticationException(new CVSStatus(CVSStatus.ERROR, Policy.bind("error"))); - } catch (CVSException e) { - throw e; - } - try { - // The following will throw an exception if authentication fails - return createConnection(); - } catch (CVSAuthenticationException ex) { - retry = true; - message = ex.getMessage(); - } - } - } - - /* - * Implementation of inherited toString() - */ - public String toString() { - return getLocation(); - } - - /* - * @see IUserInfo#setPassword(String) - */ - public void setPassword(String password) { - if (passwordFixed) - throw new UnsupportedOperationException(); - this.password = password; - } - - /* - * @see IUserInfo#setUsername(String) - */ - public void setUsername(String user) { - if (userFixed) - throw new UnsupportedOperationException(); - this.user = user; - } - - public void setUserMuteable(boolean muteable) { - userFixed = !muteable; - } - - public void storePassword(String password) throws CVSException { - IUserAuthenticator authenticator = getAuthenticator(); - if (authenticator != null) { - authenticator.cachePassword(this, this, password); - } - } - - public void updateCache() throws CVSException { - IUserAuthenticator authenticator = getAuthenticator(); - if (authenticator != null) { - authenticator.cachePassword(this, this, password); - } - } - - /* - * Validate that the receiver contains valid information for - * making a connection. If the receiver contains valid - * information, the method returns. Otherwise, an exception - * indicating the problem is throw. - */ - public boolean validateConnection() throws CVSException { - try { - openConnection().close(); - return true; - } catch (CVSException e) { - // If the validation failed, dispose of any cached info - dispose(); - throw e; - } - } - - public static boolean validateConnectionMethod(String methodName) { - String[] methods = CVSProviderPlugin.getProvider().getSupportedConnectionMethods(); - for (int i=0;i<methods.length;i++) { - if (methodName.equals(methods[i])) - return true; - } - return false; - } - - /* - * Parse a location string and return a CVSRepositoryLocation. - * - * On failure, the status of the exception will be a MultiStatus - * that includes the original parsing error and a general status - * displaying the passed location and proper form. This form is - * better for logging, etc. - */ - public static CVSRepositoryLocation fromString(String location) throws CVSException { - try { - return fromString(location, false); - } catch (CVSException e) { - // Parsing failed. Include a status that - // shows the passed location and the proper form - MultiStatus error = new MultiStatus(CVSProviderPlugin.ID, CVSStatus.ERROR, Policy.bind("CVSRepositoryLocation.invalidFormat", new Object[] {location}), null); - error.merge(new CVSStatus(IStatus.ERROR, null, Policy.bind("CVSRepositoryLocation.locationForm"))); - error.merge(e.getStatus()); - throw new CVSException(error); - } - } - - /* - * Parse a location string and return a CVSRepositoryLocation. - * - * The valid format (from the cederqvist) is: - * - * :method:[[user][:password]@]hostname[:[port]]/path/to/repository - * - * However, this does not work with CVS on NT so we use the format - * - * :method:[user[:password]@]hostname[#port]:/path/to/repository - * - * Some differences to note: - * The : after the host/port is not optional because of NT naming including device - * e.g. :pserver:username:password@hostname#port:D:\cvsroot - * - * If validateOnly is true, this method will always throw an exception. - * The status of the exception indicates success or failure. The status - * of the exception contains a specific message suitable for displaying - * to a user who has knowledge of the provided location string. - * @see CVSRepositoryLocation.fromString(String) - */ - public static CVSRepositoryLocation fromString(String location, boolean validateOnly) throws CVSException { - String partId = null; - try { - // Get the connection method - partId = "CVSRepositoryLocation.parsingMethod"; - int start = location.indexOf(COLON); - if (start != 0) - throw new CVSException(Policy.bind("CVSRepositoryLocation.startOfLocation")); - int end = location.indexOf(COLON, start + 1); - String methodName = location.substring(start + 1, end); - IConnectionMethod method = getPluggedInConnectionMethod(methodName); - if (method == null) - throw new CVSException(new CVSStatus(CVSStatus.ERROR, null, Policy.bind("CVSRepositoryLocation.methods", new Object[] {getPluggedInConnectionMethodNames()}))); - - // Get the user name and password (if provided) - partId = "CVSRepositoryLocation.parsingUser"; - start = end + 1; - end = location.indexOf(HOST_SEPARATOR, start); - String user = null;; - String password = null; - // if end is -1 then there is no host separator meaning that the username is not present - if (end != -1) { - // Get the optional user and password - user = location.substring(start, end); - // Separate the user and password (if there is a password) - start = user.indexOf(COLON); - if (start != -1) { - partId = "CVSRepositoryLocation.parsingPassword"; - password = user.substring(start+1); - user = user.substring(0, start); - } - // Set start to point after the host separator - start = end + 1; - } - - // Get the host (and port) - partId = "CVSRepositoryLocation.parsingHost"; - end= location.indexOf(COLON, start); - String host = location.substring(start, end); - int port = USE_DEFAULT_PORT; - // Separate the port and host if there is a port - start = host.indexOf(PORT_SEPARATOR); - if (start != -1) { - partId = "CVSRepositoryLocation.parsingPort"; - port = Integer.parseInt(host.substring(start+1)); - host = host.substring(0, start); - } - - // Get the repository path (translating backslashes to slashes) - partId = "CVSRepositoryLocation.parsingRoot"; - start = end + 1; - String root = location.substring(start).replace('\\', '/'); - - if (validateOnly) - throw new CVSException(new CVSStatus(CVSStatus.OK, Policy.bind("ok"))); - - return new CVSRepositoryLocation(method, user, password, host, port, root, (user != null), (password != null)); - } - catch (IndexOutOfBoundsException e) { - // We'll get here if anything funny happened while extracting substrings - throw new CVSException(Policy.bind(partId)); - } - catch (NumberFormatException e) { - // We'll get here if we couldn't parse a number - throw new CVSException(Policy.bind(partId)); - } - } - - public static IUserAuthenticator getAuthenticator() { - if (authenticator == null) { - authenticator = getPluggedInAuthenticator(); - } - return authenticator; - } - - /* - * Return the connection method registered for the given name or null if none - * are registered - */ - private static IConnectionMethod getPluggedInConnectionMethod(String methodName) { - IConnectionMethod[] methods = getPluggedInConnectionMethods(); - for(int i=0; i<methods.length; i++) { - if(methodName.equals(methods[i].getName())) - return methods[i]; - } - return null; - } - - /* - * Return a string containing a list of all connection methods - */ - private static String getPluggedInConnectionMethodNames() { - IConnectionMethod[] methods = getPluggedInConnectionMethods(); - StringBuffer methodNames = new StringBuffer(); - for(int i=0; i<methods.length; i++) { - String name = methods[i].getName(); - if (i>0) - methodNames.append(", "); - methodNames.append(name); - } - return methodNames.toString(); - } - - public static IConnectionMethod[] getPluggedInConnectionMethods() { - if(pluggedInConnectionMethods==null) { - List connectionMethods = new ArrayList(); - - if (STANDALONE_MODE) { - connectionMethods.add(new PServerConnectionMethod()); - } else { - IExtension[] extensions = Platform.getPluginRegistry().getExtensionPoint(CVSProviderPlugin.ID, CVSProviderPlugin.PT_CONNECTIONMETHODS).getExtensions(); - for(int i=0; i<extensions.length; i++) { - IExtension extension = extensions[i]; - IConfigurationElement[] configs = extension.getConfigurationElements(); - if (configs.length == 0) { - CVSProviderPlugin.log(new Status(IStatus.ERROR, CVSProviderPlugin.ID, 0, Policy.bind("CVSProviderPlugin.execProblem"), null)); - continue; - } - try { - IConfigurationElement config = configs[0]; - connectionMethods.add(config.createExecutableExtension("run")); - } catch (CoreException ex) { - CVSProviderPlugin.log(new Status(IStatus.ERROR, CVSProviderPlugin.ID, 0, Policy.bind("CVSProviderPlugin.execProblem"), ex)); - } - } - } - pluggedInConnectionMethods = (IConnectionMethod[])connectionMethods.toArray(new IConnectionMethod[0]); - } - return pluggedInConnectionMethods; - } - - private static IUserAuthenticator getPluggedInAuthenticator() { - IExtension[] extensions = Platform.getPluginRegistry().getExtensionPoint(CVSProviderPlugin.ID, CVSProviderPlugin.PT_AUTHENTICATOR).getExtensions(); - if (extensions.length == 0) - return null; - IExtension extension = extensions[0]; - IConfigurationElement[] configs = extension.getConfigurationElements(); - if (configs.length == 0) { - CVSProviderPlugin.log(new Status(IStatus.ERROR, CVSProviderPlugin.ID, 0, Policy.bind("CVSAdapter.noConfigurationElement", new Object[] {extension.getUniqueIdentifier()}), null)); - return null; - } - try { - IConfigurationElement config = configs[0]; - return (IUserAuthenticator) config.createExecutableExtension("run"); - } catch (CoreException ex) { - CVSProviderPlugin.log(new Status(IStatus.ERROR, CVSProviderPlugin.ID, 0, Policy.bind("CVSAdapter.unableToInstantiate", new Object[] {extension.getUniqueIdentifier()}), ex)); - return null; - } - } - - /* - * Validate that the given string could ne used to succesfully create - * an instance of the receiver. - * - * This method performs some initial checks to provide displayable - * feedback and also tries a more in-depth parse using fromString(String, boolean). - */ - public static IStatus validate(String location) { - - // Check some simple things that are not checked in creation - if (location == null) - return new CVSStatus(CVSStatus.ERROR, null, Policy.bind("CVSRepositoryLocation.nullLocation")); - if (location.equals("")) - return new CVSStatus(CVSStatus.ERROR, null, Policy.bind("CVSRepositoryLocation.emptyLocation")); - if (location.endsWith(" ") || location.endsWith("\t")) - return new CVSStatus(CVSStatus.ERROR, null, Policy.bind("CVSRepositoryLocation.endWhitespace")); - if (!location.startsWith(":") || location.indexOf(COLON, 1) == -1) - return new CVSStatus(CVSStatus.ERROR, null, Policy.bind("CVSRepositoryLocation.startOfLocation")); - - // Do some quick checks to provide geberal feedback - String formatError = Policy.bind("CVSRepositoryLocation.locationForm"); - int secondColon = location.indexOf(COLON, 1); - int at = location.indexOf(HOST_SEPARATOR); - if (at != -1) { - String user = location.substring(secondColon + 1, at); - if (user.equals("")) - return new CVSStatus(CVSStatus.ERROR, null, formatError); - } else - at = secondColon; - int colon = location.indexOf(COLON, at + 1); - if (colon == -1) - return new CVSStatus(CVSStatus.ERROR, null, formatError); - String host = location.substring(at + 1, colon); - if (host.equals("")) - return new CVSStatus(CVSStatus.ERROR, null, formatError); - String path = location.substring(colon + 1, location.length()); - if (path.equals("")) - return new CVSStatus(CVSStatus.ERROR, null, formatError); - - // Do a full parse and see if it passes - try { - fromString(location, true); - } catch (CVSException e) { - // An exception is always throw. Return the status - return e.getStatus(); - } - - // Looks ok (we'll actually never get here because above - // fromString(String, boolean) will always throw an exception). - return new CVSStatus(IStatus.OK, Policy.bind("ok")); - } -} - +package org.eclipse.team.internal.ccvs.core.connection;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.MultiStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.PlatformObject;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.team.ccvs.core.CVSProviderPlugin;
+import org.eclipse.team.ccvs.core.CVSTag;
+import org.eclipse.team.ccvs.core.ICVSRemoteResource;
+import org.eclipse.team.ccvs.core.ICVSRepositoryLocation;
+import org.eclipse.team.ccvs.core.IConnectionMethod;
+import org.eclipse.team.ccvs.core.IUserAuthenticator;
+import org.eclipse.team.ccvs.core.IUserInfo;
+import org.eclipse.team.core.TeamException;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.CVSStatus;
+import org.eclipse.team.internal.ccvs.core.Policy;
+import org.eclipse.team.internal.ccvs.core.resources.RemoteFolder;
+
+/**
+ * This class manages a CVS repository location.
+ *
+ * It provides the mapping between connection method name and the
+ * plugged in ICunnectionMethod.
+ *
+ * It parses location strings into instances.
+ *
+ * It provides a method to open a connection to the server along
+ * with a method to validate that connections can be made.
+ *
+ * It manages its user info using the plugged in IUserAuthenticator
+ * (unless a username and password are provided as part of the creation
+ * string, in which case, no authenticator is used).
+ *
+ * Instances must be disposed of when no longer needed in order to
+ * notify the authenticator so cached properties can be cleared
+ *
+ */
+public class CVSRepositoryLocation extends PlatformObject implements ICVSRepositoryLocation, IUserInfo {
+
+ // static variables for extension points
+ private static IUserAuthenticator authenticator;
+ private static IConnectionMethod[] pluggedInConnectionMethods = null;
+
+ private IConnectionMethod method;
+ private String user;
+ private String password;
+ private String host;
+ private int port;
+ private String root;
+ private boolean userFixed;
+ private boolean passwordFixed;
+
+ public static final char COLON = ':';
+ public static final char HOST_SEPARATOR = '@';
+ public static final char PORT_SEPARATOR = '#';
+ public static final boolean STANDALONE_MODE = (System.getProperty("eclipse.cvs.standalone")==null)?false:(new Boolean(System.getProperty("eclipse.cvs.standalone")).booleanValue());
+
+ /*
+ * Create a CVSRepositoryLocation from its composite parts.
+ */
+ private CVSRepositoryLocation(IConnectionMethod method, String user, String password, String host, int port, String root, boolean userFixed, boolean passwordFixed) {
+ this.method = method;
+ this.user = user;
+ this.password = password;
+ this.host = host;
+ this.port = port;
+ this.root = root;
+ // The username can be fixed only if one is provided
+ if (userFixed && (user != null))
+ this.userFixed = true;
+ // The password can only be fixed if the username is and a password is provided
+ if (userFixed && passwordFixed && (password != null))
+ this.passwordFixed = true;
+// else {
+// // If the password is not fixed, there's no need to fix the username
+// this.userFixed = false;
+// this.passwordFixed = false;
+// }
+ // Retrieve a password if one was previosuly cached or set it to blank
+ if (!passwordFixed) {
+ IUserAuthenticator authenticator = getAuthenticator();
+ if (authenticator != null) {
+ try {
+ if (!authenticator.retrievePassword(this, this))
+ password = "";
+ } catch (CVSException e) {
+ password = "";
+ }
+ }
+ }
+ }
+
+ /*
+ * Create the connection to the remote server.
+ * If anything fails, an exception will be thrown and must
+ * be handled by the caller.
+ */
+ private Connection createConnection() throws CVSException {
+ // Should the open() of Connection be done in the constructor?
+ // The only reason it should is if connections can be reused (they aren't reused now).
+ Connection connection = new Connection(this, method.createConnection(this, password));
+ connection.open();
+ return connection;
+ }
+
+ /*
+ * Dispose of the receiver by clearing any cached authorization information.
+ * This method shold only be invoked when the corresponding adapter is shut
+ * down or a connection is being validated.
+ */
+ public void dispose() throws CVSException {
+ IUserAuthenticator authenticator = getAuthenticator();
+ if (authenticator != null) {
+ authenticator.dispose(this);
+ }
+ }
+
+ /*
+ * @see ICVSRepositoryLocation#getHost()
+ */
+ public String getHost() {
+ return host;
+ }
+
+ /*
+ * @see IRepositoryLocation#getLocation()
+ *
+ * The username is included if it is fixed.
+ * The password is never included even if it is fixed.
+ * The port is included if it is not the default port.
+ */
+ public String getLocation() {
+ return COLON + method.getName() + COLON +
+ (userFixed?(user +
+ (passwordFixed?(COLON + password):"")
+ + HOST_SEPARATOR):"") +
+ host +
+ ((port == USE_DEFAULT_PORT)?"":(PORT_SEPARATOR + new Integer(port).toString())) +
+ COLON + root;
+ }
+
+ /*
+ * @see ICVSRepositoryLocation#getMethod()
+ */
+ public IConnectionMethod getMethod() {
+ return method;
+ }
+
+ public boolean setMethod(String methodName) {
+ IConnectionMethod newMethod = getPluggedInConnectionMethod(methodName);
+ if (newMethod == null)
+ return false;
+ method = newMethod;
+ return true;
+ }
+
+ /*
+ * @see ICVSRepositoryLocation#getPort()
+ */
+ public int getPort() {
+ return port;
+ }
+
+ /*
+ * @see ICVSRepositoryLocation#getRemoteFolder(IPath, String)
+ */
+ public ICVSRemoteResource[] members(CVSTag tag, IProgressMonitor progress) throws CVSException {
+ try {
+ RemoteFolder root = new RemoteFolder(null, this, Path.EMPTY, tag);
+ return (ICVSRemoteResource[])root.members(progress);
+ } catch(TeamException e) {
+ throw new CVSException(e.getStatus());
+ }
+ }
+
+ /*
+ * @see ICVSRepositoryLocation#getRootDirectory()
+ */
+ public String getRootDirectory() {
+ return root;
+ }
+
+ /*
+ * @see ICVSRepositoryLocation#getTimeout()
+ *
+ * For the time being, the timeout value is a system wide value
+ * associated with the CVSPlugin singleton.
+ */
+ public int getTimeout() {
+ return 60;
+ }
+
+ /*
+ * @see ICVSRepositoryLocation#getUserInfo()
+ */
+ public IUserInfo getUserInfo() {
+ return this;
+ }
+
+ /*
+ * @see ICVSRepositoryLocation#getUsername()
+ * @see IUserInfo#getUsername()
+ */
+ public String getUsername() {
+ return user;
+ }
+
+ /*
+ * @see IUserInfo#isUsernameMutable()
+ */
+ public boolean isUsernameMutable() {
+ return !userFixed;
+ }
+
+ /*
+ * Open a connection to the repository represented by the receiver.
+ * If the username or password are not fixed, openConnection will
+ * use the plugged-in authenticator to prompt for the username and/or
+ * password if one has not previously been provided or if the previously
+ * supplied username and password are invalid.
+ */
+ public Connection openConnection() throws CVSException {
+ String message = null;
+
+ // If we have a username and password, don't authenticate unless we fail.
+ // We would have a username and password if we previously authenticated
+ // or one was stored using storePassword()
+ if ((user != null) && (password != null))
+ try {
+ return createConnection();
+ } catch (CVSAuthenticationException ex) {
+ if (userFixed && passwordFixed)
+ throw ex;
+ message = ex.getMessage();
+ }
+
+ // If we failed above or we didn't have a username or password, authenticate
+ IUserAuthenticator authenticator = getAuthenticator();
+ if (authenticator == null) {
+ throw new CVSAuthenticationException(this.getLocation(), Policy.bind("Client.noAuthenticator"));
+ }
+
+ // If we tried above and failed, this is a retry.
+ boolean retry = (message != null);
+ while (true) {
+ try {
+ if (!authenticator.authenticateUser(this, this, retry, message))
+ throw new CVSAuthenticationException(new CVSStatus(CVSStatus.ERROR, Policy.bind("error")));
+ } catch (CVSException e) {
+ throw e;
+ }
+ try {
+ // The following will throw an exception if authentication fails
+ return createConnection();
+ } catch (CVSAuthenticationException ex) {
+ retry = true;
+ message = ex.getMessage();
+ }
+ }
+ }
+
+ /*
+ * Implementation of inherited toString()
+ */
+ public String toString() {
+ return getLocation();
+ }
+
+ /*
+ * @see IUserInfo#setPassword(String)
+ */
+ public void setPassword(String password) {
+ if (passwordFixed)
+ throw new UnsupportedOperationException();
+ this.password = password;
+ }
+
+ /*
+ * @see IUserInfo#setUsername(String)
+ */
+ public void setUsername(String user) {
+ if (userFixed)
+ throw new UnsupportedOperationException();
+ this.user = user;
+ }
+
+ public void setUserMuteable(boolean muteable) {
+ userFixed = !muteable;
+ }
+
+ public void storePassword(String password) throws CVSException {
+ IUserAuthenticator authenticator = getAuthenticator();
+ if (authenticator != null) {
+ authenticator.cachePassword(this, this, password);
+ }
+ }
+
+ public void updateCache() throws CVSException {
+ IUserAuthenticator authenticator = getAuthenticator();
+ if (authenticator != null) {
+ authenticator.cachePassword(this, this, password);
+ }
+ }
+
+ /*
+ * Validate that the receiver contains valid information for
+ * making a connection. If the receiver contains valid
+ * information, the method returns. Otherwise, an exception
+ * indicating the problem is throw.
+ */
+ public boolean validateConnection() throws CVSException {
+ try {
+ openConnection().close();
+ return true;
+ } catch (CVSException e) {
+ // If the validation failed, dispose of any cached info
+ dispose();
+ throw e;
+ }
+ }
+
+ public static boolean validateConnectionMethod(String methodName) {
+ String[] methods = CVSProviderPlugin.getProvider().getSupportedConnectionMethods();
+ for (int i=0;i<methods.length;i++) {
+ if (methodName.equals(methods[i]))
+ return true;
+ }
+ return false;
+ }
+
+ /*
+ * Parse a location string and return a CVSRepositoryLocation.
+ *
+ * On failure, the status of the exception will be a MultiStatus
+ * that includes the original parsing error and a general status
+ * displaying the passed location and proper form. This form is
+ * better for logging, etc.
+ */
+ public static CVSRepositoryLocation fromString(String location) throws CVSException {
+ try {
+ return fromString(location, false);
+ } catch (CVSException e) {
+ // Parsing failed. Include a status that
+ // shows the passed location and the proper form
+ MultiStatus error = new MultiStatus(CVSProviderPlugin.ID, CVSStatus.ERROR, Policy.bind("CVSRepositoryLocation.invalidFormat", new Object[] {location}), null);
+ error.merge(new CVSStatus(IStatus.ERROR, null, Policy.bind("CVSRepositoryLocation.locationForm")));
+ error.merge(e.getStatus());
+ throw new CVSException(error);
+ }
+ }
+
+ /*
+ * Parse a location string and return a CVSRepositoryLocation.
+ *
+ * The valid format (from the cederqvist) is:
+ *
+ * :method:[[user][:password]@]hostname[:[port]]/path/to/repository
+ *
+ * However, this does not work with CVS on NT so we use the format
+ *
+ * :method:[user[:password]@]hostname[#port]:/path/to/repository
+ *
+ * Some differences to note:
+ * The : after the host/port is not optional because of NT naming including device
+ * e.g. :pserver:username:password@hostname#port:D:\cvsroot
+ *
+ * If validateOnly is true, this method will always throw an exception.
+ * The status of the exception indicates success or failure. The status
+ * of the exception contains a specific message suitable for displaying
+ * to a user who has knowledge of the provided location string.
+ * @see CVSRepositoryLocation.fromString(String)
+ */
+ public static CVSRepositoryLocation fromString(String location, boolean validateOnly) throws CVSException {
+ String partId = null;
+ try {
+ // Get the connection method
+ partId = "CVSRepositoryLocation.parsingMethod";
+ int start = location.indexOf(COLON);
+ if (start != 0)
+ throw new CVSException(Policy.bind("CVSRepositoryLocation.startOfLocation"));
+ int end = location.indexOf(COLON, start + 1);
+ String methodName = location.substring(start + 1, end);
+ IConnectionMethod method = getPluggedInConnectionMethod(methodName);
+ if (method == null)
+ throw new CVSException(new CVSStatus(CVSStatus.ERROR, null, Policy.bind("CVSRepositoryLocation.methods", new Object[] {getPluggedInConnectionMethodNames()})));
+
+ // Get the user name and password (if provided)
+ partId = "CVSRepositoryLocation.parsingUser";
+ start = end + 1;
+ end = location.indexOf(HOST_SEPARATOR, start);
+ String user = null;;
+ String password = null;
+ // if end is -1 then there is no host separator meaning that the username is not present
+ if (end != -1) {
+ // Get the optional user and password
+ user = location.substring(start, end);
+ // Separate the user and password (if there is a password)
+ start = user.indexOf(COLON);
+ if (start != -1) {
+ partId = "CVSRepositoryLocation.parsingPassword";
+ password = user.substring(start+1);
+ user = user.substring(0, start);
+ }
+ // Set start to point after the host separator
+ start = end + 1;
+ }
+
+ // Get the host (and port)
+ partId = "CVSRepositoryLocation.parsingHost";
+ end= location.indexOf(COLON, start);
+ String host = location.substring(start, end);
+ int port = USE_DEFAULT_PORT;
+ // Separate the port and host if there is a port
+ start = host.indexOf(PORT_SEPARATOR);
+ if (start != -1) {
+ partId = "CVSRepositoryLocation.parsingPort";
+ port = Integer.parseInt(host.substring(start+1));
+ host = host.substring(0, start);
+ }
+
+ // Get the repository path (translating backslashes to slashes)
+ partId = "CVSRepositoryLocation.parsingRoot";
+ start = end + 1;
+ String root = location.substring(start).replace('\\', '/');
+
+ if (validateOnly)
+ throw new CVSException(new CVSStatus(CVSStatus.OK, Policy.bind("ok")));
+
+ return new CVSRepositoryLocation(method, user, password, host, port, root, (user != null), (password != null));
+ }
+ catch (IndexOutOfBoundsException e) {
+ // We'll get here if anything funny happened while extracting substrings
+ throw new CVSException(Policy.bind(partId));
+ }
+ catch (NumberFormatException e) {
+ // We'll get here if we couldn't parse a number
+ throw new CVSException(Policy.bind(partId));
+ }
+ }
+
+ public static IUserAuthenticator getAuthenticator() {
+ if (authenticator == null) {
+ authenticator = getPluggedInAuthenticator();
+ }
+ return authenticator;
+ }
+
+ /*
+ * Return the connection method registered for the given name or null if none
+ * are registered
+ */
+ private static IConnectionMethod getPluggedInConnectionMethod(String methodName) {
+ IConnectionMethod[] methods = getPluggedInConnectionMethods();
+ for(int i=0; i<methods.length; i++) {
+ if(methodName.equals(methods[i].getName()))
+ return methods[i];
+ }
+ return null;
+ }
+
+ /*
+ * Return a string containing a list of all connection methods
+ */
+ private static String getPluggedInConnectionMethodNames() {
+ IConnectionMethod[] methods = getPluggedInConnectionMethods();
+ StringBuffer methodNames = new StringBuffer();
+ for(int i=0; i<methods.length; i++) {
+ String name = methods[i].getName();
+ if (i>0)
+ methodNames.append(", ");
+ methodNames.append(name);
+ }
+ return methodNames.toString();
+ }
+
+ public static IConnectionMethod[] getPluggedInConnectionMethods() {
+ if(pluggedInConnectionMethods==null) {
+ List connectionMethods = new ArrayList();
+
+ if (STANDALONE_MODE) {
+ connectionMethods.add(new PServerConnectionMethod());
+ } else {
+ IExtension[] extensions = Platform.getPluginRegistry().getExtensionPoint(CVSProviderPlugin.ID, CVSProviderPlugin.PT_CONNECTIONMETHODS).getExtensions();
+ for(int i=0; i<extensions.length; i++) {
+ IExtension extension = extensions[i];
+ IConfigurationElement[] configs = extension.getConfigurationElements();
+ if (configs.length == 0) {
+ CVSProviderPlugin.log(new Status(IStatus.ERROR, CVSProviderPlugin.ID, 0, Policy.bind("CVSProviderPlugin.execProblem"), null));
+ continue;
+ }
+ try {
+ IConfigurationElement config = configs[0];
+ connectionMethods.add(config.createExecutableExtension("run"));
+ } catch (CoreException ex) {
+ CVSProviderPlugin.log(new Status(IStatus.ERROR, CVSProviderPlugin.ID, 0, Policy.bind("CVSProviderPlugin.execProblem"), ex));
+ }
+ }
+ }
+ pluggedInConnectionMethods = (IConnectionMethod[])connectionMethods.toArray(new IConnectionMethod[0]);
+ }
+ return pluggedInConnectionMethods;
+ }
+
+ private static IUserAuthenticator getPluggedInAuthenticator() {
+ IExtension[] extensions = Platform.getPluginRegistry().getExtensionPoint(CVSProviderPlugin.ID, CVSProviderPlugin.PT_AUTHENTICATOR).getExtensions();
+ if (extensions.length == 0)
+ return null;
+ IExtension extension = extensions[0];
+ IConfigurationElement[] configs = extension.getConfigurationElements();
+ if (configs.length == 0) {
+ CVSProviderPlugin.log(new Status(IStatus.ERROR, CVSProviderPlugin.ID, 0, Policy.bind("CVSAdapter.noConfigurationElement", new Object[] {extension.getUniqueIdentifier()}), null));
+ return null;
+ }
+ try {
+ IConfigurationElement config = configs[0];
+ return (IUserAuthenticator) config.createExecutableExtension("run");
+ } catch (CoreException ex) {
+ CVSProviderPlugin.log(new Status(IStatus.ERROR, CVSProviderPlugin.ID, 0, Policy.bind("CVSAdapter.unableToInstantiate", new Object[] {extension.getUniqueIdentifier()}), ex));
+ return null;
+ }
+ }
+
+ /*
+ * Validate that the given string could ne used to succesfully create
+ * an instance of the receiver.
+ *
+ * This method performs some initial checks to provide displayable
+ * feedback and also tries a more in-depth parse using fromString(String, boolean).
+ */
+ public static IStatus validate(String location) {
+
+ // Check some simple things that are not checked in creation
+ if (location == null)
+ return new CVSStatus(CVSStatus.ERROR, null, Policy.bind("CVSRepositoryLocation.nullLocation"));
+ if (location.equals(""))
+ return new CVSStatus(CVSStatus.ERROR, null, Policy.bind("CVSRepositoryLocation.emptyLocation"));
+ if (location.endsWith(" ") || location.endsWith("\t"))
+ return new CVSStatus(CVSStatus.ERROR, null, Policy.bind("CVSRepositoryLocation.endWhitespace"));
+ if (!location.startsWith(":") || location.indexOf(COLON, 1) == -1)
+ return new CVSStatus(CVSStatus.ERROR, null, Policy.bind("CVSRepositoryLocation.startOfLocation"));
+
+ // Do some quick checks to provide geberal feedback
+ String formatError = Policy.bind("CVSRepositoryLocation.locationForm");
+ int secondColon = location.indexOf(COLON, 1);
+ int at = location.indexOf(HOST_SEPARATOR);
+ if (at != -1) {
+ String user = location.substring(secondColon + 1, at);
+ if (user.equals(""))
+ return new CVSStatus(CVSStatus.ERROR, null, formatError);
+ } else
+ at = secondColon;
+ int colon = location.indexOf(COLON, at + 1);
+ if (colon == -1)
+ return new CVSStatus(CVSStatus.ERROR, null, formatError);
+ String host = location.substring(at + 1, colon);
+ if (host.equals(""))
+ return new CVSStatus(CVSStatus.ERROR, null, formatError);
+ String path = location.substring(colon + 1, location.length());
+ if (path.equals(""))
+ return new CVSStatus(CVSStatus.ERROR, null, formatError);
+
+ // Do a full parse and see if it passes
+ try {
+ fromString(location, true);
+ } catch (CVSException e) {
+ // An exception is always throw. Return the status
+ return e.getStatus();
+ }
+
+ // Looks ok (we'll actually never get here because above
+ // fromString(String, boolean) will always throw an exception).
+ return new CVSStatus(IStatus.OK, Policy.bind("ok"));
+ }
+}
+
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/connection/Connection.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/connection/Connection.java index f2babc5c1..8cb25e1d0 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/connection/Connection.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/connection/Connection.java @@ -1,339 +1,339 @@ -package org.eclipse.team.internal.ccvs.core.connection; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.io.BufferedInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.Policy; -import org.eclipse.team.ccvs.core.*; -import org.eclipse.team.ccvs.core.*; - -/** - * A connection to talk to a cvs server. The life cycle of a connection is - * as follows: - * <ul> - * <li> constructor: creates a new connection object that wraps the given - * repository location and connection method. - * <li> open: opens a connection. - * <li> send a request: use write* method or use the request stream directly. - * <code>GetRequestStream</code> returns an output stream to directly - * talk to the server. - * <li> read responses: use read* methods or use the response stream directly. - * <code>GetResponseStream</code> returns an input stream to directly - * read output from the server. - * <li> close: closes the connection. A closed connection can be reopened by - * calling open again. - * </ul> - */ -public class Connection { - - //private static final boolean DEBUG= System.getProperty("cvsclient.debug")!=null; - private static final boolean DEBUG=true; - - public static final byte NEWLINE= 0xA; - - private IServerConnection serverConnection; - - private ICVSRepositoryLocation fCVSRoot; - private String fCVSRootDirectory; - private boolean fIsEstablished; - private BufferedInputStream fResponseStream; - private char fLastUsedTokenDelimiter; - - boolean closed = false; - - public Connection(ICVSRepositoryLocation cvsroot, IServerConnection serverConnection) { - fCVSRoot = cvsroot; - this.serverConnection = serverConnection; - } - - private static byte[] append(byte[] buffer, int index, byte b) { - if (index >= buffer.length) { - byte[] newBuffer= new byte[index * 2]; - System.arraycopy(buffer, 0, newBuffer, 0, buffer.length); - buffer= newBuffer; - } - buffer[index]= b; - return buffer; - } - /** - * Closes the connection. - */ - public void close() throws CVSException { - if (!isEstablished()) - return; - try { - // Perhaps it should be left to the connection to deal with reading pending input! - readPendingInput(); - serverConnection.close(); - } catch (IOException ex) { - throw new CVSCommunicationException(Policy.bind("Connection.cannotClose"), ex); - } finally { - fResponseStream= null; - fIsEstablished= false; - } - } - /** - * Flushes the request stream. - */ - public void flush() throws CVSException { - if (!isEstablished()) - return; - try { - getRequestStream().flush(); - } catch(IOException e) { - throw new CVSCommunicationException(e); - } - } - //---- CVS root management ------------------------------------------------------- - - /** - * Returns the CVS root. - */ - public ICVSRepositoryLocation getCVSRoot() { - return fCVSRoot; - } - - /** - * Returns the last delimiter character used to read a token. - */ - public char getLastUsedDelimiterToken() { - return fLastUsedTokenDelimiter; - } - - /** - * Returns the <code>OutputStream</code> used to send requests - * to the server. - */ - public OutputStream getRequestStream() throws CVSException { - if (!isEstablished()) - return null; - return serverConnection.getOutputStream(); - } - /** - * Returns the <code>InputStream</code> used to read responses from - * the server. - */ - public InputStream getResponseStream() throws CVSException { - if (!isEstablished()) - return null; - if (fResponseStream == null) - fResponseStream= new BufferedInputStream(serverConnection.getInputStream()); - return fResponseStream; - } - - public String getRootDirectory() throws CVSException { - return getCVSRoot().getRootDirectory(); - } - - /** - * Returns <code>true</code> if the connection is established; - * otherwise <code>false</code>. - */ - public boolean isEstablished() { - return fIsEstablished; - } - //--- Helper to read strings from server ----------------------------------------- - - /** - * Is input available in the response stream. - */ - // NIK: is not used - public boolean isInputAvailable() { - if (!isEstablished()) - return false; - try { - return getResponseStream().available() != 0; - } catch (CVSException e) { - return false; - } catch (IOException e) { - return false; - } - } - public boolean isClosed() { - return closed; - } - /** - * Creates a blank separated string from the given string array. - */ - private String makeString(String[] s) { - StringBuffer buffer= new StringBuffer(); - for (int i= 0; i < s.length; i++) { - if (i != 0) - buffer.append(' '); - buffer.append(s[i]); - } - return buffer.toString(); - } - /** - * Opens the connection. - */ - public void open() throws CVSException { - if (isEstablished()) - return; - try { - serverConnection.open(); - } catch (IOException e) { - throw new CVSCommunicationException(e); - } - fIsEstablished= true; - } - /** - * Reads a line from the response stream. - */ - public String readLine() throws CVSException { - return readLineOrUntil(-1); - } - -static String readLine(InputStream in) throws IOException { - byte[] buffer = new byte[256]; - int index = 0; - int r; - while ((r = in.read()) != -1) { - if (r == NEWLINE) - break; - buffer = append(buffer, index++, (byte) r); - } - String result = new String(buffer, 0, index); - if (DEBUG) - System.out.println(result); - return result; -} - -/** - * Low level method to read a token. - */ -private String readLineOrUntil(int end) throws CVSException { - if (!isEstablished()) - throw new CVSCommunicationException(Policy.bind("Connection.readUnestablishedConnection")); - byte[] buffer = new byte[256]; - InputStream in = getResponseStream(); - int index = 0; - int r; - try { - while ((r = in.read()) != -1) { - if (r == NEWLINE || (end != -1 && r == end)) - break; - buffer = append(buffer, index++, (byte) r); - } - switch (r) { - case -1 : - closed = true; - case NEWLINE : - fLastUsedTokenDelimiter = '\n'; - break; - default : - fLastUsedTokenDelimiter = (char) r; - } - String result = new String(buffer, 0, index); - if (DEBUG) - System.out.print(result + fLastUsedTokenDelimiter); - return result; - } catch (IOException e) { - throw new CVSCommunicationException(e); - } -} - /** - * Reads any pending input from the response stream so that - * the stream can savely be closed. - */ - protected void readPendingInput() throws CVSException { - byte[] buffer= new byte[2048]; - InputStream in= getResponseStream(); - OutputStream out= getRequestStream(); - try { - while (true) { - int available = in.available(); - if (available < 1) break; - if (available > buffer.length) available = buffer.length; - if (in.read(buffer, 0, available) < 1) break; - } - out.flush(); - while (true) { - int available = in.available(); - if (available < 1) break; - if (available > buffer.length) available = buffer.length; - if (in.read(buffer, 0, available) < 1) break; - } - } catch (IOException e) { - throw new CVSCommunicationException(e); - } - } - /** - * Reads a token from the response stream. - */ - public String readToken() throws CVSException { - return readLineOrUntil(' '); - } - /** - * Sends the given array of strings to the server. The array's strings - * are concatenated using a blank. - */ - public void write(String[] a) throws CVSException { - write(makeString(a), false); - } - //---- Helper to send strings to the server ---------------------------- - - /** - * Sends the given string to the server. - */ - public void write(String s) throws CVSException { - write(s, false); - } - /** - * Sends the given two strings separated by a blank to the - * server. - */ - public void write(String s1, String s2) throws CVSException { - write(s1 + ' ' + s2, false); - } - /** - * Low level method to write a string to the server. All write* methods are - * funneled through this method. - */ - void write(String s, boolean newline) throws CVSException { - if (!isEstablished()) - throw new CVSCommunicationException(Policy.bind("Connection.writeUnestablishedConnection")); - - if (DEBUG) - System.out.print(s + (newline ? "\n" : "")); - - try { - OutputStream out= getRequestStream(); - out.write(s.getBytes()); - if (newline) - out.write(NEWLINE); - out.flush(); - - } catch (IOException e) { - throw new CVSCommunicationException(e); - } - } - /** - * Sends the given array of strings to the server. The array's strings - * are concatenated using a blank. Additionally a newline is sent. - */ - public void writeLine(String[] a) throws CVSException { - write(makeString(a), true); - } - /** - * Sends the given string and a newline to the server. - */ - public void writeLine(String s) throws CVSException { - write(s, true); - } - /** - * Sends the given two strings separated by a blank to the - * server. Additionally a newline is sent. - */ - public void writeLine(String s1, String s2) throws CVSException { - write(s1 + ' ' + s2, true); - } -} +package org.eclipse.team.internal.ccvs.core.connection;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.io.BufferedInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.Policy;
+import org.eclipse.team.ccvs.core.*;
+import org.eclipse.team.ccvs.core.*;
+
+/**
+ * A connection to talk to a cvs server. The life cycle of a connection is
+ * as follows:
+ * <ul>
+ * <li> constructor: creates a new connection object that wraps the given
+ * repository location and connection method.
+ * <li> open: opens a connection.
+ * <li> send a request: use write* method or use the request stream directly.
+ * <code>GetRequestStream</code> returns an output stream to directly
+ * talk to the server.
+ * <li> read responses: use read* methods or use the response stream directly.
+ * <code>GetResponseStream</code> returns an input stream to directly
+ * read output from the server.
+ * <li> close: closes the connection. A closed connection can be reopened by
+ * calling open again.
+ * </ul>
+ */
+public class Connection {
+
+ //private static final boolean DEBUG= (System.getProperty("eclipse.cvs.debug")==null)?false:(new Boolean(System.getProperty("eclipse.cvs.debug")).booleanValue());
+ private static final boolean DEBUG=true;
+
+ public static final byte NEWLINE= 0xA;
+
+ private IServerConnection serverConnection;
+
+ private ICVSRepositoryLocation fCVSRoot;
+ private String fCVSRootDirectory;
+ private boolean fIsEstablished;
+ private BufferedInputStream fResponseStream;
+ private char fLastUsedTokenDelimiter;
+
+ boolean closed = false;
+
+ public Connection(ICVSRepositoryLocation cvsroot, IServerConnection serverConnection) {
+ fCVSRoot = cvsroot;
+ this.serverConnection = serverConnection;
+ }
+
+ private static byte[] append(byte[] buffer, int index, byte b) {
+ if (index >= buffer.length) {
+ byte[] newBuffer= new byte[index * 2];
+ System.arraycopy(buffer, 0, newBuffer, 0, buffer.length);
+ buffer= newBuffer;
+ }
+ buffer[index]= b;
+ return buffer;
+ }
+ /**
+ * Closes the connection.
+ */
+ public void close() throws CVSException {
+ if (!isEstablished())
+ return;
+ try {
+ // Perhaps it should be left to the connection to deal with reading pending input!
+ readPendingInput();
+ serverConnection.close();
+ } catch (IOException ex) {
+ throw new CVSCommunicationException(Policy.bind("Connection.cannotClose"), ex);
+ } finally {
+ fResponseStream= null;
+ fIsEstablished= false;
+ }
+ }
+ /**
+ * Flushes the request stream.
+ */
+ public void flush() throws CVSException {
+ if (!isEstablished())
+ return;
+ try {
+ getRequestStream().flush();
+ } catch(IOException e) {
+ throw new CVSCommunicationException(e);
+ }
+ }
+ //---- CVS root management -------------------------------------------------------
+
+ /**
+ * Returns the CVS root.
+ */
+ public ICVSRepositoryLocation getCVSRoot() {
+ return fCVSRoot;
+ }
+
+ /**
+ * Returns the last delimiter character used to read a token.
+ */
+ public char getLastUsedDelimiterToken() {
+ return fLastUsedTokenDelimiter;
+ }
+
+ /**
+ * Returns the <code>OutputStream</code> used to send requests
+ * to the server.
+ */
+ public OutputStream getRequestStream() throws CVSException {
+ if (!isEstablished())
+ return null;
+ return serverConnection.getOutputStream();
+ }
+ /**
+ * Returns the <code>InputStream</code> used to read responses from
+ * the server.
+ */
+ public InputStream getResponseStream() throws CVSException {
+ if (!isEstablished())
+ return null;
+ if (fResponseStream == null)
+ fResponseStream= new BufferedInputStream(serverConnection.getInputStream());
+ return fResponseStream;
+ }
+
+ public String getRootDirectory() throws CVSException {
+ return getCVSRoot().getRootDirectory();
+ }
+
+ /**
+ * Returns <code>true</code> if the connection is established;
+ * otherwise <code>false</code>.
+ */
+ public boolean isEstablished() {
+ return fIsEstablished;
+ }
+ //--- Helper to read strings from server -----------------------------------------
+
+ /**
+ * Is input available in the response stream.
+ */
+ // NIK: is not used
+ public boolean isInputAvailable() {
+ if (!isEstablished())
+ return false;
+ try {
+ return getResponseStream().available() != 0;
+ } catch (CVSException e) {
+ return false;
+ } catch (IOException e) {
+ return false;
+ }
+ }
+ public boolean isClosed() {
+ return closed;
+ }
+ /**
+ * Creates a blank separated string from the given string array.
+ */
+ private String makeString(String[] s) {
+ StringBuffer buffer= new StringBuffer();
+ for (int i= 0; i < s.length; i++) {
+ if (i != 0)
+ buffer.append(' ');
+ buffer.append(s[i]);
+ }
+ return buffer.toString();
+ }
+ /**
+ * Opens the connection.
+ */
+ public void open() throws CVSException {
+ if (isEstablished())
+ return;
+ try {
+ serverConnection.open();
+ } catch (IOException e) {
+ throw new CVSCommunicationException(e);
+ }
+ fIsEstablished= true;
+ }
+ /**
+ * Reads a line from the response stream.
+ */
+ public String readLine() throws CVSException {
+ return readLineOrUntil(-1);
+ }
+
+static String readLine(InputStream in) throws IOException {
+ byte[] buffer = new byte[256];
+ int index = 0;
+ int r;
+ while ((r = in.read()) != -1) {
+ if (r == NEWLINE)
+ break;
+ buffer = append(buffer, index++, (byte) r);
+ }
+ String result = new String(buffer, 0, index);
+ if (DEBUG)
+ System.out.println(result);
+ return result;
+}
+
+/**
+ * Low level method to read a token.
+ */
+private String readLineOrUntil(int end) throws CVSException {
+ if (!isEstablished())
+ throw new CVSCommunicationException(Policy.bind("Connection.readUnestablishedConnection"));
+ byte[] buffer = new byte[256];
+ InputStream in = getResponseStream();
+ int index = 0;
+ int r;
+ try {
+ while ((r = in.read()) != -1) {
+ if (r == NEWLINE || (end != -1 && r == end))
+ break;
+ buffer = append(buffer, index++, (byte) r);
+ }
+ switch (r) {
+ case -1 :
+ closed = true;
+ case NEWLINE :
+ fLastUsedTokenDelimiter = '\n';
+ break;
+ default :
+ fLastUsedTokenDelimiter = (char) r;
+ }
+ String result = new String(buffer, 0, index);
+ if (DEBUG)
+ System.out.print(result + fLastUsedTokenDelimiter);
+ return result;
+ } catch (IOException e) {
+ throw new CVSCommunicationException(e);
+ }
+}
+ /**
+ * Reads any pending input from the response stream so that
+ * the stream can savely be closed.
+ */
+ protected void readPendingInput() throws CVSException {
+ byte[] buffer= new byte[2048];
+ InputStream in= getResponseStream();
+ OutputStream out= getRequestStream();
+ try {
+ while (true) {
+ int available = in.available();
+ if (available < 1) break;
+ if (available > buffer.length) available = buffer.length;
+ if (in.read(buffer, 0, available) < 1) break;
+ }
+ out.flush();
+ while (true) {
+ int available = in.available();
+ if (available < 1) break;
+ if (available > buffer.length) available = buffer.length;
+ if (in.read(buffer, 0, available) < 1) break;
+ }
+ } catch (IOException e) {
+ throw new CVSCommunicationException(e);
+ }
+ }
+ /**
+ * Reads a token from the response stream.
+ */
+ public String readToken() throws CVSException {
+ return readLineOrUntil(' ');
+ }
+ /**
+ * Sends the given array of strings to the server. The array's strings
+ * are concatenated using a blank.
+ */
+ public void write(String[] a) throws CVSException {
+ write(makeString(a), false);
+ }
+ //---- Helper to send strings to the server ----------------------------
+
+ /**
+ * Sends the given string to the server.
+ */
+ public void write(String s) throws CVSException {
+ write(s, false);
+ }
+ /**
+ * Sends the given two strings separated by a blank to the
+ * server.
+ */
+ public void write(String s1, String s2) throws CVSException {
+ write(s1 + ' ' + s2, false);
+ }
+ /**
+ * Low level method to write a string to the server. All write* methods are
+ * funneled through this method.
+ */
+ void write(String s, boolean newline) throws CVSException {
+ if (!isEstablished())
+ throw new CVSCommunicationException(Policy.bind("Connection.writeUnestablishedConnection"));
+
+ if (DEBUG)
+ System.out.print(s + (newline ? "\n" : ""));
+
+ try {
+ OutputStream out= getRequestStream();
+ out.write(s.getBytes());
+ if (newline)
+ out.write(NEWLINE);
+ out.flush();
+
+ } catch (IOException e) {
+ throw new CVSCommunicationException(e);
+ }
+ }
+ /**
+ * Sends the given array of strings to the server. The array's strings
+ * are concatenated using a blank. Additionally a newline is sent.
+ */
+ public void writeLine(String[] a) throws CVSException {
+ write(makeString(a), true);
+ }
+ /**
+ * Sends the given string and a newline to the server.
+ */
+ public void writeLine(String s) throws CVSException {
+ write(s, true);
+ }
+ /**
+ * Sends the given two strings separated by a blank to the
+ * server. Additionally a newline is sent.
+ */
+ public void writeLine(String s1, String s2) throws CVSException {
+ write(s1 + ' ' + s2, true);
+ }
+}
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/messages.properties b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/messages.properties index d2825550d..83ac32492 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/messages.properties +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/messages.properties @@ -1,92 +1,88 @@ -org.eclipse.team.internal.provider.cvs.CVSException=CVS Error: {0} - -CVSAuthenticationException.normal=Authentication error connecting to {0} -CVSAuthenticationException.detail=Authentication error: {0} - -CVSCommunicationException.io=CVS communication error: {0} -CVSFileException.io=Error accessing CVS file -CVSDiffException.message=The compared files are different - -java.io.IOException={0} -java.io.EOFException=End of file encountered: {0} -java.io.FileNotFoundException=File not found: {0} -java.io.InterruptedIOException=Interrupted IO: {0} -java.net.UnknownHostException=Cannot locate host: {0} - -Connection.cannotClose=Cannot close connection - -PServerConnection.invalidChars=Invalid characters in password -PServerConnection.noUser=No user specified -PServerConnection.hostInvalid=Invalid host -PServerConnection.loginRefused=Incorrect user name or password -PServerConnection.invalidUser={0} -PServerConnection.host=Cannot locate host: {0} -PServerConnection.socket=Cannot connect to host: {0} -PServerConnection.connectionRefused=Connection refused: {0} -PServerConnection.stream=Error opening socket connection -PServerConnection.noResponse=No response from server - -CVSProviderPlugin.cannotUpdateDescription=Error updating project description - -CVSProvider.exception=Internal error occured. -CVSProvider.invalidResource=Resource {0} is not a CVS resource -CVSProvider.noUser=A user name is required when configuring a CVS repository -CVSProvider.noHost=A host is required when configuring a CVS repository -CVSProvider.noRoot=A root directory is required when configuring a CVS repository -CVSProvider.initialImport=Initial import - -CVSTeamProvider.deconfigureProblem=Error while deconfiguring CVS project {0} -CVSTeamProvider.initializationFailed=Initialization of CVS for project {0} failed -CVSTeamProvider.visitError=An error occurred while visiting resource {0} -CVSTeamProvider.invalidResource=Resource {0} is not a child of project {1} -CVSTeamProvider.checkinProblems - -ProjectDescriptionManager.unableToReadDescription=An error occured reading the project description -ProjectDescriptionManager.ioDescription=An IO error occured while writing the project description -ProjectDescriptionManager.coreDescription=A Core error occured while writing the project description - -ResourceDeltaVisitor.visitError=Error while processing resource deltas - -ResponseDispatcher.serverError=The CVS server responded with an error (see the CVS console) -ResponseDispatcher.receiving=Receiving reponse - -FileProperties.invalidEntryLine=Invalid entry line: {0} - -ManagedFile.receiving=Receiving file {0} -ManagedFile.sending=Sending file {0} -ManagedFile.transfer={0} ({1}K of {2}K bytes) - -RemoteFolder.errorFetchingRevisions=Error fetching file revision numbers -RemoteManagedResource.invalidOperation=Invalid operation performed on remote resource -RemoteManagedFolder.invalidChild=Invalid folder {0} received during remote operation - -Command.server=Contacting server -Command.invalidRoot=Resource {0} is not a valid CVS root directory -Command.invalidResource=Resource {0} is not a valid CVS resource - -RequestSender.sendModified=Sending modified file {0} - -Response.problemsReported=The CVS server reported an error (See the CVS console) - -DefaultHandler.connectionClosed=The connection to the server has been closed -ModTimeHandler.invalidFormat=The server modification time {0} is in an unknown format -Updated.numberFormat=Server did not send length of the file -UnsupportedHandler.message=Unsupported response received from server - -CVSRepositoryLocation.nullLocation=Location must not be null -CVSRepositoryLocation.emptyLocation=Location must not be empty -CVSRepositoryLocation.endWhitespace=Location must not end with whitespace -CVSRepositoryLocation.locationForm=Location must have form ':methodname:[user[:password]@]host[#port]:/path/to/cvsroot' -CVSRepositoryLocation.startOfLocation=Location must start with a connection method name enclosed in colons -CVSRepositoryLocation.methods=Only the following methods are supported: {0} -CVSRepositoryLocation.parsingMethod=Error in connection method specification -CVSRepositoryLocation.parsingUser=Error in user name specification -CVSRepositoryLocation.parsingPassword=Error in password specification -CVSRepositoryLocation.parsingHost=Error in host specification -CVSRepositoryLocation.parsingPort=Error in port specification -CVSRepositoryLocation.parsingRoot=Error in repository root directory specification -CVSRepositoryLocation.invalidFormat=Invalid CVS repository location format: {0} - -ProjectDescriptionContentHandler.xml=Error parsing project description file - -Util.invalidResource=Resource {1} is not relative to root {0} +org.eclipse.team.internal.provider.cvs.CVSException=CVS Error: {0}
+
+CVSAuthenticationException.normal=Authentication error connecting to {0}
+CVSAuthenticationException.detail=Authentication error: {0}
+
+CVSCommunicationException.io=CVS communication error: {0}
+CVSFileException.io=Error accessing CVS file
+CVSDiffException.message=The compared files are different
+
+java.io.IOException={0}
+java.io.EOFException=End of file encountered: {0}
+java.io.FileNotFoundException=File not found: {0}
+java.io.InterruptedIOException=Interrupted IO: {0}
+java.net.UnknownHostException=Cannot locate host: {0}
+
+Connection.cannotClose=Cannot close connection
+
+PServerConnection.invalidChars=Invalid characters in password
+PServerConnection.noUser=No user specified
+PServerConnection.hostInvalid=Invalid host
+PServerConnection.loginRefused=Incorrect user name or password
+PServerConnection.invalidUser={0}
+PServerConnection.host=Cannot locate host: {0}
+PServerConnection.socket=Cannot connect to host: {0}
+PServerConnection.connectionRefused=Connection refused: {0}
+PServerConnection.stream=Error opening socket connection
+PServerConnection.noResponse=No response from server
+
+CVSProviderPlugin.cannotUpdateDescription=Error updating project description
+
+CVSProvider.exception=Internal error occured.
+CVSProvider.invalidResource=Resource {0} is not a CVS resource
+
+CVSTeamProvider.deconfigureProblem=Error while deconfiguring CVS project {0}
+CVSTeamProvider.initializationFailed=Initialization of CVS for project {0} failed
+CVSTeamProvider.visitError=An error occurred while visiting resource {0}
+CVSTeamProvider.invalidResource=Resource {0} is not a child of project {1}
+CVSTeamProvider.checkinProblems
+
+ProjectDescriptionManager.unableToReadDescription=An error occured reading the project description
+ProjectDescriptionManager.ioDescription=An IO error occured while writing the project description
+ProjectDescriptionManager.coreDescription=A Core error occured while writing the project description
+
+ResourceDeltaVisitor.visitError=Error while processing resource deltas
+
+ResponseDispatcher.serverError=The CVS server responded with an error (see the CVS console)
+ResponseDispatcher.receiving=Receiving reponse
+
+FileProperties.invalidEntryLine=Invalid entry line: {0}
+
+ManagedFile.receiving=Receiving file {0}
+ManagedFile.sending=Sending file {0}
+ManagedFile.transfer={0} ({1}K of {2}K bytes)
+
+RemoteFolder.errorFetchingRevisions=Error fetching file revision numbers
+RemoteManagedResource.invalidOperation=Invalid operation performed on remote resource
+RemoteManagedFolder.invalidChild=Invalid folder {0} received during remote operation
+
+Command.server=Contacting server
+Command.invalidRoot=Resource {0} is not a valid CVS root directory
+Command.invalidResource=Resource {0} is not a valid CVS resource
+
+RequestSender.sendModified=Sending modified file {0}
+
+Response.problemsReported=The CVS server reported an error (See the CVS console)
+
+DefaultHandler.connectionClosed=The connection to the server has been closed
+ModTimeHandler.invalidFormat=The server modification time {0} is in an unknown format
+Updated.numberFormat=Server did not send length of the file
+UnsupportedHandler.message=Unsupported response received from server
+
+CVSRepositoryLocation.nullLocation=Location must not be null
+CVSRepositoryLocation.emptyLocation=Location must not be empty
+CVSRepositoryLocation.endWhitespace=Location must not end with whitespace
+CVSRepositoryLocation.locationForm=Location must have form ':methodname:[user[:password]@]host[#port]:/path/to/cvsroot'
+CVSRepositoryLocation.startOfLocation=Location must start with a connection method name enclosed in colons
+CVSRepositoryLocation.methods=Only the following methods are supported: {0}
+CVSRepositoryLocation.parsingMethod=Error in connection method specification
+CVSRepositoryLocation.parsingUser=Error in user name specification
+CVSRepositoryLocation.parsingPassword=Error in password specification
+CVSRepositoryLocation.parsingHost=Error in host specification
+CVSRepositoryLocation.parsingPort=Error in port specification
+CVSRepositoryLocation.parsingRoot=Error in repository root directory specification
+CVSRepositoryLocation.invalidFormat=Invalid CVS repository location format: {0}
+
+ProjectDescriptionContentHandler.xml=Error parsing project description file
+
+Util.invalidResource=Resource {1} is not relative to root {0}
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/requests/RequestSender.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/requests/RequestSender.java index 19229e576..54dc65396 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/requests/RequestSender.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/requests/RequestSender.java @@ -1,263 +1,265 @@ -package org.eclipse.team.internal.ccvs.core.requests; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.util.StringTokenizer; - -import org.eclipse.team.internal.ccvs.core.util.Assert; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.Policy; -import org.eclipse.team.internal.ccvs.core.connection.Connection; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFile; -import org.eclipse.team.internal.ccvs.core.response.IResponseHandler; - -/** - * The reqest-sender is the only way to send messages to the - * server. - * - * It has a lot of helper-methods like "sendGlobalOption, sendEntry ..." - * this do send messages with parameter up to the server. These ways of - * sending are discibed in the cvs-protocol specification - * - */ -public class RequestSender { - - /** Requests that don't expect any response from the server */ - public static final String ARGUMENT = "Argument"; - public static final String ARGUMENTX = "Argumentx"; - public static final String DIRECTORY = "Directory"; - public static final String ENTRY = "Entry"; - public static final String GLOBAL_OPTION = "Global_option"; - public static final String ROOT = "Root"; - public static final String UNCHANGED = "Unchanged"; - public static final String VALID_RESPONSES = "Valid-responses"; - public static final String QUESTIONABLE = "Questionable"; - public static final String KOPT = "Kopt"; - public static final String STATIC_DIRECTORY = "Static-directory"; - public static final String STICKY = "Sticky"; - public static final String MODIFIED = "Modified"; - public static final String IS_MODIFIED = "Is-modified"; - - /** Requests that do expect any response from the server */ - public static final String CHECKOUT = "co"; - public static final String IMPORT = "import"; - public static final String VALID_REQUESTS = "valid-requests"; - public static final String EXPAND_MODULES = "expand-modules"; - public static final String CI = "ci"; - public static final String STATUS = "status"; - public static final String UPDATE = "update"; - public static final String HISTORY = "history"; - public static final String ADD = "add"; - public static final String REMOVE = "remove"; - public static final String LOG = "log"; - public static final String RTAG = "rtag"; - public static final String TAG = "tag"; - public static final String DIFF = "diff"; - public static final String ADMIN = "admin"; - - /** Helper Constants that are not going to be send to server */ - public static final String SERVER_SEPERATOR = "/"; - private static final String EMPTY_LOCAL_FOLDER = "."; - private static final String LINEFEED = "\n"; - private static final String CRETURN = "\r"; - private static final String STANDARD_PERMISSION = "u=rw,g=rw,o=r"; - - /** - * The link to the server to send things out - */ - private Connection connection; - - /** - * List of the valid-request as stated from the - * server. - * For future checking on that. - */ - private String validRequests; - - /** - * Constructor that takes the connection - */ - public RequestSender (Connection connection) { - this.connection = connection; - } - - /** - * Is the given request a valid server request. - */ - public boolean isValidRequest(String requestName) { - if (validRequests == null) - return false; - return validRequests.indexOf(requestName) != -1; - } - - /** - * Set the list of valid-request when you get - * the list of valid request from the server. - */ - void setValidRequest(String validRequests) { - this.validRequests = validRequests; - } - - /** - * Get a Handler for the "valid-request", that does - * collect the information to this class. - */ - public IResponseHandler getValidRequestHandler() { - return new ValidRequestHandler(this); - } - - /** - * This is the general way to send text to the server. - * Most commonly it is used to send a single constant - * to the server - */ - public void writeLine(String data) throws CVSException { - connection.writeLine(data); - } - - /** - * Sends an argument to the server. If arg contains newlines - * of any kind the argument as one first argument and after - * that as argument extentions.<br> - * E.g.: sendArgument("Hello\nWorld\nHello\r World") is send as - * <ul> - * <li> Argument Hello - * <li> Argumentx World - * <li> Argumentx Hello - * <li> Argumentx World - * </ul> - */ - public void sendArgument(String arg) throws CVSException { - - StringTokenizer tokenizer; - - if (arg.indexOf(LINEFEED) == -1 && - arg.indexOf(CRETURN) == -1) { - connection.writeLine(ARGUMENT, arg); - return; - } - - // Create a tokenizer, that uses all newline-caracters as - // delimitor - tokenizer = new StringTokenizer(arg,LINEFEED + CRETURN); - - // We do not want an argument with a newlines only - Assert.isTrue(tokenizer.hasMoreTokens()); - - connection.writeLine(ARGUMENT, tokenizer.nextToken()); - while (tokenizer.hasMoreTokens()) { - connection.writeLine(ARGUMENTX, tokenizer.nextToken()); - } - } - - public void sendKopt(String arg) throws CVSException { - connection.writeLine(KOPT, arg); - } - - public void sendIsModified(String file) throws CVSException { - connection.writeLine(IS_MODIFIED, file); - } - - public void sendStaticDirectory() throws CVSException { - connection.writeLine(STATIC_DIRECTORY); - } - - /** - * The Directory request is sent as: - * <ul> - * <li>Directory localdir - * <li>repository_root/remotedir - * </ul> - * - * This note is copied from an old version: - * [Note: A CVS repository root can end with a trailing slash. The CVS server - * expects that the repository root sent contain this extra slash. Including - * the foward slash in addition to the absolute remote path makes for a string - * containing two consecutive slashes (e.g. /home/cvs/repo//projecta/a.txt). - * This is valid in the CVS protocol.] - */ - public void sendConstructedDirectory(String local, String remote) throws CVSException { - - // FIXME I do not know wether this method is "ModuleFile-safe" - - connection.writeLine(DIRECTORY, local); - connection.writeLine(connection.getRootDirectory() + - SERVER_SEPERATOR + remote); - } - - /** - * The Directory request is sent as: - * <ul> - * <li>Directory localdir - * <li>repository_root/remotedir - * </ul> - */ - public void sendDirectory(String local, String remote) throws CVSException { - - if (local.equals("")) { - local = EMPTY_LOCAL_FOLDER; - } - - connection.writeLine(DIRECTORY, local); - connection.writeLine(remote); - } - - public void sendEntry(String entryLine) throws CVSException { - connection.writeLine(ENTRY, entryLine); - } - - public void sendGlobalOption(String option) throws CVSException { - connection.writeLine(GLOBAL_OPTION, option); - } - - public void sendUnchanged(String filename) throws CVSException { - connection.writeLine(UNCHANGED, filename); - } - - public void sendQuestionable(String filename) throws CVSException { - connection.writeLine(QUESTIONABLE, filename); - } - - public void sendSticky(String tag) throws CVSException { - connection.writeLine(STICKY, tag); - } - - /** - * This does not only send the message to the server that the - * file is going to be uploaded.<br> - * It does also acctually upload the file.<br> - * NOTE: The entry line has to be send before calling this method - */ - public void sendModified(IManagedFile file, IProgressMonitor monitor, boolean binary) - throws CVSException { - - // boolean binary; - - // Send - // - MODIFIED - // - permissions - // - size - // - Content of the file - - // Does not send the entryLinde !! - connection.writeLine(MODIFIED, file.getName()); - - if (file.getFileInfo() == null || - file.getFileInfo().getPermissions() == null) { - connection.writeLine(STANDARD_PERMISSION); - } else { - connection.writeLine(file.getFileInfo().getPermissions()); - } - - String progressTitle = - Policy.bind("RequestSender.sendModified", file.getName()); - monitor.subTask(progressTitle); - file.sendTo(connection.getRequestStream(),monitor,binary); - } - - -} +package org.eclipse.team.internal.ccvs.core.requests;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.util.StringTokenizer;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.Policy;
+import org.eclipse.team.internal.ccvs.core.connection.Connection;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFile;
+import org.eclipse.team.internal.ccvs.core.resources.ResourceSyncInfo;
+import org.eclipse.team.internal.ccvs.core.response.IResponseHandler;
+import org.eclipse.team.internal.ccvs.core.util.Assert;
+
+/**
+ * The reqest-sender is the only way to send messages to the
+ * server.
+ *
+ * It has a lot of helper-methods like "sendGlobalOption, sendEntry ..."
+ * this do send messages with parameter up to the server. These ways of
+ * sending are discibed in the cvs-protocol specification
+ *
+ */
+public class RequestSender {
+
+ /** Requests that don't expect any response from the server */
+ public static final String ARGUMENT = "Argument";
+ public static final String ARGUMENTX = "Argumentx";
+ public static final String DIRECTORY = "Directory";
+ public static final String ENTRY = "Entry";
+ public static final String GLOBAL_OPTION = "Global_option";
+ public static final String ROOT = "Root";
+ public static final String UNCHANGED = "Unchanged";
+ public static final String VALID_RESPONSES = "Valid-responses";
+ public static final String QUESTIONABLE = "Questionable";
+ public static final String KOPT = "Kopt";
+ public static final String STATIC_DIRECTORY = "Static-directory";
+ public static final String STICKY = "Sticky";
+ public static final String MODIFIED = "Modified";
+ public static final String IS_MODIFIED = "Is-modified";
+
+ /** Requests that do expect any response from the server */
+ public static final String CHECKOUT = "co";
+ public static final String IMPORT = "import";
+ public static final String VALID_REQUESTS = "valid-requests";
+ public static final String EXPAND_MODULES = "expand-modules";
+ public static final String CI = "ci";
+ public static final String STATUS = "status";
+ public static final String UPDATE = "update";
+ public static final String HISTORY = "history";
+ public static final String ADD = "add";
+ public static final String REMOVE = "remove";
+ public static final String LOG = "log";
+ public static final String RTAG = "rtag";
+ public static final String TAG = "tag";
+ public static final String DIFF = "diff";
+ public static final String ADMIN = "admin";
+
+ /** Helper Constants that are not going to be send to server */
+ public static final String SERVER_SEPERATOR = "/";
+ private static final String EMPTY_LOCAL_FOLDER = ".";
+ private static final String LINEFEED = "\n";
+ private static final String CRETURN = "\r";
+ private static final String STANDARD_PERMISSION = "u=rw,g=rw,o=r";
+
+ /**
+ * The link to the server to send things out
+ */
+ private Connection connection;
+
+ /**
+ * List of the valid-request as stated from the
+ * server.
+ * For future checking on that.
+ */
+ private String validRequests;
+
+ /**
+ * Constructor that takes the connection
+ */
+ public RequestSender (Connection connection) {
+ this.connection = connection;
+ }
+
+ /**
+ * Is the given request a valid server request.
+ */
+ public boolean isValidRequest(String requestName) {
+ if (validRequests == null)
+ return false;
+ return validRequests.indexOf(requestName) != -1;
+ }
+
+ /**
+ * Set the list of valid-request when you get
+ * the list of valid request from the server.
+ */
+ void setValidRequest(String validRequests) {
+ this.validRequests = validRequests;
+ }
+
+ /**
+ * Get a Handler for the "valid-request", that does
+ * collect the information to this class.
+ */
+ public IResponseHandler getValidRequestHandler() {
+ return new ValidRequestHandler(this);
+ }
+
+ /**
+ * This is the general way to send text to the server.
+ * Most commonly it is used to send a single constant
+ * to the server
+ */
+ public void writeLine(String data) throws CVSException {
+ connection.writeLine(data);
+ }
+
+ /**
+ * Sends an argument to the server. If arg contains newlines
+ * of any kind the argument as one first argument and after
+ * that as argument extentions.<br>
+ * E.g.: sendArgument("Hello\nWorld\nHello\r World") is send as
+ * <ul>
+ * <li> Argument Hello
+ * <li> Argumentx World
+ * <li> Argumentx Hello
+ * <li> Argumentx World
+ * </ul>
+ */
+ public void sendArgument(String arg) throws CVSException {
+
+ StringTokenizer tokenizer;
+
+ if (arg.indexOf(LINEFEED) == -1 &&
+ arg.indexOf(CRETURN) == -1) {
+ connection.writeLine(ARGUMENT, arg);
+ return;
+ }
+
+ // Create a tokenizer, that uses all newline-caracters as
+ // delimitor
+ tokenizer = new StringTokenizer(arg,LINEFEED + CRETURN);
+
+ // We do not want an argument with a newlines only
+ Assert.isTrue(tokenizer.hasMoreTokens());
+
+ connection.writeLine(ARGUMENT, tokenizer.nextToken());
+ while (tokenizer.hasMoreTokens()) {
+ connection.writeLine(ARGUMENTX, tokenizer.nextToken());
+ }
+ }
+
+ public void sendKopt(String arg) throws CVSException {
+ connection.writeLine(KOPT, arg);
+ }
+
+ public void sendIsModified(String file) throws CVSException {
+ connection.writeLine(IS_MODIFIED, file);
+ }
+
+ public void sendStaticDirectory() throws CVSException {
+ connection.writeLine(STATIC_DIRECTORY);
+ }
+
+ /**
+ * The Directory request is sent as:
+ * <ul>
+ * <li>Directory localdir
+ * <li>repository_root/remotedir
+ * </ul>
+ *
+ * This note is copied from an old version:
+ * [Note: A CVS repository root can end with a trailing slash. The CVS server
+ * expects that the repository root sent contain this extra slash. Including
+ * the foward slash in addition to the absolute remote path makes for a string
+ * containing two consecutive slashes (e.g. /home/cvs/repo//projecta/a.txt).
+ * This is valid in the CVS protocol.]
+ */
+ public void sendConstructedDirectory(String local, String remote) throws CVSException {
+
+ // FIXME I do not know wether this method is "ModuleFile-safe"
+
+ connection.writeLine(DIRECTORY, local);
+ connection.writeLine(connection.getRootDirectory() +
+ SERVER_SEPERATOR + remote);
+ }
+
+ /**
+ * The Directory request is sent as:
+ * <ul>
+ * <li>Directory localdir
+ * <li>repository_root/remotedir
+ * </ul>
+ */
+ public void sendDirectory(String local, String remote) throws CVSException {
+
+ if (local.equals("")) {
+ local = EMPTY_LOCAL_FOLDER;
+ }
+
+ connection.writeLine(DIRECTORY, local);
+ connection.writeLine(remote);
+ }
+
+ public void sendEntry(String entryLine) throws CVSException {
+ connection.writeLine(ENTRY, entryLine);
+ }
+
+ public void sendGlobalOption(String option) throws CVSException {
+ connection.writeLine(GLOBAL_OPTION, option);
+ }
+
+ public void sendUnchanged(String filename) throws CVSException {
+ connection.writeLine(UNCHANGED, filename);
+ }
+
+ public void sendQuestionable(String filename) throws CVSException {
+ connection.writeLine(QUESTIONABLE, filename);
+ }
+
+ public void sendSticky(String tag) throws CVSException {
+ connection.writeLine(STICKY, tag);
+ }
+
+ /**
+ * This does not only send the message to the server that the
+ * file is going to be uploaded.<br>
+ * It does also acctually upload the file.<br>
+ * NOTE: The entry line has to be send before calling this method
+ */
+ public void sendModified(ICVSFile file, IProgressMonitor monitor, boolean binary)
+ throws CVSException {
+
+ // boolean binary;
+
+ // Send
+ // - MODIFIED
+ // - permissions
+ // - size
+ // - Content of the file
+
+ // Does not send the entryLinde !!
+ connection.writeLine(MODIFIED, file.getName());
+
+ ResourceSyncInfo info = file.getSyncInfo();
+ if (info == null ||
+ info.getPermissions() == null) {
+ connection.writeLine(STANDARD_PERMISSION);
+ } else {
+ connection.writeLine(info.getPermissions());
+ }
+
+ String progressTitle =
+ Policy.bind("RequestSender.sendModified", file.getName());
+ monitor.subTask(progressTitle);
+ file.sendTo(connection.getRequestStream(),monitor,binary);
+ }
+
+
+}
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/requests/ValidRequestHandler.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/requests/ValidRequestHandler.java index c043b0aa0..de6f3b870 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/requests/ValidRequestHandler.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/requests/ValidRequestHandler.java @@ -9,7 +9,7 @@ import java.io.PrintStream; import org.eclipse.team.internal.ccvs.core.CVSException;
import org.eclipse.team.internal.ccvs.core.connection.Connection;
-import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFolder;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFolder;
import org.eclipse.team.internal.ccvs.core.response.ResponseHandler;
@@ -40,7 +40,7 @@ class ValidRequestHandler extends ResponseHandler { public void handle(
Connection connection,
PrintStream monitor,
- IManagedFolder mRoot)
+ ICVSFolder mRoot)
throws CVSException {
// Set the ValidRequests of the requestSender
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/CVSEntryLineTag.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/CVSEntryLineTag.java new file mode 100644 index 000000000..14b73bbdb --- /dev/null +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/CVSEntryLineTag.java @@ -0,0 +1,58 @@ +package org.eclipse.team.internal.ccvs.core.resources;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.team.ccvs.core.CVSTag;
+
+public class CVSEntryLineTag extends CVSTag {
+
+ /*
+ * The parameter tag must not be null.
+ */
+ public CVSEntryLineTag(CVSTag tag) {
+ super(tag.getName(), tag.getType());
+ }
+
+ public CVSEntryLineTag(String entryLineTag) {
+ switch (entryLineTag.charAt(0)) {
+ case 'T' : type = BRANCH; break;
+ case 'N' : type = VERSION; break;
+ case 'D' : type = DATE; break;
+ default: type = HEAD;
+ }
+ name = entryLineTag.substring(1);
+ }
+ /*
+ * Returns the tag name
+ */
+ public String getName() {
+ return name;
+ }
+ /*
+ * Returns the tag type
+ */
+ public int getType() {
+ return type;
+ }
+
+ public String toEntryLineFormat() {
+ if (type == BRANCH)
+ return "T" + name;
+ else if (type == VERSION)
+ return "N" + name;
+ else if (type == DATE)
+ return "D" + name;
+ return "";
+ }
+
+ public boolean equals(Object obj) {
+ // We assume, that the name and type can not be null
+ if (obj == this) return true;
+ if (!(obj instanceof CVSEntryLineTag)) return false;
+ return (type == ((CVSEntryLineTag)obj).type) && name.equals(((CVSEntryLineTag)obj).name);
+ }
+}
+
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/CVSFile.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/CVSFile.java deleted file mode 100644 index 4ca9829ae..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/CVSFile.java +++ /dev/null @@ -1,203 +0,0 @@ -package org.eclipse.team.internal.ccvs.core.resources; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -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.util.HashMap; -import java.util.Map; - -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.Policy; -import org.eclipse.team.internal.ccvs.core.resources.api.ICVSFile; -import org.eclipse.team.internal.ccvs.core.util.Assert; - - -/** - * Implement the abstract fileSystem - * @see CVSResource - */ -class CVSFile extends CVSResource implements ICVSFile { - - // We could use a normal HashMap in case the caller does not have instances - // for all the time it needs the object - private static Map instancesCache = new HashMap(); - - // The ioResource is saved in CVSResource and used from there - // private File file; - - /** - * Do not use the constructor, as it does not support the caching. - * Use createInternalFileFrom instead. - */ - private CVSFile(File ioFile) { - // puts the file into resource - super(ioFile); - - Assert.isTrue(!ioFile.exists() || ioFile.isFile()); - } - - /** - * Use this method intead of the constructur. If CACHING == true - * the instances of this class are stored in a map and given you - * on request. - */ - static CVSFile createInternalFileFrom(File newFile) throws CVSException { - - CVSFile resultFile; - - try { - newFile = newFile.getCanonicalFile(); - } catch (IOException e) { - throw new CVSException(Policy.bind("CVSFolder.invalidPath"),e); - } - - if (!CACHING) { - return new CVSFile(newFile); - } - - resultFile = (CVSFile) instancesCache.get(newFile.getAbsolutePath()+KEY_EXTENTION); - - if (resultFile == null) { - resultFile = new CVSFile(newFile); - instancesCache.put(resultFile.ioResource.getAbsolutePath()+KEY_EXTENTION,resultFile); - } - - return resultFile; - } - - /** - * @see ICVSFile#getInputStream() - */ - public InputStream getInputStream() throws CVSException { - - exceptionIfNotExist(); - - try { - return new FileInputStream(ioResource); - } catch (IOException e) { - throw wrapException(e); - } - } - - /** - * @see CVSFile#createFileFromPath(String) - */ - public static ICVSFile createFileFrom(File newFile) throws CVSException { - - if (!newFile.getParentFile().exists()) { - throw new CVSException("You tried to create a file in an non-existing Folder"); - } - - try { - newFile = newFile.getCanonicalFile(); - } catch (IOException e) { - throw wrapException(e); - } - return createInternalFileFrom(newFile); - } - - /** - * @see ICVSFile#getOutputStream() - */ - public OutputStream getOutputStream() throws CVSException { - - // If the file is read-only we need to delete it before - // we can write it new - deleteIfProtected(ioResource); - - // No CVSException should happen here, unless - // the underlying system is not O.K. - try { - return new FileOutputStream(ioResource); - } catch (IOException e) { - throw wrapException(e); - } - } - - - /** - * @see ICVSFile#getSize() - */ - public long getSize() { - - return ioResource.length(); - } - - /** - * @see ICVSResource#delete() - */ - public void delete() { - super.delete(); - } - - /** - * @see ICVSResource#isFolder() - */ - public boolean isFolder() { - return false; - } - - - /** - * @see ICVSFile#getTimeStamp() - */ - public long getTimeStamp() { - return ioResource.lastModified(); - } - - - /** - * @see ICVSFile#setTimeStamp(Date) - */ - public void setTimeStamp(long msec) { - ioResource.setLastModified(msec); - } - - /** - * @see ICVSFile#getContent() - */ - public String[] getContent() throws CVSException { - return readFromFile(ioResource); - } - - /** - * @see ICVSFile#moveTo(ICVSFile) - */ - public void moveTo(ICVSFile file) throws CVSException { - - boolean success; - - success = ioResource.renameTo(new File(file.getPath())); - - if (!success) { - throw new CVSException("Move from " + ioResource + " to " + file + " was not possible"); - } - } - - /** - * @see ICVSResource#clearCache() - */ - public void clearCache(boolean deep) throws CVSException { - // Needs to clear any information stored with this file, as this - // is called on delete - } - - public void setReadOnly() { - - boolean sucess; - sucess = ioResource.setReadOnly(); - Assert.isTrue(sucess); - - } - -} - - diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/CVSFileNotFoundException.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/CVSFileNotFoundException.java new file mode 100644 index 000000000..e1438007c --- /dev/null +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/CVSFileNotFoundException.java @@ -0,0 +1,30 @@ +package org.eclipse.team.internal.ccvs.core.resources;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.connection.CVSAuthenticationException;
+import org.eclipse.team.internal.ccvs.core.connection.ResourceStatus;
+import org.eclipse.team.ccvs.core.CVSProviderPlugin;
+
+/**
+ * This exception represents the attemp to access a file/folder
+ * that did not exist.
+ */
+public class CVSFileNotFoundException extends CVSException {
+
+ public CVSFileNotFoundException(IStatus status) {
+ super(status);
+ }
+
+ public CVSFileNotFoundException(String message) {
+ super(message);
+ }
+}
+
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/CVSFolder.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/CVSFolder.java deleted file mode 100644 index a96fd2703..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/CVSFolder.java +++ /dev/null @@ -1,477 +0,0 @@ -package org.eclipse.team.internal.ccvs.core.resources; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.io.File; -import java.io.FileFilter; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.Policy; -import org.eclipse.team.internal.ccvs.core.resources.api.CVSFileNotFoundException; -import org.eclipse.team.internal.ccvs.core.resources.api.ICVSFile; -import org.eclipse.team.internal.ccvs.core.resources.api.ICVSFolder; -import org.eclipse.team.internal.ccvs.core.resources.api.ICVSResource; -import org.eclipse.team.internal.ccvs.core.resources.api.NotCVSFolderException; -import org.eclipse.team.internal.ccvs.core.util.Assert; -import org.eclipse.team.internal.ccvs.core.util.ListFileFilter; -import org.eclipse.team.internal.ccvs.core.util.Util; - - -/** - * Implement the abstract fileSystem - * @see CVSResource - */ -class CVSFolder extends CVSResource implements ICVSFolder { - - // The ioFolder is stored in the ioResource of the - // superclass CVSResource - // -- private File ioFolder; - - public static final String CVS_FOLDER_NAME = "CVS"; - - // We could use a normal HashMap in case the caller does not have instances - // for all the time it needs the object - private static Map instancesCache = new HashMap(); - private HashMap propertiesCache = new HashMap(); - private Boolean cvsFolderCache = null; - - /** - * NOT to be called (directly). Use createInternalFolder indtead. - */ - private CVSFolder(File ioFolder) { - // puts the file into resource - super(ioFolder); - - Assert.isTrue(ioFolder == null || !ioFolder.exists() || ioFolder.isDirectory()); - } - - /** - * @see ICVSFolder#getFolders() - */ - public ICVSFolder[] getFolders() throws CVSException { - - File[] folderList; - ICVSFolder[] cvsFolderList; - - // Get all folder without the cvs-folder - folderList = ioResource.listFiles(new FoFilter()); - cvsFolderList = new ICVSFolder[folderList.length]; - - - for (int i = 0; i<folderList.length; i++) { - cvsFolderList[i] = createInternalFolderFrom(folderList[i]); - } - return cvsFolderList; - } - - - /** - * @see ICVSFolder#getFiles() - */ - public ICVSFile[] getFiles() throws CVSException { - - File[] fileList; - ICVSFile[] cvsFileList; - - // Get all files - fileList = ioResource.listFiles(new FiFilter()); - cvsFileList = new ICVSFile[fileList.length]; - - for (int i = 0; i<fileList.length; i++) { - cvsFileList[i] = CVSFile.createInternalFileFrom(fileList[i]); - } - return cvsFileList; - } - - /** - * Does list the whole content of the folder - * (files and folders) - */ - public ICVSResource[] getResources() throws CVSException { - - File[] resourceList; - ICVSResource[] cvsResourceList; - - exceptionIfNotExist(); - - // Get all resources - resourceList = ioResource.listFiles(new NoCVSFilter()); - - - cvsResourceList = new ICVSResource[resourceList.length]; - - for (int i = 0; i<resourceList.length; i++) { - if (resourceList[i].isDirectory()) { - cvsResourceList[i] = createInternalFolderFrom(resourceList[i]); - } else { - cvsResourceList[i] = CVSFile.createInternalFileFrom(resourceList[i]); - } - } - - return cvsResourceList; - } - - - /** - * @see ICVSFolder#createFolder(String) - */ - public ICVSFolder createFolder(String name) throws CVSException { - return createFolderFrom(new File(ioResource, convertSeparator(name))); - } - - /** - * Get a file-object, that may or may not exist - */ - public static ICVSFolder createFolderFrom(File newFolder) throws CVSException { - - try { - newFolder = newFolder.getCanonicalFile(); - } catch (IOException e) { - throw wrapException(e); - } - - if (newFolder.getName().toUpperCase().equals(CVS_FOLDER_NAME)) { - throw new CVSException("You are not allowed to create the CVS-Folder"); - } else { - return createInternalFolderFrom(newFolder); - } - } - - /** - * Use this method intead of the constructur. If CACHING == true - * the instances of this class are stored in a map and given you - * on request. - */ - static CVSFolder createInternalFolderFrom(File newFolder) throws CVSException { - - CVSFolder resultFolder; - - try { - newFolder = newFolder.getCanonicalFile(); - } catch (IOException e) { - throw new CVSException(Policy.bind("CVSFolder.invalidPath"),e); - } - - if (!CACHING) { - return new CVSFolder(newFolder); - } - - resultFolder = (CVSFolder) instancesCache.get(newFolder.getAbsolutePath()+KEY_EXTENTION); - - if (resultFolder == null) { - resultFolder = new CVSFolder(newFolder); - instancesCache.put(resultFolder.ioResource.getAbsolutePath()+KEY_EXTENTION,resultFolder); - } - - return resultFolder; - } - - /** - * @see ICVSFolder#createFile(String) - * - */ - public ICVSFile createFile(String name) throws CVSException { - - // No converting of the seperators here - // this function does not work on subfolders anyway - return CVSFile.createFileFrom(new File(ioResource, name)); - - } - - - /** - * @see ICVSFolder#isCVSFolder() - */ - public boolean isCVSFolder() throws CVSFileNotFoundException { - - if (!CACHING || cvsFolderCache == null) { - exceptionIfNotExist(); - cvsFolderCache = new Boolean((new File(ioResource, CVS_FOLDER_NAME)).exists()); - } - - return cvsFolderCache.booleanValue(); - - } - - - /** - * @see ICVSFolder#makeCVSFolder() - */ - public void makeCVSFolder() throws CVSException { - - exceptionIfNotExist(); - - (new File(ioResource, CVS_FOLDER_NAME)).mkdir(); - - clearCache(false); - - } - - /** - * Throw an exception if the folder in no cvs-folder - */ - private File getCVSFolder() throws NotCVSFolderException, CVSFileNotFoundException { - - if (!isCVSFolder()) { - throw new NotCVSFolderException("You tried to do an cvs-operation on a non cvs-folder"); - } - - return new File(ioResource, CVS_FOLDER_NAME); - } - - /** - * @see ICVSFolder#setProperty(String, String[]) - */ - public void setProperty(String key, String[] content) throws CVSException { - - File cvsFolder; - File propertyFile; - - // If we have got a property that is null, - // then it is acctually an unset property - if (content == null) { - unsetProperty(key); - return; - } - - Assert.isTrue(content.length == 0 || content[0]!=null); - - cvsFolder = getCVSFolder(); - propertyFile = new File(cvsFolder, key); - - writeToFile(propertyFile,content); - - if (CACHING) { - propertiesCache.put(key, content); - } - } - - - /** - * @see ICVSFolder#unsetProperty(String) - */ - public void unsetProperty(String key) throws CVSException { - File cvsFolder; - - cvsFolder = getCVSFolder(); - (new File(cvsFolder, key)).delete(); - - if (CACHING) { - propertiesCache.put(key, null); - } - } - - - /** - * @see ICVSFolder#getProperty(String) - */ - public String[] getProperty(String key) - throws NotCVSFolderException, CVSException { - - String[] property; - File cvsFolder; - File propertyFile; - - if (CACHING && propertiesCache.containsKey(key)) { - return (String[])propertiesCache.get(key); - } - - cvsFolder = getCVSFolder(); - propertyFile = new File(cvsFolder, key); - - // If the property does not exsist we return null - // this is specified - if (propertyFile.exists()) { - property = readFromFile(propertyFile); - } else { - property = null; - } - - if (CACHING) { - propertiesCache.put(key, property); - } - - return property; - } - - /** - * The oposite of makeCVSFolder, - * does delete the whoole CVS folder - */ - public void unmakeCVSFolder() { - - File[] fileList; - - try { - if (!isCVSFolder()) { - return; - } - - fileList = getCVSFolder().listFiles(); - for (int i = 0; i < fileList.length; i++) { - fileList[i].delete(); - } - getCVSFolder().delete(); - clearCache(false); - } catch (CVSException e) { - Assert.isTrue(false); - } - - } - - /** - * @see ICVSResource#delete() - */ - public void delete() { - - // If there is nothing to delete return - if (!ioResource.exists()) { - return; - } - - ICVSResource[] resourceList; - - try { - resourceList = getResources(); - } catch (CVSException e) { - // If the file has been deletet in between we - // stop executing - return; - } - - for (int i = 0; i < resourceList.length; i++) { - resourceList[i].delete(); - } - - unmakeCVSFolder(); - super.delete(); - - try { - clearCache(false); - } catch (CVSException e) { - Assert.isTrue(false); - } - } - - - /** - * @see ICVSResource#isFolder() - */ - public boolean isFolder() { - return true; - } - - /** - * @see ICVSFolder#getChild(IPath) - */ - public ICVSResource getChild(String path) throws CVSException { - File file; - - file = new File(ioResource, convertSeparator(path)); - - if (!childExists(path)) { - throw new CVSFileNotFoundException(getPath() + "/" + path + " does not exist"); - } - - if (file.isDirectory()) { - return createInternalFolderFrom(file); - } else { - return CVSFile.createInternalFileFrom(file); - } - } - - - /** - * @see ICVSFolder#childExists(String) - */ - public boolean childExists(String name) { - return (new File(ioResource,name)).exists(); - } - - - /** - * @see ICVSFolder#childIsFolder(String) - */ - public boolean childIsFolder(String name) { - return (new File(ioResource,name)).isDirectory(); - } - - - /** - * @see ICVSFolder#mkdir() - */ - public void mkdir() throws CVSException { - - boolean success; - - success = ioResource.mkdir(); - if (!success && !exists()) { - throw new CVSException("Folder-Creation failed: " + getName()); - } - } - - /** - * @see ICVSResource#clearCache() - */ - public void clearCache(boolean deep) throws CVSException { - - ICVSResource[] resources; - - // Do that first, maybe we have got wrong entries - // cached - propertiesCache = new HashMap(); - cvsFolderCache = null; - - if (!deep) { - return; - } - - resources = getResources(); - - for (int i = 0; i < resources.length; i++) { - resources[i].clearCache(true); - } - - } - -} - - -/** - * Does filter that you get files back (and no folders) - */ -class FiFilter implements FileFilter { - public boolean accept(File file) { - return file.isFile(); - } -} - - -/** - * Does filter that you get folders back (and no files) - * Does not give the folder called - * cvs (no matter wether lowcase or upcase back) - */ -class FoFilter extends ListFileFilter { - public FoFilter() { - // get all folders, that are not the cvs-folder - super(new String[]{CVSFolder.CVS_FOLDER_NAME},true,false,true); - } -} - - -/** - * Gives you every Resouce but the CVS-Folder back - */ -class NoCVSFilter extends ListFileFilter { - public NoCVSFilter() { - // get all that is not the cvs-folder - super(new String[]{CVSFolder.CVS_FOLDER_NAME},true); - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSLocalSyncElement.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/CVSLocalSyncElement.java index 5c5d55df0..aadefbde6 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSLocalSyncElement.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/CVSLocalSyncElement.java @@ -1,125 +1,120 @@ -package org.eclipse.team.internal.ccvs.core; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.core.resources.IResource; -import org.eclipse.team.core.sync.ILocalSyncElement; -import org.eclipse.team.core.sync.IRemoteResource; -import org.eclipse.team.core.sync.LocalSyncElement; -import org.eclipse.team.internal.ccvs.core.resources.api.FileProperties; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFile; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFolder; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedResource; - -public class CVSLocalSyncElement extends LocalSyncElement { - - protected IManagedFolder folder; - protected IManagedResource cvsResource; - - protected IRemoteResource base; - protected IResource local; - - public CVSLocalSyncElement(IResource local, IRemoteResource base, IManagedFolder parent) { - this.folder = parent; - - this.local = local; - this.base = base; - - try { - this.cvsResource = folder.getChild(local.getFullPath().removeFirstSegments(1).toString()); - } catch(CVSException e) { - // XXX when should this fail - and what does it mean? - this.cvsResource = null; - } - } - - /* - * @see RemoteSyncElement#create(IResource, IRemoteResource, IRemoteResource) - */ - public ILocalSyncElement create(IResource local, IRemoteResource base, Object data) { - return new CVSLocalSyncElement(local, base, (IManagedFolder)data); - } - - /* - * @see ILocalSyncElement#getLocal() - */ - public IResource getLocal() { - return local; - } - - /* - * @see ILocalSyncElement#getBase() - */ - public IRemoteResource getBase() { - return base; - } - - /* - * @see ILocalSyncElement#isDirty() - */ - public boolean isDirty() { - if(cvsResource == null) { - return false; - } else { - if(cvsResource.isFolder()) { - return false; - } else { - try { - FileProperties info = ((IManagedFile)cvsResource).getFileInfo(); - if(info == null) { - return false; - } - return ((IManagedFile)cvsResource).isDirty(); - } catch(CVSException e) { - return true; - } - } - } - } - - /* - * @see ILocalSyncElement#isCheckedOut() - */ - public boolean isCheckedOut() { - return cvsResource != null; - } - - /* - * @see ILocalSyncElement#hasRemote() - */ - public boolean hasRemote() { - return cvsResource != null; - } - - /* - * @see RemoteSyncElement#getData() - */ - protected Object getData() { - return folder; - } - - /* - * Answers the CVS resource for this sync element - */ - public IManagedResource getCVSResource() { - return cvsResource; - } - /* - * @see LocalSyncElement#isIgnored(IResource) - */ - protected boolean isIgnored(IResource child) { - if(cvsResource==null || !cvsResource.isFolder() ) { - return false; - } else { - try { - IManagedResource managedChild = ((IManagedFolder)cvsResource).getChild(child.getName()); - return managedChild.isIgnored(); - } catch(CVSException e) { - return false; - } - } - } +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.core.sync.ILocalSyncElement;
+import org.eclipse.team.core.sync.IRemoteResource;
+import org.eclipse.team.core.sync.LocalSyncElement;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+
+public class CVSLocalSyncElement extends LocalSyncElement {
+
+ protected ICVSResource cvsResource;
+ protected IRemoteResource base;
+ protected IResource local;
+
+ public CVSLocalSyncElement(IResource local, IRemoteResource base) {
+
+ this.local = local;
+ this.base = base;
+
+ File file = new File(local.getLocation().toOSString());
+ if(local.getType() != IResource.FILE) {
+ this.cvsResource = new LocalFolder(file);
+ } else {
+ this.cvsResource = new LocalFile(file);
+ }
+ }
+
+ /*
+ * @see RemoteSyncElement#create(IResource, IRemoteResource, IRemoteResource)
+ */
+ public ILocalSyncElement create(IResource local, IRemoteResource base, Object data) {
+ return new CVSLocalSyncElement(local, base);
+ }
+
+ /*
+ * @see ILocalSyncElement#getLocal()
+ */
+ public IResource getLocal() {
+ return local;
+ }
+
+ /*
+ * @see ILocalSyncElement#getBase()
+ */
+ public IRemoteResource getBase() {
+ return base;
+ }
+
+ /*
+ * @see ILocalSyncElement#isDirty()
+ */
+ public boolean isDirty() {
+ if(cvsResource == null) {
+ return false;
+ } else {
+ if(cvsResource.isFolder()) {
+ return false;
+ } else {
+ try {
+ if(cvsResource.getSyncInfo()==null) {
+ return false;
+ }
+ return ((ICVSFile)cvsResource).isDirty();
+ } catch(CVSException e) {
+ return true;
+ }
+ }
+ }
+ }
+
+ /*
+ * @see ILocalSyncElement#isCheckedOut()
+ */
+ public boolean isCheckedOut() {
+ return cvsResource != null;
+ }
+
+ /*
+ * @see ILocalSyncElement#hasRemote()
+ */
+ public boolean hasRemote() {
+ return cvsResource != null;
+ }
+
+ /*
+ * @see RemoteSyncElement#getData()
+ */
+ protected Object getData() {
+ return null;
+ }
+
+ /*
+ * Answers the CVS resource for this sync element
+ */
+ public ICVSResource getCVSResource() {
+ return cvsResource;
+ }
+ /*
+ * @see LocalSyncElement#isIgnored(IResource)
+ */
+ protected boolean isIgnored(IResource child) {
+ if(cvsResource==null || !cvsResource.isFolder() ) {
+ return false;
+ } else {
+ try {
+ ICVSResource managedChild = ((ICVSFolder)cvsResource).getChild(child.getName());
+ return managedChild.isIgnored();
+ } catch(CVSException e) {
+ return false;
+ }
+ }
+ }
}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSRemoteSyncElement.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/CVSRemoteSyncElement.java index 194d87c74..bd5ec8d32 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSRemoteSyncElement.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/CVSRemoteSyncElement.java @@ -1,144 +1,145 @@ -package org.eclipse.team.internal.ccvs.core; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.core.resources.IResource; -import org.eclipse.team.ccvs.core.ICVSRemoteFile; -import org.eclipse.team.core.TeamException; -import org.eclipse.team.core.sync.ILocalSyncElement; -import org.eclipse.team.core.sync.IRemoteResource; -import org.eclipse.team.core.sync.IRemoteSyncElement; -import org.eclipse.team.core.sync.LocalSyncElement; -import org.eclipse.team.core.sync.RemoteSyncElement; -import org.eclipse.team.internal.ccvs.core.resources.api.FileProperties; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFile; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFolder; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedResource; -import org.eclipse.team.internal.ccvs.core.util.Assert; - -public class CVSRemoteSyncElement extends RemoteSyncElement { - - CVSLocalSyncElement localSync; - IRemoteResource remote; - - public CVSRemoteSyncElement(IResource local, IRemoteResource base, IRemoteResource remote, IManagedFolder parent) { - localSync = new CVSLocalSyncElement(local, base, parent); - this.remote = remote; - } - - /* - * @see RemoteSyncElement#create(IResource, IRemoteResource, IRemoteResource) - */ - public IRemoteSyncElement create(IResource local, IRemoteResource base, IRemoteResource remote, Object data) { - return new CVSRemoteSyncElement(local, base, remote, (IManagedFolder)data); - } - - /* - * @see IRemoteSyncElement#getRemote() - */ - public IRemoteResource getRemote() { - return remote; - } - - /* - * @see IRemoteSyncElement#isOutOfDate() - */ - public boolean isOutOfDate() { - - // XXX gender changes? - if(isContainer()) { - return false; - } - - boolean hasBase = false; - - IManagedResource cvsResource = localSync.getCVSResource(); - if(cvsResource != null && !cvsResource.isFolder()) { - try { - FileProperties info = ((IManagedFile)cvsResource).getFileInfo(); - if(info != null) { - hasBase = true; - } - } catch(CVSException e) { - return true; - } - } - boolean hasRemote = remote != null; - - if(hasBase && hasRemote) { - IManagedFile file = (IManagedFile)localSync.getCVSResource(); - try { - // at this point remote and file can't be null - Assert.isNotNull(remote); - Assert.isNotNull(file); - return ! ((ICVSRemoteFile)remote).getRevision().equalsIgnoreCase(file.getFileInfo().getVersion()); - } catch(CVSException e) { - return true; - } catch(TeamException e) { - return true; - } - } else if(hasBase && !hasRemote) { - return true; - } else { - return false; - } - } - - /* - * @see LocalSyncElement#getData() - */ - protected Object getData() { - return localSync.getData(); - } - - /* - * @see ILocalSyncElement#getLocal() - */ - public IResource getLocal() { - return localSync.getLocal(); - } - - /* - * @see ILocalSyncElement#getBase() - */ - public IRemoteResource getBase() { - return localSync.getBase(); - } - - /* - * @see ILocalSyncElement#isDirty() - */ - public boolean isDirty() { - return localSync.isDirty(); - } - - /* - * @see ILocalSyncElement#isCheckedOut() - */ - public boolean isCheckedOut() { - return localSync.isCheckedOut(); - } - - /* - * @see ILocalSyncElement#hasRemote() - */ - public boolean hasRemote() { - return remote != null; - } - - /* - * @see LocalSyncElement#create(IResource, IRemoteResource, Object) - */ - public ILocalSyncElement create(IResource local, IRemoteResource base, Object data) { - return localSync.create(local, base, data); - } - /* - * @see LocalSyncElement#isIgnored(IResource) - */ - protected boolean isIgnored(IResource resource) { - return localSync.isIgnored(resource); - } +package org.eclipse.team.internal.ccvs.core.resources;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.team.ccvs.core.ICVSRemoteFile;
+import org.eclipse.team.core.TeamException;
+import org.eclipse.team.core.sync.ILocalSyncElement;
+import org.eclipse.team.core.sync.IRemoteResource;
+import org.eclipse.team.core.sync.IRemoteSyncElement;
+import org.eclipse.team.core.sync.LocalSyncElement;
+import org.eclipse.team.core.sync.RemoteSyncElement;
+import org.eclipse.team.internal.ccvs.core.resources.ResourceSyncInfo;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFile;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFolder;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSResource;
+import org.eclipse.team.internal.ccvs.core.util.Assert;
+import org.eclipse.team.internal.ccvs.core.*;
+
+public class CVSRemoteSyncElement extends RemoteSyncElement {
+
+ CVSLocalSyncElement localSync;
+ IRemoteResource remote;
+
+ public CVSRemoteSyncElement(IResource local, IRemoteResource base, IRemoteResource remote) {
+ localSync = new CVSLocalSyncElement(local, base);
+ this.remote = remote;
+ }
+
+ /*
+ * @see RemoteSyncElement#create(IResource, IRemoteResource, IRemoteResource)
+ */
+ public IRemoteSyncElement create(IResource local, IRemoteResource base, IRemoteResource remote, Object data) {
+ return new CVSRemoteSyncElement(local, base, remote);
+ }
+
+ /*
+ * @see IRemoteSyncElement#getRemote()
+ */
+ public IRemoteResource getRemote() {
+ return remote;
+ }
+
+ /*
+ * @see IRemoteSyncElement#isOutOfDate()
+ */
+ public boolean isOutOfDate() {
+
+ // XXX gender changes?
+ if(isContainer()) {
+ return false;
+ }
+
+ boolean hasBase = false;
+
+ ICVSResource cvsResource = localSync.getCVSResource();
+ if(cvsResource != null && !cvsResource.isFolder()) {
+ try {
+ if(cvsResource.getSyncInfo() != null) {
+ hasBase = true;
+ }
+ } catch(CVSException e) {
+ return true;
+ }
+ }
+ boolean hasRemote = remote != null;
+
+ if(hasBase && hasRemote) {
+ ICVSFile file = (ICVSFile)localSync.getCVSResource();
+ try {
+ // at this point remote and file can't be null
+ Assert.isNotNull(remote);
+ Assert.isNotNull(file);
+ ResourceSyncInfo info = file.getSyncInfo();
+ return ! ((ICVSRemoteFile)remote).getRevision().equalsIgnoreCase(info.getRevision());
+ } catch(CVSException e) {
+ return true;
+ } catch(TeamException e) {
+ return true;
+ }
+ } else if(hasBase && !hasRemote) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /*
+ * @see LocalSyncElement#getData()
+ */
+ protected Object getData() {
+ return localSync.getData();
+ }
+
+ /*
+ * @see ILocalSyncElement#getLocal()
+ */
+ public IResource getLocal() {
+ return localSync.getLocal();
+ }
+
+ /*
+ * @see ILocalSyncElement#getBase()
+ */
+ public IRemoteResource getBase() {
+ return localSync.getBase();
+ }
+
+ /*
+ * @see ILocalSyncElement#isDirty()
+ */
+ public boolean isDirty() {
+ return localSync.isDirty();
+ }
+
+ /*
+ * @see ILocalSyncElement#isCheckedOut()
+ */
+ public boolean isCheckedOut() {
+ return localSync.isCheckedOut();
+ }
+
+ /*
+ * @see ILocalSyncElement#hasRemote()
+ */
+ public boolean hasRemote() {
+ return remote != null;
+ }
+
+ /*
+ * @see LocalSyncElement#create(IResource, IRemoteResource, Object)
+ */
+ public ILocalSyncElement create(IResource local, IRemoteResource base, Object data) {
+ return localSync.create(local, base, data);
+ }
+ /*
+ * @see LocalSyncElement#isIgnored(IResource)
+ */
+ protected boolean isIgnored(IResource resource) {
+ return localSync.isIgnored(resource);
+ }
}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/CVSResource.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/CVSResource.java deleted file mode 100644 index b4517cebb..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/CVSResource.java +++ /dev/null @@ -1,291 +0,0 @@ -package org.eclipse.team.internal.ccvs.core.resources; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.Policy; -import org.eclipse.team.internal.ccvs.core.resources.api.CVSFileNotFoundException; -import org.eclipse.team.internal.ccvs.core.resources.api.ICVSFolder; -import org.eclipse.team.internal.ccvs.core.resources.api.ICVSResource; -import org.eclipse.team.internal.ccvs.core.util.Assert; -import org.eclipse.team.internal.ccvs.core.util.Util; - -/** - * CVSResource, CVSFile, CVSFolder implement the - * ICVSResource, ICVSFile, ICVSFolder interfaces that are needed - * to use the cvs-client. - * - * Just call CVSFolder.createFolderFromPath(String path) to create an - * ICVSFolder and pass it to the client. - * - * @see CVSFolder#createFolderFromPath(String) - * @see CVSFolder - * @see CVSFile - * @see CVSResource - * @see ICVSFolder - * @see ICVSFile - * @see ICVSResource - */ -abstract class CVSResource implements ICVSResource { - - public static final boolean CACHING = true; - - // If we do not extend the key and therefore the key is the same like - // the absolut pathname we have indirectly an reference to the key in - // the weak hashmap. Therefore the WeakHashMap does not finalize anything - static final String KEY_EXTENTION = "KEY"; - - public static final String PLATFORM_NEWLINE = System.getProperty("line.separator"); - - File ioResource; - - CVSResource(String path) { - this(new File(path)); - } - - - CVSResource(File ioResource) { - this.ioResource = ioResource; - } - - - /** - * @see ICVSResource#getName() - */ - public String getName() { - -// String path; -// int lastFileSeperatorPos; -// String name; -// -// path = ioResource.getAbsolutePath(); -// lastFileSeperatorPos = path.lastIndexOf(File.separator); -// // check that -// name = path.substring(lastFileSeperatorPos + 1); - - return ioResource.getName(); - } - - /** - * @see ICVSResource#getPath() - */ - public String getPath() { - return ioResource.getAbsolutePath(); - } - - - /** - * @see ICVSResource#delete() - */ - public void delete() { - ioResource.delete(); - } - - - /** - * @see ICVSResource#getParent() - */ - public ICVSFolder getParent() { - - try { - return CVSFolder.createInternalFolderFrom(ioResource.getParentFile()); - } catch (CVSException e) { - // This should not happen, because the canonical Path of - // a parent should be O.K. - throw new RuntimeException("Can not canonize: " + ioResource.getParentFile().getAbsolutePath()); -// Util.logError(Policy.bind("CVSFolder.invalidPath"),e); -// Assert.isTrue(false); -// return null; - } - } - - /** - * Equals is equals on the abstract pathnames - */ - public boolean equals(Object obj) { - - if (!(obj instanceof CVSResource)) { - return false; - } else { - return ((CVSResource) obj).getPath().equals(getPath()); - } - } - - /** - * Generate a Standard CVSException for an - * IOException - */ - protected static CVSException wrapException(IOException e) { - return new CVSException(IStatus.ERROR, - CVSException.IO_FAILED, - "An IOException occured while using your file-system.", - e); - } - - /** Clean up fileName. "/" and "\" are both replaced for - * File.seperator - */ - protected static String convertSeparator(String path) { - if (File.separatorChar == '/') { - return path.replace('\\','/'); - } else { - return path.replace('/','\\'); - } - } - - /** - * Give the pathname back - */ - public String toString() { - return getPath(); - } - - /** - * @see ICVSResource#isFolder() - */ - public boolean isFolder() { - return false; - } - - - /** - * @see ICVSResource#exists() - */ - public boolean exists() { - return ioResource.exists(); - } - - /** - * throw an exeption, if the underlying resource - * does not exist. - */ - void exceptionIfNotExist() throws CVSFileNotFoundException { - - if (!exists()) { - throw new CVSFileNotFoundException(ioResource + " not found"); - } - } - - /** - * Write String[] to file as lines - * - * @param file has to be non-null - * @param content has to be non-null - */ - protected static void writeToFile(File file, String[] content) - throws CVSException { - writeToFile(file, content, PLATFORM_NEWLINE); - /* - BufferedWriter fileWriter; - - try { - fileWriter = new BufferedWriter(new FileWriter(file)); - for (int i = 0; i<content.length; i++) { - fileWriter.write(content[i]); - fileWriter.newLine(); - } - fileWriter.close(); - } catch (IOException e) { - throw rapIOtoCVS(e); - } - */ - } - - /** - * Write String[] to file as lines - * - * @param file has to be non-null - * @param content has to be non-null - */ - protected static void writeToFile(File file, String[] content, String delim) - throws CVSException { - - BufferedWriter fileWriter; - - deleteIfProtected(file); - - try { - fileWriter = new BufferedWriter(new FileWriter(file)); - for (int i = 0; i<content.length; i++) { - fileWriter.write(content[i]); - fileWriter.write(delim); - } - fileWriter.close(); - } catch (IOException e) { - throw wrapException(e); - } - } - - /** - * Delete the file if it is WriteProtected in order to be able to - * write new content in this place - */ - protected static void deleteIfProtected(File ioFile) throws CVSException { - - boolean sucess; - - // If the file is read-only we need to delete it before - // we can write it new - if (!ioFile.canWrite()) { - sucess = ioFile.delete(); - if (!sucess && ioFile.exists()) { - throw new CVSException("Not able to delete file"); - } - } - } - - /** - * load file in lines to String[] - * - * @param file has to be non-null and file.exists() == true - */ - protected static String[] readFromFile(File file) - throws CVSException { - - BufferedReader fileReader; - List fileContentStore = new ArrayList(); - String line; - - try { - fileReader = new BufferedReader(new FileReader(file)); - while ((line = fileReader.readLine()) != null) { - fileContentStore.add(line); - } - fileReader.close(); - } catch (IOException e) { - throw wrapException(e); - } - - return (String[]) fileContentStore.toArray(new String[fileContentStore.size()]); - } - - /** - * This is to be used by the ResourceFactory only - */ - public File getIOResource() { - return ioResource; - } - - /** - * Implement the hashcode on the underlying strings, like it - * is done in the equals. - */ - public int hashCode() { - return getPath().hashCode(); - } -} - - diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/FilePropertiesContainer.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/FilePropertiesContainer.java deleted file mode 100644 index 1647aca38..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/FilePropertiesContainer.java +++ /dev/null @@ -1,278 +0,0 @@ -package org.eclipse.team.internal.ccvs.core.resources; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.resources.api.FileProperties; -import org.eclipse.team.internal.ccvs.core.resources.api.ICVSFile; -import org.eclipse.team.internal.ccvs.core.resources.api.ICVSFolder; -import org.eclipse.team.internal.ccvs.core.util.Assert; - -/** - * A FilePropertiesContainer stores informations about the files - * of a folder. It cares about loading saving this information - * in the folder the container belongs to. - */ -public class FilePropertiesContainer { - - private ICVSFolder cvsFolder; - - private static final String seperator = "/"; - private static final String FOLDER_ENTRY = "D/"; - private static final String ENTRIES = FileProperties.ENTRIES; - - /** - * Construct a container for the file-infos for - * the files of this folder - */ - public FilePropertiesContainer(ICVSFolder cvsFolder, boolean autoSave) { - this.cvsFolder = cvsFolder; - } - - /** - * Costruct a FileProperties-Object for the file. - * The file has to be child of the folder. - * - * Changing the FileProperties does not change anything - * in the FilePropertiesContainer. You have to set the - * fileInfo to acctually change something. - */ - public FileProperties getFileInfo(String fileName) throws CVSException { - - FileProperties fileProperties = new FileProperties(); - String key; - String property; - boolean foundFile = false; - - if (!cvsFolder.isCVSFolder()) { - return null; - } - - // Go through all the keys that we want to load from - // our cvsFolder - // take them from cvsFolder and put them into our - // new FileProperties - for (Iterator i = fileProperties.keySet().iterator(); i.hasNext();) { - key = (String) i.next(); - property = getProperty(key,fileName); - - if (property != null) { - fileProperties.putProperty(key,property); - foundFile = true; - } - } - - // If there was nothing to load at all, then we give null back - // istead of the empty FileProperties - // I do not know if we really need that - if (foundFile) { - return fileProperties; - } else { - return null; - } - } - - /** - * Set the fileinfo into the container. - */ - public void setFileInfo(String fileName, FileProperties fileProperties) throws CVSException { - - Assert.isNotNull(fileName); - Assert.isTrue(fileProperties == null || fileName.equals(fileProperties.getName())); - - String key; - - // If we want to "unset" the file, then we just create a - // new FileProperties, what is going to have null in all - // arguments, and null removes the value. - if (fileProperties == null) { - fileProperties = new FileProperties(); - } - - for (Iterator i = fileProperties.keySet().iterator(); i.hasNext();) { - key = (String)i.next(); - putProperty(key,fileName,fileProperties.getProperty(key)); - } - } - - /** - * Set a property of a file to the value. Value null removes the - * information. Saves this information in the cvsFolder. - */ - private void putProperty(String key,String fileName,String value) throws CVSException { - - String[] data; - Map mapData = new HashMap(); - int start; - int end; - boolean noDirectories = false; - - data = cvsFolder.getProperty(key); - - if (data != null) { - for (int i = 0; i < data.length; i++) { - start = data[i].indexOf(seperator)+1; - end = data[i].indexOf(seperator,start+1); - // The entry may contain a D indicating that there are no directories. ignore the D. - if (start != -1 && end != -1) - mapData.put(data[i].substring(start,end),data[i]); - } - } - - if (value == null) { - mapData.remove(fileName); - } else { - mapData.put(fileName,formatProperty(fileName,value)); - } - - cvsFolder.setProperty(key, - (String[])mapData.values().toArray(new String[mapData.size()])); - } - - /** - * Get a property for a file. - */ - private String getProperty(String key, String fileName) throws CVSException { - - String[] data = cvsFolder.getProperty(key); - String fileKey = seperator + fileName + seperator; - - if (data == null) { - return null; - } - - for (int j = 0; j < data.length; j++) { - if (data[j].startsWith(fileKey) || data[j].substring(1).startsWith(fileKey)) { - return data[j]; - } - } - - return null; - } - - /** - * Bring a value into a valid property-format. If the - * value is not in the "{something}/filename/{something}"-format - * "/filename/" is the new prefix of the String. - */ - private String formatProperty(String fileName,String value) { - - int start; - int end; - String fileKey = seperator + fileName + seperator; - - if (value == null) { - return null; - } - - start = value.indexOf(seperator)+1; - end = value.indexOf(seperator,start+1); - - if (start != -1 && end != -1 && - value.substring(start,end).equals(fileName)) { - return value; - } else { - return fileKey + value; - } - } - - - /** - * Adds folders to the container - * - * @throws CVSException if autoSave & !folder.exists() - */ - public void addFolder(String name) throws CVSException { - String entryLine; - entryLine = FOLDER_ENTRY + name + "////"; - putProperty(ENTRIES,name,entryLine); - } - - /** - * Removes folders from the conatainer - */ - public void removeFolder(String name) throws CVSException { - putProperty(ENTRIES,name,null); - } - - /** - * Is the folder in the container ? - */ - public boolean containsFolder(String fileName) throws CVSException { - return getProperty(ENTRIES,fileName) != null; - } - - /** - * This gives a list of all files stated in the - * entries. These files do not have to exist on - * the filesystem. - */ - public ICVSFile[] getEntriesFileList() throws CVSException { - - List fileList = new ArrayList(); - String fileName; - String[] entries; - - // If we are not in an cvs-folder or the entries are empty we do not have - // entry-files. - // NOTE: We are setting the entries-variable in that momnet - if (!cvsFolder.isCVSFolder() || - (entries = cvsFolder.getProperty(ENTRIES)) == null) { - return new ICVSFile[0]; - } - - for (int i=0; i<entries.length; i++) { - if (entries[i].startsWith(seperator)) { - - // get the name of the file with the help of the - // of the FileProperties Object. We need to do that in - // another way sometime - fileName = (new FileProperties(entries[i],null)).getName(); - fileList.add(cvsFolder.createFile(fileName)); - } - } - - return (ICVSFile[]) fileList.toArray(new ICVSFile[fileList.size()]); - } - - /** - * This gives a list of all folders stated in the - * entries. These files do not have to exist on - * the filesystem. - */ - public ICVSFolder[] getEntriesFolderList() throws CVSException { - - List folderList = new ArrayList(); - String folderName; - - String[] entries; - - // If we are not in an cvs-folder or the entries are empty we do not have - // entry-files. - // NOTE: We are setting the entries in that momnet - if (!cvsFolder.isCVSFolder() || - (entries = cvsFolder.getProperty(ENTRIES)) == null) { - return new ICVSFolder[0]; - } - - for (int i=0; i<entries.length; i++) { - if (entries[i].startsWith(FOLDER_ENTRY)) { - folderName = entries[i].substring(FOLDER_ENTRY.length()); - folderName = folderName.substring(0,folderName.indexOf(seperator)); - folderList.add(cvsFolder.createFolder(folderName)); - } - } - - return (ICVSFolder[]) folderList.toArray(new ICVSFolder[folderList.size()]); - } -} - diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/FolderSyncInfo.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/FolderSyncInfo.java new file mode 100644 index 000000000..e2ebf5d8d --- /dev/null +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/FolderSyncInfo.java @@ -0,0 +1,118 @@ +package org.eclipse.team.internal.ccvs.core.resources;
+
+import org.eclipse.team.ccvs.core.CVSTag;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+
+public class FolderSyncInfo {
+
+ private String repository;
+ private String root;
+ private CVSEntryLineTag tag;
+ private boolean isStatic;
+
+ public FolderSyncInfo() {
+ }
+
+ public FolderSyncInfo(String repo, String root, boolean isStatic) {
+ this.repository = repo;
+ this.root = root;
+ this.isStatic = isStatic;
+ }
+
+ public FolderSyncInfo(String repo, String root, String entryLineTag, boolean isStatic) {
+ this(repo, root, isStatic);
+ if(entryLineTag!=null) {
+ this.tag = new CVSEntryLineTag(entryLineTag);
+ }
+ }
+
+ /*
+ * The provided tag must not be null.
+ */
+ public FolderSyncInfo(String repo, String root, CVSTag tag, boolean isStatic) {
+ this(repo, root, isStatic);
+ this.tag = new CVSEntryLineTag(tag);
+ }
+
+ /**
+ * Gets the root.
+ * @return Returns a String
+ */
+ public String getRoot() {
+ return root;
+ }
+
+ /**
+ * Sets the root.
+ * @param root The root to set
+ */
+ public void setRoot(String root) {
+ this.root = root;
+ }
+
+ /**
+ * Gets the tag.
+ * @return Returns a String
+ */
+ public CVSEntryLineTag getTag() {
+ return tag;
+ }
+
+ /**
+ * Sets the tag for the folder. The provided tag must not be null.
+ * @param tag The tag to set
+ */
+ public void setTag(CVSTag tag) {
+ this.tag = new CVSEntryLineTag(tag);
+ }
+
+ /**
+ * Gets the repository.
+ * @return Returns a String
+ */
+ public String getRepository() {
+ return repository;
+ }
+
+ /**
+ * Sets the repository.
+ * @param repository The repository to set
+ */
+ public void setRepository(String repository) {
+ this.repository = repository;
+ }
+ /**
+ * Gets the isStatic.
+ * @return Returns a boolean
+ */
+ public boolean getIsStatic() {
+ return isStatic;
+ }
+
+ /**
+ * Sets the isStatic.
+ * @param isStatic The isStatic to set
+ */
+ public void setIsStatic(boolean isStatic) {
+ this.isStatic = isStatic;
+ }
+
+ /**
+ * Compute the remote-location out of root and repository
+ */
+ public String getRemoteLocation() throws CVSException {
+
+ String result;
+
+ try {
+ result = getRoot().substring(getRoot().indexOf("@")+1);
+ result = result.substring(result.indexOf(":")+1);
+ result = result + "/" + getRepository();
+ } catch (IndexOutOfBoundsException e) {
+ throw new CVSException("Maleformed root");
+ }
+
+ return result;
+ }
+}
+
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/api/IManagedFile.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/ICVSFile.java index 53cfb54a3..4667e60b8 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/api/IManagedFile.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/ICVSFile.java @@ -1,119 +1,92 @@ -package org.eclipse.team.internal.ccvs.core.resources.api; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.io.InputStream; -import java.io.OutputStream; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.internal.ccvs.core.CVSException; - -/** - * The managedFile gives you an FileProperties-Object, that - * conains CVS-specific information about a file. - * - * It also provides sending and reciving contend to/from an - * OutputStream/InputStrem. - * - * @see IManagedResource - */ -public interface IManagedFile extends IManagedResource { - - /** - * Get the size of a file - * - * @return 0 if exists() = false - */ - long getSize(); - - /** - * Get the FileProperties for this file - * - * Changing the Object has no influence on - * the infos of the file, you need to set it. - * - * @see IManagedFile#setFileInfo(FileProperties) - * @return null if the file is not in the entries-list of the parent-folder (can return something also exists() = false) - */ - FileProperties getFileInfo() throws CVSException; - - /** - * Set the FileProperties for the file. - * - * @param if fileInfo == null, the info is removed - * @throws CVSException if getName() != fileInfo.getName() - */ - void setFileInfo(FileProperties fileInfo) throws CVSException; - - /** - * Send the fileContend to an InputStream. - * A progressmonitor monitors this process. - * - * If not exists() the file is created. - * - * @throws CVSException if file is contained by an non-existing folder - * @throws CVSException if it is not possible to write the file - */ - void sendTo(OutputStream outputStream, IProgressMonitor monitor, boolean binary) throws CVSException; - - /** - * Get the fileContend from a stream and put - * it into this file. - * - * @throws CVSFileNotFoundException if not exists() - */ - void receiveFrom(InputStream inputStream, IProgressMonitor monitor, long size, boolean binary, boolean readOnly) throws CVSException; - - /** - * Get the timpstamp of the file as a date - * the format is going to be like: Thu Oct 18 20:21:13 2001 - * - * @throws CVSFileNotFoundException if exists() = false - */ - String getTimeStamp() throws CVSFileNotFoundException; - - /** - * Set the timpstamp of the file as a date - * the format needs to be like: Thu Oct 18 20:21:13 2001 - * - * if the date==null then the current time is used as - * timestamp - * - * @throws CVSFileNotFoundException if exists() = false - * @throws CVSException if the format of the date is not correct - */ - void setTimeStamp(String date) throws CVSException; - - /** - * Move the resource to another location. Does overwrite without - * promting. - * - * @throws CVSException if the move was not successful - * @throws ClassCastException if getClass != mFile.getClass - */ - void moveTo(IManagedFile mFile) throws CVSException, ClassCastException; - - /** - * Gives the content of the file as a string-array. - * This is thought for testing purpose only. - * - * @throws CVSFileNotFoundException if exists() = false - */ - String[] getContent() throws CVSException; - - /** - * Get if the file has been modified since the last time - * saved in the fileEntry. This is the exact but slow - * operation that acctually reads the dirty-state from - * disk. - * - * @return true if !isManaged() - * @throws CVSFileNotFoundException if exists() = false - */ - boolean isDirty() throws CVSException; -} - - +package org.eclipse.team.internal.ccvs.core.resources;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+
+/**
+ * The managedFile gives you an FileProperties-Object, that
+ * conains CVS-specific information about a file.
+ *
+ * It also provides sending and reciving contend to/from an
+ * OutputStream/InputStrem.
+ *
+ * @see ICVSResource
+ */
+public interface ICVSFile extends ICVSResource {
+
+ /**
+ * Get the size of a file
+ *
+ * @return 0 if exists() = false
+ */
+ long getSize();
+
+ /**
+ * Send the fileContend to an InputStream.
+ * A progressmonitor monitors this process.
+ *
+ * If not exists() the file is created.
+ *
+ * @throws CVSException if file is contained by an non-existing folder
+ * @throws CVSException if it is not possible to write the file
+ */
+ void sendTo(OutputStream outputStream, IProgressMonitor monitor, boolean binary) throws CVSException;
+
+ /**
+ * Get the fileContend from a stream and put
+ * it into this file.
+ *
+ * @throws CVSFileNotFoundException if not exists()
+ */
+ void receiveFrom(InputStream inputStream, IProgressMonitor monitor, long size, boolean binary, boolean readOnly) throws CVSException;
+
+ /**
+ * Get the timpstamp of the file as a date
+ * the format is going to be like: Thu Oct 18 20:21:13 2001
+ *
+ * @throws CVSFileNotFoundException if exists() = false
+ */
+ String getTimeStamp() throws CVSFileNotFoundException;
+
+ /**
+ * Set the timpstamp of the file as a date
+ * the format needs to be like: Thu Oct 18 20:21:13 2001
+ *
+ * if the date==null then the current time is used as
+ * timestamp
+ *
+ * @throws CVSFileNotFoundException if exists() = false
+ * @throws CVSException if the format of the date is not correct
+ */
+ void setTimeStamp(String date) throws CVSException;
+
+ /**
+ * Move the resource to another location. Does overwrite without
+ * promting.
+ *
+ * @throws CVSException if the move was not successful
+ * @throws ClassCastException if getClass != mFile.getClass
+ */
+ void moveTo(ICVSFile mFile) throws CVSException, ClassCastException;
+
+ /**
+ * Get if the file has been modified since the last time
+ * saved in the fileEntry. This is the exact but slow
+ * operation that acctually reads the dirty-state from
+ * disk.
+ *
+ * @return true if !isManaged()
+ * @throws CVSFileNotFoundException if exists() = false
+ */
+ boolean isDirty() throws CVSException;
+}
+
+
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/api/IManagedFolder.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/ICVSFolder.java index 7c29ed7db..dd6888fa8 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/api/IManagedFolder.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/ICVSFolder.java @@ -1,156 +1,134 @@ -package org.eclipse.team.internal.ccvs.core.resources.api; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.team.internal.ccvs.core.CVSException; - -/** - * The managedFile gives you an FolderProperties-Object, that - * conains CVS-specific information about a file. It takes - * care about tracking files in every folder and additional - * information about these files. - * - * One of the most important things are getFolders() and - * getFiles(). These functions give you files/folders that:<ul> - * <li> do exist locally - * <li> do exist in the entrie-file of this folder - * <li> do satisfy both of the above criteria - * </ul> - * - * You can find out wether a resource locally exists with exists() - * and you can find out whether it is in the entries with isManaged(). - * - * Folders that do not exist, can only be generated by deleting the - * folder. It is not of much use, because the FolderProperties is saved in the - * folder itself and therefore can not be saved as long as the folder - * does not exist. - * - * @see IManagedResource - */ -public interface IManagedFolder extends IManagedResource { - - /** - * Get all the folders in the current folder. - * There are three types of folders:<ul> - * <li> Does exist() but not isManaged() (local, non registered folder. Should we ignore?) - * <li> Does not exist() but isManaged() (deleted folder?) - * <li> Does exist() and isManaged() (normal registerd file) - * </ul> - * - * @throws CVSException if not exists() - */ - IManagedFolder[] getFolders() throws CVSException; - - /** - * Get all the files in the current folder - * There are three types of files:<ul> - * <li> Does exist() but not isManaged() (local, non registerd file) - * <li> Does not exist() but isManaged() (deleted file without remove or commit?) - * <li> Does exist() and isManaged() (normal registerd file) - * </ul> - * - * @throws CVSException if not exists() - */ - IManagedFile[] getFiles() throws CVSException; - - /** - * - * => is about to be renamed to getFolder() - * - * @throws CVSException if not exists() - */ - IManagedFolder getFolder(String name) throws CVSException; - - /** - * Does create a file in the given folder. Does not accept - * any subfolders given in that moment. - * - * => is about to be renamed to getFile() - * - * @throws CVSException if not exists() - */ - IManagedFile getFile(String name) throws CVSException; - - /** - * States if the resource at the given path relative to this - * folder does exist. - */ - boolean childExists(String path); - - /** - * Return the child resource at the given path relative to - * the receiver. - * - * @throws CVSException if childExists(path) = false - */ - IManagedResource getChild(String path) throws CVSException; - - /** - * Create the folder if it did not exist before. Does only - * work if the direct subfolder did exist. - * - * @throws CVSException if for some reason it was not possible to create the folder - */ - void mkdir() throws CVSException; - - /** - * Get Infos about the folder. - * - * Changing the Object has no influence on - * the infos of the file, you need to set it. - * - * @see IManagedFolder#setFolderInfo(FolderProperties) - * @return null if isManaged() == false (but not returns non-null if isManaged() == true) - * @return null if exists() == false (but not returns non-null if exists() == true) - */ - FolderProperties getFolderInfo() throws CVSException; - - /** - * Set the infos of the folder. - * - * @param if folderInfo == null, the info is removed - * @throws CVSException if (folderInfo!=null & exists()==false) - */ - void setFolderInfo(FolderProperties folderInfo) throws CVSException; - - /** - * Attache a property to the folder. - * - * @param content==null has the same effect as unsetProperty, - content==String[0] creates an empty Property - * @throws CVSFileNotFoundException if exists() = false - */ - void setProperty(String key, String[] content) throws CVSException; - - /** - * Get the property of a folder. - * - * @return the contend of the property if the property does exsist, null otherwise - * @throws CVSFileNotFoundException if exists() = false - * @throws NoCVSFolderException if isCVSFolder() = false of the underling CVSFolder - */ - String[] getProperty(String key) throws CVSException; - - /** - * Gives the ability of the folder to store properties back. - * - * (isCVSFolder() == true) <=> (getFolderInfo() != null) - */ - boolean isCVSFolder() throws CVSException; - - /** - * Visitor-Pattern.<br> - * - * Accepts the visitor on all files and all subFolder - * in the folder. - * First all the files are to be called then all the folders are - * to be called. - */ - public void acceptChildren(IManagedVisitor visitor) throws CVSException; - -} - - +package org.eclipse.team.internal.ccvs.core.resources;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.team.internal.ccvs.core.CVSException;
+
+/**
+ * The managedFile gives you an FolderProperties-Object, that
+ * conains CVS-specific information about a file. It takes
+ * care about tracking files in every folder and additional
+ * information about these files.
+ *
+ * One of the most important things are getFolders() and
+ * getFiles(). These functions give you files/folders that:<ul>
+ * <li> do exist locally
+ * <li> do exist in the entrie-file of this folder
+ * <li> do satisfy both of the above criteria
+ * </ul>
+ *
+ * You can find out wether a resource locally exists with exists()
+ * and you can find out whether it is in the entries with isManaged().
+ *
+ * Folders that do not exist, can only be generated by deleting the
+ * folder. It is not of much use, because the FolderProperties is saved in the
+ * folder itself and therefore can not be saved as long as the folder
+ * does not exist.
+ *
+ * @see ICVSResource
+ */
+public interface ICVSFolder extends ICVSResource {
+
+ /**
+ * Get all the folders in the current folder.
+ * There are three types of folders:<ul>
+ * <li> Does exist() but not isManaged() (local, non registered folder. Should we ignore?)
+ * <li> Does not exist() but isManaged() (deleted folder?)
+ * <li> Does exist() and isManaged() (normal registered file)
+ * </ul>
+ *
+ * @throws CVSException if not exists()
+ */
+ ICVSFolder[] getFolders() throws CVSException;
+
+ /**
+ * Get all the files in the current folder
+ * There are three types of files:<ul>
+ * <li> Does exist() but not isManaged() (local, non registerd file)
+ * <li> Does not exist() but isManaged() (deleted file without remove or commit?)
+ * <li> Does exist() and isManaged() (normal registerd file)
+ * </ul>
+ *
+ * @throws CVSException if not exists()
+ */
+ ICVSFile[] getFiles() throws CVSException;
+
+ /**
+ *
+ * => is about to be renamed to getFolder()
+ *
+ * @throws CVSException if not exists()
+ */
+ ICVSFolder getFolder(String name) throws CVSException;
+
+ /**
+ * Does create a file in the given folder. Does not accept
+ * any subfolders given in that moment.
+ *
+ * => is about to be renamed to getFile()
+ *
+ * @throws CVSException if not exists()
+ */
+ ICVSFile getFile(String name) throws CVSException;
+
+ /**
+ * States if the resource at the given path relative to this
+ * folder does exist.
+ */
+ boolean childExists(String path);
+
+ /**
+ * Return the child resource at the given path relative to
+ * the receiver.
+ *
+ * @throws CVSException if childExists(path) = false
+ */
+ ICVSResource getChild(String path) throws CVSException;
+
+ /**
+ * Create the folder if it did not exist before. Does only
+ * work if the direct subfolder did exist.
+ *
+ * @throws CVSException if for some reason it was not possible to create the folder
+ */
+ void mkdir() throws CVSException;
+
+ /**
+ * Get Infos about the folder.
+ *
+ * Changing the Object has no influence on
+ * the infos of the file, you need to set it.
+ *
+ * @see ICVSFolder#setFolderInfo(FolderProperties)
+ * @return null if isManaged() == false (but not returns non-null if isManaged() == true)
+ * @return null if exists() == false (but not returns non-null if exists() == true)
+ */
+ FolderSyncInfo getFolderSyncInfo() throws CVSException;
+
+ /**
+ * Set the infos of the folder.
+ *
+ * @param if folderInfo == null, the info is removed
+ * @throws CVSException if (folderInfo!=null & exists()==false)
+ */
+ void setFolderSyncInfo(FolderSyncInfo folderInfo) throws CVSException;
+
+ /**
+ * Visitor-Pattern.<br>
+ *
+ * Accepts the visitor on all files and all subFolder
+ * in the folder.
+ * First all the files are to be called then all the folders are
+ * to be called.
+ */
+ public void acceptChildren(ICVSResourceVisitor visitor) throws CVSException;
+
+ /**
+ * Answers <code>true</code> if the folder has an immediate child directory
+ * called <b>CVS</b>, and <code>false</code> otherwise.
+ */
+ public boolean isCVSFolder();
+}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/ICVSResource.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/ICVSResource.java new file mode 100644 index 000000000..dcd42190b --- /dev/null +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/ICVSResource.java @@ -0,0 +1,109 @@ +package org.eclipse.team.internal.ccvs.core.resources;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.team.internal.ccvs.core.CVSException;
+
+/**
+ * The CVS analog of file system files and directories. These are handles to
+ * state maintained by a CVS client. That is, the CVS resource does not
+ * actually contain data but rather represents CVS state and behavior. You are
+ * free to manipulate handles for CVS resources that do not exist but be aware
+ * that some methods require that an actual resource be available.
+ * <p>
+ * The CVS client has been designed work on these handles uniquely. As such, the
+ * handle could be to a remote resource or a local resource and the client could
+ * perform CVS operations ignoring the actual location of the resources.</p>
+ *
+ * @see
+ */
+public interface ICVSResource {
+
+ /**
+ * The CVS separator that is used in the client/server protocol for
+ * building paths. This is independant of the system separator
+ */
+ public static final String SEPARATOR = "/";
+
+ /**
+ * Answers the name of the resource.
+ */
+ public String getName();
+
+ /**
+ * Answer whether the resource is managed by it's parent. In general CVS terms,
+ * this means that the parent folder has an entry for the given resource in
+ * its CVS/Entries file.
+ */
+ public boolean isManaged() throws CVSException;
+
+ /**
+ * Unmanage the given resource by purging any CVS information associated with the
+ * resource. The only way a resource can become managed is by running the
+ * appropriate CVS commands (e.g. add/commit/update).
+ */
+ public void unmanage() throws CVSException;
+
+ /**
+ * Answer whether the resource is to be ignored or not.
+ */
+ public boolean isIgnored() throws CVSException;
+
+ /**
+ * Answers if the handle is a file or a folder handle.
+ */
+ boolean isFolder();
+
+ /**
+ * Answers if the resource identified by this handle exists.
+ */
+ boolean exists();
+
+ /**
+ * Gives the path from the root folder to this folder.
+ */
+ String getRelativePath(ICVSFolder ancestor) throws CVSException;
+
+ /**
+ * Get the remote location of a file either by reading it out of the
+ * file-info or by asking the parent-directory for it and appending the
+ * own name (recursivly).It stops recuring when it hits stopSearching.
+ * If you want to get the remoteLocation of the currentFolder only then
+ * use it with getRemoteLocation(this).
+ */
+ public String getRemoteLocation(ICVSFolder stopSearching) throws CVSException;
+
+ /**
+ * Answers the workspace synchronization information for this resource or
+ * <code>null</code> if the resource does not have any. This would typically
+ * include information from the <b>Entries</b> file that is used to track
+ * the base revision of a local CVS resource.
+ */
+ public ResourceSyncInfo getSyncInfo() throws CVSException;
+
+ /**
+ * Called to set the workspace synchronization information for a resource. To
+ * clear sync information call <code>unmanage</code>. The sync info will
+ * become the persisted between workbench sessions.
+ */
+ public void setSyncInfo(ResourceSyncInfo info) throws CVSException;
+
+ /**
+ * Delete the resource deep.
+ */
+ void delete();
+
+ /**
+ * Give the folder that contains this resource. If the resource is not managed
+ * then the result of the operation is not specified.
+ */
+ ICVSFolder getParent();
+
+ /**
+ * Accept a vistor to this resource.
+ */
+ public void accept(ICVSResourceVisitor visitor) throws CVSException;
+}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/ICVSResourceVisitor.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/ICVSResourceVisitor.java new file mode 100644 index 000000000..a61b0b6c4 --- /dev/null +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/ICVSResourceVisitor.java @@ -0,0 +1,19 @@ +package org.eclipse.team.internal.ccvs.core.resources;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.team.internal.ccvs.core.CVSException;
+
+/**
+ * Interface for an visitor of the IManagedResources.
+ */
+public interface ICVSResourceVisitor {
+
+ public void visitFile(ICVSFile file) throws CVSException;
+ public void visitFolder(ICVSFolder folder) throws CVSException;
+
+}
+
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/ManagedFile.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/LocalFile.java index fca2abb58..d12c889cb 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/ManagedFile.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/LocalFile.java @@ -1,408 +1,328 @@ -package org.eclipse.team.internal.ccvs.core.resources; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.text.ParseException; -import java.util.Calendar; -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.Policy; -import org.eclipse.team.internal.ccvs.core.resources.api.CVSFileNotFoundException; -import org.eclipse.team.internal.ccvs.core.resources.api.FileProperties; -import org.eclipse.team.internal.ccvs.core.resources.api.ICVSFile; -import org.eclipse.team.internal.ccvs.core.resources.api.ICVSFolder; -import org.eclipse.team.internal.ccvs.core.resources.api.ICVSResource; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFile; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFolder; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedVisitor; -import org.eclipse.team.internal.ccvs.core.util.Assert; -import org.eclipse.team.internal.ccvs.core.util.FileDateFormat; -import org.eclipse.team.internal.ccvs.core.util.Util; - -/** - * Implements the IManagedFile interface on top of an - * instance of the ICVSFile interface - * - * @see IManagedFile - */ -class ManagedFile extends ManagedResource implements IManagedFile { - - ICVSFile cvsFile; - - private static final byte[] BUFFER = new byte[4096]; - - // We could use a normal HashMap in case the caller does not have instances - // for all the time it needs the object - private static Map instancesCache = new HashMap(); - - /** - * Not to be used. Use createInternalFileFrom istead. - */ - private ManagedFile(ICVSFile cvsFile) { - super(); - this.cvsFile = cvsFile; - } - - /** - * This method is the alternative constructor for the class. It ensures, that - * for every file there exists only one instance. This is needed in order to - * make caching possible. - */ - static ManagedFile createInternalFileFrom(ICVSFile newFile) { - - ManagedFile resultFile; - - if (!CACHING) { - return new ManagedFile(newFile); - } - - resultFile = (ManagedFile) instancesCache.get(newFile.getPath()+KEY_EXTENTION); - - if (resultFile == null) { - resultFile = new ManagedFile(newFile); - instancesCache.put(newFile.getPath()+KEY_EXTENTION,resultFile); - } - - return resultFile; - } - - /** - * @see IManagedFile#getSize() - */ - public long getSize() { - return cvsFile.getSize(); - } - - /** - * @see IManagedFile#getFileInfo() - */ - public FileProperties getFileInfo() throws CVSException { - - return getInternalParent().getFileInfo(this); - - } - - /** - * @see IManagedFile#setFileInfo(FileProperties) - */ - public void setFileInfo(FileProperties fileInfo) throws CVSException { - - if (!(fileInfo == null || fileInfo.getName().equals(cvsFile.getName()))) { - throw new CVSException("Try to set fileInfo where fileInfo.getName() != file.getName()"); - } - - getInternalParent().setFileInfo(this,fileInfo); - - clearDirty(true); - clearManaged(); - } - - /** - * @see IManagedFile#reciveFrom(OutputStream, IProgressMonitor) - */ - public void receiveFrom(InputStream in, - IProgressMonitor monitor, - long size, - boolean binary, - boolean readOnly) - - throws CVSException { - - OutputStream out; - String title; - - title = Policy.bind("ManagedFile.receiving", - new Object[] {cvsFile.getName()}); - - try { - - out = cvsFile.getOutputStream(); - - if (binary) { - // System.out.println("BinaryReciving: " + getName() + "(" + size + ")"); - transferWithProgress(in,out,size,monitor,title); - } else { - // System.out.println("TextReciving: " + getName() + "(" + size + ")"); - transferText(in,out,size,monitor,title,false); - } - - out.close(); - - if (readOnly) { - cvsFile.setReadOnly(); - } - - } catch (IOException e) { - throw wrapException(e); - } - - clearDirty(true); - } - - /** - * @see IManagedFile#sendTo(InputStream, IProgressMonitor, long) - */ - public void sendTo( - OutputStream out, - IProgressMonitor monitor, - boolean binary) - throws CVSException { - - InputStream in; - String title; - long size = getSize(); - title = Policy.bind("ManagedFile.sending", - new Object[]{cvsFile.getName()}); - - try { - in = cvsFile.getInputStream(); - - if (binary) { - - // Send the size to the server - out.write(("" + cvsFile.getSize()).getBytes()); - out.write(SERVER_NEWLINE.getBytes()); - transferWithProgress(in,out,size,monitor,title); - - // System.out.println("BinarySending: " + getName() + "(" + size + ")"); - - } else { - - // In this case the size has to be computed. - // Therefore we do send the size in transferText - transferText(in,out,cvsFile.getSize(),monitor,title,true); - - // System.out.println("TextSending: " + getName() + "(" + size + ")"); - } - - in.close(); - - } catch (IOException e) { - throw wrapException(e); - } - } - /** - * @see IManagedFile#getTimeStamp() - */ - public String getTimeStamp() throws CVSFileNotFoundException { - - exceptionIfNotExists(); - - FileDateFormat df = new FileDateFormat(); - - return df.formatMill(cvsFile.getTimeStamp()); - } - - /** - * @see IManagedFile#setTimeStamp(long) - */ - public void setTimeStamp(String date) throws CVSException { - - long millSec; - Calendar calendar; - FileDateFormat df = new FileDateFormat(); - - exceptionIfNotExists(); - - if (date==null) { - // get the current time - calendar = Calendar.getInstance(); - millSec = calendar.getTime().getTime(); - } else { - try { - millSec = df.parseMill(date); - } catch (ParseException e) { - throw new CVSException(0,0,"Format of the Date for a TimeStamp not parseable",e); - } - } - - cvsFile.setTimeStamp(millSec); - - clearDirty(true); - } - - /** - * @see IManagedResource#isFolder() - */ - public boolean isFolder() { - return false; - } - - /** - * @see IManagedResource#isManaged() - */ - public boolean isManaged() throws CVSException { - return (getInternalParent().getFileInfo(this) != null); - } - - /** - * Send/Recive a textFile from/to the server. It does the conversion - * of the newlines and sends the filesize to the server (only on a - * send) - */ - protected static void transferText(InputStream in, - OutputStream out, - long size, - IProgressMonitor monitor, - String title, - boolean toServer) - throws IOException { - - // If we get a file bigger than 2 GigaByte, this does not - // work - Assert.isTrue(size < Integer.MAX_VALUE); - - if (size > 25000) { - - monitor.setTaskName( - Policy.bind( - "ManagedFile.transfer", - new Object[]{title,new Long(0),new Long(size/1024)} - ) - ); - - } - - byte[] buffer = new byte[(int)size]; - - // Get the content from the file - int num = in.read(buffer); - int pos = num; - while ((num != -1) && (size - pos > 0)) { - Policy.checkCanceled(monitor); - num = in.read(buffer, pos, ((int)size) - pos); - pos += num; - } - - // care about newlines - if (toServer) { - buffer = Util.replace(buffer,PLATFORM_NEWBYTE,SERVER_NEWBYTE); - // Send the size to the server - out.write(("" + buffer.length).getBytes()); - out.write(SERVER_NEWLINE.getBytes()); - - } else { - buffer = Util.replace(buffer,PLATFORM_NEWBYTE,SERVER_NEWBYTE); - buffer = Util.replace(buffer,SERVER_NEWBYTE,PLATFORM_NEWBYTE); - } - - out.write(buffer); - } - - /** - * Transfer an InputStream to an OutputStream - * and update the monitor in between. - * - * Used for saving files from server - * on disc, etc. - */ - protected static void transferWithProgress( - InputStream in, - OutputStream out, - long size, - IProgressMonitor monitor, - String title) - throws IOException { - - // This special transfer utility will show progress to - // the monitor for files that are bigger than 25K - boolean progress = size > 25000; - int read = 0; - long totalRead = 0; - long ksize = size / 1024; - // buffer size is smaller than MAXINT... - int toRead = (int) Math.min(BUFFER.length, size); - synchronized (BUFFER) { - while ((totalRead < size) && (read = in.read(BUFFER, 0, toRead)) != -1) { - if (progress && totalRead > 0) { - monitor.subTask( - Policy.bind( - "ManagedFile.transfer", - new Object[] { title, new Long(totalRead / 1024), new Long(ksize)})); - monitor.worked(read); - } - totalRead += read; - out.write(BUFFER, 0, read); - toRead = (int) Math.min(BUFFER.length, size - totalRead); - } - } - } - - /** - * @see ManagedResource#getResource() - */ - public ICVSResource getCVSResource() { - return cvsFile; - } - - - /** - * @see IManagedResource#showDirty() - */ - public boolean showDirty() throws CVSException { - - if (!CACHING || showDirtyCache == null) { - showDirtyCache = new Boolean(isDirty()); - } - return showDirtyCache.booleanValue(); - } - - /** - * @see IManagedFile#isDirty() - */ - public boolean isDirty() throws CVSException { - if (!exists() || !isManaged()) { - return true; - } else { - return !getTimeStamp().equals(getFileInfo().getTimeStamp()); - } - } - - /** - * @see IManagedResource#accept(IManagedVisitor) - */ - public void accept(IManagedVisitor visitor) throws CVSException { - visitor.visitFile(this); - } - - /** - * @see IManagedFile#moveTo(IManagedFile) - */ - public void moveTo(IManagedFile mFile) throws CVSException, ClassCastException { - cvsFile.moveTo(((ManagedFile)mFile).cvsFile); - - clearDirty(true); - } - - /** - * @see IManagedFile#getContent() - */ - public String[] getContent() throws CVSException { - return cvsFile.getContent(); - } - - /** - * @see IManagedResource#getRemoteLocation() - */ - public String getRemoteLocation(IManagedFolder stopSearching) throws CVSException { - return getParent().getRemoteLocation(stopSearching) + separator + getName(); - } - - /** - * @see IManagedResource#unmanage() - */ - public void unmanage() throws CVSException { - setFileInfo(null); - } - -} - +package org.eclipse.team.internal.ccvs.core.resources;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+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.Calendar;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.Policy;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFile;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFolder;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSResourceVisitor;
+import org.eclipse.team.internal.ccvs.core.util.Assert;
+import org.eclipse.team.internal.ccvs.core.util.FileDateFormat;
+import org.eclipse.team.internal.ccvs.core.util.FileUtil;
+import org.eclipse.team.internal.ccvs.core.util.Util;
+
+/**
+ * Implements the IManagedFile interface on top of an
+ * instance of the ICVSFile interface
+ *
+ * @see IManagedFile
+ */
+public class LocalFile extends LocalResource implements ICVSFile {
+
+ /**
+ *
+ */
+ public LocalFile(File file) {
+ super(file);
+ }
+
+ /**
+ * @see IManagedFile#getSize()
+ */
+ public long getSize() {
+ return ioResource.length();
+ }
+
+ /**
+ * @see IManagedFile#reciveFrom(OutputStream, IProgressMonitor)
+ */
+ public void receiveFrom(InputStream in,
+ IProgressMonitor monitor,
+ long size,
+ boolean binary,
+ boolean readOnly)
+
+ throws CVSException {
+
+ OutputStream out;
+ String title;
+
+ title = Policy.bind("LocalFile.receiving",
+ new Object[] {ioResource.getName()});
+
+ try {
+
+ out = new FileOutputStream(ioResource);
+
+ if (binary) {
+ // System.out.println("BinaryReciving: " + getName() + "(" + size + ")");
+ transferWithProgress(in,out,size,monitor,title);
+ } else {
+ // System.out.println("TextReciving: " + getName() + "(" + size + ")");
+ transferText(in,out,size,monitor,title,false);
+ }
+
+ out.close();
+
+ if (readOnly) {
+ ioResource.setReadOnly();
+ }
+
+ } catch (IOException e) {
+ throw CVSException.wrapException(e);
+ }
+ }
+
+ /**
+ * @see IManagedFile#sendTo(InputStream, IProgressMonitor, long)
+ */
+ public void sendTo(
+ OutputStream out,
+ IProgressMonitor monitor,
+ boolean binary)
+ throws CVSException {
+
+ InputStream in;
+ String title;
+ long size = getSize();
+ title = Policy.bind("LocalFile.sending",
+ new Object[]{ioResource.getName()});
+
+ try {
+ in = new FileInputStream(ioResource);
+
+ if (binary) {
+
+ // Send the size to the server
+ out.write(("" + getSize()).getBytes());
+ out.write(SERVER_NEWLINE.getBytes());
+ transferWithProgress(in,out,size,monitor,title);
+
+ // System.out.println("BinarySending: " + getName() + "(" + size + ")");
+
+ } else {
+
+ // In this case the size has to be computed.
+ // Therefore we do send the size in transferText
+ transferText(in,out,getSize(),monitor,title,true);
+
+ // System.out.println("TextSending: " + getName() + "(" + size + ")");
+ }
+
+ in.close();
+
+ } catch (IOException e) {
+ throw CVSException.wrapException(e);
+ }
+ }
+ /**
+ * @see IManagedFile#getTimeStamp()
+ */
+ public String getTimeStamp() throws CVSFileNotFoundException {
+
+ FileDateFormat df = new FileDateFormat();
+
+ return df.formatMill(ioResource.lastModified());
+ }
+
+ /**
+ * @see IManagedFile#setTimeStamp(long)
+ */
+ public void setTimeStamp(String date) throws CVSException {
+
+ long millSec;
+ Calendar calendar;
+ FileDateFormat df = new FileDateFormat();
+
+ if (date==null) {
+ // get the current time
+ calendar = Calendar.getInstance();
+ millSec = calendar.getTime().getTime();
+ } else {
+ try {
+ millSec = df.parseMill(date);
+ } catch (ParseException e) {
+ throw new CVSException(0,0,"Format of the Date for a TimeStamp not parseable",e);
+ }
+ }
+
+ ioResource.setLastModified(millSec);
+ }
+
+ /**
+ * @see ICVSResource#isFolder()
+ */
+ public boolean isFolder() {
+ return false;
+ }
+
+ /**
+ * Send/Recive a textFile from/to the server. It does the conversion
+ * of the newlines and sends the filesize to the server (only on a
+ * send)
+ */
+ protected static void transferText(InputStream in,
+ OutputStream out,
+ long size,
+ IProgressMonitor monitor,
+ String title,
+ boolean toServer)
+ throws IOException {
+
+ // If we get a file bigger than 2 GigaByte, this does not
+ // work
+ Assert.isTrue(size < Integer.MAX_VALUE);
+
+ if (size > 25000) {
+
+ monitor.setTaskName(
+ Policy.bind(
+ "LocalFile.transfer",
+ new Object[]{title,new Long(0),new Long(size/1024)}
+ )
+ );
+
+ }
+
+ byte[] buffer = new byte[(int)size];
+
+ // Get the content from the file
+ int num = in.read(buffer);
+ int pos = num;
+ while ((num != -1) && (size - pos > 0)) {
+ Policy.checkCanceled(monitor);
+ num = in.read(buffer, pos, ((int)size) - pos);
+ pos += num;
+ }
+
+ // care about newlines
+ if (toServer) {
+ buffer = Util.replace(buffer,PLATFORM_NEWBYTE,SERVER_NEWBYTE);
+ // Send the size to the server
+ out.write(("" + buffer.length).getBytes());
+ out.write(SERVER_NEWLINE.getBytes());
+
+ } else {
+ buffer = Util.replace(buffer,PLATFORM_NEWBYTE,SERVER_NEWBYTE);
+ buffer = Util.replace(buffer,SERVER_NEWBYTE,PLATFORM_NEWBYTE);
+ }
+
+ out.write(buffer);
+ }
+
+ /**
+ * Transfer an InputStream to an OutputStream
+ * and update the monitor in between.
+ *
+ * Used for saving files from server
+ * on disc, etc.
+ */
+ protected static void transferWithProgress(
+ InputStream in,
+ OutputStream out,
+ long size,
+ IProgressMonitor monitor,
+ String title)
+ throws IOException {
+
+ byte[] BUFFER = new byte[4096];
+
+ // This special transfer utility will show progress to
+ // the monitor for files that are bigger than 25K
+ boolean progress = size > 25000;
+ int read = 0;
+ long totalRead = 0;
+ long ksize = size / 1024;
+ // buffer size is smaller than MAXINT...
+ int toRead = (int) Math.min(BUFFER.length, size);
+ synchronized (BUFFER) {
+ while ((totalRead < size) && (read = in.read(BUFFER, 0, toRead)) != -1) {
+ if (progress && totalRead > 0) {
+ monitor.subTask(
+ Policy.bind(
+ "LocalFile.transfer",
+ new Object[] { title, new Long(totalRead / 1024), new Long(ksize)}));
+ monitor.worked(read);
+ }
+ totalRead += read;
+ out.write(BUFFER, 0, read);
+ toRead = (int) Math.min(BUFFER.length, size - totalRead);
+ }
+ }
+ }
+
+ /**
+ * @see IManagedFile#isDirty()
+ */
+ public boolean isDirty() 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);
+ }
+
+ /**
+ * @see IManagedFile#moveTo(IManagedFile)
+ */
+ public void moveTo(ICVSFile mFile) throws CVSException {
+
+ LocalFile file;
+ try {
+ file = (LocalFile)mFile;
+ } catch(ClassCastException e) {
+ throw CVSException.wrapException(e);
+ }
+
+ boolean success;
+
+ success = ioResource.renameTo(file.getFile());
+
+ if (!success) {
+ throw new CVSException("Move from " + ioResource + " to " + file + " was not possible");
+ }
+ }
+
+ public File getFile() {
+ return ioResource;
+ }
+
+ /**
+ * @see IManagedFile#getContent()
+ */
+ public String[] getContent() throws CVSException {
+ return FileUtil.readLines(ioResource);
+ }
+
+ /**
+ * @see ICVSResource#getRemoteLocation()
+ */
+ public String getRemoteLocation(ICVSFolder stopSearching) throws CVSException {
+ return getParent().getRemoteLocation(stopSearching) + SEPARATOR + getName();
+ }
+}
+
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/LocalFolder.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/LocalFolder.java new file mode 100644 index 000000000..2cfab6934 --- /dev/null +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/LocalFolder.java @@ -0,0 +1,228 @@ +package org.eclipse.team.internal.ccvs.core.resources;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.io.File;
+import java.io.FileFilter;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.Policy;
+import org.eclipse.team.internal.ccvs.core.commands.FileNameMatcher;
+import org.eclipse.team.internal.ccvs.core.util.SyncFileUtil;
+
+/**
+ * Implements the ICVSFolder interface on top of an
+ * instance of the ICVSFolder interface
+ *
+ * @see ICVSFolder
+ */
+public class LocalFolder extends LocalResource implements ICVSFolder {
+
+ public LocalFolder(File ioResource) {
+ super(ioResource);
+ }
+
+ /**
+ *
+ * @see ICVSFolder#getFolders()
+ */
+ public ICVSFolder[] getFolders() throws CVSException {
+
+ final Set folders = new HashSet();
+ final FileNameMatcher matcher = FileNameMatcher.getIgnoreMatcherFor(ioResource);
+
+ ResourceSyncInfo[] syncDirs = Synchronizer.getInstance().members(ioResource);
+ for (int i = 0; i < syncDirs.length; i++) {
+ if(syncDirs[i].isDirectory()) {
+ folders.add((new LocalFolder(new File(ioResource, syncDirs[i].getName()))));
+ }
+ }
+
+ File[] realDirs = ioResource.listFiles(new FileFilter() {
+ public boolean accept(File file) {
+ if(file.isDirectory() && !matcher.match(file.getName())) {
+ folders.add(new LocalFolder(file));
+ }
+ return false;
+ }
+ });
+
+ return (ICVSFolder[]) folders.toArray(new ICVSFolder[folders.size()]);
+ }
+
+ /**
+ * @see ICVSFolder#getFiles()
+ */
+ public ICVSFile[] getFiles() throws CVSException {
+
+ final Set files = new HashSet();
+ final FileNameMatcher matcher = FileNameMatcher.getIgnoreMatcherFor(ioResource);
+
+ ResourceSyncInfo[] syncDirs = Synchronizer.getInstance().members(ioResource);
+ for (int i = 0; i < syncDirs.length; i++) {
+ if(!syncDirs[i].isDirectory()) {
+ files.add((new LocalFile(new File(ioResource, syncDirs[i].getName()))));
+ }
+ }
+
+ File[] realDirs = ioResource.listFiles(new FileFilter() {
+ public boolean accept(File file) {
+ if(!file.isDirectory() && !matcher.match(file.getName())) {
+ files.add(new LocalFile(file));
+ }
+ return false;
+ }
+ });
+
+ return (ICVSFile[]) files.toArray(new ICVSFile[files.size()]);
+ }
+
+ /**
+ * @see ICVSFolder#createFolder(String)
+ */
+ public ICVSFolder getFolder(String name) throws CVSException {
+ if ((".".equals(name)) || (("." + SEPARATOR).equals(name)))
+ return this;
+ return new LocalFolder(new File(ioResource, name));
+ }
+
+ /**
+ * @see ICVSFolder#createFile(String)
+ */
+ public ICVSFile getFile(String name) throws CVSException {
+ return new LocalFile(new File(ioResource, name));
+ }
+
+ /**
+ * @see ICVSFolder#getChild(String)
+ */
+ public ICVSResource getChild(String name) throws CVSException {
+
+ boolean isDirectory;
+
+ File child = new File(ioResource, name);
+ if(child.exists()) {
+ isDirectory = child.isDirectory();
+ } else {
+ ResourceSyncInfo info = Synchronizer.getInstance().getSyncInfo(child);
+ if (info == null)
+ throw new CVSFileNotFoundException(Policy.bind("LocalFolder.invalidChild", child.getAbsolutePath()));
+ isDirectory = info.isDirectory();
+ }
+
+ if(isDirectory) {
+ return getFolder(name);
+ } else {
+ return getFile(name);
+ }
+ }
+ /**
+ * @see ICVSFolder#mkdir()
+ */
+ public void mkdir() throws CVSException {
+ ioResource.mkdir();
+ }
+
+ /**
+ * @see ICVSResource#isFolder()
+ */
+ public boolean isFolder() {
+ return true;
+ }
+
+// /**
+// * Remove the fileInfo for a specific file. If it was not there
+// * before nothing happens.
+// *
+// * @param file has to satisfy file.getParent().equals(this)
+// */
+// void removeFileInfo(IManagedFile file) throws CVSException {
+//
+// Assert.isTrue(file.getParent().equals(this));
+//
+// fileInfoContainer.removeFileInfo(file.getName());
+// }
+
+ /**
+ * @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#childExists(String)
+ */
+ public boolean childExists(String path) {
+ return false;
+ }
+
+ /*
+ * @see ICVSFolder#getFolderInfo()
+ */
+ public FolderSyncInfo getFolderSyncInfo() throws CVSException {
+ return Synchronizer.getInstance().getFolderSyncInfo(ioResource);
+ }
+
+ /*
+ * @see ICVSFolder#setFolderInfo(FolderSyncInfo)
+ */
+ public void setFolderSyncInfo(FolderSyncInfo folderInfo) throws CVSException {
+ Synchronizer.getInstance().setFolderSyncInfo(ioResource, folderInfo);
+ }
+ /*
+ * @see ICVSFolder#isCVSFolder()
+ */
+ public boolean isCVSFolder() {
+ return SyncFileUtil.getCVSSubdirectory(ioResource).exists();
+ }
+}
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/LocalResource.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/LocalResource.java new file mode 100644 index 000000000..593db8f85 --- /dev/null +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/LocalResource.java @@ -0,0 +1,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);
+ }
+}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/ManagedFolder.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/ManagedFolder.java deleted file mode 100644 index 3ef2e4ed1..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/ManagedFolder.java +++ /dev/null @@ -1,713 +0,0 @@ -package org.eclipse.team.internal.ccvs.core.resources; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.commands.FileNameMatcher; -import org.eclipse.team.internal.ccvs.core.resources.api.CVSFileNotFoundException; -import org.eclipse.team.internal.ccvs.core.resources.api.FileProperties; -import org.eclipse.team.internal.ccvs.core.resources.api.FolderProperties; -import org.eclipse.team.internal.ccvs.core.resources.api.ICVSFile; -import org.eclipse.team.internal.ccvs.core.resources.api.ICVSFolder; -import org.eclipse.team.internal.ccvs.core.resources.api.ICVSResource; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFile; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFolder; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedResource; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedVisitor; -import org.eclipse.team.internal.ccvs.core.util.Assert; - -/** - * Implements the IManagedFolder interface on top of an - * instance of the ICVSFolder interface - * - * @see IManagedFolder - */ -class ManagedFolder extends ManagedResource implements IManagedFolder { - - private ICVSFolder cvsFolder; - private FilePropertiesContainer fileInfoContainer; - - // We could use a normal HashMap in case the caller does not have instances - // for all the time it needs the object - private static Map instancesCache = new HashMap(); - - /** - * This constructor should never be used. Use createInternalFolderFrom - * instead. - */ - private ManagedFolder(ICVSFolder cvsFolder) { - super(); - this.cvsFolder = cvsFolder; - fileInfoContainer = new FilePropertiesContainer(cvsFolder,AUTO_SAVE); - } - - /** - * This method is the alternative constructor for the class. It ensures, that - * for every file there exists only one instance. This is needed in order to - * make caching possible. - */ - static ManagedFolder createInternalFolderFrom(ICVSFolder newFolder) { - - ManagedFolder resultFolder; - - if (!CACHING) { - return new ManagedFolder(newFolder); - } - - resultFolder = (ManagedFolder) instancesCache.get(newFolder.getPath()+KEY_EXTENTION); - - if (resultFolder == null) { - resultFolder = new ManagedFolder(newFolder); - instancesCache.put(newFolder.getPath()+KEY_EXTENTION,resultFolder); - } - - return resultFolder; - } - - /** - * @see IManagedFolder#getFolders() - */ - public IManagedFolder[] getFolders() throws CVSException { - - ICVSFolder[] entrieFolders; - ICVSFolder[] underlyingFolders; - ICVSFolder[] allFolders; - IManagedFolder[] resultFolders; - - exceptionIfNotExists(); - - entrieFolders = fileInfoContainer.getEntriesFolderList(); - underlyingFolders = cvsFolder.getFolders(); - - // merge the list of the folders - allFolders = (ICVSFolder[]) merge(entrieFolders, - underlyingFolders, - new ICVSFolder[0]); - - // NIK: we could add a folder, that we are going to ignore - // afterwards, it would stay forever in the entries - // as to be added ?!? - allFolders = (ICVSFolder[])removeIgnored(allFolders, new ICVSFolder[0]); - - // wrap the cvsFolders to managedFolders - resultFolders = new IManagedFolder[allFolders.length]; - for (int i=0; i<allFolders.length; i++) { - resultFolders[i] = createResourceFrom(allFolders[i]); - } - - return resultFolders; - } - - /** - * Takes two Array and returns the contend of the two arrays - * minus all dublication entries. - * A dublication is a entrie x that has an entry y allready in the - * result with x.equals(y). - * - * e.g.: tmp = (String[])merge(new String[]{"a","b","c"}, - * new String[]{"b","c","d"}, - * new String[0]); - * - * result: tmp.equals(new String[]{"a","b","c","d"}) - */ - private Object[] merge(Object[] array1, Object[] array2, Object[] resultArray) { - - Set mergeSet = new HashSet(); - - for (int i=0; i<array1.length; i++) { - mergeSet.add(array1[i]); - } - - for (int i=0; i<array2.length; i++) { - mergeSet.add(array2[i]); - } - - return mergeSet.toArray(resultArray); - } - - /** - * @see IManagedFolder#getFiles() - */ - public IManagedFile[] getFiles() throws CVSException { - - ICVSFile[] entrieFiles; - ICVSFile[] underlyingFiles; - ICVSFile[] allFiles; - IManagedFile[] resultFiles; - - exceptionIfNotExists(); - - entrieFiles = fileInfoContainer.getEntriesFileList(); - underlyingFiles = cvsFolder.getFiles(); - - // merge the list of the Files - allFiles = (ICVSFile[]) merge(entrieFiles, - underlyingFiles, - new ICVSFile[0]); - allFiles = (ICVSFile[])removeIgnored(allFiles, new ICVSFile[0]); - - - // wrap the cvsFiles to managedFiles - resultFiles = new IManagedFile[allFiles.length]; - for (int i=0; i<allFiles.length; i++) { - resultFiles[i] = createResourceFrom(allFiles[i]); - } - - return resultFiles; - } - - /** - * @see IManagedFolder#createFolder(String) - */ - public IManagedFolder getFolder(String name) throws CVSException { - return createResourceFrom(cvsFolder.createFolder(name)); - } - - /** - * @see IManagedFolder#createFile(String) - */ - public IManagedFile getFile(String name) throws CVSException { - return createResourceFrom(cvsFolder.createFile(name)); - } - - /** - * @see IManagedFolder#childExists(String) - */ - public boolean childExists(String path) { - return cvsFolder.childExists(path); - } - - /** - * @see IManagedFolder#getChild(String) - */ - public IManagedResource getChild(String name) throws CVSException { - - IManagedResource mResource; - - mResource = getRealChild(name); - - if (mResource == null) { - mResource = getVirtualChild(name); - } - - if (mResource == null) { - throw new CVSFileNotFoundException("used getChild(" + name + ") on a not existing file"); - } - - return mResource; - - } - - /** - * Tries to find the child "path" in the file-system. If the child is not - * there, then it returns null - */ - private IManagedResource getRealChild(String name) throws CVSException { - - ICVSResource cvsResource; - - if (!cvsFolder.childExists(name)) { - return null; - } - - cvsResource = cvsFolder.getChild(name); - - if (cvsResource.isFolder()) { - return createResourceFrom((ICVSFolder)cvsResource); - } else { - return createResourceFrom((ICVSFile)cvsResource); - } - } - - /** - * Tries to find the child "path" in the entries. If it is not there the - * method returns null - */ - private IManagedResource getVirtualChild(String name) throws CVSException { - - IManagedFolder virtualParent; - - IManagedFolder[] folders; - IManagedFile[] files; - - // get the direct parent of the child that we want to - // find if it does not exist then the virtual child - // can not exist - // We "cheat" and say, that the virtualChild is going to - // be a file. But as we use it for string-manipulation - // only this is allright - virtualParent = getFile(name).getParent(); - name = getFile(name).getName(); - - if (!virtualParent.exists()) { - return null; - } - - folders = virtualParent.getFolders(); - - for (int i=0; i<folders.length; i++) { - if (folders[i].getName().equals(name)) { - return folders[i]; - } - } - - files = virtualParent.getFiles(); - - for (int i=0; i<files.length; i++) { - if (files[i].getName().equals(name)) { - return files[i]; - } - } - - return null; - } - - - /** - * @see IManagedFolder#mkdir() - */ - public void mkdir() throws CVSException { - cvsFolder.mkdir(); - } - - /** - * @see IManagedFolder#getFolderInfo() - */ - public FolderProperties getFolderInfo() throws CVSException { - - FolderProperties folderProperties = new FolderProperties(); - String key; - String[] data; - - if (!exists() || !cvsFolder.isCVSFolder()) { - return null; - } - - for (Iterator i = folderProperties.keySet().iterator(); i.hasNext();) { - key = (String) i.next(); - data = cvsFolder.getProperty(key); - - if (data == null) { - // throw new CVSException("The FolderInformation in the folder " + cvsFolder + " is partrtial"); - continue; - } else if (data.length == 0) { - folderProperties.putProperty(key,""); - } else { - folderProperties.putProperty(key,data[0]); - } - } - - return folderProperties; - } - - /** - * @see IManagedFolder#setFolderInfo(FolderProperties) - */ - public void setFolderInfo(FolderProperties folderProperties) throws CVSException { - - String key; - - if (folderProperties == null) { - removeFolderInfo(); - return; - } - - exceptionIfNotExists(); - cvsFolder.makeCVSFolder(); - - for (Iterator i = folderProperties.keySet().iterator(); i.hasNext();) { - key = (String) i.next(); - if (folderProperties.getProperty(key) == null) { - cvsFolder.setProperty(key,null); - } else { - cvsFolder.setProperty(key, - new String[]{folderProperties.getProperty(key)}); - } - } - - getInternalParent().addFolderEntrie(this); - clearManaged(); - } - - /** - * Remove the FileProperties and therefore all the knowlege of the entrie-systen - * about this folder. - * The properties are deleted and the entries of the parent-folder - * are updated. - */ - private void removeFolderInfo() throws CVSException { - - IManagedFile[] subFiles; - - if (exists() && cvsFolder.isCVSFolder()) { - cvsFolder.unmakeCVSFolder(); - } - - getInternalParent().removeFolderEntrie(this); - - // Remove chached information about this folder - clearDirty(true); - clearManaged(); - - // Remove all the cached information from the children - // because effectivly we are removing all the entries - // of the children. - - // If the folder does not exist, then the sub-files do - // not exist any more neither. Therefore a delete on them - // was called and we do not need to do anything any more - if (!exists()) { - return; - } - - subFiles =getFiles(); - - for (int i = 0; i < subFiles.length; i++) { - subFiles[i].clearDirty(false); - subFiles[i].clearManaged(); - } - } - - /** - * @see IManagedFolder#setProperty(String, String[]) - */ - public void setProperty(String key, String[] content) throws CVSException { - - // We want to create a cvs-folder on the first time - // setting a property - cvsFolder.makeCVSFolder(); - - cvsFolder.setProperty(key,content); - - } - - /** - * @see IManagedFolder#unsetProperty(String) - */ - public void unsetProperty(String key) throws CVSException { - - // Otherwise we do not want to do anything - if (cvsFolder.isCVSFolder()) { - cvsFolder.setProperty(key,null); - } - } - - /** - * @see IManagedFolder#getProperty(String) - */ - public String[] getProperty(String key) throws CVSException { - return cvsFolder.getProperty(key); - } - - /** - * @see IManagedResource#isFolder() - */ - public boolean isFolder() { - return true; - } - - protected boolean isIgnored(String child) throws CVSException { - // NOTE: This is the wrong place for this - if (child.equals("CVS")) - return true; - FileNameMatcher matcher = null; - try { - matcher = FileNameMatcher.getIgnoreMatcherFor(cvsFolder); - } catch (IOException e) { - // Log the exception and return files unchanged - throw wrapException(e); - } - if (matcher == null) - return false; - return matcher.match(child); - } - - /** - * Set the entry and the rest of the fileInfo for the file. - */ - void setFileInfo(IManagedFile file, FileProperties fileInfo) throws CVSException { - - Assert.isTrue(file.getParent().equals(this)); - Assert.isTrue(fileInfo == null || file.getName().equals(fileInfo.getName())); - - exceptionIfNotExists(); - cvsFolder.makeCVSFolder(); - - fileInfoContainer.setFileInfo(file.getName(),fileInfo); - } - - /** - * Get the fileInfo for a specific file. - * - * @param file has to satisfy file.getParent().equals(this) - * @return null if isManaged() = false - */ - FileProperties getFileInfo(IManagedFile file) throws CVSException { - - Assert.isTrue(file.getParent().equals(this)); - - return fileInfoContainer.getFileInfo(file.getName()); - } - -// /** -// * Remove the fileInfo for a specific file. If it was not there -// * before nothing happens. -// * -// * @param file has to satisfy file.getParent().equals(this) -// */ -// void removeFileInfo(IManagedFile file) throws CVSException { -// -// Assert.isTrue(file.getParent().equals(this)); -// -// fileInfoContainer.removeFileInfo(file.getName()); -// } - - /** - * Add an folder to the entries of this folder. If the folder - * was in the list allready, it just stays there. - * - * @param folder must satisfy: folder.getParent().equals(this) - * @throws CVSException if AUTO_SAVE & !folder.exists() - */ - void addFolderEntrie(IManagedFolder folder) throws CVSException { - - Assert.isTrue(folder.getParent().equals(this)); - - // This could be the project-folder wich is not a CVSFolder - // and we do not need to updated the entries - if (cvsFolder.isCVSFolder()) { - fileInfoContainer.addFolder(folder.getName()); - } - } - - /** - * Remove an folder from the entrie of this folder. If the folder - * has not been there before it is not in it after the operation. - * - * @param folder must satisfy: folder.getParent().equals(this) - * @throws CVSException if AUTO_SAVE & !folder.exists() - */ - void removeFolderEntrie(IManagedFolder folder) throws CVSException { - - Assert.isTrue(folder.getParent().equals(this)); - - // This could be the project-folder wich is not a CVSFolder - // and we do not need to updated the entries - if (cvsFolder.isCVSFolder()) { - fileInfoContainer.removeFolder(folder.getName()); - } - } - - /** - * Is the folder in the entries - * - * @return false if !folder.getParent().equals(this) - * @throws CVSException if AUTO_SAVE & !folder.exists() - */ - boolean containsFolderEntrie(IManagedFolder folder) throws CVSException { - - if (!folder.getParent().equals(this) || !cvsFolder.isCVSFolder()) { - return false; - } else { - return fileInfoContainer.containsFolder(folder.getName()); - } - } - - /** - * @see IManagedResource#isManaged() - */ - public boolean isManaged() throws CVSException { - - // To be implemented after ManagedFolder - // we need a method, that tells us wether a folder - // or a file is in the entries-property. - - return getInternalParent().containsFolderEntrie(this); - } - - /** - * @see ManagedResource#getResource() - */ - public ICVSResource getCVSResource() { - return cvsFolder; - } - - /** - * @see IManagedFolder#isCVSFolder() - */ - public boolean isCVSFolder() throws CVSException { - return exists() && cvsFolder.isCVSFolder(); - } - - - /** - * @see IManagedFolder#acceptChildren(IManagedVisitor) - */ - public void acceptChildren(IManagedVisitor visitor) throws CVSException { - - IManagedResource[] subFiles; - IManagedResource[] 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 IManagedResource#accept(IManagedVisitor) - */ - public void accept(IManagedVisitor visitor) throws CVSException { - visitor.visitFolder(this); - } - - /** - * @see IManagedResource#getRemoteLocation(IManagedFolder) - */ - public String getRemoteLocation(IManagedFolder stopSearching) throws CVSException { - - String parentLocation; - - if (getFolderInfo() != null) { - return getFolderInfo().getRemoteLocation(); - } - - if (equals(stopSearching)) { - return null; - } - - parentLocation = getParent().getRemoteLocation(stopSearching); - if (parentLocation == null) { - return null; - } else { - return parentLocation + separator + getName(); - } - - } - - /** - * @see IManagedResource#unmanage() - * @deprecated uses unmakeCVSFolder intstead of setFolderInfo(null) - */ - public void unmanage() throws CVSException { - accept(new IManagedVisitor() { - public void visitFile(IManagedFile file) throws CVSException {} - public void visitFolder(IManagedFolder folder) throws CVSException { - folder.acceptChildren(this); - folder.setFolderInfo(null); - } - }); - } - - /** - * Remove the ignored resources from the provided list of resources. - * The type variable is used to determine the type of the elements in - * the resulting array. - */ - private ICVSResource[] removeIgnored(ICVSResource[] resources, ICVSResource[] type) throws CVSException { - FileNameMatcher matcher = null; - try { - matcher = FileNameMatcher.getIgnoreMatcherFor(cvsFolder); - } catch (IOException e) { - // Log the exception and return files unchanged - throw wrapException(e); - } - if (matcher == null) - return resources; - List result = new ArrayList(resources.length); - for (int i=0;i<resources.length;i++) { - if (!matcher.match(resources[i].getName())) - result.add(resources[i]); - } - if (result.size() == resources.length) - return resources; - return (ICVSResource[])result.toArray(type); - } - - /** - * @see IManagedFolder#clearCache(boolean) - */ - public void clearCache(boolean deep) throws CVSException { - -// for (Iterator iter = instancesCache.keySet().iterator(); iter.hasNext();) { -// String element = (String) iter.next(); -// System.out.println(element); -// } -// -// -//// IManagedResource[] resources; -//// -//// // Do that first, maybe we have got wrong entries -//// // cached -//// cvsFolder.clearCache(false); -//// -//// if (!deep) { -//// return; -//// } -//// -//// resources = getFolders(); -//// -//// for (int i = 0; i < resources.length; i++) { -//// resources[i].clearCache(true); -//// } - - } - - /** - * @see IManagedResource#isDirty() - */ - public boolean showDirty() throws CVSException { - - IManagedResource[] children; - boolean result = false; - - if (!CACHING || showDirtyCache == null) { - - // We do not have a cached value therefore we: - // 1. init the result to false - // 2. search in all subfolders and files - // until we find a dirty element - // 3. If we do we just skip the rest with the - // "shortcut OR" (||) - - if (!exists() || !isCVSFolder()) { - showDirtyCache = new Boolean(true); - } else { - - children = getFiles(); - for (int i = 0; i < children.length; i++) { - result = result || children[i].showDirty(); - } - - children = getFolders(); - for (int i = 0; i < children.length; i++) { - result = result || children[i].showDirty(); - } - - showDirtyCache = new Boolean(result); - } - } - - return showDirtyCache.booleanValue(); - } - -} - diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/ManagedResource.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/ManagedResource.java deleted file mode 100644 index 569556329..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/ManagedResource.java +++ /dev/null @@ -1,250 +0,0 @@ -package org.eclipse.team.internal.ccvs.core.resources; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.io.IOException; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.resources.api.CVSFileNotFoundException; -import org.eclipse.team.internal.ccvs.core.resources.api.ICVSFile; -import org.eclipse.team.internal.ccvs.core.resources.api.ICVSFolder; -import org.eclipse.team.internal.ccvs.core.resources.api.ICVSResource; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFile; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFolder; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedResource; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedVisitor; -import org.eclipse.team.internal.ccvs.core.util.Assert; -import org.eclipse.team.internal.ccvs.core.util.Util; - -/** - * Implements the IManagedResource interface on top of an - * instance of the ICVSResource interface - * - * @see IManagedResource - */ -abstract class ManagedResource implements IManagedResource { - - // If we do not extend the key and therefore the key is the same like - // the absolut pathname we have indirectly an reference to the key in - // the weak hashmap. Therefore the WeakHashMap does not finalize anything - static final String KEY_EXTENTION = "KEY"; - - static final String PLATFORM_NEWLINE = System.getProperty("line.separator"); - static final String SERVER_NEWLINE = "\n"; - - static final byte[] PLATFORM_NEWBYTE = PLATFORM_NEWLINE.getBytes(); - static final byte[] SERVER_NEWBYTE = SERVER_NEWLINE.getBytes(); - - // Flag for the caching of folders/files - static final boolean CACHING = true; - - // Initialise Chaches to empty - Boolean showDirtyCache = null; - Boolean showManagedCache = null; - - /** - * 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(IManagedFolder root) - throws CVSException { - - ManagedResource rootFolder; - String result; - - try { - rootFolder = (ManagedResource)root; - } catch (ClassCastException e) { - throw new CVSException(0,0,"two different implementations of IManagedResource used",e); - } - - result = Util.getRelativePath(rootFolder.getCVSResource().getPath(),getCVSResource().getPath()); - return convertSeparatorOutgoing(result); - - } - - /** - * @see IManagedResource#delete() - */ - public void delete() { - getCVSResource().delete(); - clearDirty(true); - } - - /** - * @see IManagedResource#exists() - */ - public boolean exists() { - return getCVSResource().exists(); - } - - /** - * @see IManagedResource#getParent() - */ - public IManagedFolder getParent() { - return getInternalParent(); - } - - /** - * @see IManagedResource#getParent() - */ - ManagedFolder getInternalParent() { - return ManagedFolder.createInternalFolderFrom(getCVSResource().getParent()); - } - - - /** - * @see IManagedResource#getName() - */ - public String getName() { - return getCVSResource().getName(); - } - - /** - * @see IManagedResource#isIgnored() - */ - public boolean isIgnored() throws CVSException { - return (!isManaged() && ((ManagedFolder)getParent()).isIgnored(getName())); - } - - /** - * Create a IManagedFolder from a CVSFolder - */ - public static IManagedFolder createResourceFrom(ICVSFolder folder) { - return ManagedFolder.createInternalFolderFrom(folder); - } - - /** - * Create a IManagedFile form a CVSFile - * - * For internal use only - */ - public static IManagedFile createResourceFrom(ICVSFile file) { - return ManagedFile.createInternalFileFrom(file); - } - -// /** -// * Clean up incoming path -// * replaces "/" and "\\" for ICVSResource.seperator -// */ -// static String convertSeparatorIncoming(String path) { -// return convertSeperator(path, ICVSResource.seperator); -// } - - /** - * Clean up outgoing path - * replaces "/" and "\\" for this.seperator - */ - static String convertSeparatorOutgoing(String path) { - return convertSeperator(path, separator); - } - - /** - * replaces "/" and "\\" for newSeperator - * @param newSeperator has to be "/" or "\\" - */ - private static String convertSeperator(String path,String newSeperator) { - - Assert.isTrue(newSeperator.equals("/") || newSeperator.equals("\\")); - - if (newSeperator.equals("/")) { - return path.replace('\\','/'); - } else { - return path.replace('/','\\'); - } - } - - /** - * Throws an CVSFileNotFoundException if exists() = false - */ - void exceptionIfNotExists() throws CVSFileNotFoundException { - if (!exists()) { - throw new CVSFileNotFoundException(getName() + " does not exist"); - } - } - - /** - * 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 ManagedResource)) { - return false; - } else { - return getCVSResource().equals(((ManagedResource) obj).getCVSResource()); - } - } - - /** - * Generate a Standard CVSException for an - * IOException - * - * Copied from CVSResource, we might have other texts here - */ - protected static CVSException wrapException(IOException e) { - return new CVSException(IStatus.ERROR, - CVSException.IO_FAILED, - "An IOException occured while using your file-system.", - e); - } - - /** - * In order not to intrudce an new resource variable in this class we - * have an abstract method that returns the resource. - * - * As the resource could be of two different types, we do not want to - * save it here and do the cast in the Folder or the File - */ - public abstract ICVSResource getCVSResource(); - - /** - * Implement the hashcode on the underlying strings, like it - * is done in the equals. - */ - public int hashCode() { - return getCVSResource().hashCode(); - } - - /** - * @see IManagedResource#clearDirty(boolean) - */ - public void clearDirty(boolean up) { - if (showDirtyCache == null) { - return; - } - - showDirtyCache = null; - - if (up) { - getInternalParent().clearDirty(up); - } - } - - /** - * @see IManagedResource#showManaged() - */ - public boolean showManaged() throws CVSException { - if (!CACHING || showManagedCache == null) { - showManagedCache = new Boolean(isManaged()); - } - return showManagedCache.booleanValue(); - } - - /** - * @see IManagedResource#clearManaged() - */ - public void clearManaged() throws CVSException { - showManagedCache = null; - } - -} - - - diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/api/NotCVSFolderException.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/NotCVSFolderException.java index a1ff9c60c..c5a4ee972 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/api/NotCVSFolderException.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/NotCVSFolderException.java @@ -1,4 +1,4 @@ -package org.eclipse.team.internal.ccvs.core.resources.api;
+package org.eclipse.team.internal.ccvs.core.resources;
/*
* (c) Copyright IBM Corp. 2000, 2001.
@@ -8,9 +8,9 @@ package org.eclipse.team.internal.ccvs.core.resources.api; import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
+import org.eclipse.team.ccvs.core.CVSProviderPlugin;
import org.eclipse.team.internal.ccvs.core.CVSException;
import org.eclipse.team.internal.ccvs.core.connection.ResourceStatus;
-import org.eclipse.team.ccvs.core.CVSProviderPlugin;
/**
* This Exception indicates that you have tried to call
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/RemoteFile.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/RemoteFile.java index 3d481fb1e..6644102a9 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/RemoteFile.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/RemoteFile.java @@ -1,300 +1,273 @@ -package org.eclipse.team.internal.ccvs.core.resources; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.ccvs.core.ICVSRemoteFile; -import org.eclipse.team.ccvs.core.ICVSRepositoryLocation; -import org.eclipse.team.ccvs.core.ILogEntry; -import org.eclipse.team.core.TeamException; -import org.eclipse.team.core.sync.IRemoteResource; -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.Client; -import org.eclipse.team.internal.ccvs.core.Policy; -import org.eclipse.team.internal.ccvs.core.connection.CVSRepositoryLocation; -import org.eclipse.team.internal.ccvs.core.resources.api.CVSFileNotFoundException; -import org.eclipse.team.internal.ccvs.core.resources.api.FileProperties; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFile; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFolder; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedVisitor; -import org.eclipse.team.internal.ccvs.core.response.IResponseHandler; -import org.eclipse.team.internal.ccvs.core.response.custom.LogHandler; - -/** - * This class provides the implementation of ICVSRemoteFile and IManagedFile for - * use by the repository and sync view. - */ -public class RemoteFile extends RemoteResource implements ICVSRemoteFile, IManagedFile { - - // cache for file properties provided by cvs commands - private FileProperties info; - - // cache for file contents received from the server - private ByteArrayOutputStream bos; - - protected RemoteFolder parent; - - /** - * Constructor for RemoteFile. +package org.eclipse.team.internal.ccvs.core.resources;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.team.ccvs.core.CVSTag;
+import org.eclipse.team.ccvs.core.ICVSRemoteFile;
+import org.eclipse.team.ccvs.core.ICVSRepositoryLocation;
+import org.eclipse.team.ccvs.core.ILogEntry;
+import org.eclipse.team.core.TeamException;
+import org.eclipse.team.core.sync.IRemoteResource;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.Client;
+import org.eclipse.team.internal.ccvs.core.Policy;
+import org.eclipse.team.internal.ccvs.core.connection.CVSRepositoryLocation;
+import org.eclipse.team.internal.ccvs.core.response.IResponseHandler;
+import org.eclipse.team.internal.ccvs.core.response.custom.LogHandler;
+
+/**
+ * This class provides the implementation of ICVSRemoteFile and IManagedFile for
+ * use by the repository and sync view.
+ */
+public class RemoteFile extends RemoteResource implements ICVSRemoteFile, ICVSFile {
+
+ // cache for file contents received from the server
+ private InputStream contents;
+
+ /**
+ * Constructor for RemoteFile.
+ */
+ public RemoteFile(RemoteFolder parent, String name, CVSTag tag) {
+ this(parent, name, "0", tag);
+ }
+
+ public RemoteFile(RemoteFolder parent, String name, String revision, CVSTag tag) {
+ super(parent, name, tag, false);
+ info.setTimeStamp("dummy");
+ info.setKeywordMode("-kb"); // NOTE: We need to get the right one
+ info.setRevision(revision);
+ info.setPermissions("u=rw,g=rw,o=rw");
+ }
+
+ /**
+ * @see ICVSResource#accept(IManagedVisitor) */ - public RemoteFile(RemoteFolder parent, String name, String tag) { - super(name, tag); - this.parent = parent; - } - - /** - * @see IManagedResource#accept(IManagedVisitor) - */ - public void accept(IManagedVisitor visitor) throws CVSException { + public void accept(ICVSResourceVisitor visitor) throws CVSException { visitor.visitFile(this); } /** - * @see ICVSRemoteFile#getContents() - */ - public InputStream getContents(final IProgressMonitor monitor) { - - // Perform a "cvs update..." - try { - List localOptions = getLocalOptionsForTag(); - Client.execute( - Client.UPDATE, - Client.EMPTY_ARGS_LIST, - (String[])localOptions.toArray(new String[localOptions.size()]), - new String[]{getName()}, - parent, - monitor, - getPrintStream(), - (CVSRepositoryLocation)getRepository(), - null); - return getCachedContents(); - } catch(CVSException e) { - return null; - } - } - - /** - * @see ICVSRemoteFile#getLogEntries() - */ - public ILogEntry[] getLogEntries(IProgressMonitor monitor) throws CVSException { - - // Perform a "cvs log..." with a custom message handler - final List entries = new ArrayList(); - Client.execute( - Client.LOG, - Client.EMPTY_ARGS_LIST, - Client.EMPTY_ARGS_LIST, - new String[]{getName()}, - parent, - monitor, - getPrintStream(), - (CVSRepositoryLocation)getRepository(), - new IResponseHandler[] {new LogHandler(this, entries)}); - return (ILogEntry[])entries.toArray(new ILogEntry[entries.size()]); - } - - /** - * @see ICVSRemoteFile#getRevision() - */ - public String getRevision() { - return tag; - } - - public RemoteFile toRevision(String revision) { - return new RemoteFile(parent, getName(), revision); - } - - /** - * @see IManagedFile#getSize() - */ - public long getSize() { - return 0; - } - - /** - * @see IManagedFile#getFileInfo() - */ - public FileProperties getFileInfo() throws CVSException { - if (info == null) { - FileProperties properties = new FileProperties(); - properties.setName(getName()); - properties.setTimeStamp("dummy"); - properties.setKeywordMode("-kb"); - properties.setVersion("0"); - properties.setPermissions("u=rw,g=rw,o=rw"); - if ((parent.tag != null) && !(parent.tag.equals("HEAD"))) - properties.setTag("T" + parent.tag); - return properties; - } - return info; - } - - /* - * @see IManagedResource#getParent() - */ - public IManagedFolder getParent() { + * @see ICVSRemoteFile#getContents()
+ */
+ public InputStream getContents(final IProgressMonitor monitor) {
+
+ try {
+
+ if(contents==null) {
+ List localOptions = getLocalOptionsForTag();
+ Client.execute(
+ Client.UPDATE,
+ Client.EMPTY_ARGS_LIST,
+ new String[]{"-r", info.getRevision()},
+ new String[]{getName()},
+ parent,
+ monitor,
+ getPrintStream(),
+ (CVSRepositoryLocation)getRepository(),
+ null);
+ }
+ return contents;
+ } catch(CVSException e) {
+ return null;
+ }
+ }
+
+ /**
+ * @see ICVSRemoteFile#getLogEntries()
+ */
+ public ILogEntry[] getLogEntries(IProgressMonitor monitor) throws CVSException {
+
+ // Perform a "cvs log..." with a custom message handler
+ final List entries = new ArrayList();
+ Client.execute(
+ Client.LOG,
+ Client.EMPTY_ARGS_LIST,
+ Client.EMPTY_ARGS_LIST,
+ new String[]{getName()},
+ parent,
+ monitor,
+ getPrintStream(),
+ (CVSRepositoryLocation)getRepository(),
+ new IResponseHandler[] {new LogHandler(this, entries)});
+ return (ILogEntry[])entries.toArray(new ILogEntry[entries.size()]);
+ }
+
+ /**
+ * @see ICVSRemoteFile#getRevision()
+ */
+ public String getRevision() {
+ return info.getRevision();
+ }
+
+ public RemoteFile toRevision(String revision) {
+ return new RemoteFile(parent, getName(), revision, new CVSTag());
+ }
+
+ /**
+ * @see IManagedFile#getSize()
+ */
+ public long getSize() {
+ return 0;
+ }
+
+ /**
+ * @see IManagedFile#getFileInfo()
+ */
+ public ResourceSyncInfo getSyncInfo() {
+ return info;
+ }
+
+ public ICVSFolder getParent() { return parent; } - /** - * @see IManagedResource#getRelativePath(IManagedFolder) - */ - public String getRelativePath(IManagedFolder ancestor) throws CVSException { - String result = parent.getRelativePath(ancestor); - if (result.length() == 0) - return getName(); - else - return result + Client.SERVER_SEPARATOR + getName(); - } - - /** - * @see IManagedResource#getRemoteLocation(IManagedFolder) - */ - public String getRemoteLocation(IManagedFolder stopSearching) throws CVSException { - return parent.getRemoteLocation(stopSearching) + Client.SERVER_SEPARATOR + getName(); - } - - /** - * Get the remote path for the receiver relative to the repository location path - */ - public String getRemotePath() { - String parentPath = parent.getRemotePath(); - return parentPath + Client.SERVER_SEPARATOR + getName(); - } - - /** - * Return the server root directory for the repository - */ - public ICVSRepositoryLocation getRepository() { - return parent.getRepository(); - } - - /** - * @see IManagedFile#setFileInfo(FileProperties) - */ - public void setFileInfo(FileProperties fileInfo) throws CVSException { - info = fileInfo; - } - - public void setRevision(String revision) { - tag = revision; - } - - /** - * @see IManagedFile#sendTo(OutputStream, IProgressMonitor, boolean) - */ - public void sendTo( - OutputStream outputStream, - IProgressMonitor monitor, - boolean binary) - throws CVSException { - - throw new CVSException(Policy.bind("RemoteResource.invalidOperation")); - } - - /** - * @see IManagedFile#receiveFrom(InputStream, IProgressMonitor, long, boolean) - */ - public void receiveFrom( - InputStream inputStream, - IProgressMonitor monitor, - long size, - boolean binary, - boolean readOnly) - throws CVSException { - - // NOTE: This should be changed such that the client or connection handles - // the proper transfer - try { - bos = new ByteArrayOutputStream(); - if (binary) - ManagedFile.transferWithProgress(inputStream, bos, (long)size, monitor, ""); - else - ManagedFile.transferText(inputStream, bos, (long)size, monitor, "", false); - } catch (IOException ex) { - throw ManagedFile.wrapException(ex); - } - } - - /** - * @see IManagedFile#getTimeStamp() - */ - public String getTimeStamp() throws CVSFileNotFoundException { - return null; - } - - /** - * @see IManagedFile#setTimeStamp(String) - */ - public void setTimeStamp(String date) throws CVSException { - } - - /** - * @see IManagedFile#isDirty() - */ - public boolean isDirty() throws CVSException { - return false; - } - - /** - * @see IManagedFile#moveTo(IManagedFile) + /**
+ * @see ICVSResource#getRelativePath(ICVSFolder)
*/ - public void moveTo(IManagedFile mFile) throws CVSException, ClassCastException { - throw new CVSException(Policy.bind("RemoteResource.invalidOperation")); - } - - /** - * @see IManagedFile#getContent() - */ - public String[] getContent() throws CVSException { - throw new CVSException(Policy.bind("RemoteResource.invalidOperation")); - } - - /** - * @see Comparable#compareTo(Object) - */ - public int compareTo(Object arg0) { - return 0; - } - - /** - * Return an InputStream which contains the contents of the remote file. - */ - private InputStream getCachedContents() { - InputStream is = new ByteArrayInputStream(bos.toByteArray()); - bos = null; - return is; - } - /* - * @see IRemoteResource#members(IProgressMonitor) - */ - public IRemoteResource[] members(IProgressMonitor progress) throws TeamException { - return new IRemoteResource[0]; - } - - /* - * @see IRemoteResource#isContainer() - */ - public boolean isContainer() { - return false; - } - - /* - * @see IManagedResource#isFolder() - */ - public boolean isFolder() { - return false; - } -} - + public String getRelativePath(ICVSFolder ancestor) throws CVSException { + String result = parent.getRelativePath(ancestor);
+ if (result.length() == 0)
+ return getName();
+ else
+ return result + Client.SERVER_SEPARATOR + getName();
+ }
+
+ /**
+ * @see ICVSResource#getRemoteLocation(ICVSFolder)
+ */
+ public String getRemoteLocation(ICVSFolder stopSearching) throws CVSException {
+ return parent.getRemoteLocation(stopSearching) + Client.SERVER_SEPARATOR + getName();
+ }
+
+ /**
+ * Get the remote path for the receiver relative to the repository location path
+ */
+ public String getRemotePath() {
+ String parentPath = parent.getRemotePath();
+ return parentPath + Client.SERVER_SEPARATOR + getName();
+ }
+
+ /**
+ * Return the server root directory for the repository
+ */
+ public ICVSRepositoryLocation getRepository() {
+ return parent.getRepository();
+ }
+
+ /**
+ * @see IManagedFile#setFileInfo(FileProperties)
+ */
+ public void setSyncInfo(ResourceSyncInfo fileInfo) {
+ info = fileInfo;
+ }
+
+ protected void setRevision(String revision) {
+ info.setRevision(revision);
+ }
+
+ /**
+ * @see IManagedFile#sendTo(OutputStream, IProgressMonitor, boolean)
+ */
+ public void sendTo(
+ OutputStream out,
+ IProgressMonitor monitor,
+ boolean binary)
+ throws CVSException {
+ try {
+ String SERVER_NEWLINE = "\n";
+ // Send the size to the server and no contents
+ out.write(0);
+ out.write(SERVER_NEWLINE.getBytes());
+ } catch(IOException e) {
+ }
+ }
+
+ /**
+ * @see IManagedFile#receiveFrom(InputStream, IProgressMonitor, long, boolean)
+ */
+ public void receiveFrom(
+ InputStream inputStream,
+ IProgressMonitor monitor,
+ long size,
+ boolean binary,
+ boolean readOnly)
+ throws CVSException {
+
+ // NOTE: This should be changed such that the client or connection handles
+ // the proper transfer
+ try {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ if (binary)
+ LocalFile.transferWithProgress(inputStream, bos, (long)size, monitor, "");
+ else
+ LocalFile.transferText(inputStream, bos, (long)size, monitor, "", false);
+
+ contents = new ByteArrayInputStream(bos.toByteArray());
+
+ } catch (IOException ex) {
+ throw CVSException.wrapException(ex);
+ }
+ }
+
+ /**
+ * @see IManagedFile#getTimeStamp()
+ */
+ public String getTimeStamp() throws CVSFileNotFoundException {
+ return null;
+ }
+
+ /**
+ * @see IManagedFile#setTimeStamp(String)
+ */
+ public void setTimeStamp(String date) throws CVSException {
+ }
+
+ /**
+ * @see IManagedFile#isDirty()
+ */
+ public boolean isDirty() throws CVSException {
+ return false;
+ }
+
+ /**
+ * @see IManagedFile#moveTo(IManagedFile)
+ */
+ public void moveTo(ICVSFile mFile) throws CVSException, ClassCastException {
+ throw new CVSException(Policy.bind("RemoteResource.invalidOperation"));
+ }
+
+ /*
+ * @see IRemoteResource#members(IProgressMonitor)
+ */
+ public IRemoteResource[] members(IProgressMonitor progress) throws TeamException {
+ return new IRemoteResource[0];
+ }
+
+ /*
+ * @see IRemoteResource#isContainer()
+ */
+ public boolean isContainer() {
+ return false;
+ }
+
+ /*
+ * @see ICVSResource#isFolder()
+ */
+ public boolean isFolder() {
+ return false;
+ }
+
+}
+
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/RemoteFolder.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/RemoteFolder.java index cfb60e183..51526f46a 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/RemoteFolder.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/RemoteFolder.java @@ -1,99 +1,95 @@ -package org.eclipse.team.internal.ccvs.core.resources; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.io.InputStream; -import java.io.PrintStream; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.OperationCanceledException; -import org.eclipse.core.runtime.Path; -import org.eclipse.team.ccvs.core.ICVSRemoteFolder; -import org.eclipse.team.ccvs.core.ICVSRemoteResource; -import org.eclipse.team.ccvs.core.ICVSRepositoryLocation; -import org.eclipse.team.core.TeamException; -import org.eclipse.team.core.sync.IRemoteResource; -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.Client; -import org.eclipse.team.internal.ccvs.core.Policy; -import org.eclipse.team.internal.ccvs.core.connection.CVSRepositoryLocation; -import org.eclipse.team.internal.ccvs.core.connection.CVSServerException; -import org.eclipse.team.internal.ccvs.core.connection.Connection; -import org.eclipse.team.internal.ccvs.core.resources.api.FolderProperties; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFile; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFolder; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedResource; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedVisitor; -import org.eclipse.team.internal.ccvs.core.response.IResponseHandler; -import org.eclipse.team.internal.ccvs.core.response.custom.IStatusListener; -import org.eclipse.team.internal.ccvs.core.response.custom.IUpdateMessageListener; -import org.eclipse.team.internal.ccvs.core.response.custom.StatusErrorHandler; -import org.eclipse.team.internal.ccvs.core.response.custom.StatusMessageHandler; -import org.eclipse.team.internal.ccvs.core.response.custom.UpdateErrorHandler; -import org.eclipse.team.internal.ccvs.core.response.custom.UpdateMessageHandler; - -/** - * This class provides the implementation of ICVSRemoteFolder - */ -public class RemoteFolder extends RemoteResource implements ICVSRemoteFolder, IManagedFolder { - - private ICVSRemoteResource[] children; - private CVSRepositoryLocation repository; - private IPath repositoryRelativePath; - - /** - * Constructor for RemoteFolder. - */ - public RemoteFolder(ICVSRepositoryLocation repository, IPath repositoryRelativePath, String tag) { - super(repositoryRelativePath.lastSegment(), tag); - this.repository = (CVSRepositoryLocation)repository; - this.repositoryRelativePath = repositoryRelativePath; - } - - // Get the file revisions for the given filenames - protected void updateFileRevisions(Connection connection, String[] fileNames, IProgressMonitor monitor) throws CVSException { - - final int[] count = new int[] {0}; - - // Create a listener for receiving the revision info - final Map revisions = new HashMap(); - IStatusListener listener = new IStatusListener() { - public void fileStatus(IPath path, String remoteRevision) { +package org.eclipse.team.internal.ccvs.core.resources;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.io.InputStream;
+import java.io.PrintStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.team.ccvs.core.CVSTag;
+import org.eclipse.team.ccvs.core.ICVSRemoteFolder;
+import org.eclipse.team.ccvs.core.ICVSRemoteResource;
+import org.eclipse.team.ccvs.core.ICVSRepositoryLocation;
+import org.eclipse.team.core.TeamException;
+import org.eclipse.team.core.sync.IRemoteResource;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.Client;
+import org.eclipse.team.internal.ccvs.core.Policy;
+import org.eclipse.team.internal.ccvs.core.connection.CVSRepositoryLocation;
+import org.eclipse.team.internal.ccvs.core.connection.CVSServerException;
+import org.eclipse.team.internal.ccvs.core.connection.Connection;
+import org.eclipse.team.internal.ccvs.core.response.IResponseHandler;
+import org.eclipse.team.internal.ccvs.core.response.custom.IStatusListener;
+import org.eclipse.team.internal.ccvs.core.response.custom.IUpdateMessageListener;
+import org.eclipse.team.internal.ccvs.core.response.custom.StatusErrorHandler;
+import org.eclipse.team.internal.ccvs.core.response.custom.StatusMessageHandler;
+import org.eclipse.team.internal.ccvs.core.response.custom.UpdateErrorHandler;
+import org.eclipse.team.internal.ccvs.core.response.custom.UpdateMessageHandler;
+
+/**
+ * This class provides the implementation of ICVSRemoteFolder
+ */
+public class RemoteFolder extends RemoteResource implements ICVSRemoteFolder, ICVSFolder {
+
+ private ICVSRemoteResource[] children;
+ private CVSRepositoryLocation repository;
+ private IPath repositoryRelativePath;
+
+ /**
+ * Constructor for RemoteFolder.
+ */
+ public RemoteFolder(RemoteFolder parent, ICVSRepositoryLocation repository, IPath repositoryRelativePath, CVSTag tag) {
+ super(parent, repositoryRelativePath.lastSegment() == null ? "" : repositoryRelativePath.lastSegment() , tag, true);
+ this.repository = (CVSRepositoryLocation)repository;
+ this.repositoryRelativePath = repositoryRelativePath;
+ }
+
+ // Get the file revisions for the given filenames
+ protected void updateFileRevisions(Connection connection, String[] fileNames, IProgressMonitor monitor) throws CVSException {
+
+ final int[] count = new int[] {0};
+
+ // Create a listener for receiving the revision info
+ final Map revisions = new HashMap();
+ IStatusListener listener = new IStatusListener() {
+ public void fileStatus(IPath path, String remoteRevision) {
if (remoteRevision == IStatusListener.FOLDER_RIVISION) // Ignore any folders return; - try { - ((RemoteFile)getChild(path.lastSegment())).setRevision(remoteRevision); - count[0]++; - } catch (CVSException e) { - // The count wil be off to indicate an error - } - } - }; - - // Perform a "cvs status..." with a custom message handler + try {
+ ((RemoteFile)getChild(path.lastSegment())).setRevision(remoteRevision);
+ count[0]++;
+ } catch (CVSException e) {
+ // The count wil be off to indicate an error
+ }
+ }
+ };
+
+ // Perform a "cvs status..." with a custom message handler
final List errors = new ArrayList(); try { - Client.execute( - Client.STATUS, - Client.EMPTY_ARGS_LIST, + Client.execute(
+ Client.STATUS,
+ Client.EMPTY_ARGS_LIST,
Client.EMPTY_ARGS_LIST, - fileNames, - this, - monitor, - getPrintStream(), - connection, + fileNames,
+ this,
+ monitor,
+ getPrintStream(),
+ connection,
new IResponseHandler[] {new StatusMessageHandler(listener),new StatusErrorHandler(listener, errors)}, - false); + false);
} catch (CVSException e) { if (!errors.isEmpty()) { PrintStream out = getPrintStream(); @@ -102,107 +98,109 @@ public class RemoteFolder extends RemoteResource implements ICVSRemoteFolder, IM } throw e; } - - if (count[0] != fileNames.length) - throw new CVSException(Policy.bind("RemoteFolder.errorFetchingRevisions")); - } - - /** +
+ if (count[0] != fileNames.length)
+ throw new CVSException(Policy.bind("RemoteFolder.errorFetchingRevisions"));
+ }
+
+ /**
* @see IManagedResource#accept(IManagedVisitor) */ - public void accept(IManagedVisitor visitor) throws CVSException { + public void accept(ICVSResourceVisitor visitor) throws CVSException { visitor.visitFolder(this); } /** - * @see ICVSRemoteFolder#getMembers() - */ - public ICVSRemoteResource[] getMembers(IProgressMonitor monitor) throws TeamException { - return getMembers(tag, monitor); - } - - /* + * @see ICVSRemoteFolder#getMembers()
+ */
+ public ICVSRemoteResource[] getMembers(IProgressMonitor monitor) throws TeamException {
+ return getMembers(getTag(), monitor);
+ }
+
+ /**
* This method gets the members for a given tag and returns them. * During the execution of this method, the instance variable children * will be used to contain the children. However, the variable is reset * and the result returned. Thus, instances of RemoteFolder do not * persist the children. Subclasses (namely RemoteFolderTree) may * persist the children. - */ - public ICVSRemoteResource[] getMembers(final String tagName, IProgressMonitor monitor) throws TeamException { - - final IProgressMonitor progress = Policy.monitorFor(monitor); - - // Forget about our children - children = null; - - // Create the listener for remote files and folders - final List errors = new ArrayList(); - final List newRemoteDirectories = new ArrayList(); - final List newRemoteFiles = new ArrayList(); - IUpdateMessageListener listener = new IUpdateMessageListener() { - public void directoryInformation(IPath path, boolean newDirectory) { - if (newDirectory && path.segmentCount() == 1) { - newRemoteDirectories.add(path.lastSegment()); - progress.subTask(path.lastSegment().toString()); - progress.worked(1); - } - } - public void directoryDoesNotExist(IPath path) { - } - public void fileInformation(char type, String filename) { - IPath filePath = new Path(filename); - if( filePath.segmentCount() == 1 ) { - String properFilename = filePath.lastSegment(); - newRemoteFiles.add(properFilename); - progress.subTask(properFilename); - progress.worked(1); - } - } - }; - - // Build the local options - List localOptions = new ArrayList(); - localOptions.add("-d"); - if ((tagName != null) && (!tagName.equals("HEAD"))) { - localOptions.add(Client.TAG_OPTION); - localOptions.add(tagName); - } - - // Retrieve the children and any file revision numbers in a single connection - Connection c = ((CVSRepositoryLocation)getRepository()).openConnection(); - try { - // Perform a "cvs -n update -d -r tagName folderName" with custom message and error handlers - Client.execute( - Client.UPDATE, - new String[]{Client.NOCHANGE_OPTION}, - (String[])localOptions.toArray(new String[localOptions.size()]), - new String[]{"."}, - this, - monitor, - getPrintStream(), - c, - new IResponseHandler[]{new UpdateMessageHandler(listener), new UpdateErrorHandler(listener, errors)}, - true); - - if (progress.isCanceled()) { - throw new OperationCanceledException(); - } - - // Convert the file and folder names to IManagedResources - List result = new ArrayList(); - for (int i=0;i<newRemoteFiles.size();i++) { - result.add(new RemoteFile(this, (String)newRemoteFiles.get(i), null)); - } - for (int i=0;i<newRemoteDirectories.size();i++) - result.add(new RemoteFolder(getRepository(), repositoryRelativePath.append((String)newRemoteDirectories.get(i)), tagName)); - children = (ICVSRemoteResource[])result.toArray(new ICVSRemoteResource[0]); - - // Get the revision numbers for the files - if (newRemoteFiles.size() > 0) { - updateFileRevisions(c, (String[])newRemoteFiles.toArray(new String[newRemoteFiles.size()]), monitor); - } - + */
+ protected ICVSRemoteResource[] getMembers(final CVSTag tag, IProgressMonitor monitor) throws TeamException {
+
+ final IProgressMonitor progress = Policy.monitorFor(monitor);
+
+ // Forget about our children
+ children = null;
+
+ // Create the listener for remote files and folders
+ final List errors = new ArrayList();
+ final List newRemoteDirectories = new ArrayList();
+ final List newRemoteFiles = new ArrayList();
+ IUpdateMessageListener listener = new IUpdateMessageListener() {
+ public void directoryInformation(IPath path, boolean newDirectory) {
+ if (newDirectory && path.segmentCount() == 1) {
+ newRemoteDirectories.add(path.lastSegment());
+ progress.subTask(path.lastSegment().toString());
+ progress.worked(1);
+ }
+ }
+ public void directoryDoesNotExist(IPath path) {
+ }
+ public void fileInformation(char type, String filename) {
+ IPath filePath = new Path(filename);
+ if( filePath.segmentCount() == 1 ) {
+ String properFilename = filePath.lastSegment();
+ newRemoteFiles.add(properFilename);
+ progress.subTask(properFilename);
+ progress.worked(1);
+ }
+ }
+ public void fileDoesNotExist(String filename) {
+ }
+ };
+
+ // Build the local options
+ List localOptions = new ArrayList();
+ localOptions.add("-d");
+ if ((tag != null) && (tag.getType() != CVSTag.HEAD)) {
+ localOptions.add(Client.TAG_OPTION);
+ localOptions.add(tag.getName());
+ }
+
+ // Retrieve the children and any file revision numbers in a single connection
+ Connection c = ((CVSRepositoryLocation)getRepository()).openConnection();
+ try {
+ // Perform a "cvs -n update -d -r tagName folderName" with custom message and error handlers
+ Client.execute(
+ Client.UPDATE,
+ new String[]{Client.NOCHANGE_OPTION},
+ (String[])localOptions.toArray(new String[localOptions.size()]),
+ new String[]{"."},
+ this,
+ monitor,
+ getPrintStream(),
+ c,
+ new IResponseHandler[]{new UpdateMessageHandler(listener), new UpdateErrorHandler(listener, errors)},
+ true);
+
+ if (progress.isCanceled()) {
+ throw new OperationCanceledException();
+ }
+
+ // Convert the file and folder names to IManagedResources
+ List result = new ArrayList();
+ for (int i=0;i<newRemoteFiles.size();i++) {
+ result.add(new RemoteFile(this, (String)newRemoteFiles.get(i), tag));
+ }
+ for (int i=0;i<newRemoteDirectories.size();i++)
+ result.add(new RemoteFolder(this, getRepository(), repositoryRelativePath.append((String)newRemoteDirectories.get(i)), tag));
+ children = (ICVSRemoteResource[])result.toArray(new ICVSRemoteResource[0]);
+
+ // Get the revision numbers for the files
+ if (newRemoteFiles.size() > 0) {
+ updateFileRevisions(c, (String[])newRemoteFiles.toArray(new String[newRemoteFiles.size()]), monitor);
+ }
+
} catch (CVSServerException e) { if( ! isNoTagException(errors) ) throw e; @@ -211,108 +209,108 @@ public class RemoteFolder extends RemoteResource implements ICVSRemoteFolder, IM // workaround: retry the request with no tag to get the directory names (if any) Policy.checkCanceled(progress); children = getMembers(null, progress); - } catch (CVSException e) { + } catch (CVSException e) {
if (!errors.isEmpty()) { PrintStream out = getPrintStream(); for (int i=0;i<errors.size();i++) out.println(errors.get(i)); } throw e; - } finally { - c.close(); - } + } finally {
+ c.close();
+ }
// Forget the children ICVSRemoteResource[] result = children; children = null; return result; - } - - /** - * @see IManagedFolder#getFolders() - */ - public IManagedFolder[] getFolders() throws CVSException { - ICVSRemoteResource[] children = getChildren(); - if (children == null) - return new IManagedFolder[0]; - else { - List result = new ArrayList(); - for (int i=0;i<children.length;i++) - if (((IManagedResource)children[i]).isFolder()) - result.add(children[i]); - return (IManagedFolder[])result.toArray(new IManagedFolder[result.size()]); - } - } - - /** - * @see IManagedFolder#getFiles() - */ - public IManagedFile[] getFiles() throws CVSException { - ICVSRemoteResource[] children = getChildren(); - if (children == null) - return new IManagedFile[0]; - else { - List result = new ArrayList(); - for (int i=0;i<children.length;i++) - if (!((IManagedResource)children[i]).isFolder()) - result.add(children[i]); - return (IManagedFile[])result.toArray(new IManagedFile[result.size()]); - } - } - - /** - * @see IManagedFolder#getFolder(String) - */ - public IManagedFolder getFolder(String name) throws CVSException { - if (name.equals(Client.CURRENT_LOCAL_FOLDER) || name.equals(Client.CURRENT_LOCAL_FOLDER + Client.SERVER_SEPARATOR)) - return this; - IManagedResource child = getChild(name); - if (child.isFolder()) - return (IManagedFolder)child; - throw new CVSException(Policy.bind("RemoteFolder.invalidChild", new Object[] {name})); - } - - /** - * @see IManagedFolder#getFile(String) - */ - public IManagedFile getFile(String name) throws CVSException { - IManagedResource child = getChild(name); - if (!child.isFolder()) - return (IManagedFile)child; - throw new CVSException(Policy.bind("RemoteFolder.invalidChild", new Object[] {name})); - - } - - public String getRemotePath() { - return repositoryRelativePath.toString(); - } - - /** - * @see IManagedResource#getRelativePath(IManagedFolder) - */ - public String getRelativePath(IManagedFolder ancestor) throws CVSException { + }
+
+ /**
+ * @see ICVSFolder#getFolders()
+ */
+ public ICVSFolder[] getFolders() throws CVSException {
+ ICVSRemoteResource[] children = getChildren();
+ if (children == null)
+ return new ICVSFolder[0];
+ else {
+ List result = new ArrayList();
+ for (int i=0;i<children.length;i++)
+ if (((ICVSResource)children[i]).isFolder())
+ result.add(children[i]);
+ return (ICVSFolder[])result.toArray(new ICVSFolder[result.size()]);
+ }
+ }
+
+ /**
+ * @see ICVSFolder#getFiles()
+ */
+ public ICVSFile[] getFiles() throws CVSException {
+ ICVSRemoteResource[] children = getChildren();
+ if (children == null)
+ return new ICVSFile[0];
+ else {
+ List result = new ArrayList();
+ for (int i=0;i<children.length;i++)
+ if (!((ICVSResource)children[i]).isFolder())
+ result.add(children[i]);
+ return (ICVSFile[])result.toArray(new ICVSFile[result.size()]);
+ }
+ }
+
+ /**
+ * @see ICVSFolder#getFolder(String)
+ */
+ public ICVSFolder getFolder(String name) throws CVSException {
+ if (name.equals(Client.CURRENT_LOCAL_FOLDER) || name.equals(Client.CURRENT_LOCAL_FOLDER + Client.SERVER_SEPARATOR))
+ return this;
+ ICVSResource child = getChild(name);
+ if (child.isFolder())
+ return (ICVSFolder)child;
+ throw new CVSException(Policy.bind("RemoteFolder.invalidChild", new Object[] {name}));
+ }
+
+ /**
+ * @see ICVSFolder#getFile(String)
+ */
+ public ICVSFile getFile(String name) throws CVSException {
+ ICVSResource child = getChild(name);
+ if (!child.isFolder())
+ return (ICVSFile)child;
+ throw new CVSException(Policy.bind("RemoteFolder.invalidChild", new Object[] {name}));
+
+ }
+
+ public String getRemotePath() {
+ return repositoryRelativePath.toString();
+ }
+
+ /**
+ * @see ICVSResource#getRelativePath(ICVSFolder)
+ */
+ public String getRelativePath(ICVSFolder ancestor) throws CVSException { if (ancestor == this) return "."; // NOTE: This is a quick and dirty way. return this.getRemotePath().substring(((RemoteFolder)ancestor).getRemotePath().length() + 1); // throw new CVSException(Policy.bind("RemoteFolder.invalidOperation")); - } - - public ICVSRepositoryLocation getRepository() { - return repository; - } - - /** - * @see IManagedResource#isFolder() - */ - public boolean isFolder() { - return true; - } - - /* + }
+
+ public ICVSRepositoryLocation getRepository() {
+ return repository;
+ }
+
+ /**
+ * @see ICVSResource#isFolder()
+ */
+ public boolean isFolder() {
+ return true;
+ }
+
+ /**
* Return true if the exception from the cvs server is the no tag error, and false * otherwise. - */ + */
protected boolean isNoTagException(List errors) { if (errors.size() != 1) return false; @@ -322,154 +320,130 @@ public class RemoteFolder extends RemoteResource implements ICVSRemoteFolder, IM } /** - * @see IManagedFolder#childExists(String) - */ - public boolean childExists(String path) { - try { - return getChild(path) != null; - } catch (CVSException e) { - return false; - } - } - - /** - * @see IManagedFolder#getChild(String) - * - * XXX: shouldn't this consider the case where children is null. Maybe - * by running the update + status with only one member? - */ - public IManagedResource getChild(String path) throws CVSException { - ICVSRemoteResource[] children = getChildren(); - if (path.equals(Client.CURRENT_LOCAL_FOLDER) || children == null) - return this; - // NOTE: We only search down one level for now!!! - if (path.indexOf(Client.SERVER_SEPARATOR) == -1) { - for (int i=0;i<children.length;i++) { - if (children[i].getName().equals(path)) - return (IManagedResource)children[i]; - } - } else { - IPath p = new Path(path); - return ((IManagedFolder)getChild(p.segment(0))).getChild(p.removeFirstSegments(1).toString()); - } - throw new CVSException(Policy.bind("RemoteFolder.invalidChild", new Object[] {name})); - } - - /** - * @see IManagedFolder#mkdir() - */ - public void mkdir() throws CVSException { - throw new CVSException(Policy.bind("RemoteResource.invalidOperation")); - } - - /** - * @see IManagedFolder#flush(boolean) - */ - public void flush(boolean deep) { - } - - /** - * @see IManagedFolder#getFolderInfo() - */ - public FolderProperties getFolderInfo() throws CVSException { - FolderProperties fp = new FolderProperties(getRepository().getLocation(), getRemotePath(), false); - if ((tag != null) && !(tag.equals("HEAD"))) - fp.setTag("T" + tag); - return fp; - } - - /** - * @see IManagedFolder#setFolderInfo(FolderProperties) - */ - public void setFolderInfo(FolderProperties folderInfo) throws CVSException { - } - - /** - * @see IManagedFolder#setProperty(String, String[]) - */ - public void setProperty(String key, String[] content) throws CVSException { - } - - /** - * @see IManagedFolder#unsetProperty(String) - */ - public void unsetProperty(String key) throws CVSException { - } - - /** - * @see IManagedFolder#getProperty(String) - */ - public String[] getProperty(String key) throws CVSException { - throw new CVSException(Policy.bind("RemoteResource.invalidOperation")); - } - - /** - * @see IManagedResource#getRemoteLocation(IManagedFolder) + * @see ICVSFolder#childExists(String) */ - public String getRemoteLocation(IManagedFolder stopSearching) throws CVSException { - return getRepository().getRootDirectory() + Client.SERVER_SEPARATOR + getRemotePath(); - } - - /** - * @see IManagedFolder#isCVSFolder() - */ - public boolean isCVSFolder() throws CVSException { - return true; - } - - /** - * @see IManagedFolder#acceptChildren(IManagedVisitor) - */ - public void acceptChildren(IManagedVisitor visitor) throws CVSException { - throw new CVSException(Policy.bind("RemoteResource.invalidOperation")); - } - - /* - * @see IRemoteResource#isContainer() - */ - public boolean isContainer() { - return true; - } - - /* - * @see IRemoteResource#members(IProgressMonitor) - */ - public IRemoteResource[] members(IProgressMonitor progress) throws TeamException { - return getMembers(progress); - } - - /* - * @see IRemoteResource#getContents(IProgressMonitor) - */ - public InputStream getContents(IProgressMonitor progress) throws TeamException { - return null; - } - - /* - * Answers the immediate cached children of this remote folder or null if the remote folder - * handle has not yet queried the server for the its children. - */ - protected ICVSRemoteResource[] getChildren() { - return children; - } - - /* + public boolean childExists(String path) {
+ try {
+ return getChild(path) != null;
+ } catch (CVSException e) {
+ return false;
+ }
+ }
+
+ /**
+ * @see ICVSFolder#getChild(String)
+ *
+ * XXX: shouldn't this consider the case where children is null. Maybe
+ * by running the update + status with only one member?
+ */
+ public ICVSResource getChild(String path) throws CVSException {
+ ICVSRemoteResource[] children = getChildren();
+ if (path.equals(Client.CURRENT_LOCAL_FOLDER) || children == null)
+ return this;
+ // NOTE: We only search down one level for now!!!
+ if (path.indexOf(Client.SERVER_SEPARATOR) == -1) {
+ for (int i=0;i<children.length;i++) {
+ if (children[i].getName().equals(path))
+ return (ICVSResource)children[i];
+ }
+ } else {
+ IPath p = new Path(path);
+ return ((RemoteFolder)getChild(p.segment(0))).getChild(p.removeFirstSegments(1).toString());
+ }
+ throw new CVSException(Policy.bind("RemoteFolder.invalidChild", new Object[] {getName()}));
+ }
+
+ /**
+ * @see ICVSFolder#mkdir()
+ */
+ public void mkdir() throws CVSException {
+ throw new CVSException(Policy.bind("RemoteResource.invalidOperation"));
+ }
+
+ /**
+ * @see ICVSFolder#flush(boolean)
+ */
+ public void flush(boolean deep) {
+ }
+
+ /**
+ * @see ICVSFolder#getFolderInfo()
+ */
+ public FolderSyncInfo getFolderSyncInfo() throws CVSException {
+ return new FolderSyncInfo(getRepository().getLocation(), getRemotePath(), getTag(), false);
+ }
+
+ /**
+ * @see ICVSResource#getRemoteLocation(ICVSFolder)
+ */
+ public String getRemoteLocation(ICVSFolder stopSearching) throws CVSException {
+ return getRepository().getRootDirectory() + Client.SERVER_SEPARATOR + getRemotePath();
+ }
+
+ /**
+ * @see ICVSFolder#isCVSFolder()
+ */
+ public boolean isCVSFolder() {
+ return true;
+ }
+
+ /**
+ * @see ICVSFolder#acceptChildren(ICVSResourceVisitor)
+ */
+ public void acceptChildren(ICVSResourceVisitor visitor) throws CVSException {
+ throw new CVSException(Policy.bind("RemoteResource.invalidOperation"));
+ }
+
+ /*
+ * @see IRemoteResource#isContainer()
+ */
+ public boolean isContainer() {
+ return true;
+ }
+
+ /*
+ * @see IRemoteResource#members(IProgressMonitor)
+ */
+ public IRemoteResource[] members(IProgressMonitor progress) throws TeamException {
+ return getMembers(progress);
+ }
+
+ /*
+ * @see IRemoteResource#getContents(IProgressMonitor)
+ */
+ public InputStream getContents(IProgressMonitor progress) throws TeamException {
+ return null;
+ }
+
+ /*
+ * Answers the immediate cached children of this remote folder or null if the remote folder
+ * handle has not yet queried the server for the its children.
+ */
+ protected ICVSRemoteResource[] getChildren() {
+ return children;
+ }
+ /*
* This allows subclass to set the children */ protected void setChildren(ICVSRemoteResource[] children) { this.children = children; } /* - * @see ICVSRemoteFolder#setTag(String) - */ - public void setTag(String tagName) { - tag = tagName; - } - - /* - * @see ICVSRemoteFolder#getTag() - */ - public String getTag() { - return tag; - } + * @see ICVSRemoteFolder#setTag(String)
+ */
+ public void setTag(CVSTag tag) {
+ getSyncInfo().setTag(tag);
+ }
+
+ /*
+ * @see ICVSRemoteFolder#getTag()
+ */
+ public CVSTag getTag() {
+ return getSyncInfo().getTag();
+ }
+ /*
+ * @see ICVSFolder#setFolderInfo(FolderSyncInfo)
+ */
+ public void setFolderSyncInfo(FolderSyncInfo folderInfo) throws CVSException {
+ }
}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/RemoteFolderTree.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/RemoteFolderTree.java index e5db26650..4a815115c 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/RemoteFolderTree.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/RemoteFolderTree.java @@ -1,42 +1,43 @@ -package org.eclipse.team.internal.ccvs.core.resources; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.ccvs.core.ICVSRemoteResource; -import org.eclipse.team.ccvs.core.ICVSRepositoryLocation; -import org.eclipse.team.core.TeamException; - -/** - * Whereas the RemoteFolder class provides access to a remote hierarchy using - * lazy retrieval via <code>getMembers()</code>, the RemoteFolderTree will force - * a recursive retrieval of the remote hierarchy in one round trip. - */ -public class RemoteFolderTree extends RemoteFolder { - - public RemoteFolderTree(ICVSRepositoryLocation repository, IPath repositoryRelativePath, String tag) { - super(repository, repositoryRelativePath, tag); - } - - /* - * Override of inherited method which persists the children - */ - public ICVSRemoteResource[] getMembers(String tagName, IProgressMonitor monitor) throws TeamException { - if (getChildren() == null) - setChildren(super.getMembers(tagName, monitor)); - return getChildren(); - } - - /* - * This method is public to allow access by the RemoteFolderTreeBuilder utility class. - * No other external classes should use this method. - */ - public void setChildren(ICVSRemoteResource[] children) { - super.setChildren(children); - } -} - +package org.eclipse.team.internal.ccvs.core.resources;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.team.ccvs.core.CVSTag;
+import org.eclipse.team.ccvs.core.ICVSRemoteResource;
+import org.eclipse.team.ccvs.core.ICVSRepositoryLocation;
+import org.eclipse.team.core.TeamException;
+
+/**
+ * Whereas the RemoteFolder class provides access to a remote hierarchy using
+ * lazy retrieval via <code>getMembers()</code>, the RemoteFolderTree will force
+ * a recursive retrieval of the remote hierarchy in one round trip.
+ */
+public class RemoteFolderTree extends RemoteFolder {
+
+ public RemoteFolderTree(RemoteFolder parent, ICVSRepositoryLocation repository, IPath repositoryRelativePath, CVSTag tag) {
+ super(parent, repository, repositoryRelativePath, tag);
+ }
+
+ /*
+ * Override of inherited method which persists the children
+ */
+ public ICVSRemoteResource[] getMembers(CVSTag tagName, IProgressMonitor monitor) throws TeamException {
+ if (getChildren() == null)
+ setChildren(super.getMembers(tagName, monitor));
+ return getChildren();
+ }
+
+ /*
+ * This method is public to allow access by the RemoteFolderTreeBuilder utility class.
+ * No other external classes should use this method.
+ */
+ public void setChildren(ICVSRemoteResource[] children) {
+ super.setChildren(children);
+ }
+}
+
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/RemoteResource.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/RemoteResource.java index 26af4fe3f..1caa76473 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/RemoteResource.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/RemoteResource.java @@ -1,139 +1,130 @@ -package org.eclipse.team.internal.ccvs.core.resources; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.io.InputStream; -import java.io.PrintStream; -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.PlatformObject; -import org.eclipse.team.ccvs.core.CVSProviderPlugin; -import org.eclipse.team.ccvs.core.ICVSRemoteResource; -import org.eclipse.team.ccvs.core.ICVSRepositoryLocation; -import org.eclipse.team.core.TeamException; -import org.eclipse.team.core.sync.IRemoteResource; -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.Client; -import org.eclipse.team.internal.ccvs.core.Policy; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFolder; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedResource; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedVisitor; - -/** - * The purpose of this class and its subclasses is to implement the corresponding - * ICVSRemoteResource interfaces for the purpose of communicating information about - * resources that reside in a CVS repository but have not necessarily been loaded - * locally. - */ -public abstract class RemoteResource extends PlatformObject implements ICVSRemoteResource, IManagedResource { - - protected String name; - protected String tag; - - protected RemoteResource(String name, String tag) { - this.name = name; - this.tag = tag; - } - - /** - * @see ICVSRemoteResource#getName() - */ - public String getName() { - return name; - } - - /* - * Get the local options for including a tag in a CVS command - */ - protected List getLocalOptionsForTag() { - List localOptions = new ArrayList(); - if ((tag != null) && (!tag.equals("HEAD"))) { - localOptions.add(Client.TAG_OPTION); - localOptions.add(tag); - } - return localOptions; - } - - public abstract String getRemotePath(); - - public abstract ICVSRepositoryLocation getRepository(); - - /* - * @see IManagedResource#delete() - */ - public void delete() { - // XXX we should know how to delete a remote? - } - - /* - * @see IManagedResource#exists() - */ - public boolean exists() { - // XXX perform silent checkout to test if this remote handle actually has a corresponding remote - // resource - return true; - } - - /* - * @see IManagedResource#getParent() - */ - public IManagedFolder getParent() { - throw new UnsupportedOperationException(Policy.bind("RemoteManagedResource.invalidOperation")); - } - - /* - * @see IManagedResource#isIgnored() - */ - public boolean isIgnored() throws CVSException { - return false; - } - - /* - * @see IManagedResource#isManaged() - */ - public boolean isManaged() throws CVSException { - return true; - } - - /* - * @see IManagedResource#unmanage() - */ - public void unmanage() throws CVSException { - throw new CVSException(Policy.bind("RemoteManagedResource.invalidOperation")); - } - - protected PrintStream getPrintStream() { - return CVSProviderPlugin.getProvider().getPrintStream(); - } - - /* - * @see IManagedResource#showDirty() - */ - public boolean showDirty() throws CVSException { - return false; - } - - /* - * @see IManagedResource#clearDirty(boolean) - */ - public void clearDirty(boolean up) throws CVSException { - } - - /* - * @see IManagedResource#showManaged() - */ - public boolean showManaged() throws CVSException { - return true; - } - - /* - * @see IManagedResource#clearManaged() - */ - public void clearManaged() throws CVSException { - } +package org.eclipse.team.internal.ccvs.core.resources;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.io.PrintStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.PlatformObject;
+import org.eclipse.team.ccvs.core.CVSProviderPlugin;
+import org.eclipse.team.ccvs.core.CVSTag;
+import org.eclipse.team.ccvs.core.ICVSRemoteResource;
+import org.eclipse.team.ccvs.core.ICVSRepositoryLocation;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.Client;
+import org.eclipse.team.internal.ccvs.core.Policy;
+import org.eclipse.team.internal.ccvs.core.util.Assert;
+
+/**
+ * The purpose of this class and its subclasses is to implement the corresponding
+ * ICVSRemoteResource interfaces for the purpose of communicating information about
+ * resources that reside in a CVS repository but have not necessarily been loaded
+ * locally.
+ */
+public abstract class RemoteResource extends PlatformObject implements ICVSRemoteResource, ICVSResource {
+
+ protected ResourceSyncInfo info;
+ protected RemoteFolder parent;
+
+ protected RemoteResource(RemoteFolder parent, String name, CVSTag tag, boolean isFolder) {
+ info = new ResourceSyncInfo(name, isFolder);
+ info.setTag(tag);
+ this.parent = parent;
+ }
+
+ /**
+ * @see ICVSRemoteResource#getName()
+ */
+ public String getName() {
+ return info.getName();
+ }
+
+ /**
+ * @see ICVSRemoteResource#getParent()
+ */
+ public ICVSRemoteResource getRemoteParent() {
+ return parent;
+ }
+
+ /*
+ * Get the local options for including a tag in a CVS command
+ */
+ protected List getLocalOptionsForTag() {
+ List localOptions = new ArrayList();
+ CVSTag tag = info.getTag();
+ if ((tag != null) && (tag.getType() != tag.HEAD)) {
+ localOptions.add(Client.TAG_OPTION);
+ localOptions.add(tag.getName());
+ }
+ return localOptions;
+ }
+
+ public abstract String getRemotePath();
+
+ public abstract ICVSRepositoryLocation getRepository();
+
+ /*
+ * @see ICVSResource#delete()
+ */
+ public void delete() {
+ // XXX we should know how to delete a remote?
+ }
+
+ /*
+ * @see ICVSResource#exists()
+ */
+ public boolean exists() {
+ // XXX perform silent checkout to test if this remote handle actually has a corresponding remote
+ // resource
+ return true;
+ }
+
+ /*
+ * @see ICVSResource#getParent()
+ */
+ public ICVSFolder getParent() {
+ throw new UnsupportedOperationException(Policy.bind("RemoteManagedResource.invalidOperation"));
+ }
+
+ /*
+ * @see ICVSResource#isIgnored()
+ */
+ public boolean isIgnored() throws CVSException {
+ return false;
+ }
+
+ /*
+ * @see ICVSResource#isManaged()
+ */
+ public boolean isManaged() throws CVSException {
+ return true;
+ }
+
+ /*
+ * @see ICVSResource#unmanage()
+ */
+ public void unmanage() throws CVSException {
+ throw new CVSException(Policy.bind("RemoteManagedResource.invalidOperation"));
+ }
+
+ protected PrintStream getPrintStream() {
+ return CVSProviderPlugin.getProvider().getPrintStream();
+ }
+
+ /*
+ * @see ICVSResource#getSyncInfo()
+ */
+ public ResourceSyncInfo getSyncInfo() {
+ return info;
+ }
+ /*
+ * @see ICVSResource#setSyncInfo(ResourceSyncInfo)
+ */
+ public void setSyncInfo(ResourceSyncInfo info) {
+ //this.info = info;
+ }
}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/ResourceFactory.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/ResourceFactory.java deleted file mode 100644 index 1210b0e0d..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/ResourceFactory.java +++ /dev/null @@ -1,185 +0,0 @@ -package org.eclipse.team.internal.ccvs.core.resources;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved.
- */
-
-import java.io.File;
-
-import org.eclipse.team.internal.ccvs.core.CVSException;
-import org.eclipse.team.internal.ccvs.core.resources.api.CVSFileNotFoundException;
-import org.eclipse.team.internal.ccvs.core.resources.api.ICVSFile;
-import org.eclipse.team.internal.ccvs.core.resources.api.ICVSFolder;
-import org.eclipse.team.internal.ccvs.core.resources.api.ICVSResource;
-import org.eclipse.team.internal.ccvs.core.resources.CVSFile;
-import org.eclipse.team.internal.ccvs.core.resources.CVSFolder;
-import org.eclipse.team.internal.ccvs.core.resources.CVSResource;
-import org.eclipse.team.internal.ccvs.core.resources.ManagedFile;
-import org.eclipse.team.internal.ccvs.core.resources.ManagedFolder;
-import org.eclipse.team.internal.ccvs.core.resources.ManagedResource;
-import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFile;
-import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFolder;
-import org.eclipse.team.internal.ccvs.core.resources.api.IManagedResource;
-import org.eclipse.team.internal.ccvs.core.*;
-
-/**
- * This class is the way to access the current implementations of
- * ICVSResources and IMangedResources.
- *
- * All methods with the word "Temp" in it, get a resource that is
- * relative to a tempFolder rather then the root of the system.
- */
-public class ResourceFactory {
-
- public static final File TEMP_ROOT = new File("C:\\temp");
-
- public static String getPath(File ioFile) {
- return ioFile.getAbsolutePath();
- }
-
- public static String getPath(ICVSResource cvsResource) {
- return getIO(cvsResource).getAbsolutePath();
- }
-
- public static String getPath(IManagedFolder managedResource) {
- return getIO(managedResource).getAbsolutePath();
- }
-
- public static File getIO(ICVSResource cvsResource) throws ClassCastException {
- return ((CVSResource) cvsResource).getIOResource();
- }
-
- public static File getIO(IManagedResource managedResource) throws ClassCastException {
- return getIO(getCvs(managedResource));
- }
-
- public static File getTempIO(String path) {
- return new File(TEMP_ROOT,path);
- }
-
- public static File getIO(String path) {
- return new File(path);
- }
-
- public static ICVSResource getCvs(IManagedResource managedResource) throws ClassCastException {
- return ((ManagedResource) managedResource).getCVSResource();
- }
-
- public static ICVSFolder getCvs(IManagedFolder managedFolder) throws ClassCastException {
- return (ICVSFolder)((ManagedFolder) managedFolder).getCVSResource();
- }
-
- public static ICVSFile getCvs(IManagedFile managedFile) throws ClassCastException {
- return (ICVSFile)((ManagedFile) managedFile).getCVSResource();
- }
-
- public static ICVSResource getCvs(File ioFile) throws CVSException {
-
- if (!ioFile.exists()) {
- throw new CVSFileNotFoundException("File not Found " + ioFile);
- }
-
- if (ioFile.isDirectory()) {
- return CVSFolder.createFolderFrom(ioFile);
- } else if (ioFile.isFile()) {
- return CVSFile.createFileFrom(ioFile);
- } else {
- throw new CVSException("Unexpected error in ResourceFactory");
- }
- }
-
- public static ICVSResource getCvs(String path) throws CVSException {
- return getCvs(getIO(path));
- }
-
- public static ICVSResource getTempCvs(String path) throws CVSException {
- return getCvs(getTempIO(path));
- }
-
- public static ICVSFolder getCvsFolder(File ioFile) throws CVSException {
- return CVSFolder.createFolderFrom(ioFile);
- }
-
- public static ICVSFolder getCvsFolder(String path) throws CVSException {
- return getCvsFolder(getIO(path));
- }
-
- public static ICVSFolder getTempCvsFolder(String path) throws CVSException {
- return getCvsFolder(getTempIO(path));
- }
-
- public static ICVSFolder getCvsFolder(IManagedFolder managedFolder) throws CVSException {
- return getCvs(managedFolder);
- }
-
- public static ICVSFile getCvsFile(String path) throws CVSException {
- return getCvsFile(getIO(path));
- }
-
- public static ICVSFile getTempCvsFile(String path) throws CVSException {
- return getCvsFile(getTempIO(path));
- }
-
- public static ICVSFile getCvsFile(File ioFile) throws CVSException {
- return CVSFile.createFileFrom(ioFile);
- }
-
- public static ICVSFile getCvsFile(IManagedFile managedFile) throws CVSException {
- return getCvs(managedFile);
- }
-
- public static IManagedFolder getManaged(ICVSFolder cvsFolder) {
- return ManagedFolder.createResourceFrom(cvsFolder);
- }
-
- public static IManagedFile getManaged(ICVSFile cvsFile) {
- return ManagedFolder.createResourceFrom(cvsFile);
- }
-
- public static IManagedResource getManaged(ICVSResource cvsResource) {
- if (cvsResource.isFolder()) {
- return getManaged((ICVSFolder)cvsResource);
- } else {
- return getManaged((ICVSFile)cvsResource);
- }
- }
-
- public static IManagedResource getManaged(File file) throws CVSException {
- return getManaged(getCvs(file));
- }
-
- public static IManagedFolder getManagedFolder(File ioFile) throws CVSException {
- return getManaged(getCvsFolder(ioFile));
- }
-
- public static IManagedFolder getManagedFolder(String path) throws CVSException {
- return getManagedFolder(getIO(path));
- }
-
- public static IManagedFolder getTempManagedFolder(String path) throws CVSException {
- return getManagedFolder(getTempIO(path));
- }
-
- public static IManagedFolder getManagedFolder(ICVSFolder cvsFolder) throws CVSException {
- return getManaged(cvsFolder);
- }
-
- public static IManagedFile getManagedFile(File ioFile) throws CVSException {
- return getManaged(getCvsFile(ioFile));
- }
-
- public static IManagedFile getTempManagedFile(String path) throws CVSException {
- return getManagedFile(getTempIO(path));
- }
-
- public static IManagedFile getManagedFile(String path) throws CVSException {
- return getManagedFile(getIO(path));
- }
-
- public static IManagedFile getManagedFile(ICVSFile cvsFile) throws CVSException {
- return getManaged(cvsFile);
- }
-
-}
-
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/ResourceSyncInfo.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/ResourceSyncInfo.java new file mode 100644 index 000000000..966d77ec0 --- /dev/null +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/ResourceSyncInfo.java @@ -0,0 +1,269 @@ +package org.eclipse.team.internal.ccvs.core.resources;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.team.ccvs.core.CVSTag;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.util.Assert;
+import org.eclipse.team.internal.ccvs.core.util.EmptyTokenizer;
+
+public class ResourceSyncInfo {
+
+ private boolean isDirectory = false;
+
+ private static final String DIRECTORY_PREFIX = "D/";
+ public static final String BINARY_TAG = "-kb";
+ private static final String SEPERATOR = "/";
+
+ private static final String DEFAULT_PERMISSIONS = "u=rw,g=rw,o=r";
+
+ private int type;
+ private String name;
+ private String revision;
+ private String timeStamp;
+ private String keywordMode;
+ private CVSEntryLineTag tag;
+ private String permissions;
+
+ public ResourceSyncInfo(String entryLine, String permissions) throws CVSException {
+ setEntryLine(entryLine);
+ if (permissions != null)
+ setPermissions(permissions);
+ }
+
+ public ResourceSyncInfo(String name, boolean isDirectory) {
+ Assert.isNotNull(name);
+ this.name = name;
+ this.isDirectory = isDirectory;
+ }
+
+ public boolean isDirectory() {
+ return isDirectory;
+ }
+
+ /**
+ * Cosntruct a CVS compatible entry line
+ * that can be stored on disk.
+ * @return null if the entry line was not set or set to null
+ */
+ public String getEntryLine(boolean includeTimeStamp) {
+
+ if(name == null) {
+ return null;
+ }
+
+ StringBuffer result = new StringBuffer();
+
+ if(isDirectory) {
+ result.append(DIRECTORY_PREFIX);
+ result.append(name + "////");
+ } else {
+ result.append(SEPERATOR);
+ result.append(name);
+ result.append(SEPERATOR);
+ result.append(revision);
+ result.append(SEPERATOR);
+ // in some cases the timestamp not include in entry lines
+ if(includeTimeStamp) {
+ result.append(timeStamp);
+ }
+ result.append(SEPERATOR);
+ result.append(keywordMode);
+ result.append(SEPERATOR);
+ if (tag != null) {
+ result.append(tag.toEntryLineFormat());
+ }
+ }
+
+ return result.toString();
+ }
+
+ public String getPermissionLine() {
+ if(isDirectory) {
+ return null;
+ } else {
+ return SEPERATOR + name + SEPERATOR + permissions;
+ }
+ }
+
+ /**
+ * Set the entry line
+ * @throws CVSException if the entryLine is malformed
+ */
+ public void setEntryLine(String entryLine) throws CVSException {
+
+ Assert.isTrue(entryLine!=null);
+
+// if (entryLine == null) {
+// name = revision = timeStamp = tag = keywordMode = null;
+// return;
+// }
+
+ //Assert.isLegal(entryLine.startsWith(seperator) &&
+ // tokenizer.countTokens() == 5,
+ // Policy.bind("FileProperties.invalidEntryLine"));
+
+ if(entryLine.startsWith(DIRECTORY_PREFIX)) {
+ isDirectory = true;
+ entryLine = entryLine.substring(1);
+ } else {
+ isDirectory = false;
+ }
+
+ EmptyTokenizer tokenizer = new EmptyTokenizer(entryLine,SEPERATOR);
+
+ name = tokenizer.nextToken();
+ revision = tokenizer.nextToken();
+ timeStamp = tokenizer.nextToken();
+ keywordMode = tokenizer.nextToken();
+ String tagEntry = tokenizer.nextToken();
+ if(tagEntry.length()>0) {
+ tag = new CVSEntryLineTag(tagEntry);
+ }
+ }
+
+ /**
+ * Gets the permissions
+ * @return Returns a String
+ */
+ public String getPermissions() {
+ return permissions;
+
+ }
+
+ /**
+ * Sets the permissions
+ *
+ * /foo.java/u=rw,g=rw,o=rw
+ *
+ * @param permissions The permissions to set
+ */
+ public void setPermissionLine(String permissionLine) throws CVSException {
+
+ if (permissionLine == null) {
+ permissions = DEFAULT_PERMISSIONS;
+ return;
+ }
+
+ EmptyTokenizer tokenizer;
+ tokenizer = new EmptyTokenizer(permissionLine,SEPERATOR);
+ String filename = tokenizer.nextToken();
+ permissions = tokenizer.nextToken();
+ }
+
+ /**
+ * u=rw,g=rw,o=rw
+ */
+ public void setPermissions(String permissions) {
+ this.permissions = permissions;
+ }
+
+ /**
+ * Gets the tag
+ * @return Returns a String
+ */
+ public CVSTag getTag() {
+ return tag;
+ }
+ /**
+ * Sets the tag for the resource. The provided tag must not be null.
+ * @param tag The tag to set
+ */
+ public void setTag(CVSTag tag) {
+ if(tag!=null) {
+ this.tag = new CVSEntryLineTag(tag);
+ } else {
+ this.tag = null;
+ }
+ }
+
+ /**
+ * Gets the timeStamp
+ * @return Returns a String usually in the format
+ "Thu Oct 18 20:21:13 2001"
+ */
+ public String getTimeStamp() {
+ return timeStamp;
+ }
+ /**
+ * Sets the timeStamp
+ *
+ * @param timeStamp The timeStamp to set
+ * has the format "Thu Oct 18 20:21:13 2001" otherwise
+ * isDirty is allways true
+ */
+ public void setTimeStamp(String timeStamp) {
+ this.timeStamp = timeStamp;
+ }
+
+ /**
+ * Gets the version
+ * @return Returns a String
+ */
+ public String getRevision() {
+ return revision;
+ }
+ /**
+ * Sets the version
+ * @param version the version to set
+ */
+ public void setRevision(String version) {
+ this.revision = version;
+ }
+
+ /**
+ * Gets the name
+ * @return Returns a String
+ */
+ public String getName() {
+ return name;
+ }
+ /**
+ * Sets the name
+ * @param name The name to set
+ */
+ public void setName(String name) {
+ Assert.isTrue(name!=null);
+ this.name = name;
+ }
+
+ /**
+ * Gets the keyword mode
+ * @return Returns a String
+ */
+ public String getKeywordMode() {
+ return keywordMode;
+ }
+
+ /**
+ * Sets the keyword mode
+ * @param keywordMode The keyword expansion mode (-kb, -ko, etc.)
+ */
+ public void setKeywordMode(String keywordMode) {
+ this.keywordMode = keywordMode;
+ }
+
+ public boolean equals(Object other) {
+ if(other instanceof ResourceSyncInfo) {
+
+ ResourceSyncInfo syncInfo = ((ResourceSyncInfo)other);
+
+ // We have to avoid Null-Pointer-Exceptions, other and this are not null
+ // for sure the rest has to be checked
+ if(other == this) return true;
+ if(getName() == syncInfo.getName()) return true;
+ if ((getName()==null) != (syncInfo.getName()==null)) return false;
+ return getName().equals(syncInfo.getName());
+
+ } else {
+ return false;
+ }
+ }
+
+ public int hashCode() {
+ return getName().hashCode();
+ }
+}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/Synchronizer.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/Synchronizer.java new file mode 100644 index 000000000..1fbd3a43c --- /dev/null +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/Synchronizer.java @@ -0,0 +1,104 @@ +package org.eclipse.team.internal.ccvs.core.resources;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.util.Assert;
+import org.eclipse.team.internal.ccvs.core.util.SyncFileUtil;
+import sun.rmi.transport.Utils;
+
+/**
+ * A singleton that provides access to CVS specific information about local CVS
+ * resources.
+ */
+public class Synchronizer {
+
+ private static Synchronizer instance;
+
+ private Synchronizer() {
+ }
+
+ public static Synchronizer getInstance() {
+ if(instance==null) {
+ instance = new Synchronizer();
+ }
+ return instance;
+ }
+
+ public ResourceSyncInfo getSyncInfo(File file) throws CVSException {
+ ResourceSyncInfo[] infos = SyncFileUtil.readEntriesFile(file.getParentFile());
+ for (int i = 0; i < infos.length; i++) {
+ if(infos[i].getName().equals(file.getName())) {
+ return infos[i];
+ }
+ }
+ return null;
+ }
+
+ public void setSyncInfo(File file, ResourceSyncInfo info) throws CVSException {
+ List infos = new ArrayList();
+ infos.addAll(Arrays.asList(SyncFileUtil.readEntriesFile(file.getParentFile())));
+ infos.remove(info);
+ infos.add(info);
+
+ SyncFileUtil.writeEntriesFile(file.getParentFile(), (ResourceSyncInfo[]) infos.toArray(new ResourceSyncInfo[infos.size()]));
+ }
+
+ public void flushSyncInfo(File file, int depth) throws CVSException {
+
+ ResourceSyncInfo[] infos = SyncFileUtil.readEntriesFile(file.getParentFile());
+ // If the length of infos is 0, the parent is not a managed folder so we don't
+ // need to do anything unless we actually perform the deep operation.
+ if (infos.length > 0) {
+ List result = new ArrayList(infos.length - 1);
+
+ for (int i = 0; i < infos.length; i++) {
+ if (!infos[i].getName().equals(file.getName())) {
+ result.add(infos[i]);
+ } + }
+
+ SyncFileUtil.writeEntriesFile(file.getParentFile(), (ResourceSyncInfo[]) result.toArray(new ResourceSyncInfo[result.size()]));
+ }
+ }
+
+ public FolderSyncInfo getFolderSyncInfo(File file) throws CVSException {
+ if(file.isDirectory()) {
+ return SyncFileUtil.readFolderConfig(file);
+ } else {
+ return null;
+ }
+ }
+
+ public void setFolderSyncInfo(File file, FolderSyncInfo info) throws CVSException {
+ Assert.isTrue(file.isDirectory());
+
+ // if parent has the sync folder (e.g. CVS) then ensure that the directory
+ // entry for this folder is added.
+ if(SyncFileUtil.getCVSSubdirectory(file.getParentFile()).exists()) {
+ ResourceSyncInfo resourceInfo = new ResourceSyncInfo(file.getName(), true);
+ setSyncInfo(file, resourceInfo);
+ }
+ SyncFileUtil.writeFolderConfig(file, info);
+ }
+
+ public void refreshFromLocal(File file, int depth, IProgressMonitor progress) throws CVSException {
+ }
+
+ public ResourceSyncInfo[] members(File file) throws CVSException {
+ if(file.isDirectory()) {
+ return SyncFileUtil.readEntriesFile(file);
+ } else {
+ return new ResourceSyncInfo[0];
+ }
+ }
+}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/api/CVSFileNotFoundException.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/api/CVSFileNotFoundException.java deleted file mode 100644 index 2a9b1be8b..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/api/CVSFileNotFoundException.java +++ /dev/null @@ -1,81 +0,0 @@ -package org.eclipse.team.internal.ccvs.core.resources.api;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved.
- */
-
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.team.internal.ccvs.core.CVSException;
-import org.eclipse.team.internal.ccvs.core.connection.ResourceStatus;
-import org.eclipse.team.ccvs.core.CVSProviderPlugin;
-
-/**
- * This exception represents the attemp to access a file/folder
- * that did not exist.
- */
-public class CVSFileNotFoundException extends CVSException {
-
- public CVSFileNotFoundException(
- int severity,
- int code,
- IPath path,
- String message,
- Throwable exception) {
- super(new ResourceStatus(severity, code, path, message, exception));
- }
- public CVSFileNotFoundException(
- int severity,
- int code,
- IPath path,
- String message) {
- this(severity, code, path, message, null);
- }
- public CVSFileNotFoundException(
- int severity,
- int code,
- IPath path,
- Throwable exception) {
- this(severity, code, path, null, exception);
- }
- public CVSFileNotFoundException(
- int severity,
- int code,
- String message,
- Exception e) {
- super(new Status(severity, CVSProviderPlugin.ID, code, message, null));
- }
- public CVSFileNotFoundException(
- int severity,
- int code,
- String message) {
- this(severity, code, message, null);
- }
-
- public CVSFileNotFoundException(
- int severity,
- int code,
- Exception e) {
- super(new Status(severity, CVSProviderPlugin.ID, code, null, e));
-
- }
-
- public CVSFileNotFoundException(String message) {
- super(new Status(IStatus.ERROR, CVSProviderPlugin.ID, IStatus.ERROR, message, null));
- }
-
- public CVSFileNotFoundException(String message, IPath path) {
- this(message, path, null);
- }
-
- public CVSFileNotFoundException(String message, IPath path, Throwable throwable) {
- this(new ResourceStatus(IStatus.ERROR, path, message, throwable));
- }
- public CVSFileNotFoundException(IStatus status) {
- super(status);
- }
-
-}
-
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/api/CVSProperties.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/api/CVSProperties.java deleted file mode 100644 index bc9711a52..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/api/CVSProperties.java +++ /dev/null @@ -1,79 +0,0 @@ -package org.eclipse.team.internal.ccvs.core.resources.api; - -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - -import org.eclipse.team.internal.ccvs.core.Policy; -import org.eclipse.team.internal.ccvs.core.util.Assert; - -/** - * The CVSProperties are a way to store Properties about a file - * or a folder. The CVSProperties have a predefined and not - * changing set of keys (you can not set on a key that is not - * predefined).<br> - * This class is for overloading, also it could be instanceated. - */ -public class CVSProperties { - - private Map properties = new HashMap(); - - /** - * @param supportedKeys the set of predefined keys - * to be set by a subclass - */ - public CVSProperties(String[] supportedKeys) { - for (int i=0; i<supportedKeys.length; i++) { - properties.put(supportedKeys[i],null); - } - } - - /** - * Get the property with the name key. - * - * @throws IllegalArgumentException if key is not in - * supportedKeys - */ - public String getProperty(String key) { - - Assert.isLegal(properties.containsKey(key), - Policy.bind("CVSProperties.IllegalKey")); - - return (String) properties.get(key); - } - - /** - * Set the value of the property key. - * @throws IllegalArgumentException if key is not in - * supportedKeys - */ - public String putProperty(String key, String value) throws - IllegalArgumentException { - - Assert.isLegal(properties.containsKey(key), - Policy.bind("CVSProperties.IllegalKey")); - - return (String) properties.put(key,value); - } - - /** - * Gives all supported keys as a Set. - */ - public Set keySet() { - return properties.keySet(); - } - - /** - * CVSProperties are equal, when keys and values are equal. - */ - public boolean equals(Object o) { - if (o == this) { - return true; - } else if (!(o instanceof CVSProperties)) { - return false; - } else { - return properties.equals(((CVSProperties)o).properties); - } - } -} - diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/api/FileProperties.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/api/FileProperties.java deleted file mode 100644 index a1925b6d8..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/api/FileProperties.java +++ /dev/null @@ -1,287 +0,0 @@ -package org.eclipse.team.internal.ccvs.core.resources.api;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved.
- */
-
-import java.util.Set;
-
-import org.eclipse.team.internal.ccvs.core.CVSException;
-import org.eclipse.team.internal.ccvs.core.Policy;
-import org.eclipse.team.internal.ccvs.core.util.Assert;
-import org.eclipse.team.internal.ccvs.core.util.EmptyTokenizer;
-
-/**
- * A FileProperties bundles all the CVS information stored on disk
- * about a file such as the name, revision, sever timestamp, etc.
- * It does not contain information about the physical file in the local file system.
- */
-public class FileProperties extends CVSProperties {
-
- private String name;
-
- private String version;
- private String timeStamp;
- private String keywordMode;
- private String tag;
-
- public static final String BINARY_TAG = "-kb";
-
- public static final String ENTRIES = "Entries";
- public static final String PERMISSIONS = "Permissions";
- public static final String seperator = "/";
-
- /**
- * Construct the FileProperties
- */
- public FileProperties() {
- super(new String[]{ENTRIES,PERMISSIONS});
- }
-
- /**
- * Construct the FileProperties
- */
- public FileProperties(String entryLine, String permissions) throws CVSException {
- this();
- setEntryLine(entryLine);
- setPermissions(permissions);
- }
-
- /**
- * Cosntruct a CVS compatible entry line
- * that can be stored on disk.
- * @return null if the entry line was not set or set to null
- */
- public String getEntryLine() {
-
- if (name == null) {
- return null;
- }
-
- StringBuffer result = new StringBuffer();
-
- result.append(seperator);
- result.append(name);
- result.append(seperator);
- result.append(version);
- result.append(seperator);
- result.append(timeStamp);
- result.append(seperator);
- result.append(keywordMode);
- result.append(seperator);
- result.append(tag);
-
- return result.toString();
- }
-
- /**
- * Cosntruct an entry line for the client that can be sent to the server.
- * For this the timestamp is not included.
- * @return null if the entry line was not set or set to null
- */
- public String getEntryLineForServer() {
-
- if (name == null) {
- return null;
- }
-
- StringBuffer result = new StringBuffer();
-
- result.append(seperator);
- result.append(name);
- result.append(seperator);
- result.append(version);
- result.append(seperator);
- result.append(seperator);
- result.append(keywordMode);
- result.append(seperator);
- result.append(tag);
-
- return result.toString();
- }
-
- /**
- * Set the entry line
- * @throws CVSException if the entryLine is malformed
- */
- public void setEntryLine(String entryLine) throws
- IllegalArgumentException {
-
- EmptyTokenizer tokenizer;
-
- if (entryLine == null) {
- name = null;
- return;
- }
-
- tokenizer = new EmptyTokenizer(entryLine,seperator);
-
- Assert.isLegal(entryLine.startsWith(seperator) &&
- tokenizer.countTokens() == 5,
- Policy.bind("FileProperties.invalidEntryLine"));
-
- name = tokenizer.nextToken();
- version = tokenizer.nextToken();
- timeStamp = tokenizer.nextToken();
- keywordMode = tokenizer.nextToken();
- tag = tokenizer.nextToken();
- }
-
- /**
- * Gets the permissions
- * @return Returns a String
- */
- public String getPermissions() {
- return getProperty(PERMISSIONS);
-
- }
- /**
- * Sets the permissions
- * @param permissions The permissions to set
- */
- public void setPermissions(String permissions) {
- putProperty(PERMISSIONS,permissions);
- }
-
- /**
- * Gets the tag
- * @return Returns a String
- */
- public String getTag() {
- return tag;
- }
- /**
- * Sets the tag
- * @param tag The tag to set
- */
- public void setTag(String tag) {
- this.tag = tag;
- }
-
- /**
- * Gets the timeStamp
- * @return Returns a String usually in the format
- "Thu Oct 18 20:21:13 2001"
- */
- public String getTimeStamp() {
- return timeStamp;
- }
- /**
- * Sets the timeStamp
- *
- * @param timeStamp The timeStamp to set
- has the format "Thu Oct 18 20:21:13 2001" otherwise
- isDirty is allways true
- */
- public void setTimeStamp(String timeStamp) {
- this.timeStamp = timeStamp;
- }
-
-
- /**
- * Gets the version
- * @return Returns a String
- */
- public String getVersion() {
- return version;
- }
- /**
- * Sets the version
- * @param version the version to set
- */
- public void setVersion(String version) {
- this.version = version;
- }
-
- /**
- * Gets the name
- * @return Returns a String
- */
- public String getName() {
- return name;
- }
- /**
- * Sets the name
- * @param name The name to set
- */
- public void setName(String name) {
- this.name = name;
- }
-
- /**
- * Gets the keyword mode
- * @return Returns a String
- */
- public String getKeywordMode() {
- return keywordMode;
- }
-
- /**
- * Sets the keyword mode
- * @param keywordMode The keyword expansion mode (-kb, -ko, etc.)
- */
- public void setKeywordMode(String keywordMode) {
- this.keywordMode = keywordMode;
- }
-
- /**
- * Special handling for the entries added.
- * @see CVSProperties#getProperty(String)
- */
- public String getProperty(String key) {
-
- String data;
-
- if (ENTRIES.equals(key)) {
-
- return getEntryLine();
-
- } else {
- data = super.getProperty(key);
-
- if (data == null) {
- return null;
- }
-
- if (data.substring(0,1).equals(seperator)) {
- data = data.substring(data.indexOf(seperator,1)+1);
- }
- return data;
- }
- }
-
- /**
- * Special handling for the entries added.
- * @see CVSProperties#putProperty(String,String)
- */
- public String putProperty(String key, String value)
- throws IllegalArgumentException {
-
- if (ENTRIES.equals(key)) {
- setEntryLine(value);
- return value;
- } else {
- return super.putProperty(key,value);
- }
- }
-
- /**
- * Put the entries into the entries-properties. This is
- * done before equals.
- */
- private void putEntries() {
- super.putProperty(ENTRIES,getEntryLine());
- }
-
- public boolean equals(Object o) {
-
- if (o instanceof FileProperties) {
- putEntries();
- ((FileProperties)o).putEntries();
- }
-
- return super.equals(o);
- }
-}
-
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/api/FolderProperties.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/api/FolderProperties.java deleted file mode 100644 index 18e1e13a6..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/api/FolderProperties.java +++ /dev/null @@ -1,130 +0,0 @@ -package org.eclipse.team.internal.ccvs.core.resources.api; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.Policy; - -/** - * FolderProperties bundels the informations about a folder that - * are needed for the cvsClient. - * It cares about loading saving this information - * in the folder the container belongs to. - */ -public class FolderProperties extends CVSProperties { - - public static final String REPOSITORY = "Repository"; - public static final String ROOT = "Root"; - public static final String STATIC = "Entries.Static"; - public static final String TAG = "Tag"; - public static final String seperator = "/"; - - public FolderProperties() { - super(new String[]{REPOSITORY,ROOT,STATIC,TAG}); - } - - /** - * Create a new FolderProperties and load the information of the cvsFolder - * into it. - * Does not save the cvsFolder in any way. - */ - public FolderProperties(String root, String repository, boolean staticFolder) { - this(); - setRoot(root); - setRepository(repository); - setStaticFolder(staticFolder); - } - - /** - * Gets the repolsitory e.g. "proj1/folder1" - * @return Returns a String - */ - public String getRepository() { - return getProperty(REPOSITORY); - } - /** - * Sets the repolsitory - * @param repolsitory e.g. "proj1/folder1" - * @throws CVSException on wrong parameter - */ - public void setRepository(String repository) { - - putProperty(REPOSITORY,repository); - } - - /** - * Gets the root e.g. ":pserver:nkrambro@fiji:/home/nkrambro/repo" - * @return Returns a String - */ - public String getRoot() { - return getProperty(ROOT); - } - /** - * Sets the root - * @param the Root of the Folder e.g. ":pserver:nkrambro@fiji:/home/nkrambro/repo" - * @throws CVSException on wrong parameter - */ - public void setRoot(String root) { - putProperty(ROOT,root); - } - - /** - * Returns the Location of the folder on the server constructed - * using the root and repository. - * - * For example, if the <code>root</code> is ":pserver:username@host:/cvs/root" - * and the <code>repository</code> is "proj1/folder1" then <code>getRemoteLocation()</code> - * returns "/cvs/root/proj1/folder1". - */ - public String getRemoteLocation() throws CVSException { - - String rootFolder; - int start = getRoot().lastIndexOf(":"); - if (start == -1) - throw new CVSException(Policy.bind("FolderProperties.invalidRoot", new Object[] {getRoot()})); - rootFolder = getRoot().substring(start + 1); - - return rootFolder + seperator + getRepository(); - } - - /** - * Gets wheter the folder is static - * @return Returns a boolean - */ - public boolean getStaticFolder() { - return getProperty(STATIC) != null; - } - - /** - * Sets wheter the folder is static - * @param staticFolder The staticFolder to set - */ - public void setStaticFolder(boolean staticFolder) { - if (staticFolder) { - putProperty(STATIC,""); - } else { - putProperty(STATIC,null); - } - } - - /** - * Gets the tag e.g. "TmyVersion" - * @return Returns a String - */ - public String getTag() { - return getProperty(TAG); - } - /** - * Sets the tag - * @param repolsitory e.g. "TmyVersion" - */ - public void setTag(String tag) { - - putProperty(TAG,tag); - } - -} - diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/api/ICVSFile.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/api/ICVSFile.java deleted file mode 100644 index fb6558c29..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/api/ICVSFile.java +++ /dev/null @@ -1,93 +0,0 @@ -package org.eclipse.team.internal.ccvs.core.resources.api;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved.
- */
-
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.Date;
-
-import org.eclipse.team.internal.ccvs.core.CVSException;
-
-/**
- * Represents an abstract file.
- *
- * @see ICVSResource
- */
-
-public interface ICVSFile extends ICVSResource {
-
- /**
- * Opens the file for reading. Closing the stream
- * is responsibility of the caller.
- *
- * @throws CVSFileNotFoundException if exists() = false
- * @throws CVSException if it was not possible to open the pipe for any other reason
- */
- InputStream getInputStream() throws CVSException;
-
- /**
- * Opens the file for writing. Closing the stream
- * is responsibility of the caller.
- *
- * @throws CVSFileNotFoundException if exists() = false
- * @throws CVSException if it was not possible to open the pipe for any other reason
- */
- OutputStream getOutputStream() throws CVSException;
-
- /**
- * Get the size of a file
- *
- * @return 0 if exists() = false
- */
- long getSize();
-
- /**
- * Get the timpstamp of the file as a date
- *
- * @throws CVSFileNotFoundException if exists() = false
- */
- long getTimeStamp() throws CVSFileNotFoundException;
-
- /**
- * Set the timpstamp of the file as a date
- *
- * @throws CVSFileNotFoundException if exists() = false
- */
- void setTimeStamp(long date) throws CVSFileNotFoundException;
-
- /**
- * Gives the content of the file as a string-array.
- */
- String[] getContent() throws CVSException;
-
- /**
- * Gives the content of the file as a string-array.
- *
- * @param delim is the end of line (e.g. "\n","\n\r")
- */
- // void setContent(String[] content, String delim) throws CVSException;
-
- /**
- * Move the resource to another location. Does overwrite without
- * promting.
- *
- * @throws CVSException if the move was not successful
- */
- void moveTo(ICVSFile file) throws CVSException;
-
- /**
- * Get a temporary cvs-file (it does not yet delete on
- * exit
- */
- // public ICVSFile createTempFile() throws CVSException;
-
- /**
- * Set the file to read-Only mode.
- */
- void setReadOnly();
-}
-
-
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/api/ICVSFolder.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/api/ICVSFolder.java deleted file mode 100644 index 53e30b81a..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/api/ICVSFolder.java +++ /dev/null @@ -1,158 +0,0 @@ -package org.eclipse.team.internal.ccvs.core.resources.api;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved.
- */
-
-import java.io.IOException;
-
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.team.internal.ccvs.core.CVSException;
-
-
-/**
- * Represents an abstract folder.
- *
- * @see ICVSResource
- */
-public interface ICVSFolder extends ICVSResource {
-
- /**
- * Does list the whole content of the folder
- * (files and folders)
- *
- * @throws CVSFileNotFoundException if exists() = false
- */
- public ICVSResource[] getResources() throws CVSException;
-
- /**
- * Gives all the sub-folders of this folder (excluding the
- * cvs-folder)
- *
- * @throws CVSFileNotFoundException if exists() = false
- */
- public ICVSFolder[] getFolders() throws CVSException;
-
- /**
- * Gives all the files in this folder
- *
- * @throws CVSFileNotFoundException if exists() = false
- */
- public ICVSFile[] getFiles() throws CVSException;
-
- /**
- * create a folder as a subfolder of this
- * accepts "/" or "\" to make it a sub-sub folder of the
- * current one. Alle folder on the way, that do not exsist
- * are generated.
- *
- * This is only calling a function in the file-system
- *
- */
- ICVSFolder createFolder(String name) throws CVSException;
-
- /**
- * Does create a file in the given folder. Does not accept
- * any subfolders given in that moment.
- * If the file does exist, returns the file.
- *
- * This is only calling a function in the file-system
- *
- */
- ICVSFile createFile(String name) throws CVSException;
-
- /**
- * Return the child resource at the given path relative to
- * the receiver.
- * This gets a file child of the current folder. It needs to
- * contact the fileSystem to figure out whether we have got
- * an folder or an file.
- * It is decepated, because it should be possible to create
- * non-existend files (and then we need the information whether it
- * is a file or a folder).
- * Use createFile or createFolder intstead. (Check whether it is
- * a folder or a file with childIsFolder)
- *
- * @throws CVSFileNotFoundException if exists() = false
- * @throws CVSFileNotFoundException if childExists(path) = false
- */
- ICVSResource getChild(String path) throws CVSException;
-
- /**
- * Checks wether the child of the currentFolder with the
- * name exists.
- */
- boolean childExists(String name);
-
- /**
- * Checks wether a child is a folder. If the child does not
- * exist then it automatically does return false.
- *
- * @return false if childExists(name) = false
- */
- boolean childIsFolder(String name);
-
- /**
- * Create the folder if it did not exist before. Does only
- * work if the direct subfolder did exist.
- *
- * @throws CVSException if for some reason it was not possible to create the folder
- */
- void mkdir() throws CVSException;
-
- // ---------- Here starts the property handling ----------
- /**
- * This method creats the ability to store properties.
- * It does create the current folder as well, if it did not
- * exist before.
- * At the moment this invokes mkdir, so it craetest the current
- * folder if it was not there before.
- * (This is going to change properbly)
- */
- void makeCVSFolder() throws CVSException;
-
- /**
- * The opposite of makeCVSFolder, delets all the properties of
- * the folder and the ability to store such
- */
- void unmakeCVSFolder();
-
- /**
- * Checks if properties are accessable and if so,
- * whether it has at least the following three properties:
- * root, repolsitory, entries
- *
- * @throws CVSFileNotFoundException if exists() = false
- */
- boolean isCVSFolder() throws CVSFileNotFoundException;
-
- /**
- * Attace a property to the folder.
- *
- * @throws CVSFileNotFoundException if exists() = false
- * @throws NoCVSFolderException if isCVSFolder = false
- */
- void setProperty(String key, String[] content) throws CVSException;
-
- /**
- * Delete a property from a folder. If the property did not exist,
- * nothing happens.
- *
- * @throws CVSFileNotFoundException if exists() = false
- * @throws NoCVSFolderException if isCVSFolder = false
- */
- // void unsetProperty(String key) throws CVSException;
-
- /**
- * Get the property of a folder.
- *
- * @return the contend of the property if the property does exsist, null otherwise
- * @throws CVSFileNotFoundException if exists() = false
- * @throws NoCVSFolderException if isCVSFolder = false
- */
- String[] getProperty(String key) throws CVSException;
-
-}
-
-
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/api/ICVSResource.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/api/ICVSResource.java deleted file mode 100644 index 5e65a5e47..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/api/ICVSResource.java +++ /dev/null @@ -1,81 +0,0 @@ -package org.eclipse.team.internal.ccvs.core.resources.api; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.io.File; - -import org.eclipse.team.internal.ccvs.core.CVSException; - - -/** - * Represents an abstract file or a folder. - * - * This can be a acctual file in the local system, webDev - * or ftp remote-files etc. - * - * The interfaces are to be implemented by the user of the - * cvsclient.core. - * - * The handle to an resource-object (like in java.io) does not nessarily - * mean that the underlying resource exists. The function exists() - * checks that. Many Operations give an CVSFileNotFoundException if the - * file is not there. - */ - -public interface ICVSResource { - - /** - * The seperator that is used for giving and - * reciving pathnames - */ - //MV: This should be in CVSResource, not ICVSResource - public static final String seperator = File.separator; - - /** - * Gives the platform dependend Path of the file back. - * Should be used for monitoring only. - */ - String getPath(); - - /** - * Indicates whether the object is a file or a folder - */ - boolean isFolder(); - - /** - * Delete the resource. - * In case of folder, with all the subfolders and files. - * - * Deleting a non-existing resourec does nothing. - */ - void delete(); - - /** - * Give the folder that contains this resource. - * - * The behavior is unspecified as soon as isCVSFolder() = false - */ - ICVSFolder getParent(); - - /** - * Give the name of the file back - * e.g. "folder1" for "C:\temp\folder1\" - */ - public String getName(); - - /** - * Check if the file exists in the underlying fileSystem - */ - boolean exists(); - - /** - * Clears all the information in the cache, if a cache exists. - */ - void clearCache(boolean deep) throws CVSException ; - -} - - diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/api/IManagedResource.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/api/IManagedResource.java deleted file mode 100644 index d16804735..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/api/IManagedResource.java +++ /dev/null @@ -1,157 +0,0 @@ -package org.eclipse.team.internal.ccvs.core.resources.api; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.team.internal.ccvs.core.CVSException; - -/** - * An managedResource is an interface for an resource the cvs-client - * accepts. It does provide storage of certain properties for every resource. - * - * It also provides a list of resources within every folder, that is - * independend of underlign file-system - */ -public interface IManagedResource { - - /** - * Do we save the properties after every set - * of an info ? (AUTO_SAVE=true <=> no caching) - */ - public static final boolean AUTO_SAVE = true; - - /** - * The seperator that is used for giving and - * receiving pathnames - */ - public static final String separator = "/"; - - /** - * Gives the path from the root folder to this folder. - * - * root.getChild(getRelativePath()).equals(this) - * - * @throws CVSException if getClass() != ancestor.getClass() - * @throws CVSException if ! absolutePathOf(this).startsWith(absolutePathOf(ancestor)) - */ - String getRelativePath(IManagedFolder ancestor) throws CVSException; - - /** - * Indicates whether the object is a file or a folder - */ - boolean isFolder(); - - /** - * Delete the resource. - * In case of folder, with all the subfolders and files - */ - void delete(); - - /** - * Tells if the underlying resource does exist. - * (Maybe it has been delted in between) - */ - boolean exists(); - - /** - * Give the folder that contains this resource. - * - * If not isManaged() then the result of the operation is - * unsepecified. - */ - IManagedFolder getParent(); - - /** - * Give the name of the file back - * e.g. "folder1" for "C:\temp\folder1\" - */ - public String getName(); - - /** - * Answer whether the resource is to be ignored or not - */ - public boolean isIgnored() throws CVSException; - - /** - * - * Answer whether the resource is managed by it's parent. In CVS - * terms, this meanes the parent folder has an entry for the given - * resource in its CVS/Entries file. - * - * @see IManagedFolder#isCVSFolder() - * A folder may not have an FolderProperties also it is - * managed. This could only happen if the folder has - * been removed locally. - * - */ - public boolean isManaged() throws CVSException; - - /** - * Unmanage the given resource by purging any CVS information - * associated with the resource. - */ - public void unmanage() throws CVSException; - - /** - * Vistor-Pattern.<br> - * - * Accept a vistor to this resource. - * To be implemented in file and folder (otherwise - * we do not know whether to call visitFolder or - * visitFile) - */ - public void accept(IManagedVisitor visitor) throws CVSException; - - /** - * Get the remote location of a file either by reading it out of the - * file-info or by asking the parent-directory for it and appending the - * own name (recursivly).It stops recuring when it hits stopSearching.<br> - * - * If you want to get the remoteLocation of the currentFolder only then - * use it with getRemoteLocation(this). - * - * @return null if there was no remote-location until the folder stopSerarching - * @throws NullPointerException if stopSearching in not an ancestor of this - */ - public String getRemoteLocation(IManagedFolder stopSearching) throws CVSException; - - /** - * Get if the file has been modified since the last time - * saved in the fileEntry. Used on a folder it returns - * whether a file in the tree under this folder has been - * modified. This is an aproximation -- not to be used on - * critical operations.<br> - * Use isDirty of the IManagedFile instead. - * - * @return true if !isManaged() - * @throws CVSFileNotFoundException if exists() = false - */ - boolean showDirty() throws CVSException; - - /** - * Look, whether the dirty-state of the file has acctally changed. - * If so then clear the cache for the dirty status of this element - * and all elements above. - * - * @param up determins if the parents are acctually called. Setting this to false - * can have bad consequences. Use it only if you are sure that the parents - * allready have a clean cache. - */ - void clearDirty(boolean up) throws CVSException; - - /** - * Get the information if a resource is managed from a - * buffer. showManaged on a not-existing resource may or - * may not give the proper result. - */ - boolean showManaged() throws CVSException; - - /** - * clear the buffer whether this resource is managed. - */ - void clearManaged() throws CVSException; -} - - diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/api/IManagedVisitor.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/api/IManagedVisitor.java deleted file mode 100644 index 60c6c8bf4..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/api/IManagedVisitor.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.eclipse.team.internal.ccvs.core.resources.api;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved.
- */
-
-import org.eclipse.team.internal.ccvs.core.CVSException;
-
-/**
- * Interface for an visitor of the IManagedResources.
- */
-public interface IManagedVisitor {
-
- public void visitFile(IManagedFile file) throws CVSException;
- public void visitFolder(IManagedFolder folder) throws CVSException;
-
-}
-
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/CheckedIn.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/CheckedIn.java index a4cce3f57..b2c301275 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/CheckedIn.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/CheckedIn.java @@ -10,9 +10,9 @@ import java.io.PrintStream; import org.eclipse.team.internal.ccvs.core.util.Assert;
import org.eclipse.team.internal.ccvs.core.CVSException;
import org.eclipse.team.internal.ccvs.core.connection.Connection;
-import org.eclipse.team.internal.ccvs.core.resources.api.FileProperties;
-import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFile;
-import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFolder;
+import org.eclipse.team.internal.ccvs.core.resources.ResourceSyncInfo;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFile;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFolder;
/**
* Response to a "Checked-in" form the server.
@@ -34,7 +34,7 @@ class CheckedIn extends ResponseHandler { public void handle(
Connection connection,
PrintStream messageOutput,
- IManagedFolder mRoot)
+ ICVSFolder mRoot)
throws CVSException {
String entryLine;
@@ -43,9 +43,9 @@ class CheckedIn extends ResponseHandler { String fileName;
boolean changeFile;
- IManagedFile mFile;
- IManagedFolder mParent;
- FileProperties fileInfo;
+ ICVSFile mFile;
+ ICVSFolder mParent;
+ ResourceSyncInfo fileInfo;
// Read the info associated with the Updated response
localDirectory = connection.readLine();
@@ -65,7 +65,7 @@ class CheckedIn extends ResponseHandler { // haven't got anything from the server we do not need
// to. Saveing permissions is only cashing information
// from the server.
- changeFile = mFile.getFileInfo() == null;
+ changeFile = mFile.getSyncInfo() == null;
// If the file is not on disk then we have got an removed
// file and therefore a file that is dirty after the check-in
@@ -73,20 +73,19 @@ class CheckedIn extends ResponseHandler { changeFile = changeFile || !mFile.exists();
if (changeFile) {
- fileInfo = new FileProperties();
+ fileInfo = new ResourceSyncInfo(entryLine, null);
} else {
- fileInfo = mFile.getFileInfo();
+ fileInfo = mFile.getSyncInfo();
+ fileInfo.setEntryLine(entryLine);
}
- fileInfo.setEntryLine(entryLine);
-
if (changeFile) {
fileInfo.setTimeStamp(DUMMY_TIMESTAMP);
} else {
fileInfo.setTimeStamp(mFile.getTimeStamp());
}
- mFile.setFileInfo(fileInfo);
+ mFile.setSyncInfo(fileInfo);
Assert.isTrue(changeFile == mFile.isDirty());
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/CopyHandler.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/CopyHandler.java index d2310221a..61b395515 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/CopyHandler.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/CopyHandler.java @@ -1,72 +1,72 @@ -package org.eclipse.team.internal.ccvs.core.response; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.io.PrintStream; - -import org.eclipse.team.internal.ccvs.core.util.Assert; -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.connection.Connection; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFile; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFolder; - -/** - * Reacts on the "Copy-file"-Response of the server. - * Just copies the file as suggested by the server.<br> - * NOTE: The handler acctually copies the file, what does not - * seem to cause a problem, because it is only used for - * making copies for security on a merge. - */ -class CopyHandler extends ResponseHandler { - - /** - * @see IResponseHandler#getName() - */ - public String getName() { - return "Copy-file"; - } - - /** - * @see IResponseHandler#handle(Connection, PrintStream, IManagedFolder) - */ - public void handle( - Connection connection, - PrintStream messageOutput, - IManagedFolder mRoot) - throws CVSException { - - String fileName; - - IManagedFolder mParent; - IManagedFile mFile; - IManagedFile mNewFile; - - // Read the info associated with the Updated response - String localDirectory = connection.readLine(); - String repositoryFilename = connection.readLine(); - String newFilename = connection.readLine(); - - // Get the local file - fileName = repositoryFilename.substring(repositoryFilename.lastIndexOf("/") + 1); - mParent = mRoot.getFolder(localDirectory); - mFile = mParent.getFile(fileName); - - Assert.isTrue(mParent.exists() && mParent.isCVSFolder()); - Assert.isTrue(mFile.exists() && mFile.isManaged()); - - // Move the file to newFile (we know we do not need the - // original any more anyway) - // If this file exists then overwrite it - mNewFile = mParent.getFile(newFilename); - if (mNewFile.exists()) { - mNewFile.delete(); - } - - mFile.moveTo(mNewFile); - } - -} - +package org.eclipse.team.internal.ccvs.core.response;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.io.PrintStream;
+
+import org.eclipse.team.internal.ccvs.core.util.Assert;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.connection.Connection;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFile;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFolder;
+
+/**
+ * Reacts on the "Copy-file"-Response of the server.
+ * Just copies the file as suggested by the server.<br>
+ * NOTE: The handler acctually copies the file, what does not
+ * seem to cause a problem, because it is only used for
+ * making copies for security on a merge.
+ */
+class CopyHandler extends ResponseHandler {
+
+ /**
+ * @see IResponseHandler#getName()
+ */
+ public String getName() {
+ return "Copy-file";
+ }
+
+ /**
+ * @see IResponseHandler#handle(Connection, PrintStream, ICVSFolder)
+ */
+ public void handle(
+ Connection connection,
+ PrintStream messageOutput,
+ ICVSFolder mRoot)
+ throws CVSException {
+
+ String fileName;
+
+ ICVSFolder mParent;
+ ICVSFile mFile;
+ ICVSFile mNewFile;
+
+ // Read the info associated with the Updated response
+ String localDirectory = connection.readLine();
+ String repositoryFilename = connection.readLine();
+ String newFilename = connection.readLine();
+
+ // Get the local file
+ fileName = repositoryFilename.substring(repositoryFilename.lastIndexOf("/") + 1);
+ mParent = mRoot.getFolder(localDirectory);
+ mFile = mParent.getFile(fileName);
+
+ Assert.isTrue(mParent.exists());
+ Assert.isTrue(mFile.exists() && mFile.isManaged());
+
+ // Move the file to newFile (we know we do not need the
+ // original any more anyway)
+ // If this file exists then overwrite it
+ mNewFile = mParent.getFile(newFilename);
+ if (mNewFile.exists()) {
+ mNewFile.delete();
+ }
+
+ mFile.moveTo(mNewFile);
+ }
+
+}
+
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/DefaultHandler.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/DefaultHandler.java index 5236d1ee7..95823b13c 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/DefaultHandler.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/DefaultHandler.java @@ -11,7 +11,7 @@ import org.eclipse.core.runtime.MultiStatus; import org.eclipse.team.internal.ccvs.core.CVSException;
import org.eclipse.team.internal.ccvs.core.Policy;
import org.eclipse.team.internal.ccvs.core.connection.Connection;
-import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFolder;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFolder;
import org.eclipse.team.ccvs.core.CVSProviderPlugin;
/**
@@ -35,7 +35,7 @@ class DefaultHandler extends ResponseHandler { public void handle(
Connection connection,
PrintStream messageOutput,
- IManagedFolder mRoot)
+ ICVSFolder mRoot)
throws CVSException {
// FIXME look wether we need this or if the connection has
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/DumpHandler.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/DumpHandler.java index a46e577e3..2cbb2bb0b 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/DumpHandler.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/DumpHandler.java @@ -9,7 +9,7 @@ import java.io.PrintStream; import org.eclipse.team.internal.ccvs.core.CVSException;
import org.eclipse.team.internal.ccvs.core.connection.Connection;
-import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFolder;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFolder;
/**
* The Dump-Handler reads the rest of the
@@ -36,7 +36,7 @@ class DumpHandler extends ResponseHandler { public void handle(
Connection connection,
PrintStream messageOutput,
- IManagedFolder mRoot)
+ ICVSFolder mRoot)
throws CVSException {
connection.readLine();
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/IResponseHandler.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/IResponseHandler.java index 8efea1069..e4de131ea 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/IResponseHandler.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/IResponseHandler.java @@ -10,7 +10,7 @@ import java.io.PrintStream; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.team.internal.ccvs.core.CVSException;
import org.eclipse.team.internal.ccvs.core.connection.Connection;
-import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFolder;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFolder;
/**
* Represents an handler for a specific response of the
@@ -33,7 +33,7 @@ public interface IResponseHandler { */
public void handle(Connection connection,
PrintStream messageOutput,
- IManagedFolder mRoot,
+ ICVSFolder mRoot,
IProgressMonitor monitor)
throws CVSException;
}
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/MessageOutputHandler.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/MessageOutputHandler.java index 992714451..b3519459f 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/MessageOutputHandler.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/MessageOutputHandler.java @@ -10,7 +10,7 @@ import java.io.PrintStream; import org.eclipse.team.internal.ccvs.core.CVSException;
import org.eclipse.team.internal.ccvs.core.connection.Connection;
-import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFolder;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFolder;
/**
* The MessageOutputHandler sends the whoole line (incl. read token)
@@ -37,7 +37,7 @@ class MessageOutputHandler extends ResponseHandler { public void handle(
Connection connection,
PrintStream messageOutput,
- IManagedFolder mRoot)
+ ICVSFolder mRoot)
throws CVSException {
messageOutput.println(connection.readLine());
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/ModTimeHandler.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/ModTimeHandler.java index b4218c7c4..f5761f554 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/ModTimeHandler.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/ModTimeHandler.java @@ -11,7 +11,7 @@ import java.text.ParseException; import org.eclipse.team.internal.ccvs.core.CVSException;
import org.eclipse.team.internal.ccvs.core.Policy;
import org.eclipse.team.internal.ccvs.core.connection.Connection;
-import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFolder;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFolder;
import org.eclipse.team.internal.ccvs.core.util.FileDateFormat;
import org.eclipse.team.internal.ccvs.core.util.ServerDateFormat;
@@ -35,12 +35,12 @@ class ModTimeHandler extends ResponseHandler { }
/**
- * @see IResponseHandler#handle(Connection, OutputStream, IManagedFolder)
+ * @see IResponseHandler#handle(Connection, OutputStream, ICVSFolder)
*/
public void handle(
Connection connection,
PrintStream messageOutput,
- IManagedFolder mRoot)
+ ICVSFolder mRoot)
throws CVSException {
String unConverted = connection.readLine();
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/RemoveEntry.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/RemoveEntry.java index 9295c4686..2b14b7fb5 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/RemoveEntry.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/RemoveEntry.java @@ -10,8 +10,8 @@ import java.io.PrintStream; import org.eclipse.team.internal.ccvs.core.util.Assert;
import org.eclipse.team.internal.ccvs.core.CVSException;
import org.eclipse.team.internal.ccvs.core.connection.Connection;
-import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFile;
-import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFolder;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFile;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFolder;
/**
* This class responds to the Removed-response of the server<br>
@@ -29,18 +29,18 @@ class RemoveEntry extends ResponseHandler { }
/**
- * @see IResponseHandler#handle(Connection, PrintStream, IManagedFolder)
+ * @see IResponseHandler#handle(Connection, PrintStream, ICVSFolder)
*/
public void handle(
Connection connection,
PrintStream messageOutput,
- IManagedFolder mRoot)
+ ICVSFolder mRoot)
throws CVSException {
String fileName;
- IManagedFolder mParent;
- IManagedFile mFile;
+ ICVSFolder mParent;
+ ICVSFile mFile;
// Read the info associated with the Updated response
String localDirectory = connection.readLine();
@@ -54,7 +54,7 @@ class RemoveEntry extends ResponseHandler { // NOTE: Should we do something here other than throw a run-time exception
Assert.isTrue(mParent.exists() && !mFile.exists());
- mFile.setFileInfo(null);
+ mFile.unmanage();
}
}
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/Removed.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/Removed.java index 0dfbf13b4..3ba823a3e 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/Removed.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/Removed.java @@ -10,8 +10,8 @@ import java.io.PrintStream; import org.eclipse.team.internal.ccvs.core.util.Assert;
import org.eclipse.team.internal.ccvs.core.CVSException;
import org.eclipse.team.internal.ccvs.core.connection.Connection;
-import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFile;
-import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFolder;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFile;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFolder;
/**
* This class responds to the Removed-response of the server<br>
@@ -28,18 +28,18 @@ class Removed extends ResponseHandler { }
/**
- * @see IResponseHandler#handle(Connection, PrintStream, IManagedFolder)
+ * @see IResponseHandler#handle(Connection, PrintStream, ICVSFolder)
*/
public void handle(
Connection connection,
PrintStream messageOutput,
- IManagedFolder mRoot)
+ ICVSFolder mRoot)
throws CVSException {
String fileName;
- IManagedFolder mParent;
- IManagedFile mFile;
+ ICVSFolder mParent;
+ ICVSFile mFile;
// Read the info associated with the Updated response
String localDirectory = connection.readLine();
@@ -53,7 +53,7 @@ class Removed extends ResponseHandler { Assert.isTrue(mFile.exists() && mFile.isManaged());
// "unmanage" the folder and delete it ...
- mFile.setFileInfo(null);
+ mFile.unmanage();
mFile.delete();
}
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/ResponseDispatcher.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/ResponseDispatcher.java index 5471f6b57..9f7533800 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/ResponseDispatcher.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/ResponseDispatcher.java @@ -1,280 +1,280 @@ -package org.eclipse.team.internal.ccvs.core.response; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.io.OutputStream; -import java.io.PrintStream; -import java.util.Hashtable; -import java.util.Iterator; - -import org.eclipse.core.internal.utils.Assert; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.OperationCanceledException; -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.Policy; -import org.eclipse.team.internal.ccvs.core.connection.CVSServerException; -import org.eclipse.team.internal.ccvs.core.connection.Connection; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFolder; - -/** - * The ResponseContainer manages the respones of the server and - * pipes them to the appropiate handlers. - * - * It also takes care about registering handlers for response-tokens - * form the server. Standard-handlers are loaded on creation. - */ -public class ResponseDispatcher { - - public static final String OK = "ok"; - public static final String ERROR = "error"; - - private Hashtable standardResponsePool; - private Hashtable replaceResponsePool; - private Connection connection; - // Idea: private IResponse[] addResponsePool; - - /** - * Puts all the Request in a container in order to have access - * to them when they come from the stream - * - * Generic approach to "plug in" new responses just by adding them - * to this constructor - */ - public ResponseDispatcher(Connection connection, IResponseHandler[] customHandlers) { - - ModTimeHandler modTimeHandler = new ModTimeHandler(); - - this.connection = connection; - - standardResponsePool = new Hashtable(); - replaceResponsePool = new Hashtable(); - - registerStandardHandler(modTimeHandler); - registerStandardHandler(new CopyHandler()); - registerStandardHandler(new RemoveEntry()); - registerStandardHandler(new Updated(modTimeHandler,true)); - registerStandardHandler(new Updated(modTimeHandler,false)); - // registerStandardHandler(new UpdateExisting(modTimeHandler)); - registerStandardHandler(new UnsupportedHandler("Valid-requests")); - registerStandardHandler(new CheckedIn()); - registerStandardHandler(new Removed()); - registerStandardHandler(new MessageOutputHandler("M")); - registerStandardHandler(new MessageOutputHandler("E")); - registerStandardHandler(new StaticHandler(true)); - registerStandardHandler(new StaticHandler(false)); - registerStandardHandler(new StickyHandler(true)); - registerStandardHandler(new StickyHandler(false)); - - if (customHandlers != null) { - for (int i=0;i<customHandlers.length;i++) { - registerResponseHandler(customHandlers[i]); - } - } - - } - - /** - * Get the handler matching the string. Take it from the replaceResponsePool if - * possible, otherwise take it from the standardResponsePool. - * - * If there is no matching handler at all, return a standard-handler - */ - private IResponseHandler getHandler(String responseToken) { - - IResponseHandler responseHandler = (IResponseHandler) replaceResponsePool.get(responseToken); - - if (responseHandler == null) { - responseHandler = (IResponseHandler) standardResponsePool.get(responseToken); - } - - if (responseHandler == null) { - responseHandler = new DefaultHandler(); - } - - return responseHandler; - } - - /** - * Give a list of all registered Responses from the Server. - * - * (ok, error is added, because they are not fromal - * registerd as handler) - * - */ - public String makeResponseList() { - - StringBuffer result = new StringBuffer("ok error"); - - /* We are only looking into the standardResponsePool - all the registerd responses must be here as well, - otherwise you are not allowed to register special - handler - */ - Iterator elements = standardResponsePool.values().iterator(); - while (elements.hasNext()) { - IResponseHandler handler = (IResponseHandler) elements.next(); - result.append(' '); - result.append(handler.getName()); - } - - return result.toString(); - } - - /** - * Given a token of response from the server, this method - * reacts on it and does the appropiate handling with the - * responseHandler, that are loaded in it. - */ - public void handle(String responseToken, - Connection connection, - PrintStream messageOutput, - IManagedFolder mRoot, - IProgressMonitor monitor) - throws CVSException { - - IResponseHandler responseHandler; - - responseHandler = getHandler(responseToken); - responseHandler.handle(connection, messageOutput, mRoot, monitor); - - } - - /** - * To register a non-standard responseHandler. - * - * Replaces the preloaded responshandler for one response of the - * server. The name of the replaced response is response.getName(). - * - * If the response is not known to the server, then the call crashes. - * - */ - public void registerResponseHandler(IResponseHandler responseHandler) { - - Assert.isNotNull(standardResponsePool.get(responseHandler.getName())); - Assert.isTrue(replaceResponsePool.get(responseHandler.getName()) == null); - - replaceResponsePool.put(responseHandler.getName(),responseHandler); - } - - /** - * To unregister a non-standard responseHandler. - * - */ - public void unregisterResponseHandler(IResponseHandler responseHandler) { - - Assert.isNotNull(standardResponsePool.get(responseHandler.getName())); - Assert.isNotNull(replaceResponsePool.get(responseHandler.getName())); - - replaceResponsePool.remove(responseHandler.getName()); - } - - /** - * Registers a standard-handler while doing the - * init. - */ - private void registerStandardHandler(IResponseHandler responseHandler) { - - Assert.isTrue(standardResponsePool.get(responseHandler.getName()) == null); - - standardResponsePool.put(responseHandler.getName(),responseHandler); - } - - /** - * Runs the response event loop. - * - * If OK is in the pipe => stop looping. - * In Error is in the pipe => throw error, stop looping. - * Something else in the pipe => handle it with handle(response) - * and continou looping - * - * Does the work with the monitor - */ - public void manageResponse(IProgressMonitor monitor, - IManagedFolder mRoot, - PrintStream messageOutput) - throws CVSException { - - // Processing responses contributes 70% of total work. - // This depends on the caller to have picked the magic number of 100 - // as the amount of work for the operation!!! - IProgressMonitor subMonitor = Policy.subMonitorFor(monitor, 70); - - // This number can be tweaked if the monitor is judged to move too - // quickly or too slowly. After some experimentation this is a good - // number for both large projects (it doesn't move so quickly as to - // give a false sense of speed) and smaller projects (it actually does - // move some rather than remaining still and then jumping to 100). - final int TOTAL_WORK = 300; - subMonitor.beginTask(Policy.bind("ResponseDispatcher.receiving"), TOTAL_WORK); - - int halfWay = TOTAL_WORK / 2; - int currentIncrement = 4; - int nextProgress = currentIncrement; - int worked = 0; - - connection.flush(); - - try { - while (true) { - String response = connection.readToken(); - - // Update monitor work amount - if (--nextProgress <= 0) { - subMonitor.worked(1); - worked++; - if (worked >= halfWay) { - //we have passed the current halfway point, so double the - //increment and reset the halfway point. - currentIncrement *= 2; - halfWay += (TOTAL_WORK - halfWay) / 2; - } - //reset the progress counter to another full increment - nextProgress = currentIncrement; - } - Policy.checkCanceled(subMonitor); - - // Distiguage between three different tokens: - // OK => break - // ERROR => throw error (implicit break) - // rest => handle it - if (response.startsWith(OK)) { - break; - } else if (ERROR.equals(response)) { - throw serverErrorConnection(connection); - } else { - handle(response,connection,messageOutput,mRoot,monitor); - } - } - } finally { - subMonitor.done(); - } - } - - /** - * Reads error-data from the server and throws an - * exception. - */ - private static CVSException serverErrorConnection(Connection connection) { - - String message = ERROR; - - // The error tag can be followed by an error message too - if (connection.getLastUsedDelimiterToken() == IResponseHandler.BLANK_DELIMITER) { - try { - message = connection.readLine(); - } catch (CVSException e) { - // We get nothing and go on sending the standard-message - } - } - - if (message.equals("") || message.equals(" ")) { - message = Policy.bind("ResponseDispatcher.serverError"); - } - - return new CVSServerException(message); - } -} - +package org.eclipse.team.internal.ccvs.core.response;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.util.Hashtable;
+import java.util.Iterator;
+
+import org.eclipse.core.internal.utils.Assert;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.Policy;
+import org.eclipse.team.internal.ccvs.core.connection.CVSServerException;
+import org.eclipse.team.internal.ccvs.core.connection.Connection;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFolder;
+
+/**
+ * The ResponseContainer manages the respones of the server and
+ * pipes them to the appropiate handlers.
+ *
+ * It also takes care about registering handlers for response-tokens
+ * form the server. Standard-handlers are loaded on creation.
+ */
+public class ResponseDispatcher {
+
+ public static final String OK = "ok";
+ public static final String ERROR = "error";
+
+ private Hashtable standardResponsePool;
+ private Hashtable replaceResponsePool;
+ private Connection connection;
+ // Idea: private IResponse[] addResponsePool;
+
+ /**
+ * Puts all the Request in a container in order to have access
+ * to them when they come from the stream
+ *
+ * Generic approach to "plug in" new responses just by adding them
+ * to this constructor
+ */
+ public ResponseDispatcher(Connection connection, IResponseHandler[] customHandlers) {
+
+ ModTimeHandler modTimeHandler = new ModTimeHandler();
+
+ this.connection = connection;
+
+ standardResponsePool = new Hashtable();
+ replaceResponsePool = new Hashtable();
+
+ registerStandardHandler(modTimeHandler);
+ registerStandardHandler(new CopyHandler());
+ registerStandardHandler(new RemoveEntry());
+ registerStandardHandler(new Updated(modTimeHandler,true));
+ registerStandardHandler(new Updated(modTimeHandler,false));
+ // registerStandardHandler(new UpdateExisting(modTimeHandler));
+ registerStandardHandler(new UnsupportedHandler("Valid-requests"));
+ registerStandardHandler(new CheckedIn());
+ registerStandardHandler(new Removed());
+ registerStandardHandler(new MessageOutputHandler("M"));
+ registerStandardHandler(new MessageOutputHandler("E"));
+ registerStandardHandler(new StaticHandler(true));
+ registerStandardHandler(new StaticHandler(false));
+ registerStandardHandler(new StickyHandler(true));
+ registerStandardHandler(new StickyHandler(false));
+
+ if (customHandlers != null) {
+ for (int i=0;i<customHandlers.length;i++) {
+ registerResponseHandler(customHandlers[i]);
+ }
+ }
+
+ }
+
+ /**
+ * Get the handler matching the string. Take it from the replaceResponsePool if
+ * possible, otherwise take it from the standardResponsePool.
+ *
+ * If there is no matching handler at all, return a standard-handler
+ */
+ private IResponseHandler getHandler(String responseToken) {
+
+ IResponseHandler responseHandler = (IResponseHandler) replaceResponsePool.get(responseToken);
+
+ if (responseHandler == null) {
+ responseHandler = (IResponseHandler) standardResponsePool.get(responseToken);
+ }
+
+ if (responseHandler == null) {
+ responseHandler = new DefaultHandler();
+ }
+
+ return responseHandler;
+ }
+
+ /**
+ * Give a list of all registered Responses from the Server.
+ *
+ * (ok, error is added, because they are not fromal
+ * registerd as handler)
+ *
+ */
+ public String makeResponseList() {
+
+ StringBuffer result = new StringBuffer("ok error");
+
+ /* We are only looking into the standardResponsePool
+ all the registerd responses must be here as well,
+ otherwise you are not allowed to register special
+ handler
+ */
+ Iterator elements = standardResponsePool.values().iterator();
+ while (elements.hasNext()) {
+ IResponseHandler handler = (IResponseHandler) elements.next();
+ result.append(' ');
+ result.append(handler.getName());
+ }
+
+ return result.toString();
+ }
+
+ /**
+ * Given a token of response from the server, this method
+ * reacts on it and does the appropiate handling with the
+ * responseHandler, that are loaded in it.
+ */
+ public void handle(String responseToken,
+ Connection connection,
+ PrintStream messageOutput,
+ ICVSFolder mRoot,
+ IProgressMonitor monitor)
+ throws CVSException {
+
+ IResponseHandler responseHandler;
+
+ responseHandler = getHandler(responseToken);
+ responseHandler.handle(connection, messageOutput, mRoot, monitor);
+
+ }
+
+ /**
+ * To register a non-standard responseHandler.
+ *
+ * Replaces the preloaded responshandler for one response of the
+ * server. The name of the replaced response is response.getName().
+ *
+ * If the response is not known to the server, then the call crashes.
+ *
+ */
+ public void registerResponseHandler(IResponseHandler responseHandler) {
+
+ Assert.isNotNull(standardResponsePool.get(responseHandler.getName()));
+ Assert.isTrue(replaceResponsePool.get(responseHandler.getName()) == null);
+
+ replaceResponsePool.put(responseHandler.getName(),responseHandler);
+ }
+
+ /**
+ * To unregister a non-standard responseHandler.
+ *
+ */
+ public void unregisterResponseHandler(IResponseHandler responseHandler) {
+
+ Assert.isNotNull(standardResponsePool.get(responseHandler.getName()));
+ Assert.isNotNull(replaceResponsePool.get(responseHandler.getName()));
+
+ replaceResponsePool.remove(responseHandler.getName());
+ }
+
+ /**
+ * Registers a standard-handler while doing the
+ * init.
+ */
+ private void registerStandardHandler(IResponseHandler responseHandler) {
+
+ Assert.isTrue(standardResponsePool.get(responseHandler.getName()) == null);
+
+ standardResponsePool.put(responseHandler.getName(),responseHandler);
+ }
+
+ /**
+ * Runs the response event loop.
+ *
+ * If OK is in the pipe => stop looping.
+ * In Error is in the pipe => throw error, stop looping.
+ * Something else in the pipe => handle it with handle(response)
+ * and continou looping
+ *
+ * Does the work with the monitor
+ */
+ public void manageResponse(IProgressMonitor monitor,
+ ICVSFolder mRoot,
+ PrintStream messageOutput)
+ throws CVSException {
+
+ // Processing responses contributes 70% of total work.
+ // This depends on the caller to have picked the magic number of 100
+ // as the amount of work for the operation!!!
+ IProgressMonitor subMonitor = Policy.subMonitorFor(monitor, 70);
+
+ // This number can be tweaked if the monitor is judged to move too
+ // quickly or too slowly. After some experimentation this is a good
+ // number for both large projects (it doesn't move so quickly as to
+ // give a false sense of speed) and smaller projects (it actually does
+ // move some rather than remaining still and then jumping to 100).
+ final int TOTAL_WORK = 300;
+ subMonitor.beginTask(Policy.bind("ResponseDispatcher.receiving"), TOTAL_WORK);
+
+ int halfWay = TOTAL_WORK / 2;
+ int currentIncrement = 4;
+ int nextProgress = currentIncrement;
+ int worked = 0;
+
+ connection.flush();
+
+ try {
+ while (true) {
+ String response = connection.readToken();
+
+ // Update monitor work amount
+ if (--nextProgress <= 0) {
+ subMonitor.worked(1);
+ worked++;
+ if (worked >= halfWay) {
+ //we have passed the current halfway point, so double the
+ //increment and reset the halfway point.
+ currentIncrement *= 2;
+ halfWay += (TOTAL_WORK - halfWay) / 2;
+ }
+ //reset the progress counter to another full increment
+ nextProgress = currentIncrement;
+ }
+ Policy.checkCanceled(subMonitor);
+
+ // Distiguage between three different tokens:
+ // OK => break
+ // ERROR => throw error (implicit break)
+ // rest => handle it
+ if (response.startsWith(OK)) {
+ break;
+ } else if (ERROR.equals(response)) {
+ throw serverErrorConnection(connection);
+ } else {
+ handle(response,connection,messageOutput,mRoot,monitor);
+ }
+ }
+ } finally {
+ subMonitor.done();
+ }
+ }
+
+ /**
+ * Reads error-data from the server and throws an
+ * exception.
+ */
+ private static CVSException serverErrorConnection(Connection connection) {
+
+ String message = ERROR;
+
+ // The error tag can be followed by an error message too
+ if (connection.getLastUsedDelimiterToken() == IResponseHandler.BLANK_DELIMITER) {
+ try {
+ message = connection.readLine();
+ } catch (CVSException e) {
+ // We get nothing and go on sending the standard-message
+ }
+ }
+
+ if (message.equals("") || message.equals(" ")) {
+ message = Policy.bind("ResponseDispatcher.serverError");
+ }
+
+ return new CVSServerException(message);
+ }
+}
+
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/ResponseHandler.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/ResponseHandler.java index db5cfc7eb..8aa115bcf 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/ResponseHandler.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/ResponseHandler.java @@ -1,100 +1,101 @@ -package org.eclipse.team.internal.ccvs.core.response; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.io.PrintStream; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.connection.Connection; -import org.eclipse.team.internal.ccvs.core.resources.api.FolderProperties; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFolder; -import org.eclipse.team.internal.ccvs.core.util.Util; - -/** - * ResponseHandler is an abstract class implementing the IResponseHandler. - * - * At the moment it does just provide some additional helper-classes. - */ -public abstract class ResponseHandler implements IResponseHandler { - - public static final String SERVER_DELIM = "/"; - public static final String DUMMY_TIMESTAMP = "dummy timestamp"; - public static final String RESULT_OF_MERGE = "Result of merge+"; - - /** - * Call the old method without a monitor. Either this method or - * the called method have to be overloaded, otherwise an - * UnsupportedOperationException is thrown.<br> - * This is done for convinience to be able to keep the old methods - * that do not use a progress-monitor. - * - * Handle the given response from the server. - */ - public void handle(Connection connection, - PrintStream messageOutput, - IManagedFolder mRoot, - IProgressMonitor monitor) - throws CVSException { - - handle(connection,messageOutput,mRoot); - } - - /** - * This method throws an UnsupportedOperationException. - * To be overloaded - */ - public void handle(Connection connection, - PrintStream messageOutput, - IManagedFolder mRoot) - throws CVSException { - throw new UnsupportedOperationException(); - } - - /** - * Set the properties of the local folder, creating the folder if it does - * not exist. If the folder does exist, the remote parameter is not used. - * Also, the tag parameter is only set if setTag is true. Similarly, - * the parameter staticFolder is only set if setStatic is true. - * Otherwise these parameters are ignored. - */ - protected static void createFolder(Connection connection, - IManagedFolder mRoot, - String local, - String remote, - String tag, - boolean staticFolder, - boolean setTag, - boolean setStatic) - throws CVSException { - - FolderProperties folderProperties; - IManagedFolder mFolder; - - mFolder = mRoot.getFolder(local); - - if (mFolder.exists() && mFolder.isCVSFolder()) { - folderProperties = mFolder.getFolderInfo(); - } else { - mFolder.mkdir(); - folderProperties = new FolderProperties(); - folderProperties.setRoot(connection.getCVSRoot().getLocation()); - folderProperties.setRepository(Util.getRelativePath(connection.getRootDirectory(), - remote)); - } - - if (setTag) { - folderProperties.setTag(tag); - } - - if (setStatic) { - folderProperties.setStaticFolder(staticFolder); - } - - mFolder.setFolderInfo(folderProperties); - } -} - +package org.eclipse.team.internal.ccvs.core.response;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.io.PrintStream;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.connection.Connection;
+import org.eclipse.team.internal.ccvs.core.resources.CVSEntryLineTag;
+import org.eclipse.team.internal.ccvs.core.resources.FolderSyncInfo;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFolder;
+import org.eclipse.team.internal.ccvs.core.util.Util;
+
+/**
+ * ResponseHandler is an abstract class implementing the IResponseHandler.
+ *
+ * At the moment it does just provide some additional helper-classes.
+ */
+public abstract class ResponseHandler implements IResponseHandler {
+
+ public static final String SERVER_DELIM = "/";
+ public static final String DUMMY_TIMESTAMP = "dummy timestamp";
+ public static final String RESULT_OF_MERGE = "Result of merge+";
+
+ /**
+ * Call the old method without a monitor. Either this method or
+ * the called method have to be overloaded, otherwise an
+ * UnsupportedOperationException is thrown.<br>
+ * This is done for convinience to be able to keep the old methods
+ * that do not use a progress-monitor.
+ *
+ * Handle the given response from the server.
+ */
+ public void handle(Connection connection,
+ PrintStream messageOutput,
+ ICVSFolder mRoot,
+ IProgressMonitor monitor)
+ throws CVSException {
+
+ handle(connection,messageOutput,mRoot);
+ }
+
+ /**
+ * This method throws an UnsupportedOperationException.
+ * To be overloaded
+ */
+ public void handle(Connection connection,
+ PrintStream messageOutput,
+ ICVSFolder mRoot)
+ throws CVSException {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * Set the properties of the local folder, creating the folder if it does
+ * not exist. If the folder does exist, the remote parameter is not used.
+ * Also, the tag parameter is only set if setTag is true. Similarly,
+ * the parameter staticFolder is only set if setStatic is true.
+ * Otherwise these parameters are ignored.
+ */
+ protected static void createFolder(Connection connection,
+ ICVSFolder mRoot,
+ String local,
+ String remote,
+ String tag,
+ boolean staticFolder,
+ boolean setTag,
+ boolean setStatic)
+ throws CVSException {
+
+ FolderSyncInfo info;
+ ICVSFolder mFolder;
+
+ mFolder = mRoot.getFolder(local);
+
+ if (mFolder.exists() && mFolder.isCVSFolder()) {
+ info = mFolder.getFolderSyncInfo();
+ } else {
+ mFolder.mkdir();
+ info = new FolderSyncInfo();
+ info.setRoot(connection.getCVSRoot().getLocation());
+ info.setRepository(Util.getRelativePath(connection.getRootDirectory(),
+ remote));
+ }
+
+ if ((setTag) && (tag != null)) {
+ info.setTag(new CVSEntryLineTag(tag));
+ }
+
+ if (setStatic) {
+ info.setIsStatic(staticFolder);
+ }
+
+ mFolder.setFolderSyncInfo(info);
+ }
+}
+
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/StaticHandler.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/StaticHandler.java index 7d3a3f3ce..bd2ae9b49 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/StaticHandler.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/StaticHandler.java @@ -1,86 +1,81 @@ -package org.eclipse.team.internal.ccvs.core.response; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.io.PrintStream; - -import org.eclipse.team.internal.ccvs.core.util.Assert; -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.connection.Connection; -import org.eclipse.team.internal.ccvs.core.resources.api.FolderProperties; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFolder; -import org.eclipse.team.internal.ccvs.core.requests.RequestSender; -import org.eclipse.team.internal.ccvs.core.util.Util; - -/** - * Response to the Clear-static-directory and the Set-static-directory - * responses of the server. - * Out of this responses the folder-structure is generated and the - * information wether the folder a static is set. - */ -class StaticHandler extends ResponseHandler { - - public static final String SET_STATIC_RESPONSE = "Set-static-directory"; - public static final String CLEAR_STATIC_RESPONSE = "Clear-static-directory"; - private final boolean setStatic; - - /** - * Constructor - * - * @param setStatic => SetStaticHandler - !setStatic => ClearStaticHandler - */ - public StaticHandler(boolean setStatic) { - this.setStatic = setStatic; - } - - /** - * @see IResponseHandler#getName() - */ - public String getName() { - if (setStatic) { - return SET_STATIC_RESPONSE; - } else { - return CLEAR_STATIC_RESPONSE; - } - } - - /** - * @see IResponseHandler#handle(Connection, PrintStream, IManagedFolder) - */ - public void handle( - Connection connection, - PrintStream messageOutput, - IManagedFolder mRoot) - throws CVSException { - - String localDirectory; - String remoteDirectory; - - IManagedFolder mFolder; - FolderProperties folderInfo; - - // Read the info associated with the Updated response - localDirectory = connection.readLine(); - remoteDirectory = connection.readLine(); - - // Cut the last slash form the - Assert.isTrue(remoteDirectory.endsWith(SERVER_DELIM)); - remoteDirectory = remoteDirectory.substring(0,remoteDirectory.length() - - SERVER_DELIM.length()); - - createFolder(connection, - mRoot, - localDirectory, - remoteDirectory, - "Unvalid Tag that should never appear", - setStatic, - false, - true); - } - -} - +package org.eclipse.team.internal.ccvs.core.response;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.io.PrintStream;
+
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.connection.Connection;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFolder;
+import org.eclipse.team.internal.ccvs.core.util.Assert;
+
+/**
+ * Response to the Clear-static-directory and the Set-static-directory
+ * responses of the server.
+ * Out of this responses the folder-structure is generated and the
+ * information wether the folder a static is set.
+ */
+class StaticHandler extends ResponseHandler {
+
+ public static final String SET_STATIC_RESPONSE = "Set-static-directory";
+ public static final String CLEAR_STATIC_RESPONSE = "Clear-static-directory";
+ private final boolean setStatic;
+
+ /**
+ * Constructor
+ *
+ * @param setStatic => SetStaticHandler
+ !setStatic => ClearStaticHandler
+ */
+ public StaticHandler(boolean setStatic) {
+ this.setStatic = setStatic;
+ }
+
+ /**
+ * @see IResponseHandler#getName()
+ */
+ public String getName() {
+ if (setStatic) {
+ return SET_STATIC_RESPONSE;
+ } else {
+ return CLEAR_STATIC_RESPONSE;
+ }
+ }
+
+ /**
+ * @see IResponseHandler#handle(Connection, PrintStream, ICVSFolder)
+ */
+ public void handle(
+ Connection connection,
+ PrintStream messageOutput,
+ ICVSFolder mRoot)
+ throws CVSException {
+
+ String localDirectory;
+ String remoteDirectory;
+
+ ICVSFolder mFolder;
+
+ // Read the info associated with the Updated response
+ localDirectory = connection.readLine();
+ remoteDirectory = connection.readLine();
+
+ // Cut the last slash form the
+ Assert.isTrue(remoteDirectory.endsWith(SERVER_DELIM));
+ remoteDirectory = remoteDirectory.substring(0,remoteDirectory.length() -
+ SERVER_DELIM.length());
+
+ createFolder(connection,
+ mRoot,
+ localDirectory,
+ remoteDirectory,
+ "",
+ setStatic,
+ false,
+ true);
+ }
+}
+
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/StickyHandler.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/StickyHandler.java index 6adb3708b..e641d4820 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/StickyHandler.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/StickyHandler.java @@ -1,92 +1,89 @@ -package org.eclipse.team.internal.ccvs.core.response; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.io.PrintStream; - -import org.eclipse.team.internal.ccvs.core.util.Assert; -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.connection.Connection; -import org.eclipse.team.internal.ccvs.core.resources.api.FolderProperties; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFolder; -import org.eclipse.team.internal.ccvs.core.requests.RequestSender; -import org.eclipse.team.internal.ccvs.core.util.Util; - -/** - * Response to the Clear-static-directory and the Set-static-directory - * responses of the server. - * Out of this responses the folder-structure is generated and the - * information wether the folder a static is set. - */ -class StickyHandler extends ResponseHandler { - - public static final String SET_STICKY = "Set-sticky"; - public static final String CLEAR_STICKY = "Clear-sticky"; - private final boolean setSticky; - - /** - * Constructor - * - * @param setSticky => SetStickyHandler - !setSticky => ClearStickyHandler - */ - public StickyHandler(boolean setSticky) { - this.setSticky = setSticky; - } - - /** - * @see IResponseHandler#getName() - */ - public String getName() { - if (setSticky) { - return SET_STICKY; - } else { - return CLEAR_STICKY; - } - } - - /** - * @see IResponseHandler#handle(Connection, PrintStream, IManagedFolder) - */ - public void handle( - Connection connection, - PrintStream messageOutput, - IManagedFolder mRoot) - throws CVSException { - - String localDirectory; - String remoteDirectory; - String tag; - - // Read the info associated with the Updated response - localDirectory = connection.readLine(); - remoteDirectory = connection.readLine(); - - if (setSticky) { - tag = connection.readLine(); - if ("".equals(tag)) { - tag = null; - } - } else { - tag = null; - } - - // Cut the last slash from the remote directory - Assert.isTrue(remoteDirectory.endsWith(SERVER_DELIM)); - remoteDirectory = remoteDirectory.substring(0,remoteDirectory.length() - - SERVER_DELIM.length()); - - createFolder(connection, - mRoot, - localDirectory, - remoteDirectory, - tag, - false, - true, - false); - } -} - +package org.eclipse.team.internal.ccvs.core.response;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.io.PrintStream;
+
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.connection.Connection;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFolder;
+import org.eclipse.team.internal.ccvs.core.util.Assert;
+
+/**
+ * Response to the Clear-static-directory and the Set-static-directory
+ * responses of the server.
+ * Out of this responses the folder-structure is generated and the
+ * information wether the folder a static is set.
+ */
+class StickyHandler extends ResponseHandler {
+
+ public static final String SET_STICKY = "Set-sticky";
+ public static final String CLEAR_STICKY = "Clear-sticky";
+ private final boolean setSticky;
+
+ /**
+ * Constructor
+ *
+ * @param setSticky => SetStickyHandler
+ !setSticky => ClearStickyHandler
+ */
+ public StickyHandler(boolean setSticky) {
+ this.setSticky = setSticky;
+ }
+
+ /**
+ * @see IResponseHandler#getName()
+ */
+ public String getName() {
+ if (setSticky) {
+ return SET_STICKY;
+ } else {
+ return CLEAR_STICKY;
+ }
+ }
+
+ /**
+ * @see IResponseHandler#handle(Connection, PrintStream, ICVSFolder)
+ */
+ public void handle(
+ Connection connection,
+ PrintStream messageOutput,
+ ICVSFolder mRoot)
+ throws CVSException {
+
+ String localDirectory;
+ String remoteDirectory;
+ String tag;
+
+ // Read the info associated with the Updated response
+ localDirectory = connection.readLine();
+ remoteDirectory = connection.readLine();
+
+ if (setSticky) {
+ tag = connection.readLine();
+ if ("".equals(tag)) {
+ tag = null;
+ }
+ } else {
+ tag = null;
+ }
+
+ // Cut the last slash from the remote directory
+ Assert.isTrue(remoteDirectory.endsWith(SERVER_DELIM));
+ remoteDirectory = remoteDirectory.substring(0,remoteDirectory.length() -
+ SERVER_DELIM.length());
+
+ createFolder(connection,
+ mRoot,
+ localDirectory,
+ remoteDirectory,
+ tag,
+ false,
+ true,
+ false);
+ }
+}
+
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/UnsupportedHandler.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/UnsupportedHandler.java index da0fc3966..c3df0a75e 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/UnsupportedHandler.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/UnsupportedHandler.java @@ -10,7 +10,7 @@ import java.io.PrintStream; import org.eclipse.team.internal.ccvs.core.CVSException;
import org.eclipse.team.internal.ccvs.core.Policy;
import org.eclipse.team.internal.ccvs.core.connection.Connection;
-import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFolder;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFolder;
/**
* The UnsupportedHandler throws an error whenever
@@ -39,7 +39,7 @@ class UnsupportedHandler extends ResponseHandler { public void handle(
Connection connection,
PrintStream monitor,
- IManagedFolder mRoot)
+ ICVSFolder mRoot)
throws CVSException {
throw new CVSException(Policy.bind("UnsupportedHandler.message"));
}
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/Updated.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/Updated.java index 34822f651..24d4f2349 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/Updated.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/Updated.java @@ -12,9 +12,9 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.team.internal.ccvs.core.CVSException;
import org.eclipse.team.internal.ccvs.core.Policy;
import org.eclipse.team.internal.ccvs.core.connection.Connection;
-import org.eclipse.team.internal.ccvs.core.resources.api.FileProperties;
-import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFile;
-import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFolder;
+import org.eclipse.team.internal.ccvs.core.resources.ResourceSyncInfo;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFile;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFolder;
import org.eclipse.team.internal.ccvs.core.util.Assert;
import org.eclipse.team.internal.ccvs.core.util.Util;
@@ -72,7 +72,7 @@ class Updated extends ResponseHandler { public void handle(Connection connection,
PrintStream messageOutput,
- IManagedFolder mRoot,
+ ICVSFolder mRoot,
IProgressMonitor monitor)
throws CVSException {
@@ -81,9 +81,9 @@ class Updated extends ResponseHandler { boolean binary;
boolean readOnly;
- IManagedFile mFile;
- IManagedFolder mParent;
- FileProperties fileInfo;
+ ICVSFile mFile;
+ ICVSFolder mParent;
+ ResourceSyncInfo fileInfo;
InputStream in;
@@ -106,13 +106,13 @@ class Updated extends ResponseHandler { fileName = repositoryFilename.substring(
repositoryFilename.lastIndexOf(SERVER_DELIM) + 1);
mParent = mRoot.getFolder(localDirectory);
- Assert.isTrue(mParent.exists() && mParent.isCVSFolder());
+ Assert.isTrue(mParent.exists());
mFile = mParent.getFile(fileName);
in = connection.getResponseStream();
- fileInfo = new FileProperties(entry, permissions);
- binary = fileInfo.getKeywordMode().indexOf(FileProperties.BINARY_TAG) != -1;
+ fileInfo = new ResourceSyncInfo(entry, permissions);
+ binary = fileInfo.getKeywordMode().indexOf(ResourceSyncInfo.BINARY_TAG) != -1;
readOnly = permissions.indexOf(READ_ONLY_FLAG) == -1;
mFile.receiveFrom(in,monitor,size,binary,readOnly);
@@ -125,7 +125,7 @@ class Updated extends ResponseHandler { } else {
fileInfo.setTimeStamp(RESULT_OF_MERGE + mFile.getTimeStamp());
}
- mFile.setFileInfo(fileInfo);
+ mFile.setSyncInfo(fileInfo);
Assert.isTrue(mFile.isDirty()!=upToDate);
}
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/custom/CVSTag.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/custom/CVSTag.java deleted file mode 100644 index cde0d5b5e..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/custom/CVSTag.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.eclipse.team.internal.ccvs.core.response.custom; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.team.ccvs.core.ICVSTag; - -public class CVSTag implements ICVSTag { - - // Tag is a branch - public final static int BRANCH_TAG = 1; - // Tag is a version - public final static int VERSION_TAG = 2; - - // Tag name - private String name; - // Tag type - private int type; - - public CVSTag(String name, int type) { - this.name = name; - this.type = type; - } - /* - * Returns the tag name - */ - public String getName() { - return name; - } - /* - * Returns the tag type - */ - public int getType() { - return type; - } - - /* - * @see ICVSTag#isBranch() - */ - public boolean isBranch() { - return getType() == BRANCH_TAG; - } - - /* - * @see ICVSTag#isVersion() - */ - public boolean isVersion() { - return getType() == VERSION_TAG; - } - -} - diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/custom/DiffErrorHandler.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/custom/DiffErrorHandler.java index fdb1f605e..751517d05 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/custom/DiffErrorHandler.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/custom/DiffErrorHandler.java @@ -1,44 +1,44 @@ -package org.eclipse.team.internal.ccvs.core.response.custom; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.io.OutputStream; -import java.io.PrintStream; -import java.util.List; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.connection.Connection; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFolder; -import org.eclipse.team.internal.ccvs.core.response.ResponseHandler; - -public class DiffErrorHandler extends ResponseHandler { - - public static final String NAME = "E"; - protected OutputStream out; - private List errors; - - public DiffErrorHandler(List errors) throws CVSException { - this.errors = errors; - } - public String getName() { - return NAME; - } - public void handle( - Connection context, - PrintStream messageOutput, - IManagedFolder mRoot, - IProgressMonitor monitor) - throws CVSException { - - String line = context.readLine(); - // ignore these errors for now - this is used only with the diff - // request and the errors can be safely ignored. - if(!line.startsWith("cvs server:")) { - errors.add(line); - } - } -} +package org.eclipse.team.internal.ccvs.core.response.custom;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.util.List;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.connection.Connection;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFolder;
+import org.eclipse.team.internal.ccvs.core.response.ResponseHandler;
+
+public class DiffErrorHandler extends ResponseHandler {
+
+ public static final String NAME = "E";
+ protected OutputStream out;
+ private List errors;
+
+ public DiffErrorHandler(List errors) throws CVSException {
+ this.errors = errors;
+ }
+ public String getName() {
+ return NAME;
+ }
+ public void handle(
+ Connection context,
+ PrintStream messageOutput,
+ ICVSFolder mRoot,
+ IProgressMonitor monitor)
+ throws CVSException {
+
+ String line = context.readLine();
+ // ignore these errors for now - this is used only with the diff
+ // request and the errors can be safely ignored.
+ if(!line.startsWith("cvs server:")) {
+ errors.add(line);
+ }
+ }
+}
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/custom/DiffMessageHandler.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/custom/DiffMessageHandler.java index cf46c519e..ad5d83400 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/custom/DiffMessageHandler.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/custom/DiffMessageHandler.java @@ -1,52 +1,52 @@ -package org.eclipse.team.internal.ccvs.core.response.custom; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.io.OutputStream; -import java.io.PrintStream; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.connection.Connection; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFolder; -import org.eclipse.team.internal.ccvs.core.response.ResponseHandler; - -public class DiffMessageHandler extends ResponseHandler { - - /** The response key */ - public static final String NAME = "M"; - - /** - * Handle the response. This response sends the message to the - * progress monitor using <code>IProgressMonitor.subTask(Strin) - * </code>. - */ - public DiffMessageHandler() throws CVSException { - } - /** - * @see ResponseHandler#getName() - */ - public String getName() { - return NAME; - } - /** - * Handle the response. - * - * Write lines that are not prefixed by "cvs server:" to the stream - */ - public void handle( - Connection context, - PrintStream messageOutput, - IManagedFolder mRoot, - IProgressMonitor monitor) - throws CVSException { - - String line = context.readLine(); - if (line != null && !line.startsWith("cvs server:")) { - messageOutput.println(line); - } - } +package org.eclipse.team.internal.ccvs.core.response.custom;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.io.OutputStream;
+import java.io.PrintStream;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.connection.Connection;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFolder;
+import org.eclipse.team.internal.ccvs.core.response.ResponseHandler;
+
+public class DiffMessageHandler extends ResponseHandler {
+
+ /** The response key */
+ public static final String NAME = "M";
+
+ /**
+ * Handle the response. This response sends the message to the
+ * progress monitor using <code>IProgressMonitor.subTask(Strin)
+ * </code>.
+ */
+ public DiffMessageHandler() throws CVSException {
+ }
+ /**
+ * @see ResponseHandler#getName()
+ */
+ public String getName() {
+ return NAME;
+ }
+ /**
+ * Handle the response.
+ *
+ * Write lines that are not prefixed by "cvs server:" to the stream
+ */
+ public void handle(
+ Connection context,
+ PrintStream messageOutput,
+ ICVSFolder mRoot,
+ IProgressMonitor monitor)
+ throws CVSException {
+
+ String line = context.readLine();
+ if (line != null && !line.startsWith("cvs server:")) {
+ messageOutput.println(line);
+ }
+ }
}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/custom/ILogListener.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/custom/ILogListener.java index 2de73eeca..0e1444bcd 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/custom/ILogListener.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/custom/ILogListener.java @@ -1,5 +1,5 @@ package org.eclipse.team.internal.ccvs.core.response.custom;
-import org.eclipse.team.internal.ccvs.core.response.*;
+import org.eclipse.team.ccvs.core.CVSTag;
/*
* (c) Copyright IBM Corp. 2000, 2001.
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/custom/IUpdateMessageListener.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/custom/IUpdateMessageListener.java index 7261ce0b8..24e01816f 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/custom/IUpdateMessageListener.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/custom/IUpdateMessageListener.java @@ -1,29 +1,31 @@ -package org.eclipse.team.internal.ccvs.core.response.custom; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.core.runtime.IPath; -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.resources.*; - -/** - * This listener is used by RemoteFolder to listener for E and M messages - * from the CVS server in order to determine the files and folders contained in a parent folder. - */ -public interface IUpdateMessageListener { - /** - * information that a directory which has been reported using directoryInformation() does not exist - */ - public void directoryDoesNotExist(IPath path); - /** - * directory information - */ - public void directoryInformation(IPath path, boolean newDirectory); - /** - * file information - */ - public void fileInformation(char type, String filename) throws CVSException; -} +package org.eclipse.team.internal.ccvs.core.response.custom;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.resources.*;
+
+/**
+ * This listener is used by RemoteFolder to listener for E and M messages
+ * from the CVS server in order to determine the files and folders contained in a parent folder.
+ */
+public interface IUpdateMessageListener {
+ /**
+ * information that a directory which has been reported using directoryInformation() does not exist
+ */
+ public void directoryDoesNotExist(IPath path);
+ /**
+ * directory information
+ */
+ public void directoryInformation(IPath path, boolean newDirectory);
+ /**
+ * file information
+ */
+ public void fileInformation(char type, String filename) throws CVSException;
+
+ public void fileDoesNotExist(String filename);
+}
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/custom/LogEntry.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/custom/LogEntry.java index 01a34ebbd..9ee492793 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/custom/LogEntry.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/custom/LogEntry.java @@ -1,84 +1,84 @@ -package org.eclipse.team.internal.ccvs.core.response.custom; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.core.runtime.PlatformObject; -import org.eclipse.team.ccvs.core.ICVSRemoteFile; -import org.eclipse.team.ccvs.core.ICVSTag; -import org.eclipse.team.ccvs.core.ILogEntry; -import org.eclipse.team.internal.ccvs.core.resources.RemoteFile; - -public class LogEntry extends PlatformObject implements ILogEntry { - - private RemoteFile file; - private String author; - private String date; - private String comment; - private String state; - private CVSTag[] tags; - - public LogEntry(RemoteFile file, String revision, String author, String date, String comment, String state, CVSTag[] tags) { - this.file = file.toRevision(revision); - this.author = author; - this.date = date; - this.comment = comment; - this.state = state; - this.tags = tags; - } - - /** - * @see ILogEntry#getRevision() - */ - public String getRevision() { - return file.getRevision(); - } - - /** - * @see ILogEntry#getAuthor() - */ - public String getAuthor() { - return author; - } - - /** - * @see ILogEntry#getDate() - */ - public String getDate() { - return date; - } - - /** - * @see ILogEntry#getComment() - */ - public String getComment() { - return comment; - } - - /** - * @see ILogEntry#getState() - */ - public String getState() { - return state; - } - - /** - * @see ILogEntry#getTags() - */ - public ICVSTag[] getTags() { - ICVSTag[] result = new ICVSTag[tags.length]; - System.arraycopy(tags, 0, result, 0, tags.length); - return result; - } - - /** - * @see ILogEntry#getRemoteFile() - */ - public ICVSRemoteFile getRemoteFile() { - return file; - } - -} - +package org.eclipse.team.internal.ccvs.core.response.custom;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.core.runtime.PlatformObject;
+import org.eclipse.team.ccvs.core.CVSTag;
+import org.eclipse.team.ccvs.core.ICVSRemoteFile;
+import org.eclipse.team.ccvs.core.ILogEntry;
+import org.eclipse.team.internal.ccvs.core.resources.RemoteFile;
+
+public class LogEntry extends PlatformObject implements ILogEntry {
+
+ private RemoteFile file;
+ private String author;
+ private String date;
+ private String comment;
+ private String state;
+ private CVSTag[] tags;
+
+ public LogEntry(RemoteFile file, String revision, String author, String date, String comment, String state, CVSTag[] tags) {
+ this.file = file.toRevision(revision);
+ this.author = author;
+ this.date = date;
+ this.comment = comment;
+ this.state = state;
+ this.tags = tags;
+ }
+
+ /**
+ * @see ILogEntry#getRevision()
+ */
+ public String getRevision() {
+ return file.getRevision();
+ }
+
+ /**
+ * @see ILogEntry#getAuthor()
+ */
+ public String getAuthor() {
+ return author;
+ }
+
+ /**
+ * @see ILogEntry#getDate()
+ */
+ public String getDate() {
+ return date;
+ }
+
+ /**
+ * @see ILogEntry#getComment()
+ */
+ public String getComment() {
+ return comment;
+ }
+
+ /**
+ * @see ILogEntry#getState()
+ */
+ public String getState() {
+ return state;
+ }
+
+ /**
+ * @see ILogEntry#getTags()
+ */
+ public CVSTag[] getTags() {
+ CVSTag[] result = new CVSTag[tags.length];
+ System.arraycopy(tags, 0, result, 0, tags.length);
+ return result;
+ }
+
+ /**
+ * @see ILogEntry#getRemoteFile()
+ */
+ public ICVSRemoteFile getRemoteFile() {
+ return file;
+ }
+
+}
+
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/custom/LogHandler.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/custom/LogHandler.java index 735f6adff..452769b6d 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/custom/LogHandler.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/custom/LogHandler.java @@ -10,10 +10,12 @@ import java.util.ArrayList; import java.util.List;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.team.ccvs.core.CVSTag;
import org.eclipse.team.internal.ccvs.core.CVSException;
import org.eclipse.team.internal.ccvs.core.connection.Connection;
+import org.eclipse.team.internal.ccvs.core.resources.CVSEntryLineTag;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFolder;
import org.eclipse.team.internal.ccvs.core.resources.RemoteFile;
-import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFolder;
import org.eclipse.team.internal.ccvs.core.response.ResponseHandler;
import org.eclipse.team.internal.ccvs.core.util.Assert;
@@ -68,7 +70,7 @@ public class LogHandler extends ResponseHandler { public void handle(
Connection context,
PrintStream messageOutput,
- IManagedFolder mRoot,
+ ICVSFolder mRoot,
IProgressMonitor monitor)
throws CVSException {
@@ -159,7 +161,7 @@ public class LogHandler extends ResponseHandler { tagRev = tagRev.substring(0, lastDot);
}
if (tagRev.equals(revision)) {
- int type = isBranch ? CVSTag.BRANCH_TAG : CVSTag.VERSION_TAG;
+ int type = isBranch ? CVSTag.BRANCH : CVSTag.VERSION;
thisRevisionTags.add(new CVSTag(tagName, type));
}
}
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/custom/LogListener.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/custom/LogListener.java index a82f0b545..8cf841691 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/custom/LogListener.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/custom/LogListener.java @@ -1,39 +1,40 @@ -package org.eclipse.team.internal.ccvs.core.response.custom; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.util.List; - -import org.eclipse.team.internal.ccvs.core.resources.RemoteFile; - -public class LogListener implements ILogListener { - - private List entries; - private RemoteFile file; - /** - * Constructor for LogListener. - */ - public LogListener(RemoteFile file, List entries) { - this.entries = entries; - this.file = file; - } - - /** - * @see ILogListener#log(String, String, String, String, String, CVSTag[]) - */ - public void log( - String revision, - String author, - String date, - String comment, - String state, - CVSTag[] tags) { - - entries.add(new LogEntry(file, revision, author, date, comment, state, tags)); - } - -} - +package org.eclipse.team.internal.ccvs.core.response.custom;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.util.List;
+
+import org.eclipse.team.ccvs.core.CVSTag;
+import org.eclipse.team.internal.ccvs.core.resources.RemoteFile;
+
+public class LogListener implements ILogListener {
+
+ private List entries;
+ private RemoteFile file;
+ /**
+ * Constructor for LogListener.
+ */
+ public LogListener(RemoteFile file, List entries) {
+ this.entries = entries;
+ this.file = file;
+ }
+
+ /**
+ * @see ILogListener#log(String, String, String, String, String, CVSTag[])
+ */
+ public void log(
+ String revision,
+ String author,
+ String date,
+ String comment,
+ String state,
+ CVSTag[] tags) {
+
+ entries.add(new LogEntry(file, revision, author, date, comment, state, tags));
+ }
+
+}
+
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/custom/StatusErrorHandler.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/custom/StatusErrorHandler.java index 6e808a740..a5cebbb2a 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/custom/StatusErrorHandler.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/custom/StatusErrorHandler.java @@ -12,7 +12,7 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.Path;
import org.eclipse.team.internal.ccvs.core.CVSException;
import org.eclipse.team.internal.ccvs.core.connection.Connection;
-import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFolder;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFolder;
import org.eclipse.team.internal.ccvs.core.response.*;
public class StatusErrorHandler extends ResponseHandler {
@@ -33,7 +33,7 @@ public class StatusErrorHandler extends ResponseHandler { public void handle(
Connection context,
PrintStream messageOutput,
- IManagedFolder mRoot,
+ ICVSFolder mRoot,
IProgressMonitor monitor)
throws CVSException {
String line = context.readLine();
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/custom/StatusMessageHandler.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/custom/StatusMessageHandler.java index f35644ca2..8e8ea0711 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/custom/StatusMessageHandler.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/custom/StatusMessageHandler.java @@ -12,7 +12,7 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.Path;
import org.eclipse.team.internal.ccvs.core.CVSException;
import org.eclipse.team.internal.ccvs.core.connection.Connection;
-import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFolder;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFolder;
import org.eclipse.team.internal.ccvs.core.response.*;
public class StatusMessageHandler extends ResponseHandler {
@@ -39,7 +39,7 @@ public class StatusMessageHandler extends ResponseHandler { public void handle(
Connection context,
PrintStream messageOutput,
- IManagedFolder mRoot,
+ ICVSFolder mRoot,
IProgressMonitor monitor)
throws CVSException {
String line = context.readLine();
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/custom/UpdateErrorHandler.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/custom/UpdateErrorHandler.java index 6dc5af528..9b559a42f 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/custom/UpdateErrorHandler.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/custom/UpdateErrorHandler.java @@ -1,71 +1,88 @@ -package org.eclipse.team.internal.ccvs.core.response.custom; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.io.PrintStream; -import java.util.List; - -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Status; -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.connection.Connection; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFolder; -import org.eclipse.team.internal.ccvs.core.response.ResponseHandler; -import org.eclipse.team.ccvs.core.CVSProviderPlugin; -import org.eclipse.team.ccvs.core.CVSTeamProvider; -import org.eclipse.team.internal.ccvs.core.resources.*; - -/** - * This handler is used by the RemoteResource hierarchy to retrieve E messages - * from the CVS server in order to determine the folders contained in a parent folder. - */ -public class UpdateErrorHandler extends ResponseHandler { - - public static final String NAME = "E"; - - IUpdateMessageListener updateMessageListener; - List errors; - - public UpdateErrorHandler(IUpdateMessageListener updateMessageListener, List errors) { - this.updateMessageListener = updateMessageListener; - this.errors = errors; - } - public String getName() { - return NAME; - } - public void handle(Connection context, - PrintStream messageOutput, - IManagedFolder mRoot, - IProgressMonitor monitor) throws CVSException { - String line = context.readLine(); - if (line.startsWith("cvs server: Updating")) { - if (updateMessageListener != null) { - IPath path = new Path(line.substring(21)); - updateMessageListener.directoryInformation(path, false); - } - } else if (line.startsWith("cvs server: skipping directory")) { - if (updateMessageListener != null) { - IPath path = new Path(line.substring(31)); - updateMessageListener.directoryDoesNotExist(path); - } - } else if (line.startsWith("cvs server: New directory")) { - if (updateMessageListener != null) { - IPath path = new Path(line.substring(27, line.indexOf('\'', 27))); - updateMessageListener.directoryInformation(path, true); - } - } else if (line.startsWith("cvs [server aborted]: no such tag")) { - // This is reported from CVS when a tag is used on the update there are no files in the directory - // To get the folders, the update request should be re-issued for HEAD - errors.add(new Status(IStatus.ERROR, CVSProviderPlugin.ID, CVSException.IO_FAILED, line, null)); - } else if (!line.startsWith("cvs server: cannot open directory") - && !line.startsWith("cvs server: nothing known about")) { - errors.add(new Status(IStatus.ERROR, CVSProviderPlugin.ID, CVSException.IO_FAILED, line, null)); - } - } +package org.eclipse.team.internal.ccvs.core.response.custom;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.io.PrintStream;
+import java.util.List;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.connection.Connection;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFolder;
+import org.eclipse.team.internal.ccvs.core.response.ResponseHandler;
+import org.eclipse.team.ccvs.core.CVSProviderPlugin;
+import org.eclipse.team.ccvs.core.CVSTeamProvider;
+import org.eclipse.team.internal.ccvs.core.resources.*;
+
+/**
+ * This handler is used by the RemoteResource hierarchy to retrieve E messages
+ * from the CVS server in order to determine the folders contained in a parent folder.
+ */
+public class UpdateErrorHandler extends ResponseHandler {
+
+ public static final String NAME = "E";
+
+ public static final String SERVER_PREFIX = "cvs server: ";
+ public static final String SERVER_ABORTED_PREFIX = "cvs [server aborted]: ";
+
+ IUpdateMessageListener updateMessageListener;
+ List errors;
+
+ public UpdateErrorHandler(IUpdateMessageListener updateMessageListener, List errors) {
+ this.updateMessageListener = updateMessageListener;
+ this.errors = errors;
+ }
+ public String getName() {
+ return NAME;
+ }
+ public void handle(Connection context,
+ PrintStream messageOutput,
+ ICVSFolder mRoot,
+ IProgressMonitor monitor) throws CVSException {
+ String line = context.readLine();
+ if (line.startsWith(SERVER_PREFIX)) {
+ // Strip the prefix from the line
+ String message = line.substring(SERVER_PREFIX.length());
+ if (message.startsWith("Updating")) {
+ if (updateMessageListener != null) {
+ IPath path = new Path(message.substring(8));
+ updateMessageListener.directoryInformation(path, false);
+ }
+ } else if (message.startsWith("skipping directory")) {
+ if (updateMessageListener != null) {
+ IPath path = new Path(message.substring(18));
+ updateMessageListener.directoryDoesNotExist(path);
+ }
+ } else if (message.startsWith("New directory")) {
+ if (updateMessageListener != null) {
+ IPath path = new Path(message.substring(15, message.indexOf('\'', 15)));
+ updateMessageListener.directoryInformation(path, true);
+ }
+ } else if (message.endsWith("is no longer in the repository")) {
+ if (updateMessageListener != null) {
+ String filename = message.substring(0, message.indexOf(' '));
+ updateMessageListener.fileDoesNotExist(filename);
+ }
+ } else if (!message.startsWith("cannot open directory")
+ && !message.startsWith("nothing known about")) {
+ errors.add(new Status(IStatus.ERROR, CVSProviderPlugin.ID, CVSException.IO_FAILED, line, null));
+ }
+ } else if (line.startsWith(SERVER_ABORTED_PREFIX)) {
+ // Strip the prefix from the line
+ String message = line.substring(SERVER_ABORTED_PREFIX.length());
+ if (message.startsWith("no such tag")) {
+ // This is reported from CVS when a tag is used on the update there are no files in the directory
+ // To get the folders, the update request should be re-issued for HEAD
+ // XXX should we add special handling or just let the caller hande the error
+ }
+ errors.add(new Status(IStatus.ERROR, CVSProviderPlugin.ID, CVSException.IO_FAILED, line, null));
+ }
+ }
}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/custom/UpdateMessageHandler.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/custom/UpdateMessageHandler.java index 05e4ee26a..218a70230 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/custom/UpdateMessageHandler.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/response/custom/UpdateMessageHandler.java @@ -1,54 +1,54 @@ -package org.eclipse.team.internal.ccvs.core.response.custom; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.io.PrintStream; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.connection.Connection; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFolder; -import org.eclipse.team.internal.ccvs.core.response.ResponseHandler; -import org.eclipse.team.internal.ccvs.core.resources.*; - - -/** - * This handler is used by the RemoteResource hierarchy to retrieve M messages - * from the CVS server in order to determine the files contained in a parent folder. - */ -public class UpdateMessageHandler extends ResponseHandler { - - /** The response key */ - public static final String NAME = "M"; - - IUpdateMessageListener updateMessageListener; - - public UpdateMessageHandler(IUpdateMessageListener updateMessageListener) { - this.updateMessageListener = updateMessageListener; - } - /** - * @see ResponseHandler#getName() - */ - public String getName() { - return NAME; - } - /** - * Handle the response. This response sends the message to the - * progress monitor using <code>IProgressMonitor.subTask(Strin) - * </code>. - */ - public void handle(Connection connection, - PrintStream messageOutput, - IManagedFolder mRoot, - IProgressMonitor monitor) throws CVSException { - String line = connection.readLine(); - if (updateMessageListener == null) - return; - String path = line.substring(2); - updateMessageListener.fileInformation(line.charAt(0), path); - - } +package org.eclipse.team.internal.ccvs.core.response.custom;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.io.PrintStream;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.connection.Connection;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFolder;
+import org.eclipse.team.internal.ccvs.core.response.ResponseHandler;
+import org.eclipse.team.internal.ccvs.core.resources.*;
+
+
+/**
+ * This handler is used by the RemoteResource hierarchy to retrieve M messages
+ * from the CVS server in order to determine the files contained in a parent folder.
+ */
+public class UpdateMessageHandler extends ResponseHandler {
+
+ /** The response key */
+ public static final String NAME = "M";
+
+ IUpdateMessageListener updateMessageListener;
+
+ public UpdateMessageHandler(IUpdateMessageListener updateMessageListener) {
+ this.updateMessageListener = updateMessageListener;
+ }
+ /**
+ * @see ResponseHandler#getName()
+ */
+ public String getName() {
+ return NAME;
+ }
+ /**
+ * Handle the response. This response sends the message to the
+ * progress monitor using <code>IProgressMonitor.subTask(Strin)
+ * </code>.
+ */
+ public void handle(Connection connection,
+ PrintStream messageOutput,
+ ICVSFolder mRoot,
+ IProgressMonitor monitor) throws CVSException {
+ String line = connection.readLine();
+ if (updateMessageListener == null)
+ return;
+ String path = line.substring(2);
+ updateMessageListener.fileInformation(line.charAt(0), path);
+
+ }
}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/DirtyDeltaVisitor.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/DirtyDeltaVisitor.java index f0a75cd56..a846fceee 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/DirtyDeltaVisitor.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/DirtyDeltaVisitor.java @@ -1,54 +1,53 @@ -package org.eclipse.team.internal.ccvs.core.util; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.team.internal.ccvs.core.CVSException; -import org.eclipse.team.internal.ccvs.core.Client; -import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFile; - -public class DirtyDeltaVisitor extends ResourceDeltaVisitor { - - /** - * @see ResourceDeltaVisitor#handleAdded(IProject, IResource) - */ - protected void handleAdded(IProject project, IResource resource) { - } - - /** - * @see ResourceDeltaVisitor#handleRemoved(IProject, IResource) - */ - protected void handleRemoved(IProject project, IResource resource) { - clear(resource); - } - - /** - * @see ResourceDeltaVisitor#handleChanged(IProject, IResource) - */ - protected void handleChanged(IProject project, IResource resource) { - clear(resource); - } - - private void clear(IResource resource) { - IManagedFile mFile; - - if (!(resource instanceof IFile)) { - return; - } - - try { - mFile = Client.getManagedFile(resource.getLocation().toFile()); - mFile.clearDirty(true); - } catch (CVSException e) { - Assert.isTrue(false); - } - - System.out.println(resource.getName() + " cleared"); - } -} - +package org.eclipse.team.internal.ccvs.core.util;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.Client;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFile;
+
+public class DirtyDeltaVisitor extends ResourceDeltaVisitor {
+
+ /**
+ * @see ResourceDeltaVisitor#handleAdded(IProject, IResource)
+ */
+ protected void handleAdded(IProject project, IResource resource) {
+ }
+
+ /**
+ * @see ResourceDeltaVisitor#handleRemoved(IProject, IResource)
+ */
+ protected void handleRemoved(IProject project, IResource resource) {
+ clear(resource);
+ }
+
+ /**
+ * @see ResourceDeltaVisitor#handleChanged(IProject, IResource)
+ */
+ protected void handleChanged(IProject project, IResource resource) {
+ clear(resource);
+ }
+
+ private void clear(IResource resource) {
+ ICVSFile mFile;
+
+ if (!(resource instanceof IFile)) {
+ return;
+ }
+
+ try {
+ mFile = Client.getManagedFile(resource.getLocation().toFile());
+ } catch (CVSException e) {
+ Assert.isTrue(false);
+ }
+
+ System.out.println(resource.getName() + " cleared");
+ }
+}
+
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/DumpDeltaVisitor.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/DumpDeltaVisitor.java index adab74eb8..b51486d4e 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/DumpDeltaVisitor.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/DumpDeltaVisitor.java @@ -1,38 +1,38 @@ -package org.eclipse.team.internal.ccvs.core.util; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; - -/** - * Dumps every change in the resources to the consol - */ -public class DumpDeltaVisitor extends ResourceDeltaVisitor { - - /** - * @see ResourceDeltaVisitor#handleAdded(IProject, IResource) - */ - protected void handleAdded(IProject project, IResource resource) { - System.out.println(resource.getName() + " added"); - } - - /** - * @see ResourceDeltaVisitor#handleRemoved(IProject, IResource) - */ - protected void handleRemoved(IProject project, IResource resource) { - System.out.println(resource.getName() + " removed"); - } - - /** - * @see ResourceDeltaVisitor#handleChanged(IProject, IResource) - */ - protected void handleChanged(IProject project, IResource resource) { - System.out.println(resource.getName() + " changed"); - } - -} - +package org.eclipse.team.internal.ccvs.core.util;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+
+/**
+ * Dumps every change in the resources to the consol
+ */
+public class DumpDeltaVisitor extends ResourceDeltaVisitor {
+
+ /**
+ * @see ResourceDeltaVisitor#handleAdded(IProject, IResource)
+ */
+ protected void handleAdded(IProject project, IResource resource) {
+ System.out.println(resource.getName() + " added");
+ }
+
+ /**
+ * @see ResourceDeltaVisitor#handleRemoved(IProject, IResource)
+ */
+ protected void handleRemoved(IProject project, IResource resource) {
+ System.out.println(resource.getName() + " removed");
+ }
+
+ /**
+ * @see ResourceDeltaVisitor#handleChanged(IProject, IResource)
+ */
+ protected void handleChanged(IProject project, IResource resource) {
+ System.out.println(resource.getName() + " changed");
+ }
+
+}
+
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/EntriesVisitor.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/EntriesVisitor.java deleted file mode 100644 index dac3ccb80..000000000 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/EntriesVisitor.java +++ /dev/null @@ -1,108 +0,0 @@ -package org.eclipse.team.internal.ccvs.core.util;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved.
- */
-
-import java.util.ArrayList;
-
-import org.eclipse.team.internal.ccvs.core.CVSException;
-import org.eclipse.team.internal.ccvs.core.resources.api.FileProperties;
-import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFile;
-import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFolder;
-import org.eclipse.team.internal.ccvs.core.resources.api.IManagedVisitor;
-
-/**
- * Merges all the Entries.Log files with the corriponding
- * Entries files in the CVS folders in this folder and all
- * the subfolders (deep).<br>
- *
- * (Entries.Log files contain changes in the Entries files
- * read a CVS command line client manual)
- */
-public class EntriesVisitor implements IManagedVisitor {
-
- public static final String ENTRIES_PROPERTY = FileProperties.ENTRIES;
- public static final String ENTRIES_LOG_PROPERTY="Entries.Log";
- public static final String FOLDER_TAG="D";
- public static final String ADD_TAG="A ";
- public static final String REMOVE_TAG="R ";
-
- /**
- * Constructor for EntriesVisitor.
- */
- public EntriesVisitor() {
- super();
- }
-
- /**
- * @see IManagedVisitor#visitFile(IManagedFile)
- */
- public void visitFile(IManagedFile mFile) {
- // Do nothing ... files do not have cvs-folders in that we could
- // possible merge
- }
-
- /**
- * @see IManagedVisitor#visitFolder(IManagedFolder)
- */
- public void visitFolder(IManagedFolder mFolder) throws CVSException {
-
- if (!mFolder.exists()) {
- return;
- }
-
- // We still go into the subdirectories if we are not in a cvs-folder,
- // because we might be in the root (on a checkout in a testcase).
- //
- // The case that we are not in a cvsFolder could be changed to an
- // assert or even an exception. Make sure you break nothing.
- if (mFolder.isCVSFolder()) {
- mergeEntries(mFolder);
- }
-
- mFolder.acceptChildren(this);
-
- }
-
- /**
- * Get an entries and an entries.log file in a cvs-folder of
- * the cvsfolder and merge them into one new entries-file
- */
- public static void mergeEntries(IManagedFolder mFolder) throws CVSException {
-
- String[] entrieLogs;
- String[] entries;
- ArrayList newEntries = new ArrayList();
-
- entrieLogs = mFolder.getProperty(ENTRIES_LOG_PROPERTY);
- entries = mFolder.getProperty(ENTRIES_PROPERTY);
-
- if (entrieLogs == null) {
- return;
- }
-
- for (int i=0; i<entries.length; i++) {
- if (!entries[i].equals(FOLDER_TAG)) {
- newEntries.add(entries[i]);
- }
- }
-
- for (int i=0; i<entrieLogs.length; i++) {
- if (entrieLogs[i].startsWith(ADD_TAG)) {
- newEntries.add(entrieLogs[i].substring(ADD_TAG.length()));
- } else if (entrieLogs[i].startsWith(REMOVE_TAG)) {
- newEntries.remove(entrieLogs[i].substring(REMOVE_TAG.length()));
- }
- }
-
- newEntries.add(FOLDER_TAG);
-
- entries = (String[]) newEntries.toArray(new String[newEntries.size()]);
-
- mFolder.setProperty(ENTRIES_PROPERTY,entries);
- mFolder.setProperty(ENTRIES_LOG_PROPERTY,null);
- }
-}
-
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/FileUtil.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/FileUtil.java new file mode 100644 index 000000000..3336c2aea --- /dev/null +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/FileUtil.java @@ -0,0 +1,67 @@ +package org.eclipse.team.internal.ccvs.core.util;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.team.internal.ccvs.core.CVSException;
+
+public class FileUtil {
+
+ public static final String PLATFORM_NEWLINE = System.getProperty("line.separator");
+ public static void writeLines(File file, String[] content) throws CVSException {
+
+ BufferedWriter fileWriter;
+
+ try {
+ fileWriter = new BufferedWriter(new FileWriter(file));
+ for (int i = 0; i<content.length; i++) {
+ fileWriter.write(content[i]);
+ fileWriter.newLine();
+ }
+ fileWriter.close();
+ } catch (IOException e) {
+ throw CVSException.wrapException(e);
+ }
+ }
+
+ /**
+ * load file in lines to String[]
+ *
+ * @param file has to be non-null and file.exists() == true
+ */
+ public static String[] readLines(File file) throws CVSException {
+
+ BufferedReader fileReader;
+ List fileContentStore = new ArrayList();
+ String line;
+
+ try {
+ fileReader = new BufferedReader(new FileReader(file));
+ while ((line = fileReader.readLine()) != null) {
+ fileContentStore.add(line);
+ }
+ fileReader.close();
+ } catch (IOException e) {
+ throw CVSException.wrapException(e);
+ }
+
+ return (String[]) fileContentStore.toArray(new String[fileContentStore.size()]);
+ }
+
+ public static void deepDelete(File resource) {
+ if (resource.isDirectory()) {
+ File[] fileList = resource.listFiles();
+ for (int i = 0; i < fileList.length; i++) {
+ deepDelete(fileList[i]); + }
+ }
+ resource.delete();
+ }
+}
+
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/RemoteFolderTreeBuilder.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/RemoteFolderTreeBuilder.java index e316daf38..a63018f1b 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/RemoteFolderTreeBuilder.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/RemoteFolderTreeBuilder.java @@ -11,32 +11,32 @@ import java.util.HashMap; import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Map.Entry;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.team.ccvs.core.CVSProviderPlugin;
+import org.eclipse.team.ccvs.core.CVSTag;
import org.eclipse.team.ccvs.core.ICVSRemoteResource;
import org.eclipse.team.internal.ccvs.core.CVSException;
import org.eclipse.team.internal.ccvs.core.Client;
import org.eclipse.team.internal.ccvs.core.Policy;
import org.eclipse.team.internal.ccvs.core.connection.CVSRepositoryLocation;
import org.eclipse.team.internal.ccvs.core.connection.Connection;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFile;
+import org.eclipse.team.internal.ccvs.core.resources.ICVSFolder;
import org.eclipse.team.internal.ccvs.core.resources.RemoteFile;
import org.eclipse.team.internal.ccvs.core.resources.RemoteFolder;
import org.eclipse.team.internal.ccvs.core.resources.RemoteFolderTree;
import org.eclipse.team.internal.ccvs.core.resources.RemoteResource;
-import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFile;
-import org.eclipse.team.internal.ccvs.core.resources.api.IManagedFolder;
+import org.eclipse.team.internal.ccvs.core.resources.ResourceSyncInfo;
import org.eclipse.team.internal.ccvs.core.response.IResponseHandler;
import org.eclipse.team.internal.ccvs.core.response.custom.IStatusListener;
import org.eclipse.team.internal.ccvs.core.response.custom.IUpdateMessageListener;
import org.eclipse.team.internal.ccvs.core.response.custom.StatusMessageHandler;
import org.eclipse.team.internal.ccvs.core.response.custom.UpdateErrorHandler;
import org.eclipse.team.internal.ccvs.core.response.custom.UpdateMessageHandler;
-import org.omg.CORBA.UNKNOWN;
/*
* This class is responsible for building a remote tree that shows the repository
@@ -56,11 +56,11 @@ public class RemoteFolderTreeBuilder { private List errors;
- private IManagedFolder root;
+ private ICVSFolder root;
private RemoteFolderTree remoteRoot;
private CVSRepositoryLocation repository;
- private String tag;
+ private CVSTag tag;
private String[] updateLocalOptions;
@@ -71,7 +71,7 @@ public class RemoteFolderTreeBuilder { private static Map EMPTY_MAP = new HashMap();
- private RemoteFolderTreeBuilder(CVSRepositoryLocation repository, IManagedFolder root, String tag) {
+ private RemoteFolderTreeBuilder(CVSRepositoryLocation repository, ICVSFolder root, CVSTag tag) {
this.repository = repository;
this.root = root;
this.tag = tag;
@@ -82,18 +82,18 @@ public class RemoteFolderTreeBuilder { // Build the local options
List localOptions = new ArrayList();
localOptions.add("-d");
- if ((tag != null) && (!tag.equals("HEAD"))) {
+ if ((tag != null) && (tag.getType() != tag.HEAD)) {
localOptions.add(Client.TAG_OPTION);
- localOptions.add(tag);
+ localOptions.add(tag.getName());
}
updateLocalOptions = (String[])localOptions.toArray(new String[localOptions.size()]);
}
- public static RemoteFolderTree buildRemoteTree(CVSRepositoryLocation repository, IContainer root, String tag, IProgressMonitor monitor) throws CVSException {
+ public static RemoteFolderTree buildRemoteTree(CVSRepositoryLocation repository, IContainer root, CVSTag tag, IProgressMonitor monitor) throws CVSException {
return buildRemoteTree(repository, Client.getManagedFolder(root.getLocation().toFile()), tag, monitor);
}
- public static RemoteFolderTree buildRemoteTree(CVSRepositoryLocation repository, IManagedFolder root, String tag, IProgressMonitor monitor) throws CVSException {
+ public static RemoteFolderTree buildRemoteTree(CVSRepositoryLocation repository, ICVSFolder root, CVSTag tag, IProgressMonitor monitor) throws CVSException {
RemoteFolderTreeBuilder builder = new RemoteFolderTreeBuilder(repository, root, tag);
return builder.buildTree(monitor);
}
@@ -102,12 +102,11 @@ public class RemoteFolderTreeBuilder { Connection connection = repository.openConnection();
try {
fetchDelta(connection, monitor);
- remoteRoot = new RemoteFolderTree(repository, new Path(root.getFolderInfo().getRepository()), tag);
+ remoteRoot = new RemoteFolderTree(null, repository, new Path(root.getFolderSyncInfo().getRepository()), tag);
buildRemoteTree(connection, root, remoteRoot, Path.EMPTY, monitor);
fetchFileRevisions(connection, remoteRoot, (String[])changedFiles.toArray(new String[changedFiles.size()]), monitor);
return remoteRoot;
} catch (CVSException e) {
- // throw CVSTeamProvider.wrapException(e, errors);
if (!errors.isEmpty()) {
PrintStream out = getPrintStream();
for (int i=0;i<errors.size();i++)
@@ -122,66 +121,62 @@ public class RemoteFolderTreeBuilder { /*
* Build the remote tree from the local tree and the recorded deltas.
*
- * If the remote is null, it is created from the local.
- * If the local is null, the remote is used.
- *
* The localPath is used to retrieve deltas from the recorded deltas
*
*/
- private RemoteFolderTree buildRemoteTree(Connection connection, IManagedFolder local, RemoteFolderTree remote, IPath localPath, IProgressMonitor monitor) throws CVSException {
-
- // Pre-create the resulting tree so it can be used as the parent in RemoteFile creation
- RemoteFolderTree tree;
- if (remote == null)
- tree = new RemoteFolderTree(repository, new Path(local.getFolderInfo().getRepository()), tag);
- else
- tree = remote;
+ private void buildRemoteTree(Connection connection, ICVSFolder local, RemoteFolderTree remote, IPath localPath, IProgressMonitor monitor) throws CVSException {
// Create a map to contain the created children
Map children = new HashMap();
- // Check if we have a local copy corresponding to the remote folder
- Map deltas;
+ // If there's no corresponding local resource then we need to fetch its contents in order to populate the deltas
if (local == null) {
- // This is a new folder. We need to fetch its contents in order to populate the deltas
fetchNewDirectory(connection, remote, localPath, monitor);
- deltas = (Map)fileDeltas.get(localPath);
- if (deltas == null)
- deltas = EMPTY_MAP;
- } else {
- // This is an existing folder. The deltas will already be populated
- deltas = (Map)fileDeltas.get(localPath);
- if (deltas == null)
- deltas = EMPTY_MAP;
+ }
+
+ // Fetch the delta's for the folder
+ Map deltas = deltas = (Map)fileDeltas.get(localPath);
+ if (deltas == null)
+ deltas = EMPTY_MAP;
+
+ // If there is a local, use the local children to start buidling the remote children
+ if (local != null) {
// Build the child folders corresponding to local folders
- IManagedFolder[] folders = local.getFolders();
+ ICVSFolder[] folders = local.getFolders();
for (int i=0;i<folders.length;i++) {
if (deltas.get(folders[i].getName()) != DELETED)
- children.put(folders[i].getName(), new RemoteFolderTree(repository, new Path(folders[i].getFolderInfo().getRepository()), tag));
+ children.put(folders[i].getName(), new RemoteFolderTree(remote, repository, new Path(folders[i].getFolderSyncInfo().getRepository()), tag));
}
// Build the child files corresponding to local files
- IManagedFile[] files = local.getFiles();
+ ICVSFile[] files = local.getFiles();
for (int i=0;i<files.length;i++) {
- if (deltas.get(files[i].getName()) != DELETED)
- children.put(files[i].getName(), new RemoteFile(tree, files[i].getName(), files[i].getFileInfo().getVersion()));
+ ICVSFile file = files[i];
+ if (deltas.get(file.getName()) != DELETED) {
+ ResourceSyncInfo info = file.getSyncInfo();
+ // if there is no sync info then there isn't a remote file for this local file on the
+ // server.
+ if(info!=null) {
+ children.put(file.getName(), new RemoteFile(remote, file.getName(), info.getRevision(), tag));
+ }
+ }
}
}
- // Build the children for new resources from the deltas
+ // Build the children for new or out-of-date resources from the deltas
Iterator i = deltas.keySet().iterator();
while (i.hasNext()) {
String name = (String)i.next();
String revision = (String)deltas.get(name);
if (revision == FOLDER) {
- // NOTE: getRemotePath() should just return an IPath
- children.put(name, new RemoteFolderTree(repository, new Path(tree.getRemotePath()).append(name), tag));
+ // XXX should getRemotePath() return an IPath instead of a String?
+ children.put(name, new RemoteFolderTree(remote, repository, new Path(remote.getRemotePath()).append(name), tag));
} else if (revision == ADDED) {
- children.put(name, new RemoteFile(tree, name, UNKNOWN));
+ children.put(name, new RemoteFile(remote, name, tag));
} else if (revision == UNKNOWN) {
// This should have been created from the local resources.
// If it wasn't, we'll add it!
if (!children.containsKey(name))
- children.put(name, new RemoteFile(tree, name, UNKNOWN));
+ children.put(name, new RemoteFile(remote, name, tag));
} else if (revision == DELETED) {
// This should have been deleted while creating from the local resources.
// If it wasn't, delete it now.
@@ -193,16 +188,18 @@ public class RemoteFolderTreeBuilder { }
// Add the children to the remote folder tree
- tree.setChildren((ICVSRemoteResource[])children.values().toArray(new ICVSRemoteResource[children.size()]));
+ remote.setChildren((ICVSRemoteResource[])children.values().toArray(new ICVSRemoteResource[children.size()]));
- // We have to delay building the children to support the proper fetching of new directories
+ // We have to delay building the child folders to support the proper fetching of new directories
+ // due to the fact that the same CVS home directory (i.e. the same root directory) must
+ // be used for all requests sent over the same connection
Iterator childIterator = children.entrySet().iterator();
while (childIterator.hasNext()) {
Map.Entry entry = (Map.Entry)childIterator.next();
if (((RemoteResource)entry.getValue()).isFolder()) {
RemoteFolderTree remoteFolder = (RemoteFolderTree)entry.getValue();
String name = (String)entry.getKey();
- IManagedFolder localFolder;
+ ICVSFolder localFolder;
if (deltas.get(name) == FOLDER)
localFolder = null;
else
@@ -210,7 +207,6 @@ public class RemoteFolderTreeBuilder { buildRemoteTree(connection, localFolder, remoteFolder, localPath.append(name), monitor);
}
}
- return tree;
}
/*
@@ -293,6 +289,8 @@ public class RemoteFolderTreeBuilder { changedFiles.add(filename);
recordDelta(new Path(filename), ADDED);
}
+ public void fileDoesNotExist(String filename) {
+ }
};
// NOTE: Should use the path relative to the remoteRoot
@@ -342,8 +340,11 @@ public class RemoteFolderTreeBuilder { new IResponseHandler[] {new StatusMessageHandler(listener)},
false);
- if (count[0] != fileNames.length)
- throw new CVSException(Policy.bind("RemoteFolder.errorFetchingRevisions"));
+ // XXX we can't make this check because it may be valid to call this method
+ // without any file names (e.g. fileNames array empty) which would run the
+ // status on all files.
+ //if (count[0] != fileNames.length)
+ // throw new CVSException(Policy.bind("RemoteFolder.errorFetchingRevisions"));
}
@@ -370,7 +371,7 @@ public class RemoteFolderTreeBuilder { }
private void updateRevision(RemoteFolder root, IPath path, String revision) throws CVSException {
- ((RemoteFile)root.getFile(path.toString())).setRevision(revision);
+ ((RemoteFile)root.getFile(path.toString())).getSyncInfo().setRevision(revision);
}
}
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/ResourceDeltaVisitor.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/ResourceDeltaVisitor.java index b5e61954f..fe04cfed0 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/ResourceDeltaVisitor.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/ResourceDeltaVisitor.java @@ -1,223 +1,223 @@ -package org.eclipse.team.internal.ccvs.core.util; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceChangeEvent; -import org.eclipse.core.resources.IResourceChangeListener; -import org.eclipse.core.resources.IResourceDelta; -import org.eclipse.core.resources.IResourceDeltaVisitor; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.team.core.ITeamProvider; -import org.eclipse.team.core.TeamPlugin; -import org.eclipse.team.internal.ccvs.core.Policy; -import org.eclipse.team.ccvs.core.CVSTeamProvider; - -public abstract class ResourceDeltaVisitor implements IResourceDeltaVisitor { - - private static IResourceChangeListener listener; - private static ResourceDeltaVisitor visitor; - - private Map removals; - private Map additions; - private Map changes; - - public ResourceDeltaVisitor register() { - if (visitor == null) - visitor = this; - if (listener == null) - listener = new IResourceChangeListener() { - public void resourceChanged(IResourceChangeEvent event) { - try { - IResourceDelta root = event.getDelta(); - IResourceDelta[] projectDeltas = root.getAffectedChildren(); - for (int i = 0; i < projectDeltas.length; i++) { - IResourceDelta delta = projectDeltas[i]; - IResource resource = delta.getResource(); - ITeamProvider provider = TeamPlugin.getManager().getProvider(resource); - if (provider instanceof CVSTeamProvider) - delta.accept(visitor); - } - visitor.handle(); - } catch (CoreException e) { - Util.logError(Policy.bind("ResourceDeltaVisitor.visitError"), e); - } - } - }; - ResourcesPlugin.getWorkspace().addResourceChangeListener(listener, IResourceChangeEvent.POST_CHANGE); - return visitor; - } - - public void deregister() { - ResourcesPlugin.getWorkspace().removeResourceChangeListener(listener); - } - - public ResourceDeltaVisitor() { - this.additions = new HashMap(); - this.removals = new HashMap(); - this.changes = new HashMap(); - } - - /** - * @see IResourceDeltaVisitor#visit(IResourceDelta) - */ - public boolean visit(IResourceDelta delta) throws CoreException { - IResource resource = delta.getResource(); - IProject project = resource.getProject(); - switch (delta.getKind()) { - case IResourceDelta.ADDED : - addAddition(project, resource); - break; - case IResourceDelta.REMOVED : - // Only record files as there's nothing we can do about folders - addRemoval(project, resource); - break; - case IResourceDelta.CHANGED : - if ((delta.getFlags() & IResourceDelta.MOVED_TO) > 0) - addAddition(project, project.getFile(delta.getMovedToPath())); - if ((delta.getFlags() & IResourceDelta.MOVED_FROM) > 0) - addRemoval(project, project.getFile(delta.getMovedFromPath())); - addChange(project, resource); - break; - } - return true; - } - - private void addChange(IProject project, IResource resource) { - List changes = (List)this.changes.get(project); - if (changes == null) { - changes = new ArrayList(); - this.changes.put(project, changes); - } - changes.add(resource); - } - - private void addAddition(IProject project, IResource resource) { - List additions = (List)this.additions.get(project); - if (additions == null) { - additions = new ArrayList(); - this.additions.put(project, additions); - } - additions.add(resource); - } - - private void addRemoval(IProject project, IResource resource) { - // Only record files as there's nothing we can do about folders - if (resource.getType() != IResource.FILE) - return; - List removals = (List)this.removals.get(project); - if (removals == null) { - removals = new ArrayList(); - this.removals.put(project, removals); - } - removals.add(resource); - } - - private void handle() { - - handleAdded(additions); - additions.clear(); - - handleRemoved(removals); - removals.clear(); - - handleChanged(changes); - changes.clear(); - } - - /** - * Handle all the additions, can be overwritten (not suggested) - * - * The map contains lists of changes mapped to the IProjects - * the changes are in. The default handling calles handleAdded - * for every entry. - */ - protected void handleAdded(Map additions) { - // Start by printing out the changes - //System.out.println("Resources added"); - Iterator i = additions.keySet().iterator(); - while (i.hasNext()) { - IProject project = (IProject)i.next(); - ITeamProvider provider = TeamPlugin.getManager().getProvider(project); - Iterator j = ((List)additions.get(project)).iterator(); - while (j.hasNext()) { - IResource resource = (IResource)j.next(); - handleAdded(project,resource); - //System.out.println(resource.toString()); - } - } - } - - /** - * Handle all the changes, can be overwritten (not suggested) - * - * The map contains lists of changes mapped to the IProjects - * the changes are in. The default handling calles handleChanged - * for every entry. - */ - protected void handleChanged(Map changes) { - // Start by printing out the changes - //System.out.println("Resources added"); - Iterator i = changes.keySet().iterator(); - while (i.hasNext()) { - IProject project = (IProject)i.next(); - ITeamProvider provider = TeamPlugin.getManager().getProvider(project); - Iterator j = ((List)changes.get(project)).iterator(); - while (j.hasNext()) { - IResource resource = (IResource)j.next(); - handleChanged(project,resource); - //System.out.println(resource.toString()); - } - } - } - - /** - * Handle all the removals, can be overwritten (not suggested) - * - * The map contains lists of changes mapped to the IProjects - * the changes are in. The default handling calles handleRemoved - * for every entry. - */ - protected void handleRemoved(Map removals) { - //System.out.println("Resources removed"); - Iterator i = removals.keySet().iterator(); - while (i.hasNext()) { - IProject project = (IProject)i.next(); - ITeamProvider provider = TeamPlugin.getManager().getProvider(project); - Iterator j = ((List)removals.get(project)).iterator(); - while (j.hasNext()) { - IResource resource = (IResource)j.next(); - handleRemoved(project,resource); - //System.out.println(resource.toString()); - } - } - } - - /** - * React on every addition - */ - protected abstract void handleAdded(IProject project,IResource resource); - - /** - * React on every removal - */ - protected abstract void handleRemoved(IProject project,IResource resource); - - /** - * React on every change - */ - protected abstract void handleChanged(IProject project,IResource resource); - -} - +package org.eclipse.team.internal.ccvs.core.util;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceChangeEvent;
+import org.eclipse.core.resources.IResourceChangeListener;
+import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.resources.IResourceDeltaVisitor;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.team.core.ITeamProvider;
+import org.eclipse.team.core.TeamPlugin;
+import org.eclipse.team.internal.ccvs.core.Policy;
+import org.eclipse.team.ccvs.core.CVSTeamProvider;
+
+public abstract class ResourceDeltaVisitor implements IResourceDeltaVisitor {
+
+ private static IResourceChangeListener listener;
+ private static ResourceDeltaVisitor visitor;
+
+ private Map removals;
+ private Map additions;
+ private Map changes;
+
+ public ResourceDeltaVisitor register() {
+ if (visitor == null)
+ visitor = this;
+ if (listener == null)
+ listener = new IResourceChangeListener() {
+ public void resourceChanged(IResourceChangeEvent event) {
+ try {
+ IResourceDelta root = event.getDelta();
+ IResourceDelta[] projectDeltas = root.getAffectedChildren();
+ for (int i = 0; i < projectDeltas.length; i++) {
+ IResourceDelta delta = projectDeltas[i];
+ IResource resource = delta.getResource();
+ ITeamProvider provider = TeamPlugin.getManager().getProvider(resource);
+ if (provider instanceof CVSTeamProvider)
+ delta.accept(visitor);
+ }
+ visitor.handle();
+ } catch (CoreException e) {
+ Util.logError(Policy.bind("ResourceDeltaVisitor.visitError"), e);
+ }
+ }
+ };
+ ResourcesPlugin.getWorkspace().addResourceChangeListener(listener, IResourceChangeEvent.POST_CHANGE);
+ return visitor;
+ }
+
+ public void deregister() {
+ ResourcesPlugin.getWorkspace().removeResourceChangeListener(listener);
+ }
+
+ public ResourceDeltaVisitor() {
+ this.additions = new HashMap();
+ this.removals = new HashMap();
+ this.changes = new HashMap();
+ }
+
+ /**
+ * @see IResourceDeltaVisitor#visit(IResourceDelta)
+ */
+ public boolean visit(IResourceDelta delta) throws CoreException {
+ IResource resource = delta.getResource();
+ IProject project = resource.getProject();
+ switch (delta.getKind()) {
+ case IResourceDelta.ADDED :
+ addAddition(project, resource);
+ break;
+ case IResourceDelta.REMOVED :
+ // Only record files as there's nothing we can do about folders
+ addRemoval(project, resource);
+ break;
+ case IResourceDelta.CHANGED :
+ if ((delta.getFlags() & IResourceDelta.MOVED_TO) > 0)
+ addAddition(project, project.getFile(delta.getMovedToPath()));
+ if ((delta.getFlags() & IResourceDelta.MOVED_FROM) > 0)
+ addRemoval(project, project.getFile(delta.getMovedFromPath()));
+ addChange(project, resource);
+ break;
+ }
+ return true;
+ }
+
+ private void addChange(IProject project, IResource resource) {
+ List changes = (List)this.changes.get(project);
+ if (changes == null) {
+ changes = new ArrayList();
+ this.changes.put(project, changes);
+ }
+ changes.add(resource);
+ }
+
+ private void addAddition(IProject project, IResource resource) {
+ List additions = (List)this.additions.get(project);
+ if (additions == null) {
+ additions = new ArrayList();
+ this.additions.put(project, additions);
+ }
+ additions.add(resource);
+ }
+
+ private void addRemoval(IProject project, IResource resource) {
+ // Only record files as there's nothing we can do about folders
+ if (resource.getType() != IResource.FILE)
+ return;
+ List removals = (List)this.removals.get(project);
+ if (removals == null) {
+ removals = new ArrayList();
+ this.removals.put(project, removals);
+ }
+ removals.add(resource);
+ }
+
+ private void handle() {
+
+ handleAdded(additions);
+ additions.clear();
+
+ handleRemoved(removals);
+ removals.clear();
+
+ handleChanged(changes);
+ changes.clear();
+ }
+
+ /**
+ * Handle all the additions, can be overwritten (not suggested)
+ *
+ * The map contains lists of changes mapped to the IProjects
+ * the changes are in. The default handling calles handleAdded
+ * for every entry.
+ */
+ protected void handleAdded(Map additions) {
+ // Start by printing out the changes
+ //System.out.println("Resources added");
+ Iterator i = additions.keySet().iterator();
+ while (i.hasNext()) {
+ IProject project = (IProject)i.next();
+ ITeamProvider provider = TeamPlugin.getManager().getProvider(project);
+ Iterator j = ((List)additions.get(project)).iterator();
+ while (j.hasNext()) {
+ IResource resource = (IResource)j.next();
+ handleAdded(project,resource);
+ //System.out.println(resource.toString());
+ }
+ }
+ }
+
+ /**
+ * Handle all the changes, can be overwritten (not suggested)
+ *
+ * The map contains lists of changes mapped to the IProjects
+ * the changes are in. The default handling calles handleChanged
+ * for every entry.
+ */
+ protected void handleChanged(Map changes) {
+ // Start by printing out the changes
+ //System.out.println("Resources added");
+ Iterator i = changes.keySet().iterator();
+ while (i.hasNext()) {
+ IProject project = (IProject)i.next();
+ ITeamProvider provider = TeamPlugin.getManager().getProvider(project);
+ Iterator j = ((List)changes.get(project)).iterator();
+ while (j.hasNext()) {
+ IResource resource = (IResource)j.next();
+ handleChanged(project,resource);
+ //System.out.println(resource.toString());
+ }
+ }
+ }
+
+ /**
+ * Handle all the removals, can be overwritten (not suggested)
+ *
+ * The map contains lists of changes mapped to the IProjects
+ * the changes are in. The default handling calles handleRemoved
+ * for every entry.
+ */
+ protected void handleRemoved(Map removals) {
+ //System.out.println("Resources removed");
+ Iterator i = removals.keySet().iterator();
+ while (i.hasNext()) {
+ IProject project = (IProject)i.next();
+ ITeamProvider provider = TeamPlugin.getManager().getProvider(project);
+ Iterator j = ((List)removals.get(project)).iterator();
+ while (j.hasNext()) {
+ IResource resource = (IResource)j.next();
+ handleRemoved(project,resource);
+ //System.out.println(resource.toString());
+ }
+ }
+ }
+
+ /**
+ * React on every addition
+ */
+ protected abstract void handleAdded(IProject project,IResource resource);
+
+ /**
+ * React on every removal
+ */
+ protected abstract void handleRemoved(IProject project,IResource resource);
+
+ /**
+ * React on every change
+ */
+ protected abstract void handleChanged(IProject project,IResource resource);
+
+}
+
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/StringMatcher.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/StringMatcher.java index 3af537687..6255b4661 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/StringMatcher.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/StringMatcher.java @@ -1,385 +1,385 @@ -package org.eclipse.team.internal.ccvs.core.util; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ - -import java.util.*; - -/** - * A string pattern matcher, suppporting * and ? wildcards. - * Note: code copied from org.eclipse.jdt.internal.core.util.StringMatcher on April 3, 2001 - * (version 0.1 - 010901H18 [rename jbl]). - */ -public class StringMatcher { - protected String fPattern; - protected int fLength; // pattern length - protected boolean fIgnoreWildCards; - protected boolean fIgnoreCase; - protected boolean fHasLeadingStar; - protected boolean fHasTrailingStar; - protected String fSegments[]; //the given pattern is split into * separated segments - - /* boundary value beyond which we don't need to search in the text */ - protected int fBound = 0; - - - protected static final char fSingleWildCard = '\u0000'; - - public static class Position { - int start; //inclusive - int end; //exclusive - public Position(int start, int end) { - this.start = start; - this.end = end; - } - public int getStart() { - return start; - } - public int getEnd() { - return end; - } - } - /** - * Find the first occurrence of the pattern between <code>start</code)(inclusive) - * and <code>end</code>(exclusive). - * @param <code>text</code>, the String object to search in - * @param <code>start</code>, the starting index of the search range, inclusive - * @param <code>end</code>, the ending index of the search range, exclusive - * @return an <code>StringMatcher.Position</code> object that keeps the starting - * (inclusive) and ending positions (exclusive) of the first occurrence of the - * pattern in the specified range of the text; return null if not found or subtext - * is empty (start==end). A pair of zeros is returned if pattern is empty string - * Note that for pattern like "*abc*" with leading and trailing stars, position of "abc" - * is returned. For a pattern like"*??*" in text "abcdf", (1,3) is returned - */ - - public StringMatcher.Position find(String text, int start, int end) { - if (fPattern == null|| text == null) - throw new IllegalArgumentException(); - - int tlen = text.length(); - if (start < 0) - start = 0; - if (end > tlen) - end = tlen; - if (end < 0 ||start >= end ) - return null; - if (fLength == 0) - return new Position(start, start); - if (fIgnoreWildCards) { - int x = posIn(text, start, end); - if (x < 0) - return null; - return new Position(x, x+fLength); - } - - int segCount = fSegments.length; - if (segCount == 0)//pattern contains only '*'(s) - return new Position (start, end); - - int curPos = start; - int matchStart = -1; - for (int i = 0; i < segCount && curPos < end; ++i) { - String current = fSegments[i]; - int nextMatch = regExpPosIn(text, curPos, end, current); - if (nextMatch < 0 ) - return null; - if(i == 0) - matchStart = nextMatch; - curPos = nextMatch + current.length(); - } - return new Position(matchStart, curPos); - } - /** - * StringMatcher constructor takes in a String object that is a simple - * pattern which may contain * for 0 and many characters and - * ? for exactly one character. - * - * Literal '*' and '?' characters must be escaped in the pattern - * e.g., "\*" means literal "*", etc. - * - * Escaping any other character (including the escape character itself), - * just results in that character in the pattern. - * e.g., "\a" means "a" and "\\" means "\" - * - * If invoking the StringMatcher with string literals in Java, don't forget - * escape characters are represented by "\\". - * - * @param aPattern the pattern to match text against - * @param ignoreCase if true, case is ignored - * @param ignoreWildCards if true, wild cards and their escape sequences are ignored - * (everything is taken literally). - */ - public StringMatcher(String aPattern, boolean ignoreCase, boolean ignoreWildCards) { - fIgnoreCase = ignoreCase; - fIgnoreWildCards = ignoreWildCards; - fLength = aPattern.length(); - - /* convert case */ - if (fIgnoreCase) { - fPattern = aPattern.toUpperCase(); - } else { - fPattern = aPattern; - } - - if (fIgnoreWildCards) { - parseNoWildCards(); - } else { - parseWildCards(); - } - } - /** - * Given the starting (inclusive) and the ending (exclusive) poisitions in the - * <code>text</code>, determine if the given substring matches with aPattern - * @return true if the specified portion of the text matches the pattern - * @param String <code>text</code>, a String object that contains the substring to match - * @param int <code>start<code> marks the starting position (inclusive) of the substring - * @param int <code>end<code> marks the ending index (exclusive) of the substring - */ - public boolean match(String text, int start, int end) { - if (null == fPattern || null == text) - throw new IllegalArgumentException(); - - if (start >= end) - return false; - - if (fIgnoreWildCards) - return fPattern.regionMatches(fIgnoreCase, 0, text, start, fLength); - int segCount = fSegments.length; - if (segCount == 0)//pattern contains only '*'(s) or empty pattern - return true; - if (start == end) - return fLength == 0; - if (fLength == 0) - return start == end; - - int tlen = text.length(); - if (start < 0) - start = 0; - if (end > tlen) - end = tlen; - - int tCurPos = start; - int bound = end - fBound; - if ( bound < 0) - return false; - int i=0; - String current = fSegments[i]; - int segLength = current.length(); - - /* process first segment */ - if (!fHasLeadingStar){ - if(!regExpRegionMatches(text, start, current, 0, segLength)) { - return false; - } else { - ++i; - tCurPos = tCurPos + segLength; - } - } - - /* process middle segments */ - for ( ; i < segCount && tCurPos <= bound; ++i) { - current = fSegments[i]; - int currentMatch; - int k = current.indexOf(fSingleWildCard); - if (k < 0) { - currentMatch = textPosIn(text, tCurPos, end, current); - if (currentMatch < 0) - return false; - } else { - currentMatch = regExpPosIn(text, tCurPos, end, current); - if (currentMatch < 0) - return false; - } - tCurPos = currentMatch + current.length(); - } - - /* process final segment */ - if (!fHasTrailingStar && tCurPos != end) { - int clen = current.length(); - return regExpRegionMatches(text, end - clen, current, 0, clen); - } - return i == segCount ; - } - /** - * match the given <code>text</code> with the pattern - * @return true if matched eitherwise false - * @param <code>text</code>, a String object - */ - public boolean match(String text) { - return match(text, 0, text.length()); - } - /** - * This method parses the given pattern into segments seperated by wildcard '*' characters. - * Since wildcards are not being used in this case, the pattern consists of a single segment. - */ - private void parseNoWildCards() { - fSegments = new String[1]; - fSegments[0] = fPattern; - fBound = fLength; - } - /** - * This method parses the given pattern into segments seperated by wildcard '*' characters. - * @param p, a String object that is a simple regular expression with * and/or ? - */ - private void parseWildCards() { - if(fPattern.startsWith("*")) - fHasLeadingStar = true; - if(fPattern.endsWith("*")) { - /* make sure it's not an escaped wildcard */ - if (fLength > 1 && fPattern.charAt(fLength - 2) != '\\') { - fHasTrailingStar = true; - } - } - - Vector temp = new Vector(); - - int pos = 0; - StringBuffer buf = new StringBuffer(); - while (pos < fLength) { - char c = fPattern.charAt(pos++); - switch (c) { - case '\\': - if (pos >= fLength) { - buf.append(c); - } else { - char next = fPattern.charAt(pos++); - /* if it's an escape sequence */ - if (next == '*' || next == '?' || next == '\\') { - buf.append(next); - } else { - /* not an escape sequence, just insert literally */ - buf.append(c); - buf.append(next); - } - } - break; - case '*': - if (buf.length() > 0) { - /* new segment */ - temp.addElement(buf.toString()); - fBound += buf.length(); - buf.setLength(0); - } - break; - case '?': - /* append special character representing single match wildcard */ - buf.append(fSingleWildCard); - break; - default: - buf.append(c); - } - } - - /* add last buffer to segment list */ - if (buf.length() > 0) { - temp.addElement(buf.toString()); - fBound += buf.length(); - } - - fSegments = new String[temp.size()]; - temp.copyInto(fSegments); - } - /** - * @param <code>text</code>, a string which contains no wildcard - * @param <code>start</code>, the starting index in the text for search, inclusive - * @param <code>end</code>, the stopping point of search, exclusive - * @return the starting index in the text of the pattern , or -1 if not found - */ - protected int posIn(String text, int start, int end) {//no wild card in pattern - int max = end - fLength; - - if (!fIgnoreCase) { - int i = text.indexOf(fPattern, start); - if (i == -1 || i > max) - return -1; - return i; - } - - for (int i = start; i <= max; ++i) { - if (text.regionMatches(true, i, fPattern, 0, fLength)) - return i; - } - - return -1; - } - /** - * @param <code>text</code>, a simple regular expression that may only contain '?'(s) - * @param <code>start</code>, the starting index in the text for search, inclusive - * @param <code>end</code>, the stopping point of search, exclusive - * @param <code>p</code>, a simple regular expression that may contains '?' - * @param <code>caseIgnored</code>, wether the pattern is not casesensitive - * @return the starting index in the text of the pattern , or -1 if not found - */ - protected int regExpPosIn(String text, int start, int end, String p) { - int plen = p.length(); - - int max = end - plen; - for (int i = start; i <= max; ++i) { - if (regExpRegionMatches(text, i, p, 0, plen)) - return i; - } - return -1; - } - /** - * - * @return boolean - * @param <code>text</code>, a String to match - * @param <code>start</code>, int that indicates the starting index of match, inclusive - * @param <code>end</code> int that indicates the ending index of match, exclusive - * @param <code>p</code>, String, String, a simple regular expression that may contain '?' - * @param <code>ignoreCase</code>, boolean indicating wether code>p</code> is case sensitive - */ - protected boolean regExpRegionMatches(String text, int tStart, String p, int pStart, int plen) { - while (plen-- > 0) { - char tchar = text.charAt(tStart++); - char pchar = p.charAt(pStart++); - - /* process wild cards */ - if (!fIgnoreWildCards) { - /* skip single wild cards */ - if (pchar == fSingleWildCard) { - continue; - } - } - if (pchar == tchar) - continue; - if (fIgnoreCase) { - char tc = Character.toUpperCase(tchar); - if (tc == pchar) - continue; - } - return false; - } - return true; - } - /** - * @param <code>text</code>, the string to match - * @param <code>start</code>, the starting index in the text for search, inclusive - * @param <code>end</code>, the stopping point of search, exclusive - * @param code>p</code>, a string that has no wildcard - * @param <code>ignoreCase</code>, boolean indicating wether code>p</code> is case sensitive - * @return the starting index in the text of the pattern , or -1 if not found - */ - protected int textPosIn(String text, int start, int end, String p) { - - int plen = p.length(); - int max = end - plen; - - if (!fIgnoreCase) { - int i = text.indexOf(p, start); - if (i == -1 || i > max) - return -1; - return i; - } - - for (int i = 0; i <= max; ++i) { - if (text.regionMatches(true, i, p, 0, plen)) - return i; - } - - return -1; - } -} +package org.eclipse.team.internal.ccvs.core.util;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.util.*;
+
+/**
+ * A string pattern matcher, suppporting * and ? wildcards.
+ * Note: code copied from org.eclipse.jdt.internal.core.util.StringMatcher on April 3, 2001
+ * (version 0.1 - 010901H18 [rename jbl]).
+ */
+public class StringMatcher {
+ protected String fPattern;
+ protected int fLength; // pattern length
+ protected boolean fIgnoreWildCards;
+ protected boolean fIgnoreCase;
+ protected boolean fHasLeadingStar;
+ protected boolean fHasTrailingStar;
+ protected String fSegments[]; //the given pattern is split into * separated segments
+
+ /* boundary value beyond which we don't need to search in the text */
+ protected int fBound = 0;
+
+
+ protected static final char fSingleWildCard = '\u0000';
+
+ public static class Position {
+ int start; //inclusive
+ int end; //exclusive
+ public Position(int start, int end) {
+ this.start = start;
+ this.end = end;
+ }
+ public int getStart() {
+ return start;
+ }
+ public int getEnd() {
+ return end;
+ }
+ }
+ /**
+ * Find the first occurrence of the pattern between <code>start</code)(inclusive)
+ * and <code>end</code>(exclusive).
+ * @param <code>text</code>, the String object to search in
+ * @param <code>start</code>, the starting index of the search range, inclusive
+ * @param <code>end</code>, the ending index of the search range, exclusive
+ * @return an <code>StringMatcher.Position</code> object that keeps the starting
+ * (inclusive) and ending positions (exclusive) of the first occurrence of the
+ * pattern in the specified range of the text; return null if not found or subtext
+ * is empty (start==end). A pair of zeros is returned if pattern is empty string
+ * Note that for pattern like "*abc*" with leading and trailing stars, position of "abc"
+ * is returned. For a pattern like"*??*" in text "abcdf", (1,3) is returned
+ */
+
+ public StringMatcher.Position find(String text, int start, int end) {
+ if (fPattern == null|| text == null)
+ throw new IllegalArgumentException();
+
+ int tlen = text.length();
+ if (start < 0)
+ start = 0;
+ if (end > tlen)
+ end = tlen;
+ if (end < 0 ||start >= end )
+ return null;
+ if (fLength == 0)
+ return new Position(start, start);
+ if (fIgnoreWildCards) {
+ int x = posIn(text, start, end);
+ if (x < 0)
+ return null;
+ return new Position(x, x+fLength);
+ }
+
+ int segCount = fSegments.length;
+ if (segCount == 0)//pattern contains only '*'(s)
+ return new Position (start, end);
+
+ int curPos = start;
+ int matchStart = -1;
+ for (int i = 0; i < segCount && curPos < end; ++i) {
+ String current = fSegments[i];
+ int nextMatch = regExpPosIn(text, curPos, end, current);
+ if (nextMatch < 0 )
+ return null;
+ if(i == 0)
+ matchStart = nextMatch;
+ curPos = nextMatch + current.length();
+ }
+ return new Position(matchStart, curPos);
+ }
+ /**
+ * StringMatcher constructor takes in a String object that is a simple
+ * pattern which may contain * for 0 and many characters and
+ * ? for exactly one character.
+ *
+ * Literal '*' and '?' characters must be escaped in the pattern
+ * e.g., "\*" means literal "*", etc.
+ *
+ * Escaping any other character (including the escape character itself),
+ * just results in that character in the pattern.
+ * e.g., "\a" means "a" and "\\" means "\"
+ *
+ * If invoking the StringMatcher with string literals in Java, don't forget
+ * escape characters are represented by "\\".
+ *
+ * @param aPattern the pattern to match text against
+ * @param ignoreCase if true, case is ignored
+ * @param ignoreWildCards if true, wild cards and their escape sequences are ignored
+ * (everything is taken literally).
+ */
+ public StringMatcher(String aPattern, boolean ignoreCase, boolean ignoreWildCards) {
+ fIgnoreCase = ignoreCase;
+ fIgnoreWildCards = ignoreWildCards;
+ fLength = aPattern.length();
+
+ /* convert case */
+ if (fIgnoreCase) {
+ fPattern = aPattern.toUpperCase();
+ } else {
+ fPattern = aPattern;
+ }
+
+ if (fIgnoreWildCards) {
+ parseNoWildCards();
+ } else {
+ parseWildCards();
+ }
+ }
+ /**
+ * Given the starting (inclusive) and the ending (exclusive) poisitions in the
+ * <code>text</code>, determine if the given substring matches with aPattern
+ * @return true if the specified portion of the text matches the pattern
+ * @param String <code>text</code>, a String object that contains the substring to match
+ * @param int <code>start<code> marks the starting position (inclusive) of the substring
+ * @param int <code>end<code> marks the ending index (exclusive) of the substring
+ */
+ public boolean match(String text, int start, int end) {
+ if (null == fPattern || null == text)
+ throw new IllegalArgumentException();
+
+ if (start >= end)
+ return false;
+
+ if (fIgnoreWildCards)
+ return fPattern.regionMatches(fIgnoreCase, 0, text, start, fLength);
+ int segCount = fSegments.length;
+ if (segCount == 0)//pattern contains only '*'(s) or empty pattern
+ return true;
+ if (start == end)
+ return fLength == 0;
+ if (fLength == 0)
+ return start == end;
+
+ int tlen = text.length();
+ if (start < 0)
+ start = 0;
+ if (end > tlen)
+ end = tlen;
+
+ int tCurPos = start;
+ int bound = end - fBound;
+ if ( bound < 0)
+ return false;
+ int i=0;
+ String current = fSegments[i];
+ int segLength = current.length();
+
+ /* process first segment */
+ if (!fHasLeadingStar){
+ if(!regExpRegionMatches(text, start, current, 0, segLength)) {
+ return false;
+ } else {
+ ++i;
+ tCurPos = tCurPos + segLength;
+ }
+ }
+
+ /* process middle segments */
+ for ( ; i < segCount && tCurPos <= bound; ++i) {
+ current = fSegments[i];
+ int currentMatch;
+ int k = current.indexOf(fSingleWildCard);
+ if (k < 0) {
+ currentMatch = textPosIn(text, tCurPos, end, current);
+ if (currentMatch < 0)
+ return false;
+ } else {
+ currentMatch = regExpPosIn(text, tCurPos, end, current);
+ if (currentMatch < 0)
+ return false;
+ }
+ tCurPos = currentMatch + current.length();
+ }
+
+ /* process final segment */
+ if (!fHasTrailingStar && tCurPos != end) {
+ int clen = current.length();
+ return regExpRegionMatches(text, end - clen, current, 0, clen);
+ }
+ return i == segCount ;
+ }
+ /**
+ * match the given <code>text</code> with the pattern
+ * @return true if matched eitherwise false
+ * @param <code>text</code>, a String object
+ */
+ public boolean match(String text) {
+ return match(text, 0, text.length());
+ }
+ /**
+ * This method parses the given pattern into segments seperated by wildcard '*' characters.
+ * Since wildcards are not being used in this case, the pattern consists of a single segment.
+ */
+ private void parseNoWildCards() {
+ fSegments = new String[1];
+ fSegments[0] = fPattern;
+ fBound = fLength;
+ }
+ /**
+ * This method parses the given pattern into segments seperated by wildcard '*' characters.
+ * @param p, a String object that is a simple regular expression with * and/or ?
+ */
+ private void parseWildCards() {
+ if(fPattern.startsWith("*"))
+ fHasLeadingStar = true;
+ if(fPattern.endsWith("*")) {
+ /* make sure it's not an escaped wildcard */
+ if (fLength > 1 && fPattern.charAt(fLength - 2) != '\\') {
+ fHasTrailingStar = true;
+ }
+ }
+
+ Vector temp = new Vector();
+
+ int pos = 0;
+ StringBuffer buf = new StringBuffer();
+ while (pos < fLength) {
+ char c = fPattern.charAt(pos++);
+ switch (c) {
+ case '\\':
+ if (pos >= fLength) {
+ buf.append(c);
+ } else {
+ char next = fPattern.charAt(pos++);
+ /* if it's an escape sequence */
+ if (next == '*' || next == '?' || next == '\\') {
+ buf.append(next);
+ } else {
+ /* not an escape sequence, just insert literally */
+ buf.append(c);
+ buf.append(next);
+ }
+ }
+ break;
+ case '*':
+ if (buf.length() > 0) {
+ /* new segment */
+ temp.addElement(buf.toString());
+ fBound += buf.length();
+ buf.setLength(0);
+ }
+ break;
+ case '?':
+ /* append special character representing single match wildcard */
+ buf.append(fSingleWildCard);
+ break;
+ default:
+ buf.append(c);
+ }
+ }
+
+ /* add last buffer to segment list */
+ if (buf.length() > 0) {
+ temp.addElement(buf.toString());
+ fBound += buf.length();
+ }
+
+ fSegments = new String[temp.size()];
+ temp.copyInto(fSegments);
+ }
+ /**
+ * @param <code>text</code>, a string which contains no wildcard
+ * @param <code>start</code>, the starting index in the text for search, inclusive
+ * @param <code>end</code>, the stopping point of search, exclusive
+ * @return the starting index in the text of the pattern , or -1 if not found
+ */
+ protected int posIn(String text, int start, int end) {//no wild card in pattern
+ int max = end - fLength;
+
+ if (!fIgnoreCase) {
+ int i = text.indexOf(fPattern, start);
+ if (i == -1 || i > max)
+ return -1;
+ return i;
+ }
+
+ for (int i = start; i <= max; ++i) {
+ if (text.regionMatches(true, i, fPattern, 0, fLength))
+ return i;
+ }
+
+ return -1;
+ }
+ /**
+ * @param <code>text</code>, a simple regular expression that may only contain '?'(s)
+ * @param <code>start</code>, the starting index in the text for search, inclusive
+ * @param <code>end</code>, the stopping point of search, exclusive
+ * @param <code>p</code>, a simple regular expression that may contains '?'
+ * @param <code>caseIgnored</code>, wether the pattern is not casesensitive
+ * @return the starting index in the text of the pattern , or -1 if not found
+ */
+ protected int regExpPosIn(String text, int start, int end, String p) {
+ int plen = p.length();
+
+ int max = end - plen;
+ for (int i = start; i <= max; ++i) {
+ if (regExpRegionMatches(text, i, p, 0, plen))
+ return i;
+ }
+ return -1;
+ }
+ /**
+ *
+ * @return boolean
+ * @param <code>text</code>, a String to match
+ * @param <code>start</code>, int that indicates the starting index of match, inclusive
+ * @param <code>end</code> int that indicates the ending index of match, exclusive
+ * @param <code>p</code>, String, String, a simple regular expression that may contain '?'
+ * @param <code>ignoreCase</code>, boolean indicating wether code>p</code> is case sensitive
+ */
+ protected boolean regExpRegionMatches(String text, int tStart, String p, int pStart, int plen) {
+ while (plen-- > 0) {
+ char tchar = text.charAt(tStart++);
+ char pchar = p.charAt(pStart++);
+
+ /* process wild cards */
+ if (!fIgnoreWildCards) {
+ /* skip single wild cards */
+ if (pchar == fSingleWildCard) {
+ continue;
+ }
+ }
+ if (pchar == tchar)
+ continue;
+ if (fIgnoreCase) {
+ char tc = Character.toUpperCase(tchar);
+ if (tc == pchar)
+ continue;
+ }
+ return false;
+ }
+ return true;
+ }
+ /**
+ * @param <code>text</code>, the string to match
+ * @param <code>start</code>, the starting index in the text for search, inclusive
+ * @param <code>end</code>, the stopping point of search, exclusive
+ * @param code>p</code>, a string that has no wildcard
+ * @param <code>ignoreCase</code>, boolean indicating wether code>p</code> is case sensitive
+ * @return the starting index in the text of the pattern , or -1 if not found
+ */
+ protected int textPosIn(String text, int start, int end, String p) {
+
+ int plen = p.length();
+ int max = end - plen;
+
+ if (!fIgnoreCase) {
+ int i = text.indexOf(p, start);
+ if (i == -1 || i > max)
+ return -1;
+ return i;
+ }
+
+ for (int i = 0; i <= max; ++i) {
+ if (text.regionMatches(true, i, p, 0, plen))
+ return i;
+ }
+
+ return -1;
+ }
+}
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/SyncFileUtil.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/SyncFileUtil.java new file mode 100644 index 000000000..ea89df969 --- /dev/null +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/SyncFileUtil.java @@ -0,0 +1,226 @@ +package org.eclipse.team.internal.ccvs.core.util;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+import org.eclipse.team.ccvs.core.CVSTag;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.resources.CVSEntryLineTag;
+import org.eclipse.team.internal.ccvs.core.resources.FolderSyncInfo;
+import org.eclipse.team.internal.ccvs.core.resources.ResourceSyncInfo;
+
+public class SyncFileUtil {
+
+ // All possible files available in the CVS subdir
+
+ private static final String REPOSITORY = "Repository";
+ private static final String ROOT = "Root";
+ private static final String STATIC = "Entries.Static";
+ private static final String TAG = "Tag";
+ private static final String ENTRIES = "Entries";
+ private static final String PERMISSIONS = "Permissions";
+ private static final String ENTRIES_LOG="Entries.Log";
+
+ // Some older CVS clients may of added a line to the entries file consisting
+ // of only a 'D'. It is safe to ingnore these entries.
+ private static final String FOLDER_TAG="D";
+
+ public static ResourceSyncInfo[] readEntriesFile(File parent) throws CVSException {
+
+ if(!getCVSSubdirectory(parent).exists()) {
+ return new ResourceSyncInfo[0];
+ }
+
+ Map infos = new TreeMap();
+ String[] entries = getContents(parent, ENTRIES);
+ String[] permissions = getContents(parent, PERMISSIONS);
+
+ if (entries == null) {
+ return new ResourceSyncInfo[0];
+ }
+
+ for (int i = 0; i < entries.length; i++) {
+ String line = entries[i];
+ if(!FOLDER_TAG.equals(line) && !"".equals(line)) {
+ ResourceSyncInfo info = new ResourceSyncInfo(line, null);
+ infos.put(info.getName(), info);
+ }
+ }
+
+ if (permissions != null) {
+ for (int i = 0; i < permissions.length; i++) {
+ if ("".equals(permissions[i])) {
+ continue;
+ }
+ String line = permissions[i];
+ String name = line.substring(1,line.indexOf("/",1));
+ ResourceSyncInfo info = (ResourceSyncInfo) infos.get(name);
+ if (info == null) {
+ throw new CVSException("Entries-File modified");
+ }
+ info.setPermissionLine(line);
+ }
+ }
+
+ return (ResourceSyncInfo[])infos.values().toArray(new ResourceSyncInfo[infos.size()]);
+ }
+
+ public static void writeEntriesFile(File parent, ResourceSyncInfo[] infos) throws CVSException {
+
+ if(!getCVSSubdirectory(parent).exists()) {
+ getCVSSubdirectory(parent).mkdir();
+ }
+
+ String[] entries = new String[infos.length];
+ List permissions = new ArrayList(infos.length);
+
+ for(int i = 0; i < infos.length; i++){
+ entries[i] = infos[i].getEntryLine(true);
+ if (!infos[i].isDirectory()) {
+ permissions.add(infos[i].getPermissionLine());
+ }
+ }
+ setContents(parent, ENTRIES, entries);
+ setContents(parent, PERMISSIONS, (String[])permissions.toArray(new String[permissions.size()]));
+ }
+
+ public static FolderSyncInfo readFolderConfig(File parent) throws CVSException {
+
+ if(!getCVSSubdirectory(parent).exists()) {
+ return null;
+ }
+
+ String staticDir = readLine(parent, STATIC);
+ String repo = readLine(parent, REPOSITORY);
+ String root = readLine(parent, ROOT);
+ String tag = readLine(parent, TAG);
+
+ boolean isStatic = false;
+ if (staticDir != null)
+ isStatic = true;
+
+ return new FolderSyncInfo(repo, root, tag, isStatic);
+ }
+
+ public static void writeFolderConfig(File parent, FolderSyncInfo info) throws CVSException {
+
+ if(!getCVSSubdirectory(parent).exists()) {
+ getCVSSubdirectory(parent).mkdir();
+ }
+
+ writeLine(parent, ROOT, info.getRoot());
+ if (info.getTag() != null)
+ writeLine(parent, TAG, info.getTag().toEntryLineFormat());
+ if(info.getIsStatic()) {
+ writeLine(parent, STATIC, ""); // touch file
+ }
+ writeLine(parent, REPOSITORY, info.getRepository());
+ }
+
+ protected static void setContents(File parent, String filename, String[] contents) throws CVSException {
+
+ File propertyFile = new File(getCVSSubdirectory(parent), filename);
+
+ if (contents == null) {
+ propertyFile.delete();
+ } else {
+ FileUtil.writeLines(propertyFile,contents);
+ }
+ }
+
+ protected static void writeLine(File parent, String filename, String content) throws CVSException {
+ if (content == null) {
+ setContents(parent, filename, null);
+ } else {
+ setContents(parent, filename, new String[]{content});
+ }
+ }
+
+ protected static String readLine(File parent, String filename) throws CVSException {
+ String[] contents = getContents(parent, filename);
+ if (contents == null) {
+ return null;
+ } else if (contents.length == 0) {
+ return "";
+ } else {
+ return contents[0];
+ }
+ }
+
+ protected static String[] getContents(File parent, String filename) throws CVSException {
+
+ File propertyFile = new File(getCVSSubdirectory(parent), filename);
+
+ // If the property does not exsist we return null
+ // this is specified
+ if (propertyFile.exists()) {
+ return FileUtil.readLines(propertyFile);
+ } else {
+ return null;
+ }
+ }
+
+ public static File getCVSSubdirectory(File parent) {
+ return new File(parent, "CVS");
+ }
+
+ public static void mergeEntriesLogFiles(File root) throws CVSException {
+
+ String FOLDER_TAG="D";
+ String ADD_TAG="A ";
+ String REMOVE_TAG="R ";
+
+ File[] dirs = root.listFiles(new FileFilter() {
+ public boolean accept(File file) {
+ return file.isDirectory() && !file.getName().equals("CVS");
+ }
+ });
+
+ for (int i = 0; i < dirs.length; i++) {
+ mergeEntriesLogFiles(dirs[i]); + }
+
+ File logEntriesFile = new File(getCVSSubdirectory(root), ENTRIES_LOG);
+ File entriesFile = new File(getCVSSubdirectory(root), ENTRIES);
+
+ if (!logEntriesFile.exists()) {
+ // If we do not have an Entries.Log file we are done because there is nothing
+ // to merge (this includes the case where we do not have CVSDirectory)
+ return;
+ }
+
+ // The map contains the name of the resource as the key and the entryLine as the
+ // value
+ // "new ResourceSyncInfo(entryLine,null)).getName()" ist used to parse the name
+ // out of the entryLine and shoud maybe be replaced sometime
+
+ Map mergedEntries = new HashMap();
+
+ String[] entries = FileUtil.readLines(entriesFile);
+ for (int i = 0; i < entries.length; i++) {
+ if (!FOLDER_TAG.equals(entries[i])) {
+ mergedEntries.put((new ResourceSyncInfo(entries[i],null)).getName(),entries[i]);
+ } + }
+
+ String[] logEntries = FileUtil.readLines(logEntriesFile);
+ for (int i = 0; i < logEntries.length; i++) {
+
+ if (logEntries[i].startsWith(ADD_TAG)) {
+ String newEntry = logEntries[i].substring(ADD_TAG.length());
+ mergedEntries.put((new ResourceSyncInfo(newEntry,null)).getName(),newEntry);
+ } else if (logEntries[i].startsWith(REMOVE_TAG)) {
+ String newEntry = logEntries[i].substring(REMOVE_TAG.length());
+ mergedEntries.remove((new ResourceSyncInfo(newEntry,null)).getName());
+ }
+ }
+
+ FileUtil.writeLines(entriesFile,(String[]) mergedEntries.values().toArray(new String[mergedEntries.size()]));
+ logEntriesFile.delete();
+ }
+}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/Util.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/Util.java index f6d260d3b..6797f8c9f 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/Util.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/util/Util.java @@ -243,30 +243,6 @@ public class Util { return result.toString();
}
-// /**
-// * not used
-// */
-// public static IProgressMonitor monitorFor(IProgressMonitor monitor) {
-// if (monitor == null)
-// return new NullProgressMonitor();
-// return monitor;
-// }
-//
-// /**
-// * not used
-// */
-// public static IProgressMonitor subMonitorFor(
-// IProgressMonitor monitor,
-// int ticks,
-// int style) {
-// if (monitor == null)
-// return new NullProgressMonitor();
-// if (monitor instanceof NullProgressMonitor)
-// return monitor;
-// return new SubProgressMonitor(monitor, ticks, style);
-// }
-
-
/**
* Get the extention of the path of resource
* relative to the path of root
|