示例#1
0
        /// <summary>
        /// Is this reference matches another one.
        /// </summary>
        /// <param name="other"></param>
        /// <param name="versionCompare">A comparison can be specified. Default is <see cref="PppmVersion.Comparison.Same"/></param>
        /// <returns></returns>
        public bool Matches(PackageReference other, PppmVersion.VersionCompare versionCompare = null)
        {
            if (other == null)
            {
                return(false);
            }

            versionCompare = versionCompare ?? PppmVersion.Comparison.Same;

            var versionmatches = false;

            if (!string.IsNullOrWhiteSpace(Version) && !string.IsNullOrWhiteSpace(other.Version))
            {
                var iscurrsemver      = IsSemanticalVersion(out var currsemversion);
                var isothersemversion = other.IsSemanticalVersion(out var othersemversion);

                if (iscurrsemver && isothersemversion)
                {
                    versionmatches = versionCompare(currsemversion, othersemversion);
                }
                else if (iscurrsemver == isothersemversion) // so both are false
                {
                    versionmatches = Version.EqualsCaseless(other.Version);
                }
            }
            else
            {
                versionmatches = string.IsNullOrWhiteSpace(Version) == string.IsNullOrWhiteSpace(other.Version);
            }

            var repositorymatches = false;

            if (RepositoryUrl != null && other.RepositoryUrl != null)
            {
                repositorymatches = RepositoryUrl.EqualsCaseless(other.RepositoryUrl);
            }
            else
            {
                repositorymatches = (RepositoryUrl == null) == (other.RepositoryUrl == null);
            }

            return(Name.EqualsCaseless(other.Name) && repositorymatches && versionmatches);
        }
示例#2
0
        /// <summary>
        /// Parse metadata from JSON format
        /// </summary>
        /// <param name="hjson"></param>
        /// <param name="packmeta"></param>
        /// <param name="parentRepo">Optionally a parent repository can be specified. This is used mostly for keeping dependency contexts correct.</param>
        public static void ParseFromJson(string json, ref PackageMeta packmeta, string parentRepo = "")
        {
            var jobj = packmeta.MetaData = JObject.Parse(json);

            // TODO: Case insensitive contract bs
            packmeta = jobj.ToObject <PackageMeta>();

            //packmeta.Name = jobj["name"].ToString();
            //packmeta.Version = jobj["version"].ToString();
            //packmeta.Author = jobj["author"]?.ToString();
            //packmeta.Author = jobj["author"]?.ToString();
            //packmeta.License = jobj["license"]?.ToString();
            //packmeta.ProjectUrl = jobj["projectUrl"]?.ToString();
            //packmeta.Repository = jobj["repository"]?.ToString();
            //packmeta.Description = jobj["description"]?.ToString();
            //packmeta.CompatibleAppVersion = jobj["compatibleAppVersion"]?.ToString();
            //packmeta.ForceGlobal = bool.TryParse(jobj["forceGlobal"]?.ToString() ?? "false", out var fg) && fg;
            packmeta.InferSelf();
            packmeta.Dependencies.Clear();

            if (jobj.TryGetValue("dependencies", out var jdeps))
            {
                foreach (var jdep in jdeps)
                {
                    var packref = PackageReference.Parse(jdep.ToString());

                    if (!string.IsNullOrWhiteSpace(parentRepo) &&
                        !string.IsNullOrWhiteSpace(packref.RepositoryUrl)
                        )
                    {
                        packref.RepositoryUrl = parentRepo;
                    }

                    packmeta.Dependencies.Update(packref);
                }
            }
        }