Esempio n. 1
0
        private ReferencedFile VisitReferencedFile(
            string absoluteFilePath,
            IFrameworkDefinition definition,
            HashSet <string> discoveredPaths,
            ICollection <ReferencedFile> referencedFiles,
            ChutzpahTestSettingsFile chutzpahTestSettings,
            ReferencePathSettings pathSettings)
        {
            // If the file doesn't exit exist or we have seen it already then return
            if (discoveredPaths.Contains(absoluteFilePath))
            {
                return(null);
            }

            var referencedFile = new ReferencedFile
            {
                Path                 = absoluteFilePath,
                IsLocal              = true,
                IsTestFrameworkFile  = pathSettings.IsTestFrameworkFile,
                IncludeInTestHarness = pathSettings.IncludeInTestHarness || chutzpahTestSettings.TestHarnessReferenceMode == TestHarnessReferenceMode.Normal,
                TemplateOptions      = pathSettings.TemplateOptions
            };

            ChutzpahTracer.TraceInformation(
                "Added file '{0}' to referenced files. Local: {1}, IncludeInTestHarness: {2}",
                referencedFile.Path,
                referencedFile.IsLocal,
                referencedFile.IncludeInTestHarness);

            referencedFiles.Add(referencedFile);
            discoveredPaths.Add(referencedFile.Path); // Remmember this path to detect reference loops


            ChutzpahTracer.TraceInformation("Processing referenced file '{0}' for expanded references", absoluteFilePath);
            if (pathSettings.ExpandReferenceComments)
            {
                referencedFile.ReferencedFiles = ExpandNestedReferences(discoveredPaths, definition, absoluteFilePath, chutzpahTestSettings);
            }

            return(referencedFile);
        }
        private ReferencedFile VisitReferencedFile(
            string absoluteFilePath,
            IFrameworkDefinition definition,
            HashSet<string> discoveredPaths,
            ICollection<ReferencedFile> referencedFiles,
            ChutzpahTestSettingsFile chutzpahTestSettings,
            ReferencePathSettings pathSettings)
        {
            // If the file doesn't exit exist or we have seen it already then return
            if (discoveredPaths.Contains(absoluteFilePath)) return null;

            var referencedFile = new ReferencedFile
            {
                Path = absoluteFilePath,
                IsLocal = true,
                IsTestFrameworkFile = pathSettings.IsTestFrameworkFile,
                IncludeInTestHarness = pathSettings.IncludeInTestHarness || chutzpahTestSettings.TestHarnessReferenceMode == TestHarnessReferenceMode.Normal,
                TemplateOptions = pathSettings.TemplateOptions
            };

            ChutzpahTracer.TraceInformation(
                "Added file '{0}' to referenced files. Local: {1}, IncludeInTestHarness: {2}",
                referencedFile.Path,
                referencedFile.IsLocal,
                referencedFile.IncludeInTestHarness);

            referencedFiles.Add(referencedFile);
            discoveredPaths.Add(referencedFile.Path); // Remmember this path to detect reference loops


            ChutzpahTracer.TraceInformation("Processing referenced file '{0}' for expanded references", absoluteFilePath);
            if (pathSettings.ExpandReferenceComments)
            {
                referencedFile.ReferencedFiles = ExpandNestedReferences(discoveredPaths, definition, absoluteFilePath, chutzpahTestSettings);
            }

            return referencedFile;
        }
Esempio n. 3
0
        private void ProcessFilePathAsReference(
            HashSet <string> discoveredPaths,
            IFrameworkDefinition definition,
            string relativeProcessingPath,
            ChutzpahTestSettingsFile chutzpahTestSettings,
            string referencePath,
            List <ReferencedFile> referencedFiles,
            ReferencePathSettings pathSettings)
        {
            ChutzpahTracer.TraceInformation("Investigating reference file path '{0}'", referencePath);

            // Check test settings and adjust the path if it is rooted (e.g. /some/path)
            referencePath = AdjustPathIfRooted(chutzpahTestSettings, referencePath);

            var    referenceUri      = new Uri(referencePath, UriKind.RelativeOrAbsolute);
            string referenceFileName = Path.GetFileName(referencePath);

            //  Ignore test runner, since we use our own.
            if (definition.ReferenceIsDependency(referenceFileName, chutzpahTestSettings))
            {
                ChutzpahTracer.TraceInformation(
                    "Ignoring reference file '{0}' as a duplicate reference to {1}",
                    referenceFileName,
                    definition.FrameworkKey);
                return;
            }

            var isRelativeUri = !referenceUri.IsAbsoluteUri;

            // If this either a relative uri or a file uri
            if (isRelativeUri || referenceUri.IsFile)
            {
                var relativeProcessingPathFolder = fileSystem.FolderExists(relativeProcessingPath)
                    ? relativeProcessingPath
                    : Path.GetDirectoryName(relativeProcessingPath);
                string relativeReferencePath = Path.Combine(relativeProcessingPathFolder, referencePath);

                // Check if reference is a file
                string absoluteFilePath = fileProbe.FindFilePath(relativeReferencePath);
                if (absoluteFilePath != null)
                {
                    VisitReferencedFile(absoluteFilePath, definition, discoveredPaths, referencedFiles, chutzpahTestSettings, pathSettings);
                    return;
                }

                // Check if reference is a folder
                string absoluteFolderPath = fileProbe.FindFolderPath(relativeReferencePath);
                if (absoluteFolderPath != null)
                {
                    var includePatterns = pathSettings.Includes.Select(x => UrlBuilder.NormalizeFilePath(x)).ToList();
                    var excludePatterns = pathSettings.Excludes.Select(x => UrlBuilder.NormalizeFilePath(x)).ToList();

                    // Find all files in this folder including sub-folders. This can be ALOT of files.
                    // Only a subset of these files Chutzpah might understand so many of these will be ignored.
                    var childFiles = fileSystem.GetFiles(absoluteFolderPath, "*.*", SearchOption.AllDirectories);
                    var validFiles = from file in childFiles
                                     let normalizedFile = UrlBuilder.NormalizeFilePath(file)
                                                          where !fileProbe.IsTemporaryChutzpahFile(file) &&
                                                          (!includePatterns.Any() || includePatterns.Any(pat => NativeImports.PathMatchSpec(normalizedFile, pat))) &&
                                                          (!excludePatterns.Any() || !excludePatterns.Any(pat => NativeImports.PathMatchSpec(normalizedFile, pat)))
                                                          select file;

                    validFiles.ForEach(file => VisitReferencedFile(file, definition, discoveredPaths, referencedFiles, chutzpahTestSettings, pathSettings));

                    return;
                }

                // At this point we know that this file/folder does not exist!
                ChutzpahTracer.TraceWarning("Referenced file '{0}' which was resolved to '{1}' does not exist", referencePath, relativeReferencePath);
            }
            else if (referenceUri.IsAbsoluteUri)
            {
                var referencedFile = new ReferencedFile
                {
                    Path    = referencePath,
                    IsLocal = false,
                    IncludeInTestHarness = true,
                    IsTestFrameworkFile  = pathSettings.IsTestFrameworkFile,
                    TemplateOptions      = pathSettings.TemplateOptions
                };

                ChutzpahTracer.TraceInformation(
                    "Added file '{0}' to referenced files. Local: {1}, IncludeInTestHarness: {2}",
                    referencedFile.Path,
                    referencedFile.IsLocal,
                    referencedFile.IncludeInTestHarness);
                referencedFiles.Add(referencedFile);
            }
        }
        private void ProcessFilePathAsReference(
            HashSet<string> discoveredPaths,
            IFrameworkDefinition definition,
            string relativeProcessingPath,
            ChutzpahTestSettingsFile chutzpahTestSettings,
            string referencePath,
            List<ReferencedFile> referencedFiles,
            ReferencePathSettings pathSettings)
        {
            ChutzpahTracer.TraceInformation("Investigating reference file path '{0}'", referencePath);

            // Check test settings and adjust the path if it is rooted (e.g. /some/path)
            referencePath = AdjustPathIfRooted(chutzpahTestSettings, referencePath);

            var referenceUri = new Uri(referencePath, UriKind.RelativeOrAbsolute);
            string referenceFileName = Path.GetFileName(referencePath);

            //  Ignore test runner, since we use our own.
            if (definition.ReferenceIsDependency(referenceFileName, chutzpahTestSettings))
            {
                ChutzpahTracer.TraceInformation(
                    "Ignoring reference file '{0}' as a duplicate reference to {1}",
                    referenceFileName,
                    definition.FrameworkKey);
                return;
            }

            var isRelativeUri = !referenceUri.IsAbsoluteUri;

            // If this either a relative uri or a file uri 
            if (isRelativeUri || referenceUri.IsFile)
            {
                var relativeProcessingPathFolder = fileSystem.FolderExists(relativeProcessingPath)
                    ? relativeProcessingPath
                    : Path.GetDirectoryName(relativeProcessingPath);
                string relativeReferencePath = Path.Combine(relativeProcessingPathFolder, referencePath);

                // Check if reference is a file
                string absoluteFilePath = fileProbe.FindFilePath(relativeReferencePath);
                if (absoluteFilePath != null)
                {
                    VisitReferencedFile(absoluteFilePath, definition, discoveredPaths, referencedFiles, chutzpahTestSettings, pathSettings);
                    return;
                }

                // Check if reference is a folder
                string absoluteFolderPath = fileProbe.FindFolderPath(relativeReferencePath);
                if (absoluteFolderPath != null)
                {
                    var includePatterns = pathSettings.Includes.Select(x => FileProbe.NormalizeFilePath(x)).ToList();
                    var excludePatterns = pathSettings.Excludes.Select(x => FileProbe.NormalizeFilePath(x)).ToList();

                    // Find all files in this folder including sub-folders. This can be ALOT of files.
                    // Only a subset of these files Chutzpah might understand so many of these will be ignored.
                    var childFiles = fileSystem.GetFiles(absoluteFolderPath, "*.*", SearchOption.AllDirectories);
                    var validFiles = from file in childFiles
                        let normalizedFile = FileProbe.NormalizeFilePath(file)
                        where !fileProbe.IsTemporaryChutzpahFile(file)
                        && (!includePatterns.Any() || includePatterns.Any(pat => NativeImports.PathMatchSpec(normalizedFile, pat)))
                        && (!excludePatterns.Any() || !excludePatterns.Any(pat => NativeImports.PathMatchSpec(normalizedFile, pat)))
                        select file;

                    validFiles.ForEach(file => VisitReferencedFile(file, definition, discoveredPaths, referencedFiles, chutzpahTestSettings, pathSettings));

                    return;
                }

                // At this point we know that this file/folder does not exist!
                ChutzpahTracer.TraceWarning("Referenced file '{0}' which was resolved to '{1}' does not exist", referencePath, relativeReferencePath);
            }
            else if (referenceUri.IsAbsoluteUri)
            {
                var referencedFile = new ReferencedFile
                {
                    Path = referencePath,
                    IsLocal = false,
                    IncludeInTestHarness = true,
                    IsTestFrameworkFile = pathSettings.IsTestFrameworkFile,
                    TemplateOptions = pathSettings.TemplateOptions
                };

                ChutzpahTracer.TraceInformation(
                    "Added file '{0}' to referenced files. Local: {1}, IncludeInTestHarness: {2}",
                    referencedFile.Path,
                    referencedFile.IsLocal,
                    referencedFile.IncludeInTestHarness);
                referencedFiles.Add(referencedFile);
            }
        }