예제 #1
0
        public static PackageManifest FromFile(string path = "./vc-package.json")
        {
            var result = SerializationTasks.JsonDeserializeFromFile <PackageManifest>(path);

            PlatformVersion.CurrentVersion = new SemanticVersion(Version.Parse(result.PlatformVersion));
            return(result);
        }
예제 #2
0
        private static IEnumerable <InstalledPackage> GetLocalInstalledPackagesFromAssetsFile(
            string packagesConfigFile,
            bool resolveDependencies = true)
        {
            var assetsObject = SerializationTasks.JsonDeserializeFromFile <JObject>(packagesConfigFile);

            // ReSharper disable HeapView.BoxingAllocation
            var directReferences =
                assetsObject["project"]["frameworks"]
                .Single().Single()["dependencies"]
                ?.Children <JProperty>()
                .Select(x => x.Name).ToList()
                ?? new List <string>();

            var allReferences =
                assetsObject["libraries"]
                .Children <JProperty>()
                .Where(x => x.Value["type"].ToString() == "package")
                .Select(x => x.Name.Split('/'))
                .Select(x => (PackageId: x.First(), Version: x.Last())).ToList();

            // ReSharper restore HeapView.BoxingAllocation

            foreach (var(name, version) in allReferences)
            {
                if (!resolveDependencies && !directReferences.Contains(name))
                {
                    continue;
                }

                yield return(GetGlobalInstalledPackage(name, version, packagesConfigFile));
            }
        }
예제 #3
0
        private static Dictionary <string, string> LoadSecrets(IReadOnlyCollection <string> secretParameters, byte[] password, string parametersFile)
        {
            var jobject = SerializationTasks.JsonDeserializeFromFile <JObject>(parametersFile);

            return(jobject.Properties()
                   .Where(x => secretParameters.Contains(x.Name))
                   .ToDictionary(x => x.Name, x => Decrypt(x.Value.Value <string>(), password, x.Name)));
        }
        private static string GetDotNetRuntimeVersion()
        {
            var globalJsonFile = NukeBuild.RootDirectory / "global.json";
            var jobject        = File.Exists(globalJsonFile)
                ? SerializationTasks.JsonDeserializeFromFile <JObject>(globalJsonFile)
                : new JObject();

            return(jobject["sdk"]?["version"]?.Value <string>().Substring(startIndex: 0, length: 5));
        }
예제 #5
0
    public void ChangeProjectVersion(string prefix = null, string suffix = null)
    {
        //theme
        if (IsTheme)
        {
            //var json = JsonDocument.Parse(File.ReadAllText(PackageJsonPath));
            //json.RootElement.GetProperty("version")
            var json = SerializationTasks.JsonDeserializeFromFile <JObject>(PackageJsonPath);
            json["version"] = prefix;
            SerializationTasks.JsonSerializeToFile(json, Path.GetFullPath(PackageJsonPath));
        }
        else
        {
            //module.manifest
            if (IsModule)
            {
                var manifest = ModuleManifest.Clone();
                if (!String.IsNullOrEmpty(prefix))
                {
                    manifest.Version = prefix;
                }
                if (!String.IsNullOrEmpty(suffix))
                {
                    manifest.VersionTag = suffix;
                }
                using (var writer = new Utf8StringWriter())
                {
                    XmlSerializer xml = new XmlSerializer(typeof(ModuleManifest));
                    xml.Serialize(writer, manifest);
                    File.WriteAllText(ModuleManifestFile, writer.ToString(), Encoding.UTF8);
                }
            }

            //Directory.Build.props
            var xmlDoc = new XmlDocument()
            {
                PreserveWhitespace = true
            };
            xmlDoc.LoadXml(File.ReadAllText(DirectoryBuildPropsPath));
            if (!String.IsNullOrEmpty(prefix))
            {
                var prefixNodex = xmlDoc.GetElementsByTagName("VersionPrefix");
                prefixNodex[0].InnerText = prefix;
            }
            if (String.IsNullOrEmpty(VersionSuffix) && !String.IsNullOrEmpty(suffix))
            {
                var suffixNodes = xmlDoc.GetElementsByTagName("VersionSuffix");
                suffixNodes[0].InnerText = suffix;
            }
            using (var writer = new Utf8StringWriter())
            {
                xmlDoc.Save(writer);
                File.WriteAllText(DirectoryBuildPropsPath, writer.ToString());
            }
        }
    }
예제 #6
0
        private static void SaveSecrets(Dictionary <string, string> secrets, byte[] password, string parametersFile)
        {
            var jobject = SerializationTasks.JsonDeserializeFromFile <JObject>(parametersFile);

            foreach (var(name, secret) in secrets)
            {
                jobject[name] = Encrypt(secret, password);
            }

            SerializationTasks.JsonSerializeToFile(jobject, parametersFile);
        }
예제 #7
0
        private static IEnumerable <string> GetSecretParameters(AbsolutePath rootDirectory)
        {
            var buildSchemaFile = GetBuildSchemaFile(rootDirectory);
            var jobject         = SerializationTasks.JsonDeserializeFromFile <JObject>(buildSchemaFile);

            return(jobject
                   .GetPropertyValue("definitions")
                   .GetPropertyValue("build")
                   .GetPropertyValue("properties")
                   .Children <JProperty>()
                   .Where(x => x.Value.Value <JObject>().GetPropertyValueOrNull <string>("default") != null)
                   .Select(x => x.Name));
        }
예제 #8
0
 private static OctoVersionInfo GetResult(IProcess process, OctoVersionGetVersionSettings toolSettings)
 {
     Assert.FileExists(toolSettings.OutputJsonFile);
     try
     {
         return(SerializationTasks.JsonDeserializeFromFile <OctoVersionInfo>(toolSettings.OutputJsonFile, settings =>
         {
             settings.ContractResolver = new AllWritableContractResolver();
             return settings;
         }));
     }
     catch (Exception exception)
     {
         throw new Exception($"Cannot parse {nameof(OctoVersion)} output from {toolSettings.OutputJsonFile.SingleQuote()}.", exception);
     }
 }
예제 #9
0
        private static void UpdateGlobalJsonFile(AbsolutePath rootDirectory)
        {
            var latestInstalledSdk = DotNetTasks.DotNet("--list-sdks", logInvocation: false, logOutput: false)
                                     .LastOrDefault().Text?.Split(" ").First();

            if (latestInstalledSdk == null)
            {
                return;
            }

            var globalJsonFile = rootDirectory / "global.json";
            var jobject        = File.Exists(globalJsonFile)
                ? SerializationTasks.JsonDeserializeFromFile <JObject>(globalJsonFile)
                : new JObject();

            jobject["sdk"] ??= new JObject();
            jobject["sdk"].NotNull()["version"] = latestInstalledSdk;
            SerializationTasks.JsonSerializeToFile(jobject, globalJsonFile);
        }
예제 #10
0
        public static PackageManifest FromFile(string path = "./vc-package.json")
        {
            var result = SerializationTasks.JsonDeserializeFromFile <PackageManifest>(path);

            return(result);
        }