示例#1
0
        private void WriteRuntimeFile(JObject json, RuntimeFile runtimeFile)
        {
            var runtimes = new JObject();

            json["runtimes"] = runtimes;
            foreach (var x in runtimeFile.Runtimes.Values)
            {
                WriteRuntimeSpec(runtimes, x);
            }
        }
示例#2
0
        public RuntimeFile ReadRuntimeFile(JToken json)
        {
            var file = new RuntimeFile();

            foreach (var runtimeSpec in EachProperty(json["runtimes"]).Select(ReadRuntimeSpec))
            {
                file.Runtimes.Add(runtimeSpec.Name, runtimeSpec);
            }
            return(file);
        }
示例#3
0
 public void WriteRuntimeFile(string filePath, RuntimeFile runtimeFile)
 {
     using (var fileStream = new FileStream(filePath, FileMode.Create))
     {
         using (var textWriter = new StreamWriter(fileStream))
         {
             using (var jsonWriter = new JsonTextWriter(textWriter))
             {
                 jsonWriter.Formatting = Formatting.Indented;
                 var json = new JObject();
                 WriteRuntimeFile(json, runtimeFile);
                 json.WriteTo(jsonWriter);
             }
         }
     }
 }
        private void WriteRuntimeFile(JObject json, RuntimeFile runtimeFile)
        {
            var runtimes = new JObject();

            json["runtimes"] = runtimes;
            foreach (var x in runtimeFile.Runtimes.Values)
            {
                WriteRuntimeSpec(runtimes, x);
            }

            if (runtimeFile.Supports.Count > 0)
            {
                var supports = new JObject();
                json["supports"] = supports;
                foreach (var s in runtimeFile.Supports.Values)
                {
                    WriteSupportSpec(supports, s);
                }
            }
        }
        public override bool Execute()
        {
            if (Dependencies == null || Dependencies.Length == 0)
            {
                Log.LogError("Dependencies argument must be specified");
                return false;
            }

            if (String.IsNullOrEmpty(PackageId))
            {
                Log.LogError("PackageID argument must be specified");
                return false;
            }

            if (RuntimeJson == null)
            {
                Log.LogError("RuntimeJson argument must be specified");
                return false;
            }

            RuntimeFileFormatter formatter = new RuntimeFileFormatter();
            RuntimeFile runtimeFile = null;
            string sourceRuntimeFilePath = null;
            if (RuntimeJsonTemplate != null)
            {
                sourceRuntimeFilePath = RuntimeJsonTemplate.GetMetadata("FullPath");
            }
            string destRuntimeFilePath = RuntimeJson.GetMetadata("FullPath");

            // read in existing JSON, if it was provided so that we preserve any 
            // hand authored #imports or dependencies
            if (!String.IsNullOrEmpty(sourceRuntimeFilePath))
            {
                runtimeFile = formatter.ReadRuntimeFile(sourceRuntimeFilePath);
            }
            else
            {
                runtimeFile = new RuntimeFile();
            }

            Dictionary<string, string> packageAliases = new Dictionary<string, string>();
            foreach (var dependency in Dependencies)
            {
                string alias = dependency.GetMetadata("PackageAlias");

                if (String.IsNullOrEmpty(alias))
                {
                    continue;
                }

                Log.LogMessage(LogImportance.Low, "Aliasing {0} -> {1}", alias, dependency.ItemSpec);
                packageAliases[alias] = dependency.ItemSpec;
            }

            foreach (var dependency in Dependencies)
            {
                string targetRuntimeId = dependency.GetMetadata("TargetRuntime");
                string targetPackageId = dependency.GetMetadata("TargetPackage");
                string targetPackageAlias = dependency.GetMetadata("TargetPackageAlias");
                string dependencyId = dependency.ItemSpec;
                string dependencyVersion = dependency.GetMetadata("version");

                if (String.IsNullOrEmpty(targetRuntimeId))
                {
                    Log.LogMessage(LogImportance.Low, "Skipping dependency {0} since it doesn't have a TargetRuntime.", dependency.ItemSpec);
                    continue;
                }

                if (!String.IsNullOrEmpty(targetPackageAlias) && !packageAliases.TryGetValue(targetPackageAlias, out targetPackageId))
                {
                    Log.LogWarning("Dependency {0} specified TargetPackageAlias {1} but no package was found defining this alias.", dependency.ItemSpec, targetPackageAlias);
                }
                else
                {
                    Log.LogMessage(LogImportance.Low, "Using {0} for TargetPackageAlias {1}", targetPackageId, targetPackageAlias);
                }

                RuntimeSpec targetRuntime = null;
                if (!runtimeFile.Runtimes.TryGetValue(targetRuntimeId, out targetRuntime))
                {
                    targetRuntime = new RuntimeSpec() { Name = targetRuntimeId };
                    runtimeFile.Runtimes.Add(targetRuntimeId, targetRuntime);
                }

                if (String.IsNullOrEmpty(targetPackageId))
                {
                    Log.LogMessage(LogImportance.Low, "Dependency {0} has no parent so will assume {1}.", dependency.ItemSpec, PackageId);
                    targetPackageId = PackageId;
                }

                DependencySpec targetPackage = null;
                if (!targetRuntime.Dependencies.TryGetValue(targetPackageId, out targetPackage))
                {
                    targetPackage = new DependencySpec() { Name = targetPackageId };
                    targetRuntime.Dependencies.Add(targetPackageId, targetPackage);
                }

                if (dependencyId == c_emptyDependency)
                {
                    targetPackage.Implementations.Clear();
                }
                else
                {
                    if (String.IsNullOrEmpty(dependencyVersion))
                    {
                        Log.LogWarning("Dependency {0} has no version", dependency.ItemSpec);
                    }

                    ImplementationSpec existing;

                    if (targetPackage.Implementations.TryGetValue(dependencyId, out existing))
                    {
                        string newVersion = CompareSemanticVersion(dependencyVersion, existing.Version) > 0 ? dependencyVersion : existing.Version;
                        Log.LogMessage(LogImportance.Low, "Dependency {0} has been added more than once, {1}, {2}, using {3}", dependencyId, existing.Version, dependencyVersion, newVersion);
                        dependencyVersion = newVersion;
                    }

                    targetPackage.Implementations[dependencyId] = new ImplementationSpec() { Name = dependencyId, Version = dependencyVersion };
                }
            }

            if (EnsureBase)
            {
                // RID base is used to lift the library packages up to a baseline version
                // we don't want to obscure these associations or else we may bring in
                // old reference packages prior to an implementation package split
                // and thus, clashing implementations.

                // EG: Version 1 of System.Banana had a single implementation that was
                //     windows specific.
                //     Version 2 split the implementation to Windows and Unix
                //     If Version 1 was referenced we'd get both the V1 windows implementation
                //     and the V2 unix implementation when resolving for Unix

                // To avoid this problem we always ensure that we have the matching
                // reference package in the runtime graph.

                RuntimeSpec baseRuntime = null;
                if (runtimeFile.Runtimes.TryGetValue("base", out baseRuntime))
                {
                    // look at all sections other than base
                    foreach (var runtime in runtimeFile.Runtimes.Values.Where(rt => rt != baseRuntime))
                    {
                        // examine each dependency and copy the content from base, if it exists
                        foreach (var dependency in runtime.Dependencies)
                        {
                            string packageName = dependency.Key;
                            DependencySpec packageDependencies = dependency.Value;

                            // are there any entries for this package in base?
                            DependencySpec baseDependencies = null;
                            if (!baseRuntime.Dependencies.TryGetValue(dependency.Key, out baseDependencies))
                            {
                                continue;
                            }

                            // copy all entries from base to this runtime
                            foreach (var baseImplementation in baseDependencies.Implementations)
                            {
                                packageDependencies.Implementations.Add(baseImplementation.Key, baseImplementation.Value);
                            }
                        }
                    }
                }
            }

            string destRuntimeFileDir = Path.GetDirectoryName(destRuntimeFilePath);
            if (!String.IsNullOrEmpty(destRuntimeFileDir) && !Directory.Exists(destRuntimeFileDir))
            {
                Directory.CreateDirectory(destRuntimeFileDir);
            }

            formatter.WriteRuntimeFile(destRuntimeFilePath, runtimeFile);

            return true;
        }
 private void WriteRuntimeFile(JObject json, RuntimeFile runtimeFile)
 {
     var runtimes = new JObject();
     json["runtimes"] = runtimes;
     foreach (var x in runtimeFile.Runtimes.Values)
     {
         WriteRuntimeSpec(runtimes, x);
     }
 }
 public RuntimeFile ReadRuntimeFile(JToken json)
 {
     var file = new RuntimeFile();
     foreach (var runtimeSpec in EachProperty(json["runtimes"]).Select(ReadRuntimeSpec))
     {
         file.Runtimes.Add(runtimeSpec.Name, runtimeSpec);
     }
     return file;
 }
 public void WriteRuntimeFile(string filePath, RuntimeFile runtimeFile)
 {
     using (var fileStream = new FileStream(filePath, FileMode.Create))
     {
         using (var textWriter = new StreamWriter(fileStream))
         {
             using (var jsonWriter = new JsonTextWriter(textWriter))
             {
                 jsonWriter.Formatting = Formatting.Indented;
                 var json = new JObject();
                 WriteRuntimeFile(json, runtimeFile);
                 json.WriteTo(jsonWriter);
             }
         }
     }
 }
示例#9
0
        public override bool Execute()
        {
            if (Dependencies == null || Dependencies.Length == 0)
            {
                Log.LogError("Dependencies argument must be specified");
                return(false);
            }

            if (String.IsNullOrEmpty(PackageId))
            {
                Log.LogError("PackageID argument must be specified");
                return(false);
            }

            if (RuntimeJson == null)
            {
                Log.LogError("RuntimeJson argument must be specified");
                return(false);
            }

            RuntimeFileFormatter formatter   = new RuntimeFileFormatter();
            RuntimeFile          runtimeFile = null;
            string sourceRuntimeFilePath     = null;

            if (RuntimeJsonTemplate != null)
            {
                sourceRuntimeFilePath = RuntimeJsonTemplate.GetMetadata("FullPath");
            }
            string destRuntimeFilePath = RuntimeJson.GetMetadata("FullPath");

            // read in existing JSON, if it was provided so that we preserve any
            // hand authored #imports or dependencies
            if (!String.IsNullOrEmpty(sourceRuntimeFilePath))
            {
                runtimeFile = formatter.ReadRuntimeFile(sourceRuntimeFilePath);
            }
            else
            {
                runtimeFile = new RuntimeFile();
            }

            Dictionary <string, string> packageAliases = new Dictionary <string, string>();

            foreach (var dependency in Dependencies)
            {
                string alias = dependency.GetMetadata("PackageAlias");

                if (String.IsNullOrEmpty(alias))
                {
                    continue;
                }

                Log.LogMessage(LogImportance.Low, "Aliasing {0} -> {1}", alias, dependency.ItemSpec);
                packageAliases[alias] = dependency.ItemSpec;
            }

            foreach (var dependency in Dependencies)
            {
                string targetRuntimeId    = dependency.GetMetadata("TargetRuntime");
                string targetPackageId    = dependency.GetMetadata("TargetPackage");
                string targetPackageAlias = dependency.GetMetadata("TargetPackageAlias");
                string dependencyId       = dependency.ItemSpec;
                string dependencyVersion  = dependency.GetMetadata("version");

                if (String.IsNullOrEmpty(targetRuntimeId))
                {
                    Log.LogMessage(LogImportance.Low, "Skipping dependency {0} since it doesn't have a TargetRuntime.", dependency.ItemSpec);
                    continue;
                }

                if (!String.IsNullOrEmpty(targetPackageAlias) && !packageAliases.TryGetValue(targetPackageAlias, out targetPackageId))
                {
                    Log.LogWarning("Dependency {0} specified TargetPackageAlias {1} but no package was found defining this alias.", dependency.ItemSpec, targetPackageAlias);
                }
                else
                {
                    Log.LogMessage(LogImportance.Low, "Using {0} for TargetPackageAlias {1}", targetPackageId, targetPackageAlias);
                }

                RuntimeSpec targetRuntime = null;
                if (!runtimeFile.Runtimes.TryGetValue(targetRuntimeId, out targetRuntime))
                {
                    targetRuntime = new RuntimeSpec()
                    {
                        Name = targetRuntimeId
                    };
                    runtimeFile.Runtimes.Add(targetRuntimeId, targetRuntime);
                }

                if (String.IsNullOrEmpty(targetPackageId))
                {
                    Log.LogMessage(LogImportance.Low, "Dependency {0} has no parent so will assume {1}.", dependency.ItemSpec, PackageId);
                    targetPackageId = PackageId;
                }

                DependencySpec targetPackage = null;
                if (!targetRuntime.Dependencies.TryGetValue(targetPackageId, out targetPackage))
                {
                    targetPackage = new DependencySpec()
                    {
                        Name = targetPackageId
                    };
                    targetRuntime.Dependencies.Add(targetPackageId, targetPackage);
                }

                if (dependencyId == c_emptyDependency)
                {
                    targetPackage.Implementations.Clear();
                }
                else
                {
                    if (String.IsNullOrEmpty(dependencyVersion))
                    {
                        Log.LogWarning("Dependency {0} has no version", dependency.ItemSpec);
                    }

                    ImplementationSpec existing;

                    if (targetPackage.Implementations.TryGetValue(dependencyId, out existing))
                    {
                        string newVersion = CompareSemanticVersion(dependencyVersion, existing.Version) > 0 ? dependencyVersion : existing.Version;
                        Log.LogMessage(LogImportance.Low, "Dependency {0} has been added more than once, {1}, {2}, using {3}", dependencyId, existing.Version, dependencyVersion, newVersion);
                        dependencyVersion = newVersion;
                    }

                    targetPackage.Implementations[dependencyId] = new ImplementationSpec()
                    {
                        Name = dependencyId, Version = dependencyVersion
                    };
                }
            }

            if (EnsureBase)
            {
                // RID base is used to lift the library packages up to a baseline version
                // we don't want to obscure these associations or else we may bring in
                // old reference packages prior to an implementation package split
                // and thus, clashing implementations.

                // EG: Version 1 of System.Banana had a single implementation that was
                //     windows specific.
                //     Version 2 split the implementation to Windows and Unix
                //     If Version 1 was referenced we'd get both the V1 windows implementation
                //     and the V2 unix implementation when resolving for Unix

                // To avoid this problem we always ensure that we have the matching
                // reference package in the runtime graph.

                RuntimeSpec baseRuntime = null;
                if (runtimeFile.Runtimes.TryGetValue("base", out baseRuntime))
                {
                    // look at all sections other than base
                    foreach (var runtime in runtimeFile.Runtimes.Values.Where(rt => rt != baseRuntime))
                    {
                        // examine each dependency and copy the content from base, if it exists
                        foreach (var dependency in runtime.Dependencies)
                        {
                            string         packageName         = dependency.Key;
                            DependencySpec packageDependencies = dependency.Value;

                            // are there any entries for this package in base?
                            DependencySpec baseDependencies = null;
                            if (!baseRuntime.Dependencies.TryGetValue(dependency.Key, out baseDependencies))
                            {
                                continue;
                            }

                            // copy all entries from base to this runtime
                            foreach (var baseImplementation in baseDependencies.Implementations)
                            {
                                packageDependencies.Implementations.Add(baseImplementation.Key, baseImplementation.Value);
                            }
                        }
                    }
                }
            }

            string destRuntimeFileDir = Path.GetDirectoryName(destRuntimeFilePath);

            if (!String.IsNullOrEmpty(destRuntimeFileDir) && !Directory.Exists(destRuntimeFileDir))
            {
                Directory.CreateDirectory(destRuntimeFileDir);
            }

            formatter.WriteRuntimeFile(destRuntimeFilePath, runtimeFile);

            return(true);
        }
        private void WriteRuntimeFile(JObject json, RuntimeFile runtimeFile)
        {
            var runtimes = new JObject();
            json["runtimes"] = runtimes;
            foreach (var x in runtimeFile.Runtimes.Values)
            {
                WriteRuntimeSpec(runtimes, x);
            }

            if (runtimeFile.Supports.Count > 0)
            {
                var supports = new JObject();
                json["supports"] = supports;
                foreach(var s in runtimeFile.Supports.Values)
                {
                    WriteSupportSpec(supports, s);
                }
            }
        }