Skip to content

Commit e47a8ff

Browse files
committed
use AnalyzerLoggingContext instead of LoggingService in BuildCheckManager
1 parent bc63e18 commit e47a8ff

6 files changed

Lines changed: 22 additions & 18 deletions

File tree

src/Build/BackEnd/Components/RequestBuilder/RequestBuilder.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
1010
using System.Threading;
1111
using System.Threading.Tasks;
1212
using Microsoft.Build.BackEnd.Logging;
13-
using Microsoft.Build.Experimental.BuildCheck.Infrastructure;
1413
using Microsoft.Build.Collections;
1514
using Microsoft.Build.Evaluation;
1615
using Microsoft.Build.Eventing;
1716
using Microsoft.Build.Exceptions;
1817
using Microsoft.Build.Execution;
1918
using Microsoft.Build.Experimental.BuildCheck;
19+
using Microsoft.Build.Experimental.BuildCheck.Infrastructure;
20+
using Microsoft.Build.Experimental.BuildCheck.Logging;
2021
using Microsoft.Build.Framework;
2122
using Microsoft.Build.Internal;
2223
using Microsoft.Build.Shared;
@@ -1123,7 +1124,7 @@ private async Task<BuildResult> BuildProject()
11231124
{
11241125
buildCheckManager.StartProjectEvaluation(
11251126
BuildCheckDataSource.BuildExecution,
1126-
_requestEntry.Request.ParentBuildEventContext,
1127+
new AnalyzerLoggingContext(_nodeLoggingContext.LoggingService, _requestEntry.Request.ParentBuildEventContext),
11271128
_requestEntry.RequestConfiguration.ProjectFullPath);
11281129

11291130
_requestEntry.RequestConfiguration.LoadProjectIntoConfiguration(

src/Build/BuildCheck/Infrastructure/BuildCheckConnectorLogger.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ private void HandleProjectEvaluationStartedEvent(ProjectEvaluationStartedEventAr
6666
{
6767
if (!IsMetaProjFile(eventArgs.ProjectFile))
6868
{
69-
_buildCheckManager.StartProjectEvaluation(BuildCheckDataSource.EventArgs, eventArgs.BuildEventContext!, eventArgs.ProjectFile!);
69+
_buildCheckManager.StartProjectEvaluation(
70+
BuildCheckDataSource.EventArgs,
71+
_loggingContextFactory.CreateLoggingContext(eventArgs.BuildEventContext!),
72+
eventArgs.ProjectFile!);
7073
}
7174
}
7275

src/Build/BuildCheck/Infrastructure/BuildCheckManagerProvider.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
using System.Threading;
99
using Microsoft.Build.BackEnd;
1010
using Microsoft.Build.BackEnd.Logging;
11+
using Microsoft.Build.Experimental.BuildCheck;
1112
using Microsoft.Build.Experimental.BuildCheck.Acquisition;
1213
using Microsoft.Build.Experimental.BuildCheck.Analyzers;
1314
using Microsoft.Build.Experimental.BuildCheck.Logging;
14-
using Microsoft.Build.Experimental.BuildCheck;
1515
using Microsoft.Build.Framework;
1616
using Microsoft.Build.Shared;
1717

@@ -46,7 +46,7 @@ public void InitializeComponent(IBuildComponentHost host)
4646
IBuildCheckManager instance;
4747
if (host!.BuildParameters.IsBuildCheckEnabled)
4848
{
49-
instance = new BuildCheckManager(host.LoggingService);
49+
instance = new BuildCheckManager();
5050
}
5151
else
5252
{
@@ -66,17 +66,15 @@ internal sealed class BuildCheckManager : IBuildCheckManager
6666
private readonly TracingReporter _tracingReporter = new TracingReporter();
6767
private readonly ConfigurationProvider _configurationProvider = new ConfigurationProvider();
6868
private readonly BuildCheckCentralContext _buildCheckCentralContext;
69-
private readonly ILoggingService _loggingService;
7069
private readonly List<BuildAnalyzerFactoryContext> _analyzersRegistry;
7170
private readonly bool[] _enabledDataSources = new bool[(int)BuildCheckDataSource.ValuesCount];
7271
private readonly BuildEventsProcessor _buildEventsProcessor;
7372
private readonly IBuildCheckAcquisitionModule _acquisitionModule;
7473

75-
internal BuildCheckManager(ILoggingService loggingService)
74+
internal BuildCheckManager()
7675
{
7776
_analyzersRegistry = new List<BuildAnalyzerFactoryContext>();
7877
_acquisitionModule = new BuildCheckAcquisitionModule();
79-
_loggingService = loggingService;
8078
_buildCheckCentralContext = new(_configurationProvider);
8179
_buildEventsProcessor = new(_buildCheckCentralContext);
8280
}
@@ -205,7 +203,7 @@ internal void RegisterCustomAnalyzer(
205203
}
206204
}
207205

208-
private void SetupSingleAnalyzer(BuildAnalyzerFactoryContext analyzerFactoryContext, string projectFullPath, BuildEventContext buildEventContext)
206+
private void SetupSingleAnalyzer(BuildAnalyzerFactoryContext analyzerFactoryContext, string projectFullPath)
209207
{
210208
// For custom analyzers - it should run only on projects where referenced
211209
// (otherwise error out - https://github.com/orgs/dotnet/projects/373/views/1?pane=issue&itemId=57849480)
@@ -283,7 +281,7 @@ private void SetupSingleAnalyzer(BuildAnalyzerFactoryContext analyzerFactoryCont
283281
}
284282
}
285283

286-
private void SetupAnalyzersForNewProject(string projectFullPath, BuildEventContext buildEventContext)
284+
private void SetupAnalyzersForNewProject(string projectFullPath, AnalyzerLoggingContext loggingContext)
287285
{
288286
// Only add analyzers here
289287
// On an execution node - we might remove and dispose the analyzers once project is done
@@ -295,11 +293,11 @@ private void SetupAnalyzersForNewProject(string projectFullPath, BuildEventConte
295293
{
296294
try
297295
{
298-
SetupSingleAnalyzer(analyzerFactoryContext, projectFullPath, buildEventContext);
296+
SetupSingleAnalyzer(analyzerFactoryContext, projectFullPath);
299297
}
300298
catch (BuildCheckConfigurationException e)
301299
{
302-
_loggingService.LogErrorFromText(buildEventContext, null, null, null,
300+
loggingContext.LogErrorFromText(null, null, null,
303301
new BuildEventFileInfo(projectFullPath),
304302
e.Message);
305303
analyzersToRemove.Add(analyzerFactoryContext);
@@ -309,7 +307,7 @@ private void SetupAnalyzersForNewProject(string projectFullPath, BuildEventConte
309307
analyzersToRemove.ForEach(c =>
310308
{
311309
_analyzersRegistry.Remove(c);
312-
_loggingService.LogCommentFromText(buildEventContext, MessageImportance.High, $"Dismounting analyzer '{c.FriendlyName}'");
310+
loggingContext.LogCommentFromText(MessageImportance.High, $"Dismounting analyzer '{c.FriendlyName}'");
313311
});
314312
foreach (var analyzerToRemove in analyzersToRemove.Select(a => a.MaterializedAnalyzer).Where(a => a != null))
315313
{
@@ -377,7 +375,9 @@ public void FinalizeProcessing(LoggingContext loggingContext)
377375
loggingContext.LogBuildEvent(analyzerEventArg);
378376
}
379377

380-
public void StartProjectEvaluation(BuildCheckDataSource buildCheckDataSource, BuildEventContext buildEventContext,
378+
public void StartProjectEvaluation(
379+
BuildCheckDataSource buildCheckDataSource,
380+
AnalyzerLoggingContext loggingContext,
381381
string fullPath)
382382
{
383383
if (buildCheckDataSource == BuildCheckDataSource.EventArgs && IsInProcNode)
@@ -388,7 +388,7 @@ public void StartProjectEvaluation(BuildCheckDataSource buildCheckDataSource, Bu
388388
return;
389389
}
390390

391-
SetupAnalyzersForNewProject(fullPath, buildEventContext);
391+
SetupAnalyzersForNewProject(fullPath, loggingContext);
392392
}
393393

394394
/*

src/Build/BuildCheck/Infrastructure/IBuildCheckManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ void ProcessTaskParameterEventArgs(
6464
// but as well from the ConnectorLogger - as even if interleaved, it gives the info
6565
// to manager about what analyzers need to be materialized and configuration fetched.
6666
// No unloading of analyzers is yet considered - once loaded it stays for whole build.
67-
void StartProjectEvaluation(BuildCheckDataSource buildCheckDataSource, BuildEventContext buildEventContext, string fullPath);
67+
void StartProjectEvaluation(BuildCheckDataSource buildCheckDataSource, AnalyzerLoggingContext loggingContext, string fullPath);
6868

6969
void EndProjectEvaluation(BuildCheckDataSource buildCheckDataSource, BuildEventContext buildEventContext);
7070

src/Build/BuildCheck/Infrastructure/NullBuildCheckManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void FinalizeProcessing(LoggingContext loggingContext)
5050
{
5151
}
5252

53-
public void StartProjectEvaluation(BuildCheckDataSource buildCheckDataSource, BuildEventContext buildEventContext, string fullPath)
53+
public void StartProjectEvaluation(BuildCheckDataSource buildCheckDataSource, AnalyzerLoggingContext loggingContext, string fullPath)
5454
{
5555
}
5656

src/BuildCheck.UnitTests/BuildCheckManagerProviderTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public BuildCheckManagerTests(ITestOutputHelper output)
3030
_loggingService = LoggingService.CreateLoggingService(LoggerMode.Synchronous, 1);
3131
_logger = new MockLogger();
3232
_loggingService.RegisterLogger(_logger);
33-
_testedInstance = new BuildCheckManager(_loggingService);
33+
_testedInstance = new BuildCheckManager();
3434
}
3535

3636
[Theory]

0 commit comments

Comments
 (0)