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

tem.out.println("Deleting CVS directory from " + folder.getFullPath());
      }
      getCVSSubdirectory(folder).delete(0, null);
    }
    catch (CoreException e)
    {
      throw CVSException.wrapException(e);
    }
  }
  
  public static NotifyInfo[] readAllNotifyInfo(IContainer parent)
    throws CVSException
  {
    IFolder cvsSubDir = getCVSSubdirectory(parent);
    if (!folderExists(cvsSubDir)) {
      return null;
    }
    String[] entries = readLines(cvsSubDir.getFile("Notify"));
    if (entries == null) {
      return null;
    }
    Map infos = new TreeMap();
    for (int i = 0; i < entries.length; i++)
    {
      String line = entries[i];
      if (!"".equals(line)) {
        try
        {
          NotifyInfo info = new NotifyInfo(parent, line);
          infos.put(info.getName(), info);
        }
        catch (CVSException e)
        {
          CVSProviderPlugin.log(e);
        }
      }
    }
    return (NotifyInfo[])infos.values().toArray(new NotifyInfo[infos.size()]);
  }
  
  public static void writeAllNotifyInfo(IContainer parent, NotifyInfo[] infos)
    throws CVSException
  {
    IFolder cvsSubDir = getCVSSubdirectory(parent);
    if (infos.length == 0)
    {
      try
      {
        IFile notifyFile = cvsSubDir.getFile("Notify");
        if (!notifyFile.exists()) {
          return;
        }
        notifyFile.delete(0, null);
      }
      catch (CoreException e)
      {
        throw CVSException.wrapException(e);
      }
    }
    else
    {
      String[] entries = new String[infos.length];
      for (int i = 0; i < infos.length; i++)
      {
        NotifyInfo info = infos[i];
        entries[i] = info.getNotifyLine();
      }
      writeLines(cvsSubDir.getFile("Notify"), entries);
    }
  }
  
  public static BaserevInfo[] readAllBaserevInfo(IContainer parent)
    throws CVSException
  {
    IFolder cvsSubDir = getCVSSubdirectory(parent);
    if (!folderExists(cvsSubDir)) {
      return null;
    }
    String[] entries = readLines(cvsSubDir.getFile("Baserev"));
    if (entries == null) {
      return null;
    }
    Map infos = new TreeMap();
    for (int i = 0; i < entries.length; i++)
    {
      String line = entries[i];
      if (!"".equals(line))
      {
        BaserevInfo info = new BaserevInfo(line);
        infos.put(info.getName(), info);
      }
    }
    return (BaserevInfo[])infos.values().toArray(new BaserevInfo[infos.size()]);
  }
  
  public static void writeAllBaserevInfo(IContainer parent, BaserevInfo[] infos)
    throws CVSException
  {
    IFolder cvsSubDir = getCVSSubdirectory(parent);
    
    String[] entries = new String[infos.length];
    for (int i = 0; i < infos.length; i++)
    {
      BaserevInfo info = infos[i];
      entries[i] = info.getEntryLine();
    }
    writeLines(cvsSubDir.getFile("Baserev"), entries);
  }
  
  private static IFolder getCVSSubdirectory(IContainer folder)
  {
    return folder.getFolder(new Path("CVS"));
  }
  
  private static IFolder createCVSSubdirectory(IContainer folder)
    throws CVSException
  {
    try
    {
      IFolder cvsSubDir = getCVSSubdirectory(folder);
      if (!cvsSubDir.exists()) {
        ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable()
        {
          public void run(IProgressMonitor monitor)
            throws CoreException
          {
            if (!exists())
            {
              if (SyncFileWriter.existsInFileSystem(SyncFileWriter.this))
              {
                refreshLocal(2, null);
                setTeamPrivateMember(true);
              }
              else
              {
                create(2048, true, null);
              }
            }
            else if (!isTeamPrivateMember()) {
              setTeamPrivateMember(true);
            }
          }
        }, folder, 0, null);
      }
      return cvsSubDir;
    }
    catch (CoreException e)
    {
      throw CVSException.wrapException(e);
    }
  }
  
  protected static boolean existsInFileSystem(IFolder cvsSubDir)
  {
    URI uri = cvsSubDir.getLocationURI();
    if (uri != null) {
      try
      {
        IFileStore store = EFS.getStore(uri);
        if (store != null) {
          return store.fetchInfo().exists();
        }
      }
      catch (CoreException e)
      {
        CVSProviderPlugin.log(e);
      }
    }
    return false;
  }
  
  private static String readFirstLine(IFile file)
    throws CVSException
  {
    try
    {
      InputStream in = getInputStream(file);
      if (in != null)
      {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in), 512);
        try
        {
          String line = reader.readLine();
          if (line == null) {
            return "";
          }
          return line;
        }
        finally
        {
          reader.close();
        }
      }
      return null;
    }
    catch (IOException e)
    {
      throw CVSException.wrapException(e);
    }
    catch (CoreException e)
    {
      if ((e.getStatus().getCode() == 368) || 
        (e.getStatus().getCode() == 271)) {
        return null;
      }
      throw CVSException.wrapException(e);
    }
  }
  
  private static InputStream getInputStream(IFile file)
    throws CoreException, FileNotFoundException
  {
    if (file.exists()) {
      return file.getContents(true);
    }
    URI uri = file.getLocationURI();
    if (uri != null)
    {
      IFileStore store = EFS.getStore(uri);
      if (store != null) {
        return store.openInputStream(0, null);
      }
    }
    IPath location = file.getLocation();
    if (location != null)
    {
      File ioFile = location.toFile();
      if ((ioFile != null) && (ioFile.exists())) {
        return new FileInputStream(ioFile);
      }
    }
    return null;
  }
  
  private static String[] readLines(IFile file)
    throws CVSException
  {
    try
    {
      InputStream in = getInputStream(file);
      if (in != null)
      {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in), 512);
        List fileContentStore = new ArrayList();
        try
        {
          String line;
          while ((line = reader.readLine()) != null)
          {
            String line;
            fileContentStore.add(line);
          }
          return (String[])fileContentStore.toArray(new String[fileContentStore.size()]);
        }
        finally
        {
          reader.close();
        }
      }
      return null;
    }
    catch (IOException e)
    {
      throw CVSException.wrapException(e);
    }
    catch (CoreException e)
    {
      if ((e.getStatus().getCode() == 368) || 
        (e.getStatus().getCode() == 271)) {
        return null;
      }
      throw CVSException.wrapException(e);
    }
  }
  
  private static void writeLines(IFile file, String[] contents)
    throws CVSException
  {
    try
    {
      ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable()
      {
        private final IFile val$file;
        
        public void run(IProgressMonitor monitor)
          throws CoreException
        {
          try
          {
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            SyncFileWriter.writeLinesToStreamAndClose(os, SyncFileWriter.this);
            if (!val$file.exists()) {
              val$file.create(new ByteArrayInputStream(os.toByteArray()), 1, null);
            } else {
              val$file.setContents(new ByteArrayInputStream(os.toByteArray()), 1, null);
            }
            val$file.setSessionProperty(SyncFileWriter.MODSTAMP_KEY, new Long(val$file.getModificationStamp()));
          }
          catch (CVSException e)
          {
            throw new CoreException(e.getStatus());
          }
        }
      }, ResourcesPlugin.getWorkspace().getRuleFactory().createRule(file), 0, null);
    }
    catch (CoreException e)
    {
      throw CVSException.wrapException(e);
    }
  }
  
  /* Error */
  private static void writeLinesToStreamAndClose(java.io.OutputStream os, String[] contents)
    throws CVSException
  {
    // Byte code:
    //   0: invokestatic 624	org/eclipse/team/internal/ccvs/core/util/SyncFileWriter:getLineDelimiter	()[B
    //   3: astore_2
    //   4: iconst_0
    //   5: istore_3
    //   6: goto +21 -> 27
    //   9: aload_0
    //   10: aload_1
    //   11: iload_3
    //   12: aaload
    //   13: invokevirtual 572	java/lang/String:getBytes	()[B
    //   16: invokevirtual 568	java/io/OutputStream:write	([B)V
    //   19: aload_0
    //   20: aload_2
    //   21: invokevirtual 568	java/io/OutputStream:write	([B)V
    //   24: iinc 3 1
    //   27: iload_3
    //   28: aload_1
    //   29: arraylength
    //   30: if_icmplt -21 -> 9
    //   33: goto +12 -> 45
    //   36: astore 4
    //   38: aload_0
    //   39: invokevirtual 567	java/io/OutputStream:close	()V
    //   42: aload 4
    //   44: athrow
    //   45: aload_0
    //   46: invokevirtual 567	java/io/OutputStream:close	()V
    //   49: goto +9 -> 58
    //   52: astore_3
    //   53: aload_3
    //   54: invokestatic 598	org/eclipse/team/internal/ccvs/core/CVSException:wrapException	(Ljava/lang/Exception;)Lorg/eclipse/team/internal/ccvs/core/CVSException;
    //   57: athrow
    //   58: return
    // Line number table:
    //   Java source line #608	-> byte code offset #0
    //   Java source line #611	-> byte code offset #4
    //   Java source line #612	-> byte code offset #9
    //   Java source line #613	-> byte code offset #19
    //   Java source line #611	-> byte code offset #24
    //   Java source line #615	-> byte code offset #36
    //   Java source line #616	-> byte code offset #38
    //   Java source line #617	-> byte code offset #42
    //   Java source line #616	-> byte code offset #45
    //   Java source line #618	-> byte code offset #52
    //   Java source line #619	-> byte code offset #53
    //   Java source line #621	-> byte code offset #58
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	59	0	os	java.io.OutputStream
    //   0	59	1	contents	String[]
    //   3	18	2	lineEnd	byte[]
    //   5	23	3	i	int
    //   52	2	3	e	IOException
    //   36	7	4	localObject	Object
    // Exception table:
    //   from	to	target	type
    //   4	36	36	finally
    //   4	49	52	java/io/IOException
  }
  
  /* Error */
  public static void writeFileToBaseDirectory(IFile file, IProgressMonitor monitor)
    throws CVSException
  {
    // Byte code:
    //   0: aload_1
    //   1: invokestatic 606	org/eclipse/team/internal/ccvs/core/Policy:monitorFor	(Lorg/eclipse/core/runtime/IProgressMonitor;)Lorg/eclipse/core/runtime/IProgressMonitor;
    //   4: astore_1
    //   5: aload_1
    //   6: aconst_null
    //   7: bipush 100
    //   9: invokeinterface 682 3 0
    //   14: aload_0
    //   15: invokestatic 634	org/eclipse/team/internal/ccvs/core/util/SyncFileWriter:getBaseDirectory	(Lorg/eclipse/core/resources/IFile;)Lorg/eclipse/core/resources/IFolder;
    //   18: astore_2
    //   19: aload_2
    //   20: invokeinterface 668 1 0
    //   25: ifne +17 -> 42
    //   28: aload_2
    //   29: iconst_0
    //   30: iconst_1
    //   31: aload_1
    //   32: bipush 10
    //   34: invokestatic 607	org/eclipse/team/internal/ccvs/core/Policy:subMonitorFor	(Lorg/eclipse/core/runtime/IProgressMonitor;I)Lorg/eclipse/core/runtime/IProgressMonitor;
    //   37: invokeinterface 673 4 0
    //   42: aload_2
    //   43: new 325	org/eclipse/core/runtime/Path
    //   46: dup
    //   47: aconst_null
    //   48: aload_0
    //   49: invokeinterface 656 1 0
    //   54: invokespecial 594	org/eclipse/core/runtime/Path:<init>	(Ljava/lang/String;Ljava/lang/String;)V
    //   57: invokeinterface 675 2 0
    //   62: astore_3
    //   63: aload_3
    //   64: invokeinterface 654 1 0
    //   69: ifeq +21 -> 90
    //   72: aload_3
    //   73: iconst_0
    //   74: invokestatic 625	org/eclipse/team/internal/ccvs/core/util/SyncFileWriter:setReadOnly	(Lorg/eclipse/core/resources/IFile;Z)V
    //   77: aload_3
    //   78: iconst_1
    //   79: aload_1
    //   80: bipush 10
    //   82: invokestatic 607	org/eclipse/team/internal/ccvs/core/Policy:subMonitorFor	(Lorg/eclipse/core/runtime/IProgressMonitor;I)Lorg/eclipse/core/runtime/IProgressMonitor;
    //   85: invokeinterface 664 3 0
    //   90: aload_0
    //   91: aload_3
    //   92: invokeinterface 661 1 0
    //   97: iconst_1
    //   98: aload_1
    //   99: bipush 80
    //   101: invokestatic 607	org/eclipse/team/internal/ccvs/core/Policy:subMonitorFor	(Lorg/eclipse/core/runtime/IProgressMonitor;I)Lorg/eclipse/core/runtime/IProgressMonitor;
    //   104: invokeinterface 666 4 0
    //   109: goto +20 -> 129
    //   112: astore_2
    //   113: aload_2
    //   114: invokestatic 599	org/eclipse/team/internal/ccvs/core/CVSException:wrapException	(Lorg/eclipse/core/runtime/CoreException;)Lorg/eclipse/team/internal/ccvs/core/CVSException;
    //   117: athrow
    //   118: astore 4
    //   120: aload_1
    //   121: invokeinterface 681 1 0
    //   126: aload 4
    //   128: athrow
    //   129: aload_1
    //   130: invokeinterface 681 1 0
    //   135: return
    // Line number table:
    //   Java source line #630	-> byte code offset #0
    //   Java source line #631	-> byte code offset #5
    //   Java source line #633	-> byte code offset #14
    //   Java source line #634	-> byte code offset #19
    //   Java source line #635	-> byte code offset #28
    //   Java source line #637	-> byte code offset #42
    //   Java source line #638	-> byte code offset #63
    //   Java source line #641	-> byte code offset #72
    //   Java source line #642	-> byte code offset #77
    //   Java source line #645	-> byte code offset #90
    //   Java source line #646	-> byte code offset #112
    //   Java source line #647	-> byte code offset #113
    //   Java source line #648	-> byte code offset #118
    //   Java source line #649	-> byte code offset #120
    //   Java source line #650	-> byte code offset #126
    //   Java source line #649	-> byte code offset #129
    //   Java source line #651	-> byte code offset #135
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	136	0	file	IFile
    //   0	136	1	monitor	IProgressMonitor
    //   18	25	2	baseFolder	IFolder
    //   112	2	2	e	CoreException
    //   62	30	3	target	IFile
    //   118	9	4	localObject	Object
    // Exception table:
    //   from	to	target	type
    //   14	109	112	org/eclipse/core/runtime/CoreException
    //   14	118	118	finally
  }
  
  /* Error */
  public static void restoreFileFromBaseDirectory(IFile file, IProgressMonitor monitor)
    throws CVSException
  {
    // Byte code:
    //   0: aload_1
    //   1: invokestatic 606	org/eclipse/team/internal/ccvs/core/Policy:monitorFor	(Lorg/eclipse/core/runtime/IProgressMonitor;)Lorg/eclipse/core/runtime/IProgressMonitor;
    //   4: astore_1
    //   5: aload_1
    //   6: aconst_null
    //   7: bipush 100
    //   9: invokeinterface 682 3 0
    //   14: aload_0
    //   15: invokestatic 634	org/eclipse/team/internal/ccvs/core/util/SyncFileWriter:getBaseDirectory	(Lorg/eclipse/core/resources/IFile;)Lorg/eclipse/core/resources/IFolder;
    //   18: astore_2
    //   19: aload_2
    //   20: new 325	org/eclipse/core/runtime/Path
    //   23: dup
    //   24: aconst_null
    //   25: aload_0
    //   26: invokeinterface 656 1 0
    //   31: invokespecial 594	org/eclipse/core/runtime/Path:<init>	(Ljava/lang/String;Ljava/lang/String;)V
    //   34: invokeinterface 675 2 0
    //   39: astore_3
    //   40: aload_3
    //   41: invokeinterface 654 1 0
    //   46: ifne +49 -> 95
    //   49: new 331	org/eclipse/team/internal/ccvs/core/CVSStatus
    //   52: dup
    //   53: iconst_4
    //   54: iconst_4
    //   55: getstatic 558	org/eclipse/team/internal/ccvs/core/CVSMessages:SyncFileWriter_baseNotAvailable	Ljava/lang/String;
    //   58: iconst_1
    //   59: anewarray 302	java/lang/String
    //   62: dup
    //   63: iconst_0
    //   64: aload_0
    //   65: invokeinterface 661 1 0
    //   70: invokeinterface 680 1 0
    //   75: aastore
    //   76: invokestatic 596	org/eclipse/osgi/util/NLS:bind	(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;
    //   79: aload_0
    //   80: invokespecial 605	org/eclipse/team/internal/ccvs/core/CVSStatus:<init>	(IILjava/lang/String;Lorg/eclipse/core/resources/IResource;)V
    //   83: astore 4
    //   85: new 328	org/eclipse/team/internal/ccvs/core/CVSException
    //   88: dup
    //   89: aload 4
    //   91: invokespecial 597	org/eclipse/team/internal/ccvs/core/CVSException:<init>	(Lorg/eclipse/core/runtime/IStatus;)V
    //   94: athrow
    //   95: aload_0
    //   96: invokeinterface 654 1 0
    //   101: ifeq +17 -> 118
    //   104: aload_0
    //   105: iconst_0
    //   106: iconst_1
    //   107: aload_1
    //   108: bipush 10
    //   110: invokestatic 607	org/eclipse/team/internal/ccvs/core/Policy:subMonitorFor	(Lorg/eclipse/core/runtime/IProgressMonitor;I)Lorg/eclipse/core/runtime/IProgressMonitor;
    //   113: invokeinterface 665 4 0
    //   118: aload_3
    //   119: iconst_0
    //   120: invokestatic 625	org/eclipse/team/internal/ccvs/core/util/SyncFileWriter:setReadOnly	(Lorg/eclipse/core/resources/IFile;Z)V
    //   123: aload_3
    //   124: aload_0
    //   125: invokeinterface 661 1 0
    //   130: iconst_0
    //   131: iconst_1
    //   132: aload_1
    //   133: bipush 100
    //   135: invokestatic 607	org/eclipse/team/internal/ccvs/core/Policy:subMonitorFor	(Lorg/eclipse/core/runtime/IProgressMonitor;I)Lorg/eclipse/core/runtime/IProgressMonitor;
    //   138: invokeinterface 667 5 0
    //   143: goto +20 -> 163
    //   146: astore_2
    //   147: aload_2
    //   148: invokestatic 599	org/eclipse/team/internal/ccvs/core/CVSException:wrapException	(Lorg/eclipse/core/runtime/CoreException;)Lorg/eclipse/team/internal/ccvs/core/CVSException;
    //   151: athrow
    //   152: astore 5
    //   154: aload_1
    //   155: invokeinterface 681 1 0
    //   160: aload 5
    //   162: athrow
    //   163: aload_1
    //   164: invokeinterface 681 1 0
    //   169: return
    // Line number table:
    //   Java source line #659	-> byte code offset #0
    //   Java source line #660	-> byte code offset #5
    //   Java source line #662	-> byte code offset #14
    //   Java source line #663	-> byte code offset #19
    //   Java source line #664	-> byte code offset #40
    //   Java source line #665	-> byte code offset #49
    //   Java source line #666	-> byte code offset #85
    //   Java source line #668	-> byte code offset #95
    //   Java source line #669	-> byte code offset #104
    //   Java source line #672	-> byte code offset #118
    //   Java source line #674	-> byte code offset #123
    //   Java source line #675	-> byte code offset #146
    //   Java source line #676	-> byte code offset #147
    //   Java source line #677	-> byte code offset #152
    //   Java source line #678	-> byte code offset #154
    //   Java source line #679	-> byte code offset #160
    //   Java source line #678	-> byte code offset #163
    //   Java source line #680	-> byte code offset #169
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	170	0	file	IFile
    //   0	170	1	monitor	IProgressMonitor
    //   18	2	2	baseFolder	IFolder
    //   146	2	2	e	CoreException
    //   39	85	3	source	IFile
    //   83	7	4	status	IStatus
    //   152	9	5	localObject	Object
    // Exception table:
    //   from	to	target	type
    //   14	143	146	org/eclipse/core/runtime/CoreException
    //   14	152	152	finally
  }
  
  private static void setReadOnly(IFile source, boolean readOnly)
  {
    ResourceAttributes attrs = source.getResourceAttributes();
    if ((attrs != null) && (attrs.isReadOnly() != readOnly))
    {
      attrs.setReadOnly(readOnly);
      try
      {
        source.setResourceAttributes(attrs);
      }
      catch (CoreException e)
      {
        CVSProviderPlugin.log(e);
      }
    }
  }
  
  /* Error */
  public static void deleteFileFromBaseDirectory(IFile file, IProgressMonitor monitor)
    throws CVSException
  {
    // Byte code:
    //   0: aload_1
    //   1: invokestatic 606	org/eclipse/team/internal/ccvs/core/Policy:monitorFor	(Lorg/eclipse/core/runtime/IProgressMonitor;)Lorg/eclipse/core/runtime/IProgressMonitor;
    //   4: astore_1
    //   5: aload_1
    //   6: aconst_null
    //   7: bipush 100
    //   9: invokeinterface 682 3 0
    //   14: aload_0
    //   15: invokestatic 634	org/eclipse/team/internal/ccvs/core/util/SyncFileWriter:getBaseDirectory	(Lorg/eclipse/core/resources/IFile;)Lorg/eclipse/core/resources/IFolder;
    //   18: astore_2
    //   19: aload_2
    //   20: new 325	org/eclipse/core/runtime/Path
    //   23: dup
    //   24: aconst_null
    //   25: aload_0
    //   26: invokeinterface 656 1 0
    //   31: invokespecial 594	org/eclipse/core/runtime/Path:<init>	(Ljava/lang/String;Ljava/lang/String;)V
    //   34: invokeinterface 675 2 0
    //   39: astore_3
    //   40: aload_3
    //   41: invokeinterface 654 1 0
    //   46: ifeq +42 -> 88
    //   49: aload_3
    //   50: iconst_0
    //   51: invokestatic 625	org/eclipse/team/internal/ccvs/core/util/SyncFileWriter:setReadOnly	(Lorg/eclipse/core/resources/IFile;Z)V
    //   54: aload_3
    //   55: iconst_0
    //   56: iconst_0
    //   57: aload_1
    //   58: bipush 100
    //   60: invokestatic 607	org/eclipse/team/internal/ccvs/core/Policy:subMonitorFor	(Lorg/eclipse/core/runtime/IProgressMonitor;I)Lorg/eclipse/core/runtime/IProgressMonitor;
    //   63: invokeinterface 665 4 0
    //   68: goto +20 -> 88
    //   71: astore_2
    //   72: aload_2
    //   73: invokestatic 599	org/eclipse/team/internal/ccvs/core/CVSException:wrapException	(Lorg/eclipse/core/runtime/CoreException;)Lorg/eclipse/team/internal/ccvs/core/CVSException;
    //   76: athrow
    //   77: astore 4
    //   79: aload_1
    //   80: invokeinterface 681 1 0
    //   85: aload 4
    //   87: athrow
    //   88: aload_1
    //   89: invokeinterface 681 1 0
    //   94: return
    // Line number table:
    //   Java source line #701	-> byte code offset #0
    //   Java source line #702	-> byte code offset #5
    //   Java source line #704	-> byte code offset #14
    //   Java source line #705	-> byte code offset #19
    //   Java source line #706	-> byte code offset #40
    //   Java source line #707	-> byte code offset #49
    //   Java source line #708	-> byte code offset #54
    //   Java source line #710	-> byte code offset #71
    //   Java source line #711	-> byte code offset #72
    //   Java source line #712	-> byte code offset #77
    //   Java source line #713	-> byte code offset #79
    //   Java source line #714	-> byte code offset #85
    //   Java source line #713	-> byte code offset #88
    //   Java source line #715	-> byte code offset #94
    // Local variable table:
    //   start	length	slot	name	signature
    //   0	95	0	file	IFile
    //   0	95	1	monitor	IProgressMonitor
    //   18	2	2	baseFolder	IFolder
    //   71	2	2	e	CoreException
    //   39	16	3	source	IFile
    //   77	9	4	localObject	Object
    // Exception table:
    //   from	to	target	type
    //   14	68	71	org/eclipse/core/runtime/CoreException
    //   14	77	77	finally
  }
  
  private static IFolder getBaseDirectory(IFile file)
  {
    IContainer cvsFolder = getCVSSubdirectory(file.getParent());
    IFolder baseFolder = cvsFolder.getFolder(new Path("Base"));
    return baseFolder;
  }
  
  public static IFile getTemplateFile(IContainer folder)
    throws CVSException
  {
    IFolder cvsFolder = createCVSSubdirectory(folder);
    return cvsFolder.getFile("Template");
  }
  
  public static boolean isEdited(IFile file)
  {
    IFolder baseFolder = getBaseDirectory(file);
    IFile baseFile = baseFolder.getFile(file.getName());
    return baseFile.exists();
  }
  
  private static byte[] getLineDelimiter()
  {
    if (CVSProviderPlugin.getPlugin().isUsePlatformLineend())
    {
      String property = System.getProperty("line.separator");
      if (property != null) {
        return property.getBytes();
      }
    }
    return new byte[] { 10 };
  }
}

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

import java.io.IOException;

class Util$1
  implements Runnable
{
  private final String[] val$command;
  private final Process[] val$process;
  private final Exception[] val$exception;
  
  Util$1(String[] paramArrayOfString, Process[] paramArrayOfProcess, Exception[] paramArrayOfException)
  {
    val$command = paramArrayOfString;val$process = paramArrayOfProcess;val$exception = paramArrayOfException;
  }
  
  public void run()
  {
    try
    {
      Process newProcess = Runtime.getRuntime().exec(val$command);
      synchronized (val$process)
      {
        if (Thread.interrupted()) {
          newProcess.destroy();
        } else {
          val$process[0] = newProcess;
        }
      }
    }
    catch (IOException e)
    {
      val$exception[0] = e;
    }
  }
}

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

import java.io.IOException;
import java.io.InterruptedIOException;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
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.ICVSResource;
import org.eclipse.team.internal.ccvs.core.ICVSStorage;
import org.eclipse.team.internal.ccvs.core.Policy;
import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot;
import org.eclipse.team.internal.ccvs.core.syncinfo.FolderSyncInfo;
import org.eclipse.team.internal.ccvs.core.syncinfo.ResourceSyncInfo;

public class Util
{
  public static String getLastSegment(String path)
  {
    int index = path.lastIndexOf("/");
    if (index == -1) {
      return path;
    }
    if (index == path.length() - 1) {
      return getLastSegment(path.substring(0, index));
    }
    return path.substring(index + 1);
  }
  
  public static String removeLastSegment(String path)
  {
    int index = path.lastIndexOf("/");
    if (index == -1) {
      return "";
    }
    return path.substring(0, index);
  }
  
  public static String asPath(String path)
  {
    if (path.endsWith("/")) {
      return path.substring(0, path.length() - "/".length());
    }
    return path;
  }
  
  public static String getRelativePath(String rootName, String resourceName)
    throws CVSException
  {
    if ((!resourceName.startsWith(rootName)) || (rootName.length() > resourceName.length())) {
      throw new CVSException(CVSMessages.Util_Internal_error__resource_does_not_start_with_root_3);
    }
    if (rootName.length() == resourceName.length()) {
      return "";
    }
    String result = resourceName.substring(rootName.length());
    if (result.startsWith("/")) {
      result = result.substring(1);
    }
    return result;
  }
  
  public static String appendPath(String prefix, String suffix)
  {
    if ((prefix.length() == 0) || (prefix.equals("."))) {
      return suffix;
    }
    if (prefix.endsWith("/"))
    {
      if (suffix.startsWith("/")) {
        return prefix + suffix.substring(1);
      }
      return prefix + suffix;
    }
    if (suffix.startsWith("/")) {
      return prefix + suffix;
    }
    return prefix + "/" + suffix;
  }
  
  public static void logError(String message, Throwable throwable)
  {
    CVSProviderPlugin.log(4, message, throwable);
  }
  
  public static String toTruncatedPath(ICVSResource resource, ICVSFolder root, int split)
  {
    try
    {
      String stringPath = resource.getRelativePath(root);
      if (stringPath.equals(".")) {
        return resource.getName();
      }
      return toTruncatedPath(stringPath, split);
    }
    catch (CVSException localCVSException) {}
    return resource.getName();
  }
  
  public static String toTruncatedPath(String stringPath, int split)
  {
    int count = 0;
    int index = stringPath.length();
    while ((count++ < split) && (index != -1)) {
      index = stringPath.lastIndexOf("/", index - 1);
    }
    if (index == -1) {
      return stringPath;
    }
    return NLS.bind(CVSMessages.Util_truncatedPath, new String[] { stringPath.substring(index) });
  }
  
  public static Socket createSocket(String host, int port, IProgressMonitor monitor)
    throws UnknownHostException, IOException
  {
    int timeout = CVSProviderPlugin.getPlugin().getTimeout();
    if (timeout == 0) {
      timeout = 60;
    }
    ResponsiveSocketFactory factory = new ResponsiveSocketFactory(monitor, timeout);
    return factory.createSocket(host, port);
  }
  
  public static Process createProcess(String[] command, IProgressMonitor monitor)
    throws IOException
  {
    Process[] process = new Process[1];
    Exception[] exception = new Exception[1];
    Thread thread = new Thread(new Runnable()
    {
      private final Process[] val$process;
      private final Exception[] val$exception;
      
      public void run()
      {
        try
        {
          Process newProcess = Runtime.getRuntime().exec(Util.this);
          synchronized (val$process)
          {
            if (Thread.interrupted()) {
              newProcess.destroy();
            } else {
              val$process[0] = newProcess;
            }
          }
        }
        catch (IOException e)
        {
          val$exception[0] = e;
        }
      }
    });
    thread.start();
    
    int timeout = CVSProviderPlugin.getPlugin().getTimeout();
    if (timeout == 0) {
      timeout = 60;
    }
    for (int i = 0; i < timeout; i++)
    {
      try
      {
        thread.join(1000L);
      }
      catch (InterruptedException localInterruptedException) {}
      synchronized (process)
      {
        if (monitor.isCanceled())
        {
          if (thread.isAlive()) {
            thread.interrupt();
          }
          if (process[0] != null) {
            process[0].destroy();
          }
          Policy.checkCanceled(monitor);
        }
      }
    }
    synchronized (process)
    {
      if (thread.isAlive()) {
        thread.interrupt();
      }
    }
    if (exception[0] != null) {
      throw ((IOException)exception[0]);
    }
    if (process[0] == null) {
      throw new InterruptedIOException(NLS.bind(CVSMessages.Util_processTimeout, new String[] { command[0] }));
    }
    return process[0];
  }
  
  public static String[] parseIntoSubstrings(String string, String delimiter)
  {
    List result = new ArrayList();
    int start = 0;
    int index = string.indexOf(delimiter);
    while (index != -1)
    {
      String next = string.substring(start, index);
      result.add(next);
      start = index + 1;
      index = string.indexOf(delimiter, start);
    }
    String next;
    String next;
    if (start >= string.length()) {
      next = "";
    } else {
      next = string.substring(start);
    }
    result.add(next);
    return (String[])result.toArray(new String[result.size()]);
  }
  
  public static String getSubstring(byte[] bytes, byte delimiter, int index, boolean includeRest)
  {
    byte[] bytesForSlot = getBytesForSlot(bytes, delimiter, index, includeRest);
    if (bytesForSlot == null) {
      return null;
    }
    return new String(bytesForSlot);
  }
  
  public static int getOffsetOfDelimeter(byte[] bytes, byte delimiter, int start, int n)
  {
    int count = 0;
    for (int i = start; i < bytes.length; i++)
    {
      if (bytes[i] == delimiter) {
        count++;
      }
      if (count == n) {
        return i;
      }
    }
    return -1;
  }
  
  public static byte[] getBytesForSlot(byte[] bytes, byte delimiter, int index, boolean includeRest)
  {
    int start;
    int start;
    if (index == 0)
    {
      start = -1;
    }
    else
    {
      start = getOffsetOfDelimeter(bytes, delimiter, 0, index);
      if (start == -1) {
        return null;
      }
    }
    int end = getOffsetOfDelimeter(bytes, delimiter, start + 1, 1);
    int length;
    int length;
    if ((end == -1) || (includeRest)) {
      length = bytes.length - start - 1;
    } else {
      length = end - start - 1;
    }
    byte[] result = new byte[length];
    System.arraycopy(bytes, start + 1, result, 0, length);
    return result;
  }
  
  public static boolean equals(byte[] syncBytes, byte[] oldBytes)
  {
    if ((syncBytes == null) || (oldBytes == null)) {
      return syncBytes == oldBytes;
    }
    if (syncBytes.length != oldBytes.length) {
      return false;
    }
    for (int i = 0; i < oldBytes.length; i++) {
      if (oldBytes[i] != syncBytes[i]) {
        return false;
      }
    }
    return true;
  }
  
  public static CVSTag getAccurateFolderTag(IResource resource, CVSTag tag)
  {
    if (resource.getType() != 2) {
      return tag;
    }
    IResource[] members = (IResource[])null;
    try
    {
      members = ((IFolder)resource).members();
    }
    catch (CoreException localCoreException)
    {
      return tag;
    }
    for (int i = 0; i < members.length; i++) {
      if (members[i].getType() == 1) {
        return tag;
      }
    }
    IProject project = resource.getProject();
    if (project == null) {
      return tag;
    }
    ICVSFolder projectFolder = CVSWorkspaceRoot.getCVSFolderFor(project);
    try
    {
      projectSyncInfo = projectFolder.getFolderSyncInfo();
    }
    catch (CVSException localCVSException)
    {
      FolderSyncInfo projectSyncInfo;
      return tag;
    }
    FolderSyncInfo projectSyncInfo;
    if (projectSyncInfo == null) {
      return tag;
    }
    CVSTag projectTag = projectSyncInfo.getTag();
    if ((projectTag != null) && (projectTag.getName().equals(tag.getName()))) {
      return projectTag;
    }
    return tag;
  }
  
  public static CVSTag getAccurateFileTag(ICVSResource cvsResource)
    throws CVSException
  {
    CVSTag tag = null;
    ResourceSyncInfo info = cvsResource.getSyncInfo();
    if (info != null) {
      tag = info.getTag();
    }
    FolderSyncInfo parentInfo = cvsResource.getParent().getFolderSyncInfo();
    CVSTag parentTag = null;
    if (parentInfo != null) {
      parentTag = parentInfo.getTag();
    }
    if (tag != null) {
      if (tag.getName().equals(info.getRevision())) {
        tag = new CVSTag(tag.getName(), 2);
      } else if (parentTag != null) {
        tag = new CVSTag(tag.getName(), parentTag.getType());
      }
    }
    return tag;
  }
  
  public static String getFullestPath(ICVSResource resource)
  {
    IResource local = resource.getIResource();
    if (local != null) {
      return local.getFullPath().toString();
    }
    try
    {
      String remotePath = resource.getRepositoryRelativePath();
      if (remotePath != null) {
        return remotePath;
      }
    }
    catch (CVSException localCVSException) {}
    return resource.getName();
  }
  
  public static String getVariablePattern(String pattern, String variableName)
  {
    return "(" + variableName + ":" + pattern + ":" + variableName + ")";
  }
  
  public static int[] convertToDigits(String localRevision)
  {
    try
    {
      String[] digitStrings = localRevision.split("\\.");
      int[] digits = new int[digitStrings.length];
      for (int i = 0; i < digitStrings.length; i++)
      {
        String digitString = digitStrings[i];
        digits[i] = Integer.parseInt(digitString);
      }
      return digits;
    }
    catch (NumberFormatException e)
    {
      CVSProviderPlugin.log(CVSException.wrapException(e));
    }
    return new int[0];
  }
  
  public static String toTruncatedPath(ICVSStorage file, ICVSFolder localRoot, int i)
  {
    if ((file instanceof ICVSResource)) {
      return toTruncatedPath((ICVSResource)file, localRoot, i);
    }
    return file.getName();
  }
  
  public static String removeAtticSegment(String path)
  {
    int lastSeparator = path.lastIndexOf("/");
    if (lastSeparator == -1) {
      return path;
    }
    int secondLastSeparator = path.lastIndexOf("/", lastSeparator - 1);
    if (secondLastSeparator == -1) {
      return path;
    }
    String secondLastSegment = path.substring(secondLastSeparator + 1, lastSeparator);
    if (secondLastSegment.equals("Attic")) {
      return path.substring(0, secondLastSeparator) + path.substring(lastSeparator);
    }
    return path;
  }
  
  public static String flattenText(String string)
  {
    StringBuffer buffer = new StringBuffer(string.length() + 20);
    boolean skipAdjacentLineSeparator = true;
    for (int i = 0; i < string.length(); i++)
    {
      char c = string.charAt(i);
      if ((c == '\r') || (c == '\n'))
      {
        if (!skipAdjacentLineSeparator) {
          buffer.append("/");
        }
        skipAdjacentLineSeparator = true;
      }
      else
      {
        buffer.append(c);
        skipAdjacentLineSeparator = false;
      }
    }
    return buffer.toString();
  }
}

/* Location:
 * Qualified Name:     org.eclipse.team.internal.ccvs.core.util.Util
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
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