2016-11-16 23:49:25 +00:00
|
|
|
|
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
|
|
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
|
|
|
|
|
|
|
|
using Microsoft.Build.Construction;
|
|
|
|
|
using Microsoft.DotNet.ProjectJsonMigration;
|
2016-11-22 22:41:56 +00:00
|
|
|
|
using System.Linq;
|
2016-11-16 23:49:25 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
2016-11-29 23:42:16 +00:00
|
|
|
|
namespace Msbuild.Tests.Utilities
|
2016-11-16 23:49:25 +00:00
|
|
|
|
{
|
2016-11-29 23:42:16 +00:00
|
|
|
|
public static class ProjectRootElementExtensions
|
2016-11-16 23:49:25 +00:00
|
|
|
|
{
|
2016-11-23 23:35:01 +00:00
|
|
|
|
public static int NumberOfItemGroupsWithConditionContaining(
|
|
|
|
|
this ProjectRootElement root,
|
|
|
|
|
string patternInCondition)
|
2016-11-16 23:49:25 +00:00
|
|
|
|
{
|
2016-11-22 22:41:56 +00:00
|
|
|
|
return root.ItemGroups.Count((itemGroup) => itemGroup.Condition.Contains(patternInCondition));
|
2016-11-16 23:49:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static int NumberOfItemGroupsWithoutCondition(this ProjectRootElement root)
|
|
|
|
|
{
|
|
|
|
|
return root.ItemGroups.Count((ig) => string.IsNullOrEmpty(ig.Condition));
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-23 23:35:01 +00:00
|
|
|
|
public static IEnumerable<ProjectElement> ItemsWithIncludeAndConditionContaining(
|
|
|
|
|
this ProjectRootElement root,
|
|
|
|
|
string itemType,
|
|
|
|
|
string includePattern,
|
|
|
|
|
string patternInCondition)
|
2016-11-16 23:49:25 +00:00
|
|
|
|
{
|
|
|
|
|
return root.Items.Where((it) =>
|
|
|
|
|
{
|
|
|
|
|
if (it.ItemType != itemType || !it.Include.Contains(includePattern))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var condChain = it.ConditionChain();
|
|
|
|
|
return condChain.Count == 1 && condChain.First().Contains(patternInCondition);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-23 23:35:01 +00:00
|
|
|
|
public static int NumberOfProjectReferencesWithIncludeAndConditionContaining(
|
2017-03-03 04:35:20 +00:00
|
|
|
|
this ProjectRootElement root,
|
|
|
|
|
string includePattern,
|
2016-11-23 23:35:01 +00:00
|
|
|
|
string patternInCondition)
|
2016-11-16 23:49:25 +00:00
|
|
|
|
{
|
2016-11-23 23:35:01 +00:00
|
|
|
|
return root.ItemsWithIncludeAndConditionContaining(
|
|
|
|
|
"ProjectReference",
|
|
|
|
|
includePattern,
|
|
|
|
|
patternInCondition)
|
|
|
|
|
.Count();
|
2016-11-16 23:49:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-23 23:35:01 +00:00
|
|
|
|
public static IEnumerable<ProjectElement> ItemsWithIncludeContaining(
|
|
|
|
|
this ProjectRootElement root,
|
|
|
|
|
string itemType,
|
|
|
|
|
string includePattern)
|
2016-11-16 23:49:25 +00:00
|
|
|
|
{
|
2016-11-30 20:07:13 +00:00
|
|
|
|
return root.Items.Where((it) => it.ItemType == itemType && it.Include.Contains(includePattern)
|
|
|
|
|
&& it.ConditionChain().Count() == 0);
|
2016-11-16 23:49:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-23 23:35:01 +00:00
|
|
|
|
public static int NumberOfProjectReferencesWithIncludeContaining(
|
|
|
|
|
this ProjectRootElement root,
|
|
|
|
|
string includePattern)
|
2016-11-16 23:49:25 +00:00
|
|
|
|
{
|
|
|
|
|
return root.ItemsWithIncludeContaining("ProjectReference", includePattern).Count();
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-03-03 04:35:20 +00:00
|
|
|
|
}
|