Skip to content

Commit 675d423

Browse files
committed
Parse the structure of "There was a conflict" message blobs in RAR.
1 parent ed6fae2 commit 675d423

File tree

2 files changed

+117
-2
lines changed

2 files changed

+117
-2
lines changed

src/StructuredLogger.Tests/ItemGroupParserTests.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,50 @@ public void ParseSuggestedBindingRedirectsMetadata()
4343
Assert.Equal("MaxVersion", metadata.Name);
4444
Assert.Equal("15.1.0.0", metadata.Value);
4545
}
46+
47+
[Fact]
48+
public void ParseThereWasAConflict()
49+
{
50+
var lines = @"""System.IO.Compression, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"" was chosen because it was primary and ""System.IO.Compression, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"" was not.
51+
References which depend on ""System.IO.Compression, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"" [C:\Program Files (x86)\System.IO.Compression.dll].
52+
C:\Program Files (x86)\System.IO.Compression.dll
53+
Project file item includes which caused reference ""C:\Program Files (x86)\System.IO.Compression.dll"".
54+
System.IO.Compression
55+
References which depend on ""System.IO.Compression, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"" [].
56+
C:\A\\A.dll
57+
Project file item includes which caused reference ""C:\A\\A.dll"".
58+
C:\A\bin\Debug\C.dll
59+
C:\A\\B.dll
60+
Project file item includes which caused reference ""C:\A\\B.dll"".
61+
C:\A\\B\D.dll
62+
C:\A\\C.dll".GetLines();
63+
var parameter = new Parameter()
64+
{
65+
Name = "There was a conflict"
66+
};
67+
var stringCache = new StringCache();
68+
foreach (var line in lines)
69+
{
70+
MessageProcessor.HandleThereWasAConflict(parameter, line, stringCache);
71+
}
72+
73+
Assert.True(parameter.Children.Count == 3);
74+
var text = StringWriter.GetString(parameter);
75+
Assert.Equal(@"There was a conflict
76+
""System.IO.Compression, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"" was chosen because it was primary and ""System.IO.Compression, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"" was not.
77+
References which depend on ""System.IO.Compression, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"" [C:\Program Files (x86)\System.IO.Compression.dll].
78+
C:\Program Files (x86)\System.IO.Compression.dll
79+
Project file item includes which caused reference ""C:\Program Files (x86)\System.IO.Compression.dll"".
80+
System.IO.Compression
81+
References which depend on ""System.IO.Compression, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"" [].
82+
C:\A\\A.dll
83+
Project file item includes which caused reference ""C:\A\\A.dll"".
84+
C:\A\bin\Debug\C.dll
85+
C:\A\\B.dll
86+
Project file item includes which caused reference ""C:\A\\B.dll"".
87+
C:\A\\B\D.dll
88+
C:\A\\C.dll
89+
", text);
90+
}
4691
}
4792
}

src/StructuredLogger/Construction/MessageProcessor.cs

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,13 @@ public void AddMessage(LazyFormattedBuildEventArgs args, string message)
211211
var parameter = node.FindLastChild<Parameter>();
212212
if (parameter != null)
213213
{
214+
bool thereWasAConflict = parameter.ToString().StartsWith("There was a conflict");
215+
if (thereWasAConflict)
216+
{
217+
HandleThereWasAConflict(parameter, message, stringTable);
218+
return;
219+
}
220+
214221
if (!string.IsNullOrWhiteSpace(message))
215222
{
216223
node = parameter;
@@ -233,7 +240,8 @@ public void AddMessage(LazyFormattedBuildEventArgs args, string message)
233240

234241
if (!string.IsNullOrEmpty(message))
235242
{
236-
if (message.IndexOf('=') != -1)
243+
var equals = message.IndexOf('=');
244+
if (equals != -1)
237245
{
238246
var kvp = Utilities.ParseNameValue(message);
239247
node.AddChild(new Metadata
@@ -263,7 +271,8 @@ public void AddMessage(LazyFormattedBuildEventArgs args, string message)
263271
message.StartsWith("Primary reference ") ||
264272
message.StartsWith("Dependency ") ||
265273
message.StartsWith("Unified Dependency ") ||
266-
message.StartsWith("AssemblyFoldersEx location");
274+
message.StartsWith("AssemblyFoldersEx location") ||
275+
message.StartsWith("There was a conflict");
267276

268277
if (isResult)
269278
{
@@ -393,6 +402,67 @@ public void AddMessage(LazyFormattedBuildEventArgs args, string message)
393402
node.AddChild(nodeToAdd);
394403
}
395404

405+
public static void HandleThereWasAConflict(Parameter parameter, string message, StringCache stringTable)
406+
{
407+
var numberOfLeadingSpaces = Utilities.GetNumberOfLeadingSpaces(message);
408+
TreeNode node = parameter;
409+
switch (numberOfLeadingSpaces)
410+
{
411+
case 0:
412+
parameter.AddChild(new Item()
413+
{
414+
Text = stringTable.Intern(message)
415+
});
416+
break;
417+
case 4:
418+
node = parameter.LastChild as TreeNode ?? node;
419+
Add(node, message, 4);
420+
break;
421+
case 6:
422+
{
423+
if (parameter.LastChild is TreeNode item)
424+
{
425+
node = item;
426+
if (item.LastChild is TreeNode item2)
427+
{
428+
node = item2;
429+
}
430+
}
431+
Add(node, message, 6);
432+
}
433+
break;
434+
case 8:
435+
{
436+
if (parameter.LastChild is TreeNode item)
437+
{
438+
node = item;
439+
if (item.LastChild is TreeNode item2)
440+
{
441+
node = item2;
442+
if (item2.LastChild is TreeNode item3)
443+
{
444+
node = item3;
445+
}
446+
}
447+
}
448+
Add(node, message, 8);
449+
}
450+
break;
451+
default:
452+
Add(node, message, 0);
453+
break;
454+
}
455+
456+
void Add(TreeNode parent, string text, int spaces)
457+
{
458+
text = text.Substring(spaces);
459+
parent.AddChild(new Item
460+
{
461+
Text = stringTable.Intern(text)
462+
});
463+
}
464+
}
465+
396466
private bool IsEvaluationMessage(string message)
397467
{
398468
return message.StartsWith("Search paths being used")

0 commit comments

Comments
 (0)