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;
        }
        public override List<OutputEntry> Process(DependencyGraph graph)
        {
            var result = new List<OutputEntry>();

            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);

            foreach (var g in circularDependencies)
            {
                var projs = g.Select(i => i.Proj)
                    .ToList();
                projs.Sort(Library.NaturalOrdering);

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

                var deps = graph.Edges.Where(e => projsSet.Contains(e.Source) && projsSet.Contains(e.Target));

                var message = new OutputMessage();
                message.Append("Circular dependency found between projects ");

                var first = true;
                foreach (var proj in projs)
                {
                    if (first)
                        first = false;
                    else
                        message.Append(", ");

                    message.Append(proj, OutputMessage.ProjInfo.Name);
                }

                result.Add(new CircularDependencyRuleMatch(Severity, message, this, deps));
            }

            return result;
        }
        public override List<OutputEntry> Process(DependencyGraph graph)
        {
            var result = new List<OutputEntry>();

            graph.Edges.Where(d => filter(d, Matchers.NullReporter))
                .Where(e => e.Source.Equals(e.Target))
                .GroupBy(e => e.Source)
                .ForEach(deps =>
                {
                    var message = new OutputMessage();
                    message.Append(deps.Key, OutputMessage.ProjInfo.Name)
                        .Append(" depends on itself");
                    result.Add(new SelfDependencyRuleMatch(Severity, message, this, deps));
                });

            return result;
        }
Ejemplo n.º 4
0
        public override OutputEntry Process(Dependency dep)
        {
            var fields = new List<ProcessedField>();

            if (!Dependency(dep, (f, v, m) => fields.Add(new ProcessedField("Dependency " + f, v, m))))
                return null;

            if (!Matches(Source, dep.Source, (f, v, m) => fields.Add(new ProcessedField("Source " + f, v, m))))
                return null;

            if (!Matches(Target, dep.Target, (f, v, m) => fields.Add(new ProcessedField("Target " + f, v, m))))
                return null;

            var messsage = new OutputMessage();
            messsage.Append("Dependency between ")
                .Append(dep.Source, OutputMessage.ProjInfo.Name)
                .Append(" and ")
                .Append(dep.Target, OutputMessage.ProjInfo.Name)
                .Append(Allow ? "" : " not")
                .Append(" allowed");

            return new DependencyRuleMatch(Allow, "Dependency", Severity, messsage, this, dep.AsList(), fields);
        }
        public override List<OutputEntry> Process(DependencyGraph graph)
        {
            var result = new List<OutputEntry>();

            var same = graph.Vertices.OfType<Project>()
                .Where(v => filter(v))
                .GroupBy(v => id(v))
                .Where(g => g.Count() > 1);
            same.ForEach(g =>
            {
                var projs = g.ToList();

                var message = new OutputMessage();
                message.Append(projs.Count())
                    .Append(" projects ")
                    .Append(description(projs.First()))
                    .Append(" found");

                result.Add(new UniqueProjectOutputEntry(Severity, message, this, projs));
            });

            return result;
        }
        private void WarnIfSimilarFound(List<Library> result, Project proj, Dependency dep, string filename, string refName)
        {
            if (result == null || !result.Any())
                return;

            var message = new OutputMessage().Append("The project ")
                .Append(proj, OutputMessage.ProjInfo.Name)
                .Append(" references the project ")
                .Append(filename)
                .Append(" but it could not be loaded. Using project")
                .Append(result.Count > 1 ? "s" : "")
                .Append(" ")
                .Append(refName)
                .Append(" instead:");

            if (result.Count == 1)
                result.ForEach(p => message.Append(result.First(), OutputMessage.ProjInfo.ProjectPath));
            else
                result.ForEach(p => message.Append("\n  - ")
                    .Append(p, OutputMessage.ProjInfo.ProjectPath));

            warnings.Add(new LoadingOutputEntry("Only similar project found", message, result.Select(dep.WithTarget)
                .ToArray()));
        }
        private OutputEntry CreateMultipleReferencesWarning(List<Library> candidates, Project proj, Dependency dep, string refName)
        {
            var message = new OutputMessage().Append("The project ")
                .Append(proj, OutputMessage.ProjInfo.NameAndProjectPath)
                .Append(" references the project ")
                .Append(refName)
                .Append(", but there are ")
                .Append(candidates.Count)
                .Append(" projects that match:");

            candidates.ForEach(c => message.Append("\n  - ")
                .Append(c, OutputMessage.ProjInfo.ProjectPath));
            message.Append("\nMultiple dependencies will be created.");

            return new LoadingOutputEntry("Multiple projects found", message, candidates.Select(dep.WithTarget)
                .ToArray());
        }