Example #1
0
        /// <summary>
        /// Creates a subgraph including the provided packages and the packages they depend on
        /// </summary>
        /// <param name="targetPackages">Packages to use for slicing</param>
        /// <param name="excludeNonExclusiveDependencies">When true, all dependencies shared with the packages outside of the subgraph will not be included</param>
        /// <returns>New graph which includes the requested packages and the dependencies</returns>
        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());
        }
        /// <summary>
        /// Removes package from a list of the configured packages
        /// </summary>
        /// <param name="packageId">Package to remove</param>
        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();
        }
        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 => new PackageFileInfo(x.ToString())));
                            }

                            var 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;
                }
            }
        }
Example #4
0
        /// <summary>
        /// Creates a subgraph including the provided packages and the packages which depend on them
        /// </summary>
        /// <param name="packages">Packages to use for slicing</param>
        /// <returns>New graph which includes the requested packages and the dependents</returns>
        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());
        }