示例#1
0
        public void TwoRootPackagesAndSharedDependencyTest()
        {
            var builder = new PackageGraphBuilder();

            builder.Append(_packageA, new[] { _packageC });
            builder.Append(_packageB, new[] { _packageC });
            var graph = builder.Build();

            graph.Count.Should().Be(3);
            graph.Packages.Count.Should().Be(2);

            var packageA = graph.Packages.First(x => x.Package.Id == "A");

            packageA.Dependencies.First().Package.Id.Should().Be("C");

            var packageB = graph.Packages.First(x => x.Package.Id == "B");

            packageB.Dependencies.First().Package.Id.Should().Be("C");

            var list = graph.FlattenLeastDependentFirst().ToArray();

            list[0].Id.Should().Be("C");

            list = graph.FlattenMostDependentFirst().ToArray();
            list[2].Id.Should().Be("C");
        }
        public void RemovePackage(PackageId packageId)
        {
            var packageInfo = ProductPackages.FirstOrDefault(x => x.Configuration.Id.IsSamePackage(packageId));

            if (packageInfo != null)
            {
                ProductPackages.Remove(packageInfo);
            }

            var allPackages = Packages.GetNodes(new PackageId[] {});
            var builder     = new PackageGraphBuilder();

            foreach (var packageNode in allPackages)
            {
                if (packageNode.Package.IsSamePackage(packageId))
                {
                    continue;
                }

                builder.Append(packageNode.Package,
                               packageNode.Dependencies.Where(x => !x.Package.IsSamePackage(packageId)).Select(p => p.Package));
            }

            Packages = builder.Build();
        }
示例#3
0
        public IPackageGraph SliceWithDependencies(ICollection <PackageId> targetPackages, bool excludeNonExclusiveDependencies)
        {
            var collectedPackages = new List <IPackageGraphNode>();
            var marks             = new Dictionary <PackageId, Mark>();

            foreach (var package in _packages)
            {
                MarkPackages(package, targetPackages, collectedPackages, marks, Mark.DoNotInclude,
                             excludeNonExclusiveDependencies);
            }

            var graphBuilder = new PackageGraphBuilder();

            foreach (var collectedPackage in collectedPackages)
            {
                var mark = marks[collectedPackage.Package];
                if (mark == Mark.Include || mark == Mark.Tentative)
                {
                    graphBuilder.Append(collectedPackage.Package,
                                        collectedPackage.Dependencies.Where(p =>
                    {
                        Mark packageMark;
                        return(marks.TryGetValue(p.Package, out packageMark) &&
                               (packageMark == Mark.Include || packageMark == Mark.Tentative));
                    }).Select(x => x.Package));
                }
            }

            return(graphBuilder.Build());
        }
        private void TryParseConfiguration()
        {
            if (!File.Exists(_configPath))
            {
                return;
            }

            using (var stream = File.OpenText(_configPath))
            {
                var reader = new JsonTextReader(stream);
                _jsonObject = JObject.Load(reader);

                JToken token;
                if (_jsonObject.TryGetValue(_packagesTag, out token))
                {
                    var builder = new PackageGraphBuilder();
                    foreach (var package in token.Children())
                    {
                        var packageProp   = (JProperty)package;
                        var packageObject = (JObject)packageProp.Value;

                        var packageId = new PackageId(packageProp.Name);
                        var info      = new ProductPackageInfo();

                        if (packageObject.TryGetValue(_packageTag, out token))
                        {
                            var packageConfigObject = (JObject)token;
                            info.Configuration = new PackageConfiguration(packageId, packageConfigObject);

                            if (packageObject.TryGetValue(_filesTag, out token) && token.HasValues)
                            {
                                var array = (JArray)token;
                                info.Files.AddRange(array.Select(x => x.ToString()));
                            }

                            List <PackageId> dependencies = new List <PackageId>();
                            if (packageObject.TryGetValue(_dependenciesTag, out token) && token.HasValues)
                            {
                                var array = (JArray)token;
                                dependencies.AddRange(array.Select(x => new PackageId(x.ToString())));
                            }

                            builder.Append(packageId, dependencies);
                            ProductPackages.Add(info);
                        }
                    }

                    Packages            = builder.Build();
                    IsProductConfigured = true;
                }
            }
        }
示例#5
0
        public void OneRootPackageTest()
        {
            var builder = new PackageGraphBuilder();

            builder.Append(_packageA, new PackageId[] { });
            var graph = builder.Build();

            graph.Count.Should().Be(1);

            var list = graph.FlattenLeastDependentFirst();

            list.Count.Should().Be(1);

            list = graph.FlattenMostDependentFirst();
            list.Count.Should().Be(1);
        }
示例#6
0
        private IPackageGraph BuildGraphForSlicing()
        {
            var builder = new PackageGraphBuilder();

            builder.Append(_packageA, new[] { _packageC, _packageD });
            builder.Append(_packageB, new[] { _packageE, _packageJ });
            builder.Append(_packageC, new[] { _packageI });
            builder.Append(_packageD, new[] { _packageF });
            builder.Append(_packageE, new[] { _packageF, _packageG });
            builder.Append(_packageF, new[] { _packageJ, _packageH });
            builder.Append(_packageG, new[] { _packageH });
            builder.Append(_packageJ, new PackageId[] { });
            builder.Append(_packageI, new PackageId[] { });

            return(builder.Build());
        }
示例#7
0
        public void TwoRootPackagesTest()
        {
            var builder = new PackageGraphBuilder();

            builder.Append(_packageA, new PackageId[] { });
            builder.Append(_packageB, new PackageId[] { });
            var graph = builder.Build();

            graph.Count.Should().Be(2);
            graph.Packages.Count(x => x.Package.Id == "A").Should().Be(1);
            graph.Packages.Count(x => x.Package.Id == "B").Should().Be(1);

            var list = graph.FlattenLeastDependentFirst();

            list.Count.Should().Be(2);

            list = graph.FlattenMostDependentFirst();
            list.Count.Should().Be(2);
        }
示例#8
0
        public IPackageGraph SliceWithDependents(ICollection <PackageId> packages)
        {
            var nodes = GetNodes(packages);

            var collectedNodes = new List <IPackageGraphNode>();

            foreach (var node in nodes)
            {
                CollectNode(node, collectedNodes);
            }

            var graphBuilder = new PackageGraphBuilder();

            foreach (var collectedNode in collectedNodes)
            {
                graphBuilder.Append(collectedNode.Package,
                                    collectedNode.Dependencies.Where(x => collectedNodes.Contains(x)).Select(d => d.Package));
            }
            return(graphBuilder.Build());
        }
示例#9
0
        public void PackageHierarhyTest()
        {
            var builder = new PackageGraphBuilder();

            builder.Append(_packageA, new[] { _packageB, _packageC });
            builder.Append(_packageB, new[] { _packageD, _packageE });
            builder.Append(_packageC, new[] { _packageF });
            builder.Append(_packageD, new PackageId[] { });
            builder.Append(_packageE, new[] { _packageF });
            builder.Append(_packageF, new[] { _packageG });
            builder.Append(_packageG, new PackageId[] { });
            builder.Append(_packageH, new PackageId[] { });
            var graph = builder.Build();

            graph.Count.Should().Be(8);
            graph.Packages.Count.Should().Be(2);

            var packageA1 = graph.Packages.First(x => x.Package.Id == "A");

            packageA1.Dependencies.Count.Should().Be(2);

            packageA1.Dependencies.First(x => x.Package.Id == "B").Dependencies.Count.Should().Be(2);
            packageA1.Dependencies.First(x => x.Package.Id == "C").Dependencies.Count.Should().Be(1);

            var list = graph.FlattenMostDependentFirst().ToArray();

            list[0].Id.Should().BeOneOf("A", "H");
            list[1].Id.Should().BeOneOf("A", "H");
            list[2].Id.Should().BeOneOf("B", "C");
            list[3].Id.Should().BeOneOf("B", "C");
            list[4].Id.Should().Be("E");
            list[5].Id.Should().Be("F");

            list = graph.FlattenLeastDependentFirst().ToArray();
            list[0].Id.Should().BeOneOf("D", "G");
            list[1].Id.Should().BeOneOf("D", "G");
            list[2].Id.Should().Be("F");
            list[3].Id.Should().Be("E");
        }