Beispiel #1
0
        public override IPackageFile Fetch(PackageDependency dependency, string directory)
        {
            var package = Get(dependency) as NuGetODataPackage;

            if (package == null)
            {
                return(null);
            }

            var path = System.IO.Path.Combine(directory, package.IdAndVersion() + ".nupkg");

            // Download the actual application/zip
            var client = new WebClient();

            client.Headers.Add("user-agent", Moo.UserAgent);
            client.DownloadFile(package.DownloadUrl, path);

            return(new Nupkg(path));
        }
Beispiel #2
0
        public override IPackageFile Fetch(PackageDependency dependency, string directory)
        {
            var package = Get(dependency) as MooDirPackage;

            if (package == null)
            {
                throw new PackageNotFoundException(dependency);
            }

            var nupkg = package.Nupkg;

            if (nupkg == null)
            {
                nupkg = package.CreateNupkg();
            }

            var newFile = nupkg.Copy(directory);

            return(new Nupkg(newFile.Path));
        }
Beispiel #3
0
        /// <summary>Thanks to Yank(), it makes sense to have a base implementation of Uninstall()</summary>
        public virtual bool Uninstall(PackageDependency dependency, bool uninstallDependencies)
        {
            var package = Get(dependency);

            if (package == null)
            {
                return(false);
            }

            if (uninstallDependencies)
            {
                foreach (var dep in package.Details.Dependencies)
                {
                    Uninstall(dep, true);
                }
            }

            Yank(package.ToPackageDependency());
            return(true);
        }
Beispiel #4
0
        public override bool Yank(PackageDependency dependency)
        {
            var package = Get(dependency) as MooDirPackage;

            if (package == null)
            {
                return(false);
            }
            var unpacked = package.Unpacked;

            // If this has tools and was the highest version of this package, delete the tools
            if (unpacked.Tools.Count > 0)
            {
                if (this.HighestVersionAvailableOf(package.Id) == package.Version)
                {
                    DeleteBinariesFor(package);
                }
            }

            // Delete our UnpackedPackage directory
            unpacked.Delete();

            return(true);
        }
Beispiel #5
0
 public virtual IPackage Get(PackageDependency dependency)
 {
     return(Packages.Where(pkg => dependency.Matches(pkg)).ToList().Latest());
 }
Beispiel #6
0
 public abstract bool           Yank(PackageDependency dependency);
Beispiel #7
0
 public abstract IPackageFile   Fetch(PackageDependency dependency, string directory);
Beispiel #8
0
 public virtual List <IPackage> GetPackagesMatchingDependencies(params PackageDependency[] dependencies)
 {
     return(Packages.Where(pkg => PackageDependency.MatchesAll(pkg, dependencies)).ToList());
 }
Beispiel #9
0
 public override bool Yank(PackageDependency dependency)
 {
     return(false);
 }
Beispiel #10
0
        public void LoadSpec(string pathToNuspec)
        {
            var doc = Util.GetXmlDocumentForFile(pathToNuspec);

            foreach (XmlNode metadata in doc.GetElementsByTagName("metadata")[0])
            {
                var text = metadata.InnerText.Trim();
                switch (metadata.Name.ToLower())
                {
                case "id":          Id = text; break;

                case "version":     VersionText = text; break;

                case "title":       Title = text; break;

                case "description": Description = text; break;

                case "language":    Language = text; break;

                case "licenseurl":  LicenseUrl = text; break;

                case "projecturl":  ProjectUrl = text; break;

                case "iconurl":     IconUrl = text; break;

                case "created":  Created = DateTime.Parse(text); break;

                case "modified": Modified = DateTime.Parse(text); break;

                case "requirelicenseacceptance":
                    RequireLicenseAcceptance = bool.Parse(text); break;

                case "authors":
                    if (text.Contains(","))
                    {
                        foreach (var author in text.Split(','))
                        {
                            Authors.Add(author.Trim());
                        }
                    }
                    else
                    {
                        foreach (XmlNode authorNode in metadata.ChildNodes)
                        {
                            Authors.Add(authorNode.InnerText);
                        }
                    }
                    break;

                case "owners":
                    if (text.Contains(","))
                    {
                        foreach (var owner in text.Split(','))
                        {
                            Owners.Add(owner.Trim());
                        }
                    }
                    else
                    {
                        foreach (XmlNode ownerNode in metadata.ChildNodes)
                        {
                            Owners.Add(ownerNode.InnerText);
                        }
                    }
                    break;

                case "tags":
                    char separator = metadata.InnerText.Contains(",") ? ',' : ' ';
                    foreach (var tag in metadata.InnerText.Trim().Split(separator))
                    {
                        Tags.Add(tag.Trim());
                    }
                    break;

                default:
                    Console.WriteLine("Unknown <metadata> element: {0}", metadata.Name);
                    break;
                }
            }
            foreach (XmlNode dependencyNode in doc.GetElementsByTagName("dependency"))
            {
                var dependency = new PackageDependency();
                foreach (XmlAttribute attr in dependencyNode.Attributes)
                {
                    switch (attr.Name.ToLower())
                    {
                    case "id":         dependency.Id = attr.Value; break;

                    case "version":    dependency.VersionText = attr.Value; break;

                    case "minversion": dependency.MinVersionText = attr.Value; break;

                    case "maxversion": dependency.MaxVersionText = attr.Value; break;

                    default:
                        Console.WriteLine("Unknown <dependency> attribute: {0}", attr.Name);
                        break;
                    }
                }
                Dependencies.Add(dependency);
            }
        }
Beispiel #11
0
        static List <RemotePackage> FindDependencies(IDictionary <string, List <PackageDependency> > discoveredDependencies, Package[] packages, params List <RemotePackage>[] listsOfPackages)
        {
            var  found          = new List <RemotePackage>();
            var  packageIds     = packages.Select(p => p.Id);
            bool throwIfMissing = (discoveredDependencies == null);             // if this is null, then we're not recursing

            // TODO this should be pulled out into its own method that JUST returns a list of PackageDependency for us to find
            //
            // get ALL of the dependencies for these packages, grouped by package Id
            // eg. { "log4net" => ["log4net > 2.0", "log4net < 2.5"] }
            var allDependencies = new Dictionary <string, List <PackageDependency> >();

            foreach (var package in packages)
            {
                foreach (var packageDependency in package.Dependencies)
                {
                    if (packageIds.Contains(packageDependency.PackageId))
                    {
                        continue;
                    }
                    if (!allDependencies.ContainsKey(packageDependency.PackageId))
                    {
                        allDependencies[packageDependency.PackageId] = new List <PackageDependency>();
                    }
                    if (!allDependencies[packageDependency.PackageId].Contains(packageDependency))
                    {
                        allDependencies[packageDependency.PackageId].Add(packageDependency);
                    }
                }
            }

            // add these packages' dependencies into discoveredDependencies.
            // we track these to know whether or not we're missing any dependencies for any of the packages found.
            if (discoveredDependencies == null)
            {
                discoveredDependencies = new Dictionary <string, List <PackageDependency> >();
            }
            foreach (var packageDependency in allDependencies)
            {
                var dependencyId = packageDependency.Key;
                var dependencies = packageDependency.Value.ToArray();
                if (!discoveredDependencies.ContainsKey(dependencyId))
                {
                    discoveredDependencies[dependencyId] = new List <PackageDependency>();
                }
                foreach (var dependency in dependencies)
                {
                    if (!discoveredDependencies[dependencyId].Contains(dependency))
                    {
                        discoveredDependencies[dependencyId].Add(dependency);
                    }
                }
            }

            foreach (var packageDependency in allDependencies)
            {
                var dependencyId = packageDependency.Key;
                var dependencies = packageDependency.Value.ToArray();

                // go through all sources and get the *latest* version of this dependency (that matches)
                RemotePackage dependencyPackage = null;
                foreach (var sourcePackages in listsOfPackages)
                {
                    var match = sourcePackages.Where(pkg => pkg.Id == dependencyId && PackageDependency.MatchesAll(pkg.Version, dependencies)).OrderBy(pkg => pkg.Version).Reverse().FirstOrDefault();

                    if (match != null)
                    {
                        if (dependencyPackage == null || dependencyPackage.Version < match.Version)
                        {
                            dependencyPackage = match;
                        }
                    }
                }

                if (dependencyPackage != null)
                {
                    found.Add(dependencyPackage);
                    if (dependencyPackage.Dependencies.Any())
                    {
                        found.AddRange(Package.FindDependencies(discoveredDependencies, new Package[] { dependencyPackage }, listsOfPackages));                        // <--- recurse!
                    }
                }
                else
                {
                    Console.WriteLine("Could not find dependency: {0}", dependencyId);
                }
            }

            // throw a MissingDependencyException if any of the discovered dependencies were not found
            if (throwIfMissing)
            {
                var foundIds = found.Select(pkg => pkg.Id);
                var missing  = new List <PackageDependency>();

                foreach (var dependencyPackage in discoveredDependencies)
                {
                    if (!foundIds.Contains(dependencyPackage.Key))
                    {
                        missing.AddRange(dependencyPackage.Value);
                    }
                }

                if (missing.Count > 0)
                {
                    throw new MissingDependencyException(missing);
                }
            }

            // TODO instead of just doing a Distinct(), we need to actually inspect the dependencies ...

            // do not include any of the packages that were passed in as dependencies
            return(found.Where(pkg => !packageIds.Contains(pkg.Id)).Distinct().ToList());
        }
 public PackageNotFoundException(PackageDependency dependency) : this("Package not found: " + dependency.PackageId)
 {
 }
Beispiel #13
0
        static RemotePackage PackageFromFeedEntry(XmlElement entry)
        {
            var package = new RemotePackage();

            foreach (XmlNode node in entry.ChildNodes)
            {
                switch (node.Name.ToLower())
                {
                case "id": break;

                case "pkg:packageid": package.Id = node.InnerText; break;

                case "pkg:version":   package.VersionText = node.InnerText; break;

                case "pkg:language":  package.Language = node.InnerText; break;

                case "title":         package.Title = node.InnerText; break;

                case "content":       package.Description = node.InnerText; break;

                case "author":        package.Authors.Add(node.InnerText);    break;

                case "owner":         package.Owners.Add(node.InnerText);     break;

                case "published":     package.Created = DateTime.Parse(node.InnerText); break;

                case "updated":       package.Modified = DateTime.Parse(node.InnerText); break;

                case "category":
                    var term = node.Attributes["term"].Value;
                    if (!package.Tags.Contains(term))
                    {
                        package.Tags.Add(term);
                    }
                    break;

                case "pkg:requirelicenseacceptance":
                    package.RequireLicenseAcceptance = bool.Parse(node.InnerText); break;

                case "pkg:keywords":
                    // if there is 1 <string>, split it on spaces
                    // else if there are many, each element is a tag
                    var tagNodes = node.ChildNodes;
                    if (tagNodes.Count == 1)
                    {
                        foreach (var tag in tagNodes[0].InnerText.Split(' '))
                        {
                            if (!package.Tags.Contains(tag.Trim()))
                            {
                                package.Tags.Add(tag.Trim());
                            }
                        }
                    }
                    else
                    {
                        foreach (XmlNode tagString in tagNodes)
                        {
                            if (!package.Tags.Contains(tagString.InnerText.Trim()))
                            {
                                package.Tags.Add(tagString.InnerText.Trim());
                            }
                        }
                    }
                    break;

                case "link":
                    switch (node.Attributes["rel"].Value)
                    {
                    case "enclosure":
                        package.DownloadUrl = node.Attributes["href"].Value; break;

                    case "license":
                        package.LicenseUrl = node.Attributes["href"].Value; break;

                    case "project":
                        package.ProjectUrl = node.Attributes["href"].Value; break;

                    case "icon":
                        package.IconUrl = node.Attributes["href"].Value; break;

                    default:
                        Console.WriteLine("Unsupported <link> rel: {0}", node.Attributes["rel"].Value); break;
                    }
                    break;

                case "pkg:dependencies":
                    foreach (XmlNode dependencyNode in node.ChildNodes)
                    {
                        var dependency = new PackageDependency();
                        foreach (XmlNode depNode in dependencyNode.ChildNodes)
                        {
                            switch (depNode.Name.ToLower())
                            {
                            case "pkg:id":         dependency.Id = depNode.InnerText; break;

                            case "pkg:version":    dependency.VersionText = depNode.InnerText; break;

                            case "pkg:minversion": dependency.MinVersionText = depNode.InnerText; break;

                            case "pkg:maxversion": dependency.MaxVersionText = depNode.InnerText; break;

                            default:
                                Console.WriteLine("Unknown dependency node: {0}", depNode.Name);
                                break;
                            }
                        }
                        package.Dependencies.Add(dependency);
                    }
                    break;

                default:
                    Console.WriteLine("Unsupported <entry> element: {0} \"{1}\"", node.Name, node.InnerText);
                    break;
                }
            }

            return(package);
        }
Beispiel #14
0
 public override string ToString()
 {
     return(string.Format("{0} {1}", PackageDependency.GetOperatorString(Operator), Version));
 }
Beispiel #15
0
        public static PackageVersion HighestVersionMatching(this ISource source, PackageDependency dependency)
        {
            var packages = source.GetPackagesMatchingDependencies(dependency);

            return(PackageVersion.HighestVersion(packages.Select(pkg => pkg.Version).ToArray()));
        }