private void OutputReferences(Output result, DependencyGraph graph, Library lib, string type)
        {
            result.AppendLine(GetName(lib) + ":");

            var directDeps = new HashSet<Library>(graph.OutEdges(lib)
                .Select(d => d.Target));

            result.IncreaseIndent();
            result.AppendLine("Direct " + type + ":");

            result.IncreaseIndent();
            Output(result, directDeps);
            result.DecreaseIndent();

            result.DecreaseIndent();

            if (directDeps.Any())
            {
                var indirectDeps = ComputeIndirectDeps(graph, lib)
                    .Where(d => !directDeps.Contains(d))
            // ReSharper disable once PossibleUnintendedReferenceComparison
                    .Where(d => d != lib);

                result.IncreaseIndent();
                result.AppendLine("Indirect " + type + ":");

                result.IncreaseIndent();
                Output(result, indirectDeps);
                result.DecreaseIndent();

                result.DecreaseIndent();
            }

            result.AppendLine();
        }
        private bool OutputPath(Output result, DependencyGraph graph, Library source, Library target)
        {
            var tryGetPaths = graph.ShortestPathsDijkstra(e => 1, source);
            IEnumerable<Dependency> path;
            if (!tryGetPaths(target, out path))
                return false;

            try
            {
                result.AppendLine("Path between {0} and {1}:", GetName(source), GetName(target));
                result.IncreaseIndent();

                Output.LineOutput line = result.StartLine();

                line.Append(GetName(source));
                foreach (Dependency edge in path)
                    line.Append(" -> ")
                        .Append(GetName(edge.Target));

                line.EndLine();
            }
            finally
            {
                result.DecreaseIndent();
                result.AppendLine();
            }

            return true;
        }
예제 #3
0
        private void OutputInfo(Output result, Library lib)
        {
            result.AppendLine(GetName(lib) + ":");
            result.IncreaseIndent();

            var proj = lib as Project;
            if (proj != null)
            {
                WriteProperty(result, "Type", "Project");
                WriteProperty(result, "Project name", proj.ProjectName);
                WriteProperty(result, "Library name", proj.LibraryName);
                WriteProperty(result, "Project path", proj.ProjectPath);
                WriteProperty(result, "GUID", proj.Guid != null ? proj.Guid.ToString() : "missing");
            }
            else
            {
                WriteProperty(result, "Type", "Library");
                WriteProperty(result, "Library name", lib.LibraryName);
            }

            if (lib.GroupElement != null)
                WriteProperty(result, "Group", lib.GroupElement.Name);

            lib.Languages.ForEach(p => WriteProperty(result, "Language", p));

            var projectPath = (lib is Project ? ((Project) lib).ProjectPath : null);
            lib.Paths.Where(p => p != projectPath)
                .ForEach(p => WriteProperty(result, "Path", p));

            result.DecreaseIndent();
            result.AppendLine();
        }
        protected override void InternalHandle(Output result, string args, DependencyGraph graph)
        {
            var projctsFiltered = FilterLibs(graph, args);

            IDictionary<Library, int> components;
            graph.StronglyConnectedComponents(out components);

            var circularDependencies = components.Select(c => new { Proj = c.Key, Group = c.Value })
                .GroupBy(c => c.Group)
                .Where(g => g.Count() > 1);

            bool found = false;
            foreach (var g in circularDependencies)
            {
                var libs = g.Select(i => i.Proj)
                    .ToList();

                var projsSet = new HashSet<Library>(libs);

                if (!projsSet.Intersect(projctsFiltered)
                    .Any())
                    continue;

                found = true;

                libs.Sort(Library.NaturalOrdering);

                result.AppendLine("Circular dependency:");
                result.IncreaseIndent();

                foreach (var lib in libs)
                {
                    var proj = lib as Project;
                    if (proj != null)
                        result.AppendLine("{0} (project path: {1})", GetName(proj), proj.ProjectPath);
                    else
                        result.AppendLine(GetName(lib));
                }

                result.DecreaseIndent();
                result.AppendLine();
            }

            if (!found)
                result.AppendLine("No circular dependency found");
        }
예제 #5
0
        public static string GroupsToConsole(Output result, IEnumerable<Library> projects)
        {
            var groups = projects.GroupBy(p => p.GroupElement)
                .ToList();

            groups.Sort((e1, e2) =>
            {
                GroupElement g1 = e1.Key;
                GroupElement g2 = e2.Key;

                if (Equals(g1, g2))
                    return 0;

                if (g1 == null)
                    return 1;

                if (g2 == null)
                    return -1;

                return string.Compare(g1.Name, g2.Name, StringComparison.CurrentCultureIgnoreCase);
            });

            groups.ForEach(g =>
            {
                result.AppendLine((g.Key != null ? g.Key.Name : "Without a group") + ":");

                result.IncreaseIndent();

                List<Library> projs = g.ToList();
                projs.Sort(Library.NaturalOrdering);
                projs.ForEach(p => result.AppendLine(ProjectGlance(p)));

                result.DecreaseIndent();
                result.AppendLine();
            });

            return result.ToString();
        }