/// <summary>
        /// Generates a table in markdown that lists the API version supported by
        /// various packages at all levels of NETStandard.
        /// </summary>
        /// <returns></returns>
        public override bool Execute()
        {
            if (PackageReports == null || PackageReports.Length == 0)
            {
                Log.LogError("PackageReports argument must be specified");
                return(false);
            }

            if (TargetMoniker == null || TargetMoniker.Length == 0)
            {
                Log.LogError("TargetMoniker argument must be specified");
                return(false);
            }

            NuGetFramework fx = NuGetFramework.Parse(TargetMoniker);

            string targetString = String.IsNullOrEmpty(TargetRuntime) ? fx.ToString() : $"{fx}/{TargetRuntime}";

            var compileAssets = new List <ITaskItem>();
            var runtimeAssets = new List <ITaskItem>();
            var nativeAssets  = new List <ITaskItem>();
            var buildProjects = new List <BuildProject>();

            foreach (var reportPath in PackageReports)
            {
                var report = PackageReport.Load(reportPath);

                Target target = null;
                if (report.Targets.TryGetValue(targetString, out target))
                {
                    compileAssets.AddRange(target.CompileAssets.Select(c => ItemFromApplicableAsset(c, report.Id, report.Version)));
                    buildProjects.AddRange(target.CompileAssets.Select(c => c.SourceProject).Where(bp => bp != null));
                    runtimeAssets.AddRange(target.RuntimeAssets.Select(r => ItemFromApplicableAsset(r, report.Id, report.Version)));
                    buildProjects.AddRange(target.RuntimeAssets.Select(r => r.SourceProject).Where(bp => bp != null));
                    nativeAssets.AddRange(target.NativeAssets.Select(r => ItemFromApplicableAsset(r, report.Id, report.Version)));
                    buildProjects.AddRange(target.NativeAssets.Select(r => r.SourceProject).Where(bp => bp != null));
                }
                else
                {
                    Log.LogMessage($"No assets found for '{report.Id}' applicable to '{targetString}'.");
                }
            }

            CompileAssets = compileAssets.ToArray();
            RuntimeAssets = runtimeAssets.ToArray();
            NativeAssets  = nativeAssets.ToArray();
            BuildProjects = buildProjects.Distinct().Select(bp => bp.ToItem()).ToArray();

            return(!Log.HasLoggedErrors);
        }
        public override bool Execute()
        {
            var supportedPackages = new List <ITaskItem>();

            foreach (var packageReport in PackageReports.NullAsEmpty())
            {
                var report         = PackageReport.Load(packageReport);
                var packageId      = report.Id;
                var packageVersion = report.Version;

                var supportedTargets = report.Targets.Values.Where(target => report.SupportedFrameworks.ContainsKey(target.Framework));
                var fxRIDGroupings   = supportedTargets.GroupBy(target => target.Framework, target => target.RuntimeID);

                foreach (var fxRIDGrouping in fxRIDGroupings)
                {
                    var fx      = fxRIDGrouping.Key;
                    var rids    = fxRIDGrouping.ToArray();
                    var nugetFx = NuGetFramework.Parse(fx);

                    var supportedPackage = new TaskItem(packageId);
                    supportedPackage.SetMetadata("Version", packageVersion);
                    supportedPackage.SetMetadata("TargetFramework", fx);
                    supportedPackage.SetMetadata("TargetFrameworkShort", nugetFx.GetShortFolderName());

                    var ridList = string.Join(";", rids);

                    if (!String.IsNullOrEmpty(ridList))
                    {
                        supportedPackage.SetMetadata("RuntimeIdentifiers", ridList);
                    }

                    supportedPackages.Add(supportedPackage);
                }
            }

            SupportedPackages = supportedPackages.ToArray();

            return(!Log.HasLoggedErrors);
        }
 private void LoadReport()
 {
     _report = PackageReport.Load(ReportFile);
 }
        /// <summary>
        /// Generates a table in markdown that lists the API version supported by
        /// various packages at all levels of NETStandard.
        /// </summary>
        /// <returns></returns>
        public override bool Execute()
        {
            if (Reports == null || Reports.Length == 0)
            {
                Log.LogError("Reports argument must be specified");
                return(false);
            }

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

            string docDir = Path.GetDirectoryName(DocFilePath);

            if (!Directory.Exists(docDir))
            {
                Directory.CreateDirectory(docDir);
            }

            SortedSet <Version> knownNetStandardVersions = new SortedSet <Version>();
            List <SupportRow>   rows = new List <SupportRow>(Reports.Length);

            foreach (var reportPath in Reports.Select(r => r.GetMetadata("FullPath")))
            {
                SupportRow row = new SupportRow();
                row.Name             = Path.GetFileNameWithoutExtension(reportPath);
                row.SuportedVersions = new SortedSet <NETStandardApiVersion>();

                var report = PackageReport.Load(reportPath);

                foreach (var supportedFramework in report.SupportedFrameworks)
                {
                    var fx = NuGetFramework.Parse(supportedFramework.Key);

                    if (fx.Framework == FrameworkConstants.FrameworkIdentifiers.NetStandard)
                    {
                        row.SuportedVersions.Add(new NETStandardApiVersion(fx.Version, new Version(supportedFramework.Value.ToString())));
                        knownNetStandardVersions.Add(fx.Version);
                    }
                }
                rows.Add(row);
            }

            StringBuilder table = new StringBuilder();

            table.AppendLine($"| Contract | {String.Join(" | ", knownNetStandardVersions.Select(v => v.ToString(2)))} |");
            table.AppendLine($"| -------- | {String.Join(" | ", Enumerable.Repeat("---", knownNetStandardVersions.Count))}");

            foreach (var row in rows.OrderBy(r => r.Name))
            {
                if (row.SuportedVersions.Count == 0)
                {
                    Log.LogMessage($"Skipping {row.Name} since it has no supported NETStandard versions");
                    continue;
                }

                table.Append($"| {row.Name} |");

                foreach (var netStandardVersion in knownNetStandardVersions)
                {
                    var apiVersion = row.SuportedVersions.LastOrDefault(a => a.NETStandardVersion <= netStandardVersion);

                    table.Append(" ");
                    if (apiVersion != null)
                    {
                        table.Append(apiVersion.APIVersion.ToString(3));
                    }
                    table.Append(" |");
                }
                table.AppendLine();
            }

            if (!InsertIntoFile)
            {
                File.WriteAllText(DocFilePath, table.ToString());
            }
            else
            {
                if (!File.Exists(DocFilePath))
                {
                    Log.LogError($"InsertIntoFile was specified as true but {DocFilePath} did not exist.");
                    return(false);
                }

                string originalText = File.ReadAllText(DocFilePath);
                int    startIndex   = originalText.IndexOf(startMarker);

                if (startIndex < 0)
                {
                    Log.LogError($"InsertIntoFile was specified as true but could not locate insertion start text \"{startMarker}\".");
                    return(false);
                }
                startIndex += startMarker.Length;
                // skip any white-space / new line
                while (startIndex < originalText.Length && Char.IsWhiteSpace(originalText[startIndex]))
                {
                    startIndex++;
                }

                int endIndex = originalText.IndexOf(endMarker, startIndex);

                if (endIndex < 0)
                {
                    Log.LogError($"InsertIntoFile was specified as true but could not locate insertion end text \"{endMarker}\".");
                    return(false);
                }
                var docText = new StringBuilder(originalText);
                docText.Remove(startIndex, endIndex - startIndex);
                docText.Insert(startIndex, table.ToString());

                File.WriteAllText(DocFilePath, docText.ToString(), Encoding.UTF8);
            }


            return(!Log.HasLoggedErrors);
        }
 // Making this method protected virtual for tests.
 protected virtual PackageReport GetPackageReportFromPath()
 {
     return(PackageReport.Load(PackageReportPath));
 }
Example #6
0
 // Making this method protected virtual for tests.
 protected virtual PackageReport GetPackageReportFromPath(string path)
 {
     return(PackageReport.Load(path));
 }
Example #7
0
        public override bool Execute()
        {
            var frameworks = Frameworks.NullAsEmpty().ToDictionary(
                i => NuGetFramework.Parse(i.ItemSpec),
                i =>
            {
                var rids = i.GetMetadata("RuntimeIds");
                return(String.IsNullOrEmpty(rids) ? new HashSet <string>() : new HashSet <string>(rids.Split(';')));
            },
                NuGetFramework.Comparer);

            var layoutFiles = new List <ITaskItem>();

            foreach (var packageReportFile in PackageReports)
            {
                var packageReport = PackageReport.Load(packageReportFile);

                foreach (var targetInfo in packageReport.Targets)
                {
                    var targetName = targetInfo.Key;
                    var target     = targetInfo.Value;

                    var targetParts = targetName.Split('/');

                    var    fx  = NuGetFramework.Parse(targetParts[0]);
                    string rid = null;

                    if (targetParts.Length > 1)
                    {
                        rid = targetParts[1];
                    }

                    if (frameworks.Count != 0)
                    {
                        HashSet <string> rids = null;

                        if (!frameworks.TryGetValue(fx, out rids))
                        {
                            Log.LogMessage(LogImportance.Low, $"Skipping {fx} since it is not in {nameof(Frameworks)}");
                            continue;
                        }

                        if (rid != null && rids.Count > 0 && !rids.Contains(rid))
                        {
                            Log.LogMessage(LogImportance.Low, $"Skipping {fx}/{rid} since it is not in {nameof(Frameworks)}");
                            continue;
                        }
                    }

                    if (!packageReport.SupportedFrameworks.ContainsKey(fx.ToString()))
                    {
                        Log.LogMessage(LogImportance.Low, $"Skipping {fx} since it is not supported");
                        continue;
                    }

                    var fxFolder = fx.GetShortFolderName();

                    if (rid == null)
                    {
                        // only consider compile assets for RID-less target
                        layoutFiles.AddRange(CreateLayoutFiles(target.CompileAssets, $"ref\\{fxFolder}", "Compile"));
                    }

                    layoutFiles.AddRange(CreateLayoutFiles(target.RuntimeAssets, $"runtimes\\{rid}\\lib\\{fxFolder}", "Runtime"));
                    layoutFiles.AddRange(CreateLayoutFiles(target.NativeAssets, $"runtimes\\{rid}\\native", "Native"));
                }
            }

            LayoutFiles = layoutFiles.ToArray();

            return(!Log.HasLoggedErrors);
        }