Skip to content

Commit 80f316e

Browse files
Properly Consider WarningsAsMessages In TaskLoggingHelper's HasLoggedErrors (#6308)
Fixes #6306 Context #6174 didn't properly account for warningsaserrors and warningsasmessages together. This PR makes each taskhost aware of both WarningsAsMessages and WarningsAsErrors when telling tasks whether or not an error should be treated as a warning. Changes Made LoggingService and TaskLoggingContext expose a GetWarningsAsMessages to each taskhost for them to store. No changes to IBE8 API Taskhosts first check if a warning would be treated as a message when telling tasks whether or not a warning should be treated as a warning.
1 parent 7a89210 commit 80f316e

File tree

10 files changed

+224
-154
lines changed

10 files changed

+224
-154
lines changed

src/Build.UnitTests/BackEnd/MockLoggingService.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,12 @@ public bool HasBuildSubmissionLoggedErrors(int submissionId)
557557
return false;
558558
}
559559

560-
public ICollection<string> GetWarningsToBeLoggedAsErrorsByProject(BuildEventContext context)
560+
public ICollection<string> GetWarningsAsErrors(BuildEventContext context)
561+
{
562+
throw new NotImplementedException();
563+
}
564+
565+
public ICollection<string> GetWarningsAsMessages(BuildEventContext context)
561566
{
562567
throw new NotImplementedException();
563568
}

src/Build.UnitTests/BackEnd/TaskHostConfiguration_Tests.cs

Lines changed: 90 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ public void ConstructorWithNullName()
5757
taskLocation: @"c:\my tasks\mytask.dll",
5858
taskParameters: null,
5959
globalParameters: null,
60-
warningsAsErrors: null);
60+
warningsAsErrors: null,
61+
warningsAsMessages: null);
6162
}
6263
);
6364
}
@@ -90,7 +91,8 @@ public void ConstructorWithEmptyName()
9091
taskLocation: @"c:\my tasks\mytask.dll",
9192
taskParameters: null,
9293
globalParameters: null,
93-
warningsAsErrors: null);
94+
warningsAsErrors: null,
95+
warningsAsMessages: null);
9496
}
9597
);
9698
}
@@ -123,7 +125,8 @@ public void ConstructorWithNullLocation()
123125
taskLocation: null,
124126
taskParameters: null,
125127
globalParameters: null,
126-
warningsAsErrors: null);
128+
warningsAsErrors: null,
129+
warningsAsMessages: null);
127130
}
128131
);
129132
}
@@ -158,7 +161,8 @@ public void ConstructorWithEmptyLocation()
158161
taskLocation: String.Empty,
159162
taskParameters: null,
160163
globalParameters: null,
161-
warningsAsErrors: null);
164+
warningsAsErrors: null,
165+
warningsAsMessages: null);
162166
}
163167
);
164168
}
@@ -191,26 +195,32 @@ public void TestValidConstructors()
191195
taskLocation: @"c:\MyTasks\MyTask.dll",
192196
taskParameters: null,
193197
globalParameters: null,
194-
warningsAsErrors: null);
198+
warningsAsErrors: null,
199+
warningsAsMessages: null);
195200

196201
TaskHostConfiguration config2 = new TaskHostConfiguration(
197-
1,
198-
Directory.GetCurrentDirectory(),
199-
null,
200-
Thread.CurrentThread.CurrentCulture,
201-
Thread.CurrentThread.CurrentUICulture,
202+
nodeId: 1,
203+
startupDirectory: Directory.GetCurrentDirectory(),
204+
buildProcessEnvironment: null,
205+
culture: Thread.CurrentThread.CurrentCulture,
206+
uiCulture: Thread.CurrentThread.CurrentUICulture,
207+
#if FEATURE_APPDOMAIN
208+
appDomainSetup:
202209
#if FEATURE_APPDOMAIN
203210
null,
211+
#endif
212+
lineNumberOfTask:
204213
#endif
205214
1,
206-
1,
207-
@"c:\my project\myproj.proj",
208-
_continueOnErrorDefault,
209-
"TaskName",
210-
@"c:\MyTasks\MyTask.dll",
211-
null,
212-
null,
213-
null);
215+
columnNumberOfTask: 1,
216+
projectFileOfTask: @"c:\my project\myproj.proj",
217+
continueOnError: _continueOnErrorDefault,
218+
taskName: "TaskName",
219+
taskLocation: @"c:\MyTasks\MyTask.dll",
220+
taskParameters: null,
221+
globalParameters: null,
222+
warningsAsErrors: null,
223+
warningsAsMessages: null);
214224

215225
IDictionary<string, object> parameters = new Dictionary<string, object>();
216226
TaskHostConfiguration config3 = new TaskHostConfiguration(
@@ -234,7 +244,8 @@ public void TestValidConstructors()
234244
taskLocation: @"c:\MyTasks\MyTask.dll",
235245
taskParameters: parameters,
236246
globalParameters: null,
237-
warningsAsErrors: null);
247+
warningsAsErrors: null,
248+
warningsAsMessages: null);
238249

239250
IDictionary<string, object> parameters2 = new Dictionary<string, object>();
240251
parameters2.Add("Text", "Hello!");
@@ -263,7 +274,8 @@ public void TestValidConstructors()
263274
taskLocation: @"c:\MyTasks\MyTask.dll",
264275
taskParameters: parameters2,
265276
globalParameters: null,
266-
warningsAsErrors: null);
277+
warningsAsErrors: null,
278+
warningsAsMessages: null);
267279

268280
HashSet<string> WarningsAsErrors = new HashSet<string>();
269281
WarningsAsErrors.Add("MSB1234");
@@ -292,7 +304,8 @@ public void TestValidConstructors()
292304
taskLocation: @"c:\MyTasks\MyTask.dll",
293305
taskParameters: parameters2,
294306
globalParameters: null,
295-
warningsAsErrors: WarningsAsErrors);
307+
warningsAsErrors: WarningsAsErrors,
308+
warningsAsMessages: null);
296309
}
297310

298311
/// <summary>
@@ -328,7 +341,8 @@ public void TestTranslationWithNullDictionary()
328341
taskLocation: @"c:\MyTasks\MyTask.dll",
329342
taskParameters: null,
330343
globalParameters: expectedGlobalProperties,
331-
warningsAsErrors: null);
344+
warningsAsErrors: null,
345+
warningsAsMessages: null);
332346

333347
((ITranslatable)config).Translate(TranslationHelpers.GetWriteTranslator());
334348
INodePacket packet = TaskHostConfiguration.FactoryForDeserialization(TranslationHelpers.GetReadTranslator());
@@ -371,7 +385,8 @@ public void TestTranslationWithEmptyDictionary()
371385
taskLocation: @"c:\MyTasks\MyTask.dll",
372386
taskParameters: new Dictionary<string, object>(),
373387
globalParameters: new Dictionary<string, string>(),
374-
warningsAsErrors: null);
388+
warningsAsErrors: null,
389+
warningsAsMessages: null);
375390

376391
((ITranslatable)config).Translate(TranslationHelpers.GetWriteTranslator());
377392
INodePacket packet = TaskHostConfiguration.FactoryForDeserialization(TranslationHelpers.GetReadTranslator());
@@ -419,7 +434,8 @@ public void TestTranslationWithValueTypesInDictionary()
419434
taskLocation: @"c:\MyTasks\MyTask.dll",
420435
taskParameters: parameters,
421436
globalParameters: null,
422-
warningsAsErrors: null);
437+
warningsAsErrors: null,
438+
warningsAsMessages: null);
423439

424440
((ITranslatable)config).Translate(TranslationHelpers.GetWriteTranslator());
425441
INodePacket packet = TaskHostConfiguration.FactoryForDeserialization(TranslationHelpers.GetReadTranslator());
@@ -465,7 +481,8 @@ public void TestTranslationWithITaskItemInDictionary()
465481
taskLocation: @"c:\MyTasks\MyTask.dll",
466482
taskParameters: parameters,
467483
globalParameters: null,
468-
warningsAsErrors: null);
484+
warningsAsErrors: null,
485+
warningsAsMessages: null);
469486

470487
((ITranslatable)config).Translate(TranslationHelpers.GetWriteTranslator());
471488
INodePacket packet = TaskHostConfiguration.FactoryForDeserialization(TranslationHelpers.GetReadTranslator());
@@ -510,7 +527,8 @@ public void TestTranslationWithITaskItemArrayInDictionary()
510527
taskLocation: @"c:\MyTasks\MyTask.dll",
511528
taskParameters: parameters,
512529
globalParameters: null,
513-
warningsAsErrors: null);
530+
warningsAsErrors: null,
531+
warningsAsMessages: null);
514532

515533
((ITranslatable)config).Translate(TranslationHelpers.GetWriteTranslator());
516534
INodePacket packet = TaskHostConfiguration.FactoryForDeserialization(TranslationHelpers.GetReadTranslator());
@@ -562,7 +580,8 @@ public void TestTranslationWithWarningsAsErrors()
562580
taskLocation: @"c:\MyTasks\MyTask.dll",
563581
taskParameters: null,
564582
globalParameters: null,
565-
warningsAsErrors: WarningsAsErrors);
583+
warningsAsErrors: WarningsAsErrors,
584+
warningsAsMessages: null);
566585

567586
((ITranslatable)config).Translate(TranslationHelpers.GetWriteTranslator());
568587
INodePacket packet = TaskHostConfiguration.FactoryForDeserialization(TranslationHelpers.GetReadTranslator());
@@ -578,6 +597,50 @@ public void TestTranslationWithWarningsAsErrors()
578597

579598
}
580599

600+
/// <summary>
601+
/// Test serialization / deserialization when the parameter dictionary contains warningsasmessages
602+
/// </summary>
603+
[Fact]
604+
public void TestTranslationWithWarningsAsMessages()
605+
{
606+
HashSet<string> WarningsAsMessages = new HashSet<string>();
607+
WarningsAsMessages.Add("MSB1234");
608+
WarningsAsMessages.Add("MSB1235");
609+
WarningsAsMessages.Add("MSB1236");
610+
WarningsAsMessages.Add("MSB1237");
611+
TaskHostConfiguration config = new TaskHostConfiguration(
612+
nodeId: 1,
613+
startupDirectory: Directory.GetCurrentDirectory(),
614+
buildProcessEnvironment: null,
615+
culture: Thread.CurrentThread.CurrentCulture,
616+
uiCulture: Thread.CurrentThread.CurrentUICulture,
617+
#if FEATURE_APPDOMAIN
618+
appDomainSetup:
619+
#if FEATURE_APPDOMAIN
620+
null,
621+
#endif
622+
lineNumberOfTask:
623+
#endif
624+
1,
625+
columnNumberOfTask: 1,
626+
projectFileOfTask: @"c:\my project\myproj.proj",
627+
continueOnError: _continueOnErrorDefault,
628+
taskName: "TaskName",
629+
taskLocation: @"c:\MyTasks\MyTask.dll",
630+
taskParameters: null,
631+
globalParameters: null,
632+
warningsAsErrors: null,
633+
warningsAsMessages: WarningsAsMessages);
634+
635+
((ITranslatable)config).Translate(TranslationHelpers.GetWriteTranslator());
636+
INodePacket packet = TaskHostConfiguration.FactoryForDeserialization(TranslationHelpers.GetReadTranslator());
637+
638+
TaskHostConfiguration deserializedConfig = packet as TaskHostConfiguration;
639+
640+
Assert.NotNull(deserializedConfig.WarningsAsMessages);
641+
config.WarningsAsMessages.SequenceEqual(deserializedConfig.WarningsAsMessages, StringComparer.Ordinal).ShouldBeTrue();
642+
}
643+
581644
/// <summary>
582645
/// Helper methods for testing the task host-related packets.
583646
/// </summary>

0 commit comments

Comments
 (0)