Пример #1
0
        public static IGraphNode <LibraryDescription> Build([NotNull] IList <LibraryDescription> libraries,
                                                            [NotNull] Runtime.Project project)
        {
            var libDictionary = libraries.ToDictionary(desc => desc.Identity);

            LibraryDescription root;

            if (!libDictionary.TryGetValue(new Library {
                Name = project.Name, Version = project.Version
            }, out root))
            {
                throw new InvalidOperationException(string.Format("Failed to retrieve {0} of project {1} - {2}", typeof(LibraryDependency).Name, project.Name, project.Version));
            }

            // build a tree of LibraryDescriptions of the given project root
            return(DepthFirstGraphTraversal.PostOrderWalk <LibraryDescription, IGraphNode <LibraryDescription> >(
                       node: root,
                       getChildren: node =>
            {
                if (node.Resolved)
                {
                    return node.Dependencies.Select(dependency => libDictionary[dependency.Library]);
                }
                else
                {
                    return Enumerable.Empty <LibraryDescription>();
                }
            },
                       visitNode: (node, children) =>
            {
                return new GraphNode <LibraryDescription>(node, children);
            }));
        }
Пример #2
0
        public static IGraphNode <LibraryDescription> Build([NotNull] IEnumerable <LibraryDescription> libraries,
                                                            [NotNull] Runtime.Project project)
        {
            var root = libraries.FirstOrDefault(p => string.Equals(p.Identity.Name, project.Name));

            if (root == null)
            {
                throw new InvalidOperationException(string.Format("Failed to retrieve {0} of project {1} - {2}", typeof(LibraryDependency).Name, project.Name, project.Version));
            }

            // build a tree of LibraryDescriptions of the given project root
            return(DepthFirstGraphTraversal.PostOrderWalk <LibraryDescription, IGraphNode <LibraryDescription> >(
                       node: root,
                       getChildren: node =>
            {
                if (node.Resolved)
                {
                    return node.Dependencies.Select(dependency => dependency.Library);
                }
                else
                {
                    return Enumerable.Empty <LibraryDescription>();
                }
            },
                       visitNode: (node, children) =>
            {
                return new GraphNode <LibraryDescription>(node, children);
            }));
        }
Пример #3
0
        public static IGraphNode<LibraryDependency> Build(
            IEnumerable<LibraryDescription> libraries,
            Runtime.Project project)
        {
            if (libraries == null)
            {
                throw new ArgumentNullException(nameof(libraries));
            }

            if (project == null)
            {
                throw new ArgumentNullException(nameof(project));
            }

            var root = new LibraryDependency
            {
                Library = libraries.FirstOrDefault(p => string.Equals(p.Identity.Name, project.Name)),
                LibraryRange = null
            };

            if (root.Library == null)
            {
                throw new InvalidOperationException($"Failed to retrieve {nameof(LibraryDependency)} of project {project.Name}/{project.Version}");
            }

            // build a tree of LibraryDescriptions of the given project root
            return DepthFirstGraphTraversal.PostOrderWalk<LibraryDependency, IGraphNode<LibraryDependency>>(
                node: root,
                getChildren: node =>
                {
                    if (node.Library.Resolved)
                    {
                        return node.Library.Dependencies;
                    }
                    else
                    {
                        return Enumerable.Empty<LibraryDependency>();
                    }
                },
                visitNode: (node, children) =>
                {
                    return new GraphNode<LibraryDependency>(node, children);
                });
        }
Пример #4
0
        private bool VisitLibrary(IGraphNode <LibraryDescription> node,
                                  IEnumerable <IGraphNode <LibraryDescription> > ancestors,
                                  ISet <LibraryDescription> visitedLibraries)
        {
            if (visitedLibraries.Add(node.Item))
            {
                foreach (var loadableAssembly in node.Item.Assemblies)
                {
                    AddDependencySource(_dependencyPackageSources, loadableAssembly, node.Item.Identity.Name);

                    DepthFirstGraphTraversal.PreOrderWalk(
                        root: loadableAssembly,
                        visitNode: VisitAssembly,
                        getChildren: GetAssemblyDependencies);
                }

                return(true);
            }

            return(false);
        }
Пример #5
0
 public IGraphNode <Library> Build(Library root)
 {
     return(DepthFirstGraphTraversal.PostOrderWalk <Library, IGraphNode <Library> >(
                node: root,
                getChildren: node =>
     {
         LibraryDescription desc;
         if (_libDictionary.TryGetValue(node, out desc))
         {
             return desc.Dependencies.Select(dep => dep.Library);
         }
         else
         {
             return Enumerable.Empty <Library>();
         }
     },
                visitNode: (node, children) =>
     {
         return new GraphNode <Library>(node, children);
     }));
 }
Пример #6
0
        private bool VisitLibrary(IGraphNode <Library> node,
                                  IEnumerable <IGraphNode <Library> > ancestors,
                                  ISet <Library> visitedLibraries,
                                  ISet <string> assemblies)
        {
            if (visitedLibraries.Add(node.Item))
            {
                LibraryDescription desc;
                if (_libDictionary.TryGetValue(node.Item, out desc))
                {
                    foreach (var loadableAssembly in desc.LoadableAssemblies)
                    {
                        DepthFirstGraphTraversal.PreOrderWalk(
                            root: loadableAssembly,
                            visitNode: (assemblyNode, assemblyAncestors) => VisitAssembly(assemblyNode, assemblyAncestors, assemblies),
                            getChildren: GetAssemblyDependencies);
                    }
                }

                return(true);
            }

            return(false);
        }