public void CreateRepositoryTest() { String fullPath = this.settings.Config.LocalPath; ICvsFile cvsFile = factory.CreateCvsObject(fullPath, Repository.FILE_NAME, REPOSITORY_LINE); Assert.IsTrue(cvsFile is Repository); Assert.AreEqual(fullPath, cvsFile.Path); Assert.AreEqual(REPOSITORY_LINE, cvsFile.FileContents); }
public void CreateRootTest() { String fullPath = this.settings.Config.LocalPath; ICvsFile cvsFile = factory.CreateCvsObject(fullPath, Factory.FileType.Root.ToString(), ROOT_LINE); Assert.IsTrue(cvsFile is Root); Assert.AreEqual(Path.Combine(fullPath, "CVS"), cvsFile.ParentDir.FullName); Assert.AreEqual(fullPath, cvsFile.Path); Assert.AreEqual(ROOT_LINE, cvsFile.FileContents); }
public void CreateEntryTest() { String path = this.settings.Config.LocalPath; ICvsFile cvsFile = factory.CreateCvsObject(path, Factory.FileType.Entries.ToString(), ENTRY_LINE); Assert.IsTrue(cvsFile is Entry); Assert.AreEqual(path, cvsFile.Path); Assert.AreEqual(Path.Combine(path, ENTRY_NAME_OF_FILE), cvsFile.FullPath); Assert.AreEqual(ENTRY_LINE, cvsFile.FileContents); }
public void CreateTagTest() { String fullPath = this.settings.Config.LocalPath; ICvsFile cvsFile = factory.CreateCvsObject(fullPath, Factory.FileType.Tag.ToString(), TAG_LINE); Assert.IsTrue(cvsFile is Tag); Assert.AreEqual(Path.Combine(fullPath, "CVS"), cvsFile.ParentDir.FullName); Assert.AreEqual(fullPath, cvsFile.Path); Assert.AreEqual("N" + TAG_LINE.Substring(1), cvsFile.FileContents); }
private void CreateCvsDir (ICvsFile cvsFile) { this.Touch(cvsFile); }
/// <summary> /// Checks if a cvs directory exists in the specified path, /// if it does not then it is created. If the CVS directory /// already exists at the end of the path specified, then it /// is returned untouched. /// </summary> /// <param name="cvsFile">The full path to the file or directory.</param> /// <returns>The path to the cvs directory.</returns> internal String GetCvsDir (ICvsFile cvsFile) { String path = cvsFile.ParentDir.FullName; if (cvsFile is Entry) { Entry entry = (Entry)cvsFile; if (entry.IsDirectory && path.EndsWith(Path.DirectorySeparatorChar.ToString())) { path = path.Substring(0, path.Length - 1); } } path = Path.GetDirectoryName(path); string cvsDir; if (PathTranslator.IsCvsDir(path)) { cvsDir = path; } else { cvsDir = Path.Combine(path, CVS); } LOGGER.Debug("path=[" + path + "]"); LOGGER.Debug("GetCvsDir(String)=[" + cvsDir + "]"); return cvsDir; }
/// <summary> /// Adds a collection of lines to the cvs file. The first /// entry overwrites any file currently in the directory /// and all other following entries are appended to the /// file. /// </summary> /// <param name="entries">The collection of cvs entries to add to the /// file system.</param> private void WriteToFile (ICvsFile[] entries) { LOGGER.Debug("entries count=[" + entries.Length + "]"); Hashtable existingEntries; if (entries[0].IsMultiLined) { try { existingEntries = this.GetContents(entries[0].CvsFile); foreach (ICvsFile entry in entries) { if (!existingEntries.Contains(entry.Key)) { existingEntries.Add(entry.Key, entry); } } } catch (CvsFileNotFoundException) { } } bool append = false; foreach (ICvsFile entry in entries) { this.WriteToFile (entry.CvsFile, entry.FileContents, append); if (!append) { append = true; } } }
/// <summary> /// Adds a single file or line to the CVS management file on the local /// file system. /// </summary> /// <param name="cvsFile">The collection of cvs entries to add to the /// file system.</param> private void WriteToFile (ICvsFile cvsFile) { ICvsFile[] cvsFiles = {cvsFile}; this.WriteToFile(cvsFiles); }
/// <summary> /// Remove the contents from the cvs control file. /// </summary> public void Remove (ICvsFile file) { this.RemoveFromFile (file.CvsFile.FullName, file.Filename, file.FileContents); }
/// <summary> /// Add the contents of the cvs file object to the respective file. /// </summary> public void Add (ICvsFile newCvsEntry) { this.CreateCvsDir (newCvsEntry); Hashtable newCvsEntries = new Hashtable(); try { ArrayList currentCvsFiles = new ArrayList(this.Fetch (newCvsEntry.ParentDir.FullName, newCvsEntry.Type)); int originalCount = currentCvsFiles.Count; if (currentCvsFiles.Count >= 1 && !newCvsEntry.IsMultiLined) { LOGGER.Debug ("The file already has an entry and cannot be modified."); return; } foreach (ICvsFile currentCvsFile in currentCvsFiles) { if (newCvsEntries.Contains(currentCvsFile.Key)) { throw new DuplicateEntryException("Should not have a duplicate."); } newCvsEntries.Add(currentCvsFile.Key, currentCvsFile); } // replace old entry or create new if (newCvsEntries.Contains(newCvsEntry.Key)) { newCvsEntries[newCvsEntry.Key] = newCvsEntry; } else { LOGGER.Error("Adding new entry to the entries file=[" + newCvsEntry + "]"); newCvsEntries.Add(newCvsEntry.Key, newCvsEntry); } } catch (FileNotFoundException e) { // If we can't find the file, chances are this is the first // entry that we are adding. LOGGER.Error(e); newCvsEntries.Add(newCvsEntry.Key, newCvsEntry); } ArrayList modifiedEntries = new ArrayList(newCvsEntries.Values); LOGGER.Error("modifiedEntries.Count=[" + modifiedEntries.Count + "]"); this.WriteToFile ( (ICvsFile[])modifiedEntries.ToArray (typeof (ICvsFile))); }
private void Touch (ICvsFile cvsFile) { this.Touch(cvsFile.CvsFile); }