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;
        }
        public override List<OutputEntry> Process(DependencyGraph graph, Library element)
        {
            var proj = element as Project;
            if (proj == null)
                return null;

            var result = new List<OutputEntry>();

            var same = graph.OutEdges(proj)
                .Where(d => filter(d, Matchers.NullReporter))
                .GroupBy(d => d.Target)
                .Where(g => g.Count() > 1);

            same.ForEach(g =>
            {
                var message = new OutputMessage();
                message.Append("The project ")
                    .Append(proj, OutputMessage.ProjInfo.Name)
                    .Append(" has multiple dependencies with ")
                    .Append(g.Key, OutputMessage.ProjInfo.Name);

                result.Add(new UniqueDependencyOutputEntry(Severity, message, this, g));
            });

            return result;
        }
        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();
        }
        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 Matches(LibraryMatcher test, Library proj, Matchers.Reporter reporter)
        {
            if (test(proj, (f, v, m) => reporter("Library " + f, v, m)))
                return true;

            if (proj.GroupElement != null && test(proj.GroupElement, (f, v, m) => reporter("Group " + f, v, m)))
                return true;

            return false;
        }
        private static List<Library> ComputeIndirectDeps(DependencyGraph graph, Library lib)
        {
            var indirectDeps = new List<Library>();

            var dfs = new DepthFirstSearchAlgorithm<Library, Dependency>(graph);
            dfs.SetRootVertex(lib);
            dfs.DiscoverVertex += indirectDeps.Add;
            dfs.Compute();

            return indirectDeps;
        }
        private GroupElement FindGroupElement(Library proj)
        {
            var configGroup = config.Groups.FirstOrDefault(g => g.Matches(proj, Matchers.NullReporter));
            if (configGroup == null)
                return null;

            usedGroups.Add(configGroup.Location);

            if (configGroup.Name == null)
                return null;

            Group group;
            if (!groups.TryGetValue(configGroup.Name, out group))
            {
                group = new Group(configGroup.Name);
                groups.Add(configGroup.Name, group);
            }

            return new GroupElement(group, configGroup.Location, proj);
        }
        private static string ToConsole(Library proj, OutputMessage.ProjInfo info)
        {
            switch (info)
            {
                case OutputMessage.ProjInfo.Name:
                {
                    return string.Join(" or ", proj.SortedNames);
                }
                case OutputMessage.ProjInfo.NameAndGroup:
                {
                    var result = ToConsole(proj, OutputMessage.ProjInfo.Name);

                    var group = proj.GroupElement;
                    if (group != null)
                        result = string.Format("{0} (in group {1})", result, group.Name);

                    return result;
                }
                case OutputMessage.ProjInfo.NameAndProjectPath:
                {
                    return string.Format("{0} ({1})", ToConsole(proj, OutputMessage.ProjInfo.Name), ToConsole(proj, OutputMessage.ProjInfo.ProjectPath));
                }
                case OutputMessage.ProjInfo.NameAndPath:
                {
                    if (proj.Paths.Any())
                        return string.Format("{0} ({1})", ToConsole(proj, OutputMessage.ProjInfo.Name), ToConsole(proj, OutputMessage.ProjInfo.Path));
                    else
                        return ToConsole(proj, OutputMessage.ProjInfo.Name);
                }
                case OutputMessage.ProjInfo.Path:
                {
                    if (proj.Paths.Any())
                        return string.Join(" or ", proj.Paths);
                    else
                        return ToConsole(proj, OutputMessage.ProjInfo.Name);
                }
                case OutputMessage.ProjInfo.ProjectPath:
                {
                    if (proj is Project)
                        return ((Project) proj).ProjectPath;
                    else
                        throw new InvalidDataException();
                }
                default:
                    throw new InvalidDataException();
            }
        }
        private void CreateLibraryReferences()
        {
            foreach (var tmp in refs.Where(r => r.Type == Dependency.Types.LibraryReference && !r.Source.Ignored))
            {
                var projRef = tmp;
                var proj = projRef.Source.Project;

                // Dummy reference for logs in case of errors
                var dep = Dependency.WithLibrary(proj, null, projRef.ReferenceLocation, projRef.ReferenceFilename);

                List<Library> found = null;

                if (projRef.ReferenceFilename != null)
                    found = FindLibraryByFilename(proj, dep, projRef.ReferenceFilename);

                if (projRef.ReferenceName != null && projRef.ReferenceLibraryName != null)
                    found = FindLibraryByNameAndLibraryName(proj, dep, projRef.ReferenceName, projRef.ReferenceLibraryName);

                if (projRef.ReferenceLibraryName != null)
                    found = FindLibraryByLibraryName(proj, dep, projRef.ReferenceLibraryName);

                if (projRef.ReferenceName != null)
                    found = FindLibraryByName(proj, dep, projRef.ReferenceName);

                if (found == null)
                {
                    var lib = new Library(projRef.ReferenceLibraryName ?? projRef.ReferenceName, projRef.ReferenceLanguages.EmptyIfNull());
                    if (projRef.ReferenceFilename != null)
                        lib.Paths.Add(projRef.ReferenceFilename);

                    if (!Ignore(lib))
                    {
                        AddLibrary(lib);
                        found = lib.AsList();
                    }
                }

                if (found == null || !found.Any())
                    continue;

                Merge(found, projRef);

                found.ForEach(target => dependencies.Add(dep.WithTarget(target)));
            }
        }
 public Element(Library project, ProjInfo projInfo)
 {
     Project = project;
     ProjInfo = projInfo;
     Text = null;
 }
 public Element(string text)
 {
     Text = text ?? "<null>";
     Project = null;
 }
 public OutputMessage Append(Library proj, ProjInfo info)
 {
     elements.Add(new Element(proj, info));
     return this;
 }
 public static string ProjectGlance(Library p)
 {
     return string.Join(" or ", p.SortedNames) + " (" + (p is Project ? "project" : "library") + (p.IsLocal ? " local" : "") + ")";
 }
        private void Add(Dictionary<string, HashSet<Library>> byName, Dictionary<string, HashSet<Library>> byFilename, Library lib)
        {
            foreach (var name in lib.Names)
                GetList(byName, name.ToLower())
                    .Add(lib);

            foreach (var name in lib.LibraryNames)
                GetList(byName, name.ToLower())
                    .Add(lib);

            foreach (var path in lib.Paths)
                GetList(byFilename, path.ToLower())
                    .Add(lib);

            all.Add(lib);
        }
 public bool Contais(Library lib)
 {
     return all.Contains(lib);
 }
        private bool AreTheSame(Library a1, Library a2)
        {
            if (a1.Equals(a2))
                return true;

            // Handle Proj vs Library
            if (!(a1 is Project) || !(a2 is Project))
                return a1.LibraryName.Equals(a2.LibraryName);

            return false;
        }
Beispiel #17
0
 public virtual List<OutputEntry> Process(DependencyGraph graph, Library proj)
 {
     return null;
 }
Beispiel #18
0
		protected bool Equals(Library other)
		{
			return string.Equals(LibraryName, other.LibraryName);
		}
        private bool AreFromDifferentGroups(Library p1, Library p2)
        {
            if (p1.GroupElement == null || p2.GroupElement == null)
                return true;

            return p1.GroupElement.Name != p2.GroupElement.Name;
        }
 private void AppendProject(DotStringBuilder result, Library library)
 {
     result.AppendNode(library, library.Name, "shape", library is Project ? "box" : "ellipse", "color",
         GetColor(warnings.Where(w => w.Projects.Contains(library))));
 }
        private bool Ignore(Library library)
        {
            UpdateIsLocal(library);

            foreach (var ignore in config.Ignores)
            {
                if (ignore.Matches(library, Matchers.NullReporter))
                {
                    usedIgnores.Add(ignore.Location);
                    return true;
                }
            }
            return false;
        }
 private void UpdateIsLocal(Library lib)
 {
     lib.IsLocal = IsLocal(config, lib);
 }
 private static bool IsLocal(Config config, Library lib)
 {
     if (lib is Project)
         return config.Inputs.Any(input => PathUtils.PathMatches(((Project) lib).ProjectPath, input));
     else
         return config.Inputs.Any(input => lib.Paths.Any(p => PathUtils.PathMatches(p, input)));
 }
        private void AddLibrary(Library newLibrary)
        {
            var others = new HashSet<Library>();

            var otherByName = db.FindByName(newLibrary.Name);
            if (otherByName != null)
                others.AddRange(otherByName);

            var otherByLibName = db.FindByLibraryName(newLibrary.LibraryName);
            if (otherByLibName != null)
                others.AddRange(otherByLibName);

            var sameLibraries = others.Where(p => AreTheSame(p, newLibrary))
                .ToList();
            if (sameLibraries.Any())
            {
                sameLibraries.Add(newLibrary);

                var msg = new StringBuilder();
                msg.Append("There are ")
                    .Append(sameLibraries.Count)
                    .Append(" projects that are the same:");
                sameLibraries.ForEach(p => msg.Append("\n  - ")
                    .Append(((Project) p).ProjectPath));

                throw new ConfigException(msg.ToString());
            }

            db.AddLibrary(newLibrary);
        }
 public void AddLibrary(Library library)
 {
     Add(librariesByName, librariesByFilename, library);
 }
 protected string GetName(Library l)
 {
     return string.Join(" or ", l.SortedNames);
 }