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

6.0)
 * JD-Core Version:    0.7.1
 */
package org.eclipse.team.internal.ccvs.core.resources;

class RemoteFolderTreeBuilder$DeltaNode
{
  int syncState = 0;
  String name;
  String revision;
  
  RemoteFolderTreeBuilder$DeltaNode(String name, String revision, int syncState)
  {
    this.name = name;
    this.revision = revision;
    this.syncState = syncState;
  }
  
  String getName()
  {
    return name;
  }
  
  String getRevision()
  {
    return revision;
  }
  
  int getSyncState()
  {
    return syncState;
  }
}

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

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.eclipse.core.resources.IContainer;
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.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.ICVSFile;
import org.eclipse.team.internal.ccvs.core.ICVSFolder;
import org.eclipse.team.internal.ccvs.core.ICVSRemoteResource;
import org.eclipse.team.internal.ccvs.core.ICVSResource;
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.Command.GlobalOption;
import org.eclipse.team.internal.ccvs.core.client.Command.KSubstOption;
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.client.Session;
import org.eclipse.team.internal.ccvs.core.client.Status;
import org.eclipse.team.internal.ccvs.core.client.SyncUpdate;
import org.eclipse.team.internal.ccvs.core.client.Update;
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.syncinfo.FolderSyncInfo;
import org.eclipse.team.internal.ccvs.core.syncinfo.ResourceSyncInfo;
import org.eclipse.team.internal.ccvs.core.util.Util;

public class RemoteFolderTreeBuilder
{
  private static final int MAX_REVISION_FETCHES_PER_CONNECTION = 1024;
  private Map fileDeltas;
  private List changedFiles;
  private Map remoteFolderTable;
  private ICVSFolder root;
  private RemoteFolderTree remoteRoot;
  private CVSRepositoryLocation repository;
  private CVSTag tag;
  private Command.LocalOption[] updateLocalOptions;
  private boolean rootDoesNotExist = false;
  private static String UNKNOWN = "";
  private static String DELETED = "DELETED";
  private static String ADDED = "ADDED";
  private static String FOLDER = "FOLDER";
  private static Map EMPTY_MAP = new HashMap();
  private boolean newFolderExist = false;
  
  static class DeltaNode
  {
    int syncState = 0;
    String name;
    String revision;
    
    DeltaNode(String name, String revision, int syncState)
    {
      this.name = name;
      this.revision = revision;
      this.syncState = syncState;
    }
    
    String getName()
    {
      return name;
    }
    
    String getRevision()
    {
      return revision;
    }
    
    int getSyncState()
    {
      return syncState;
    }
  }
  
  RemoteFolderTreeBuilder(CVSRepositoryLocation repository, ICVSFolder root, CVSTag tag)
  {
    this.repository = repository;
    this.root = root;
    this.tag = tag;
    fileDeltas = new HashMap();
    changedFiles = new ArrayList();
    remoteFolderTable = new HashMap();
    
    List localOptions = new ArrayList();
    if (tag != null) {
      if (tag.getType() == 0) {
        localOptions.add(Update.CLEAR_STICKY);
      } else {
        localOptions.add(Update.makeTagOption(tag));
      }
    }
    updateLocalOptions = ((Command.LocalOption[])localOptions.toArray(new Command.LocalOption[localOptions.size()]));
  }
  
  private Command.LocalOption[] getOptionsWithoutTag()
  {
    List localOptions = new ArrayList();
    localOptions.add(Update.RETRIEVE_ABSENT_DIRECTORIES);
    return (Command.LocalOption[])localOptions.toArray(new Command.LocalOption[localOptions.size()]);
  }
  
  public static RemoteFolder buildBaseTree(CVSRepositoryLocation repository, ICVSFolder root, CVSTag tag, IProgressMonitor progress)
    throws CVSException
  {
    try
    {
      RemoteFolderTreeBuilder builder = new RemoteFolderTreeBuilder(repository, root, tag);
      progress.beginTask(null, 100);
      IProgressMonitor subProgress = Policy.infiniteSubMonitorFor(progress, 100);
      subProgress.beginTask(null, 512);
      subProgress.subTask(NLS.bind(CVSMessages.RemoteFolderTreeBuilder_buildingBase, new String[] { root.getName() }));
      return builder.buildBaseTree(null, root, subProgress);
    }
    finally
    {
      progress.done();
    }
  }
  
  public static RemoteFolderTree buildRemoteTree(CVSRepositoryLocation repository, IContainer root, CVSTag tag, IProgressMonitor monitor)
    throws CVSException
  {
    return buildRemoteTree(repository, CVSWorkspaceRoot.getCVSFolderFor(root), tag, monitor);
  }
  
  public static RemoteFolderTree buildRemoteTree(CVSRepositoryLocation repository, ICVSFolder root, CVSTag tag, IProgressMonitor monitor)
    throws CVSException
  {
    RemoteFolderTreeBuilder builder = new RemoteFolderTreeBuilder(repository, root, tag);
    return builder.buildTree(new ICVSResource[] { root }, monitor);
  }
  
  public static RemoteFile buildRemoteTree(CVSRepositoryLocation repository, ICVSFile file, CVSTag tag, IProgressMonitor monitor)
    throws CVSException
  {
    RemoteFolderTreeBuilder builder = new RemoteFolderTreeBuilder(repository, file.getParent(), tag);
    return builder.buildTree(file, monitor);
  }
  
  RemoteFolderTree buildTree(ICVSResource[] resources, IProgressMonitor monitor)
    throws CVSException
  {
    Command.QuietOption quietness = CVSProviderPlugin.getPlugin().getQuietness();
    try
    {
      CVSProviderPlugin.getPlugin().setQuietness(Command.VERBOSE);
      
      monitor.beginTask(null, 100);
      if (!fetchDelta(resources, Policy.subMonitorFor(monitor, 75))) {
        return null;
      }
      fetchNewDirectories(Policy.subMonitorFor(monitor, 10));
      
      fetchFileRevisions(Policy.subMonitorFor(monitor, 15));
      
      return remoteRoot;
    }
    finally
    {
      CVSProviderPlugin.getPlugin().setQuietness(quietness);
      monitor.done();
    }
  }
  
  private boolean fetchDelta(ICVSResource[] resources, IProgressMonitor monitor)
    throws CVSException
  {
    ArrayList arguments = new ArrayList();
    for (int i = 0; i < resources.length; i++)
    {
      ICVSResource resource = resources[i];
      arguments.add(resource.getRelativePath(root));
    }
    monitor.beginTask(null, 100);
    Policy.checkCanceled(monitor);
    Session session = new Session(repository, root, false);
    session.open(Policy.subMonitorFor(monitor, 10), false);
    try
    {
      Policy.checkCanceled(monitor);
      fetchDelta(session, (String[])arguments.toArray(new String[arguments.size()]), Policy.subMonitorFor(monitor, 90));
      if (rootDoesNotExist)
      {
        if ((root.isCVSFolder()) && (!root.isManaged()))
        {
          IStatus status = new CVSStatus(4, 4, NLS.bind(CVSMessages.RemoteFolderTreeBuild_folderDeletedFromServer, new String[] { root.getFolderSyncInfo().getRepository() }), root);
          throw new CVSException(status);
        }
        return false;
      }
    }
    finally
    {
      session.close();
      monitor.done();
    }
    session.close();
    monitor.done();
    
    return true;
  }
  
  private void fetchNewDirectories(IProgressMonitor monitor)
    throws CVSException
  {
    monitor.beginTask(null, 100);
    
    FolderSyncInfo folderSyncInfo = root.getFolderSyncInfo();
    if (folderSyncInfo == null)
    {
      if (root.exists())
      {
        IResource resource = root.getIResource();
        String path;
        if (resource == null) {
          path = root.getName();
        } else {
          path = resource.getFullPath().toString();
        }
        IStatus status = new CVSStatus(4, 4, NLS.bind(CVSMessages.RemoteFolderTreeBuilder_0, new String[] { path }), root);
        throw new CVSException(status);
      }
      return;
    }
    remoteRoot = 
      new RemoteFolderTree(null, root.getName(), repository, 
      folderSyncInfo.getRepository(), 
      tagForRemoteFolder(root, tag));
    Session session;
    if (newFolderExist)
    {
      Session session = new Session(repository, remoteRoot, false);
      session.open(Policy.subMonitorFor(monitor, 10), false);
    }
    else
    {
      session = null;
    }
    try
    {
      IProgressMonitor subProgress = Policy.infiniteSubMonitorFor(monitor, 90);
      subProgress.beginTask(null, 512);
      
      buildRemoteTree(session, root, remoteRoot, "", subProgress);
    }
    finally
    {
      if (session != null) {
        session.close();
      }
      monitor.done();
    }
  }
  
  /* Error */
  private void fetchFileRevisions(IProgressMonitor monitor)
    throws CVSException
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 621	org/eclipse/team/internal/ccvs/core/resources/RemoteFolderTreeBuilder:remoteRoot	Lorg/eclipse/team/internal/ccvs/core/resources/RemoteFolderTree;
    //   4: ifnull +176 -> 180
    //   7: aload_0
    //   8: getfield 613	org/eclipse/team/internal/ccvs/core/resources/RemoteFolderTreeBuilder:changedFiles	Ljava/util/List;
    //   11: invokeinterface 719 1 0
    //   16: ifne +164 -> 180
    //   19: aload_0
    //   20: getfield 613	org/eclipse/team/internal/ccvs/core/resources/RemoteFolderTreeBuilder:changedFiles	Ljava/util/List;
    //   23: aload_0
    //   24: getfield 613	org/eclipse/team/internal/ccvs/core/resources/RemoteFolderTreeBuilder:changedFiles	Ljava/util/List;
    //   27: invokeinterface 718 1 0
    //   32: anewarray 273	java/lang/String
    //   35: invokeinterface 724 2 0
    //   40: checkcast 268	[Ljava/lang/String;
    //   43: astore_2
    //   44: aload_2
    //   45: arraylength
    //   46: sipush 1024
    //   49: idiv
    //   50: aload_2
    //   51: arraylength
    //   52: sipush 1024
    //   55: irem
    //   56: ifne +7 -> 63
    //   59: iconst_0
    //   60: goto +4 -> 64
    //   63: iconst_1
    //   64: iadd
    //   65: istore_3
    //   66: iconst_0
    //   67: istore 4
    //   69: goto +105 -> 174
    //   72: sipush 1024
    //   75: aload_2
    //   76: arraylength
    //   77: sipush 1024
    //   80: iload 4
    //   82: imul
    //   83: isub
    //   84: invokestatic 622	java/lang/Math:min	(II)I
    //   87: istore 5
    //   89: iload 5
    //   91: anewarray 273	java/lang/String
    //   94: astore 6
    //   96: aload_2
    //   97: iload 4
    //   99: sipush 1024
    //   102: imul
    //   103: aload 6
    //   105: iconst_0
    //   106: iload 5
    //   108: invokestatic 626	java/lang/System:arraycopy	(Ljava/lang/Object;ILjava/lang/Object;II)V
    //   111: new 305	org/eclipse/team/internal/ccvs/core/client/Session
    //   114: dup
    //   115: aload_0
    //   116: getfield 620	org/eclipse/team/internal/ccvs/core/resources/RemoteFolderTreeBuilder:repository	Lorg/eclipse/team/internal/ccvs/core/connection/CVSRepositoryLocation;
    //   119: aload_0
    //   120: getfield 621	org/eclipse/team/internal/ccvs/core/resources/RemoteFolderTreeBuilder:remoteRoot	Lorg/eclipse/team/internal/ccvs/core/resources/RemoteFolderTree;
    //   123: iconst_0
    //   124: invokespecial 650	org/eclipse/team/internal/ccvs/core/client/Session:<init>	(Lorg/eclipse/team/internal/ccvs/core/ICVSRepositoryLocation;Lorg/eclipse/team/internal/ccvs/core/ICVSFolder;Z)V
    //   127: astore 7
    //   129: aload 7
    //   131: aload_1
    //   132: iconst_1
    //   133: invokestatic 647	org/eclipse/team/internal/ccvs/core/Policy:subMonitorFor	(Lorg/eclipse/core/runtime/IProgressMonitor;I)Lorg/eclipse/core/runtime/IProgressMonitor;
    //   136: iconst_0
    //   137: invokevirtual 649	org/eclipse/team/internal/ccvs/core/client/Session:open	(Lorg/eclipse/core/runtime/IProgressMonitor;Z)V
    //   140: aload_0
    //   141: aload 7
    //   143: aload 6
    //   145: aload_1
    //   146: iconst_2
    //   147: invokestatic 647	org/eclipse/team/internal/ccvs/core/Policy:subMonitorFor	(Lorg/eclipse/core/runtime/IProgressMonitor;I)Lorg/eclipse/core/runtime/IProgressMonitor;
    //   150: invokespecial 685	org/eclipse/team/internal/ccvs/core/resources/RemoteFolderTreeBuilder:fetchFileRevisions	(Lorg/eclipse/team/internal/ccvs/core/client/Session;[Ljava/lang/String;Lorg/eclipse/core/runtime/IProgressMonitor;)V
    //   153: goto +13 -> 166
    //   156: astore 8
    //   158: aload 7
    //   160: invokevirtual 648	org/eclipse/team/internal/ccvs/core/client/Session:close	()V
    //   163: aload 8
    //   165: athrow
    //   166: aload 7
    //   168: invokevirtual 648	org/eclipse/team/internal/ccvs/core/client/Session:close	()V
    //   171: iinc 4 1
    //   174: iload 4
    //   176: iload_3
    //   177: if_icmplt -105 -> 72
    //   180: return
    // Line number table:
    //   Java source line #259	-> byte code offset #0
    //   Java source line #260	-> byte code offset #19
    //   Java source line #261	-> byte code offset #44
    //   Java source line #262	-> byte code offset #50
    //   Java source line #261	-> byte code offset #64
    //   Java source line #263	-> byte code offset #66
    //   Java source line #264	-> byte code offset #72
    //   Java source line #265	-> byte code offset #75
    //   Java source line #264	-> byte code offset #84
    //   Java source line #266	-> byte code offset #89
    //   Java source line #267	-> byte code offset #96
    //   Java source line #268	-> byte code offset #111
    //   Java source line #269	-> byte code offset #129
    //   Java source line #271	-> byte code offset #140
    //   Java source line #272	-> byte code offset #156
    //   Java source line #273	-> byte code offset #158
    //   Java source line #274	-> byte code offset #163
    //   Java source line #273	-> byte code offset #166
    //   Java source line #263	-> byte code offset #171
    //   Java source line #277	-> byte code offset #180
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	181	0	this	RemoteFolderTreeBuilder
    //   0	181	1	monitor	IProgressMonitor
    //   43	54	2	allChangedFiles	String[]
    //   65	112	3	iterations	int
    //   67	108	4	i	int
    //   87	20	5	length	int
    //   94	50	6	buffer	String[]
    //   127	40	7	session	Session
    //   156	8	8	localObject	Object
    // Exception table:
    //   from	to	target	type
    //   140	156	156	finally
  }
  
  RemoteFile buildTree(ICVSFile file, IProgressMonitor monitor)
    throws CVSException
  {
    Command.QuietOption quietness = CVSProviderPlugin.getPlugin().getQuietness();
    try
    {
      CVSProviderPlugin.getPlugin().setQuietness(Command.VERBOSE);
      
      monitor.beginTask(null, 100);
      
      Policy.checkCanceled(monitor);
      Session session = new Session(repository, root, false);
      session.open(Policy.subMonitorFor(monitor, 10), false);
      try
      {
        Policy.checkCanceled(monitor);
        fetchDelta(session, new String[] { file.getName() }, Policy.subMonitorFor(monitor, 50));
        if (rootDoesNotExist)
        {
          session.close();return null;
        }
      }
      finally
      {
        session.close();
      }
      session.close();
      
      remoteRoot = 
        new RemoteFolderTree(null, root.getName(), repository, 
        root.getFolderSyncInfo().getRepository(), 
        tagForRemoteFolder(root, tag));
      
      Map deltas = (Map)fileDeltas.get("");
      RemoteFile remoteFile;
      RemoteFile remoteFile;
      if ((deltas == null) || (deltas.isEmpty()))
      {
        byte[] syncBytes = file.getSyncBytes();
        if ((syncBytes == null) || (ResourceSyncInfo.isAddition(syncBytes))) {
          return null;
        }
        remoteFile = new RemoteFile(remoteRoot, syncBytes);
      }
      else
      {
        d = (DeltaNode)deltas.get(file.getName());
        if (d.getRevision() == DELETED) {
          return null;
        }
        CVSTag newTag = tagForRemoteFolder(remoteRoot, tag);
        if ((newTag == null) && (file.getSyncInfo() != null)) {
          newTag = file.getSyncInfo().getTag();
        }
        remoteFile = new RemoteFile(remoteRoot, 
          d.getSyncState(), 
          file.getName(), 
          null, 
          getKeywordMode(file), 
          newTag);
      }
      remoteRoot.setChildren(new ICVSRemoteResource[] { remoteFile });
      if (!changedFiles.isEmpty())
      {
        recordRemoteFolder(remoteRoot);
        session = new Session(repository, remoteRoot, false);
        session.open(Policy.subMonitorFor(monitor, 10), false);
        try
        {
          fetchFileRevisions(session, (String[])changedFiles.toArray(new String[changedFiles.size()]), Policy.subMonitorFor(monitor, 20));
        }
        finally
        {
          session.close();
        }
      }
      return remoteFile;
    }
    finally
    {
      CVSProviderPlugin.getPlugin().setQuietness(quietness);
      monitor.done();
    }
  }
  
  private Command.KSubstOption getKeywordMode(ICVSFile file)
    throws CVSException
  {
    if (file == null) {
      return null;
    }
    byte[] syncBytes = file.getSyncBytes();
    if (syncBytes == null) {
      return null;
    }
    return ResourceSyncInfo.getKeywordMode(syncBytes);
  }
  
  RemoteFolder buildBaseTree(RemoteFolder parent, ICVSFolder local, IProgressMonitor monitor)
    throws CVSException
  {
    Policy.checkCanceled(monitor);
    
    FolderSyncInfo folderSyncInfo = local.getFolderSyncInfo();
    if (folderSyncInfo == null) {
      return null;
    }
    RemoteFolder remote = createRemoteFolder(local, parent, folderSyncInfo);
    
    List children = new ArrayList();
    
    ICVSResource[] folders = local.members(2);
    for (int i = 0; i < folders.length; i++)
    {
      ICVSFolder folder = (ICVSFolder)folders[i];
      if ((folder.isManaged()) && (folder.isCVSFolder()))
      {
        monitor.worked(1);
        RemoteFolder tree = buildBaseTree(remote, folder, monitor);
        if (tree != null) {
          children.add(tree);
        }
      }
    }
    ICVSResource[] files = local.members(1);
    for (int i = 0; i < files.length; i++)
    {
      ICVSFile file = (ICVSFile)files[i];
      byte[] syncBytes = file.getSyncBytes();
      if (syncBytes != null) {
        if (!ResourceSyncInfo.isAddition(syncBytes))
        {
          if (ResourceSyncInfo.isDeletion(syncBytes)) {
            syncBytes = ResourceSyncInfo.convertFromDeletion(syncBytes);
          }
          children.add(createRemoteFile(remote, syncBytes));
          monitor.worked(1);
        }
      }
    }
    if ((children.isEmpty()) && (isPruneEmptyDirectories()) && (!local.exists())) {
      return null;
    }
    remote.setChildren((ICVSRemoteResource[])children.toArray(new ICVSRemoteResource[children.size()]));
    
    return remote;
  }
  
  protected RemoteFile createRemoteFile(RemoteFolder remote, byte[] syncBytes)
    throws CVSException
  {
    return new RemoteFile(remote, syncBytes);
  }
  
  protected RemoteFolder createRemoteFolder(ICVSFolder local, RemoteFolder parent, FolderSyncInfo folderSyncInfo)
  {
    return new RemoteFolderTree(parent, local.getName(), repository, folderSyncInfo.getRepository(), folderSyncInfo.getTag());
  }
  
  private void buildRemoteTree(Session session, ICVSFolder local, RemoteFolderTree remote, String localPath, IProgressMonitor monitor)
    throws CVSException
  {
    Policy.checkCanceled(monitor);
    
    recordRemoteFolder(remote);
    
    Map children = new HashMap();
    if (local == null) {
      fetchNewDirectory(session, remote, localPath, monitor);
    }
    Map deltas = (Map)fileDeltas.get(localPath);
    if (deltas == null) {
      deltas = EMPTY_MAP;
    }
    if (local != null)
    {
      ICVSResource[] folders = local.members(2);
      for (int i = 0; i < folders.length; i++)
      {
        ICVSFolder folder = (ICVSFolder)folders[i];
        DeltaNode d = (DeltaNode)deltas.get(folder.getName());
        if ((folder.isCVSFolder()) && (!isOrphanedSubtree(folder)) && ((d == null) || (d.getRevision() != DELETED))) {
          children.put(folders[i].getName(), 
            new RemoteFolderTree(remote, folders[i].getName(), repository, 
            folder.getFolderSyncInfo().getRepository(), 
            tagForRemoteFolder(folder, tag)));
        }
      }
      ICVSResource[] files = local.members(1);
      for (int i = 0; i < files.length; i++)
      {
        ICVSFile file = (ICVSFile)files[i];
        
        DeltaNode d = (DeltaNode)deltas.get(file.getName());
        byte[] syncBytes = file.getSyncBytes();
        if (syncBytes != null) {
          if ((!ResourceSyncInfo.isAddition(syncBytes)) || (d != null)) {
            if ((!ResourceSyncInfo.isDeletion(syncBytes)) || (d != null))
            {
              int type = d == null ? 0 : d.getSyncState();
              children.put(file.getName(), new RemoteFile(remote, type, syncBytes));
            }
          }
        }
      }
    }
    Iterator i = deltas.keySet().iterator();
    while (i.hasNext())
    {
      String name = (String)i.next();
      DeltaNode d = (DeltaNode)deltas.get(name);
      String revision = d.getRevision();
      if (revision == FOLDER) {
        children.put(name, new RemoteFolderTree(remote, repository, 
          Util.appendPath(remote.getRepositoryRelativePath(), name), 
          tagForRemoteFolder(remote, tag)));
      } else if (revision == ADDED) {
        children.put(name, new RemoteFile(remote, 
          d.getSyncState(), 
          name, 
          null, 
          null, 
          tagForRemoteFolder(remote, tag)));
      } else if (revision == UNKNOWN) {
        children.put(name, new RemoteFile(remote, 
          d.getSyncState(), 
          name, 
          null, 
          getKeywordMode((ICVSFile)children.get(name)), 
          tagForRemoteFolder(remote, tag)));
      } else if (revision == DELETED) {
        if (children.containsKey(name)) {
          children.remove(name);
        }
      }
      monitor.worked(1);
    }
    remote.setChildren((ICVSRemoteResource[])children.values().toArray(new ICVSRemoteResource[children.size()]));
    
    Iterator childIterator = children.entrySet().iterator();
    List emptyChildren = new ArrayList();
    while (childIterator.hasNext())
    {
      Map.Entry entry = (Map.Entry)childIterator.next();
      if (((RemoteResource)entry.getValue()).isFolder())
      {
        RemoteFolderTree remoteFolder = (RemoteFolderTree)entry.getValue();
        String name = (String)entry.getKey();
        
        DeltaNode d = (DeltaNode)deltas.get(name);
        ICVSFolder localFolder;
        ICVSFolder localFolder;
        if ((d != null) && (d.getRevision() == FOLDER)) {
          localFolder = null;
        } else {
          localFolder = local.getFolder(name);
        }
        buildRemoteTree(session, localFolder, remoteFolder, Util.appendPath(localPath, name), monitor);
        if ((isPruneEmptyDirectories()) && (remoteFolder.getChildren().length == 0)) {
          if ((localFolder == null) || (localFolder.members(63).length == 0))
          {
            emptyChildren.add(remoteFolder);
          }
          else
          {
            FolderSyncInfo info = localFolder.getFolderSyncInfo();
            if ((tag != null) && (info != null) && (!tag.equals(CVSTag.DEFAULT)) && (!tag.equals(info.getTag()))) {
              emptyChildren.add(remoteFolder);
            }
          }
        }
      }
    }
    if ((isPruneEmptyDirectories()) && (!emptyChildren.isEmpty()))
    {
      List newChildren = new ArrayList();
      newChildren.addAll(Arrays.asList(remote.getChildren()));
      newChildren.removeAll(emptyChildren);
      remote.setChildren((ICVSRemoteResource[])newChildren.toArray(new ICVSRemoteResource[newChildren.size()]));
    }
  }
  
  private List fetchDelta(Session session, String[] arguments, IProgressMonitor monitor)
    throws CVSException
  {
    IUpdateMessageListener listener = new IUpdateMessageListener()
    {
      private final IProgressMonitor val$monitor;
      
      public void directoryInformation(ICVSFolder root, String path, boolean newDirectory)
      {
        if (newDirectory)
        {
          RemoteFolderTreeBuilder.this.recordDelta(path, RemoteFolderTreeBuilder.FOLDER, 0);
          val$monitor.subTask(NLS.bind(CVSMessages.RemoteFolderTreeBuilder_receivingDelta, new String[] { Util.toTruncatedPath(path, 3) }));
        }
      }
      
      public void directoryDoesNotExist(ICVSFolder root, String path)
      {
        if (path.length() == 0)
        {
          rootDoesNotExist = true;
        }
        else
        {
          RemoteFolderTreeBuilder.this.recordDelta(path, RemoteFolderTreeBuilder.DELETED, 0);
          val$monitor.subTask(NLS.bind(CVSMessages.RemoteFolderTreeBuilder_receivingDelta, new String[] { Util.toTruncatedPath(path, 3) }));
        }
      }
      
      public void fileInformation(int type, ICVSFolder root, String filename)
      {
        switch (type)
        {
        case 6: 
        case 7: 
          Map deltas = (Map)fileDeltas.get(Util.removeLastSegment(filename));
          RemoteFolderTreeBuilder.DeltaNode d = deltas != null ? (RemoteFolderTreeBuilder.DeltaNode)deltas.get(Util.getLastSegment(filename)) : null;
          if ((d != null) && (d.getRevision() == RemoteFolderTreeBuilder.DELETED)) {
            break;
          }
        case 3: 
        case 4: 
          changedFiles.add(filename);
          RemoteFolderTreeBuilder.this.recordDelta(filename, RemoteFolderTreeBuilder.UNKNOWN, type);
          val$monitor.subTask(NLS.bind(CVSMessages.RemoteFolderTreeBuilder_receivingDelta, new String[] { Util.toTruncatedPath(filename, 3) }));
        }
      }
      
      public void fileDoesNotExist(ICVSFolder root, String filename)
      {
        RemoteFolderTreeBuilder.this.recordDelta(filename, RemoteFolderTreeBuilder.DELETED, 0);
        val$monitor.subTask(NLS.bind(CVSMessages.RemoteFolderTreeBuilder_receivingDelta, new String[] { Util.toTruncatedPath(filename, 3) }));
      }
    };
    IStatus status = Command.SYNCUPDATE.execute(session, 
      new Command.GlobalOption[] { Command.DO_NOT_CHANGE }, 
      updateLocalOptions, 
      arguments, 
      new UpdateListener(listener), 
      monitor);
    if (status.getCode() == -10)
    {
      CVSServerException e = new CVSServerException(status);
      if (e.isNoTagException()) {
        rootDoesNotExist = true;
      } else if (e.containsErrors()) {
        CVSProviderPlugin.log(e);
      }
    }
    return changedFiles;
  }
  
  private void fetchNewDirectory(Session session, RemoteFolderTree newFolder, String localPath, IProgressMonitor monitor)
    throws CVSException
  {
    IUpdateMessageListener listener = new IUpdateMessageListener()
    {
      private final IProgressMonitor val$monitor;
      
      public void directoryInformation(ICVSFolder root, String path, boolean newDirectory)
      {
        if (newDirectory)
        {
          RemoteFolderTreeBuilder.this.recordDelta(path, RemoteFolderTreeBuilder.FOLDER, 0);
          val$monitor.subTask(NLS.bind(CVSMessages.RemoteFolderTreeBuilder_receivingDelta, new String[] { Util.toTruncatedPath(path, 3) }));
        }
      }
      
      public void directoryDoesNotExist(ICVSFolder root, String path) {}
      
      public void fileInformation(int type, ICVSFolder root, String filename)
      {
        changedFiles.add(filename);
        RemoteFolderTreeBuilder.this.recordDelta(filename, RemoteFolderTreeBuilder.ADDED, type);
        val$monitor.subTask(NLS.bind(CVSMessages.RemoteFolderTreeBuilder_receivingDelta, new String[] { Util.toTruncatedPath(filename, 3) }));
      }
      
      public void fileDoesNotExist(ICVSFolder root, String filename) {}
    };
    IStatus status = Command.UPDATE.execute(session, 
      new Command.GlobalOption[] { Command.DO_NOT_CHANGE }, 
      updateLocalOptions, 
      new String[] { localPath }, 
      new UpdateListener(listener), 
      Policy.subMonitorFor(monitor, 1));
    if (status.getCode() == -10)
    {
      CVSServerException e = new CVSServerException(status);
      if ((!e.isNoTagException()) && (e.containsErrors())) {
        throw e;
      }
      Policy.checkCanceled(monitor);
      status = Command.UPDATE.execute(session, 
        new Command.GlobalOption[] { Command.DO_NOT_CHANGE }, 
        getOptionsWithoutTag(), 
        new String[] { localPath }, 
        new UpdateListener(listener), 
        Policy.subMonitorFor(monitor, 1));
      if (status.getCode() == -10) {
        throw new CVSServerException(status);
      }
    }
  }
  
  private void fetchFileRevisions(Session session, String[] fileNames, IProgressMonitor monitor)
    throws CVSException
  {
    List exceptions = new ArrayList();
    IStatusListener listener = new IStatusListener()
    {
      private final IProgressMonitor val$monitor;
      private final List val$exceptions;
      
      public void fileStatus(ICVSFolder root, String path, String remoteRevision)
      {
        try
        {
          RemoteFolderTreeBuilder.this.updateRevision(path, remoteRevision);
          val$monitor.subTask(NLS.bind(CVSMessages.RemoteFolderTreeBuilder_receivingRevision, new String[] { Util.toTruncatedPath(path, 3) }));
        }
        catch (CVSException e)
        {
          val$exceptions.add(e);
        }
      }
    };
    IStatus status = Command.STATUS.execute(session, 
      Command.NO_GLOBAL_OPTIONS, 
      Command.NO_LOCAL_OPTIONS, 
      fileNames, 
      new StatusListener(listener), 
      monitor);
    if (status.getCode() == -10) {
      throw new CVSServerException(status);
    }
    if (!exceptions.isEmpty())
    {
      if (exceptions.size() == 1) {
        throw ((CVSException)exceptions.get(0));
      }
      MultiStatus multi = new MultiStatus("org.eclipse.team.cvs.core", 0, CVSMessages.RemoteFolder_errorFetchingRevisions, null);
      for (int i = 0; i < exceptions.size(); i++) {
        multi.merge(((CVSException)exceptions.get(i)).getStatus());
      }
      throw new CVSException(multi);
    }
  }
  
  protected boolean isPruneEmptyDirectories()
  {
    return false;
  }
  
  private void recordDelta(String path, String revision, int syncState)
  {
    if (revision == FOLDER) {
      newFolderExist = true;
    }
    String parent = Util.removeLastSegment(path);
    Map deltas = (Map)fileDeltas.get(parent);
    if (deltas == null)
    {
      deltas = new HashMap();
      fileDeltas.put(parent, deltas);
    }
    String name = Util.getLastSegment(path);
    deltas.put(name, new DeltaNode(name, revision, syncState));
  }
  
  private void updateRevision(String path, String revision)
    throws CVSException
  {
    RemoteFolderTree folder = getRecoredRemoteFolder(Util.removeLastSegment(path));
    if (folder == null)
    {
      IStatus status = new CVSStatus(4, 4, NLS.bind(CVSMessages.RemoteFolderTreeBuilder_missingParent, new String[] { path.toString(), revision }), root);
      throw new CVSException(status);
    }
    ((RemoteFile)folder.getFile(Util.getLastSegment(path))).setRevision(revision);
  }
  
  private CVSTag tagForRemoteFolder(ICVSFolder folder, CVSTag tag)
    throws CVSException
  {
    return tag == null ? folder.getFolderSyncInfo().getTag() : tag;
  }
  
  private boolean isOrphanedSubtree(ICVSFolder mFolder)
    throws CVSException
  {
    return (mFolder.isCVSFolder()) && (!mFolder.isManaged()) && (!mFolder.equals(root)) && (mFolder.getParent().isCVSFolder());
  }
  
  private void recordRemoteFolder(RemoteFolderTree remote)
    throws CVSException
  {
    String path = remote.getFolderSyncInfo().getRemoteLocation();
    remoteFolderTable.put(Util.asPath(path), remote);
  }
  
  private RemoteFolderTree getRecoredRemoteFolder(String path)
  {
    return (RemoteFolderTree)remoteFolderTable.get(Util.asPath(path));
  }
  
  public String[] getFileDiffs()
  {
    return (String[])changedFiles.toArray(new String[changedFiles.size()]);
  }
}

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

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.StringTokenizer;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
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.CVSTag;
import org.eclipse.team.internal.ccvs.core.ICVSFolder;
import org.eclipse.team.internal.ccvs.core.ICVSRemoteFolder;
import org.eclipse.team.internal.ccvs.core.ICVSRemoteResource;
import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation;
import org.eclipse.team.internal.ccvs.core.ICVSResource;
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.Command.LocalOption;
import org.eclipse.team.internal.ccvs.core.syncinfo.FolderSyncInfo;

public class RemoteModule
  extends RemoteFolder
{
  private String label;
  private ICVSRemoteResource[] referencedModules;
  private Command.LocalOption[] localOptions;
  private boolean expandable;
  
  /* Error */
  public static RemoteModule[] getRemoteModules(ICVSRepositoryLocation repository, CVSTag tag, IProgressMonitor monitor)
    throws org.eclipse.team.core.TeamException
  {
    // Byte code:
    //   0: aload_2
    //   1: invokestatic 339	org/eclipse/team/internal/ccvs/core/Policy:monitorFor	(Lorg/eclipse/core/runtime/IProgressMonitor;)Lorg/eclipse/core/runtime/IProgressMonitor;
    //   4: astore_2
    //   5: aload_2
    //   6: getstatic 314	org/eclipse/team/internal/ccvs/core/CVSMessages:RemoteModule_getRemoteModules	Ljava/lang/String;
    //   9: bipush 100
    //   11: invokeinterface 387 3 0
    //   16: new 181	org/eclipse/team/internal/ccvs/core/client/Session
    //   19: dup
    //   20: aload_0
    //   21: aload_0
    //   22: invokestatic 364	org/eclipse/team/internal/ccvs/core/resources/RemoteModule:getRemoteRootFolder	(Lorg/eclipse/team/internal/ccvs/core/ICVSRepositoryLocation;)Lorg/eclipse/team/internal/ccvs/core/ICVSFolder;
    //   25: iconst_0
    //   26: invokespecial 348	org/eclipse/team/internal/ccvs/core/client/Session:<init>	(Lorg/eclipse/team/internal/ccvs/core/ICVSRepositoryLocation;Lorg/eclipse/team/internal/ccvs/core/ICVSFolder;Z)V
    //   29: astore 4
    //   31: aload 4
    //   33: aload_2
    //   34: bipush 10
    //   36: invokestatic 340	org/eclipse/team/internal/ccvs/core/Policy:subMonitorFor	(Lorg/eclipse/core/runtime/IProgressMonitor;I)Lorg/eclipse/core/runtime/IProgressMonitor;
    //   39: iconst_0
    //   40: invokevirtual 347	org/eclipse/team/internal/ccvs/core/client/Session:open	(Lorg/eclipse/core/runtime/IProgressMonitor;Z)V
    //   43: getstatic 317	org/eclipse/team/internal/ccvs/core/client/Command:CHECKOUT	Lorg/eclipse/team/internal/ccvs/core/client/Checkout;
    //   46: aload 4
    //   48: aload_1
    //   49: aload_2
    //   50: bipush 90
    //   52: invokestatic 340	org/eclipse/team/internal/ccvs/core/Policy:subMonitorFor	(Lorg/eclipse/core/runtime/IProgressMonitor;I)Lorg/eclipse/core/runtime/IProgressMonitor;
    //   55: invokevirtual 343	org/eclipse/team/internal/ccvs/core/client/Checkout:getRemoteModules	(Lorg/eclipse/team/internal/ccvs/core/client/Session;Lorg/eclipse/team/internal/ccvs/core/CVSTag;Lorg/eclipse/core/runtime/IProgressMonitor;)[Lorg/eclipse/team/internal/ccvs/core/resources/RemoteModule;
    //   58: astore_3
    //   59: goto +13 -> 72
    //   62: astore 5
    //   64: aload 4
    //   66: invokevirtual 346	org/eclipse/team/internal/ccvs/core/client/Session:close	()V
    //   69: aload 5
    //   71: athrow
    //   72: aload 4
    //   74: invokevirtual 346	org/eclipse/team/internal/ccvs/core/client/Session:close	()V
    //   77: aload_3
    //   78: astore 7
    //   80: aload_2
    //   81: invokeinterface 386 1 0
    //   86: aload 7
    //   88: areturn
    //   89: astore 6
    //   91: aload_2
    //   92: invokeinterface 386 1 0
    //   97: aload 6
    //   99: athrow
    // Line number table:
    //   Java source line #37	-> byte code offset #0
    //   Java source line #38	-> byte code offset #5
    //   Java source line #41	-> byte code offset #16
    //   Java source line #42	-> byte code offset #31
    //   Java source line #44	-> byte code offset #43
    //   Java source line #45	-> byte code offset #62
    //   Java source line #46	-> byte code offset #64
    //   Java source line #47	-> byte code offset #69
    //   Java source line #46	-> byte code offset #72
    //   Java source line #48	-> byte code offset #77
    //   Java source line #50	-> byte code offset #80
    //   Java source line #48	-> byte code offset #86
    //   Java source line #49	-> byte code offset #89
    //   Java source line #50	-> byte code offset #91
    //   Java source line #51	-> byte code offset #97
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	100	0	repository	ICVSRepositoryLocation
    //   0	100	1	tag	CVSTag
    //   0	100	2	monitor	IProgressMonitor
    //   58	2	3	modules	RemoteModule[]
    //   72	6	3	modules	RemoteModule[]
    //   29	44	4	s	org.eclipse.team.internal.ccvs.core.client.Session
    //   62	8	5	localObject1	Object
    //   89	9	6	localObject2	Object
    //   78	9	7	arrayOfRemoteModule1	RemoteModule[]
    // Exception table:
    //   from	to	target	type
    //   43	62	62	finally
    //   16	80	89	finally
  }
  
  private static ICVSFolder getRemoteRootFolder(ICVSRepositoryLocation repository)
  {
    return new RemoteFolder(null, repository, "/", null);
  }
  
  public static RemoteModule[] createRemoteModules(String[] moduleDefinitionStrings, ICVSRepositoryLocation repository, CVSTag tag)
  {
    Map modules = new HashMap();
    Map referencedModulesTable = new HashMap();
    Map moduleAliases = new HashMap();
    for (int i = 0; i < moduleDefinitionStrings.length; i++)
    {
      StringTokenizer tokenizer = new StringTokenizer(moduleDefinitionStrings[i]);
      String moduleName = tokenizer.nextToken();
      try
      {
        List localOptionsList = new ArrayList();
        String next = tokenizer.nextToken();
        while (next.ch
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