org.eclipse.team.cvs.core_3.3.400.I20110510-0800

lipse.team.internal.ccvs.core.ICVSFile;
import org.eclipse.team.internal.ccvs.core.ICVSFolder;
import org.eclipse.team.internal.ccvs.core.util.Util;

class CheckedInHandler
  extends ResponseHandler
{
  public String getResponseID()
  {
    return "Checked-in";
  }
  
  public void handle(Session session, String localDir, IProgressMonitor monitor)
    throws CVSException
  {
    String repositoryFile = session.readLine();
    String entryLine = session.readLine();
    
    session.setModTime(null);
    
    String fileName = repositoryFile.substring(repositoryFile.lastIndexOf("/") + 1);
    ICVSFolder mParent = session.getLocalRoot().getFolder(localDir);
    ICVSFile mFile = mParent.getFile(fileName);
    
    monitor.subTask(NLS.bind(CVSMessages.CheckInHandler_checkedIn, new String[] { Util.toTruncatedPath(mFile, session.getLocalRoot(), 3) }));
    mFile.checkedIn(entryLine, session.getCurrentCommand() instanceof Commit);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.team.internal.ccvs.core.client.CheckedInHandler
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.team.internal.ccvs.core.client;

import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.runtime.Assert;
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.CVSTag;
import org.eclipse.team.internal.ccvs.core.ICVSFolder;
import org.eclipse.team.internal.ccvs.core.ICVSResource;
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.client.listeners.ModuleDefinitionsListener;
import org.eclipse.team.internal.ccvs.core.client.listeners.UpdateListener;
import org.eclipse.team.internal.ccvs.core.connection.CVSServerException;
import org.eclipse.team.internal.ccvs.core.resources.RemoteModule;

public class Checkout
  extends Command
{
  public static final Command.LocalOption DO_NOT_SHORTEN = new Command.LocalOption("-N");
  public static final Command.LocalOption FETCH_MODULE_ALIASES = new Command.LocalOption("-c");
  
  public static Command.LocalOption makeDirectoryNameOption(String moduleName)
  {
    return new Command.LocalOption("-d", moduleName);
  }
  
  private static final ICommandOutputListener DEFAULT_OUTPUT_LISTENER = new UpdateListener(null);
  public static Command.LocalOption ALIAS = new Command.LocalOption("-a");
  
  public static Command.LocalOption makeStatusOption(String status)
  {
    return new Command.LocalOption("-s", status);
  }
  
  protected String getRequestId()
  {
    return "co";
  }
  
  protected ICommandOutputListener getDefaultCommandOutputListener()
  {
    return DEFAULT_OUTPUT_LISTENER;
  }
  
  protected ICVSResource[] computeWorkResources(Session session, Command.LocalOption[] localOptions, String[] arguments)
    throws CVSException
  {
    if ((arguments.length < 1) && (!FETCH_MODULE_ALIASES.isElementOf(localOptions))) {
      throw new IllegalArgumentException();
    }
    Command.Option dOption = findOption(localOptions, "-d");
    if (dOption != null) {
      return new ICVSResource[] { session.getLocalRoot().getFolder(argument) };
    }
    String[] modules = session.getModuleExpansions();
    ICVSResource[] resources = new ICVSResource[modules.length];
    for (int i = 0; i < resources.length; i++) {
      resources[i] = session.getLocalRoot().getFolder(modules[i]);
    }
    return resources;
  }
  
  protected ICVSResource[] sendLocalResourceState(Session session, Command.GlobalOption[] globalOptions, Command.LocalOption[] localOptions, ICVSResource[] resources, IProgressMonitor monitor)
    throws CVSException
  {
    Assert.isTrue(session.getLocalRoot().isFolder());
    
    List resourcesToSend = new ArrayList(resources.length);
    for (int i = 0; i < resources.length; i++)
    {
      ICVSResource resource = resources[i];
      if ((resource.exists()) && (resource.isFolder()) && (((ICVSFolder)resource).isCVSFolder())) {
        resourcesToSend.add(resource);
      }
    }
    if (!resourcesToSend.isEmpty())
    {
      resources = (ICVSResource[])resourcesToSend.toArray(new ICVSResource[resourcesToSend.size()]);
      new FileStructureVisitor(session, localOptions, true, true).visit(session, resources, monitor);
    }
    else
    {
      monitor.beginTask(null, 100);
      monitor.done();
    }
    return resources;
  }
  
  protected void sendLocalWorkingDirectory(Session session)
    throws CVSException
  {
    session.sendConstructedRootDirectory();
  }
  
  protected IStatus commandFinished(Session session, Command.GlobalOption[] globalOptions, Command.LocalOption[] localOptions, ICVSResource[] resources, IProgressMonitor monitor, IStatus status)
    throws CVSException
  {
    if (status.getCode() == -10) {
      return status;
    }
    if (FETCH_MODULE_ALIASES.isElementOf(localOptions)) {
      return status;
    }
    if ((PRUNE_EMPTY_DIRECTORIES.isElementOf(localOptions)) || 
      (findOption(localOptions, "-D") != null) || 
      (findOption(localOptions, "-r") != null)) {
      new PruneFolderVisitor().visit(session, resources);
    }
    return status;
  }
  
  protected IStatus doExecute(Session session, Command.GlobalOption[] globalOptions, Command.LocalOption[] localOptions, String[] arguments, ICommandOutputListener listener, IProgressMonitor monitor)
    throws CVSException
  {
    monitor.beginTask(null, 100);
    if (!FETCH_MODULE_ALIASES.isElementOf(localOptions))
    {
      IStatus status = Request.EXPAND_MODULES.execute(session, arguments, Policy.subMonitorFor(monitor, 10));
      if (status.getCode() == -10) {
        return status;
      }
      if ((findOption(localOptions, "-d") == null) && 
        (!DO_NOT_SHORTEN.isElementOf(localOptions)))
      {
        Command.LocalOption[] newLocalOptions = new Command.LocalOption[localOptions.length + 1];
        newLocalOptions[0] = DO_NOT_SHORTEN;
        System.arraycopy(localOptions, 0, newLocalOptions, 1, localOptions.length);
        localOptions = newLocalOptions;
      }
    }
    return super.doExecute(session, globalOptions, localOptions, arguments, listener, Policy.subMonitorFor(monitor, 90));
  }
  
  public RemoteModule[] getRemoteModules(Session session, CVSTag tag, IProgressMonitor monitor)
    throws CVSException
  {
    ModuleDefinitionsListener moduleDefinitionListener = new ModuleDefinitionsListener();
    
    IStatus status = super.execute(session, NO_GLOBAL_OPTIONS, new Command.LocalOption[] { FETCH_MODULE_ALIASES }, NO_ARGUMENTS, 
      moduleDefinitionListener, monitor);
    if (status.getCode() == -10) {
      throw new CVSServerException(status);
    }
    return RemoteModule.createRemoteModules(moduleDefinitionListener.getModuleExpansions(), session.getCVSRepositoryLocation(), tag);
  }
  
  protected String getDisplayText()
  {
    return "checkout";
  }
}

/* Location:
 * Qualified Name:     org.eclipse.team.internal.ccvs.core.client.Checkout
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.team.internal.ccvs.core.client;

public class CheckoutWithOverwrite$CreatedResponseHandler
  extends UpdatedHandler
{
  final CheckoutWithOverwrite this$0;
  
  public CheckoutWithOverwrite$CreatedResponseHandler(CheckoutWithOverwrite paramCheckoutWithOverwrite)
  {
    super(1);
    this$0 = paramCheckoutWithOverwrite;
  }
  
  public String getResponseID()
  {
    return "Created";
  }
}

/* Location:
 * Qualified Name:     org.eclipse.team.internal.ccvs.core.client.CheckoutWithOverwrite.CreatedResponseHandler
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.team.internal.ccvs.core.client;

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.listeners.ICommandOutputListener;

public class CheckoutWithOverwrite
  extends Checkout
{
  public class CreatedResponseHandler
    extends UpdatedHandler
  {
    public CreatedResponseHandler()
    {
      super();
    }
    
    public String getResponseID()
    {
      return "Created";
    }
  }
  
  protected IStatus doExecute(Session session, Command.GlobalOption[] globalOptions, Command.LocalOption[] localOptions, String[] arguments, ICommandOutputListener listener, IProgressMonitor monitor)
    throws CVSException
  {
    ResponseHandler newCreated = new CreatedResponseHandler();
    ResponseHandler oldCreated = session.getResponseHandler(newCreated.getResponseID());
    session.registerResponseHandler(newCreated);
    try
    {
      return super.doExecute(
        session, 
        globalOptions, 
        localOptions, 
        arguments, 
        listener, 
        monitor);
    }
    finally
    {
      session.registerResponseHandler(oldCreated);
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.team.internal.ccvs.core.client.CheckoutWithOverwrite
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.team.internal.ccvs.core.client;

import org.eclipse.core.resources.IResource;
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.internal.ccvs.core.CVSException;
import org.eclipse.team.internal.ccvs.core.ICVSFolder;
import org.eclipse.team.internal.ccvs.core.ICVSRunnable;
import org.eclipse.team.internal.ccvs.core.Policy;
import org.eclipse.team.internal.ccvs.core.client.listeners.ICommandOutputListener;

class Command$1
  implements ICVSRunnable
{
  final Command this$0;
  private final Session val$session;
  private final Command.GlobalOption[] val$globalOptions;
  private final Command.LocalOption[] val$localOptions;
  private final String[] val$arguments;
  private final IStatus[] val$status;
  private final ICommandOutputListener val$listener;
  
  Command$1(Command paramCommand, Session paramSession, Command.GlobalOption[] paramArrayOfGlobalOption, Command.LocalOption[] paramArrayOfLocalOption, String[] paramArrayOfString, IStatus[] paramArrayOfIStatus, ICommandOutputListener paramICommandOutputListener)
  {
    this$0 = paramCommand;val$session = paramSession;val$globalOptions = paramArrayOfGlobalOption;val$localOptions = paramArrayOfLocalOption;val$arguments = paramArrayOfString;val$status = paramArrayOfIStatus;val$listener = paramICommandOutputListener;
  }
  
  public void run(IProgressMonitor monitor)
    throws CVSException
  {
    Command.GlobalOption[] gOptions = this$0.filterGlobalOptions(val$session, val$globalOptions);
    Command.LocalOption[] lOptions = this$0.filterLocalOptions(val$session, gOptions, val$localOptions);
    if ((val$session.isOutputToConsole()) || (Policy.isDebugProtocol()))
    {
      IResource resource = val$session.getLocalRoot().getIResource();
      IPath commandRootPath;
      IPath commandRootPath;
      if (resource == null) {
        commandRootPath = Path.EMPTY;
      } else {
        commandRootPath = resource.getFullPath();
      }
      String line = Command.access$1(this$0, commandRootPath, gOptions, lOptions, val$arguments);
      ConsoleListeners.getInstance().commandInvoked(val$session, line);
      if (Policy.isDebugProtocol()) {
        Policy.printProtocolLine("CMD> " + line);
      }
    }
    try
    {
      val$session.setCurrentCommand(this$0);
      val$status[0] = this$0.doExecute(val$session, gOptions, lOptions, val$arguments, val$listener, monitor);
      Command.access$2(this$0, val$session, val$status[0], null);
    }
    catch (CVSException e)
    {
      Command.access$2(this$0, val$session, null, e);
      throw e;
    }
    catch (RuntimeException e)
    {
      Command.access$2(this$0, val$session, null, e);
      throw e;
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.team.internal.ccvs.core.client.Command.1
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.team.internal.ccvs.core.client;

import org.eclipse.team.internal.ccvs.core.CVSException;

public class Command$GlobalOption
  extends Command.Option
{
  protected Command$GlobalOption(String option)
  {
    super(option, null);
  }
  
  public void send(Session session)
    throws CVSException
  {
    session.sendGlobalOption(option);
  }
  
  protected GlobalOption[] addToEnd(GlobalOption[] options)
  {
    GlobalOption[] globalOptions = new GlobalOption[options.length + 1];
    System.arraycopy(options, 0, globalOptions, 0, options.length);
    globalOptions[(globalOptions.length - 1)] = this;
    return globalOptions;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.team.internal.ccvs.core.client.Command.GlobalOption
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.team.internal.ccvs.core.client;

import java.util.Collection;
import java.util.Map;
import org.eclipse.core.resources.IFile;
import org.eclipse.osgi.util.NLS;
import org.eclipse.team.internal.ccvs.core.CVSMessages;
import org.eclipse.team.internal.ccvs.core.CVSProviderPlugin;

public class Command$KSubstOption
  extends Command.LocalOption
{
  private boolean isUnknownMode;
  
  Command$KSubstOption(String paramString, KSubstOption paramKSubstOption)
  {
    this(paramString);
  }
  
  private Command$KSubstOption(String option)
  {
    this(option, false);
  }
  
  private Command$KSubstOption(String option, boolean isUnknownMode)
  {
    super(option);
    this.isUnknownMode = isUnknownMode;
    Command.access$0().put(option, this);
  }
  
  public static KSubstOption fromMode(String mode)
  {
    if (mode.length() == 0) {
      mode = "-kkv";
    }
    KSubstOption option = (KSubstOption)Command.access$0().get(mode);
    if (option == null) {
      option = new KSubstOption(mode, true);
    }
    return option;
  }
  
  public static KSubstOption fromFile(IFile file)
  {
    if (CVSProviderPlugin.isText(file)) {
      return getDefaultTextMode();
    }
    return Command.KSUBST_BINARY;
  }
  
  public static KSubstOption[] getAllKSubstOptions()
  {
    return (KSubstOption[])Command.access$0().values().toArray(new KSubstOption[Command.access$0().size()]);
  }
  
  public String toEntryLineMode()
  {
    if (Command.KSUBST_TEXT_EXPAND.equals(this)) {
      return "";
    }
    return getOption();
  }
  
  public String toMode()
  {
    return getOption();
  }
  
  public boolean isBinary()
  {
    return Command.KSUBST_BINARY.equals(this);
  }
  
  public String getShortDisplayText()
  {
    if (isUnknownMode) {
      return NLS.bind(CVSMessages.KSubstOption_unknown_short, new String[] { option });
    }
    if (option.equals("-kb")) {
      return CVSMessages.KSubstOption__kb_short;
    }
    if (option.equals("-kkv")) {
      return CVSMessages.KSubstOption__kkv_short;
    }
    if (option.equals("-ko")) {
      return CVSMessages.KSubstOption__ko_short;
    }
    if (option.equals("-kk")) {
      return CVSMessages.KSubstOption__kk_short;
    }
    if (option.equals("-kv")) {
      return CVSMessages.KSubstOption__kv_short;
    }
    if (option.equals("-kkvl")) {
      return CVSMessages.KSubstOption__kkvl_short;
    }
    return NLS.bind(CVSMessages.KSubstOption_unknown_short, new String[] { option });
  }
  
  public String getLongDisplayText()
  {
    if (isUnknownMode) {
      return NLS.bind(CVSMessages.KSubstOption_unknown_long, new String[] { option });
    }
    if (option.equals("-kb")) {
      return CVSMessages.KSubstOption__kb_long;
    }
    if (option.equals("-kkv")) {
      return CVSMessages.KSubstOption__kkv_long;
    }
    if (option.equals("-ko")) {
      return CVSMessages.KSubstOption__ko_long;
    }
    if (option.equals("-kk")) {
      return CVSMessages.KSubstOption__kk_long;
    }
    if (option.equals("-kv")) {
      return CVSMessages.KSubstOption__kv_long;
    }
    if (option.equals("-kkvl")) {
      return CVSMessages.KSubstOption__kkvl_long;
    }
    return NLS.bind(CVSMessages.KSubstOption_unknown_long, new String[] { option });
  }
  
  public static KSubstOption getDefaultTextMode()
  {
    return CVSProviderPlugin.getPlugin().getDefaultTextKSubstOption();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.team.internal.ccvs.core.client.Command.KSubstOption
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.team.internal.ccvs.core.client;

import java.util.ArrayList;
import java.util.List;
import org.eclipse.team.internal.ccvs.core.CVSException;

public class Command$LocalOption
  extends Command.Option
{
  protected Command$LocalOption(String option)
  {
    super(option, null);
  }
  
  protected Command$LocalOption(String option, String argument)
  {
    super(option, argument);
  }
  
  public void send(Session session)
    throws CVSException
  {
    session.sendArgument(option);
    if (argument != null) {
      session.sendArgument(argument);
    }
  }
  
  public LocalOption[] addTo(LocalOption[] options)
  {
    if (isElementOf(options)) {
      return options;
    }
    LocalOption[] newOptions = new LocalOption[options.length + 1];
    System.arraycopy(options, 0, newOptions, 0, options.length);
    newOptions[options.length] = this;
    return newOptions;
  }
  
  public LocalOption[] removeFrom(LocalOption[] options)
  {
    if (!isElementOf(options)) {
      return options;
    }
    List result = new ArrayList();
    for (int i = 0; i < options.length; i++)
    {
      LocalOption option = options[i];
      if (!option.equals(this)) {
        result.add(option);
      }
    }
    return (LocalOption[])result.toArray(new LocalOption[result.size()]);
  }
}

/* Location:
 * Qualified Name:     org.eclipse.team.internal.ccvs.core.client.Command.LocalOption
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.team.internal.ccvs.core.client;

import org.eclipse.team.internal.ccvs.core.CVSException;

public abstract class Command$Option
{
  protected String option;
  protected String argument;
  
  protected Command$Option(String option, String argument)
  {
    this.option = option;
    this.argument = argument;
  }
  
  public boolean isElementOf(Option[] array)
  {
    return Command.findOption(array, option) != null;
  }
  
  String getOption()
  {
    return option;
  }
  
  public boolean equals(Object other)
  {
    if (this == other) {
      return true;
    }
    if ((other instanceof Option))
    {
      Option otherOption = (Option)other;
      return option.equals(option);
    }
    return false;
  }
  
  public abstract void send(Session paramSession)
    throws CVSException;
  
  public String toString()
  {
    if ((argument != null) && (argument.length() != 0)) {
      return option + " \"" + argument + '"';
    }
    return option;
  }
}

/* Location:
 * Qualified Name:     org.eclipse.team.internal.ccvs.core.client.Command.Option
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.team.internal.ccvs.core.client;

import org.eclipse.team.internal.ccvs.core.CVSException;

public final class Command$QuietOption
  extends Command.GlobalOption
{
  Command$QuietOption(String paramString, QuietOption paramQuietOption)
  {
    this(paramString);
  }
  
  private Command$QuietOption(String option)
  {
    super(option);
  }
  
  public void send(Session session)
    throws CVSException
  {
    if (option.length() != 0) {
      super.send(session);
    }
  }
}

/* Location:
 * Qualified Name:     org.eclipse.team.internal.ccvs.core.client.Command.QuietOption
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.team.internal.ccvs.core.client;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.osgi.util.NLS;
import org.eclipse.team.internal.ccvs.core.CVSException;
import org.eclipse.team.internal.ccvs.core.CVSMessages;
import org.eclipse.team.internal.ccvs.core.CVSProviderPlugin;
import org.eclipse.team.internal.ccvs.core.CVSStatus;
import org.eclipse.team.internal.ccvs.core.CVSTag;
import org.eclipse.team.internal.ccvs.core.ICVSFolder;
import org.eclipse.team.internal.ccvs.core.ICVSResource;
import org.eclipse.team.internal.ccvs.core.ICVSRunnable;
import org.eclipse.team.internal.ccvs.core.Policy;
import org.eclipse.team.internal.ccvs.core.client.listeners.ICommandOutputListener;

public abstract class Command
  extends Request
{
  public static final Add ADD = new Add();
  public static final Admin ADMIN = new Admin();
  public static final Annotate ANNOTATE = new Annotate();
  public static final Checkout CHECKOUT = new CheckoutWithOverwrite();
  public static final Commit COMMIT = new Commit();
  public static final Diff DIFF = new Diff();
  public static final RDiff RDIFF = new RDiff();
  public static final Editors EDITORS = new Editors();
  public static final Import IMPORT = new Import();
  public static final Log LOG = new Log();
  public static final Remove REMOVE = new Remove();
  public static final Status STATUS = new Status();
  public static final Tag TAG = new Tag();
  public static final Tag CUSTOM_TAG = new Tag(true);
  public static final RTag RTAG = new RTag();
  public static final Update UPDATE = new Update();
  public static final Update REPLACE = new Replace();
  public static final SyncUpdate SYNCUPDATE = new SyncUpdate();
  public static final Version VERSION = new Version();
  public static final NOOPCommand NOOP = new NOOPCommand();
  public static final String[] NO_ARGUMENTS = new String[0];
  public static final GlobalOption[] NO_GLOBAL_OPTIONS = new GlobalOption[0];
  public static final GlobalOption DO_NOT_CHANGE = new GlobalOption("-n");
  public static final GlobalOption DO_NOT_LOG = new GlobalOption("-l");
  public static final GlobalOption MAKE_READ_ONLY = new GlobalOption("-r");
  public static final GlobalOption TRACE_EXECUTION = new GlobalOption("-t");
  public static final QuietOption VERBOSE = new QuietOption("", null);
  public static final QuietOption PARTLY_QUIET = new QuietOption("-q", null);
  public static final QuietOption SILENT = new QuietOption("-Q", null);
  public static final LocalOption[] NO_LOCAL_OPTIONS = new LocalOption[0];
  public static final LocalOption RECURSE = new LocalOption("-R");
  public static final LocalOption DO_NOT_RECURSE = new LocalOption("-l");
  public static final LocalOption PRUNE_EMPTY_DIRECTORIES = new LocalOption("-P");
  public static final LocalOption MESSAGE_OPTION = new LocalOption("-m");
  private static final Map ksubstOptionMap = new HashMap();
  public static final KSubstOption KSUBST_BINARY = new KSubstOption("-kb", null);
  public static final KSubstOption KSUBST_TEXT = new KSubstOption("-ko", null);
  public static final KSubstOption KSUBST_TEXT_EXPAND = new KSubstOption("-kkv", null);
  public static final KSubstOption KSUBST_TEXT_EXPAND_LOCKER = new KSubstOption("-kkvl", null);
  public static final KSubstOption KSUBST_TEXT_VALUES_ONLY = new KSubstOption("-kv", null);
  public static final KSubstOption KSUBST_TEXT_KEYWORDS_ONLY = new KSubstOption("-kk", null);
  protected static final ICommandOutputListener DEFAULT_OUTPUT_LISTENER = new CommandOutputListener();
  
  protected ICommandOutputListener getDefaultCommandOutputListener()
  {
    return DEFAULT_OUTPUT_LISTENER;
  }
  
  protected void sendArguments(Session session, String[] arguments)
    throws CVSException
  {
    for (int i = 0; i < arguments.length; i++) {
      session.sendArgument(arguments[i]);
    }
  }
  
  protected abstract ICVSResource[] sendLocalResourceState(Session paramSession, GlobalOption[] paramArrayOfGlobalOption, LocalOption[] paramArrayOfLocalOption, ICVSResource[] paramArrayOfICVSResource, IProgressMonitor paramIProgressMonitor)
    throws CVSException;
  
  protected IStatus commandFinished(Session session, GlobalOption[] globalOptions, LocalOption[] localOptions, ICVSResource[] resources, IProgressMonitor monitor, IStatus status)
    throws CVSException
  {
    return status;
  }
  
  protected void sendLocalWorkingDirectory(Session session)
    throws CVSException
  {
    ICVSFolder localRoot = session.getLocalRoot();
    if (localRoot.isCVSFolder()) {
      session.sendLocalRootDirectory();
    } else {
      session.sendConstructedRootDirectory();
    }
  }
  
  protected ICVSResource[] computeWorkResources(Session session, LocalOption[] localOptions, String[] arguments)
    throws CVSException
  {
    ICVSFolder localRoot = session.getLocalRoot();
    if (arguments.length == 0) {
      return new ICVSResource[] { localRoot };
    }
    ICVSResource[] resources = new ICVSResource[arguments.length];
    for (int i = 0; i < arguments.length; i++)
    {
      ICVSResource resource = localRoot.getChild(arguments[i]);
      if (resource == null) {
        if (localRoot.getName().length() == 0) {
          resource = localRoot.getFolder(arguments[i]);
        } else {
          resource = localRoot.getFile(arguments[i]);
        }
      }
      resources[i] = resource;
    }
    return resources;
  }
  
  protected void sendFileStructure(Session session, ICVSResource[] resources, LocalOption[] localOptions, boolean emptyFolders, IProgressMonitor monitor)
    throws CVSException
  {
    checkResourcesManaged(session, resources);
    
    new FileStructureVisitor(session, localOptions, emptyFolders, true).visit(session, resources, monitor);
  }
  
  protected void checkResourcesManaged(Session session, ICVSResource[] resources)
    throws CVSException
  {
    for (int i = 0; i < resources.length; i++)
    {
      ICVSFolder folder;
      ICVSFolder folder;
      if (resources[i].isFolder()) {
        folder = (ICVSFolder)resources[i];
      } else {
        folder = resources[i].getParent();
      }
      if ((!folder.isCVSFolder()) && (folder.exists()))
      {
        IStatus status = new CVSStatus(4, 4, NLS.bind(CVSMessages.Command_argumentNotManaged, new String[] { folder.getName() }), session.getLocalRoot());
        throw new CVSException(status);
      }
    }
  }
  
  public final IStatus execute(Session session, GlobalOption[] globalOptions, LocalOption[] localOptions, String[] arguments, ICommandOutputListener listener, IProgressMonitor pm)
    throws CVSException
  {
    IStatus[] status = new IStatus[1];
    ICVSRunnable job = new ICVSRunnable()
    {
      private final Session val$session;
      private final Command.GlobalOption[] val$globalOptions;
      private final Command.LocalOption[] val$localOptions;
      private final String[] val$arguments;
      private final IStatus[] val$status;
      private final ICommandOutputListener val$listener;
      
      public void run(IProgressMonitor monitor)
        throws CVSException
      {
        Command.GlobalOption[] gOptions = filterGlobalOptions(val$session, val$globalOptions);
        Command.LocalOption[] lOptions = filterLocalOptions(val$session, gOptions, val$localOptions);
        if ((val$session.isOutputToConsole()) || (Policy.isDebugProtocol()))
        {
          IResource resource = val$session.getLocalRoot().getIResource();
          IPath commandRootPath;
          IPath commandRootPath;
          if (resource == null) {
            commandRootPath = Path.EMPTY;
          } else {
            commandRootPath = resource.getFullPath();
          }
          String line = Command.this.constructCommandInvocationString(commandRootPath, gOptions, lOptions, val$arguments);
          ConsoleListeners.getInstance().commandInvoked(val$session, line);
          if (Policy.isDebugProtocol()) {
            Policy.printProtocolLine("CMD> " + line);
          }
        }
        try
        {
          val$session.setCurrentCommand(Command.this);
          val$status[0] = doExecute(val$session, gOptions, lOptions, val$arguments, val$listener, monitor);
          Command.this.notifyConsoleOnCompletion(val$session, val$status[0], null);
        }
        catch (CVSException e)
        {
          Command.this.notifyConsoleOnCompletion(val$session, null, e);
          throw e;
        }
        catch (RuntimeException e)
        {
          Command.this.notifyConsoleOnCompletion(val$session, null, e);
          throw e;
        }
      }
    };
    if (isWorkspaceModification()) {
      session.getLocalRoot().run(job, pm);
    } else {
      job.run(pm);
    }
    return status[0];
  }
  
  protected boolean isWorkspaceModification()
  {
    return true;
  }
  
  private void notifyConsoleOnCompletion(Session session, IStatus status, Exception exception)
  {
    ConsoleListeners.getInstance().commandCompleted(session, status, exception);
    if (Policy.isDebugProtocol()) {
      if (status != null) {
        Policy.printProtocolLine("RESULT> " + status.toString());
      } else {
        Policy.printProtocolLine("RESULT> " + exception.toString());
      }
    }
  }
  
  protected IStatus doExecute(Session session, GlobalOption[] globalOptions, LocalOption[] localOptions, String[] arguments, ICommandOutputListener listener, IProgressMonitor monitor)
    throws CVSException
  {
    ICVSResource[] resources = (ICVSResource[])null;
    
    monitor = Policy.monitorFor(monitor);
    monitor.beginTask(null, 100);
    Policy.checkCanceled(monitor);
    try
    {
      session.setNoLocalChanges(DO_NOT_CHANGE.isElementOf(globalOptions));
      session.setModTime(null);
      for (int i = 0; i < globalOptions.length; i++) {
        globalOptions[i].send(session);
      }
      Policy.checkCanceled(monitor);
      for (int i = 0; i < localOptions.length; i++) {
        localOptions[i].send(session);
      }
      Policy.checkCanceled(monitor);
      
      resources = computeWorkResources(session, localOptions, arguments);
      Policy.checkCanceled(monitor);
      
      resources = sendLocalResourceState(session, globalOptions, localOptions, 
        resources, Policy.infiniteSubMonitorFor(monitor, 48));
      Policy.checkCanceled(monitor);
      for (int i = 0; i < arguments.length; i++) {
        if (arguments[i].startsWith("-")) {
          arguments[i] = ("./" + arguments[i]);
        }
      }
      sendArguments(session, arguments);
      
      sendLocalWorkingDirectory(session);
      if (listener == null) {
        listener = getDefaultCommandOutputListener();
      }
      IStatus status = executeRequest(session, listener, Policy.subMonitorFor(monitor, 50));
      
      status = commandFinished(session, globalOptions, localOptions, resources, Policy.subMonitorFor(monitor, 2), 
        status);
      return status;
    }
    finally
    {
      monitor.done();
    }
  }
  
  private String constructCommandInvocationString(IPath commandRootPath, GlobalOption[] globalOptions, LocalOption[] localOptions, String[] arguments)
  {
    StringBuffer commandLine = new StringBuffer("cvs");
    for (int i = 0; i < globalOptions.length; i++)
    {
      String option = globalOptions[i].toString();
      if (option.length() != 0)
      {
        commandLine.append(' ');
        commandLine.append(option);
      }
    }
    commandLine.append(' ');
    commandLine.append(getRequestId());
    for (int i = 0; i < localOptions.length; i++)
    {
      String option = localOptions[i].toString();
      if (option.length() != 0)
      {
        commandLine.append(' ');
        commandLine.append(option);
      }
    }
    for (int i = 0; i < arguments.length; i++) {
      if (arguments[i].length() != 0)
      {
        commandLine.append(" \"");
        IPath completePath = commandRootPath;
        if (!arguments[i].equals(".")) {
          completePath = completePath.append(arguments[i]);
        }
        commandLine.append(completePath.toString());
        commandLine.append('"');
      }
    }
    return commandLine.toString();
  }
  
  protected static abstract class Option
  {
    protected String option;
    protected String argument;
    
    protected Option(String option, String argument)
    {
      this.option = option;
      this.argument = argument;
    }
    
    public boolean isElementOf(Option[] array)
    {
      return Command.findOption(array, option) != null;
    }
    
    String getOption()
    {
      return option;
    }
    
    public boolean equals(Object other)
    {
      if (this == other) {
        return true;
      }
      if ((other instanceof Option))
      {
        Option otherOption = (Option)other;
        return option.equals(option);
      }
      return false;
    }
    
    public abstract void send(Session paramSession)
      throws CVSException;
    
    public String toString()
    {
      if ((argument != null) && (argument.length() != 0)) {
        return option + " \"" + argument + '"';
      }
      return option;
    }
  }
  
  public static class GlobalOption
    extends Command.Option
  {
    protected GlobalOption(String option)
    {
      super(null);
    }
    
    public void send(Session session)
      throws CVSException
    {
      session.sendGlobalOption(option);
    }
    
    protected GlobalOption[] addToEnd(GlobalOption[] options)
    {
      GlobalOption[] globalOptions = new GlobalOption[options.length + 1];
      System.arraycopy(options, 0, globalOptions, 0, options.length);
      globalOptions[(globalOptions.length - 1)] = this;
      return globalOptions;
    }
  }
  
  public static final class QuietOption
    extends Command.GlobalOption
  {
    QuietOption(String paramString, QuietOption paramQuietOption)
    {
      this(paramString);
    }
    
    private QuietOption(String option)
    {
      super();
    }
    
    public void send(Session session)
      throws CVSException
    {
      if (option.length() != 0) {
        super.send(session);
      }
    }
  }
  
  public static class LocalOption
    extends Command.Option
  {
    protected LocalOption(String option)
    {
      super(null);
    }
    
    protected LocalOption(String option, String argument)
    {
      super(argument);
    }
    
    public void send(Session session)
      throws CVSException
    {
      session.sendArgument(option);
      if (argument != null) {
        session.sendArgument(argument);
      }
    }
    
    public LocalOption[] addTo(LocalOption[] options)
    {
      if (isElementOf(options)) {
        return options;
      }
      LocalOption[] newOptions = new LocalOption[options.length + 1];
      System.arraycopy(options, 0, newOptions, 0, options.length);
      newOptions[options.length] = this;
      return newOptions;
    }
    
    public LocalOption[] removeFrom(LocalOption[] options)
    {
      if (!isElementOf(options)) {
        return options;
      }
      List result = new ArrayList();
      for (int i = 0; i < options.length; i++)
      {
        LocalOption option = options[i];
        if (!option.equals(this)) {
          result.add(option);
        }
      }
      return (LocalOption[])result.toArray(new LocalOption[result.size()]);
    }
  }
  
  public static class KSubstOption
    extends Command.LocalOption
  {
    private boolean isUnknownMode;
    
    KSubstOption(String paramString, KSubstOption paramKSubstOption)
    {
      this(paramString);
    }
    
    private KSubstOption(String option)
    {
      this(option, false);
    }
    
    private KSubstOption(String option, boolean isUnknownMode)
    {
      super();
      this.isUnknownMode = isUnknownMode;
      Command.ksubstOptionMap.put(option, this);
    }
    
    public static KSubstOption fromMode(String mode)
    {
      if (mode.length() == 0) {
        mode = "-kkv";
      }
      KSubstOption option = (KSubstOption)Command.ksubstOptionMap.get(mode);
      if (option == null) {
        option = new KSubstOption(mode, true);
      }
      return option;
    }
    
    public static KSubstOption fromFile(IFile file)
    {
      if (CVSProviderPlugin.isText(file)) {
        return getDefaultTextMode();
      }
      return Command.KSUBST_BINARY;
    }
    
    public static KSubstOption[] getAllKSubstOptions()
    {
      return (KSubstOption[])Command.ksubstOptionMap.values().toArray(new KSubstOption[Command.ksubstOptionMap.size()]);
    }
    
    public String toEntryLineMode()
    {
      if (Command.KSUBST_TEXT_EXPAND.equals(this)) {
        return "";
      }
      return getOption();
    }
    
    public String toMode()
    {
      return getOption();
    }
    
    public boolean isBinary()
    {
      return Command.KSUBST_BINARY.equals(this);
    }
    
    public String getShortDisplayText()
    {
      if (isUnknownMode) {
        return NLS.bind(CVSMessages.KSubstOption_unknown_short, new String[] { option });
      }
      if (option.equals("-kb")) {
        return CVSMessages.KSubstOption__kb_short;
      }
      if (option.equals("-kkv")) {
        return CVSMessages.KSubstOption__kkv_short;
      }
      if (option.equals("-ko")) {
        return CVSMessages.KSubstOption__ko_short;
      }
      if (option.equals("-kk")) {
        return CVSMessages.KSubstOption__kk_short;
      }
      if (option.equals("-kv")) {
        return CVSMessages.KSubstOption__kv_short;
      }
      if (option.equals("-kkvl")) {
        return CVSMessages.KSubstOption__kkvl_short;
      }
      return NLS.bind(CVSMessages.KSubstOption_unknown_short, new String[] { option });
    }
    
    public String getLongDisplayText()
    {
      if (isUnknownMode) {
        return NLS.bind(CVSMessages.KSubstOption_unknown_long, new String[] { option });
      }
      if (option.equals("-kb")) {
        return CVSMessages.KSubstOption__kb_long;
      }
      if (option.equals("-kkv")) {
        return CVSMessages.KSubstOption__kkv_long;
      }
      if (option.equals("-ko")) {
        return CVSMessages.KSubstOption__ko_long;
      }
      if (option.equals("-kk")) {
        return CVSMessages.KSubstOption__kk_long;
      }
      if (option.equals("-kv")) {
        return CVSMessages.KSubstOption__kv_long;
      }
      if (option.equals("-kkvl")) {
        return CVSMessages.KSubstOption__kkvl_long;
      }
      return NLS.bind(CVSMessages.KSubstOption_unknown_long, new String[] { option });
    }
    
    public static KSubstOption getDefaultTextMode()
    {
      return CVSProviderPlugin.getPlugin().getDefaultTextKSubstOption();
    }
  }
  
  public static LocalOption makeArgumentOption(LocalOption option, String argument)
  {
    if (argument == null) {
      argument = "";
    }
    return new LocalOption(option.getOption(), argument);
  }
  
  public static LocalOption makeTagOption(CVSTag tag)
  {
    int type = tag.getType();
    switch (type)
    {
    case 1: 
    case 2: 
      return new LocalOption("-r", tag.getName());
    case 3: 
      return new LocalOption("-D", tag.getName());
    }
    throw new IllegalArgumentException(CVSMessages.Command_invalidTag);
  }
  
  public static Option findOption(Option[] array, String option)
  {
    for (int i = 0; i < array.length; i++) {
      if (array[i].getOption().equals(option)) {
        return array[i];
      }
    }
    return null;
  }
  
  protected static String[] collectOptionArguments(Option[] array, String option)
  {
    List list = new ArrayList();
    for (int i = 0; i < array.length; i++) {
      if (array[i].getOption().equals(option)) {
        list.add(argument);
      }
    }
    return (String[])list.toArray(new String[list.size()]);
  }
  
  protected GlobalOption[] filterGlobalOptions(Session session, GlobalOption[] globalOptions)
  {
    retu
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2019. Infinite Loop Ltd