public void InvalidWildCardPathReturnsNoFiles() { WildCardPath wildCard = new WildCardPath(Path.Combine("nonexistantfolder", "*")); IList files = wildCard.GetFiles(); Assert.AreEqual(0, files.Count); }
public void Can_generate_empty_route_with_WildCard_path() { var request = new WildCardPath(); var url = request.ToUrl("GET"); Assert.That(url, Is.EqualTo("/images/")); }
public void Run(IIntegrationResult result) { foreach (string mergeFile in MergeFiles) { string fullMergeFile = mergeFile; if (!Path.IsPathRooted(mergeFile)) { fullMergeFile = Path.Combine(result.WorkingDirectory, mergeFile); } WildCardPath path = new WildCardPath(fullMergeFile); FileInfo[] files = path.GetFiles(); foreach (FileInfo fileInfo in files) { Log.Info("Merging file: " + fileInfo); if (fileInfo.Exists) { result.AddTaskResult((new FileTaskResult(fileInfo))); } else { Log.Warning("File not Found: " + fileInfo); } } } }
public void StringWithNoWildCardsReturnsSingleFile() { WildCardPath wildCard = new WildCardPath("foo.xml"); IList files = wildCard.GetFiles(); Assert.AreEqual(1, files.Count); }
public void HandlesWhiteSpaceInTheFileName() { WildCardPath wildCard = new WildCardPath("fooo.xml "); FileInfo[] files = wildCard.GetFiles(); Assert.AreEqual(1, files.Length); Assert.AreEqual("fooo.xml", files[0].Name); }
public void StringWithWildcardsInPathShouldUseFolderWildcardsAndSimpleWildcardForAFolderName() { WildCardPath wildCard = new WildCardPath(Path.Combine(tempFolderFullPath, @"RootLevel\**\SecondLevelA\Thir*\*.txt")); FileInfo[] fileMatches = wildCard.GetFiles(); Assert.AreEqual(3, fileMatches.Length); }
public void StringWithWildcardsInPathShouldUseWildcardsInTwoFolderSegments() { WildCardPath wildCard = new WildCardPath(Path.Combine(tempFolderFullPath, @"RootLevel\**\SecondLevelA\**\*.txt")); FileInfo[] fileMatches = wildCard.GetFiles(); Assert.AreEqual(5, fileMatches.Length); }
public void StringWithWildcardsInPathShouldUseWildcardsFollowedByFolderNameSegment() { WildCardPath wildCard = new WildCardPath(Path.Combine(tempFolderFullPath, @"RootLevel\**\ThirdLevelA\*.txt")); FileInfo[] fileMatches = wildCard.GetFiles(); Assert.AreEqual(3, fileMatches.Length); }
public void StringWithWildcardsInPathShouldGetAllTxtFilesInsideRootLevel() { WildCardPath wildCard = new WildCardPath(Path.Combine(tempFolderFullPath, @"RootLevel\**\*.txt")); FileInfo[] fileMatches = wildCard.GetFiles(); Assert.AreEqual(9, fileMatches.Length); }
public void StringWithWildcardsInPathShouldReturnOneTxtFileInsideRootLevel() { WildCardPath wildCard = new WildCardPath(Path.Combine(tempFolderFullPath, "RootLevel", "**", "FileA.txt")); FileInfo[] fileMatches = wildCard.GetFiles(); Assert.AreEqual(5, fileMatches.Length); }
public void Can_generate_route_with_WildCard_path() { var request = new WildCardPath { ImagePath = "this/that/theother.jpg" }; var url = request.ToUrl("GET"); Assert.That(url, Is.EqualTo("/images/" + Uri.EscapeDataString(request.ImagePath))); }
public void StringWithPrefixAndWildcardsReturnsAllMatchingFiles() { string tempFile1Path = TempFileUtil.CreateTempFile(TEMP_FOLDER, "prefix-foo.txt", "foofoo"); string tempFile2Path = TempFileUtil.CreateTempFile(TEMP_FOLDER, "prefix-bar.txt", "barbar"); WildCardPath wildCard = new WildCardPath(Path.Combine(tempFolderFullPath, "prefix-*.txt")); IList files = wildCard.GetFiles(); Assert.AreEqual(2, files.Count); AssertListContainsPath(files, tempFile2Path); AssertListContainsPath(files, tempFile1Path); }
public void Run(IIntegrationResult result) { foreach (FilePair Pair in this.FilePairs) { string XmlFilePath = Pair.XmlFile; if (!Path.IsPathRooted(XmlFilePath)) { XmlFilePath = Path.Combine(result.WorkingDirectory, XmlFilePath); } string XslFilePath = Pair.XslFile; if (!Path.IsPathRooted(XslFilePath)) { XslFilePath = Path.Combine(result.WorkingDirectory, XslFilePath); } string XslFileName = Path.GetFileName(XslFilePath); if (!File.Exists(XslFilePath)) { Log.Warning("File not Found: " + XslFileName); } WildCardPath Pattern = new WildCardPath(XmlFilePath); FileInfo[] Files = Pattern.GetFiles(); foreach (FileInfo XmlFileInfo in Files) { Log.Info(String.Format("Merging file {0} through {1}", XmlFileInfo, XslFileName)); if (XmlFileInfo.Exists) { string Data; String Contents; using (TextReader Reader = XmlFileInfo.OpenText()) { Contents = Reader.ReadToEnd(); } XslTransformer Transformer = new XslTransformer(); Dictionary <string, string> XslParms = new Dictionary <string, string>(); XslParms.Add("CCNetServer", this.DashboardServerName); XslParms.Add("CCNetBuild", new LogFile(result).Filename); XslParms.Add("CCNetProject", result.ProjectName); XslParms.Add("XmlSourceName", Path.GetFileName(XmlFilePath)); XslParms.Add("XmlSourcePath", XmlFileInfo.FullName); Data = Transformer.Transform(Contents, XslFilePath, XslParms); result.AddTaskResult((new XslMergerTaskResult(Data))); } else { Log.Warning("File not Found: " + XmlFileInfo); } } } }
public void Run(IIntegrationResult result) { foreach (FilePair Pair in this.FilePairs) { string XmlFilePath = Pair.XmlFile; if (!Path.IsPathRooted(XmlFilePath)) { XmlFilePath = Path.Combine(result.WorkingDirectory, XmlFilePath); } string XslFilePath = Pair.XslFile; if (!Path.IsPathRooted(XslFilePath)) { XslFilePath = Path.Combine(result.WorkingDirectory, XslFilePath); } string XslFileName = Path.GetFileName(XslFilePath); if (!File.Exists(XslFilePath)) { Log.Warning("File not Found: " + XslFileName); } WildCardPath Pattern = new WildCardPath(XmlFilePath); FileInfo[] Files = Pattern.GetFiles(); foreach (FileInfo XmlFileInfo in Files) { Log.Info(String.Format("Merging file {0} through {1}", XmlFileInfo, XslFileName)); if (XmlFileInfo.Exists) { string Data; String Contents; using (TextReader Reader = XmlFileInfo.OpenText()) { Contents = Reader.ReadToEnd(); } XslTransformer Transformer = new XslTransformer(); Data = Transformer.Transform(Contents, XslFilePath); result.AddTaskResult((new XslMergerTaskResult(Data))); } else { Log.Warning("File not Found: " + XmlFileInfo); } } } }
/// <summary> /// Executes the specified result. /// </summary> /// <param name="result">The result.</param> /// <returns></returns> /// <remarks></remarks> protected override bool Execute(IIntegrationResult result) { result.BuildProgressInformation.SignalStartRunTask(!string.IsNullOrEmpty(Description) ? Description : "Merging Files"); var actualFileSystem = FileSystem ?? new SystemIoFileSystem(); var actualLogger = Logger ?? new DefaultLogger(); var targetSubFolder = result.Label; if (!result.Succeeded) { targetSubFolder = new LogFile(result).FilenameFormattedDateString; } // Make sure the target folder is rooted var targetFolder = TargetFolder; if (!string.IsNullOrEmpty(targetFolder)) { if (!Path.IsPathRooted(targetFolder)) { targetFolder = Path.Combine( Path.Combine(result.ArtifactDirectory, targetSubFolder), targetFolder); } } else { targetFolder = Path.Combine(result.ArtifactDirectory, targetSubFolder); } foreach (var mergeFile in MergeFiles) { // Get the name of the file string fullMergeFile = mergeFile.FileName; if (!Path.IsPathRooted(fullMergeFile)) { fullMergeFile = Path.Combine(result.WorkingDirectory, fullMergeFile); } // Merge each file WildCardPath path = new WildCardPath(fullMergeFile); foreach (var fileInfo in path.GetFiles()) { if (actualFileSystem.FileExists(fileInfo.FullName)) { switch (mergeFile.MergeAction) { case MergeFileInfo.MergeActionType.Merge: case MergeFileInfo.MergeActionType.CData: // Add the file to the merge list actualLogger.Info("Merging file '{0}'", fileInfo); result.BuildProgressInformation.AddTaskInformation(string.Format(CultureInfo.CurrentCulture, "Merging file '{0}'", fileInfo)); result.AddTaskResult( new FileTaskResult(fileInfo, mergeFile.DeleteAfterMerge, actualFileSystem) { WrapInCData = (mergeFile.MergeAction == MergeFileInfo.MergeActionType.CData) }); break; case MergeFileInfo.MergeActionType.Copy: // Copy the file to the target folder actualFileSystem.EnsureFolderExists(targetFolder); actualLogger.Info("Copying file '{0}' to '{1}'", fileInfo.Name, targetFolder); result.BuildProgressInformation.AddTaskInformation(string.Format(CultureInfo.CurrentCulture, "Copying file '{0}' to '{1}'", fileInfo.Name, targetFolder)); actualFileSystem.Copy(fileInfo.FullName, Path.Combine(targetFolder, fileInfo.Name)); break; case MergeFileInfo.MergeActionType.IndexCopy: // Copy the file to the target folder actualFileSystem.EnsureFolderExists(targetFolder); actualLogger.Info("Reading index file '{0}' for copy", fileInfo.Name); this.CopyFromIndex(fileInfo.Name, targetFolder, actualFileSystem, actualLogger, result); break; default: throw new CruiseControlException( string.Format(CultureInfo.CurrentCulture, "Unknown file merge action '{0}'", mergeFile.MergeAction)); } } else { actualLogger.Warning("File not found '{0}", fileInfo); } } } return(true); }