예제 #1
0
        public void IncludeGraphs([NotNull, ItemNotNull] IEnumerable <string> namesToBeIncluded, bool removeIncluded)
        {
            IEnumerable <WorkingGraph> toBeIncluded = FindGraphs(namesToBeIncluded.Any() ? namesToBeIncluded : new[] { "2" });

            if (toBeIncluded != null)
            {
                if (toBeIncluded.Contains(CurrentGraph))
                {
                    Log.WriteError("Cannot add current graph to itself");
                }
                foreach (var g in toBeIncluded)
                {
                    CurrentGraph.AddDependencies(g.VisibleDependencies);
                    if (removeIncluded)
                    {
                        _workingGraphs.Remove(g);
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Extract file patterns from args and read files
        /// </summary>
        /// <param name="includes"></param>
        /// <param name="excludes"></param>
        /// <param name="assemblyName"></param>
        /// <param name="readerFactoryClassNameOrNull">if null, detect from reader class from first extension in patterns</param>
        public void ReadFiles(IEnumerable <string> includes, IEnumerable <string> excludes, string assemblyName,
                              [CanBeNull] string readerFactoryClassNameOrNull)
        {
            IReaderFactory readerFactory;

            if (readerFactoryClassNameOrNull == null)
            {
                IEnumerable <string> allFileNames = includes.Concat(excludes);
                readerFactory = GetSuitableInternalReader(assemblyName, allFileNames);
                if (readerFactory == null)
                {
                    throw new ApplicationException($"Found no reader for files {string.Join(",", allFileNames)}");
                }
            }
            else
            {
                readerFactory = GetOrCreatePlugin <IReaderFactory>(assemblyName, readerFactoryClassNameOrNull);
            }

            InputFilesOrTestDataSpecified = true;

            IEnumerable <string> extensionsForDirectoryReading = readerFactory.SupportedFileExtensions;

            IEnumerable <string> includedFilenames = includes.SelectMany(p => Option.ExpandFilePatternFileNames(p, extensionsForDirectoryReading));
            IEnumerable <string> excludedFilenames = excludes.SelectMany(p => Option.ExpandFilePatternFileNames(p, extensionsForDirectoryReading));

            string[] fileNames = includedFilenames
                                 .Except(excludedFilenames)
                                 .Distinct()
                                 .OrderBy(s => s)
                                 .ToArray();

            if (Log.IsVerboseEnabled)
            {
                Log.WriteInfo("Files to be read");
                foreach (var f in fileNames)
                {
                    Log.WriteInfo("  " + f);
                }
            }

            IDependencyReader[] readers = fileNames.Select(fileName => readerFactory.CreateReader(fileName, needsOnlyItemTails: false /*???*/)).ToArray();

            foreach (var r in readers)
            {
                r.SetReadersInSameReadFilesBeforeReadDependencies(readers);
            }

            // Currently, we add the previous set of dependencies to the newly read ones; with the introduction of a useful "working set" concept, this should vanish ...
            var readSet = new List <Dependency>();

            foreach (var r in readers)
            {
                Dependency[] dependencies = r.ReadDependencies(CurrentGraph, 0, IgnoreCase).ToArray();
                if (!dependencies.Any())
                {
                    Log.WriteWarning("No dependencies found in " + r.FullFileName);
                }

                readSet.AddRange(dependencies);
            }
            if (_autoGraphsForRead > 0)
            {
                CreateWorkingGraph(readerFactory.GetType().Name, GraphCreationType.AutoRead, readSet);
                RemoveSuperfluousGraphs(_autoGraphsForRead, GraphCreationType.AutoRead);
            }
            else
            {
                CurrentGraph.AddDependencies(readSet);
            }

            Log.WriteInfo($"... now {CurrentGraph.DependencyCount} dependencies");
        }