|
1 | | -// Licensed to the .NET Foundation under one or more agreements. |
2 | | -// The .NET Foundation licenses this file to you under the MIT license. |
3 | | - |
4 | | -using System; |
5 | | -using System.Collections.Generic; |
6 | | -using System.Linq; |
7 | | -using System.Threading.Tasks; |
8 | | -using DotNet.Models; |
9 | | -using DotNet.Releases.Extensions; |
10 | | -using Microsoft.Deployment.DotNet.Releases; |
11 | | - |
12 | | -namespace DotNet.Releases |
13 | | -{ |
14 | | - internal class UnsupportedProjectReporter : IUnsupportedProjectReporter |
15 | | - { |
16 | | - readonly ICoreReleaseIndexService _coreReleaseIndexService; |
17 | | - readonly IFrameworkReleaseService _frameworkReleaseService; |
18 | | - |
19 | | - public UnsupportedProjectReporter( |
20 | | - ICoreReleaseIndexService coreReleaseIndexService, |
21 | | - IFrameworkReleaseService frameworkReleaseService) => |
22 | | - (_coreReleaseIndexService, _frameworkReleaseService) = |
23 | | - (coreReleaseIndexService, frameworkReleaseService); |
24 | | - |
25 | | - async IAsyncEnumerable<ProjectSupportReport> IUnsupportedProjectReporter.ReportAsync(Project project) |
26 | | - { |
27 | | - HashSet<TargetFrameworkMonikerSupport> resultingSupports = new(); |
28 | | - |
29 | | - var products = await _coreReleaseIndexService.GetReleasesAsync(); |
30 | | - foreach (var product in products.Keys) |
31 | | - { |
32 | | - var tfmSupports = |
33 | | - project.Tfms.Select( |
34 | | - tfm => TryEvaluateReleaseSupport( |
35 | | - tfm, product.ProductVersion, |
36 | | - product, out var tfmSupport) |
37 | | - ? tfmSupport : null) |
38 | | - .Where(tfmSupport => tfmSupport is not null); |
39 | | - |
40 | | - if (tfmSupports.Any()) |
41 | | - { |
42 | | - var supports = await Task.WhenAll( |
43 | | - tfmSupports.Where(support => support?.IsUnsupported ?? false) |
44 | | - .Select( |
45 | | - async support => |
46 | | - { |
47 | | - var release = await _coreReleaseIndexService.GetNextLtsVersionAsync( |
48 | | - product.LatestReleaseVersion.ToString()); |
49 | | - |
50 | | - return support! with |
51 | | - { |
52 | | - NearestLtsVersion = release!.GetTargetFrameworkMoniker() |
53 | | - }; |
54 | | - })); |
55 | | - |
56 | | - foreach (var support in supports) |
57 | | - { |
58 | | - resultingSupports.Add(support); |
59 | | - } |
60 | | - } |
61 | | - } |
62 | | - |
63 | | - await foreach (var frameworkRelease |
64 | | - in _frameworkReleaseService.GetAllReleasesAsync()) |
65 | | - { |
66 | | - var tfmSupports = |
67 | | - project.Tfms.Select( |
68 | | - tfm => TryEvaluateReleaseSupport( |
69 | | - tfm, frameworkRelease!.Version, |
70 | | - frameworkRelease, out var tfmSupport) |
71 | | - ? tfmSupport : null) |
72 | | - .Where(tfmSupport => tfmSupport is not null); |
73 | | - |
74 | | - if (tfmSupports.Any()) |
75 | | - { |
76 | | - var supports = await Task.WhenAll( |
77 | | - tfmSupports.Where(support => support?.IsUnsupported ?? false) |
78 | | - .Select( |
79 | | - async support => |
80 | | - { |
81 | | - var release = await _frameworkReleaseService.GetNextLtsVersionAsync( |
82 | | - (LabeledVersion)frameworkRelease.Version); |
83 | | - |
84 | | - return support! with |
85 | | - { |
86 | | - NearestLtsVersion = release!.TargetFrameworkMoniker |
87 | | - }; |
88 | | - })); |
89 | | - |
90 | | - foreach (var support in supports) |
91 | | - { |
92 | | - resultingSupports.Add(support); |
93 | | - } |
94 | | - } |
95 | | - } |
96 | | - |
97 | | - if (resultingSupports.Any()) |
98 | | - yield return new(project, resultingSupports); |
99 | | - } |
100 | | - |
101 | | - static bool TryEvaluateReleaseSupport( |
102 | | - string tfm, string version, |
103 | | - Product product, |
104 | | - out TargetFrameworkMonikerSupport? tfmSupport) |
105 | | - { |
106 | | - var release = ReleaseFactory.Create( |
107 | | - product, |
108 | | - pr => $"{pr.ProductName} {pr.ProductVersion}", |
109 | | - product.ProductName switch |
110 | | - { |
111 | | - ".NET" => $"net{product.ProductVersion}", |
112 | | - ".NET Core" => $"netcoreapp{product.ProductVersion}", |
113 | | - _ => product.ProductVersion |
114 | | - }, |
115 | | - product.SupportPhase, |
116 | | - product.EndOfLifeDate, |
117 | | - product.ReleasesJson.ToString()); |
118 | | - |
119 | | - if (TargetFrameworkMonikerMap.RawMapsToKnown(tfm, release.TargetFrameworkMoniker)) |
120 | | - { |
121 | | - var isOutOfSupport = product.IsOutOfSupport(); |
122 | | - tfmSupport = new(tfm, version, isOutOfSupport, release); |
123 | | - return true; |
124 | | - } |
125 | | - |
126 | | - tfmSupport = default; |
127 | | - return false; |
128 | | - } |
129 | | - |
130 | | - static bool TryEvaluateReleaseSupport( |
131 | | - string tfm, string version, |
132 | | - IRelease release, |
133 | | - out TargetFrameworkMonikerSupport? tfmSupport) |
134 | | - { |
135 | | - if (TargetFrameworkMonikerMap.RawMapsToKnown(tfm, release.TargetFrameworkMoniker)) |
136 | | - { |
137 | | - var isOutOfSupport = release.SupportPhase == SupportPhase.EOL || |
138 | | - release.EndOfLifeDate?.Date <= DateTime.Now.Date; |
139 | | - tfmSupport = new(tfm, version, isOutOfSupport, release); |
140 | | - return true; |
141 | | - } |
142 | | - |
143 | | - tfmSupport = default; |
144 | | - return false; |
145 | | - } |
146 | | - } |
147 | | -} |
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the MIT license. |
| 3 | + |
| 4 | +using System; |
| 5 | +using System.Collections.Generic; |
| 6 | +using System.Linq; |
| 7 | +using System.Threading.Tasks; |
| 8 | +using DotNet.Models; |
| 9 | +using DotNet.Releases.Extensions; |
| 10 | +using Microsoft.Deployment.DotNet.Releases; |
| 11 | + |
| 12 | +namespace DotNet.Releases |
| 13 | +{ |
| 14 | + internal class UnsupportedProjectReporter : IUnsupportedProjectReporter |
| 15 | + { |
| 16 | + readonly ICoreReleaseIndexService _coreReleaseIndexService; |
| 17 | + readonly IFrameworkReleaseService _frameworkReleaseService; |
| 18 | + |
| 19 | + public UnsupportedProjectReporter( |
| 20 | + ICoreReleaseIndexService coreReleaseIndexService, |
| 21 | + IFrameworkReleaseService frameworkReleaseService) => |
| 22 | + (_coreReleaseIndexService, _frameworkReleaseService) = |
| 23 | + (coreReleaseIndexService, frameworkReleaseService); |
| 24 | + |
| 25 | + async IAsyncEnumerable<ProjectSupportReport> IUnsupportedProjectReporter.ReportAsync( |
| 26 | + Project project, int outOfSupportWithinDays) |
| 27 | + { |
| 28 | + HashSet<TargetFrameworkMonikerSupport> resultingSupports = new(); |
| 29 | + DateTime outOfSupportWithinDate = DateTime.Now.Date.AddDays(outOfSupportWithinDays); |
| 30 | + |
| 31 | + var products = await _coreReleaseIndexService.GetReleasesAsync(); |
| 32 | + foreach (var product in products.Keys) |
| 33 | + { |
| 34 | + var tfmSupports = |
| 35 | + project.Tfms.Select( |
| 36 | + tfm => TryEvaluateReleaseSupport( |
| 37 | + tfm, product.ProductVersion, |
| 38 | + product, outOfSupportWithinDate, out var tfmSupport) |
| 39 | + ? tfmSupport : null) |
| 40 | + .Where(tfmSupport => tfmSupport is not null); |
| 41 | + |
| 42 | + if (tfmSupports.Any()) |
| 43 | + { |
| 44 | + var supports = await Task.WhenAll( |
| 45 | + tfmSupports.Where(support => support?.IsUnsupported ?? false) |
| 46 | + .Select( |
| 47 | + async support => |
| 48 | + { |
| 49 | + var release = await _coreReleaseIndexService.GetNextLtsVersionAsync( |
| 50 | + product.LatestReleaseVersion.ToString()); |
| 51 | + |
| 52 | + return support! with |
| 53 | + { |
| 54 | + NearestLtsVersion = release!.GetTargetFrameworkMoniker() |
| 55 | + }; |
| 56 | + })); |
| 57 | + |
| 58 | + foreach (var support in supports) |
| 59 | + { |
| 60 | + resultingSupports.Add(support); |
| 61 | + } |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + await foreach (var frameworkRelease |
| 66 | + in _frameworkReleaseService.GetAllReleasesAsync()) |
| 67 | + { |
| 68 | + var tfmSupports = |
| 69 | + project.Tfms.Select( |
| 70 | + tfm => TryEvaluateReleaseSupport( |
| 71 | + tfm, frameworkRelease!.Version, |
| 72 | + frameworkRelease, outOfSupportWithinDate, out var tfmSupport) |
| 73 | + ? tfmSupport : null) |
| 74 | + .Where(tfmSupport => tfmSupport is not null); |
| 75 | + |
| 76 | + if (tfmSupports.Any()) |
| 77 | + { |
| 78 | + var supports = await Task.WhenAll( |
| 79 | + tfmSupports.Where(support => support?.IsUnsupported ?? false) |
| 80 | + .Select( |
| 81 | + async support => |
| 82 | + { |
| 83 | + var release = await _frameworkReleaseService.GetNextLtsVersionAsync( |
| 84 | + (LabeledVersion)frameworkRelease.Version); |
| 85 | + |
| 86 | + return support! with |
| 87 | + { |
| 88 | + NearestLtsVersion = release!.TargetFrameworkMoniker |
| 89 | + }; |
| 90 | + })); |
| 91 | + |
| 92 | + foreach (var support in supports) |
| 93 | + { |
| 94 | + resultingSupports.Add(support); |
| 95 | + } |
| 96 | + } |
| 97 | + } |
| 98 | + |
| 99 | + if (resultingSupports.Any()) |
| 100 | + yield return new(project, resultingSupports); |
| 101 | + } |
| 102 | + |
| 103 | + static bool TryEvaluateReleaseSupport( |
| 104 | + string tfm, string version, |
| 105 | + Product product, |
| 106 | + DateTime outOfSupportWithinDate, |
| 107 | + out TargetFrameworkMonikerSupport? tfmSupport) |
| 108 | + { |
| 109 | + var release = ReleaseFactory.Create( |
| 110 | + product, |
| 111 | + pr => $"{pr.ProductName} {pr.ProductVersion}", |
| 112 | + product.ProductName switch |
| 113 | + { |
| 114 | + ".NET" => $"net{product.ProductVersion}", |
| 115 | + ".NET Core" => $"netcoreapp{product.ProductVersion}", |
| 116 | + _ => product.ProductVersion |
| 117 | + }, |
| 118 | + product.SupportPhase, |
| 119 | + product.EndOfLifeDate, |
| 120 | + product.ReleasesJson.ToString()); |
| 121 | + |
| 122 | + if (TargetFrameworkMonikerMap.RawMapsToKnown(tfm, release.TargetFrameworkMoniker)) |
| 123 | + { |
| 124 | + var isOutOfSupport = product.IsOutOfSupport() || |
| 125 | + product.EndOfLifeDate <= outOfSupportWithinDate; |
| 126 | + |
| 127 | + tfmSupport = new(tfm, version, isOutOfSupport, release); |
| 128 | + return true; |
| 129 | + } |
| 130 | + |
| 131 | + tfmSupport = default; |
| 132 | + return false; |
| 133 | + } |
| 134 | + |
| 135 | + static bool TryEvaluateReleaseSupport( |
| 136 | + string tfm, string version, |
| 137 | + IRelease release, |
| 138 | + DateTime outOfSupportWithinDate, |
| 139 | + out TargetFrameworkMonikerSupport? tfmSupport) |
| 140 | + { |
| 141 | + if (TargetFrameworkMonikerMap.RawMapsToKnown(tfm, release.TargetFrameworkMoniker)) |
| 142 | + { |
| 143 | + var isOutOfSupport = release.SupportPhase == SupportPhase.EOL || |
| 144 | + release.EndOfLifeDate?.Date <= outOfSupportWithinDate; |
| 145 | + |
| 146 | + tfmSupport = new(tfm, version, isOutOfSupport, release); |
| 147 | + return true; |
| 148 | + } |
| 149 | + |
| 150 | + tfmSupport = default; |
| 151 | + return false; |
| 152 | + } |
| 153 | + } |
| 154 | +} |
0 commit comments