improve finding encompassed items in a configuration
This commit is contained in:
parent
b03f4c282b
commit
2dd99ce015
3 changed files with 25 additions and 7 deletions
|
@ -15,6 +15,18 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
||||||
{
|
{
|
||||||
public static class MSBuildExtensions
|
public static class MSBuildExtensions
|
||||||
{
|
{
|
||||||
|
public static IEnumerable<string> GetEncompassedIncludes(this ProjectItemElement item,
|
||||||
|
ProjectItemElement otherItem)
|
||||||
|
{
|
||||||
|
if (otherItem.IsEquivalentToExceptIncludeAndExclude(item) &&
|
||||||
|
new HashSet<string>(otherItem.Excludes()).IsSubsetOf(new HashSet<string>(item.Excludes())))
|
||||||
|
{
|
||||||
|
return otherItem.IntersectIncludes(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Enumerable.Empty<string>();
|
||||||
|
}
|
||||||
|
|
||||||
public static bool IsEquivalentTo(this ProjectItemElement item, ProjectItemElement otherItem)
|
public static bool IsEquivalentTo(this ProjectItemElement item, ProjectItemElement otherItem)
|
||||||
{
|
{
|
||||||
// Different includes
|
// Different includes
|
||||||
|
@ -31,6 +43,11 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return item.IsEquivalentToExceptIncludeAndExclude(otherItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool IsEquivalentToExceptIncludeAndExclude(this ProjectItemElement item, ProjectItemElement otherItem)
|
||||||
|
{
|
||||||
// Different remove
|
// Different remove
|
||||||
if (item.Remove != otherItem.Remove)
|
if (item.Remove != otherItem.Remove)
|
||||||
{
|
{
|
||||||
|
|
|
@ -102,12 +102,12 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Transforms
|
||||||
|
|
||||||
foreach (var existingItem in existingItemsWithDifferentCondition)
|
foreach (var existingItem in existingItemsWithDifferentCondition)
|
||||||
{
|
{
|
||||||
// When the existing item encompasses this item and it's condition is empty, ignore the current item
|
var encompassedIncludes = existingItem.GetEncompassedIncludes(item);
|
||||||
if (item.IsEquivalentTo(existingItem))
|
if (encompassedIncludes.Any())
|
||||||
{
|
{
|
||||||
MigrationTrace.Instance.WriteLine($"{nameof(TransformApplicator)}: equivalent {existingItem.ConditionChain().Count()}");
|
MigrationTrace.Instance.WriteLine($"{nameof(TransformApplicator)}: encompassed includes {string.Join(", ", encompassedIncludes)}");
|
||||||
|
item.RemoveIncludes(encompassedIncludes);
|
||||||
if (existingItem.ConditionChain().Count() == 0)
|
if (!item.Includes().Any())
|
||||||
{
|
{
|
||||||
MigrationTrace.Instance.WriteLine($"{nameof(TransformApplicator)}: Ignoring Item {{ ItemType: {existingItem.ItemType}, Condition: {existingItem.Condition}, Include: {existingItem.Include}, Exclude: {existingItem.Exclude} }}");
|
MigrationTrace.Instance.WriteLine($"{nameof(TransformApplicator)}: Ignoring Item {{ ItemType: {existingItem.ItemType}, Condition: {existingItem.Condition}, Include: {existingItem.Include}, Exclude: {existingItem.Exclude} }}");
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -110,7 +110,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
|
||||||
""buildOptions"": {
|
""buildOptions"": {
|
||||||
""copyToOutput"": {
|
""copyToOutput"": {
|
||||||
""include"": [""root"", ""src"", ""rootfile.cs""],
|
""include"": [""root"", ""src"", ""rootfile.cs""],
|
||||||
""exclude"": [""src"", ""rootfile.cs""],
|
""exclude"": [""src"", ""root/rootfile.cs""],
|
||||||
""includeFiles"": [""src/file1.cs"", ""src/file2.cs""],
|
""includeFiles"": [""src/file1.cs"", ""src/file2.cs""],
|
||||||
""excludeFiles"": [""src/file2.cs""]
|
""excludeFiles"": [""src/file2.cs""]
|
||||||
}
|
}
|
||||||
|
@ -118,6 +118,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}");
|
}");
|
||||||
|
Console.WriteLine(mockProj.RawXml);
|
||||||
|
|
||||||
var contentItems = mockProj.Items.Where(item => item.ItemType == "Content");
|
var contentItems = mockProj.Items.Where(item => item.ItemType == "Content");
|
||||||
|
|
||||||
|
@ -137,7 +138,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
|
||||||
// Directories are not converted to globs in the result because we did not write the directory
|
// Directories are not converted to globs in the result because we did not write the directory
|
||||||
configRemoveContentItem.Remove.Should().Be(@"root;src;rootfile.cs");
|
configRemoveContentItem.Remove.Should().Be(@"root;src;rootfile.cs");
|
||||||
configIncludeContentItem.Include.Should().Be(@"root;src;rootfile.cs");
|
configIncludeContentItem.Include.Should().Be(@"root;src;rootfile.cs");
|
||||||
configIncludeContentItem.Exclude.Should().Be(@"src;rootfile.cs;src\file2.cs");
|
configIncludeContentItem.Exclude.Should().Be(@"src;root\rootfile.cs;src\file2.cs");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue