remove cross project reference from dotnet-add-p2p tests

This commit is contained in:
Krzysztof Wicher 2016-12-27 13:19:40 -08:00
parent 5095981ec3
commit 35bc8e1cc1
3 changed files with 41 additions and 46 deletions

View file

@ -3,17 +3,18 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.Build.Construction; using System.IO;
using System.Linq; using System.Linq;
using Microsoft.Build.Construction;
namespace Microsoft.DotNet.ProjectJsonMigration namespace Microsoft.DotNet.ProjectJsonMigration
{ {
internal static class MSBuildExtensions public static class MSBuildExtensions
{ {
public static IEnumerable<string> GetEncompassedIncludes(this ProjectItemElement item, public static IEnumerable<string> GetEncompassedIncludes(this ProjectItemElement item,
ProjectItemElement otherItem) ProjectItemElement otherItem, TextWriter trace = null)
{ {
if (otherItem.IsEquivalentToExceptIncludeAndExclude(item) && if (otherItem.IsEquivalentToExceptIncludeAndExclude(item, trace) &&
new HashSet<string>(otherItem.Excludes()).IsSubsetOf(new HashSet<string>(item.Excludes()))) new HashSet<string>(otherItem.Excludes()).IsSubsetOf(new HashSet<string>(item.Excludes())))
{ {
return otherItem.IntersectIncludes(item); return otherItem.IntersectIncludes(item);
@ -22,37 +23,31 @@ namespace Microsoft.DotNet.ProjectJsonMigration
return Enumerable.Empty<string>(); return Enumerable.Empty<string>();
} }
public static bool IsEquivalentTo(this ProjectItemElement item, ProjectItemElement otherItem) public static bool IsEquivalentTo(this ProjectItemElement item, ProjectItemElement otherItem, TextWriter trace = null)
{ {
// Different includes // Different includes
if (item.IntersectIncludes(otherItem).Count() != item.Includes().Count()) if (item.IntersectIncludes(otherItem).Count() != item.Includes().Count())
{ {
#if !DISABLE_TRACE trace?.WriteLine(String.Format(LocalizableStrings.IncludesNotEquivalent, nameof(MSBuildExtensions), nameof(IsEquivalentTo)));
MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.IncludesNotEquivalent, nameof(MSBuildExtensions), nameof(IsEquivalentTo)));
#endif
return false; return false;
} }
// Different Excludes // Different Excludes
if (item.IntersectExcludes(otherItem).Count() != item.Excludes().Count()) if (item.IntersectExcludes(otherItem).Count() != item.Excludes().Count())
{ {
#if !DISABLE_TRACE trace?.WriteLine(String.Format(LocalizableStrings.ExcludesNotEquivalent, nameof(MSBuildExtensions), nameof(IsEquivalentTo)));
MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.ExcludesNotEquivalent, nameof(MSBuildExtensions), nameof(IsEquivalentTo)));
#endif
return false; return false;
} }
return item.IsEquivalentToExceptIncludeAndExclude(otherItem); return item.IsEquivalentToExceptIncludeAndExclude(otherItem, trace);
} }
public static bool IsEquivalentToExceptIncludeAndExclude(this ProjectItemElement item, ProjectItemElement otherItem) public static bool IsEquivalentToExceptIncludeAndExclude(this ProjectItemElement item, ProjectItemElement otherItem, TextWriter trace = null)
{ {
// Different remove // Different remove
if (item.Remove != otherItem.Remove) if (item.Remove != otherItem.Remove)
{ {
#if !DISABLE_TRACE trace?.WriteLine(String.Format(LocalizableStrings.RemovesNotEquivalent, nameof(MSBuildExtensions), nameof(IsEquivalentTo)));
MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.RemovesNotEquivalent, nameof(MSBuildExtensions), nameof(IsEquivalentTo)));
#endif
return false; return false;
} }
@ -67,17 +62,13 @@ namespace Microsoft.DotNet.ProjectJsonMigration
var otherMetadata = itemToCompare.GetMetadataWithName(metadata.Name); var otherMetadata = itemToCompare.GetMetadataWithName(metadata.Name);
if (otherMetadata == null) if (otherMetadata == null)
{ {
#if !DISABLE_TRACE trace?.WriteLine(String.Format(LocalizableStrings.MetadataDoesntExist, nameof(MSBuildExtensions), nameof(IsEquivalentTo), metadata.Name, metadata.Value));
MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.MetadataDoesntExist, nameof(MSBuildExtensions), nameof(IsEquivalentTo), metadata.Name, metadata.Value));
#endif
return false; return false;
} }
if (!metadata.ValueEquals(otherMetadata)) if (!metadata.ValueEquals(otherMetadata))
{ {
#if !DISABLE_TRACE trace?.WriteLine(String.Format(LocalizableStrings.MetadataHasAnotherValue, nameof(MSBuildExtensions), nameof(IsEquivalentTo), metadata.Name, metadata.Value, otherMetadata.Value));
MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.MetadataHasAnotherValue, nameof(MSBuildExtensions), nameof(IsEquivalentTo), metadata.Name, metadata.Value, otherMetadata.Value));
#endif
return false; return false;
} }
} }
@ -175,11 +166,11 @@ namespace Microsoft.DotNet.ProjectJsonMigration
return metadata.Value.Equals(otherMetadata.Value, StringComparison.Ordinal); return metadata.Value.Equals(otherMetadata.Value, StringComparison.Ordinal);
} }
public static void AddMetadata(this ProjectItemElement item, ICollection<ProjectMetadataElement> metadataElements) public static void AddMetadata(this ProjectItemElement item, ICollection<ProjectMetadataElement> metadataElements, TextWriter trace = null)
{ {
foreach (var metadata in metadataElements) foreach (var metadata in metadataElements)
{ {
item.AddMetadata(metadata); item.AddMetadata(metadata, trace);
} }
} }
@ -196,7 +187,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
return item.Metadata.FirstOrDefault(m => m.Name.Equals(name, StringComparison.OrdinalIgnoreCase)); return item.Metadata.FirstOrDefault(m => m.Name.Equals(name, StringComparison.OrdinalIgnoreCase));
} }
public static void AddMetadata(this ProjectItemElement item, ProjectMetadataElement metadata) public static void AddMetadata(this ProjectItemElement item, ProjectMetadataElement metadata, TextWriter trace = null)
{ {
var existingMetadata = item.GetMetadataWithName(metadata.Name); var existingMetadata = item.GetMetadataWithName(metadata.Name);
@ -207,9 +198,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
if (existingMetadata == default(ProjectMetadataElement)) if (existingMetadata == default(ProjectMetadataElement))
{ {
#if !DISABLE_TRACE trace?.WriteLine(String.Format(LocalizableStrings.AddingMetadataToItem, nameof(AddMetadata), item.ItemType, metadata.Name, metadata.Value, metadata.Condition));
MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.AddingMetadataToItem, nameof(AddMetadata), item.ItemType, metadata.Name, metadata.Value, metadata.Condition));
#endif
var metametadata = item.AddMetadata(metadata.Name, metadata.Value); var metametadata = item.AddMetadata(metadata.Name, metadata.Value);
metametadata.Condition = metadata.Condition; metametadata.Condition = metadata.Condition;
metametadata.ExpressedAsAttribute = metadata.ExpressedAsAttribute; metametadata.ExpressedAsAttribute = metadata.ExpressedAsAttribute;

View file

@ -2,37 +2,47 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System; using System;
using System.IO;
using System.Text;
namespace Microsoft.DotNet.ProjectJsonMigration namespace Microsoft.DotNet.ProjectJsonMigration
{ {
internal class MigrationTrace internal class MigrationTrace : TextWriter
{ {
public static MigrationTrace Instance { get; set; } public static MigrationTrace Instance { get; set; }
public string EnableEnvironmentVariable => "DOTNET_MIGRATION_TRACE";
public bool IsEnabled { get; private set; }
private TextWriter _underlyingWriter;
static MigrationTrace () static MigrationTrace ()
{ {
Instance = new MigrationTrace(); Instance = new MigrationTrace();
} }
public string EnableEnvironmentVariable => "DOTNET_MIGRATION_TRACE"; public MigrationTrace()
public bool IsEnabled
{ {
get _underlyingWriter = Console.Out;
{ IsEnabled = IsEnabledValue();
#if DEBUG
return true;
#else
return Environment.GetEnvironmentVariable(EnableEnvironmentVariable) != null;
#endif
}
} }
public void WriteLine(string message) private bool IsEnabledValue()
{
#if DEBUG
return true;
#else
return Environment.GetEnvironmentVariable(EnableEnvironmentVariable) != null;
#endif
}
public override Encoding Encoding => _underlyingWriter.Encoding;
public override void Write(char value)
{ {
if (IsEnabled) if (IsEnabled)
{ {
Console.WriteLine(message); _underlyingWriter.Write(value);
} }
} }
} }

View file

@ -6,13 +6,9 @@
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles> <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<AssemblyName>dotnet-add-p2p.Tests</AssemblyName> <AssemblyName>dotnet-add-p2p.Tests</AssemblyName>
<PackageTargetFallback Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">$(PackageTargetFallback);dotnet5.4;portable-net451+win8</PackageTargetFallback> <PackageTargetFallback Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">$(PackageTargetFallback);dotnet5.4;portable-net451+win8</PackageTargetFallback>
<DefineConstants>$(DefineConstants);DISABLE_TRACE</DefineConstants>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Compile Include="**\*.cs" /> <Compile Include="**\*.cs" />
<Compile Include="..\..\src\Microsoft.DotNet.ProjectJsonMigration\MSBuildExtensions.cs">
<Link>src\Microsoft.DotNet.ProjectJsonMigration\MSBuildExtensions.cs</Link>
</Compile>
<EmbeddedResource Include="**\*.resx" /> <EmbeddedResource Include="**\*.resx" />
<EmbeddedResource Include="compiler\resources\**\*" /> <EmbeddedResource Include="compiler\resources\**\*" />
</ItemGroup> </ItemGroup>