diff options
author | Michael Valenta | 2002-01-23 19:09:24 +0000 |
---|---|---|
committer | Michael Valenta | 2002-01-23 19:09:24 +0000 |
commit | eb11cdd6bf1a07ce276d4a5c54c7afde0521bab0 (patch) | |
tree | cb6a4c8d45ad93fe05853270006d882290a7e00c | |
parent | 6c94c517c324558dfde8cd371d9792b9272be1e4 (diff) | |
download | eclipse.platform.team-eb11cdd6bf1a07ce276d4a5c54c7afde0521bab0.tar.gz eclipse.platform.team-eb11cdd6bf1a07ce276d4a5c54c7afde0521bab0.tar.xz eclipse.platform.team-eb11cdd6bf1a07ce276d4a5c54c7afde0521bab0.zip |
Updates due to Command refactoring
63 files changed, 3815 insertions, 1324 deletions
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/Attic/CVSStatus.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/Attic/CVSStatus.java index 623663080..be80c83ad 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/Attic/CVSStatus.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/Attic/CVSStatus.java @@ -1,48 +1,48 @@ -package org.eclipse.team.internal.ccvs.core;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved.
- */
-
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.team.ccvs.core.CVSProviderPlugin;
-
-public class CVSStatus extends Status{
-
- IPath path;
-
- public CVSStatus(
- int type,
- int code,
- IPath path,
- String message,
- Throwable exception) {
- super(type, CVSProviderPlugin.ID, code, message, exception);
- this.path = path;
- }
-
- public CVSStatus(int code, String message) {
- this(code, code, null, message, null);
- }
-
- public CVSStatus(int code, IPath path, String message) {
- this(code, code, path, message, null);
- }
-
- public CVSStatus(int code, IPath path, String message, Throwable exception) {
- this(code, code, path, message, exception);
- }
-
- /**
- * @see IResourceStatus#getPath
- */
- public IPath getPath() {
- return path;
- }
-
- protected static int getSeverity(int code) {
- return code;
- }
+package org.eclipse.team.internal.ccvs.core; + +/* + * (c) Copyright IBM Corp. 2000, 2001. + * All Rights Reserved. + */ + +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Status; +import org.eclipse.team.ccvs.core.CVSProviderPlugin; + +public class CVSStatus extends Status{ + + IPath path; + + public CVSStatus( + int type, + int code, + IPath path, + String message, + Throwable exception) { + super(type, CVSProviderPlugin.ID, code, message, exception); + this.path = path; + } + + public CVSStatus(int code, String message) { + this(code, code, null, message, null); + } + + public CVSStatus(int code, IPath path, String message) { + this(code, code, path, message, null); + } + + public CVSStatus(int code, IPath path, String message, Throwable exception) { + this(code, code, path, message, exception); + } + + /** + * @see IResourceStatus#getPath + */ + public IPath getPath() { + return path; + } + + protected static int getSeverity(int code) { + return code; + } }
\ No newline at end of file diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSDiffException.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSDiffException.java index d993fa9d8..86d4a16d3 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSDiffException.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSDiffException.java @@ -1,25 +1,25 @@ -package org.eclipse.team.internal.ccvs.core;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved.
- */
-
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IStatus;
-
-/**
- * This is a special Exception for the diff command and is
- * thrown when there is a difference between the two
- * compared files (this is the default behavior of the
- * diff-command)
- */
-public class CVSDiffException extends CVSException {
-
- public CVSDiffException() {
- super(Policy.bind(("CVSDiffException.message")));
- }
-
-
-}
-
+package org.eclipse.team.internal.ccvs.core; + +/* + * (c) Copyright IBM Corp. 2000, 2001. + * All Rights Reserved. + */ + +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; + +/** + * This is a special Exception for the diff command and is + * thrown when there is a difference between the two + * compared files (this is the default behavior of the + * diff-command) + */ +public class CVSDiffException extends CVSException { + + public CVSDiffException() { + super(Policy.bind(("CVSDiffException.message"))); + } + + +} + 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 d3f6ca379..6cbd974f1 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 @@ -42,19 +42,24 @@ import org.eclipse.team.ccvs.core.ICVSProvider; import org.eclipse.team.ccvs.core.ICVSRemoteFolder; import org.eclipse.team.ccvs.core.ICVSRepositoryLocation; import org.eclipse.team.ccvs.core.IConnectionMethod; -import org.eclipse.team.ccvs.core.CVSCommandOptions.QuietOption; import org.eclipse.team.core.IFileTypeRegistry; import org.eclipse.team.core.ITeamManager; 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.client.Checkout; +import org.eclipse.team.internal.ccvs.core.client.Command; +import org.eclipse.team.internal.ccvs.core.client.Import; +import org.eclipse.team.internal.ccvs.core.client.Session; +import org.eclipse.team.internal.ccvs.core.client.Command.GlobalOption; +import org.eclipse.team.internal.ccvs.core.client.Command.LocalOption; +import org.eclipse.team.internal.ccvs.core.client.Command.QuietOption; 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.resources.FolderSyncInfo; import org.eclipse.team.internal.ccvs.core.resources.ICVSFolder; import org.eclipse.team.internal.ccvs.core.resources.RemoteFolder; import org.eclipse.team.internal.ccvs.core.resources.Synchronizer; -import org.eclipse.team.internal.ccvs.core.util.ProjectDescriptionManager; -import org.eclipse.team.internal.ccvs.core.Policy; public class CVSProvider implements ICVSProvider { @@ -140,53 +145,49 @@ public class CVSProvider implements ICVSProvider { 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(); - // Add the option to load into a directory of a different name - String module = project.getName(); - if (sourceModule != null) { - localOptions.add("-d"); //$NON-NLS-1$ - localOptions.add(module); - module = sourceModule; - } - // Prune empty directories if pruning enabled - if (CVSProviderPlugin.getPlugin().getPruneEmptyDirectories()) - localOptions.add(Client.PRUNE_OPTION); - // Add the options related to the CVSTag - if (tag != null) { - String option = tag.getUpdateOption(); - if (option != null) { - localOptions.add(option); - localOptions.add(tag.getName()); - } - } + // 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()); - monitor = Policy.monitorFor(monitor); - monitor.beginTask(null, 100); - - // Perform a checkout - // Checkout will take 93% of the time - Client.execute( - Client.CHECKOUT, - getDefaultGlobalOptions(), - (String[])localOptions.toArray(new String[localOptions.size()]), - new String[]{module}, - root, - Policy.subMonitorFor(monitor, 93), - getPrintStream(), - (CVSRepositoryLocation)repository, - null); - + // Get the location of the workspace root + ICVSFolder root = Session.getManagedFolder(ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile()); + + // Build the local options + List localOptions = new ArrayList(); + // Add the option to load into a directory of a different name + String module = project.getName(); + if (sourceModule != null) { + localOptions.add(Checkout.makeModuleNameOption(module)); + module = sourceModule; + } + // Prune empty directories if pruning enabled + if (CVSProviderPlugin.getPlugin().getPruneEmptyDirectories()) + localOptions.add(Checkout.PRUNE_EMPTY_DIRECTORIES); + // Add the options related to the CVSTag + if (tag != null && tag.getType() != CVSTag.HEAD) { + localOptions.add(Checkout.makeTagOption(tag)); + } + + // Perform a checkout + IStatus status; + Session s = new Session(repository, root); + s.open(monitor); + try { + status = Command.CHECKOUT.execute(s, + getDefaultGlobalOptions(), + (LocalOption[])localOptions.toArray(new LocalOption[localOptions.size()]), + new String[]{module}, + null, + monitor); + } finally { + s.close(); + } + if (status.getCode() == CVSException.SERVER_ERROR) { + throw new CVSServerException(status); + } + + try { // Create, open and/or refresh the project if (!project.exists()) project.create(Policy.subMonitorFor(monitor, 1)); @@ -295,12 +296,12 @@ public class CVSProvider implements ICVSProvider { return (String[])result.toArray(new String[result.size()]); } - public static String[] getDefaultGlobalOptions() { + public static GlobalOption[] getDefaultGlobalOptions() { QuietOption option = CVSProviderPlugin.getPlugin().getQuietness(); if (option == null) - return Client.EMPTY_ARGS_LIST; + return Command.NO_GLOBAL_OPTIONS; else - return new String[] {option.getOption()}; + return new GlobalOption[] {option}; } /** @@ -413,7 +414,7 @@ public class CVSProvider implements ICVSProvider { throws TeamException { // Get the location of the workspace root - ICVSFolder root = Client.getManagedFolder(project.getLocation().toFile()); + ICVSFolder root = Session.getManagedFolder(project.getLocation().toFile()); // Get the message String message = configuration.getProperty("message"); //$NON-NLS-1$ @@ -437,27 +438,33 @@ public class CVSProvider implements ICVSProvider { // Build the local options List localOptions = new ArrayList(); - localOptions.add(Client.MESSAGE_OPTION); - localOptions.add(message); + localOptions.add(Import.makeMessageOption(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'"); //$NON-NLS-1$ + for (int i = 0; i < patterns.length ; i++) { + localOptions.add(Import.makeBinaryWrapperOption(patterns[i])); } - + // Perform a import - Client.execute( - Client.IMPORT, + IStatus status; + Session s = new Session(location, root); + s.open(monitor); + try { + status = Command.IMPORT.execute(s, getDefaultGlobalOptions(), - (String[])localOptions.toArray(new String[localOptions.size()]), - new String[]{module, vendor, tag}, - root, - monitor, - getPrintStream(), - (CVSRepositoryLocation)location, - null); - + (LocalOption[])localOptions.toArray(new LocalOption[localOptions.size()]), + new String[] { module, vendor, tag }, + null, + monitor); + } finally { + s.close(); + } + + if (status.getCode() == CVSException.SERVER_ERROR) { + throw new CVSServerException(status); + } + // NOTE: we should check to see the results of the import } @@ -505,7 +512,7 @@ public class CVSProvider implements ICVSProvider { } // Set folder sync info - ICVSFolder folder = (ICVSFolder)Client.getManagedResource(project); + ICVSFolder folder = (ICVSFolder)Session.getManagedResource(project); FolderSyncInfo info = folder.getFolderSyncInfo(); if (info == null) { // Only set the info if there is none. 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 4aff99a49..eaa3ff145 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,7 +1,7 @@ package org.eclipse.team.ccvs.core; /* - * (c) Copyright IBM Corp. 2000, 2001. + * (c) Copyright IBM Corp. 2000, 2002. * All Rights Reserved. */ @@ -15,13 +15,13 @@ 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.ccvs.core.CVSCommandOptions.QuietOption; 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.client.Command.QuietOption; import org.eclipse.team.internal.ccvs.core.resources.Synchronizer; import org.eclipse.team.internal.ccvs.core.util.ProjectDescriptionManager; import org.eclipse.team.internal.ccvs.core.util.Util; 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 index a26a48b87..e6d051769 100644 --- 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 @@ -1,13 +1,13 @@ package org.eclipse.team.ccvs.core;
/*
- * (c) Copyright IBM Corp. 2000, 2001.
+ * (c) Copyright IBM Corp. 2000, 2002.
* All Rights Reserved.
*/
import org.eclipse.core.runtime.IStatus;
import org.eclipse.team.internal.ccvs.core.CVSStatus;
-import org.eclipse.team.internal.ccvs.core.Client;
+import org.eclipse.team.internal.ccvs.core.client.Session;
import org.eclipse.team.internal.ccvs.core.Policy;
/**
@@ -76,16 +76,4 @@ public class CVSTag { }
return new CVSStatus(IStatus.OK, "ok");
}
-
- /**
- * Return the local option that is to proceed the tag name when used with a checkout or update
- */
- public String getUpdateOption() {
- if (getType() == BRANCH || getType() == VERSION)
- return Client.TAG_OPTION;
- else if (getType() == DATE)
- return Client.DATE_TAG_OPTION;
- else
- return null;
- }
}
\ 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 06dff1112..f3dfafb03 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 @@ -27,21 +27,27 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Status; -import org.eclipse.team.ccvs.core.CVSCommandOptions.CommandOption; -import org.eclipse.team.ccvs.core.CVSCommandOptions.DiffOption; 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.CVSProvider; 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.client.Command; +import org.eclipse.team.internal.ccvs.core.client.Commit; +import org.eclipse.team.internal.ccvs.core.client.Diff; +import org.eclipse.team.internal.ccvs.core.client.Session; +import org.eclipse.team.internal.ccvs.core.client.Tag; +import org.eclipse.team.internal.ccvs.core.client.Update; +import org.eclipse.team.internal.ccvs.core.client.Command.GlobalOption; +import org.eclipse.team.internal.ccvs.core.client.Command.LocalOption; +import org.eclipse.team.internal.ccvs.core.client.listeners.DiffListener; 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.resources.CVSRemoteSyncElement; import org.eclipse.team.internal.ccvs.core.resources.FolderSyncInfo; import org.eclipse.team.internal.ccvs.core.resources.ICVSFile; @@ -55,9 +61,6 @@ 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.resources.Synchronizer; -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; @@ -143,7 +146,7 @@ public class CVSTeamProvider implements ITeamNature, ITeamProvider { public void setProject(IProject project) { this.project = project; try { - this.managedProject = Client.getManagedFolder(project.getLocation().toFile()); + this.managedProject = Session.getManagedFolder(project.getLocation().toFile()); } catch (CVSException e) { // Log any problems creating the CVS managed resource CVSProviderPlugin.log(e); @@ -258,7 +261,7 @@ public class CVSTeamProvider implements ITeamNature, ITeamProvider { final IFileTypeRegistry registry = TeamPlugin.getFileTypeRegistry(); final TeamException[] eHolder = new TeamException[1]; boolean addProject = false; - for (int i=0;i<resources.length;i++) { + for (int i=0; i<resources.length; i++) { // Throw an exception if the resource is not a child of the receiver checkIsChild(resources[i]); @@ -268,7 +271,7 @@ public class CVSTeamProvider implements ITeamNature, ITeamProvider { IContainer parent = resources[i].getParent(); // XXX Need to consider workspace root - while (parent.getType() != IResource.ROOT && !isManaged(parent)) { + while (parent.getType() != IResource.ROOT && ! isManaged(parent)) { folders.add(parent.getFullPath().removeFirstSegments(1).toString()); parent = parent.getParent(); } @@ -308,50 +311,49 @@ public class CVSTeamProvider implements ITeamNature, ITeamProvider { if (eHolder[0] != null) throw eHolder[0]; - // We need to add the project then folders, followed by files! - if (addProject) - Client.execute( - Client.ADD, - getDefaultGlobalOptions(), - new String[0], - new String[] { managedProject.getFolderSyncInfo().getRepository() }, - (ICVSFolder)Client.getManagedResource(project.getParent()), - progress, - getPrintStream(), - (CVSRepositoryLocation)CVSProviderPlugin.getProvider().getRepository(managedProject.getFolderSyncInfo().getRoot()), - null); - if (!folders.isEmpty()) - Client.execute( - Client.ADD, - getDefaultGlobalOptions(), - new String[0], - (String[])folders.toArray(new String[folders.size()]), - managedProject, - progress, - getPrintStream()); - if (!textfiles.isEmpty()) - Client.execute( - Client.ADD, - getDefaultGlobalOptions(), - 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, - getDefaultGlobalOptions(), - (String[])localOptions.toArray(new String[localOptions.size()]), - (String[])binaryfiles.toArray(new String[binaryfiles.size()]), - managedProject, - progress, - getPrintStream()); + // XXX Do we need to add the project + + // Add the folders, followed by files! + IStatus status; + Session s = new Session(getRemoteRoot(), managedProject); + s.open(progress); + try { + if (!folders.isEmpty()) { + status = Command.ADD.execute(s, + getDefaultGlobalOptions(), + Command.NO_LOCAL_OPTIONS, + (String[])folders.toArray(new String[folders.size()]), + null, + progress); + if (status.getCode() == CVSException.SERVER_ERROR) { + throw new CVSServerException(status); + } + } + if (!textfiles.isEmpty()) { + status = Command.ADD.execute(s, + getDefaultGlobalOptions(), + Command.NO_LOCAL_OPTIONS, + (String[])textfiles.toArray(new String[textfiles.size()]), + null, + progress); + if (status.getCode() == CVSException.SERVER_ERROR) { + throw new CVSServerException(status); + } } + if (!binaryfiles.isEmpty()) { + status = Command.ADD.execute(s, + getDefaultGlobalOptions(), + new LocalOption[] { Command.KSUBST_BINARY }, + (String[])binaryfiles.toArray(new String[binaryfiles.size()]), + null, + progress); + if (status.getCode() == CVSException.SERVER_ERROR) { + throw new CVSServerException(status); + } + } + } finally { + s.close(); + } } /** @@ -366,21 +368,29 @@ public class CVSTeamProvider implements ITeamNature, ITeamProvider { // Build the local options List localOptions = new ArrayList(); - localOptions.add(Client.MESSAGE_OPTION); - localOptions.add(comment); + localOptions.add(Commit.makeMessageOption(comment)); + // If the depth is not infinite, we want the -l option - if (depth != IResource.DEPTH_INFINITE) - localOptions.add(Client.LOCAL_OPTION); + if (depth != IResource.DEPTH_INFINITE) { + localOptions.add(Commit.DO_NOT_RECURSE); + } // Commit the resources - Client.execute( - Client.COMMIT, + IStatus status; + Session s = new Session(getRemoteRoot(), managedProject); + s.open(progress); + try { + status = Command.COMMIT.execute(s, getDefaultGlobalOptions(), - (String[])localOptions.toArray(new String[localOptions.size()]), - arguments, - managedProject, - progress, - getPrintStream()); + (LocalOption[])localOptions.toArray(new LocalOption[localOptions.size()]), + arguments, null, + progress); + } finally { + s.close(); + } + if (status.getCode() == CVSException.SERVER_ERROR) { + throw new CVSServerException(status); + } } /** @@ -458,14 +468,22 @@ public class CVSTeamProvider implements ITeamNature, ITeamProvider { throw eHolder[0]; // Remove the files remotely - Client.execute( - Client.REMOVE, + IStatus status; + Session s = new Session(getRemoteRoot(), managedProject); + s.open(progress); + try { + status = Command.REMOVE.execute(s, getDefaultGlobalOptions(), - new String[0], + Command.NO_LOCAL_OPTIONS, (String[])files.toArray(new String[files.size()]), - managedProject, - progress, - getPrintStream()); + null, + progress); + } finally { + s.close(); + } + if (status.getCode() == CVSException.SERVER_ERROR) { + throw new CVSServerException(status); + } } /** @@ -473,27 +491,29 @@ public class CVSTeamProvider implements ITeamNature, ITeamProvider { * output to the provided PrintStream in a form that is usable * as a patch */ - public void diff(IResource[] resources, DiffOption[] options, PrintStream stream, IProgressMonitor progress) throws TeamException { - - // Build the local options - List localOptions = createLocalOptionsFromCommandOptions(options); + public void diff(IResource[] resources, LocalOption[] options, PrintStream stream, + IProgressMonitor progress) throws TeamException { // Build the arguments list - String[] arguments = getValidArguments(resources, localOptions.contains(DiffOption.DONT_RECURSE) ? IResource.DEPTH_ONE : IResource.DEPTH_INFINITE, progress); - + String[] arguments = getValidArguments(resources, Diff.DO_NOT_RECURSE.isElementOf(options) ? + IResource.DEPTH_ONE : IResource.DEPTH_INFINITE, progress); + + IStatus status; + Session s = new Session(getRemoteRoot(), managedProject); + s.open(progress); try { - Client.execute( - Client.DIFF, - Client.EMPTY_ARGS_LIST, - (String[])localOptions.toArray(new String[localOptions.size()]), + status = Command.DIFF.execute(s, + Command.NO_GLOBAL_OPTIONS, + options, arguments, - managedProject, - progress, - stream, - null, - new IResponseHandler[] {new DiffMessageHandler(), new DiffErrorHandler()}); - } catch(CVSDiffException e) { - // Ignore this for now + new DiffListener(stream), + progress); + } finally { + s.close(); + } + if (status.getCode() == CVSException.SERVER_ERROR) { + // XXX diff errors?? + throw new CVSServerException(status); } } @@ -528,7 +548,7 @@ public class CVSTeamProvider implements ITeamNature, ITeamProvider { return getRemoteRoot().getMethod().getName(); } - private String[] getDefaultGlobalOptions() { + private GlobalOption[] getDefaultGlobalOptions() { return CVSProvider.getDefaultGlobalOptions(); } @@ -670,7 +690,7 @@ public class CVSTeamProvider implements ITeamNature, ITeamProvider { if ((depth != IResource.DEPTH_ZERO) || (resources[i].getType() == IResource.FILE)) { IPath cvsPath = resources[i].getFullPath().removeFirstSegments(1); if (cvsPath.segmentCount() == 0) { - arguments.add("."); + arguments.add(Session.CURRENT_LOCAL_FOLDER); } else arguments.add(cvsPath.toString()); @@ -777,23 +797,8 @@ public class CVSTeamProvider implements ITeamNature, ITeamProvider { // are independant as this is not the way CVS works! // Could implement a CVSProvider.MOVE!!! - - Client.execute( - Client.REMOVE, - getDefaultGlobalOptions(), - new String[0], - new String[] {source.removeFirstSegments(1).toString()}, - managedProject, - progress, - getPrintStream()); - Client.execute( - Client.ADD, - getDefaultGlobalOptions(), - new String[0], // We'll need to copy options from old entry - new String[] {resource.getFullPath().removeFirstSegments(1).toString()}, - managedProject, - progress, - getPrintStream()); + + // XXX ???? } /** @@ -840,8 +845,10 @@ public class CVSTeamProvider implements ITeamNature, ITeamProvider { public void visitFile(ICVSFile file) throws CVSException {}; public void visitFolder(ICVSFolder folder) throws CVSException { FolderSyncInfo info = folder.getFolderSyncInfo(); - folder.setFolderSyncInfo(new FolderSyncInfo(info.getRepository(), root, info.getTag(), info.getIsStatic())); - folder.acceptChildren(this); + if (info != null) { + folder.setFolderSyncInfo(new FolderSyncInfo(info.getRepository(), root, info.getTag(), info.getIsStatic())); + folder.acceptChildren(this); + } }; }); Synchronizer.getInstance().save(new NullProgressMonitor()); @@ -864,24 +871,34 @@ public class CVSTeamProvider implements ITeamNature, ITeamProvider { 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); + localOptions.add(Tag.DO_NOT_RECURSE); if (tag.getType() == CVSTag.BRANCH) - localOptions.add(Client.BRANCH_OPTION); + localOptions.add(Tag.CREATE_BRANCH); // The tag name is supposed to be the first argument ArrayList args = new ArrayList(); args.add(tag.getName()); args.addAll(Arrays.asList(arguments)); arguments = (String[])args.toArray(new String[args.size()]); - - Client.execute( - Client.TAG, + + IStatus status; + Session s = new Session(getRemoteRoot(), managedProject); + s.open(progress); + try { + status = Command.TAG.execute(s, getDefaultGlobalOptions(), - (String[])localOptions.toArray(new String[localOptions.size()]), + (LocalOption[])localOptions.toArray(new LocalOption[localOptions.size()]), + // XXX We should pass the tag to the command arguments, - managedProject, - progress, - getPrintStream()); + null, + progress); + } finally { + s.close(); + } + if (status.getCode() == CVSException.SERVER_ERROR) { + // XXX diff errors?? + throw new CVSServerException(status); + } } /** @@ -909,39 +926,47 @@ public class CVSTeamProvider implements ITeamNature, ITeamProvider { // Build the local options List localOptions = new ArrayList(); if (ignoreLocalChanges) { - localOptions.add(Client.IGNORE_LOCAL_CHANGES); + localOptions.add(Update.IGNORE_LOCAL_CHANGES); } // Use the appropriate tag options if (tag != null) { if (tag.getType() == CVSTag.HEAD) { - localOptions.add(Client.CLEAR_STICKY); + localOptions.add(Update.CLEAR_STICKY); } else { - localOptions.add(tag.getUpdateOption()); - localOptions.add(tag.getName()); + localOptions.add(Update.makeTagOption(tag)); } } // Always look for absent directories - localOptions.add(Client.RETRIEVE_ABSENT_DIRECTORIES); + localOptions.add(Update.RETRIEVE_ABSENT_DIRECTORIES); // Prune empty directories if pruning is enabled if (CVSProviderPlugin.getPlugin().getPruneEmptyDirectories()) { - localOptions.add(Client.PRUNE_OPTION); + localOptions.add(Update.PRUNE_EMPTY_DIRECTORIES); } // If depth = zero or 1, use -l if (depth != IResource.DEPTH_INFINITE) { - localOptions.add(Client.LOCAL_OPTION); + localOptions.add(Update.DO_NOT_RECURSE); } // Build the arguments list String[] arguments = getValidArguments(resources, depth, progress); - - Client.execute( - Client.UPDATE, + + IStatus status; + Session s = new Session(getRemoteRoot(), managedProject); + s.open(progress); + try { + status = Command.UPDATE.execute(s, getDefaultGlobalOptions(), - (String[])localOptions.toArray(new String[localOptions.size()]), + (LocalOption[])localOptions.toArray(new LocalOption[localOptions.size()]), arguments, - managedProject, - progress, - getPrintStream()); + null, + progress); + } finally { + s.close(); + } + if (status.getCode() == CVSException.SERVER_ERROR) { + // XXX diff errors?? + throw new CVSServerException(status); + } } private static TeamException wrapException(CoreException e) { @@ -1021,15 +1046,4 @@ public class CVSTeamProvider implements ITeamNature, ITeamProvider { Assert.isTrue(false); return false; } - - /** - * Adds CVSCommandOptions to a returned array - */ - private List createLocalOptionsFromCommandOptions(CommandOption[] options) { - List ops = new ArrayList(5); - for (int i = 0; i < options.length; i++) { - ops.add(options[i].getOption()); - } - return ops; - } }
\ No newline at end of file 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 9c44a7a18..928dc74e5 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,7 +1,7 @@ package org.eclipse.team.ccvs.core; /* - * (c) Copyright IBM Corp. 2000, 2001. + * (c) Copyright IBM Corp. 2000, 2002. * All Rights Reserved. */ @@ -90,7 +90,9 @@ public interface ICVSRepositoryLocation extends IAdaptable { /** * Validate that the receiver can be used to connect to a repository. * An exception is thrown if connection fails + * + * @param monitor the progress monitor used while validating */ - public void validateConnection() throws CVSException; + public void validateConnection(IProgressMonitor monitor) throws CVSException; } 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 baedaa11f..cfd9b2cdb 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/client/AbstractMessageCommand.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/AbstractMessageCommand.java new file mode 100644 index 000000000..7e5cba7b9 --- /dev/null +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/AbstractMessageCommand.java @@ -0,0 +1,31 @@ +package org.eclipse.team.internal.ccvs.core.client; + +/* + * (c) Copyright IBM Corp. 2000, 2002. + * 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.Command.GlobalOption; +import org.eclipse.team.internal.ccvs.core.client.Command.LocalOption; +import org.eclipse.team.internal.ccvs.core.resources.ICVSResource; + +/** + * 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 { + + protected void sendLocalResourceState(Session session, GlobalOption[] globalOptions, + LocalOption[] localOptions, ICVSResource[] resources, IProgressMonitor monitor) + throws CVSException { + + // Send all folders that are already managed to the server + sendFileStructure(session, resources, false, false, monitor); + } + +} + diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/AbstractStructureVisitor.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/AbstractStructureVisitor.java new file mode 100644 index 000000000..efc727920 --- /dev/null +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/AbstractStructureVisitor.java @@ -0,0 +1,134 @@ +package org.eclipse.team.internal.ccvs.core.client; + +/* + * (c) Copyright IBM Corp. 2000, 2002. + * All Rights Reserved. + */ + +import org.eclipse.core.runtime.IProgressMonitor; +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.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 { + protected final Session session; + + // The last folder that has already been sent to the server during this visit + private ICVSFolder lastFolderSend; + + // Subclasses can use to show visitor progress + protected final IProgressMonitor monitor; + + public AbstractStructureVisitor(Session session, IProgressMonitor monitor) { + this.session = session; + 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). + */ + protected 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(session.getLocalRoot()); + + if (constructFolder && mFolder.exists()) { + session.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 questionable below this parent-folder. + Assert.isTrue(mFolder.getParent().isCVSFolder()); + sendFolder(mFolder.getParent(), constructFolder, sendQuestionable); + session.sendQuestionable(mFolder.getName()); + return; + } + + remote = mFolder.getRemoteLocation(session.getLocalRoot()); + + if (remote == null) { + return; + } + + session.sendDirectory(local, remote); + + FolderSyncInfo info = mFolder.getFolderSyncInfo(); + if (info != null) { + + if (info.getIsStatic()) { + session.sendStaticDirectory(); + } + + tag = info.getTag(); + + if (tag != null && tag.getType() != tag.HEAD) { + session.sendSticky(tag.toEntryLineFormat(false)); + } + } + + // Remember, that we send this folder + lastFolderSend = mFolder; + } + + /* + * Send the information about the file to the server. + * + * If the file is modified, its contents are sent as well. + */ + protected void sendFile(ICVSFile mFile, boolean sendQuestionable, String mode) throws CVSException { + + // Send the file's entry line to the server + if (mFile.isManaged()) { + session.sendEntry(mFile.getSyncInfo().getEntryLine(false)); + } else { + // If the file is not managed, send a questionable to the server if the file exists locally + // A unmanaged, locally non-existant file results from the explicit use of the file name as a command argument + if (sendQuestionable) { + if (mFile.exists()) { + session.sendQuestionable(mFile.getName()); + } + return; + } + } + + // If the file exists, send the appropriate indication to the server + if (mFile.exists()) { + if (mFile.isModified()) { +// if (session.isNoLocalChanges()) { +// session.sendIsModified(mFile); +// } else { + boolean binary = mode != null && mode.indexOf(ResourceSyncInfo.BINARY_TAG) != -1; + session.sendModified(mFile, monitor, binary); +// } + } else { + session.sendUnchanged(mFile.getName()); + } + } + } +}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Add.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Add.java new file mode 100644 index 000000000..32d16664b --- /dev/null +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Add.java @@ -0,0 +1,81 @@ +package org.eclipse.team.internal.ccvs.core.client; + +/* + * (c) Copyright IBM Corp. 2000, 2002. + * 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.Command.GlobalOption; +import org.eclipse.team.internal.ccvs.core.client.Command.LocalOption; +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.util.Assert; + +public class Add extends Command { + /*** Local options: specific to add ***/ + + protected Add() { } + protected String getCommandId() { + return "add"; + } + + protected void sendLocalResourceState(Session session, GlobalOption[] globalOptions, + LocalOption[] localOptions, ICVSResource[] resources, IProgressMonitor monitor) + throws CVSException { + + // Check that all the arguments can give you an + // repo that you will need while traversing the + // file-structure + try { + for (int i = 0; i < resources.length; i++) { + Assert.isNotNull(resources[i].getRemoteLocation(session.getLocalRoot())); + } + } catch (CVSException e) { + Assert.isTrue(false); + } + + // Get a vistor and use it on every resource we should + // work on + ICVSResourceVisitor visitor = new AddStructureVisitor(session, monitor); + for (int i = 0; i < resources.length; i++) { + resources[i].accept(visitor); + } + } + + /** + * If the add succeeded then folders have to be initialized with the + * sync info + */ + protected void commandFinished(Session session, GlobalOption[] globalOptions, + LocalOption[] localOptions, ICVSResource[] resources, IProgressMonitor monitor, + boolean succeeded) throws CVSException { + + ICVSFolder mFolder; + ICVSResource[] mWorkResources; + + if (! succeeded) { + return; + } + + for (int i = 0; i < resources.length; i++) { + if (resources[i].isFolder()) { + mFolder = (ICVSFolder) resources[i]; + FolderSyncInfo info = mFolder.getParent().getFolderSyncInfo(); + String repository; + if (info == null) { + // If the parent sync info is null, there may be some already with the folder itself + // This is special case handling to allow an add of a root folder to CVS + info = mFolder.getFolderSyncInfo(); + repository = mFolder.getName(); + } else { + repository = info.getRepository() + "/" + mFolder.getName(); + } + mFolder.setFolderSyncInfo(new FolderSyncInfo(repository, info.getRoot(), info.getTag(), info.getIsStatic())); + } + } + } +}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/AddStructureVisitor.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/AddStructureVisitor.java new file mode 100644 index 000000000..06086ec49 --- /dev/null +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/AddStructureVisitor.java @@ -0,0 +1,83 @@ +package org.eclipse.team.internal.ccvs.core.client; + +/* + * (c) Copyright IBM Corp. 2000, 2002. + * 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.resources.ICVSFile; +import org.eclipse.team.internal.ccvs.core.resources.ICVSFolder; +import org.eclipse.team.internal.ccvs.core.util.Assert; + +/** + * 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). + */ +class AddStructureVisitor extends AbstractStructureVisitor { + private boolean forceSend = false; + private Set visitedFolders = new HashSet(); + private ICVSFolder lastVisitedFolder; + + /** + * Constructor for AddStructureVisitor. + * @param requestSender + * @param mRoot + * @param monitor + */ + public AddStructureVisitor(Session session, IProgressMonitor monitor) { + super(session, monitor); + } + + /** + * @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. + session.sendIsModified(mFile); + + } + + /** + * @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(session.getLocalRoot()) && !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/client/Admin.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Admin.java new file mode 100644 index 000000000..d92b36742 --- /dev/null +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Admin.java @@ -0,0 +1,16 @@ +package org.eclipse.team.internal.ccvs.core.client; + +/* + * (c) Copyright IBM Corp. 2000, 2002. + * All Rights Reserved. + */ + +public class Admin extends AbstractMessageCommand { + /*** Local options: specific to admin ***/ + + protected Admin() { } + protected String getCommandId() { + return "admin"; + } +} + diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/CheckedInHandler.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/CheckedInHandler.java new file mode 100644 index 000000000..80cc34f80 --- /dev/null +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/CheckedInHandler.java @@ -0,0 +1,75 @@ +package org.eclipse.team.internal.ccvs.core.client; + +/* + * (c) Copyright IBM Corp. 2000, 2002. + * All Rights Reserved. + */ + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.team.internal.ccvs.core.CVSException; +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.ResourceSyncInfo; + +/** + * Handles a "Checked-in" response from the CVS server. + * <p> + * Suppose as a result of performing a command the CVS server responds + * as follows:<br> + * <pre> + * [...] + * Checked-in ??? \n + * [...] + * </pre> + * Then + * </p> + */ +class CheckedInHandler extends ResponseHandler { + public String getResponseID() { + return "Checked-in"; + } + + public void handle(Session session, String localDir, + IProgressMonitor monitor) throws CVSException { + // read additional data for the response + String repositoryFile = session.readLine(); + String entryLine = session.readLine(); + + // clear file update modifiers + session.setModTime(null); + + // Get the local file + String fileName = repositoryFile.substring(repositoryFile.lastIndexOf("/") + 1); + ICVSFolder mParent = session.getLocalRoot().getFolder(localDir); + ICVSFile mFile = mParent.getFile(fileName); + + // Set the entry and do not change the permissions + // CheckIn can be an response on adding a new file, + // so we can not rely on having a fileInfo ... + + // In this case we do not save permissions, but as we + // haven't got anything from the server we do not need + // to. Saveing permissions is only cashing information + // from the server. + boolean 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 + // as well + changeFile = changeFile || !mFile.exists(); + ResourceSyncInfo newInfo; + + if (changeFile) { + newInfo = new ResourceSyncInfo(entryLine, null, ResourceSyncInfo.DUMMY_TIMESTAMP); + } else { + ResourceSyncInfo fileInfo = mFile.getSyncInfo(); + newInfo = new ResourceSyncInfo(entryLine, fileInfo.getPermissions(), mFile.getTimeStamp()); + } + + mFile.setSyncInfo(newInfo); + + // This doesn't work with remote files. + //Assert.isTrue(changeFile == mFile.isModified()); + } +} + diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Checkout.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Checkout.java new file mode 100644 index 000000000..d6bd5fcf7 --- /dev/null +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Checkout.java @@ -0,0 +1,85 @@ +package org.eclipse.team.internal.ccvs.core.client; + +/* + * (c) Copyright IBM Corp. 2000, 2002. + * 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.Command.GlobalOption; +import org.eclipse.team.internal.ccvs.core.client.Command.LocalOption; +import org.eclipse.team.internal.ccvs.core.client.Command.Option; +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.util.Assert; + +public class Checkout extends Command { + /*** Local options: specific to checkout ***/ + public static final LocalOption FETCH_MODULE_ALIASES = new LocalOption("-c"); + public static LocalOption makeModuleNameOption(String moduleName) { + return new LocalOption("-d", moduleName); + } + + protected Checkout() { } + protected String getCommandId() { + return "co"; + } + + protected ICVSResource[] computeWorkResources(Session session, String[] arguments) + throws CVSException { + if (arguments.length < 1) throw new IllegalArgumentException(); + return new ICVSResource[0]; + } + + /** + * 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) + */ + protected void sendLocalResourceState(Session session, GlobalOption[] globalOptions, + LocalOption[] localOptions, ICVSResource[] resources, IProgressMonitor monitor) + throws CVSException { + + // We need a folder to put the project(s) we checkout into + Assert.isTrue(session.getLocalRoot().isFolder()); + } + + protected void sendLocalWorkingDirectory(Session session) throws CVSException { + session.sendDefaultRootDirectory(); + } + + + /** + * On sucessful finish, prune empty directories if + * the -P option was specified (or is implied by -D or -r) + */ + protected void commandFinished(Session session, GlobalOption[] globalOptions, + LocalOption[] localOptions, ICVSResource[] resources, IProgressMonitor monitor, + boolean succeeded) throws CVSException { + // If we didn't succeed, don't do any post processing + if (! succeeded) return; + + // If we are retrieving the modules file, ignore other options + if (FETCH_MODULE_ALIASES.isElementOf(localOptions)) return; + + // If we are pruning (-P) or getting a sticky copy (-D or -r), then prune empty directories + if (PRUNE_EMPTY_DIRECTORIES.isElementOf(localOptions) || + (findOption(localOptions, "-D") != null) || + (findOption(localOptions, "-r") != null)) { + // Get the name of the resulting directory + Option dOption = findOption(localOptions, "-d"); + if (dOption != null) resources = new ICVSResource[] { + session.getLocalRoot().getFolder(dOption.argument) }; + + // Prune empty directories + ICVSResourceVisitor visitor = new PruneFolderVisitor(); + for (int i=0; i<resources.length; i++) { + resources[i].accept(visitor); + } + } + } + +}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Command.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Command.java new file mode 100644 index 000000000..2ca78d26a --- /dev/null +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Command.java @@ -0,0 +1,561 @@ +package org.eclipse.team.internal.ccvs.core.client; + +/* + * (c) Copyright IBM Corp. 2000, 2002. + * All Rights Reserved. + */ + +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Vector; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.MultiStatus; +import org.eclipse.team.ccvs.core.CVSProviderPlugin; +import org.eclipse.team.ccvs.core.CVSTag; +import org.eclipse.team.internal.ccvs.core.CVSException; +import org.eclipse.team.internal.ccvs.core.Policy; +import org.eclipse.team.internal.ccvs.core.client.listeners.ICommandOutputListener; +import org.eclipse.team.internal.ccvs.core.resources.CVSFileNotFoundException; +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.Synchronizer; + +/** + * 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. + */ +public abstract class Command { + /*** Command singleton instances ***/ + public final static Add ADD = new Add(); + public final static Admin ADMIN = new Admin(); + public final static Checkout CHECKOUT = new Checkout(); + public final static Commit COMMIT = new Commit(); + public final static Diff DIFF = new Diff(); + public final static Import IMPORT = new Import(); + public final static Log LOG = new Log(); + public final static Remove REMOVE = new Remove(); + public final static Status STATUS = new Status(); + public final static Tag TAG = new Tag(); + public final static Update UPDATE = new Update(); + final static ValidRequests VALID_REQUESTS = new ValidRequests(); + + // Empty argument array + public final static String[] NO_ARGUMENTS = new String[0]; + + /*** Global options ***/ + // Empty global option array + public static final GlobalOption[] NO_GLOBAL_OPTIONS = new GlobalOption[0]; + // Do not change file contents + public static final GlobalOption DO_NOT_CHANGE = new GlobalOption("-n"); + // Do not record this operation into CVS command history + public static final GlobalOption DO_NOT_LOG = new GlobalOption("-l"); + // Make new working files read-only + public static final GlobalOption MAKE_READ_ONLY = new GlobalOption("-r"); + // Trace command execution + public static final GlobalOption TRACE_EXECUTION = new GlobalOption("-t"); + + /*** Global options: quietness ***/ + // Don't be quiet (normal verbosity) + public static final QuietOption VERBOSE = new QuietOption(""); + // Be somewhat quiet (suppress informational messages) + public static final QuietOption PARTLY_QUIET = new QuietOption("-q"); + // Be really quiet (silent but for serious problems) + public static final QuietOption SILENT = new QuietOption("-Q"); + + /*** Local options: common to many commands ***/ + // Empty local option array + public static final LocalOption[] NO_LOCAL_OPTIONS = new LocalOption[0]; + // valid for: annotate checkout commit diff export log rdiff remove rtag status tag update + public static final LocalOption DO_NOT_RECURSE = new LocalOption("-l"); + // valid for: add checkout export import update + public static final LocalOption KSUBST_BINARY = new LocalOption("-kb"); + // valid for: checkout export update + public static final LocalOption PRUNE_EMPTY_DIRECTORIES = new LocalOption("-P"); + + /*** Response handler map ***/ + private static final Hashtable responseHandlers = new Hashtable(); + static { + registerResponseHandler(new CheckedInHandler()); + registerResponseHandler(new CopyHandler()); + registerResponseHandler(new ModTimeHandler()); + registerResponseHandler(new RemovedHandler()); + registerResponseHandler(new RemoveEntryHandler()); + registerResponseHandler(new StaticHandler(true)); + registerResponseHandler(new StaticHandler(false)); + registerResponseHandler(new StickyHandler(true)); + registerResponseHandler(new StickyHandler(false)); + registerResponseHandler(new UpdatedHandler(true)); + registerResponseHandler(new UpdatedHandler(false)); + registerResponseHandler(new ValidRequestsHandler()); + } + private static void registerResponseHandler(ResponseHandler handler) { + responseHandlers.put(handler.getResponseID(), handler); + } + + /* + * XXX For the time being, the console listener is registered with Command + */ + private static ICommandOutputListener consoleListener; + + public static void setConsoleListener(ICommandOutputListener listener) { + consoleListener = listener; + } + + /** + * Prevents client code from instantiating us. + */ + protected Command() { } + + /** + * Returns the request string used to invoke this command on the server. + * [template method] + * + * @return the command's request identifier string + */ + protected abstract String getCommandId(); + + /** + */ + protected void sendArguments(Session session, String[] arguments) throws CVSException { + for (int i = 0; i < arguments.length; ++i) { + session.sendArgument(arguments[i]); + } + } + + /** + * Describes the local resource state to the server prior to command execution. + * [template method] + * <p> + * Commands must override this method to inform the server about the state of + * local resources using the Entries, Modified, Unchanged, and Questionable + * requests as needed. + * </p> + * + * @param session the CVS session + * @param globalOptions the global options for the command + * @param localOptions the local options for the command + * @param resources the resource arguments for the command + * @param monitor the progress monitor + */ + protected abstract void sendLocalResourceState(Session session, GlobalOption[] globalOptions, + LocalOption[] localOptions, ICVSResource[] resources, IProgressMonitor monitor) + throws CVSException; + + /** + * Cleans up after command execution. + * [template method] + * <p> + * The default implementation is a no-op. Subclasses may override this + * method to follow up command execution on the server with clean up + * operations on local resources. + * </p> + * + * @param session the CVS session + * @param globalOptions the global options for the command + * @param localOptions the local options for the command + * @param resources the resource arguments for the command + * @param monitor the progress monitor + * @param serverError true iff the server returned the "ok" response + */ + protected void commandFinished(Session session, GlobalOption[] globalOptions, + LocalOption[] localOptions, ICVSResource[] resources, IProgressMonitor monitor, + boolean serverError) throws CVSException { + } + + /** + * Sends the local working directory path prior to command execution. + * [template method] + * <p> + * The default implementation sends the paths of local root directory + * (assuming it exists). Subclasses may override this method to provide + * alternate behaviour. + * </p> + * + * @param session the CVS session + */ + protected void sendLocalWorkingDirectory(Session session) throws CVSException { + ICVSFolder localRoot = session.getLocalRoot(); + if (localRoot.isCVSFolder()) { + session.sendLocalRootDirectory(); + } else { + session.sendDefaultRootDirectory(); + } + } + + /** + * Computes an array of ICVSResources corresponding to command arguments. + * [template method] + * <p> + * The default implementation assumes that all arguments supplied to the + * command represent resources in the local root so that these resources + * can be more easily manipulated. Subclasses must override this method + * if this assumption is false. + */ + protected ICVSResource[] computeWorkResources(Session session, String[] arguments) + throws CVSException { + ICVSFolder localRoot = session.getLocalRoot(); + + if (arguments.length == 0) { + // As a convenience, passing no arguments to the CVS command + // implies the command will operate on the local root folder. + return new ICVSResource[] { localRoot }; + } else { + // Assume all arguments represent resources that are descendants + // of the local root folder. + ICVSResource[] resources = new ICVSResource[arguments.length]; + for (int i = 0; i < arguments.length; i++) { + try { + resources[i] = localRoot.getChild(arguments[i]); + } catch (CVSFileNotFoundException e) { + // XXX Temporary fix to allow non-managed resources to be used as arguments + resources[i] = localRoot.getFile(arguments[i]); + } + } + return resources; + } + } + + /** + * Send an array of Resources. + * + * @see Command#sendFileStructure(ICVSResource,IProgressMonitor,boolean,boolean,boolean) + */ + protected void sendFileStructure(Session session, ICVSResource[] resources, + boolean modifiedOnly, boolean emptyFolders, IProgressMonitor monitor) throws CVSException { + checkArgumentsManaged(resources); + FileStructureVisitor fsVisitor = new FileStructureVisitor(session, modifiedOnly, emptyFolders, monitor); + for (int i = 0; i < resources.length; i++) { + resources[i].accept(fsVisitor); + } + } + + /** + * 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].getParent().isCVSFolder()) { + throw new CVSException("Argument " + mWorkResources[i].getParent() + "is not managed"); + } + } + } + } + + /** + * Reload the sync info for all arguments this command will be running on. + */ + private void reloadSyncInfo(ICVSResource[] resources, IProgressMonitor monitor) throws CVSException { + try { + monitor = Policy.monitorFor(monitor); + monitor.beginTask("", 100 * resources.length); + for (int i = 0; i < resources.length; i++) { + Synchronizer.getInstance().reload(resources[i], Policy.subMonitorFor(monitor, 100)); + } + } finally { + monitor.done(); + } + } + + /** + */ + public IStatus execute(Session session, GlobalOption[] globalOptions, + LocalOption[] localOptions, String[] arguments, ICommandOutputListener listener, + IProgressMonitor monitor) + throws CVSException { + try { + session.setNoLocalChanges(DO_NOT_CHANGE.isElementOf(globalOptions)); + session.setModTime(null); + + monitor = Policy.monitorFor(monitor); + monitor.beginTask(Policy.bind("Command.server"), 100); + Policy.checkCanceled(monitor); + + // Ensure that the commands run with the latest contents of the CVS subdirectory sync files + // and not the cached values. Allow 10% of work. + ICVSResource[] resources = computeWorkResources(session, arguments); + reloadSyncInfo(resources, Policy.subMonitorFor(monitor, 10)); + Policy.checkCanceled(monitor); + + /*** initiate command ***/ + // send global options + for (int i = 0; i < globalOptions.length; ++i) { + globalOptions[i].send(session); + } + // send local options + for (int i = 0; i < localOptions.length; ++i) { + localOptions[i].send(session); + } + // send local working directory state + sendLocalResourceState(session, globalOptions, localOptions, + resources, Policy.subMonitorFor(monitor, 10)); + Policy.checkCanceled(monitor); + // send local working directory path + sendLocalWorkingDirectory(session); + // send arguments + sendArguments(session, arguments); + + // send command + session.sendCommand(getCommandId()); + + /*** process responses ***/ + // Processing responses contributes 70% of work. + IStatus status = processResponses(session, listener, Policy.subMonitorFor(monitor, 70)); + + // Finished adds last 10% of work. + commandFinished(session, globalOptions, localOptions, resources, monitor, + status.getCode() != CVSException.SERVER_ERROR); + monitor.worked(10); + return status; + } finally { + // This will automatically persist any changes that were made to the + // sync info while running a command. + Synchronizer.getInstance().save(monitor); + monitor.done(); + } + } + + /** + * + */ + private IStatus processResponses(Session session, ICommandOutputListener listener, + IProgressMonitor monitor) throws CVSException { + // 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; + monitor.beginTask(Policy.bind("Command.receivingResponses"), TOTAL_WORK); + int halfWay = TOTAL_WORK / 2; + int currentIncrement = 4; + int nextProgress = currentIncrement; + int worked = 0; + + MultiStatus accumulatedStatus = new MultiStatus(CVSProviderPlugin.ID, CVSException.OK, + Policy.bind("Command.succeeded"), null); + for (;;) { + // update monitor work amount + if (--nextProgress <= 0) { + monitor.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(monitor); + + // retrieve a response line + String response = session.readLine(); + int spacePos = response.indexOf(' '); + String argument; + if (spacePos != -1) { + argument = response.substring(spacePos + 1); + response = response.substring(0, spacePos); + } else argument = ""; + + // handle completion responses + if (response.equals("ok")) { + break; + } else if (response.equals("error")) { + MultiStatus status = new MultiStatus(CVSProviderPlugin.ID, + CVSException.SERVER_ERROR, argument, null); + status.merge(accumulatedStatus); + return status; + // handle message responses + } else if (response.equals("M")) { + if (consoleListener != null && session.isOutputToConsole()) consoleListener.messageLine(argument, null, null); + if (listener != null) { + IStatus status = listener.messageLine(argument, session.getLocalRoot(), monitor); + accumulatedStatus.merge(status); + } + } else if (response.equals("E")) { + if (consoleListener != null && session.isOutputToConsole()) consoleListener.errorLine(argument, null, null); + if (listener != null) { + IStatus status = listener.errorLine(argument, session.getLocalRoot(), monitor); + accumulatedStatus.merge(status); + } + // handle other responses + } else { + ResponseHandler handler = (ResponseHandler) responseHandlers.get(response); + if (handler != null) { + handler.handle(session, argument, monitor); + } else { + throw new CVSException(new org.eclipse.core.runtime.Status(IStatus.ERROR, + CVSProviderPlugin.ID, CVSException.IO_FAILED, + Policy.bind("Command.unsupportedResponse", response, argument), null)); + } + } + } + return accumulatedStatus; + } + + /** + * Makes a list of all valid responses; for initializing a session. + * @return a space-delimited list of all valid response strings + */ + static String makeResponseList() { + StringBuffer result = new StringBuffer("ok error M E"); + Iterator elements = responseHandlers.keySet().iterator(); + while (elements.hasNext()) { + result.append(' '); + result.append((String) elements.next()); + } + + return result.toString(); + } + + /** + * Superclass for all CVS command options + */ + protected static abstract class Option { + protected String option, argument; + protected Option(String option, String argument) { + this.option = option; + this.argument = argument; + } + /* + * Returns the text string representing this option + * @return the option + * + public String getOption() { + return option; + }*/ + /* + * Returns the (optional) argument for this option + * @return the argument, or null if none provided + * + public String getArgument() { + return argument; + }*/ + /** + * Determines if this option is an element of an array of options + * @param array the array of options + * @return true iff the array contains this option + */ + public boolean isElementOf(Option[] array) { + return findOption(array, option) != null; + } + /** + * Sends the option to a CVS server + * @param session the CVS session + */ + public abstract void send(Session session) throws CVSException; + } + /** + * Option subtype for global options that are common to all commands. + */ + public static class GlobalOption extends Option { + protected GlobalOption(String option) { + super(option, null); + } + public void send(Session session) throws CVSException { + session.sendGlobalOption(option); + } + } + /** + * Option subtype for global quietness options. + */ + public static final class QuietOption extends GlobalOption { + private QuietOption(String option) { + super(option); + } + public void send(Session session) throws CVSException { + if (option.length() != 0) super.send(session); + } + } + /** + * Option subtype for local options that vary from command to command. + */ + public static class LocalOption extends Option { + protected LocalOption(String option) { + super(option, null); + } + protected LocalOption(String option, String argument) { + super(option, argument); + } + public void send(Session session) throws CVSException { + session.sendArgument(option); + if (argument != null) session.sendArgument(argument); + } + } + + /** + * Makes a -m log message option. + * Valid for: add commit import + */ + public static LocalOption makeMessageOption(String message) { + return new LocalOption("-m", message); + } + + /** + * Makes a -r or -D option for a tag. + * Valid for: checkout export history rdiff update + */ + public static LocalOption makeTagOption(CVSTag tag) { + int type = tag.getType(); + switch (type) { + case CVSTag.BRANCH: + case CVSTag.VERSION: + return new LocalOption("-r", tag.getName()); + case CVSTag.DATE: + return new LocalOption("-D", tag.getName()); + default: + // tag must not be HEAD + throw new IllegalArgumentException("Sticky tag not " + + "valid for trunk (HEAD)."); + } + } + + /** + * Find a specific option in an array of options + * @param array the array of options + * @param option the option string to search for + * @return the first element matching the option string, or null if none + */ + protected static Option findOption(Option[] array, String option) { + for (int i = 0; i < array.length; ++i) { + // FIXME: can be optimized using identity + if (array[i].option.equals(option)) return array[i]; + } + return null; + } + + /** + * Collect all arguments of a specific option from an array of options + * @param array the array of options + * @param option the option string to search for + * @return an array of all arguments of belonging to matching options + */ + protected static String[] collectOptionArguments(Option[] array, String option) { + Vector /* of String */ list = new Vector(); + for (int i = 0; i < array.length; ++i) { + if (array[i].option.equals(option)) { + list.add(array[i].argument); + } + } + return (String[]) list.toArray(new String[list.size()]); + } +}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Commit.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Commit.java new file mode 100644 index 000000000..23b1b5cc9 --- /dev/null +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Commit.java @@ -0,0 +1,59 @@ +package org.eclipse.team.internal.ccvs.core.client; + +/* + * (c) Copyright IBM Corp. 2000, 2002. + * 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.Command.GlobalOption; +import org.eclipse.team.internal.ccvs.core.client.Command.LocalOption; +import org.eclipse.team.internal.ccvs.core.resources.ICVSFile; +import org.eclipse.team.internal.ccvs.core.resources.ICVSResource; + +public class Commit extends Command { + /*** Local options: specific to commit ***/ + + protected Commit() { } + protected String getCommandId() { + return "ci"; + } + + /** + * Send all files under the workingFolder as changed files to + * the server. + */ + protected void sendLocalResourceState(Session session, GlobalOption[] globalOptions, + LocalOption[] localOptions, ICVSResource[] resources, IProgressMonitor monitor) + throws CVSException { + + ICVSResource[] mWorkResources; + FileStructureVisitor visitor; + ICVSFile[] changedFiles; + + visitor = new FileStructureVisitor(session, true, false, monitor); + + // Get the folders we want to work on + checkArgumentsManaged(resources); + + // Send all changed files to the server + for (int i = 0; i < resources.length; i++) { + resources[i].accept(visitor); + } + + // Send the changed files as arguments + // XXX Is this the way the command line client works? + changedFiles = visitor.getSentFiles(); + for (int i = 0; i < changedFiles.length; i++) { + session.sendArgument(changedFiles[i].getRelativePath(session.getLocalRoot())); + } + } + + /** + * We do not want to send the arguments here, because we send + * them in sendRequestsToServer (special handling). + */ + protected void sendArguments(Session session, String[] arguments) throws CVSException { + } +}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/CopyHandler.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/CopyHandler.java new file mode 100644 index 000000000..fd5b7b61b --- /dev/null +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/CopyHandler.java @@ -0,0 +1,55 @@ +package org.eclipse.team.internal.ccvs.core.client; + +/* + * (c) Copyright IBM Corp. 2000, 2002. + * All Rights Reserved. + */ + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.team.internal.ccvs.core.CVSException; +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; + +/** + * Handles a "Copy-file" response from the CVS server. + * <p> + * Suppose as a result of performing a command the CVS server responds + * as follows:<br> + * <pre> + * [...] + * Copy-file myproject/ \n + * /u/cvsroot/myproject/oldfile.txt \n + * newfile.txt + * [...] + * </pre> + * Then we copy (or optionally rename) the local file "oldfile.txt" in + * folder "myproject" to "newfile.txt". This response is used to create + * a backup copy of an existing file before merging in new changes. + * </p> + */ +class CopyHandler extends ResponseHandler { + public String getResponseID() { + return "Copy-file"; + } + + public void handle(Session session, String localDir, + IProgressMonitor monitor) throws CVSException { + // read additional data for the response + String repositoryFile = session.readLine(); + String newFile = session.readLine(); + if (session.isNoLocalChanges()) return; + + // Get the local file + String fileName = repositoryFile.substring(repositoryFile.lastIndexOf("/") + 1); + ICVSFolder mParent = session.getLocalRoot().getFolder(localDir); + ICVSFile mFile = mParent.getFile(fileName); + + Assert.isTrue(mParent.exists()); + Assert.isTrue(mFile.exists() && mFile.isManaged()); + + // rename the file + mFile.moveTo(newFile); + } +} + diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Diff.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Diff.java new file mode 100644 index 000000000..c1108fe8e --- /dev/null +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Diff.java @@ -0,0 +1,57 @@ +package org.eclipse.team.internal.ccvs.core.client; + +/* + * (c) Copyright IBM Corp. 2000, 2002. + * All Rights Reserved. + */ + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.team.internal.ccvs.core.CVSException; +import org.eclipse.team.internal.ccvs.core.client.Command.GlobalOption; +import org.eclipse.team.internal.ccvs.core.client.Command.LocalOption; +import org.eclipse.team.internal.ccvs.core.client.listeners.ICommandOutputListener; +import org.eclipse.team.internal.ccvs.core.connection.CVSServerException; +import org.eclipse.team.internal.ccvs.core.resources.ICVSResource; + +/** + * Runs the CVS diff command. + */ +public class Diff extends Command { + /*** Local options: specific to diff ***/ + public static final LocalOption UNIFIED_FORMAT = new LocalOption("-u"); + public static final LocalOption CONTEXT_FORMAT = new LocalOption("-c"); + public static final LocalOption INCLUDE_NEWFILES = new LocalOption("-N"); + + protected Diff() { } + protected String getCommandId() { + return "diff"; + } + + /** + * Overwritten to throw the CVSDiffException if the server returns an error, because it just does so when there is a + * difference between the checked files. + */ + public IStatus execute(Session session, GlobalOption[] globalOptions, + LocalOption[] localOptions, String[] arguments, ICommandOutputListener listener, + IProgressMonitor monitor) + throws CVSException { + try { + return super.execute(session, globalOptions, localOptions, arguments, listener, monitor); + } catch (CVSServerException e) { + if (e.containsErrors()) throw e; + return e.getStatus(); + } + } + + protected void sendLocalResourceState(Session session, GlobalOption[] globalOptions, + LocalOption[] localOptions, ICVSResource[] resources, IProgressMonitor monitor) + throws CVSException { + + checkArgumentsManaged(resources); + FileStructureVisitor fsVisitor = new DiffStructureVisitor(session, false, false, monitor); + for (int i = 0; i < resources.length; i++) { + resources[i].accept(fsVisitor); + } + } +}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/DiffStructureVisitor.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/DiffStructureVisitor.java new file mode 100644 index 000000000..68ee3caca --- /dev/null +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/DiffStructureVisitor.java @@ -0,0 +1,49 @@ +package org.eclipse.team.internal.ccvs.core.client; +/* + * (c) Copyright IBM Corp. 2000, 2002. + * All Rights Reserved. + */ +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.team.internal.ccvs.core.CVSException; +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.ResourceSyncInfo; + +/** + * The diff command needs to send a file structure to the server that differs somewhat from the canonical + * format sent by other commands. Instead of sending new files as questionables this class sends + * new files as modified and fakes them being added. The contents are sent to the server and are + * included in the returned diff report. + */ +class DiffStructureVisitor extends FileStructureVisitor { + public DiffStructureVisitor(Session session, boolean modifiedOnly, boolean emptyFolders, + IProgressMonitor monitor) { + super(session, modifiedOnly, emptyFolders, monitor); + } + + /** + * Send unmanaged files as modified with a default entry line. + */ + protected void sendFile(ICVSFile mFile, boolean sendQuestionable, String mode) throws CVSException { + boolean binary = mode != null && mode.indexOf(ResourceSyncInfo.BINARY_TAG) != -1; + boolean newFile = false; + + if (mFile.isManaged()) { + session.sendEntry(mFile.getSyncInfo().getEntryLine(false)); + } else { + ResourceSyncInfo info = new ResourceSyncInfo(mFile.getName(), ResourceSyncInfo.ADDED_REVISION, null, null, null, null); + session.sendEntry(info.getEntryLine(false)); + newFile = true; + } + + if (!mFile.exists()) { + return; + } + + if (mFile.isModified() || newFile) { + session.sendModified(mFile, monitor, binary); + } else { + session.sendUnchanged(mFile.getName()); + } + } +} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/FileStructureVisitor.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/FileStructureVisitor.java new file mode 100644 index 000000000..9b7596ea9 --- /dev/null +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/FileStructureVisitor.java @@ -0,0 +1,138 @@ +package org.eclipse.team.internal.ccvs.core.client; + +/* + * (c) Copyright IBM Corp. 2000, 2002. + * 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.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(Session session, + boolean modifiedOnly, boolean emptyFolders, IProgressMonitor monitor) { + super(session, 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.isModified()) { + // 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()]); + } +}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Import.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Import.java new file mode 100644 index 000000000..c80933a68 --- /dev/null +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Import.java @@ -0,0 +1,52 @@ +package org.eclipse.team.internal.ccvs.core.client; + +/* + * (c) Copyright IBM Corp. 2000, 2002. + * 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.Command.GlobalOption; +import org.eclipse.team.internal.ccvs.core.client.Command.LocalOption; +import org.eclipse.team.internal.ccvs.core.resources.ICVSResource; +import org.eclipse.team.internal.ccvs.core.resources.ICVSResourceVisitor; + +public class Import extends Command { + /*** Local options: specific to import ***/ + public static LocalOption makeBinaryWrapperOption(String pattern) { + return new LocalOption("-W", pattern + " -k 'b'"); + } + + protected Import() { } + protected String getCommandId() { + return "import"; + } + + protected ICVSResource[] computeWorkResources(Session session, String[] arguments) + throws CVSException { + if (arguments.length < 3) throw new IllegalArgumentException(); + return new ICVSResource[0]; + } + + protected void sendLocalResourceState(Session session, GlobalOption[] globalOptions, + LocalOption[] localOptions, ICVSResource[] resources, IProgressMonitor monitor) + throws CVSException { + // if the called does not specify a branch option, then the CVS client + // enforces a default value of 1.1.1 upon the server + if (findOption(localOptions, "-b") == null) { + session.sendArgument("-b"); + session.sendArgument("1.1.1"); + } + + ICVSResourceVisitor visitor = new ImportStructureVisitor(session, + collectOptionArguments(localOptions, "-W"), monitor); + session.getLocalRoot().accept(visitor); + } + + protected void sendLocalWorkingDirectory(Session session) throws CVSException { + session.sendDefaultRootDirectory(); + } + +} + diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ImportStructureVisitor.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ImportStructureVisitor.java new file mode 100644 index 000000000..d73854b1a --- /dev/null +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ImportStructureVisitor.java @@ -0,0 +1,124 @@ +package org.eclipse.team.internal.ccvs.core.client; + +/* + * (c) Copyright IBM Corp. 2000, 2002. + * 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.resources.ICVSFile; +import org.eclipse.team.internal.ccvs.core.resources.ICVSFolder; +import org.eclipse.team.internal.ccvs.core.util.FileNameMatcher; + +/** + * 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 String[] wrappers; + + private FileNameMatcher ignoreMatcher; + private FileNameMatcher wrapMatcher; + + /** + * Constructor for ImportStructureVisitor. + * @param requestSender + * @param mRoot + * @param monitor + */ + public ImportStructureVisitor(Session session, + String[] wrappers, IProgressMonitor monitor) { + super(session, monitor); + + 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 { + if (ignoreMatcher != null && ignoreMatcher.match(mFile.getName())) { + return; + } + + String mode; + if (wrapMatcher != null) { + mode = wrapMatcher.getMatch(mFile.getName()); + } else { + mode = ""; + } + 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/client/Log.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Log.java new file mode 100644 index 000000000..45486607d --- /dev/null +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Log.java @@ -0,0 +1,16 @@ +package org.eclipse.team.internal.ccvs.core.client; + +/* + * (c) Copyright IBM Corp. 2000, 2002. + * All Rights Reserved. + */ + +public class Log extends AbstractMessageCommand { + /*** Local options: specific to log ***/ + + protected Log() { } + protected String getCommandId() { + return "log"; + } +} + diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ModTimeHandler.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ModTimeHandler.java new file mode 100644 index 000000000..96568bf8d --- /dev/null +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ModTimeHandler.java @@ -0,0 +1,45 @@ +package org.eclipse.team.internal.ccvs.core.client; + +/* + * (c) Copyright IBM Corp. 2000, 2002. + * All Rights Reserved. + */ + +import java.text.ParseException; +import java.util.Date; + +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.util.ServerDateFormat; + +/** + * Handles a "Mod-time" response from the CVS server. + * <p> + * Suppose as a result of performing a command the CVS server responds + * as follows:<br> + * <pre> + * [...] + * Mod-time 18 Oct 2001 20:21:13 -0350\n + * [...] + * </pre> + * Then we parse and remember the date for use in subsequent + * file transfer responses such as Updated. + * </p> + */ +class ModTimeHandler extends ResponseHandler { + private static final ServerDateFormat dateFormatter = new ServerDateFormat(); + public String getResponseID() { + return "Mod-time"; + } + + public void handle(Session session, String timeStamp, + IProgressMonitor monitor) throws CVSException { + try { + session.setModTime(new Date(dateFormatter.parseMill(timeStamp))); + } catch (ParseException e) { + throw new CVSException(Policy.bind("ModTimeHandler.invalidFormat", timeStamp), e); + } + } +} + diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/PruneFolderVisitor.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/PruneFolderVisitor.java new file mode 100644 index 000000000..8c1494722 --- /dev/null +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/PruneFolderVisitor.java @@ -0,0 +1,37 @@ +package org.eclipse.team.internal.ccvs.core.client; + +/* + * (c) Copyright IBM Corp. 2000, 2002. + * All Rights Reserved. + */ + +import org.eclipse.team.internal.ccvs.core.CVSException; +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). + */ +class PruneFolderVisitor implements ICVSResourceVisitor { + + /** + * @see ICVSResourceVisitor#visitFile(IManagedFile) + */ + public void visitFile(ICVSFile file) throws CVSException { + } + + /** + * @see ICVSResourceVisitor#visitFolder(ICVSFolder) + */ + public void visitFolder(ICVSFolder folder) throws CVSException { + folder.acceptChildren(this); + if (folder.getFiles().length == 0 && + folder.getFolders().length == 0) { + folder.delete(); + folder.unmanage(); + } + } +}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Remove.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Remove.java new file mode 100644 index 000000000..4643d7093 --- /dev/null +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Remove.java @@ -0,0 +1,32 @@ +package org.eclipse.team.internal.ccvs.core.client; + +/* + * (c) Copyright IBM Corp. 2000, 2002. + * 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.Command.GlobalOption; +import org.eclipse.team.internal.ccvs.core.client.Command.LocalOption; +import org.eclipse.team.internal.ccvs.core.resources.ICVSResource; + +public class Remove extends Command { + /*** Local options: specific to remove ***/ + + protected Remove() { } + protected String getCommandId() { + return "remove"; + } + + protected void sendLocalResourceState(Session session, GlobalOption[] globalOptions, + LocalOption[] localOptions, ICVSResource[] resources, IProgressMonitor monitor) + throws CVSException { + + ICVSResource[] mWorkResources; + + // Send all changed files to the server + sendFileStructure(session, resources, true, false, monitor); + } +} + diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/RemoveEntryHandler.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/RemoveEntryHandler.java new file mode 100644 index 000000000..5fbb2bcc9 --- /dev/null +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/RemoveEntryHandler.java @@ -0,0 +1,55 @@ +package org.eclipse.team.internal.ccvs.core.client; + +/* + * (c) Copyright IBM Corp. 2000, 2002. + * All Rights Reserved. + */ + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.team.internal.ccvs.core.CVSException; +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; + +/** + * Handles a "Remove-entry" response from the CVS server. + * <p> + * Suppose as a result of performing a command the CVS server responds + * as follows:<br> + * <pre> + * [...] + * Remove-entry ??? \n + * [...] + * </pre> + * Then + * </p> + */ + +/** + * It removes the file from both the entries of the parent-folder. + * This happen, when the folder has allready been removed locally + * what happens on a checkin that includes a removed file. + */ +class RemoveEntryHandler extends ResponseHandler { + public String getResponseID() { + return "Remove-entry"; + } + + public void handle(Session session, String localDir, + IProgressMonitor monitor) throws CVSException { + // read additional data for the response + String repositoryFile = session.readLine(); + + // Get the local file + String fileName = repositoryFile.substring(repositoryFile.lastIndexOf("/") + 1); + ICVSFolder mParent = session.getLocalRoot().getFolder(localDir); + ICVSFile mFile = mParent.getFile(fileName); + + // NOTE: Should we do something here other than throw a run-time exception + Assert.isTrue(mParent.exists() && !mFile.exists()); + + mFile.unmanage(); + } + +} + diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/RemovedHandler.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/RemovedHandler.java new file mode 100644 index 000000000..0272db2b5 --- /dev/null +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/RemovedHandler.java @@ -0,0 +1,54 @@ +package org.eclipse.team.internal.ccvs.core.client; + +/* + * (c) Copyright IBM Corp. 2000, 2002. + * All Rights Reserved. + */ + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.team.internal.ccvs.core.CVSException; +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; + +/** + * Handles a "Removed" response from the CVS server. + * <p> + * Suppose as a result of performing a command the CVS server responds + * as follows:<br> + * <pre> + * [...] + * Removed ??? \n + * [...] + * </pre> + * Then + * </p> + */ + +/** + * It removes the file from both the entries of the parent-folder + * and from the local filesystem. + */ +class RemovedHandler extends ResponseHandler { + public String getResponseID() { + return "Removed"; + } + + public void handle(Session session, String localDir, + IProgressMonitor monitor) throws CVSException { + // read additional data for the response + String repositoryFile = session.readLine(); + + // Get the local file + String fileName = repositoryFile.substring(repositoryFile.lastIndexOf("/") + 1); + ICVSFolder mParent = session.getLocalRoot().getFolder(localDir); + ICVSFile mFile = mParent.getFile(fileName); + + Assert.isTrue(mFile.exists() && mFile.isManaged()); + + // delete then unmanage the file + mFile.delete(); + mFile.unmanage(); + } +} + diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ResponseHandler.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ResponseHandler.java new file mode 100644 index 000000000..e6d8fb092 --- /dev/null +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ResponseHandler.java @@ -0,0 +1,73 @@ +package org.eclipse.team.internal.ccvs.core.client; + +/* + * (c) Copyright IBM Corp. 2000, 2002. + * All Rights Reserved. + */ + +import org.eclipse.core.runtime.IProgressMonitor; +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.ICVSFolder; +import org.eclipse.team.internal.ccvs.core.util.Util; + +/** + * Handles server responses that arise as a result of issuing a request + * (usually a command) to a CVS server. The processing of each such + * response is deferred to subclasses. + */ +public abstract class ResponseHandler { + /** + * Returns the text string of the server response handled by this object. + * @return the id + */ + public abstract String getResponseID(); + + /** + * Handles a server response. + * <p> + * Suppose as a result of performing a command the CVS server responds + * as follows:<br> + * <pre> + * [...] + * Clear-sticky myDirectory \n + * /u/cvsroot/myDirectory \n + * [...] + * </pre> + * Then the <code>handle</code> method of the <code>ResponseHandler</code> + * for <em>Clear-sticky</em> will be invoked with <code>argument</code> + * set to <em>"myDirectory"</em>. It must then read the remaining + * response data from the connection (<em>"/u/cvsroot/myDirectory"</em> + * including the newline) and take any necessary action. + * </p><p> + * Note: The type and quantity of additional data that must be read + * from the connection varies on a per-response basis. + * </p> + * @param session the Session used for CVS communication + * @param argument the argument supplied with the response + * @param monitor the progress monitor for the current CVS command + */ + public abstract void handle(Session session, String argument, + IProgressMonitor monitor) throws CVSException; + + /** + * Creates a new CVS folder. + * @param localDir the local path of the folder relative to root + * @param repositoryDir the remote path of the folder relative to the repository + * @return the new folder + */ + protected static ICVSFolder createFolder(Session session, + String localDir, String repositoryDir) throws CVSException { + ICVSFolder folder = session.getLocalRoot().getFolder(localDir); + if (! folder.exists()) folder.mkdir(); + if (! folder.isCVSFolder()) { + folder.setFolderSyncInfo(new FolderSyncInfo( + Util.getRelativePath(session.getCVSRepositoryLocation().getRootDirectory(), repositoryDir), + session.getCVSRepositoryLocation().getLocation(), + null, false)); + } + return folder; + } +} + diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Session.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Session.java new file mode 100644 index 000000000..a070e6d90 --- /dev/null +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Session.java @@ -0,0 +1,304 @@ +package org.eclipse.team.internal.ccvs.core.client; + +/* + * (c) Copyright IBM Corp. 2000, 2002. + * All Rights Reserved. + */ + +import java.io.File; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.Date; + +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.team.ccvs.core.ICVSRepositoryLocation; +import org.eclipse.team.internal.ccvs.core.CVSException; +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.ICVSResource; +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.resources.ResourceSyncInfo; + +public class Session { + public static final String CURRENT_LOCAL_FOLDER = "."; + public static final String CURRENT_REMOTE_FOLDER = ""; + public static final String SERVER_SEPARATOR = "/"; + + private Connection connection; + private CVSRepositoryLocation location; + private ICVSFolder localRoot; + private String validRequests; + private Date modTime; + private boolean noLocalChanges; + private boolean outputToConsole; + + /** + * Creates a new CVS session. + * + * @param location + * @param localRoot represents the current working directory of the client + */ + public Session(ICVSRepositoryLocation location, ICVSFolder localRoot) { + this(location, localRoot, true); + } + + public Session(ICVSRepositoryLocation location, ICVSFolder localRoot, boolean outputToConsole) { + this.location = (CVSRepositoryLocation) location; + this.localRoot = localRoot; + this.validRequests = ""; + this.outputToConsole = outputToConsole; + } + + public void open(IProgressMonitor monitor) throws CVSException { + if (connection != null) throw new IllegalStateException(); + connection = location.openConnection(monitor); + + // Tell the serves the names of the responses we can handle + connection.writeLine("Valid-responses " + Command.makeResponseList()); + + // Ask for the set of valid requests + Command.VALID_REQUESTS.execute(this, Command.NO_GLOBAL_OPTIONS, Command.NO_LOCAL_OPTIONS, + Command.NO_ARGUMENTS, null, monitor); + + // Set the root directory on the server for this connection + connection.writeLine("Root " + location.getRootDirectory()); + } + + public void close() throws CVSException { + /// ? + if (connection == null) throw new IllegalStateException(); + connection.close(); + connection = null; + } + + public boolean isValidRequest(String request) { + return (validRequests == null) || + (validRequests.indexOf(" " + request + " ") != -1); + } + + /** + * 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); + } + + public static ICVSResource getManagedResource(IResource resource) throws CVSException { + File file = resource.getLocation().toFile(); + if (resource.getType() == IResource.FILE) + return getManagedFile(file); + else + return getManagedFolder(file); + } + + /** + * Returns the local root folder for this session. + * + * @returns the local root folder + */ + public ICVSFolder getLocalRoot() { + return localRoot; + } + + /** + * Receives a line of text minus the newline from the server. + */ + public String readLine() throws CVSException { + return connection.readLine(); + } + + /** + * Sends a line of text followed by a newline to the server. + * + * @param line the line + */ + public void writeLine(String line) throws CVSException { + connection.writeLine(line); + } + + /** + * Sends an argument to the server. + * <p> + * e.g. sendArgument("Hello\nWorld\n Hello World") is sent as + * <ul> + * <li>Argument Hello</li> + * <li>Argumentx World</li> + * <li>Argumentx Hello World</li> + * </ul></p> + * + * @param arg the argument to send + */ + public void sendArgument(String arg) throws CVSException { + connection.write("Argument "); + int oldPos = 0; + for (;;) { + int pos = arg.indexOf('\n', oldPos); + if (pos == -1) break; + connection.writeLine(arg.substring(oldPos, pos)); + connection.write("Argumentx "); + oldPos = pos + 1; + } + connection.writeLine(arg.substring(oldPos)); + } + + public void sendCommand(String commandId) throws CVSException { + connection.writeLine(commandId); + connection.flush(); + } + + public void sendKopt(String arg) throws CVSException { + connection.writeLine("Kopt " + arg); + } + + public void sendIsModified(ICVSFile file) throws CVSException { + connection.writeLine("Is-modified " + file.getName()); + } + + 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(location.getRootDirectory() + "/" + 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.length() == 0) local = Session.CURRENT_LOCAL_FOLDER; + connection.writeLine("Directory " + local); + connection.writeLine(remote); + } + + public void sendLocalRootDirectory() throws CVSException { + sendDirectory(CURRENT_LOCAL_FOLDER, localRoot.getRemoteLocation(localRoot)); + } + + public void sendDefaultRootDirectory() throws CVSException { + sendConstructedDirectory(Session.CURRENT_LOCAL_FOLDER, CURRENT_REMOTE_FOLDER); + } + + + 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(ResourceSyncInfo.DEFAULT_PERMISSIONS); + } else { + connection.writeLine(info.getPermissions()); + } + + String progressTitle = + Policy.bind("RequestSender.sendModified", file.getName()); + monitor.subTask(progressTitle); + file.sendTo(connection.getOutputStream(),binary, monitor); + } + + InputStream getInputStream() throws CVSException { + return connection.getInputStream(); + } + + OutputStream getOutputStream() throws CVSException { + return connection.getOutputStream(); + } + + public ICVSRepositoryLocation getCVSRepositoryLocation() { + return location; + } + + void setModTime(Date modTime) { + this.modTime = modTime; + } + + Date getModTime() { + return modTime; + } + + boolean isNoLocalChanges() { + return noLocalChanges; + } + + boolean isOutputToConsole() { + return outputToConsole; + } + + void setNoLocalChanges(boolean noLocalChanges) { + this.noLocalChanges = noLocalChanges; + } + + void setValidRequests(String validRequests) { + this.validRequests = " " + validRequests + " "; + } +} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/StaticHandler.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/StaticHandler.java new file mode 100644 index 000000000..90b54ccb3 --- /dev/null +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/StaticHandler.java @@ -0,0 +1,59 @@ +package org.eclipse.team.internal.ccvs.core.client; + +/* + * (c) Copyright IBM Corp. 2000, 2002. + * All Rights Reserved. + */ + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.team.internal.ccvs.core.CVSException; +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.Assert; + +/** + * Handles any "Set-static-directory" and "Clear-static-directory" responses + * from the CVS server. + * <p> + * Suppose as a result of performing a command the CVS server responds + * as follows:<br> + * <pre> + * [...] + * Set-static-directory myproject/ \n + * /u/cvsroot/myproject/ \n + * [...] + * </pre> + * Then we set or clear the static flag of the folder "myproject", + * automatically creating it if it does not exist locally, + * </p> + */ +class StaticHandler extends ResponseHandler { + private final boolean setStaticDirectory; + + public StaticHandler(boolean setStaticDirectory) { + this.setStaticDirectory = setStaticDirectory; + } + + public String getResponseID() { + if (setStaticDirectory) { + return "Set-static-directory"; + } else { + return "Clear-static-directory"; + } + } + + public void handle(Session session, String localDir, + IProgressMonitor monitor) throws CVSException { + // read additional data for the response + String repositoryDir = session.readLine(); + + // create the directory then set or clear the static flag + Assert.isTrue(repositoryDir.endsWith("/")); + repositoryDir = repositoryDir.substring(0, repositoryDir.length() - 1); + ICVSFolder folder = createFolder(session, localDir, repositoryDir); + FolderSyncInfo syncInfo = folder.getFolderSyncInfo(); + folder.setFolderSyncInfo(new FolderSyncInfo(syncInfo.getRepository(), + syncInfo.getRoot(), syncInfo.getTag(), setStaticDirectory)); + } +} + diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Status.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Status.java new file mode 100644 index 000000000..f8d583663 --- /dev/null +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Status.java @@ -0,0 +1,15 @@ +package org.eclipse.team.internal.ccvs.core.client; + +/* + * (c) Copyright IBM Corp. 2000, 2002. + * All Rights Reserved. + */ + +public class Status extends AbstractMessageCommand { + /*** Local options: specific to status ***/ + + protected Status() { } + protected String getCommandId() { + return "status"; + } +} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/StickyHandler.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/StickyHandler.java new file mode 100644 index 000000000..6672649bc --- /dev/null +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/StickyHandler.java @@ -0,0 +1,66 @@ +package org.eclipse.team.internal.ccvs.core.client; + +/* + * (c) Copyright IBM Corp. 2000, 2002. + * All Rights Reserved. + */ + +import org.eclipse.core.runtime.IProgressMonitor; +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.ICVSFolder; +import org.eclipse.team.internal.ccvs.core.util.Assert; + +/** + * Handles any "Set-sticky" and "Clear-stick" responses from the CVS server. + * <p> + * Suppose as a result of performing a command the CVS server responds + * as follows:<br> + * <pre> + * [...] + * Set-sticky myproject/ \n + * /u/cvsroot/myproject/ \n + * Tsometag \n + * [...] + * </pre> + * Then we set or clear the sticky tag property of the folder "myproject", + * automatically creating it if it does not exist locally, + * </p> + */ +class StickyHandler extends ResponseHandler { + private final boolean setSticky; + + public StickyHandler(boolean setSticky) { + this.setSticky = setSticky; + } + + public String getResponseID() { + if (setSticky) { + return "Set-sticky"; + } else { + return "Clear-sticky"; + } + } + + public void handle(Session session, String localDir, + IProgressMonitor monitor) throws CVSException { + // read additional data for the response + String repositoryDir = session.readLine(); + String tag = null; + if (setSticky) { + tag = session.readLine(); + if (tag.length() == 0) tag = null; // FIXME: is this correct + } + + // create the directory then set or clear the sticky tag + Assert.isTrue(repositoryDir.endsWith("/")); + repositoryDir = repositoryDir.substring(0, repositoryDir.length() - 1); + ICVSFolder folder = createFolder(session, localDir, repositoryDir); + FolderSyncInfo syncInfo = folder.getFolderSyncInfo(); + folder.setFolderSyncInfo(new FolderSyncInfo(syncInfo.getRepository(), + syncInfo.getRoot(), tag != null ? new CVSEntryLineTag(tag) : null, + syncInfo.getIsStatic())); + } +} + diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Tag.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Tag.java new file mode 100644 index 000000000..d177a2d09 --- /dev/null +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Tag.java @@ -0,0 +1,38 @@ +package org.eclipse.team.internal.ccvs.core.client; + +/* + * (c) Copyright IBM Corp. 2000, 2002. + * 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.Command.GlobalOption; +import org.eclipse.team.internal.ccvs.core.client.Command.LocalOption; +import org.eclipse.team.internal.ccvs.core.resources.ICVSResource; + +public class Tag extends Command { + /*** Local options: specific to tag ***/ + public static final LocalOption CREATE_BRANCH = new LocalOption("-b", null); + + protected Tag() { } + protected String getCommandId() { + return "tag"; + } + + protected ICVSResource[] computeWorkResources(Session session, String[] arguments) + throws CVSException { + if (arguments.length < 1) throw new IllegalArgumentException(); + String[] allButFirst = new String[arguments.length - 1]; + System.arraycopy(arguments, 1, allButFirst, 0, arguments.length - 1); + return super.computeWorkResources(session, allButFirst); + } + + protected void sendLocalResourceState(Session session, GlobalOption[] globalOptions, + LocalOption[] localOptions, ICVSResource[] resources, IProgressMonitor monitor) + throws CVSException { + + // Send all folders that are already managed to the server + sendFileStructure(session, resources, false, false, monitor); + } +}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Update.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Update.java new file mode 100644 index 000000000..abce5430e --- /dev/null +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Update.java @@ -0,0 +1,77 @@ +package org.eclipse.team.internal.ccvs.core.client; + +/* + * (c) Copyright IBM Corp. 2000, 2002. + * All Rights Reserved. + */ + +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.client.Command.GlobalOption; +import org.eclipse.team.internal.ccvs.core.client.Command.LocalOption; +import org.eclipse.team.internal.ccvs.core.resources.ICVSResource; +import org.eclipse.team.internal.ccvs.core.resources.ICVSResourceVisitor; + +public class Update extends Command { + /*** Local options: specific to update ***/ + public static final LocalOption CLEAR_STICKY = new LocalOption("-A"); + public static final LocalOption IGNORE_LOCAL_CHANGES = new LocalOption("-C"); + public static final LocalOption RETRIEVE_ABSENT_DIRECTORIES = new LocalOption("-d"); + + /** + * Makes a -r or -D or -A option for a tag. + * Valid for: checkout export history rdiff update + */ + public static LocalOption makeTagOption(CVSTag tag) { + int type = tag.getType(); + switch (type) { + case CVSTag.HEAD: + return CLEAR_STICKY; + default: + return Command.makeTagOption(tag); + } + } + + protected Update() { } + protected String getCommandId() { + return "update"; + } + + protected void sendLocalResourceState(Session session, GlobalOption[] globalOptions, + LocalOption[] localOptions, ICVSResource[] resources, IProgressMonitor monitor) + throws CVSException { + + // XXX other clients send this. Should we? + // 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(session, resources, false, true, monitor); + } + + /** + * On successful finish, prune empty directories if the -P or -D option was specified. + */ + protected void commandFinished(Session session, GlobalOption[] globalOptions, + LocalOption[] localOptions, ICVSResource[] resources, IProgressMonitor monitor, + boolean succeeded) throws CVSException { + // If we didn't succeed, don't do any post processing + if (! succeeded) return; + + // If we are pruning (-P) or getting a sticky copy using -D, then prune empty directories + if (PRUNE_EMPTY_DIRECTORIES.isElementOf(localOptions) || + findOption(localOptions, "-D") != null) { + // Delete empty directories + ICVSResourceVisitor visitor = new PruneFolderVisitor(); + for (int i = 0; i < resources.length; i++) { + resources[i].accept(visitor); + } + + } + } +} + + diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/UpdatedHandler.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/UpdatedHandler.java new file mode 100644 index 000000000..003c9e3f2 --- /dev/null +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/UpdatedHandler.java @@ -0,0 +1,104 @@ +package org.eclipse.team.internal.ccvs.core.client; + +/* + * (c) Copyright IBM Corp. 2000, 2002. + * All Rights Reserved. + */ + +import java.util.Date; + +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.ResourceSyncInfo; +import org.eclipse.team.internal.ccvs.core.util.Assert; +import org.eclipse.team.internal.ccvs.core.util.EntryFileDateFormat; + +/** + * Handles any "Updated" and "Merged" responses + * from the CVS server. + * <p> + * Suppose as a result of performing a command the CVS server responds + * as follows:<br> + * <pre> + * [...] + * Updated ???\n + * [...] + * </pre> + * Then + * </p> + */ + +/** + * Does get information about the file that is updated + * and the file-content itself and puts it on the fileSystem. + * + * The difference beetween the "Updated" and the "Merged" is, that + * an "Merged" file is not going to be up-to-date after the operation. + * + * Requiers a exisiting parent-folder. + */ +class UpdatedHandler extends ResponseHandler { + private static final EntryFileDateFormat dateFormatter = new EntryFileDateFormat(); + private static final String READ_ONLY_FLAG = "u=rw"; + private final boolean updateResponse; + + public UpdatedHandler(boolean updateResponse) { + this.updateResponse = updateResponse; + } + + public String getResponseID() { + if (updateResponse) { + return "Updated"; + } else { + return "Merged"; + } + } + + public void handle(Session session, String localDir, + IProgressMonitor monitor) throws CVSException { + // read additional data for the response + String repositoryFile = session.readLine(); + String entryLine = session.readLine(); + String permissionsLine = session.readLine(); + + // clear file update modifiers + Date modTime = session.getModTime(); + session.setModTime(null); + + // prepare for a file transfer + int size; + try { + size = Integer.parseInt(session.readLine()); + } catch (NumberFormatException e) { + throw new CVSException(Policy.bind("Updated.numberFormat")); + } + + // Get the local file + String fileName = + repositoryFile.substring(repositoryFile.lastIndexOf("/") + 1); + ICVSFolder mParent = session.getLocalRoot().getFolder(localDir); + Assert.isTrue(mParent.exists()); + ICVSFile mFile = mParent.getFile(fileName); + + boolean binary = entryLine.indexOf("/" + ResourceSyncInfo.BINARY_TAG) != -1; + boolean readOnly = permissionsLine.indexOf(READ_ONLY_FLAG) == -1; + + mFile.receiveFrom(session.getInputStream(), size, binary, readOnly, monitor); + + // Set the timestamp in the file, set the result in the fileInfo + String timestamp = null; + if (modTime != null) timestamp = dateFormatter.format(modTime.getTime()); + mFile.setTimeStamp(timestamp); + if (updateResponse) { + timestamp = mFile.getTimeStamp(); + } else { + timestamp = ResourceSyncInfo.RESULT_OF_MERGE + mFile.getTimeStamp(); + } + mFile.setSyncInfo(new ResourceSyncInfo(entryLine, permissionsLine, timestamp)); + + Assert.isTrue(mFile.isModified() != updateResponse); + } +}
\ No newline at end of file diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ValidRequests.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ValidRequests.java new file mode 100644 index 000000000..39a51dd9a --- /dev/null +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ValidRequests.java @@ -0,0 +1,27 @@ +package org.eclipse.team.internal.ccvs.core.client; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.team.internal.ccvs.core.CVSException; +import org.eclipse.team.internal.ccvs.core.client.Command.GlobalOption; +import org.eclipse.team.internal.ccvs.core.client.Command.LocalOption; +import org.eclipse.team.internal.ccvs.core.resources.ICVSResource; + +/* + * (c) Copyright IBM Corp. 2000, 2002. + * All Rights Reserved. + */ + +class ValidRequests extends Command { + protected ValidRequests() { } + protected String getCommandId() { + return "valid-requests"; + } + + protected void sendLocalResourceState(Session session, GlobalOption[] globalOptions, + LocalOption[] localOptions, ICVSResource[] resources, IProgressMonitor monitor) + throws CVSException { + } + + protected void sendLocalWorkingDirectory(Session session) throws CVSException { + } +} diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ValidRequestsHandler.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ValidRequestsHandler.java new file mode 100644 index 000000000..402aff67d --- /dev/null +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ValidRequestsHandler.java @@ -0,0 +1,37 @@ +package org.eclipse.team.internal.ccvs.core.client; + +/* + * (c) Copyright IBM Corp. 2000, 2002. + * 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.Session; + +/** + * Handles a "Valid-requests" response from the CVS server. + * <p> + * Suppose as a result of performing a command the CVS server responds + * as follows:<br> + * <pre> + * [...] + * Valid-requests ci co update Root Directory Valid-responses Argument ...\n + * [...] + * </pre> + * Then we remember the set of valid requests for this session in + * preparation for isValidRequests queries. + * </p> + */ +class ValidRequestsHandler extends ResponseHandler { + public String getResponseID() { + return "Valid-requests"; + } + + public void handle(Session session, String validRequests, + IProgressMonitor monitor) throws CVSException { + // remember the set of valid requests for this session + session.setValidRequests(validRequests); + } + +} 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 887520f29..3253b9318 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,14 +1,14 @@ package org.eclipse.team.internal.ccvs.core.connection; /* - * (c) Copyright IBM Corp. 2000, 2001. + * (c) Copyright IBM Corp. 2000, 2002. * All Rights Reserved. */ import java.util.ArrayList; import java.util.List; - import java.util.Properties; + import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExtension; @@ -233,7 +233,8 @@ public class CVSRepositoryLocation extends PlatformObject implements ICVSReposit * password if one has not previously been provided or if the previously * supplied username and password are invalid. */ - public Connection openConnection() throws CVSException { + public Connection openConnection(IProgressMonitor monitor) throws CVSException { + // FIXME! monitor is unused String message = null; // If we have a username and password, don't authenticate unless we fail. @@ -335,9 +336,9 @@ public class CVSRepositoryLocation extends PlatformObject implements ICVSReposit * information, the method returns. Otherwise, an exception * indicating the problem is throw. */ - public void validateConnection() throws CVSException { + public void validateConnection(IProgressMonitor monitor) throws CVSException { try { - openConnection().close(); + openConnection(monitor).close(); } catch (CVSException e) { // If the validation failed, dispose of any cached info dispose(); diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/connection/CVSServerException.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/connection/CVSServerException.java index c599eec8c..1ad4a1134 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/connection/CVSServerException.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/connection/CVSServerException.java @@ -1,13 +1,10 @@ package org.eclipse.team.internal.ccvs.core.connection; /* - * (c) Copyright IBM Corp. 2000, 2001. + * (c) Copyright IBM Corp. 2000, 2002. * All Rights Reserved. */ -import java.util.Iterator; -import java.util.List; - import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.MultiStatus; import org.eclipse.core.runtime.Status; @@ -63,13 +60,11 @@ public class CVSServerException extends CVSException { } } - private CVSServerException(IStatus status) { + public CVSServerException(IStatus status) { super(status); } private CVSServerException(String message, IStatus[] children) { super(new MultiStatus(CVSProviderPlugin.ID, SERVER_ERROR, children, message, null)); } - - }
\ No newline at end of file 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 99ee921c9..ea272bc40 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,7 +1,7 @@ package org.eclipse.team.internal.ccvs.core.connection; /* - * (c) Copyright IBM Corp. 2000, 2001. + * (c) Copyright IBM Corp. 2000, 2002. * All Rights Reserved. */ @@ -9,13 +9,7 @@ import java.io.BufferedInputStream; 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.IStatus; -import org.eclipse.core.runtime.MultiStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.team.ccvs.core.CVSProviderPlugin; import org.eclipse.team.ccvs.core.ICVSRepositoryLocation; import org.eclipse.team.ccvs.core.IServerConnection; import org.eclipse.team.internal.ccvs.core.CVSException; @@ -39,66 +33,21 @@ import org.eclipse.team.internal.ccvs.core.Policy; * </ul> */ public class Connection { - - private static final boolean DEBUG= (System.getProperty("eclipse.cvs.debug")==null)?false:(new Boolean(System.getProperty("eclipse.cvs.debug")).booleanValue()); - - public static final byte NEWLINE= 0xA; + private static final boolean DEBUG = + (System.getProperty("eclipse.cvs.debug") == null) ? false : + (new Boolean(System.getProperty("eclipse.cvs.debug")).booleanValue()); + private static final byte NEWLINE= 0xA; private IServerConnection serverConnection; - private ICVSRepositoryLocation fCVSRoot; private String fCVSRootDirectory; private boolean fIsEstablished; private BufferedInputStream fResponseStream; - private char fLastUsedTokenDelimiter; - - private List errors; - - boolean closed = false; + private byte[] readLineBuffer = new byte[256]; public Connection(ICVSRepositoryLocation cvsroot, IServerConnection serverConnection) { fCVSRoot = cvsroot; this.serverConnection = serverConnection; - this.errors = new ArrayList(); - } - - /** - * Add a server error message to the list of server errors. - * - * This is used by M and E handlers to accumulate errors that are to be reported - * at the end of command execution. - * - * XXX This may not be the right place for this! - */ - public void addError(IStatus error) { - errors.add(error); - } - - /* - * Return whether server errors have been reported on the connection - * - * XXX This is public due to packaging and should not be called by handlers - */ - public boolean hasErrors() { - return ! errors.isEmpty(); - } - - /* - * Return the server errors that have been reported for the connection. - * - * XXX This is public due to packaging and should not be called by handlers - */ - public IStatus[] getErrors() { - return (IStatus[])errors.toArray(new IStatus[errors.size()]); - } - - /* - * Clear the error list. - * - * XXX This is public due to packaging and should not be called by handlers - */ - public void resetErrors() { - errors.clear(); } private static byte[] append(byte[] buffer, int index, byte b) { @@ -134,32 +83,17 @@ public class Connection { if (!isEstablished()) return; try { - getRequestStream().flush(); + getOutputStream().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 { + public OutputStream getOutputStream() throws CVSException { if (!isEstablished()) return null; return serverConnection.getOutputStream(); @@ -168,18 +102,14 @@ public class Connection { * Returns the <code>InputStream</code> used to read responses from * the server. */ - public InputStream getResponseStream() throws CVSException { + public InputStream getInputStream() throws CVSException { if (!isEstablished()) return null; if (fResponseStream == null) - fResponseStream= new BufferedInputStream(serverConnection.getInputStream()); + 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>. @@ -187,38 +117,7 @@ public class Connection { 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. */ @@ -236,7 +135,22 @@ public class Connection { * Reads a line from the response stream. */ public String readLine() throws CVSException { - return readLineOrUntil(-1); + if (!isEstablished()) + throw new CVSCommunicationException(Policy.bind("Connection.readUnestablishedConnection")); + try { + InputStream in = getInputStream(); + int index = 0; + int r; + while ((r = in.read()) != -1) { + if (r == NEWLINE) break; + readLineBuffer = append(readLineBuffer, index++, (byte) r); + } + String result = new String(readLineBuffer, 0, index); + if (DEBUG) System.out.println(result); + return result; + } catch (IOException e) { + throw new CVSCommunicationException(e); + } } static String readLine(InputStream in) throws IOException { @@ -254,47 +168,14 @@ static String readLine(InputStream in) throws IOException { 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(); + InputStream in= getInputStream(); + OutputStream out= getOutputStream(); try { while (true) { int available = in.available(); @@ -313,19 +194,6 @@ private String readLineOrUntil(int end) throws CVSException { 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 ---------------------------- /** @@ -335,11 +203,10 @@ private String readLineOrUntil(int end) throws CVSException { write(s, false); } /** - * Sends the given two strings separated by a blank to the - * server. + * Sends the given string and a newline to the server. */ - public void write(String s1, String s2) throws CVSException { - write(s1 + ' ' + s2, false); + public void writeLine(String s) throws CVSException { + write(s, true); } /** * Low level method to write a string to the server. All write* methods are @@ -353,7 +220,7 @@ private String readLineOrUntil(int end) throws CVSException { System.out.print(s + (newline ? "\n" : "")); try { - OutputStream out= getRequestStream(); + OutputStream out= getOutputStream(); out.write(s.getBytes()); if (newline) out.write(NEWLINE); @@ -363,24 +230,4 @@ private String readLineOrUntil(int end) throws CVSException { 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/resources/CVSRemoteSyncElement.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/CVSRemoteSyncElement.java index 208c80c5d..a3471ad72 100644 --- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/CVSRemoteSyncElement.java +++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/resources/CVSRemoteSyncElement.java @@ -1,7 +1,7 @@ package org.eclipse.team.internal.ccvs.core.resources;
/*
- * (c) Copyright IBM Corp. 2000, 2001.
+ * (c) Copyright IBM Corp. 2000, 2002.
* All Rights Reserved.
*/
@@ -15,7 +15,7 @@ import org.eclipse.team.core.sync.IRemoteSyncElement; import org.eclipse.team.core.sync.RemoteSyncElement;
import org.eclipse.team.internal.ccvs.core.CVSException;
import org.eclipse.team.internal.ccvs.core.CVSProvider;
-import org.eclipse.team.internal.ccvs.core.Client;
+import org.eclipse.team.internal.ccvs.core.client.Session;
import org.eclipse.team.internal.ccvs.core.Policy;
import org.eclipse.team.internal.ccvs.core.util.Assert;
@@ -270,11 +270,11 @@ public class CVSRemoteSyncElement extends RemoteSyncElement { // No need to do anything
} else if (outgoing) {
// For now, just unmanage the local resource so the remote change can be loaded with an update
- Client.getManagedResource(getLocal()).unmanage();
+ Session.getManagedResource(getLocal()).unmanage();
Synchronizer.getInstance().save(Policy.monitorFor(monitor));
} else {
// For now, just unmanage the local resource so the remote change can be loaded with an update
- Client.getManagedResource(getLocal()).unmanage();
+ Session.getManagedResource(getLocal()).unmanage();
Synchronizer.getInstance().save(Policy.monitorFor(monitor));
}
}
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 index 65017651f..c5fafae28 100644 --- 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 @@ -1,7 +1,7 @@ package org.eclipse.team.internal.ccvs.core.resources;
/*
- * (c) Copyright IBM Corp. 2000, 2001.
+ * (c) Copyright IBM Corp. 2000, 2002.
* All Rights Reserved.
*/
@@ -19,7 +19,7 @@ import org.eclipse.team.ccvs.core.CVSProviderPlugin; 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.commands.FileNameMatcher;
+import org.eclipse.team.internal.ccvs.core.util.FileNameMatcher;
import org.eclipse.team.internal.ccvs.core.util.SyncFileUtil;
/**
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 index 8e2c9967a..361e7f0b3 100644 --- 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 @@ -1,7 +1,7 @@ package org.eclipse.team.internal.ccvs.core.resources;
/*
- * (c) Copyright IBM Corp. 2000, 2001.
+ * (c) Copyright IBM Corp. 2000, 2002.
* All Rights Reserved.
*/
@@ -9,7 +9,7 @@ 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.FileNameMatcher;
import org.eclipse.team.internal.ccvs.core.util.FileUtil;
import org.eclipse.team.internal.ccvs.core.util.Util;
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 31231cf25..ed56e0224 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,7 +1,7 @@ package org.eclipse.team.internal.ccvs.core.resources; /* - * (c) Copyright IBM Corp. 2000, 2001. + * (c) Copyright IBM Corp. 2000, 2002. * All Rights Reserved. */ @@ -14,6 +14,7 @@ import java.util.ArrayList; import java.util.List; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; import org.eclipse.team.ccvs.core.CVSTag; import org.eclipse.team.ccvs.core.ICVSRemoteFile; @@ -24,10 +25,12 @@ 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.CVSProvider; -import org.eclipse.team.internal.ccvs.core.Client; -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; +import org.eclipse.team.internal.ccvs.core.client.Command; +import org.eclipse.team.internal.ccvs.core.client.Session; +import org.eclipse.team.internal.ccvs.core.client.Update; +import org.eclipse.team.internal.ccvs.core.client.Command.LocalOption; +import org.eclipse.team.internal.ccvs.core.client.listeners.LogListener; +import org.eclipse.team.internal.ccvs.core.connection.CVSServerException; import org.eclipse.team.internal.ccvs.core.util.Assert; /** @@ -116,18 +119,24 @@ public class RemoteFile extends RemoteResource implements ICVSRemoteFile, ICVSFi 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(), "-C"}, - new String[]{getName()}, - parent, - monitor, - getPrintStream(), - (CVSRepositoryLocation)getRepository(), - null); + if (contents == null) { + IStatus status; + Session s = new Session(getRepository(), parent, false); + s.open(monitor); + try { + status = Command.UPDATE.execute(s, + Command.NO_GLOBAL_OPTIONS, + new LocalOption[] { Update.makeTagOption(new CVSTag(info.getRevision(), CVSTag.VERSION)), + Update.IGNORE_LOCAL_CHANGES }, + new String[] { getName() }, + null, + monitor); + } finally { + s.close(); + } + if (status.getCode() == CVSException.SERVER_ERROR) { + throw new CVSServerException(status); + } } return new ByteArrayInputStream(contents); } catch(CVSException e) { @@ -142,16 +151,22 @@ public class RemoteFile extends RemoteResource implements ICVSRemoteFile, ICVSFi // 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)}); + IStatus status; + Session s = new Session(getRepository(), parent, false); + s.open(monitor); + try { + status = Command.LOG.execute(s, + Command.NO_GLOBAL_OPTIONS, + Command.NO_LOCAL_OPTIONS, + new String[] { getName() }, + new LogListener(this, entries), + monitor); + } finally { + s.close(); + } + if (status.getCode() == CVSException.SERVER_ERROR) { + throw new CVSServerException(status); + } return (ILogEntry[])entries.toArray(new ILogEntry[entries.size()]); } @@ -201,7 +216,7 @@ public class RemoteFile extends RemoteResource implements ICVSRemoteFile, ICVSFi if (result.length() == 0) return getName(); else - return result + Client.SERVER_SEPARATOR + getName(); + return result + Session.SERVER_SEPARATOR + getName(); } /** @@ -215,7 +230,7 @@ public class RemoteFile extends RemoteResource implements ICVSRemoteFile, ICVSFi * @see ICVSResource#getRemoteLocation(ICVSFolder) */ public String getRemoteLocation(ICVSFolder stopSearching) throws CVSException { - return parent.getRemoteLocation(stopSearching) + Client.SERVER_SEPARATOR + getName(); + return parent.getRemoteLocation(stopSearching) + Session.SERVER_SEPARATOR + getName(); } /** @@ -223,7 +238,7 @@ public class RemoteFile extends RemoteResource implements ICVSRemoteFile, ICVSFi */ public String getRemotePath() { String parentPath = parent.getRemotePath(); - return parentPath + Client.SERVER_SEPARATOR + getName(); + return parentPath + Session.SERVER_SEPARATOR + getName(); } /** @@ -258,7 +273,7 @@ public class RemoteFile extends RemoteResource implements ICVSRemoteFile, ICVSFi try { String SERVER_NEWLINE = "\n"; // Send the size to the server and no contents - out.write(0); + out.write("0".getBytes()); out.write(SERVER_NEWLINE.getBytes()); } catch(IOException e) { } @@ -345,18 +360,5 @@ public class RemoteFile extends RemoteResource implements ICVSRemoteFile, ICVSFi public boolean updateRevision(CVSTag tag, IProgressMonitor monitor) throws CVSException { return parent.updateRevision(this, tag, monitor); } - - /* - * 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; - } } 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 4665feda6..1f63a4851 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,12 +1,11 @@ package org.eclipse.team.internal.ccvs.core.resources; /* - * (c) Copyright IBM Corp. 2000, 2001. + * (c) Copyright IBM Corp. 2000, 2002. * All Rights Reserved. */ import java.io.InputStream; -import java.io.PrintStream; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -25,18 +24,18 @@ 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.client.Command; +import org.eclipse.team.internal.ccvs.core.client.Session; +import org.eclipse.team.internal.ccvs.core.client.Update; +import org.eclipse.team.internal.ccvs.core.client.Command.GlobalOption; +import org.eclipse.team.internal.ccvs.core.client.Command.LocalOption; +import org.eclipse.team.internal.ccvs.core.client.listeners.IStatusListener; +import org.eclipse.team.internal.ccvs.core.client.listeners.IUpdateMessageListener; +import org.eclipse.team.internal.ccvs.core.client.listeners.StatusListener; +import org.eclipse.team.internal.ccvs.core.client.listeners.UpdateListener; 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 @@ -61,7 +60,7 @@ public class RemoteFolder extends RemoteResource implements ICVSRemoteFolder, IC } // Get the file revisions for the given filenames - protected void updateFileRevisions(Connection connection, String[] fileNames, IProgressMonitor monitor) throws CVSException { + protected void updateFileRevisions(Session session, String[] fileNames, IProgressMonitor monitor) throws CVSException { final int[] count = new int[] {0}; @@ -69,7 +68,7 @@ public class RemoteFolder extends RemoteResource implements ICVSRemoteFolder, IC final Map revisions = new HashMap(); IStatusListener listener = new IStatusListener() { public void fileStatus(IPath path, String remoteRevision) { - if (remoteRevision == IStatusListener.FOLDER_RIVISION) + if (remoteRevision == IStatusListener.FOLDER_REVISION) // Ignore any folders return; try { @@ -81,18 +80,16 @@ public class RemoteFolder extends RemoteResource implements ICVSRemoteFolder, IC } }; - // Perform a "cvs status..." with a custom message handler - Client.execute( - Client.STATUS, - Client.EMPTY_ARGS_LIST, - Client.EMPTY_ARGS_LIST, + // Perform a "cvs status..." with a listener + IStatus status = Command.STATUS.execute(session, + Command.NO_GLOBAL_OPTIONS, + Command.NO_LOCAL_OPTIONS, fileNames, - this, - monitor, - getPrintStream(), - connection, - new IResponseHandler[] {new StatusMessageHandler(listener), new StatusErrorHandler(listener)}, - false); + new StatusListener(listener), + monitor); + if (status.getCode() == CVSException.SERVER_ERROR) { + throw new CVSServerException(status); + } if (count[0] != fileNames.length) throw new CVSException(Policy.bind("RemoteFolder.errorFetchingRevisions")); @@ -138,38 +135,37 @@ public class RemoteFolder extends RemoteResource implements ICVSRemoteFolder, IC // 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()); - } + localOptions.add(Update.RETRIEVE_ABSENT_DIRECTORIES); + if (tag != null && tag.getType() != CVSTag.HEAD) + localOptions.add(Update.makeTagOption(tag)); // Retrieve the children and any file revision numbers in a single connection + // Perform a "cvs -n update -d -r tagName folderName" with custom message and error handlers + IStatus status; + Session s = new Session(getRepository(), this, false); + s.open(monitor); 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[]{child.getName()}, - this, - monitor, - getPrintStream(), - ((CVSRepositoryLocation)getRepository()), - new IResponseHandler[]{new UpdateMessageHandler(listener), new UpdateErrorHandler(listener)}); - - return exists[0]; - - } catch (CVSServerException e) { + status = Command.UPDATE.execute(s, + new GlobalOption[] { Command.DO_NOT_CHANGE }, + (LocalOption[]) localOptions.toArray(new LocalOption[localOptions.size()]), + new String[] { child.getName() }, + new UpdateListener(listener), + monitor); + } finally { + s.close(); + } + if (status.getCode() == CVSException.SERVER_ERROR) { + CVSServerException e = new CVSServerException(status); if ( ! e.isNoTagException() || ! child.isContainer()) if (e.containsErrors()) throw e; - // we now know that this is an exception caused by a cvs bug. - // if the folder has no files in it (just subfolders) cvs does not respond with the subfolders... - // workaround: retry the request with no tag to get the directory names (if any) + // we now know that this is an exception caused by a cvs bug. + // if the folder has no files in it (just subfolders) cvs does not respond with the subfolders... + // workaround: retry the request with no tag to get the directory names (if any) Policy.checkCanceled(progress); return exists(child, null, progress); } + return exists[0]; } /** @@ -222,31 +218,23 @@ public class RemoteFolder extends RemoteResource implements ICVSRemoteFolder, IC // Build the local options List localOptions = new ArrayList(); - localOptions.add(Client.RETRIEVE_ABSENT_DIRECTORIES); - if (tag != null) { - String option = tag.getUpdateOption(); - if (option != null) { - localOptions.add(option); - localOptions.add(tag.getName()); - } - } + localOptions.add(Update.RETRIEVE_ABSENT_DIRECTORIES); + if (tag != null) localOptions.add(Update.makeTagOption(tag)); // Retrieve the children and any file revision numbers in a single connection - Connection c = ((CVSRepositoryLocation)getRepository()).openConnection(); + Session s = new Session(getRepository(), this, false); + s.open(monitor); 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)}, - true); - + // Perform a "cvs -n update -d -r tagName folderName" + IStatus status = Command.UPDATE.execute(s, + new GlobalOption[] { Command.DO_NOT_CHANGE }, + (LocalOption[])localOptions.toArray(new LocalOption[localOptions.size()]), + new String[] { "." }, + new UpdateListener(listener), + monitor); + if (status.getCode() == CVSException.SERVER_ERROR) { + throw new CVSServerException(status); + } if (progress.isCanceled()) { throw new OperationCanceledException(); } @@ -262,7 +250,7 @@ public class RemoteFolder extends RemoteResource implements ICVSRemoteFolder, IC // Get the revision numbers for the files if (newRemoteFiles.size() > 0) { - updateFileRevisions(c, (String[])newRemoteFiles.toArray(new String[newRemoteFiles.size()]), monitor); + updateFileRevisions(s, (String[])newRemoteFiles.toArray(new String[newRemoteFiles.size()]), monitor); } } catch (CVSServerException e) { @@ -281,7 +269,7 @@ public class RemoteFolder extends RemoteResource implements ICVSRemoteFolder, IC } } } finally { - c.close(); + s.close(); } // We need to remember the children that were fetched in order to support file @@ -325,7 +313,7 @@ public class RemoteFolder extends RemoteResource implements ICVSRemoteFolder, IC * @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)) + if (name.equals(Session.CURRENT_LOCAL_FOLDER) || name.equals(Session.CURRENT_LOCAL_FOLDER + Session.SERVER_SEPARATOR)) return this; ICVSResource child = getChild(name); if (child.isFolder()) @@ -407,12 +395,12 @@ public class RemoteFolder extends RemoteResource implements ICVSRemoteFolder, IC * does not exist, an exception is thrown. */ public ICVSResource getChild(String path) throws CVSException { - if (path.equals(Client.CURRENT_LOCAL_FOLDER)) + if (path.equals(Session.CURRENT_LOCAL_FOLDER)) return this; ICVSRemoteResource[] children = getChildren(); if (children == null) throw new CVSException(Policy.bind("RemoteFolder.invalidChild", new Object[] {getName()})); - if (path.indexOf(Client.SERVER_SEPARATOR) == -1) { + if (path.indexOf(Session.SERVER_SEPARATOR) == -1) { for (int i=0;i<children.length;i++) { if (children[i].getName().equals(path)) return (ICVSResource)children[i]; @@ -448,7 +436,7 @@ public class RemoteFolder extends RemoteResource implements ICVSRemoteFolder, IC * @see ICVSResource#getRemoteLocation(ICVSFolder) */ public String getRemoteLocation(ICVSFolder stopSearching) throws CVSException { - return getRepository().getRootDirectory() + Client.SERVER_SEPARATOR + getRemotePath(); + return getRepository().getRootDirectory() + Session.SERVER_SEPARATOR + getRemotePath(); } /** @@ -550,41 +538,27 @@ public class RemoteFolder extends RemoteResource implements ICVSRemoteFolder, IC // Build the local options List localOptions = new ArrayList(); - if ((tag != null) && (tag.getType() != CVSTag.HEAD)) { - localOptions.add(Client.TAG_OPTION); - localOptions.add(tag.getName()); - } + if (tag != null && tag.getType() != CVSTag.HEAD) + localOptions.add(Update.makeTagOption(tag)); // Retrieve the children and any file revision numbers in a single connection - Connection c = ((CVSRepositoryLocation)getRepository()).openConnection(); + Session s = new Session(getRepository(), this, false); + s.open(monitor); try { // Perform a "cvs -n update -d -r tagName fileName" with custom message and error handlers - try { - Client.execute( - Client.UPDATE, - new String[]{Client.NOCHANGE_OPTION}, - (String[])localOptions.toArray(new String[localOptions.size()]), - new String[]{child.getName()}, - this, - monitor, - getPrintStream(), - c, - new IResponseHandler[]{new UpdateMessageHandler(listener), new UpdateErrorHandler(listener)}, - true); - } catch (CVSServerException e) { - if (e.containsErrors()) { - throw e; - } - } + IStatus status = Command.UPDATE.execute(s, + new GlobalOption[] { Command.DO_NOT_CHANGE }, + (LocalOption[]) localOptions.toArray(new LocalOption[localOptions.size()]), + new String[] { child.getName() }, + new UpdateListener(listener), + monitor); - if (!exists[0]) - return false; - - updateFileRevisions(c, new String[] {child.getName()}, monitor); + if (!exists[0]) return false; + updateFileRevisions(s, new String[] {child.getName()}, monitor); return true; } finally { - c.close(); + s.close(); } } finally { children = oldChildren; 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 9cd8b81ad..25b52fffd 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,7 +1,7 @@ package org.eclipse.team.internal.ccvs.core.resources; /* - * (c) Copyright IBM Corp. 2000, 2001. + * (c) Copyright IBM Corp. 2000, 2002. * All Rights Reserved. */ @@ -97,10 +97,6 @@ public abstract class RemoteResource extends PlatformObject implements ICVSRemot throw new CVSException(Policy.bind("RemoteManagedResource.invalidOperation")); } - protected PrintStream getPrintStream() { - return NullOutputStream.DEFAULT; - } - /* * @see ICVSResource#getSyncInfo() */ 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 index d3f07fa79..ac663cf32 100644 --- 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 @@ -1,7 +1,7 @@ package org.eclipse.team.internal.ccvs.core.resources;
/*
- * (c) Copyright IBM Corp. 2000, 2001.
+ * (c) Copyright IBM Corp. 2000, 2002.
* All Rights Reserved.
*/
@@ -32,9 +32,13 @@ public class ResourceSyncInfo { public static final String BINARY_TAG = "-kb";
private static final String SEPERATOR = "/";
+ // Timestamp constants used to identify special cases
+ public static final String DUMMY_TIMESTAMP = "dummy timestamp";
+ public static final String RESULT_OF_MERGE = "Result of merge+";
+
// safe default permissions. Permissions are saved separatly so that the correct permissions
// can be sent back to the server on systems that don't save execute bits (e.g. windows).
- private static final String DEFAULT_PERMISSIONS = "u=rw,g=rw,o=r";
+ public static final String DEFAULT_PERMISSIONS = "u=rw,g=rw,o=r";
// file sync information can be associated with a local resource that has been deleted. This is
// noted by prefixing the revision with this character.
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 15e917599..a3b0895f9 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 @@ -1,11 +1,10 @@ package org.eclipse.team.internal.ccvs.core.util;
/*
- * (c) Copyright IBM Corp. 2000, 2001.
+ * (c) Copyright IBM Corp. 2000, 2002.
* All Rights Reserved.
*/
-import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -16,16 +15,24 @@ import java.util.Map; import org.eclipse.core.resources.IContainer;
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.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.client.Command;
+import org.eclipse.team.internal.ccvs.core.client.Session;
+import org.eclipse.team.internal.ccvs.core.client.Update;
+import org.eclipse.team.internal.ccvs.core.client.Command.GlobalOption;
+import org.eclipse.team.internal.ccvs.core.client.Command.LocalOption;
+import org.eclipse.team.internal.ccvs.core.client.listeners.IStatusListener;
+import org.eclipse.team.internal.ccvs.core.client.listeners.IUpdateMessageListener;
+import org.eclipse.team.internal.ccvs.core.client.listeners.StatusListener;
+import org.eclipse.team.internal.ccvs.core.client.listeners.UpdateListener;
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.FolderSyncInfo;
import org.eclipse.team.internal.ccvs.core.resources.ICVSFile;
import org.eclipse.team.internal.ccvs.core.resources.ICVSFolder;
@@ -34,13 +41,7 @@ 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.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.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;
+import org.omg.CORBA.UNKNOWN;
/*
* This class is responsible for building a remote tree that shows the repository
@@ -64,7 +65,7 @@ public class RemoteFolderTreeBuilder { private CVSTag tag;
- private String[] updateLocalOptions;
+ private LocalOption[] updateLocalOptions;
private boolean projectDoesNotExist = false;
@@ -84,16 +85,15 @@ public class RemoteFolderTreeBuilder { // Build the local options
List localOptions = new ArrayList();
- localOptions.add(Client.RETRIEVE_ABSENT_DIRECTORIES);
+ localOptions.add(Update.RETRIEVE_ABSENT_DIRECTORIES);
if (tag != null) {
if (tag.getType() == CVSTag.HEAD) {
- localOptions.add(Client.CLEAR_STICKY);
+ localOptions.add(Update.CLEAR_STICKY);
} else {
- localOptions.add(tag.getUpdateOption());
- localOptions.add(tag.getName());
+ localOptions.add(Update.makeTagOption(tag));
}
}
- updateLocalOptions = (String[])localOptions.toArray(new String[localOptions.size()]);
+ updateLocalOptions = (LocalOption[])localOptions.toArray(new LocalOption[localOptions.size()]);
}
public static RemoteFolderTree buildBaseTree(CVSRepositoryLocation repository, ICVSFolder root, CVSTag tag, IProgressMonitor monitor) throws CVSException {
@@ -102,7 +102,7 @@ public class RemoteFolderTreeBuilder { }
public static RemoteFolderTree buildRemoteTree(CVSRepositoryLocation repository, IContainer root, CVSTag tag, IProgressMonitor monitor) throws CVSException {
- return buildRemoteTree(repository, Client.getManagedFolder(root.getLocation().toFile()), tag, monitor);
+ return buildRemoteTree(repository, Session.getManagedFolder(root.getLocation().toFile()), tag, monitor);
}
public static RemoteFolderTree buildRemoteTree(CVSRepositoryLocation repository, ICVSFolder root, CVSTag tag, IProgressMonitor monitor) throws CVSException {
@@ -111,19 +111,32 @@ public class RemoteFolderTreeBuilder { }
private RemoteFolderTree buildTree(IProgressMonitor monitor) throws CVSException {
- Connection connection = repository.openConnection();
+ Session session = new Session(repository, root, false);
+ session.open(monitor);
try {
- fetchDelta(connection, monitor);
+ fetchDelta(session, monitor);
if (projectDoesNotExist) {
return null;
}
- remoteRoot = new RemoteFolderTree(null, repository, new Path(root.getFolderSyncInfo().getRepository()), tag);
- buildRemoteTree(connection, root, remoteRoot, Path.EMPTY, monitor);
+ } finally {
+ session.close();
+ }
+ // FIXME: We need a second session because of the use of a different handle on the same remote resource
+ // We didn't need one before!!! Perhaps we could support the changing of a sessions root as long as
+ // the folder sync info is the same
+ remoteRoot =
+ new RemoteFolderTree(null,repository,
+ new Path(root.getFolderSyncInfo().getRepository()),
+ tagForRemoteFolder(root, tag));
+ session = new Session(repository, remoteRoot, false);
+ session.open(monitor);
+ try {
+ buildRemoteTree(session, root, remoteRoot, Path.EMPTY, monitor);
if (!changedFiles.isEmpty())
- fetchFileRevisions(connection, remoteRoot, (String[])changedFiles.toArray(new String[changedFiles.size()]), monitor);
+ fetchFileRevisions(session, remoteRoot, (String[])changedFiles.toArray(new String[changedFiles.size()]), monitor);
return remoteRoot;
} finally {
- connection.close();
+ session.close();
}
}
@@ -136,7 +149,7 @@ public class RemoteFolderTreeBuilder { private RemoteFolderTree buildBaseTree(RemoteFolderTree parent, ICVSFolder local, IProgressMonitor monitor) throws CVSException {
// Create a remote folder tree corresponding to the local resource
- RemoteFolderTree remote = new RemoteFolderTree(parent, repository, new Path(local.getFolderSyncInfo().getRepository()), tag);
+ RemoteFolderTree remote = new RemoteFolderTree(parent, repository, new Path(local.getFolderSyncInfo().getRepository()), local.getFolderSyncInfo().getTag());
// Create a List to contain the created children
List children = new ArrayList();
@@ -178,20 +191,22 @@ public class RemoteFolderTreeBuilder { * The localPath is used to retrieve deltas from the recorded deltas
*
*/
- private void buildRemoteTree(Connection connection, ICVSFolder local, RemoteFolderTree remote, IPath localPath, IProgressMonitor monitor) throws CVSException {
+ private void buildRemoteTree(Session session, ICVSFolder local, RemoteFolderTree remote, IPath localPath, IProgressMonitor monitor) throws CVSException {
// Create a map to contain the created children
Map children = new HashMap();
// If there's no corresponding local resource then we need to fetch its contents in order to populate the deltas
if (local == null) {
- fetchNewDirectory(connection, remote, localPath, monitor);
+ fetchNewDirectory(session, remote, localPath, monitor);
}
// Fetch the delta's for the folder
Map 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) {
@@ -199,7 +214,10 @@ public class RemoteFolderTreeBuilder { ICVSFolder[] folders = local.getFolders();
for (int i=0;i<folders.length;i++) {
if (folders[i].isCVSFolder() && (deltas.get(folders[i].getName()) != DELETED))
- children.put(folders[i].getName(), new RemoteFolderTree(remote, repository, new Path(folders[i].getFolderSyncInfo().getRepository()), tag));
+ children.put(folders[i].getName(),
+ new RemoteFolderTree(remote, repository,
+ new Path(folders[i].getFolderSyncInfo().getRepository()),
+ tagForRemoteFolder(folders[i],tag)));
}
// Build the child files corresponding to local files
ICVSFile[] files = local.getFiles();
@@ -230,7 +248,9 @@ public class RemoteFolderTreeBuilder { String revision = (String)deltas.get(name);
if (revision == FOLDER) {
// XXX should getRemotePath() return an IPath instead of a String?
- children.put(name, new RemoteFolderTree(remote, repository, new Path(remote.getRemotePath()).append(name), tag));
+ children.put(name, new RemoteFolderTree(remote, repository,
+ new Path(remote.getRemotePath()).append(name),
+ tagForRemoteFolder(remote, tag)));
} else if (revision == ADDED) {
children.put(name, new RemoteFile(remote, name, tag));
} else if (revision == UNKNOWN) {
@@ -266,7 +286,7 @@ public class RemoteFolderTreeBuilder { localFolder = null;
else
localFolder = local.getFolder(name);
- buildRemoteTree(connection, localFolder, remoteFolder, localPath.append(name), monitor);
+ buildRemoteTree(session, localFolder, remoteFolder, localPath.append(name), monitor);
// Record any children that are empty
if (pruneEmptyDirectories() && remoteFolder.getChildren().length == 0) {
// Prune if the local folder is also empty.
@@ -298,7 +318,7 @@ public class RemoteFolderTreeBuilder { *
* Returns the list of changed files
*/
- private List fetchDelta(Connection connection, IProgressMonitor monitor) throws CVSException {
+ private List fetchDelta(Session session, IProgressMonitor monitor) throws CVSException {
// Create an listener that will accumulate new and removed files and folders
final List newChildDirectories = new ArrayList();
@@ -348,28 +368,16 @@ public class RemoteFolderTreeBuilder { // Perform a "cvs -n update -d [-r tag] ." in order to get the
// messages from the server that will indicate what has changed on the
// server.
- try {
- Client.execute(
- Client.UPDATE,
- new String[] {"-n"},
- updateLocalOptions,
- new String[]{"."},
- root,
- monitor,
- getPrintStream(),
- connection,
- new IResponseHandler[]{new UpdateMessageHandler(listener), new UpdateErrorHandler(listener)},
- true
- );
- } catch (CVSServerException e) {
- if (e.containsErrors())
- throw e;
- }
-
+ IStatus status = Command.UPDATE.execute(session,
+ new GlobalOption[] { Command.DO_NOT_CHANGE },
+ updateLocalOptions,
+ new String[] { "." },
+ new UpdateListener(listener),
+ monitor);
return changedFiles;
}
- private void fetchNewDirectory(Connection connection, RemoteFolderTree newFolder, IPath localPath, IProgressMonitor monitor) throws CVSException {
+ private void fetchNewDirectory(Session session, RemoteFolderTree newFolder, IPath localPath, IProgressMonitor monitor) throws CVSException {
// Create an listener that will accumulate new files and folders
IUpdateMessageListener listener = new IUpdateMessageListener() {
@@ -393,43 +401,35 @@ public class RemoteFolderTreeBuilder { // NOTE: Should use the path relative to the remoteRoot
IPath path = new Path(newFolder.getRemotePath());
- try {
- Client.execute(
- Client.UPDATE,
- new String[] {"-n"},
- updateLocalOptions,
- new String[] {localPath.toString()},
- remoteRoot,
- monitor,
- getPrintStream(),
- connection,
- new IResponseHandler[]{new UpdateMessageHandler(listener), new UpdateErrorHandler(listener)},
- false
- );
- } catch (CVSServerException e) {
+ IStatus status = Command.UPDATE.execute(session,
+ new GlobalOption[] { Command.DO_NOT_CHANGE },
+ updateLocalOptions,
+ new String[] { localPath.toString() },
+ new UpdateListener(listener),
+ monitor);
+ if (status.getCode() == CVSException.SERVER_ERROR) {
+ // FIXME: This should be refactored (maybe static methods on CVSException?)
+ CVSServerException e = new CVSServerException(status);
if ( ! e.isNoTagException() && e.containsErrors())
throw e;
// we now know that this is an exception caused by a cvs bug.
// if the folder has no files in it (just subfolders) cvs does not respond with the subfolders...
// workaround: retry the request with no tag to get the directory names (if any)
Policy.checkCanceled(monitor);
- Client.execute(
- Client.UPDATE,
- new String[] {"-n"},
- Client.EMPTY_ARGS_LIST,
- new String[] {localPath.toString()},
- remoteRoot,
- monitor,
- getPrintStream(),
- connection,
- new IResponseHandler[]{new UpdateMessageHandler(listener), new UpdateErrorHandler(listener)},
- false
- );
+ status = Command.UPDATE.execute(session,
+ new GlobalOption[] { Command.DO_NOT_CHANGE },
+ updateLocalOptions,
+ new String[] { localPath.toString() },
+ new UpdateListener(listener),
+ monitor);
+ if (status.getCode() == CVSException.SERVER_ERROR) {
+ throw new CVSServerException(status);
+ }
}
}
// Get the file revisions for the given filenames
- private void fetchFileRevisions(Connection connection, final RemoteFolder root, String[] fileNames, IProgressMonitor monitor) throws CVSException {
+ private void fetchFileRevisions(Session session, final RemoteFolder root, String[] fileNames, IProgressMonitor monitor) throws CVSException {
// Create a listener for receiving the revision info
final int[] count = new int[] {0};
@@ -447,17 +447,15 @@ public class RemoteFolderTreeBuilder { };
// Perform a "cvs status..." with a custom message handler
- Client.execute(
- Client.STATUS,
- Client.EMPTY_ARGS_LIST,
- Client.EMPTY_ARGS_LIST,
+ IStatus status = Command.STATUS.execute(session,
+ Command.NO_GLOBAL_OPTIONS,
+ Command.NO_LOCAL_OPTIONS,
fileNames,
- root,
- monitor,
- getPrintStream(),
- connection,
- new IResponseHandler[] {new StatusMessageHandler(listener), new StatusErrorHandler(listener)},
- false);
+ new StatusListener(listener),
+ monitor);
+ if (status.getCode() == CVSException.SERVER_ERROR) {
+ throw new CVSServerException(status);
+ }
// 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
@@ -466,11 +464,6 @@ public class RemoteFolderTreeBuilder { // throw new CVSException(Policy.bind("RemoteFolder.errorFetchingRevisions"));
}
-
- private PrintStream getPrintStream() {
- return NullOutputStream.DEFAULT;
- }
-
private boolean pruneEmptyDirectories() {
return CVSProviderPlugin.getPlugin().getPruneEmptyDirectories();
}
@@ -495,5 +488,20 @@ public class RemoteFolderTreeBuilder { private void updateRevision(RemoteFolder root, IPath path, String revision) throws CVSException {
((RemoteFile)root.getFile(path.toString())).setRevision(revision);
}
+
+ /*
+ * Return the tag that should be associated with a remote folder.
+ *
+ * This method is used to ensure that new directories contain the tag
+ * derived from the parant local folder when appropriate. For instance,
+ *
+ * The tag should be the provided tag. However, if tag is null, the
+ * tag for the folder should be derived from the provided reference folder
+ * which could be the local resource corresponding to the remote or the parent
+ * of the remote.
+ */
+ private CVSTag tagForRemoteFolder(ICVSFolder folder, CVSTag tag) throws CVSException {
+ return tag == null ? folder.getFolderSyncInfo().getTag() : tag;
+ }
}
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 bd7291d1d..09623d412 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,7 +1,7 @@ package org.eclipse.team.internal.ccvs.core.util; /* - * (c) Copyright IBM Corp. 2000, 2001. + * (c) Copyright IBM Corp. 2000, 2002. * All Rights Reserved. */ @@ -24,7 +24,6 @@ import org.eclipse.team.ccvs.core.CVSTeamProvider; import org.eclipse.team.core.ITeamProvider; import org.eclipse.team.core.TeamPlugin; 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.ICVSFolder; @@ -248,4 +247,3 @@ public abstract class ResourceDeltaVisitor implements IResourceDeltaVisitor { protected abstract void handleChanged(IProject project,IResource resource); } - diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSOperationCancelledException.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSOperationCancelledException.java index d775b1e74..eaf786c08 100644 --- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSOperationCancelledException.java +++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSOperationCancelledException.java @@ -1,31 +1,31 @@ -package org.eclipse.team.internal.ccvs.ui;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved.
- */
-
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.team.internal.ccvs.core.CVSException;
-import org.eclipse.team.internal.ccvs.core.CVSStatus;
-
-public class CVSOperationCancelledException extends CVSException {
- /**
- * Constructor for CVSOperationCancelledException
- */
- public CVSOperationCancelledException() {
- this(new CVSStatus(IStatus.INFO, Policy.bind("CVSOperationCancelledException.operationCancelled")));
- }
- /**
- * Constructor for CVSOperationCancelledException
- */
- public CVSOperationCancelledException(String message) {
- this(new CVSStatus(IStatus.INFO, message));
- }
- /**
- * Constructor for CVSOperationCancelledException
- */
- public CVSOperationCancelledException(IStatus status) {
- super(status);
- }
-}
+package org.eclipse.team.internal.ccvs.ui; + +/* + * (c) Copyright IBM Corp. 2000, 2001. + * All Rights Reserved. + */ + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.team.internal.ccvs.core.CVSException; +import org.eclipse.team.internal.ccvs.core.CVSStatus; + +public class CVSOperationCancelledException extends CVSException { + /** + * Constructor for CVSOperationCancelledException + */ + public CVSOperationCancelledException() { + this(new CVSStatus(IStatus.INFO, Policy.bind("CVSOperationCancelledException.operationCancelled"))); + } + /** + * Constructor for CVSOperationCancelledException + */ + public CVSOperationCancelledException(String message) { + this(new CVSStatus(IStatus.INFO, message)); + } + /** + * Constructor for CVSOperationCancelledException + */ + public CVSOperationCancelledException(IStatus status) { + super(status); + } +} diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSPreferencesPage.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSPreferencesPage.java index 9d13008e6..9f85e13d4 100644 --- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSPreferencesPage.java +++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSPreferencesPage.java @@ -20,7 +20,8 @@ import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; import org.eclipse.team.ccvs.core.CVSProviderPlugin; -import org.eclipse.team.ccvs.core.CVSCommandOptions.QuietOption; +import org.eclipse.team.internal.ccvs.core.client.Command; +import org.eclipse.team.internal.ccvs.core.client.Command.QuietOption; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; @@ -241,9 +242,9 @@ public class CVSPreferencesPage protected static QuietOption getQuietnessOptionFor(int option) { switch (option) { - case 0: return null; - case 1: return QuietOption.PARTLY_QUIET; - case 2: return QuietOption.SILENT; + case 0: return Command.VERBOSE; + case 1: return Command.PARTLY_QUIET; + case 2: return Command.SILENT; } return null; } diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIPlugin.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIPlugin.java index dcb9158b0..4f5661375 100644 --- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIPlugin.java +++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIPlugin.java @@ -5,13 +5,13 @@ package org.eclipse.team.internal.ccvs.ui; * All Rights Reserved. */ -import java.io.PrintStream; import java.net.MalformedURLException; import java.net.URL; import java.util.Hashtable; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPluginDescriptor; +import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Platform; import org.eclipse.jface.preference.IPreferenceStore; @@ -22,6 +22,9 @@ import org.eclipse.team.ccvs.core.ICVSRemoteFile; import org.eclipse.team.ccvs.core.ICVSRemoteFolder; import org.eclipse.team.ccvs.core.ICVSRepositoryLocation; import org.eclipse.team.core.TeamException; +import org.eclipse.team.internal.ccvs.core.client.Command; +import org.eclipse.team.internal.ccvs.core.client.listeners.ICommandOutputListener; +import org.eclipse.team.internal.ccvs.core.resources.ICVSFolder; import org.eclipse.team.internal.ccvs.ui.model.CVSAdapterFactory; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchWindow; @@ -177,7 +180,18 @@ public class CVSUIPlugin extends AbstractUIPlugin { public void startup() throws CoreException { super.startup(); Policy.localize("org.eclipse.team.internal.ccvs.ui.messages"); - CVSProviderPlugin.getProvider().setPrintStream(new PrintStream(new ConsoleOutputStream())); + + // XXX This should be refactored!!! + Command.setConsoleListener(new ICommandOutputListener() { + public IStatus messageLine(String line, ICVSFolder commandRoot, IProgressMonitor monitor) { + Console.appendAll(line + '\n'); + return OK; + } + public IStatus errorLine(String line, ICVSFolder commandRoot, IProgressMonitor monitor) { + Console.appendAll(line + '\n'); + return OK; + } + }); CVSAdapterFactory factory = new CVSAdapterFactory(); Platform.getAdapterManager().registerAdapters(factory, ICVSRemoteFile.class); diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/Console.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/Console.java index 8992f9764..b2a875009 100644 --- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/Console.java +++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/Console.java @@ -128,13 +128,14 @@ public class Console extends ViewPart { } if (message.length() == 0) return; - boolean appendCr = message.charAt(message.length() - 1) == '\n'; + // XXX What was the purpose of this? +// boolean appendCr = message.charAt(message.length() - 1) == '\n'; Console[] consoles = Console.getInstances(); for (int i = 0; i < consoles.length; i++) { consoles[i].append(message); - if (appendCr) { - consoles[i].append("\n"); - } +// if (appendCr) { +// consoles[i].append("\n"); +// } } } diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/ConsoleOutputStream.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/ConsoleOutputStream.java index 71f5924f1..5cb5d1ad9 100644 --- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/ConsoleOutputStream.java +++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/ConsoleOutputStream.java @@ -1,39 +1,39 @@ -package org.eclipse.team.internal.ccvs.ui;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved.
- */
-
-import java.io.IOException;
-import java.io.OutputStream;
-
-/**
- * ConsoleOutputStream is a buffered output stream that additionally
- * flushes the buffer when a carriage return is found.
- */
-public class ConsoleOutputStream extends OutputStream {
-
- private static final int BUFFER_LENGTH = 256;
- private static byte[] buffer = new byte[BUFFER_LENGTH];
- private static int size = 0;
-
- /**
- * @see OutputStream#write(int)
- */
- public void write(int b) throws IOException {
- if ((((char)b) == '\n') || (size >= buffer.length))
- writeBufferToConsole();
- else
- buffer[size++] = (byte)b;
- }
-
- /**
- * Flush the buffer
- */
- private void writeBufferToConsole() {
- Console.appendAll(new String(buffer, 0, size));
- size = 0;
- }
-}
-
+package org.eclipse.team.internal.ccvs.ui; + +/* + * (c) Copyright IBM Corp. 2000, 2001. + * All Rights Reserved. + */ + +import java.io.IOException; +import java.io.OutputStream; + +/** + * ConsoleOutputStream is a buffered output stream that additionally + * flushes the buffer when a carriage return is found. + */ +public class ConsoleOutputStream extends OutputStream { + + private static final int BUFFER_LENGTH = 256; + private static byte[] buffer = new byte[BUFFER_LENGTH]; + private static int size = 0; + + /** + * @see OutputStream#write(int) + */ + public void write(int b) throws IOException { + if ((((char)b) == '\n') || (size >= buffer.length)) + writeBufferToConsole(); + else + buffer[size++] = (byte)b; + } + + /** + * Flush the buffer + */ + private void writeBufferToConsole() { + Console.appendAll(new String(buffer, 0, size)); + size = 0; + } +} + diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/ReleaseCommentDialog.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/ReleaseCommentDialog.java index fc2f700c0..9527a1981 100644 --- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/ReleaseCommentDialog.java +++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/ReleaseCommentDialog.java @@ -1,91 +1,91 @@ -package org.eclipse.team.internal.ccvs.ui;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved.
- */
-
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Text;
-
-/**
- * Prompts the user for a multi-line comment for releasing to CVS.
- */
-public class ReleaseCommentDialog extends Dialog {
- private static final int WIDTH_HINT = 350;
- private static final int HEIGHT_HINT = 50;
-
- private String comment = "";
-
- private Text text;
-
- /**
- * ReleaseCommentDialog constructor.
- *
- * @param parentShell the parent of this dialog
- */
- public ReleaseCommentDialog(Shell parentShell) {
- super(parentShell);
- }
- /*
- * @see Dialog#createDialogArea(Composite)
- */
- protected Control createDialogArea(Composite parent) {
- getShell().setText(Policy.bind("ReleaseCommentDialog.title"));
- Composite composite = new Composite(parent, SWT.NULL);
- composite.setLayout(new GridLayout());
- composite.setLayoutData(new GridData(GridData.FILL_BOTH));
-
- Label label = new Label(composite, SWT.NULL);
- label.setLayoutData(new GridData());
- label.setText(Policy.bind("ReleaseCommentDialog.enterComment"));
-
- text = new Text(composite, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
- GridData data = new GridData(GridData.FILL_BOTH);
- data.widthHint = WIDTH_HINT;
- data.heightHint = HEIGHT_HINT;
- text.setLayoutData(data);
- text.setText(comment);
- text.selectAll();
-/* text.addListener(SWT.KeyDown, new Listener() {
- public void handleEvent(Event e) {
- if (((e.stateMask & SWT.CTRL) != 0) && (e.character == '\n')) {
- okPressed();
- }
- }
- });*/
- return composite;
- }
- /**
- * Return the entered comment
- *
- * @return the comment
- */
- public String getComment() {
- return comment;
- }
- /**
- * Set the initial comment
- *
- * @param comment the initial comment
- */
- public void setComment(String comment) {
- this.comment = comment;
- }
- /*
- * @see Dialog#okPressed
- */
- protected void okPressed() {
- comment = text.getText();
- super.okPressed();
- }
-}
+package org.eclipse.team.internal.ccvs.ui; + +/* + * (c) Copyright IBM Corp. 2000, 2001. + * All Rights Reserved. + */ + +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; + +/** + * Prompts the user for a multi-line comment for releasing to CVS. + */ +public class ReleaseCommentDialog extends Dialog { + private static final int WIDTH_HINT = 350; + private static final int HEIGHT_HINT = 50; + + private String comment = ""; + + private Text text; + + /** + * ReleaseCommentDialog constructor. + * + * @param parentShell the parent of this dialog + */ + public ReleaseCommentDialog(Shell parentShell) { + super(parentShell); + } + /* + * @see Dialog#createDialogArea(Composite) + */ + protected Control createDialogArea(Composite parent) { + getShell().setText(Policy.bind("ReleaseCommentDialog.title")); + Composite composite = new Composite(parent, SWT.NULL); + composite.setLayout(new GridLayout()); + composite.setLayoutData(new GridData(GridData.FILL_BOTH)); + + Label label = new Label(composite, SWT.NULL); + label.setLayoutData(new GridData()); + label.setText(Policy.bind("ReleaseCommentDialog.enterComment")); + + text = new Text(composite, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); + GridData data = new GridData(GridData.FILL_BOTH); + data.widthHint = WIDTH_HINT; + data.heightHint = HEIGHT_HINT; + text.setLayoutData(data); + text.setText(comment); + text.selectAll(); +/* text.addListener(SWT.KeyDown, new Listener() { + public void handleEvent(Event e) { + if (((e.stateMask & SWT.CTRL) != 0) && (e.character == '\n')) { + okPressed(); + } + } + });*/ + return composite; + } + /** + * Return the entered comment + * + * @return the comment + */ + public String getComment() { + return comment; + } + /** + * Set the initial comment + * + * @param comment the initial comment + */ + public void setComment(String comment) { + this.comment = comment; + } + /* + * @see Dialog#okPressed + */ + protected void okPressed() { + comment = text.getText(); + super.okPressed(); + } +} diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/ResourcePropertiesPage.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/ResourcePropertiesPage.java index 91cbed662..e3a506c12 100644 --- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/ResourcePropertiesPage.java +++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/ResourcePropertiesPage.java @@ -1,95 +1,95 @@ -package org.eclipse.team.internal.ccvs.ui;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved.
- */
-
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.team.ccvs.core.CVSTeamProvider;
-import org.eclipse.team.core.TeamException;
-import org.eclipse.team.core.TeamPlugin;
-import org.eclipse.ui.dialogs.PropertyPage;
-
-/**
- * A property page which displays the CVS-specific properties for the
- * selected resource.
- */
-public class ResourcePropertiesPage extends PropertyPage {
- // The resource to show properties for
- IResource resource;
-
- /*
- * @see PreferencePage#createContents(Composite)
- */
- protected Control createContents(Composite parent) {
- Composite composite = new Composite(parent, SWT.NONE);
- GridLayout layout = new GridLayout();
- layout.numColumns = 2;
- layout.marginHeight = layout.marginWidth = 0;
- composite.setLayout(layout);
- composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
-
- try {
- IResource resource = getSelectedElement();
- if (resource != null) {
- CVSTeamProvider provider = (CVSTeamProvider)TeamPlugin.getManager().getProvider(resource.getProject());;
- if (!provider.isManaged(resource)) {
- createPair(composite, Policy.bind("ResourcePropertiesPage.status"), Policy.bind("ResourcePropertiesPage.notManaged"));
- } else {
- createPair(composite, Policy.bind("ResourcePropertiesPage.status"), provider.hasRemote(resource) ? Policy.bind("ResourcePropertiesPage.versioned") : Policy.bind("ResourcePropertiesPage.notVersioned"));
- createPair(composite, Policy.bind("ResourcePropertiesPage.state"), provider.isCheckedOut(resource) ? Policy.bind("ResourcePropertiesPage.checkedOut") : Policy.bind("ResourcePropertiesPage.checkedIn"));
-
- //createPair(composite, Policy.bind("ResourcePropertiesPage.baseRevision"), common != null ? common.getVersionName() : Policy.bind("ResourcePropertiesPage.none"));
- }
- }
- } catch (TeamException e) {
- createPair(composite, Policy.bind("ResourcePropertiesPage.error"), e.getMessage());
- }
- return composite;
- }
-
- /**
- * Creates a key-value property pair in the given parent.
- *
- * @param parent the parent for the labels
- * @param left the string for the left label
- * @param right the string for the right label
- */
- protected void createPair(Composite parent, String left, String right) {
- Label label = new Label(parent, SWT.NONE);
- label.setText(left);
-
- label = new Label(parent, SWT.NONE);
- label.setText(right);
- label.setToolTipText(right);
- label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- }
-
- /**
- * Returns the element selected when the properties was run
- *
- * @return the selected element
- */
- protected IResource getSelectedElement() {
- // get the resource that is the source of this property page
- IResource resource = null;
- IAdaptable element = getElement();
- if (element instanceof IResource) {
- resource = (IResource)element;
- } else {
- Object adapter = element.getAdapter(IResource.class);
- if (adapter instanceof IResource) {
- resource = (IResource)adapter;
- }
- }
- return resource;
- }
-}
+package org.eclipse.team.internal.ccvs.ui; + +/* + * (c) Copyright IBM Corp. 2000, 2001. + * All Rights Reserved. + */ + +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.team.ccvs.core.CVSTeamProvider; +import org.eclipse.team.core.TeamException; +import org.eclipse.team.core.TeamPlugin; +import org.eclipse.ui.dialogs.PropertyPage; + +/** + * A property page which displays the CVS-specific properties for the + * selected resource. + */ +public class ResourcePropertiesPage extends PropertyPage { + // The resource to show properties for + IResource resource; + + /* + * @see PreferencePage#createContents(Composite) + */ + protected Control createContents(Composite parent) { + Composite composite = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + layout.marginHeight = layout.marginWidth = 0; + composite.setLayout(layout); + composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + try { + IResource resource = getSelectedElement(); + if (resource != null) { + CVSTeamProvider provider = (CVSTeamProvider)TeamPlugin.getManager().getProvider(resource.getProject());; + if (!provider.isManaged(resource)) { + createPair(composite, Policy.bind("ResourcePropertiesPage.status"), Policy.bind("ResourcePropertiesPage.notManaged")); + } else { + createPair(composite, Policy.bind("ResourcePropertiesPage.status"), provider.hasRemote(resource) ? Policy.bind("ResourcePropertiesPage.versioned") : Policy.bind("ResourcePropertiesPage.notVersioned")); + createPair(composite, Policy.bind("ResourcePropertiesPage.state"), provider.isCheckedOut(resource) ? Policy.bind("ResourcePropertiesPage.checkedOut") : Policy.bind("ResourcePropertiesPage.checkedIn")); + + //createPair(composite, Policy.bind("ResourcePropertiesPage.baseRevision"), common != null ? common.getVersionName() : Policy.bind("ResourcePropertiesPage.none")); + } + } + } catch (TeamException e) { + createPair(composite, Policy.bind("ResourcePropertiesPage.error"), e.getMessage()); + } + return composite; + } + + /** + * Creates a key-value property pair in the given parent. + * + * @param parent the parent for the labels + * @param left the string for the left label + * @param right the string for the right label + */ + protected void createPair(Composite parent, String left, String right) { + Label label = new Label(parent, SWT.NONE); + label.setText(left); + + label = new Label(parent, SWT.NONE); + label.setText(right); + label.setToolTipText(right); + label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + } + + /** + * Returns the element selected when the properties was run + * + * @return the selected element + */ + protected IResource getSelectedElement() { + // get the resource that is the source of this property page + IResource resource = null; + IAdaptable element = getElement(); + if (element instanceof IResource) { + resource = (IResource)element; + } else { + Object adapter = element.getAdapter(IResource.class); + if (adapter instanceof IResource) { + resource = (IResource)adapter; + } + } + return resource; + } +} diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/UserValidationDialog.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/UserValidationDialog.java index 00180c4d3..d4e76ae88 100644 --- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/UserValidationDialog.java +++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/UserValidationDialog.java @@ -1,186 +1,186 @@ -package org.eclipse.team.internal.ccvs.ui;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved.
- */
-
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.dialogs.IDialogConstants;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.help.WorkbenchHelp;
-
-/**
- * A dialog for prompting for a username and password
- */
-public class UserValidationDialog extends Dialog {
- // widgets
- protected Text usernameField;
- protected Text passwordField;
-
- protected String domain;
- protected String defaultUsername;
- protected String password = null;
-
- // whether or not the username can be changed
- protected boolean isUsernameMutable = true;
- protected String username = null;
- protected String message = null;
-
- /**
- * Creates a new UserValidationDialog.
- *
- * @param parentShell the parent shell
- * @param location the location
- * @param defaultName the default user name
- * @param message a mesage to display to the user
- */
- public UserValidationDialog(Shell parentShell, String location, String defaultName, String message) {
- super(parentShell);
- this.defaultUsername = defaultName;
- this.domain = location;
- this.message = message;
- }
- /**
- * @see Window#configureShell
- */
- protected void configureShell(Shell newShell) {
- super.configureShell(newShell);
- newShell.setText(Policy.bind("UserValidationDialog.required"));
- // set F1 help
- //WorkbenchHelp.setHelp(newShell, new Object[] {ICVSHelpContextIds.USER_VALIDATION_DIALOG});
- }
- /**
- * @see Window#create
- */
- public void create() {
- super.create();
- // add some default values
- usernameField.setText(defaultUsername);
-
- if (isUsernameMutable) {
- // give focus to username field
- usernameField.selectAll();
- usernameField.setFocus();
- } else {
- usernameField.setEditable(false);
- passwordField.setFocus();
- }
- }
- /**
- * @see Dialog#createDialogArea
- */
- protected Control createDialogArea(Composite parent) {
- Composite main = new Composite(parent, SWT.NONE);
- GridLayout layout = new GridLayout();
- layout.numColumns = 3;
- main.setLayout(layout);
- main.setLayoutData(new GridData(GridData.FILL_BOTH));
-
- if (message != null) {
- Label messageLabel = new Label(main, SWT.WRAP);
- messageLabel.setText(message);
- messageLabel.setForeground(messageLabel.getDisplay().getSystemColor(SWT.COLOR_RED));
- GridData data = new GridData(GridData.FILL_HORIZONTAL);
- data.horizontalSpan = 3;
- messageLabel.setLayoutData(data);
- }
-
- Label label = new Label(main, SWT.WRAP);
- if (isUsernameMutable) {
- label.setText(Policy.bind("UserValidationDialog.labelUser", domain));
- } else {
- label.setText(Policy.bind("UserValidationDialog.labelPassword", new Object[] {defaultUsername, domain}));
- }
- GridData data = new GridData(GridData.FILL_HORIZONTAL);
- data.horizontalSpan = 3;
- label.setLayoutData(data);
-
- createUsernameFields(main);
- createPasswordFields(main);
-
- return main;
- }
- /**
- * Creates the three widgets that represent the password entry area.
- *
- * @param parent the parent of the widgets
- */
- protected void createPasswordFields(Composite parent) {
- new Label(parent, SWT.NONE).setText(Policy.bind("UserValidationDialog.password"));
-
- passwordField = new Text(parent, SWT.BORDER);
- GridData data = new GridData(GridData.FILL_HORIZONTAL);
- data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH);
- passwordField.setLayoutData(data);
- passwordField.setEchoChar('*');
-
- // spacer
- new Label(parent, SWT.NONE);
- }
- /**
- * Creates the three widgets that represent the user name entry area.
- *
- * @param parent the parent of the widgets
- */
- protected void createUsernameFields(Composite parent) {
- new Label(parent, SWT.NONE).setText(Policy.bind("UserValidationDialog.user"));
-
- usernameField = new Text(parent, SWT.BORDER);
- GridData data = new GridData(GridData.FILL_HORIZONTAL);
- data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH);
- usernameField.setLayoutData(data);
-
- // spacer
- new Label(parent, SWT.NONE);
- }
- /**
- * Returns the password entered by the user, or null
- * if the user canceled.
- *
- * @return the entered password
- */
- public String getPassword() {
- return password;
- }
- /**
- * Returns the username entered by the user, or null
- * if the user canceled.
- *
- * @return the entered username
- */
- public String getUsername() {
- return username;
- }
- /**
- * Notifies that the ok button of this dialog has been pressed.
- * <p>
- * The default implementation of this framework method sets
- * this dialog's return code to <code>Window.OK</code>
- * and closes the dialog. Subclasses may override.
- * </p>
- */
- protected void okPressed() {
- password = passwordField.getText();
- username = usernameField.getText();
-
- super.okPressed();
- }
- /**
- * Sets whether or not the username field should be mutable.
- * This method must be called before create(), otherwise it
- * will be ignored.
- *
- * @param value whether the username is mutable
- */
- public void setUsernameMutable(boolean value) {
- isUsernameMutable = value;
- }
-}
+package org.eclipse.team.internal.ccvs.ui; + +/* + * (c) Copyright IBM Corp. 2000, 2001. + * All Rights Reserved. + */ + +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.help.WorkbenchHelp; + +/** + * A dialog for prompting for a username and password + */ +public class UserValidationDialog extends Dialog { + // widgets + protected Text usernameField; + protected Text passwordField; + + protected String domain; + protected String defaultUsername; + protected String password = null; + + // whether or not the username can be changed + protected boolean isUsernameMutable = true; + protected String username = null; + protected String message = null; + + /** + * Creates a new UserValidationDialog. + * + * @param parentShell the parent shell + * @param location the location + * @param defaultName the default user name + * @param message a mesage to display to the user + */ + public UserValidationDialog(Shell parentShell, String location, String defaultName, String message) { + super(parentShell); + this.defaultUsername = defaultName; + this.domain = location; + this.message = message; + } + /** + * @see Window#configureShell + */ + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + newShell.setText(Policy.bind("UserValidationDialog.required")); + // set F1 help + //WorkbenchHelp.setHelp(newShell, new Object[] {ICVSHelpContextIds.USER_VALIDATION_DIALOG}); + } + /** + * @see Window#create + */ + public void create() { + super.create(); + // add some default values + usernameField.setText(defaultUsername); + + if (isUsernameMutable) { + // give focus to username field + usernameField.selectAll(); + usernameField.setFocus(); + } else { + usernameField.setEditable(false); + passwordField.setFocus(); + } + } + /** + * @see Dialog#createDialogArea + */ + protected Control createDialogArea(Composite parent) { + Composite main = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.numColumns = 3; + main.setLayout(layout); + main.setLayoutData(new GridData(GridData.FILL_BOTH)); + + if (message != null) { + Label messageLabel = new Label(main, SWT.WRAP); + messageLabel.setText(message); + messageLabel.setForeground(messageLabel.getDisplay().getSystemColor(SWT.COLOR_RED)); + GridData data = new GridData(GridData.FILL_HORIZONTAL); + data.horizontalSpan = 3; + messageLabel.setLayoutData(data); + } + + Label label = new Label(main, SWT.WRAP); + if (isUsernameMutable) { + label.setText(Policy.bind("UserValidationDialog.labelUser", domain)); + } else { + label.setText(Policy.bind("UserValidationDialog.labelPassword", new Object[] {defaultUsername, domain})); + } + GridData data = new GridData(GridData.FILL_HORIZONTAL); + data.horizontalSpan = 3; + label.setLayoutData(data); + + createUsernameFields(main); + createPasswordFields(main); + + return main; + } + /** + * Creates the three widgets that represent the password entry area. + * + * @param parent the parent of the widgets + */ + protected void createPasswordFields(Composite parent) { + new Label(parent, SWT.NONE).setText(Policy.bind("UserValidationDialog.password")); + + passwordField = new Text(parent, SWT.BORDER); + GridData data = new GridData(GridData.FILL_HORIZONTAL); + data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH); + passwordField.setLayoutData(data); + passwordField.setEchoChar('*'); + + // spacer + new Label(parent, SWT.NONE); + } + /** + * Creates the three widgets that represent the user name entry area. + * + * @param parent the parent of the widgets + */ + protected void createUsernameFields(Composite parent) { + new Label(parent, SWT.NONE).setText(Policy.bind("UserValidationDialog.user")); + + usernameField = new Text(parent, SWT.BORDER); + GridData data = new GridData(GridData.FILL_HORIZONTAL); + data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH); + usernameField.setLayoutData(data); + + // spacer + new Label(parent, SWT.NONE); + } + /** + * Returns the password entered by the user, or null + * if the user canceled. + * + * @return the entered password + */ + public String getPassword() { + return password; + } + /** + * Returns the username entered by the user, or null + * if the user canceled. + * + * @return the entered username + */ + public String getUsername() { + return username; + } + /** + * Notifies that the ok button of this dialog has been pressed. + * <p> + * The default implementation of this framework method sets + * this dialog's return code to <code>Window.OK</code> + * and closes the dialog. Subclasses may override. + * </p> + */ + protected void okPressed() { + password = passwordField.getText(); + username = usernameField.getText(); + + super.okPressed(); + } + /** + * Sets whether or not the username field should be mutable. + * This method must be called before create(), otherwise it + * will be ignored. + * + * @param value whether the username is mutable + */ + public void setUsernameMutable(boolean value) { + isUsernameMutable = value; + } +} diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/wizards/ConfigurationWizardAutoconnectPage.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/wizards/ConfigurationWizardAutoconnectPage.java index 431d233a6..042a9193d 100644 --- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/wizards/ConfigurationWizardAutoconnectPage.java +++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/wizards/ConfigurationWizardAutoconnectPage.java @@ -20,7 +20,7 @@ import org.eclipse.swt.widgets.Listener; import org.eclipse.team.ccvs.core.CVSProviderPlugin; import org.eclipse.team.ccvs.core.ICVSRepositoryLocation; import org.eclipse.team.core.TeamException; -import org.eclipse.team.internal.ccvs.core.Client; +import org.eclipse.team.internal.ccvs.core.client.Session; 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; @@ -102,7 +102,7 @@ public class ConfigurationWizardAutoconnectPage extends CVSWizardPage { } public void setProject(IProject project) { try { - ICVSFolder folder = (ICVSFolder)Client.getManagedResource(project); + ICVSFolder folder = (ICVSFolder)Session.getManagedResource(project); FolderSyncInfo info = folder.getFolderSyncInfo(); if (info == null) { // This should never happen diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/wizards/GenerateDiffFileOperation.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/wizards/GenerateDiffFileOperation.java index 3fd3a15af..b1933da80 100644 --- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/wizards/GenerateDiffFileOperation.java +++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/wizards/GenerateDiffFileOperation.java @@ -24,9 +24,9 @@ import org.eclipse.swt.dnd.TextTransfer; import org.eclipse.swt.dnd.Transfer; import org.eclipse.swt.widgets.Shell; import org.eclipse.team.ccvs.core.CVSTeamProvider; -import org.eclipse.team.ccvs.core.CVSCommandOptions.DiffOption; import org.eclipse.team.core.TeamException; import org.eclipse.team.core.TeamPlugin; +import org.eclipse.team.internal.ccvs.core.client.Command.LocalOption; import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin; import org.eclipse.team.internal.ccvs.ui.Policy; @@ -40,10 +40,10 @@ public class GenerateDiffFileOperation implements IRunnableWithProgress { private File outputFile; private IResource[] resources; private Shell shell; - private DiffOption[] options; + private LocalOption[] options; private boolean toClipboard; - GenerateDiffFileOperation(IResource[] resources, File file, boolean toClipboard, DiffOption[] options, Shell shell) { + GenerateDiffFileOperation(IResource[] resources, File file, boolean toClipboard, LocalOption[] options, Shell shell) { this.resources = resources; this.outputFile = file; this.shell = shell; diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/wizards/GenerateDiffFileWizard.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/wizards/GenerateDiffFileWizard.java index ef8c05b69..c742e3e47 100644 --- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/wizards/GenerateDiffFileWizard.java +++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/wizards/GenerateDiffFileWizard.java @@ -9,9 +9,9 @@ import java.io.File; import java.lang.reflect.InvocationTargetException; import java.net.MalformedURLException; import java.net.URL; - import java.util.ArrayList; import java.util.List; + import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; @@ -38,7 +38,6 @@ import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; @@ -47,7 +46,8 @@ import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Text; -import org.eclipse.team.ccvs.core.CVSCommandOptions.DiffOption; +import org.eclipse.team.internal.ccvs.core.client.Diff; +import org.eclipse.team.internal.ccvs.core.client.Command.LocalOption; import org.eclipse.team.internal.ccvs.ui.CVSUIPlugin; import org.eclipse.team.internal.ccvs.ui.Policy; import org.eclipse.ui.IWorkbench; @@ -405,20 +405,20 @@ public class GenerateDiffFileWizard extends Wizard { /** * Return the list of Diff command options configured on this page. */ - public DiffOption[] getOptions() { + public LocalOption[] getOptions() { List options = new ArrayList(5); if(!dontIncludeNewFilesOptions.getSelection()) { - options.add(DiffOption.INCLUDE_NEWFILES); + options.add(Diff.INCLUDE_NEWFILES); } if(recurseOption.getSelection()) { - options.add(DiffOption.DONT_RECURSE); + options.add(Diff.DO_NOT_RECURSE); } if(unifiedDiffOption.getSelection()) { - options.add(DiffOption.UNIFIED_FORMAT); + options.add(Diff.UNIFIED_FORMAT); } else if(contextDiffOption.getSelection()) { - options.add(DiffOption.CONTEXT_FORMAT); + options.add(Diff.CONTEXT_FORMAT); } - return (DiffOption[]) options.toArray(new DiffOption[options.size()]); + return (LocalOption[]) options.toArray(new LocalOption[options.size()]); } } // end of PatchFileCreationOptionsPage diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/wizards/SharingWizard.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/wizards/SharingWizard.java index 8840427d5..9d2e7cdc4 100644 --- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/wizards/SharingWizard.java +++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/wizards/SharingWizard.java @@ -22,7 +22,7 @@ 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.CVSProvider; -import org.eclipse.team.internal.ccvs.core.Client; +import org.eclipse.team.internal.ccvs.core.client.Session; import org.eclipse.team.internal.ccvs.core.connection.CVSRepositoryLocation; import org.eclipse.team.internal.ccvs.core.resources.FolderSyncInfo; import org.eclipse.team.internal.ccvs.core.resources.ICVSFolder; @@ -120,7 +120,7 @@ public class SharingWizard extends Wizard implements IConfigurationWizard { } // Associate project with provider - ICVSFolder folder = (ICVSFolder)Client.getManagedResource(project); + ICVSFolder folder = (ICVSFolder)Session.getManagedResource(project); FolderSyncInfo info = folder.getFolderSyncInfo(); if (info == null) { // Error! @@ -133,7 +133,7 @@ public class SharingWizard extends Wizard implements IConfigurationWizard { if (validate) { // Do the validation right now try { - location.validateConnection(); + location.validateConnection(monitor); } catch (TeamException e) { if (created) CVSProviderPlugin.getProvider().disposeRepository(location); @@ -151,7 +151,7 @@ public class SharingWizard extends Wizard implements IConfigurationWizard { ICVSRepositoryLocation location = getLocation(); try { - location.validateConnection(); + location.validateConnection(monitor); String moduleName = getModuleName(); ICVSRemoteFolder folder = location.getRemoteFolder(moduleName, null); try { @@ -256,7 +256,7 @@ public class SharingWizard extends Wizard implements IConfigurationWizard { // Determine if there is an existing CVS/ directory from which configuration // information can be retrieved. try { - ICVSFolder folder = (ICVSFolder)Client.getManagedResource(project); + ICVSFolder folder = (ICVSFolder)Session.getManagedResource(project); FolderSyncInfo info = folder.getFolderSyncInfo(); return info != null; } catch (TeamException e) { |