Skip to content
This repository has been archived by the owner on Jan 11, 2024. It is now read-only.

Commit

Permalink
Add XML attribute and artifact orderings
Browse files Browse the repository at this point in the history
  • Loading branch information
dagood committed Dec 20, 2017
1 parent 1102db3 commit bd84b29
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ public void TestMergeBuildManifests()
<OrchestratedBuild Name=""Orchestrated"" BuildId=""123"">
<Endpoint Id=""Orchestrated"" Type=""BlobFeed"" Url=""http://example.org"">
<Package Id=""Foo"" Version=""1.2.3-example"" />
<Package Id=""System.Memory"" Version=""4.5.0-preview1-25927-01"" />
<Package Id=""runtime.rhel.6-x64.Microsoft.Private.CoreFx.NETCoreApp"" Version=""4.5.0-preview1-25929-04"" Category=""noship"" />
<Blob Id=""symbols/System.ValueTuple.4.5.0-preview1-25929-04.symbols.nupkg"" NonShipping=""true"" />
<Blob Id=""symbols/runtime.rhel.6-x64.Microsoft.Private.CoreFx.NETCoreApp.4.5.0-preview1-25929-04.symbols.nupkg"" />
<Package Id=""System.Memory"" Version=""4.5.0-preview1-25927-01"" />
<Blob Id=""symbols/inner/blank-dir-nonshipping"" NonShipping=""false"" />
<Blob Id=""symbols/runtime.rhel.6-x64.Microsoft.Private.CoreFx.NETCoreApp.4.5.0-preview1-25929-04.symbols.nupkg"" />
<Blob Id=""symbols/System.ValueTuple.4.5.0-preview1-25929-04.symbols.nupkg"" NonShipping=""true"" />
</Endpoint>
<Build Name=""SimpleBuildManifest"" BuildId=""123"" />
<Build Name=""corefx"" BuildId=""20171129-04"" Branch=""master"" Commit=""defb6d52047cc3d6b5f5d0853b0afdb1512dfbf4"" />
Expand Down Expand Up @@ -110,12 +110,12 @@ private BuildModel CreatePackageOnlyBuildManifestModel()
Branch=""master""
Commit=""defb6d52047cc3d6b5f5d0853b0afdb1512dfbf4"">
<Package Id=""System.Memory"" Version=""4.5.0-preview1-25927-01"" />
<Package Id=""runtime.rhel.6-x64.Microsoft.Private.CoreFx.NETCoreApp"" Version=""4.5.0-preview1-25929-04"" Category=""noship"" />
<Package Id=""System.Memory"" Version=""4.5.0-preview1-25927-01"" />
<Blob Id=""symbols/System.ValueTuple.4.5.0-preview1-25929-04.symbols.nupkg"" NonShipping=""true"" />
<Blob Id=""symbols/runtime.rhel.6-x64.Microsoft.Private.CoreFx.NETCoreApp.4.5.0-preview1-25929-04.symbols.nupkg"" />
<Blob Id=""symbols/inner/blank-dir-nonshipping"" NonShipping=""false"" />
<Blob Id=""symbols/runtime.rhel.6-x64.Microsoft.Private.CoreFx.NETCoreApp.4.5.0-preview1-25929-04.symbols.nupkg"" />
<Blob Id=""symbols/System.ValueTuple.4.5.0-preview1-25929-04.symbols.nupkg"" NonShipping=""true"" />
</Build>";

Expand All @@ -132,17 +132,17 @@ private BuildModel CreatePackageOnlyBuildManifestModel()
<Package Id=""Microsoft.NETCore.App"" Version=""2.1.0-preview1-26001-02"" />
<Package Id=""Microsoft.NETCore.UniversalWindowsPlatform"" Version=""6.1.0-preview1-25927-01"" NonShipping=""true"" />
<Package Id=""System.Memory"" Version=""4.5.0-preview1-25927-01"" />
<Package Id=""runtime.rhel.6-x64.Microsoft.Private.CoreFx.NETCoreApp"" Version=""4.5.0-preview1-25929-04"" NonShipping=""true"" />
<Package Id=""System.Memory"" Version=""4.5.0-preview1-25927-01"" />
<Blob Id=""orchestration-metadata/manifests/corefx.xml"" />
<Blob Id=""orchestration-metadata/manifests/core-setup.xml"" />
<Blob Id=""orchestration-metadata/manifests/corefx.xml"" />
<Blob Id=""orchestration-metadata/PackageVersions.props"" />
<Blob Id=""Runtime/2.1.0-preview1-25929-04/dotnet-runtime-2.1.0-preview1-25929-04-win-x64.msi"" ShipInstaller=""dotnetcli"" />
<Blob Id=""Runtime/2.1.0-preview1-25929-04/dotnet-runtime-2.1.0-preview1-25929-04-win-x64.msi.sha512"" ShipInstaller=""dotnetclichecksums"" />
<Blob Id=""symbols/Microsoft.DotNet.PlatformAbstractions.2.1.0-preview1-25929-04.symbols.nupkg"" />
<Blob Id=""symbols/System.ValueTuple.4.5.0-preview1-25929-04.symbols.nupkg"" />
<Blob Id=""symbols/runtime.rhel.6-x64.Microsoft.Private.CoreFx.NETCoreApp.4.5.0-preview1-25929-04.symbols.nupkg"" />
<Blob Id=""symbols/System.ValueTuple.4.5.0-preview1-25929-04.symbols.nupkg"" />
</Endpoint>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
Expand All @@ -21,8 +22,13 @@ public void Add(ArtifactSet source)
}

public IEnumerable<XElement> ToXml() => Enumerable.Concat(
Packages.Select(p => p.ToXml()),
Blobs.Select(b => b.ToXml()));
Packages
.OrderBy(p => p.Id, StringComparer.OrdinalIgnoreCase)
.ThenBy(p => p.Version, StringComparer.OrdinalIgnoreCase)
.Select(p => p.ToXml()),
Blobs
.OrderBy(b => b.Id, StringComparer.OrdinalIgnoreCase)
.Select(b => b.ToXml()));

public static ArtifactSet Parse(XElement xml) => new ArtifactSet
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ namespace Microsoft.DotNet.VersionTools.BuildManifest.Model
{
public class BlobArtifactModel
{
private static readonly string[] AttributeOrder =
{
nameof(Id)
};

public Dictionary<string, string> Attributes { get; set; } = new Dictionary<string, string>();

public string Id
Expand All @@ -21,7 +26,7 @@ public string Id

public XElement ToXml() => new XElement(
"Blob",
Attributes.CreateXmlAttributes());
Attributes.CreateXmlAttributes(AttributeOrder));

public static BlobArtifactModel Parse(XElement xml) => new BlobArtifactModel
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ namespace Microsoft.DotNet.VersionTools.BuildManifest.Model
{
public class EndpointModel
{
private static readonly string[] AttributeOrder =
{
nameof(Id),
nameof(Type),
nameof(Url)
};

public const string BlobFeedType = "BlobFeed";

public const string OrchestratedBlobFeedId = "Orchestrated";
Expand Down Expand Up @@ -41,7 +48,7 @@ public string Url

public XElement ToXml() => new XElement(
"Endpoint",
Attributes.CreateXmlAttributes(),
Attributes.CreateXmlAttributes(AttributeOrder),
Artifacts?.ToXml());

public static EndpointModel Parse(XElement xml) => new EndpointModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ namespace Microsoft.DotNet.VersionTools.BuildManifest.Model
{
public class PackageArtifactModel
{
private static readonly string[] AttributeOrder =
{
nameof(Id),
nameof(Version)
};

public Dictionary<string, string> Attributes { get; set; } = new Dictionary<string, string>();

public string Id
Expand All @@ -27,7 +33,7 @@ public string Version

public XElement ToXml() => new XElement(
"Package",
Attributes.CreateXmlAttributes());
Attributes.CreateXmlAttributes(AttributeOrder));

public static PackageArtifactModel Parse(XElement xml) => new PackageArtifactModel
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,15 @@ public static string GetRequiredAttribute(this XElement element, XName name)
return element.Attributes().ToDictionary(a => a.Name.LocalName, a => a.Value);
}

public static XAttribute[] CreateXmlAttributes(this Dictionary<string, string> attributes)
public static XAttribute[] CreateXmlAttributes(
this Dictionary<string, string> attributes,
string[] keySortOrder)
{
return attributes.Select(pair => new XAttribute(pair.Key, pair.Value)).ToArray();
return attributes
.OrderBy(pair => keySortOrder.TakeWhile(o => pair.Key != o).Count())
.ThenBy(pair => pair.Key, StringComparer.OrdinalIgnoreCase)
.Select(pair => new XAttribute(pair.Key, pair.Value))
.ToArray();
}
}
}

0 comments on commit bd84b29

Please sign in to comment.