Exemplo n.º 1
0
        private static void WriteCentralTransitiveDependencyGroup(IObjectWriter writer, IList <CentralTransitiveDependencyGroup> centralTransitiveDependencyGroups)
        {
            writer.WriteObjectStart();

            foreach (var centralTransitiveDepGroup in centralTransitiveDependencyGroups.OrderBy(ptdg => ptdg.FrameworkName))
            {
                PackageSpecWriter.SetCentralTransitveDependencyGroup(writer, centralTransitiveDepGroup.FrameworkName, centralTransitiveDepGroup.TransitiveDependencies);
            }

            writer.WriteObjectEnd();
        }
Exemplo n.º 2
0
        private static void WriteLockFile(JsonWriter writer, IObjectWriter jsonObjectWriter, LockFile lockFile)
        {
            writer.WriteStartObject();

            writer.WritePropertyName(VersionProperty);
            writer.WriteValue(lockFile.Version);

            writer.WritePropertyName(TargetsProperty);
            JsonUtility.WriteObject(writer, lockFile.Targets, WriteTarget);

            writer.WritePropertyName(LibrariesProperty);
            JsonUtility.WriteObject(writer, lockFile.Libraries, WriteLibrary);

            writer.WritePropertyName(ProjectFileDependencyGroupsProperty);
            JsonUtility.WriteObject(writer, lockFile.ProjectFileDependencyGroups, WriteProjectFileDependencyGroup);

            if (lockFile.PackageFolders?.Any() == true)
            {
                writer.WritePropertyName(PackageFoldersProperty);
                JsonUtility.WriteObject(writer, lockFile.PackageFolders, WriteFileItem);
            }

            if (lockFile.Version >= 2)
            {
                if (lockFile.PackageSpec != null)
                {
                    writer.WritePropertyName(PackageSpecProperty);

                    jsonObjectWriter.WriteObjectStart();

                    PackageSpecWriter.Write(lockFile.PackageSpec, jsonObjectWriter);

                    jsonObjectWriter.WriteObjectEnd();
                }
            }

            if (lockFile.Version >= 3)
            {
                if (lockFile.LogMessages.Count > 0)
                {
                    var projectPath = lockFile.PackageSpec?.RestoreMetadata?.ProjectPath;
                    writer.WritePropertyName(LogsProperty);
                    WriteLogMessages(writer, lockFile.LogMessages, projectPath);
                }
            }

            if (lockFile.CentralTransitiveDependencyGroups.Any())
            {
                writer.WritePropertyName(CentralTransitiveDependencyGroupsProperty);
                WriteCentralTransitiveDependencyGroup(jsonObjectWriter, lockFile.CentralTransitiveDependencyGroups);
            }

            writer.WriteEndObject();
        }
Exemplo n.º 3
0
        private static JObject WriteLockFile(LockFile lockFile)
        {
            var json = new JObject
            {
                [VersionProperty]   = new JValue(lockFile.Version),
                [TargetsProperty]   = JsonUtility.WriteObject(lockFile.Targets, WriteTarget),
                [LibrariesProperty] = JsonUtility.WriteObject(lockFile.Libraries, WriteLibrary),
                [ProjectFileDependencyGroupsProperty] = JsonUtility.WriteObject(lockFile.ProjectFileDependencyGroups, WriteProjectFileDependencyGroup)
            };

            if (lockFile.PackageFolders?.Any() == true)
            {
                json[PackageFoldersProperty] = JsonUtility.WriteObject(lockFile.PackageFolders, WriteFileItem);
            }

            if (lockFile.Version >= 2)
            {
                if (lockFile.PackageSpec != null)
                {
                    using (var jsonWriter = new JTokenWriter())
                        using (var writer = new JsonObjectWriter(jsonWriter))
                        {
                            writer.WriteObjectStart();

                            PackageSpecWriter.Write(lockFile.PackageSpec, writer);

                            writer.WriteObjectEnd();

                            json[PackageSpecProperty] = (JObject)jsonWriter.Token;
                        }
                }
            }

            if (lockFile.Version >= 3)
            {
                if (lockFile.LogMessages.Count > 0)
                {
                    var projectPath = lockFile.PackageSpec?.RestoreMetadata?.ProjectPath;
                    json[LogsProperty] = WriteLogMessages(lockFile.LogMessages, projectPath);
                }
            }

            if (lockFile.CentralTransitiveDependencyGroups.Any())
            {
                JToken token = WriteCentralTransitiveDependencyGroup(lockFile.CentralTransitiveDependencyGroups);
                json[CentralTransitiveDependencyGroupsProperty] = (JObject)token;
            }

            return(json);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Clone a PackageSpec and underlying JObject.
        /// </summary>
        public PackageSpec Clone()
        {
            var writer = new JsonObjectWriter();

            PackageSpecWriter.Write(this, writer);
            var json = writer.GetJObject();

            var spec = JsonPackageSpecReader.GetPackageSpec(json);

            spec.Name     = Name;
            spec.FilePath = FilePath;

            return(spec);
        }
Exemplo n.º 5
0
        private static JToken WriteCentralTransitiveDependencyGroup(IList <CentralTransitiveDependencyGroup> centralTransitiveDependencyGroups)
        {
            using (var jsonWriter = new JTokenWriter())
                using (var writer = new JsonObjectWriter(jsonWriter))
                {
                    writer.WriteObjectStart();

                    foreach (var centralTransitiveDepGroup in centralTransitiveDependencyGroups.OrderBy(ptdg => ptdg.FrameworkName))
                    {
                        PackageSpecWriter.SetCentralTransitveDependencyGroup(writer, centralTransitiveDepGroup.FrameworkName, centralTransitiveDepGroup.TransitiveDependencies);
                    }

                    writer.WriteObjectEnd();
                    return(jsonWriter.Token);
                }
        }
Exemplo n.º 6
0
        private static JObject WriteLockFile(LockFile lockFile)
        {
            var json = new JObject
            {
                [VersionProperty]   = new JValue(lockFile.Version),
                [TargetsProperty]   = WriteObject(lockFile.Targets, WriteTarget),
                [LibrariesProperty] = WriteObject(lockFile.Libraries, WriteLibrary),
                [ProjectFileDependencyGroupsProperty] = WriteObject(lockFile.ProjectFileDependencyGroups, WriteProjectFileDependencyGroup)
            };

            if (lockFile.PackageFolders?.Any() == true)
            {
                json[PackageFoldersProperty] = WriteObject(lockFile.PackageFolders, WriteFileItem);
            }

            if (lockFile.Version >= 2)
            {
                if (lockFile.PackageSpec != null)
                {
                    var writer = new JsonObjectWriter();
                    PackageSpecWriter.Write(lockFile.PackageSpec, writer);
                    var packageSpec = writer.GetJObject();
                    json[PackageSpecProperty] = packageSpec;
                }
            }

            if (lockFile.Version >= 3)
            {
                if (lockFile.LogMessages.Count > 0)
                {
                    var projectPath = lockFile.PackageSpec?.RestoreMetadata?.ProjectPath;
                    json[LogsProperty] = WriteLogMessages(lockFile.LogMessages, projectPath);
                }
            }

            return(json);
        }