Пример #1
0
		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);
		}
Пример #2
0
 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);
             }
         }
     }
 }
Пример #3
0
		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);
		}
Пример #4
0
        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, new Dictionary<string, string>());
                        result.AddTaskResult((new XslMergerTaskResult(Data)));
                    }
                    else
                    {
                        Log.Warning("File not Found: " + XmlFileInfo);
                    }
                }
            }
        }
Пример #5
0
		public void InvalidWildCardPathReturnsNoFiles()
		{
			WildCardPath wildCard = new WildCardPath(Path.Combine("nonexistantfolder", "*"));
			IList files = wildCard.GetFiles();
			Assert.AreEqual(0, files.Count);
		}
Пример #6
0
		public void StringWithNoWildCardsReturnsSingleFile()
		{
			WildCardPath wildCard = new WildCardPath("foo.xml");
			IList files = wildCard.GetFiles();
			Assert.AreEqual(1, files.Count);
		}
Пример #7
0
        /// <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;
		}
Пример #8
0
        public void StringWithWildcardsInPathShouldUseFolderWildcardsAndSimpleWildcardForAFolderName()
        {
            WildCardPath wildCard = new WildCardPath(Path.Combine(tempFolderFullPath, @"RootLevel\**\SecondLevelA\Thir*\*.txt"));

            FileInfo[] fileMatches = wildCard.GetFiles();

            Assert.AreEqual(3, fileMatches.Length);
        }
Пример #9
0
        public void StringWithWildcardsInPathShouldUseWildcardsInTwoFolderSegments()
        {
            WildCardPath wildCard = new WildCardPath(Path.Combine(tempFolderFullPath, @"RootLevel\**\SecondLevelA\**\*.txt"));

            FileInfo[] fileMatches = wildCard.GetFiles();

            Assert.AreEqual(5, fileMatches.Length);
        }
Пример #10
0
        public void StringWithWildcardsInPathShouldUseWildcardsFollowedByFolderNameSegment()
        {
            WildCardPath wildCard = new WildCardPath(Path.Combine(tempFolderFullPath, @"RootLevel\**\ThirdLevelA\*.txt"));
            FileInfo[] fileMatches = wildCard.GetFiles();

            Assert.AreEqual(3, fileMatches.Length);
        }
Пример #11
0
        public void StringWithWildcardsInPathShouldGetAllTxtFilesInsideRootLevel()
        {
            WildCardPath wildCard = new WildCardPath(Path.Combine(tempFolderFullPath, @"RootLevel\**\*.txt"));

            FileInfo[] fileMatches = wildCard.GetFiles();

            Assert.AreEqual(9, fileMatches.Length);
        }