示例#1
0
 public DependencyResult CheckNodeReferences()
 {
     try
     {
         if (DependencyResult == null)
         {
             ServiceContext = new ServiceContextOfUser();
         }
         DependencyResult = ServiceContext.Init();
     }
     catch (Exception ex)
     {
         LoggerProvider.GetLog4netLogger("ServiceLog").Error(ex.ToString());
     }
     return(DependencyResult);
 }
示例#2
0
        public DependencyResult Process()
        {
            var result = new DependencyResult();

            NuGet.ProjectModel.PackageSpec model = NuGet.ProjectModel.JsonPackageSpecReader.GetPackageSpec(ProjectName, ProjectJsonPath);
            IList <NuGet.LibraryModel.LibraryDependency> packages = model.Dependencies;

            foreach (NuGet.LibraryModel.LibraryDependency package in packages)
            {
                var set = new Model.PackageSet();
                set.PackageId = new Model.PackageId(package.Name, package.LibraryRange.VersionRange.OriginalString);
                result.Packages.Add(set);
                result.Dependencies.Add(set.PackageId);
            }
            return(result);
        }
示例#3
0
        public DependencyResult Process()
        {
            List <NugetDependency> dependencies = GetDependencies();

            var result = new DependencyResult();

            result.Packages = CreatePackageSets(dependencies);

            result.Dependencies = new List <Model.PackageId>();
            foreach (var package in result.Packages)
            {
                var anyPackageReferences = result.Packages.Where(pkg => pkg.Dependencies.Contains(package.PackageId)).Any();
                if (!anyPackageReferences)
                {
                    result.Dependencies.Add(package.PackageId);
                }
            }

            return(result);
        }
        public IEnumerable <BuildObject> getDependencies(IVerb verb, out DependencyDisposition ddisp)
        {
            dbgQueries += 1;
            DependencyResult result;
            bool             present = theCache.TryGetValue(verb, out result);

            if (!present)
            {
                dbgMisses  += 1;
                result      = new DependencyResult();
                result.deps = verb.getDependencies(out result.ddisp);
                if (result.ddisp != DependencyDisposition.Incomplete)
                {
                    //- Can't cache incomplete results, since they may change upon
                    //- later inspection.
                    theCache[verb] = result;
                }
            }
            ddisp = result.ddisp;
            return(result.deps);
        }
示例#5
0
        public IEnumerable<BuildObject> getDependencies(IVerb verb, out DependencyDisposition ddisp)
        {
            this.dbgQueries += 1;
            DependencyResult result;
            bool present = this.theCache.TryGetValue(verb, out result);
            if (!present)
            {
                this.dbgMisses += 1;
                result = new DependencyResult();
                result.deps = verb.getDependencies(out result.ddisp);
                if (result.ddisp != DependencyDisposition.Incomplete)
                {
                    // Can't cache incomplete results, since they may change upon
                    // later inspection.
                    this.theCache[verb] = result;
                }
            }

            ddisp = result.ddisp;
            return result.deps;
        }
 public static DependencyResult CreateFrom <TDependenceInstance>(DependencyResult <TDependenceInstance> result)
     where TDependenceInstance : class
 => new DependencyResult(instance : result.Instance, isNewInstance : result.IsNewInstance, redirectHandler : result.RedirectHandler);
        public DependencyResult Process()
        {
            var result = new DependencyResult();
            var tree   = new NugetTreeResolver(NugetSearchService);

            // .NET core default version
            result.ProjectVersion = "1.0.0";
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

            XmlDocument doc = new XmlDocument();

            doc.Load(ProjectPath);

            XmlNodeList versionNodes = doc.GetElementsByTagName("Version");

            if (versionNodes != null && versionNodes.Count > 0)
            {
                foreach (XmlNode version in versionNodes)
                {
                    if (version.NodeType != XmlNodeType.Comment)
                    {
                        result.ProjectVersion = version.InnerText;
                    }
                }
            }
            else
            {
                string      prefix      = "1.0.0";
                string      suffix      = "";
                XmlNodeList prefixNodes = doc.GetElementsByTagName("VersionPrefix");
                if (prefixNodes != null && prefixNodes.Count > 0)
                {
                    foreach (XmlNode prefixNode in prefixNodes)
                    {
                        if (prefixNode.NodeType != XmlNodeType.Comment)
                        {
                            prefix = prefixNode.InnerText;
                        }
                    }
                }
                XmlNodeList suffixNodes = doc.GetElementsByTagName("VersionSuffix");
                if (suffixNodes != null && suffixNodes.Count > 0)
                {
                    foreach (XmlNode suffixNode in suffixNodes)
                    {
                        if (suffixNode.NodeType != XmlNodeType.Comment)
                        {
                            suffix = suffixNode.InnerText;
                        }
                    }
                }
                result.ProjectVersion = String.Format("{0}-{1}", prefix, suffix);;
            }
            XmlNodeList packagesNodes = doc.GetElementsByTagName("PackageReference");

            if (packagesNodes.Count > 0)
            {
                foreach (XmlNode package in packagesNodes)
                {
                    XmlAttributeCollection attributes = package.Attributes;
                    if (attributes != null)
                    {
                        XmlAttribute include = attributes["Include"];
                        XmlAttribute version = attributes["Version"];
                        if (include != null && version != null)
                        {
                            var dep = new NugetDependency(include.Value, NuGet.Versioning.VersionRange.Parse(version.Value));
                            tree.Add(dep);
                        }
                    }
                }
            }

            result.Packages     = tree.GetPackageList();
            result.Dependencies = new List <PackageId>();
            foreach (var package in result.Packages)
            {
                var anyPackageReferences = result.Packages.Where(pkg => pkg.Dependencies.Contains(package.PackageId)).Any();
                if (!anyPackageReferences)
                {
                    result.Dependencies.Add(package.PackageId);
                }
            }

            return(result);
        }
        public DependencyResult Process()
        {
            try
            {
                var tree = new NugetTreeResolver(NugetSearchService);

                Microsoft.Build.Evaluation.Project proj = new Microsoft.Build.Evaluation.Project(ProjectPath);

                List <NugetDependency> deps = new List <NugetDependency>();
                foreach (ProjectItem reference in proj.GetItemsIgnoringCondition("PackageReference"))
                {
                    var versionMetaData = reference.Metadata.Where(meta => meta.Name == "Version").FirstOrDefault().EvaluatedValue;
                    NuGet.Versioning.VersionRange version;
                    if (NuGet.Versioning.VersionRange.TryParse(versionMetaData, out version))
                    {
                        var dep = new NugetDependency(reference.EvaluatedInclude, version);
                        deps.Add(dep);
                    }
                    else
                    {
                        Console.WriteLine("Framework dependency had no version, will not be included: " + reference.EvaluatedInclude);
                    }
                }

                foreach (ProjectItem reference in proj.GetItemsIgnoringCondition("Reference"))
                {
                    if (reference.Xml != null && !String.IsNullOrWhiteSpace(reference.Xml.Include) && reference.Xml.Include.Contains("Version="))
                    {
                        string packageInfo = reference.Xml.Include;

                        var artifact = packageInfo.Substring(0, packageInfo.IndexOf(","));

                        string versionKey                 = "Version=";
                        int    versionKeyIndex            = packageInfo.IndexOf(versionKey);
                        int    versionStartIndex          = versionKeyIndex + versionKey.Length;
                        string packageInfoAfterVersionKey = packageInfo.Substring(versionStartIndex);

                        string seapirater = ",";
                        string version;
                        if (packageInfoAfterVersionKey.Contains(seapirater))
                        {
                            int firstSeapirater = packageInfoAfterVersionKey.IndexOf(seapirater);
                            version = packageInfoAfterVersionKey.Substring(0, firstSeapirater);
                        }
                        else
                        {
                            version = packageInfoAfterVersionKey;
                        }

                        var dep = new NugetDependency(artifact, NuGet.Versioning.VersionRange.Parse(version));
                        deps.Add(dep);
                    }
                }
                ProjectCollection.GlobalProjectCollection.UnloadProject(proj);

                foreach (var dep in deps)
                {
                    tree.Add(dep);
                }

                var result = new DependencyResult()
                {
                    Success      = true,
                    Packages     = tree.GetPackageList(),
                    Dependencies = new List <PackageId>()
                };

                foreach (var package in result.Packages)
                {
                    var anyPackageReferences = result.Packages.Where(pkg => pkg.Dependencies.Contains(package.PackageId)).Any();
                    if (!anyPackageReferences)
                    {
                        result.Dependencies.Add(package.PackageId);
                    }
                }

                return(result);
            }
            catch (InvalidProjectFileException e)
            {
                return(new DependencyResult()
                {
                    Success = false
                });
            }
        }
示例#9
0
        public DependencyResult Process()
        {
            var builder = new Model.PackageSetBuilder();
            var result  = new DependencyResult();

            foreach (var target in LockFile.Targets)
            {
                foreach (var library in target.Libraries)
                {
                    string name      = library.Name;
                    string version   = library.Version.ToNormalizedString();
                    var    packageId = new Model.PackageId(name, version);

                    HashSet <Model.PackageId> dependencies = new HashSet <Model.PackageId>();
                    foreach (var dep in library.Dependencies)
                    {
                        var id = dep.Id;
                        var vr = dep.VersionRange;
                        //vr.Float.FloatBehavior = NuGet.Versioning.NuGetVersionFloatBehavior.
                        var lb = target.Libraries;
                        var bs = BestVersion(id, vr, lb);
                        if (bs == null)
                        {
                            Console.WriteLine(dep.Id);
                            bs = BestVersion(id, vr, lb);
                        }
                        else
                        {
                            var depId = new Model.PackageId(id, bs.ToNormalizedString());
                            dependencies.Add(depId);
                        }
                    }

                    builder.AddOrUpdatePackage(packageId, dependencies);
                }
            }



            if (LockFile.PackageSpec.Dependencies.Count != 0)
            {
                foreach (var dep in LockFile.PackageSpec.Dependencies)
                {
                    var version = builder.GetBestVersion(dep.Name, dep.LibraryRange.VersionRange);
                    result.Dependencies.Add(new Model.PackageId(dep.Name, version));
                }
            }
            else
            {
                foreach (var framework in LockFile.PackageSpec.TargetFrameworks)
                {
                    foreach (var dep in framework.Dependencies)
                    {
                        var version = builder.GetBestVersion(dep.Name, dep.LibraryRange.VersionRange);
                        result.Dependencies.Add(new Model.PackageId(dep.Name, version));
                    }
                }
            }

            if (result.Dependencies.Count == 0)
            {
                Console.WriteLine("Found no dependencies for lock file: " + LockFile.Path);
            }

            result.Packages = builder.GetPackageList();
            return(result);
        }