Beispiel #1
0
        private static List <PackageDependencySet> ReadDependencySets(XElement dependenciesElement)
        {
            if (!dependenciesElement.HasElements)
            {
                return(new List <PackageDependencySet>());
            }

            // Disallow the <dependencies> element to contain both <dependency> and
            // <group> child elements. Unfortunately, this cannot be enforced by XSD.
            if (dependenciesElement.ElementsNoNamespace("dependency").Any() &&
                dependenciesElement.ElementsNoNamespace("group").Any())
            {
                // TODO: Resources
                throw new InvalidDataException("NuGetResources.Manifest_DependenciesHasMixedElements");
            }

            var dependencies = ReadDependencies(dependenciesElement);

            if (dependencies.Count > 0)
            {
                // old format, <dependency> is direct child of <dependencies>
                var dependencySet = new PackageDependencySet(dependencies);
                return(new List <PackageDependencySet> {
                    dependencySet
                });
            }
            else
            {
                var groups = dependenciesElement.ElementsNoNamespace("group");
                return((from element in groups
                        select new PackageDependencySet(element.GetOptionalAttributeValue("targetFramework")?.Trim(),
                                                        ReadDependencies(element))).ToList());
            }
        }
 private static string[] GetDependencies(PackageDependencySet coreDeps)
 {
     return coreDeps.Dependencies
         .Select(d => d.Id)
         .Where(d => !d.StartsWith("System."))
         .Where(d => !d.StartsWith("Microsoft.NETCore."))
         .Where(d => d != "NETStandard.Library")
         .ToArray();
 }
 internal static IPackage CreatePackage(string id, string version, IEnumerable<PackageDependency> packageDependencies)
 {
     var package = Substitute.For<IPackage>();
     package.Id.Returns(id);
     package.Version.Returns(new SemanticVersion(version));
     var packageDependencySet = new PackageDependencySet(null, packageDependencies);
     package.DependencySets.Returns(new[] { packageDependencySet, });
     return package;
 }
Beispiel #4
0
        public static IEnumerable<PackageDependency> GetCompatiblePackageDependencies(this IPackageMetadata package, FrameworkName targetFramework)
        {
            IEnumerable<PackageDependencySet> compatibleDependencySets;
            if (targetFramework == null)
            {
                compatibleDependencySets = package.DependencySets;
            }
            else if (!VersionUtility.TryGetCompatibleItems(targetFramework, package.DependencySets, out compatibleDependencySets))
            {
                compatibleDependencySets = new PackageDependencySet[0];
            }

            return compatibleDependencySets.SelectMany(d => d.Dependencies);
        }
Beispiel #5
0
        public static IEnumerable <PackageDependency> GetCompatiblePackageDependencies(this IPackageMetadata package, FrameworkName targetFramework)
        {
            IEnumerable <PackageDependencySet> dependencySets;

            if (targetFramework == null)
            {
                dependencySets = package.DependencySets;
            }
            else if (!VersionUtility.TryGetCompatibleItems <PackageDependencySet>(targetFramework, package.DependencySets, out dependencySets))
            {
                dependencySets = new PackageDependencySet[0];
            }
            return(from d in dependencySets select d.Dependencies);
        }
 public override void Context()
 {
     base.Context();
     var packageDependencies = new List<PackageDependency>
     {
         fiddlerPackageDependency,
         chocolateyPackageDependency
     };
     var packageDependencySet = new PackageDependencySet(new FrameworkName(".NETFramework, Version = 4.0"), packageDependencies);
     package.Setup(p => p.DependencySets).Returns(
         new List<PackageDependencySet>
         {
             packageDependencySet
         });
 }
        private IEnumerable<string> ConvertDependencySetToStrings(PackageDependencySet dependencySet)
        {
            if (dependencySet.Dependencies.Count == 0)
            {
                if (dependencySet.TargetFramework != null)
                {
                    // if this Dependency set is empty, we still need to send down one string of the form "::<target framework>",
                    // so that the client can reconstruct an empty group.
                    return new string[] { String.Format("::{0}", VersionUtility.GetShortFrameworkName(dependencySet.TargetFramework)) };
                }
            }
            else
            {
                return dependencySet.Dependencies.Select(dependency => ConvertDependency(dependency, dependencySet.TargetFramework));
            }

            return new string[0];
        }
        public static Stream CreateSimplePackageStream(string id, string version = "1.0")
        {
            var packageBuilder = new PackageBuilder
            {
                Id = id,
                Version = SemanticVersion.Parse(version),
                Description = "Test description",
            };

            var dependencySet = new PackageDependencySet(VersionUtility.DefaultTargetFramework,
                new PackageDependency[] {
                    new PackageDependency("Foo")
                });
            packageBuilder.DependencySets.Add(dependencySet);
            packageBuilder.Authors.Add("foo");

            var memoryStream = new MemoryStream();
            packageBuilder.Save(memoryStream);
            memoryStream.Seek(0, SeekOrigin.Begin);

            return memoryStream;
        }
Beispiel #9
0
        /// <summary>
        /// Inserts a dependency set into the packagebuilder object, based on a dictionary
        /// containing Id/version pairs (Newtonsoft.json, 5.0.6 for example).
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="packages"></param>
        private void AddNugetDependencies(NuGet.PackageBuilder builder, Dictionary<string, string> packages)
        {
            //add dependencies
              List<PackageDependency> dependencies = new List<PackageDependency>();
              foreach (var package in packages)
              {
              dependencies.Add(new PackageDependency(package.Key, new VersionSpec {MinVersion = new SemanticVersion(package.Value), IsMinInclusive = true}));
              }

              var set = new PackageDependencySet(null, dependencies);
              builder.DependencySets.Add(set);
        }
        private static IEnumerable<string> ConvertDependencySetToStrings(PackageDependencySet dependencySet)
        {
            if (dependencySet.Dependencies.Count == 0)
            {
                if (dependencySet.TargetFramework != null)
                    return new[] { String.Format("::{0}", VersionUtility.GetShortFrameworkName(dependencySet.TargetFramework)) };
            }
            else
                return dependencySet.Dependencies.Select(dependency => ConvertDependency(dependency, dependencySet.TargetFramework));

            return new string[0];
        }
 private NuGetFramework GetNuGetFramework(PackageDependencySet dependencySet)
 {
     NuGetFramework fxName = NuGetFramework.AnyFramework;
     if (dependencySet.TargetFramework != null)
         fxName = NuGetFramework.Parse(dependencySet.TargetFramework.FullName);
     return fxName;
 }
Beispiel #12
0
        static void CreatePackage(PackageInfo package)
        {
            var packageBuilder = new PackageBuilder()
            {
                Id = package.Id,
                Version = package.Version,
                Description = "Some test package"
            };

            packageBuilder.Authors.Add("Outercurve Foundation");

            string assemblySourcePath = GetAssemblyFullPath(package.FullName);
            packageBuilder.Files.Add(new PhysicalPackageFile()
            {
                SourcePath = assemblySourcePath,
                TargetPath = @"lib\" + Path.GetFileName(assemblySourcePath)
            });

            var set = new PackageDependencySet(VersionUtility.DefaultTargetFramework, 
                package.Dependencies.Select(dependency => new PackageDependency(dependency.Id, dependency.VersionSpec)));
            packageBuilder.DependencySets.Add(set);

            using (var stream = File.Create(GetPackageFileFullPath(package)))
            {
                packageBuilder.Save(stream);
            }
        }
        private PackageBuilder CreatePackage()
        {
            PackageBuilder pb = new PackageBuilder();
            pb.Id = Id;
            pb.Version = new SemanticVersion(Version);
            pb.Title = Title;
            pb.Description = Description;
            pb.Authors.AddRange(Authors.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries));
            pb.Owners.AddRange(Owners.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries));
            if (FrameworkAssemblies != null)
                foreach (var fa in FrameworkAssemblies)
                    pb.FrameworkReferences.Add(new FrameworkAssemblyReference(fa.FrameworkName));
            if (Dependencies != null)
            {
                var groups = new Dictionary<string, List<NuGetDependency>>();
                foreach (var dpg in Dependencies)
                {
                    string framework = dpg.TargetFramework;
                    if (String.IsNullOrWhiteSpace(framework))
                        framework = "";

                    List<NuGetDependency> list;
                    if (!groups.TryGetValue(framework, out list))
                        groups[framework] = list = new List<NuGetDependency>();

                    list.AddRange(dpg.Dependencies);
                }

                foreach (var g in groups)
                {
                    FrameworkName fn = g.Key == "" ? null : VersionUtility.ParseFrameworkName(g.Key);
                    PackageDependencySet ds = new PackageDependencySet(fn, g.Value.Select(v => (PackageDependency)v));
                    pb.DependencySets.Add(ds);
                }
            }
            if (Icon != null)
                pb.IconUrl = Icon;
            if (Url != null)
                pb.ProjectUrl = Url;
            if (License != null)
                pb.LicenseUrl = License;
            if (Summary != null)
                pb.Summary = Summary;
            if (Copyright != null)
                pb.Copyright = Copyright;
            if (ReleaseNotes != null)
                pb.ReleaseNotes = ReleaseNotes;

            return pb;
        }
Beispiel #14
0
        private static List<PackageDependencySet> ReadDependencySets(XElement dependenciesElement)
        {
            if (!dependenciesElement.HasElements)
            {
                return new List<PackageDependencySet>();
            }

            // Disallow the <dependencies> element to contain both <dependency> and 
            // <group> child elements. Unfortunately, this cannot be enforced by XSD.
            if (dependenciesElement.ElementsNoNamespace("dependency").Any() &&
                dependenciesElement.ElementsNoNamespace("group").Any())
            {
                throw new InvalidDataException(NuGetResources.Manifest_DependenciesHasMixedElements);
            }

            var dependencies = ReadDependencies(dependenciesElement);
            if (dependencies.Any())
            {
                // old format, <dependency> is direct child of <dependencies>
                var dependencySet = new PackageDependencySet(dependencies);
                return new List<PackageDependencySet> { dependencySet };
            }
            else
            {
                var groups = dependenciesElement.ElementsNoNamespace("group");
                return (from element in groups
                        select new PackageDependencySet(
                            element.GetOptionalAttributeValue("targetFramework")?.Trim(),
                            ReadDependencies(element))
                       ).ToList();
            }
        }
 public override void Context()
 {
     base.Context();
     var packageDependencies = new List<PackageDependency>
     {
         packageDependencyWithNoVersion
     };
     var packageDependencySet = new PackageDependencySet(null, packageDependencies);
     package.Setup(p => p.DependencySets).Returns(
         new List<PackageDependencySet>
         {
             packageDependencySet
         });
 }
 public EditablePackageDependencySet(PackageDependencySet packageDependencySet)
 {
     _targetFramework = packageDependencySet.TargetFramework;
     _dependencies = new ObservableCollection<PackageDependency>(packageDependencySet.Dependencies);
 }