Skip to content

Commit bd83103

Browse files
committed
fix: address copilot
1 parent 5eb56ec commit bd83103

4 files changed

Lines changed: 36 additions & 55 deletions

File tree

src/Stryker.Core/Stryker.Core/Initialisation/InputFileResolver.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,6 @@ private IAnalyzerResults AnalyzeSingleProject(ProjectAnalyzerContext project, IS
371371
buildResult = project.Analyze(forceFramework: true);
372372
buildResultOverallSuccess = project.HasValidResults();
373373
}
374-
375374
}
376375

377376
if (options.DiagMode || _logger.IsEnabled(LogLevel.Debug))

src/Stryker.Core/Stryker.Core/Initialisation/ProjectAnalyzerContext.cs

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using Buildalyzer;
77
using Buildalyzer.Environment;
88
using Microsoft.Extensions.Logging;
9-
using Stryker.Abstractions.Exceptions;
109
using Stryker.Utilities.Buildalyzer;
1110

1211
namespace Stryker.Core.Initialisation;
@@ -116,52 +115,6 @@ private void InitializeTargetFrameworks()
116115

117116
public IEnumerable<string> GetProjectReferences() => AnalyzerLastResults?.SelectMany(r => r.ProjectReferences).Distinct();
118117

119-
public IAnalyzerResult SelectAnalyzerResult()
120-
{
121-
var validResults = AnalyzerLastResults.ToList();
122-
if (validResults.Count == 0)
123-
{
124-
throw new InputException($"No valid project analysis results could be found for '{ProjectFileName}'.");
125-
}
126-
127-
if (_framework is null)
128-
{
129-
// we try to avoid desktop versions
130-
return PickFrameworkVersion();
131-
}
132-
133-
var resultForRequestedFramework = validResults.Find(a => a.TargetFramework == _framework);
134-
if (resultForRequestedFramework is not null)
135-
{
136-
return resultForRequestedFramework;
137-
}
138-
// if there is only one available framework version, we log an info
139-
if (validResults.Count == 1)
140-
{
141-
var singleAnalyzerResult = validResults[0];
142-
_logger.LogInformation(
143-
"Could not find a valid analysis for target {0} for project '{1}'. Selected version is {2}.",
144-
_framework, ProjectFileName, singleAnalyzerResult.TargetFramework);
145-
return singleAnalyzerResult;
146-
}
147-
148-
var firstAnalyzerResult = PickFrameworkVersion();
149-
var availableFrameworks = validResults.Select(a => a.TargetFramework).Distinct();
150-
_logger.LogWarning(
151-
"""
152-
Could not find a valid analysis for target {0} for project '{1}'.
153-
The available target frameworks are: {2}.
154-
selected version is {3}.
155-
""", _framework, ProjectFileName, string.Join(',', availableFrameworks), firstAnalyzerResult.TargetFramework);
156-
157-
return firstAnalyzerResult;
158-
159-
IAnalyzerResult PickFrameworkVersion()
160-
{
161-
return validResults.Find(a => a.IsValid() && !a.TargetsFullFramework()) ?? validResults[0];
162-
}
163-
}
164-
165118
private static readonly HashSet<string> ImportantProperties =
166119
["Configuration", "Platform", "AssemblyName", "Configurations", "TargetPath", "OS"];
167120

@@ -236,7 +189,7 @@ private void DumpTestAnalyzerResult(StringBuilder log, IAnalyzerResult analyzerR
236189

237190
public bool BuildsAnAssembly() => AnalyzerLastResults?.Any(p => p.BuildsAnAssembly()) == true;
238191

239-
public bool FindMatchingVariant(string assemblyPath, out IAnalyzerResult analyzerResult)
192+
public bool FindMatchingVariant(string assemblyPath, out IAnalyzerResult? analyzerResult)
240193
{
241194
if (AnalyzerLastResults == null)
242195
{

src/Stryker.Solutions.Test/SolutionFileShould.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void DetectPlatformIfNotSpecified(string platform)
4545
// Arrange
4646
List<string> projects = ["Project.csproj", "Test.csproj"];
4747
// Act
48-
var solution = SolutionFile.BuildFromProjectList( projects, [platform]);
48+
var solution = SolutionFile.BuildFromProjectList( projects, [platform], [platform]);
4949

5050
// Assert
5151
solution.GetProjectsWithDetails("Debug").ShouldBe(projects.Select(p => (p, "Debug", platform)));

src/Stryker.Solutions/SolutionFile.cs

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ private string GetEffectiveBuildType(string? buildType)
173173
/// <param name="configuration">requested configuration</param>
174174
/// <param name="platform">requested platform</param>
175175
/// <returns></returns>
176-
public (string configuration, string platform) GetProjectConfiguration(string filename, string configuration, string platform)
176+
public (string configuration, string platform) GetProjectConfiguration(string filename, string? configuration, string? platform)
177177
{
178178
configuration = GetEffectiveBuildType(configuration);
179179
platform ??= DefaultPlatform;
@@ -189,30 +189,59 @@ private string GetEffectiveBuildType(string? buildType)
189189
/// </summary>
190190
/// <param name="projects">list of csproj filenames</param>
191191
/// <param name="platforms">list of declared platforms. Default to AnyCpu and x86</param>
192+
/// <param name="solutionPlatforms">list of solution level platforms</param>
192193
/// <returns>a solution instance</returns>
193194
/// <remarks>This method is used for testing purposes. It is mandatory as the underlying solution parser does not support any form of mocking</remarks>
194-
public static SolutionFile BuildFromProjectList(List<string> projects, string[]? platforms = null)
195+
public static SolutionFile BuildFromProjectList(List<string> projects, string[]? platforms = null
196+
, string[]? solutionPlatforms = null)
195197
{
196198
var result = new SolutionFile();
199+
solutionPlatforms = DefineSolutionPlatforms(platforms, solutionPlatforms);
197200
platforms ??= [ "AnyCPU", "x86" ];
201+
if (platforms.Length != solutionPlatforms.Length)
202+
{
203+
throw new ArgumentException("The number of platforms should be the same as the number of solution platforms, if specified.");
204+
}
198205
// default to Debug|Any CPU
199206
string[] buildTypes = ["Debug", "Release"];
200207
foreach (var buildType in buildTypes)
201208
{
202-
foreach (var platform in platforms)
209+
for (var index = 0; index < platforms.Length; index++)
203210
{
211+
var platform = platforms[index];
204212
var projectDict = new Dictionary<string, (string buildType, string platform)>();
205213
foreach (var project in projects)
206214
{
207215
projectDict[project] = (buildType, platform);
208216
}
209-
var solutionPlatform = platform == "AnyCPU" ? "Any CPU" : platform;
210-
result._configurations.Add((buildType, solutionPlatform), projectDict);
217+
218+
result._configurations.Add((buildType, solutionPlatforms[index]), projectDict);
211219
}
212220
}
213221
return result;
214222
}
215223

224+
private static string[] DefineSolutionPlatforms(string[]? platforms, string[]? solutionPlatforms)
225+
{
226+
if (solutionPlatforms == null)
227+
{
228+
if (platforms == null)
229+
{
230+
solutionPlatforms = [ "Any CPU", "x86" ];
231+
}
232+
else
233+
{
234+
solutionPlatforms = new string[platforms.Length];
235+
for (var i = 0; i < platforms.Length; i++)
236+
{
237+
solutionPlatforms[i] = platforms[i] == DefaultProjectBuildType ? DefaultSolutionType : platforms[i];
238+
}
239+
}
240+
}
241+
242+
return solutionPlatforms;
243+
}
244+
216245
private static SolutionFile AnalyzeSolution(string solutionPath, SolutionModel solution)
217246
{
218247
// extract needed information

0 commit comments

Comments
 (0)