Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Cake.Common.Tests/Fixtures/AssemblyInfoParserFixture.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

Expand Down Expand Up @@ -27,6 +27,7 @@ internal sealed class AssemblyInfoParserFixture
public string Guid { get; set; }
public string InformationalVersion { get; set; }
public List<string> InternalsVisibleTo { get; set; }
public List<string> SupportedOSPlatform { get; set; }
public string Product { get; set; }
public string Title { get; set; }
public string Trademark { get; set; }
Expand Down Expand Up @@ -101,6 +102,10 @@ private void CreateAssemblyInfoOnDisk(FilePath path)
{
settings.InternalsVisibleTo = InternalsVisibleTo;
}
if (SupportedOSPlatform != null)
{
settings.SupportedOSPlatform = SupportedOSPlatform;
}
if (Product != null)
{
settings.Product = Product;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

Expand Down Expand Up @@ -27,6 +27,7 @@ internal sealed class AssemblyInfoParserFixture_VB
public string Guid { get; set; }
public string InformationalVersion { get; set; }
public List<string> InternalsVisibleTo { get; set; }
public List<string> SupportedOSPlatform { get; set; }
public string Product { get; set; }
public string Title { get; set; }
public string Trademark { get; set; }
Expand Down Expand Up @@ -101,6 +102,10 @@ private void CreateAssemblyInfoOnDisk(FilePath path)
{
settings.InternalsVisibleTo = InternalsVisibleTo;
}
if (SupportedOSPlatform != null)
{
settings.SupportedOSPlatform = SupportedOSPlatform;
}
if (Product != null)
{
settings.Product = Product;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,38 @@ public void Should_Add_Multiple_InternalsVisibleTo_Attribute_If_Set()
Assert.Contains("[assembly: InternalsVisibleTo(\"Assembly3.Tests\")]", result);
}

[Fact]
public void Should_Add_SupportedOSPlatform_Attribute_If_Set()
{
// Given
var fixture = new AssemblyInfoFixture();
fixture.Settings.SupportedOSPlatform = new List<string> { "windows" };

// When
var result = fixture.CreateAndReturnContent();

// Then
Assert.Contains("using System.Runtime.Versioning;", result);
Assert.Contains("[assembly: SupportedOSPlatform(\"windows\")]", result);
}

[Fact]
public void Should_Add_Multiple_SupportedOSPlatform_Attribute_If_Set()
{
// Given
var fixture = new AssemblyInfoFixture();
fixture.Settings.SupportedOSPlatform = new Collection<string> { "windows", "linux", "macos" };

// When
var result = fixture.CreateAndReturnContent();

// Then
Assert.Contains("using System.Runtime.Versioning;", result);
Assert.Contains("[assembly: SupportedOSPlatform(\"windows\")]", result);
Assert.Contains("[assembly: SupportedOSPlatform(\"linux\")]", result);
Assert.Contains("[assembly: SupportedOSPlatform(\"macos\")]", result);
}

[Fact]
public void Should_Add_Configuration_Attribute_If_Set()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

Expand Down Expand Up @@ -301,6 +301,44 @@ public void Should_Read_InternalsVisibleTo(bool extraWhiteSpaces)
Assert.Equal("Cake.Common.Tests", result.InternalsVisibleTo.ElementAt(1));
}

[Theory]
[InlineData(true)]
[InlineData(false)]
public void Should_Read_SupportedOSPlatform(bool extraWhiteSpaces)
{
// Given
var fixture = new AssemblyInfoParserFixture();
fixture.ExtraWhiteSpaces = extraWhiteSpaces;
fixture.SupportedOSPlatform = new List<string> { "windows" };

// When
var result = fixture.Parse();

// Then
Assert.Single(result.SupportedOSPlatform, x => x == "windows");
}

[Theory]
[InlineData(true)]
[InlineData(false)]
public void Should_Read_Multiple_SupportedOSPlatform(bool extraWhiteSpaces)
{
// Given
var fixture = new AssemblyInfoParserFixture();
fixture.ExtraWhiteSpaces = extraWhiteSpaces;
fixture.SupportedOSPlatform = new List<string> { "windows", "linux", "macos" };

// When
var result = fixture.Parse();

// Then
Assert.Collection(
result.SupportedOSPlatform,
item => Assert.Equal("windows", item),
item => Assert.Equal("linux", item),
item => Assert.Equal("macos", item));
}

[Theory]
[InlineData("Cake", "Cake", true)]
[InlineData("Cake", "Cake", false)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ public void Create(FilePath outputPath, AssemblyInfoSettings settings,
writer.WriteLine();
}

if (data.SupportedOSPlatform.Count > 0)
{
foreach (var attribute in data.SupportedOSPlatform)
{
writer.WriteLine(string.Format(attributeFormat, attribute));
}
}

if (data.CustomAttributes.Count > 0)
{
writer.WriteLine(comment + " Custom Attributes");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ internal sealed class AssemblyInfoCreatorData
private readonly Dictionary<string, string> _metadatattributes;
private readonly HashSet<string> _namespaces;
private readonly HashSet<string> _internalVisibleTo;
private readonly HashSet<string> _supportedOSPlatform;
private readonly string _trueStringValue;
private readonly string _falseStringValue;

Expand All @@ -30,13 +31,16 @@ internal sealed class AssemblyInfoCreatorData

public ISet<string> InternalVisibleTo => _internalVisibleTo;

public ISet<string> SupportedOSPlatform => _supportedOSPlatform;

public AssemblyInfoCreatorData(AssemblyInfoSettings settings, bool isVisualBasicAssemblyInfoFile)
{
_dictionary = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
_customAttributes = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
_metadatattributes = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
_namespaces = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
_internalVisibleTo = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
_supportedOSPlatform = new HashSet<string>(StringComparer.OrdinalIgnoreCase);

_falseStringValue = isVisualBasicAssemblyInfoFile ? "False" : "false";
_trueStringValue = isVisualBasicAssemblyInfoFile ? "True" : "true";
Expand Down Expand Up @@ -68,6 +72,18 @@ public AssemblyInfoCreatorData(AssemblyInfoSettings settings, bool isVisualBasic
_namespaces.Add("System.Runtime.CompilerServices");
}
}
if (settings.SupportedOSPlatform != null)
{
foreach (var item in settings.SupportedOSPlatform.Where(item => item != null))
{
_supportedOSPlatform.Add(string.Concat("SupportedOSPlatform(\"", item.UnQuote(), "\")"));
}

if (_supportedOSPlatform.Count > 0)
{
_namespaces.Add("System.Runtime.Versioning");
}
}
if (settings.CustomAttributes != null)
{
foreach (var item in settings.CustomAttributes.Where(item => item != null))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

Expand All @@ -13,6 +13,7 @@ namespace Cake.Common.Solution.Project.Properties
public sealed class AssemblyInfoParseResult
{
private readonly List<string> _internalsVisibleTo;
private readonly List<string> _supportedOSPlatform;

/// <summary>
/// Gets a value indicating whether the assembly is CLS compliant.
Expand Down Expand Up @@ -102,6 +103,12 @@ public sealed class AssemblyInfoParseResult
/// <value>The assemblies that internals are visible to.</value>
public ICollection<string> InternalsVisibleTo => _internalsVisibleTo;

/// <summary>
/// Gets the operating system(s) or platform(s) which this assembly supports.
/// </summary>
/// <value>The name(s), and optional version(s), of the supported platform(s).</value>
public ICollection<string> SupportedOSPlatform => _supportedOSPlatform;

/// <summary>
/// Initializes a new instance of the <see cref="AssemblyInfoParseResult"/> class.
/// </summary>
Expand All @@ -119,6 +126,7 @@ public sealed class AssemblyInfoParseResult
/// <param name="trademark">The assembly trademark attribute.</param>
/// <param name="assemblyVersion">The assembly version.</param>
/// <param name="internalsVisibleTo">The assemblies that internals are visible to.</param>
/// <param name="supportedOSPlatform">The operating system(s) or platform(s) which this assembly supports.</param>
public AssemblyInfoParseResult(string clsCompliant,
string company,
string comVisible,
Expand All @@ -132,7 +140,8 @@ public AssemblyInfoParseResult(string clsCompliant,
string title,
string trademark,
string assemblyVersion,
IEnumerable<string> internalsVisibleTo)
IEnumerable<string> internalsVisibleTo,
IEnumerable<string> supportedOSPlatform)
{
ClsCompliant = !string.IsNullOrWhiteSpace(clsCompliant) && bool.Parse(clsCompliant);
Company = company ?? string.Empty;
Expand All @@ -148,6 +157,7 @@ public AssemblyInfoParseResult(string clsCompliant,
Trademark = trademark ?? string.Empty;
AssemblyVersion = assemblyVersion ?? string.Empty;
_internalsVisibleTo = new List<string>(internalsVisibleTo ?? Enumerable.Empty<string>());
_supportedOSPlatform = new List<string>(supportedOSPlatform ?? Enumerable.Empty<string>());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

Expand Down Expand Up @@ -88,7 +88,8 @@ public AssemblyInfoParseResult Parse(FilePath assemblyInfoPath)
ParseSingle(quotedPattern, "AssemblyTitle", content),
ParseSingle(quotedPattern, "AssemblyTrademark", content),
ParseSingle(quotedPattern, "AssemblyVersion", content) ?? DefaultVersion,
ParseMultiple(quotedPattern, "InternalsVisibleTo", content));
ParseMultiple(quotedPattern, "InternalsVisibleTo", content),
ParseMultiple(quotedPattern, "SupportedOSPlatform", content));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ public sealed class AssemblyInfoSettings
/// <value>The name(s) of the assembly(s).</value>
public ICollection<string> InternalsVisibleTo { get; set; }

/// <summary>
/// Gets or sets the operating system(s) or platform(s) which this assembly supports.
/// </summary>
/// <value>The name(s), and optional version(s), of the supported platform(s).</value>
public ICollection<string> SupportedOSPlatform { get; set; }

/// <summary>
/// Gets or sets the configuration of the assembly.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ Task("Cake.Common.Solution.Project.Properties.AssemblyInfoAliases.ParseAssemblyI
"Miny",
"Moe",
"Spacey"
}
},
supportedOSPlatform: new string[] { }
);

// When
Expand All @@ -49,6 +50,7 @@ Task("Cake.Common.Solution.Project.Properties.AssemblyInfoAliases.ParseAssemblyI
Assert.Equal(expect.Trademark, result.Trademark);
Assert.Equal(expect.AssemblyVersion, result.AssemblyVersion);
Assert.Equal(expect.InternalsVisibleTo, result.InternalsVisibleTo);
Assert.Equal(expect.SupportedOSPlatform, result.SupportedOSPlatform);
});

Task("Cake.Common.Solution.Project.Properties.AssemblyInfoAliases.CreateAssemblyInfo")
Expand Down Expand Up @@ -89,6 +91,58 @@ Task("Cake.Common.Solution.Project.Properties.AssemblyInfoAliases.CreateAssembly
Assert.True(FileHashEquals(expectFile, file));
});

Task("Cake.Common.Solution.Project.Properties.AssemblyInfoAliases.CreateAssemblyInfoWithSupportedOSPlatform")
.Does(() =>
{
// Given
var path = Paths.Temp.Combine("./Cake.Common/Solution/Project/Properties/SupportedOSPlatform");
var file = path.CombineWithFilePath("AssemblyInfoWithSupportedOSPlatform.cs");
EnsureDirectoryExist(path);
var settings = new AssemblyInfoSettings {
Company = "The Company",
Product = "The Product",
Version = "1.0",
SupportedOSPlatform = new [] { "windows" }
};

// When
CreateAssemblyInfo(file, settings);

// Then
Assert.True(System.IO.File.Exists(file.FullPath));
var content = System.IO.File.ReadAllText(file.FullPath);
Assert.Contains("using System.Runtime.Versioning;", content);
Assert.Contains("[assembly: SupportedOSPlatform(\"windows\")]", content);
});

Task("Cake.Common.Solution.Project.Properties.AssemblyInfoAliases.CreateAssemblyInfoWithMultipleSupportedOSPlatform")
.Does(() =>
{
// Given
var path = Paths.Temp.Combine("./Cake.Common/Solution/Project/Properties/MultipleSupportedOSPlatform");
var file = path.CombineWithFilePath("AssemblyInfoWithMultipleSupportedOSPlatform.cs");
EnsureDirectoryExist(path);
var settings = new AssemblyInfoSettings {
Company = "The Company",
Product = "The Product",
Version = "1.0",
SupportedOSPlatform = new [] { "windows", "linux", "macos" }
};

// When
CreateAssemblyInfo(file, settings);

// Then
Assert.True(System.IO.File.Exists(file.FullPath));
var content = System.IO.File.ReadAllText(file.FullPath);
Assert.Contains("using System.Runtime.Versioning;", content);
Assert.Contains("[assembly: SupportedOSPlatform(\"windows\")]", content);
Assert.Contains("[assembly: SupportedOSPlatform(\"linux\")]", content);
Assert.Contains("[assembly: SupportedOSPlatform(\"macos\")]", content);
});

Task("Cake.Common.Solution.Project.Properties.AssemblyInfoAliases")
.IsDependentOn("Cake.Common.Solution.Project.Properties.AssemblyInfoAliases.ParseAssemblyInfo")
.IsDependentOn("Cake.Common.Solution.Project.Properties.AssemblyInfoAliases.CreateAssemblyInfo");
.IsDependentOn("Cake.Common.Solution.Project.Properties.AssemblyInfoAliases.CreateAssemblyInfo")
.IsDependentOn("Cake.Common.Solution.Project.Properties.AssemblyInfoAliases.CreateAssemblyInfoWithSupportedOSPlatform")
.IsDependentOn("Cake.Common.Solution.Project.Properties.AssemblyInfoAliases.CreateAssemblyInfoWithMultipleSupportedOSPlatform");
Loading