This repository has been archived by the owner on Mar 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #418 from NuGet/dev
[ReleasePrep][2018.11.26]RI of dev into master
- Loading branch information
Showing
115 changed files
with
5,022 additions
and
1,291 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Globalization; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace NuGet.Services.Metadata.Catalog | ||
{ | ||
/// <summary> | ||
/// Represents a single catalog commit. | ||
/// </summary> | ||
public sealed class CatalogCommit : IComparable | ||
{ | ||
private CatalogCommit(DateTime commitTimeStamp, Uri uri) | ||
{ | ||
CommitTimeStamp = commitTimeStamp; | ||
Uri = uri; | ||
} | ||
|
||
public DateTime CommitTimeStamp { get; } | ||
public Uri Uri { get; } | ||
|
||
public int CompareTo(object obj) | ||
{ | ||
var other = obj as CatalogCommit; | ||
|
||
if (ReferenceEquals(other, null)) | ||
{ | ||
throw new ArgumentException( | ||
string.Format(CultureInfo.InvariantCulture, Strings.ArgumentMustBeInstanceOfType, nameof(CatalogCommit)), | ||
nameof(obj)); | ||
} | ||
|
||
return CommitTimeStamp.CompareTo(other.CommitTimeStamp); | ||
} | ||
|
||
public static CatalogCommit Create(JObject commit) | ||
{ | ||
if (commit == null) | ||
{ | ||
throw new ArgumentNullException(nameof(commit)); | ||
} | ||
|
||
var commitTimeStamp = Utils.Deserialize<DateTime>(commit, "commitTimeStamp"); | ||
var uri = Utils.Deserialize<Uri>(commit, "@id"); | ||
|
||
return new CatalogCommit(commitTimeStamp, uri); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Globalization; | ||
using System.Linq; | ||
using Newtonsoft.Json.Linq; | ||
using NuGet.Packaging.Core; | ||
using NuGet.Versioning; | ||
|
||
namespace NuGet.Services.Metadata.Catalog | ||
{ | ||
/// <summary> | ||
/// Represents a single item in a catalog commit. | ||
/// </summary> | ||
public sealed class CatalogCommitItem : IComparable | ||
{ | ||
private const string _typeKeyword = "@type"; | ||
|
||
private CatalogCommitItem( | ||
Uri uri, | ||
string commitId, | ||
DateTime commitTimeStamp, | ||
IReadOnlyList<string> types, | ||
IReadOnlyList<Uri> typeUris, | ||
PackageIdentity packageIdentity) | ||
{ | ||
Uri = uri; | ||
CommitId = commitId; | ||
CommitTimeStamp = commitTimeStamp; | ||
PackageIdentity = packageIdentity; | ||
Types = types; | ||
TypeUris = typeUris; | ||
} | ||
|
||
public Uri Uri { get; } | ||
public DateTime CommitTimeStamp { get; } | ||
public string CommitId { get; } | ||
public PackageIdentity PackageIdentity { get; } | ||
public IReadOnlyList<string> Types { get; } | ||
public IReadOnlyList<Uri> TypeUris { get; } | ||
|
||
public int CompareTo(object obj) | ||
{ | ||
var other = obj as CatalogCommitItem; | ||
|
||
if (ReferenceEquals(other, null)) | ||
{ | ||
throw new ArgumentException( | ||
string.Format(CultureInfo.InvariantCulture, Strings.ArgumentMustBeInstanceOfType, nameof(CatalogCommitItem)), | ||
nameof(obj)); | ||
} | ||
|
||
return CommitTimeStamp.CompareTo(other.CommitTimeStamp); | ||
} | ||
|
||
public static CatalogCommitItem Create(JObject context, JObject commitItem) | ||
{ | ||
if (context == null) | ||
{ | ||
throw new ArgumentNullException(nameof(context)); | ||
} | ||
|
||
if (commitItem == null) | ||
{ | ||
throw new ArgumentNullException(nameof(commitItem)); | ||
} | ||
|
||
var commitTimeStamp = Utils.Deserialize<DateTime>(commitItem, "commitTimeStamp"); | ||
var commitId = Utils.Deserialize<string>(commitItem, "commitId"); | ||
var idUri = Utils.Deserialize<Uri>(commitItem, "@id"); | ||
var packageId = Utils.Deserialize<string>(commitItem, "nuget:id"); | ||
var packageVersion = Utils.Deserialize<string>(commitItem, "nuget:version"); | ||
var packageIdentity = new PackageIdentity(packageId, new NuGetVersion(packageVersion)); | ||
var types = GetTypes(commitItem).ToArray(); | ||
|
||
if (!types.Any()) | ||
{ | ||
throw new ArgumentException( | ||
string.Format(CultureInfo.InvariantCulture, Strings.NonEmptyPropertyValueRequired, _typeKeyword), | ||
nameof(commitItem)); | ||
} | ||
|
||
var typeUris = types.Select(type => Utils.Expand(context, type)).ToArray(); | ||
|
||
return new CatalogCommitItem(idUri, commitId, commitTimeStamp, types, typeUris, packageIdentity); | ||
} | ||
|
||
private static IEnumerable<string> GetTypes(JObject commitItem) | ||
{ | ||
if (commitItem.TryGetValue(_typeKeyword, out var value)) | ||
{ | ||
if (value is JArray) | ||
{ | ||
foreach (JToken typeToken in ((JArray)value).Values()) | ||
{ | ||
yield return typeToken.ToString(); | ||
} | ||
} | ||
else | ||
{ | ||
yield return value.ToString(); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace NuGet.Services.Metadata.Catalog | ||
{ | ||
/// <summary> | ||
/// Represents a group of <see cref="CatalogCommitItem" />. | ||
/// Items may span multiple commits but are grouped on common criteria (e.g.: lower-cased package ID). | ||
/// </summary> | ||
public sealed class CatalogCommitItemBatch | ||
{ | ||
/// <summary> | ||
/// Initializes a <see cref="CatalogCommitItemBatch" /> instance. | ||
/// </summary> | ||
/// <param name="items">An enumerable of <see cref="CatalogCommitItem" />. Items may span multiple commits.</param> | ||
/// <param name="key">A unique key for all items in a batch. This is used for parallelization and may be | ||
/// <c>null</c> if parallelization is not used.</param> | ||
/// <exception cref="ArgumentException">Thrown if <paramref name="items" /> is either <c>null</c> or empty.</exception> | ||
public CatalogCommitItemBatch(IEnumerable<CatalogCommitItem> items, string key = null) | ||
{ | ||
if (items == null || !items.Any()) | ||
{ | ||
throw new ArgumentException(Strings.ArgumentMustNotBeNullOrEmpty, nameof(items)); | ||
} | ||
|
||
var list = items.ToList(); | ||
|
||
CommitTimeStamp = list.Min(item => item.CommitTimeStamp); | ||
Key = key; | ||
|
||
list.Sort(); | ||
|
||
Items = list; | ||
} | ||
|
||
public DateTime CommitTimeStamp { get; } | ||
public IReadOnlyList<CatalogCommitItem> Items { get; } | ||
public string Key { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace NuGet.Services.Metadata.Catalog | ||
{ | ||
/// <summary> | ||
/// Represents an asynchrononous task associated with catalog changes for a specific | ||
/// <see cref="CatalogCommitItemBatch" /> and potentially spanning multiple commits. | ||
/// </summary> | ||
public sealed class CatalogCommitItemBatchTask : IEquatable<CatalogCommitItemBatchTask> | ||
{ | ||
/// <summary> | ||
/// Initializes a <see cref="CatalogCommitItemBatchTask" /> instance. | ||
/// </summary> | ||
/// <param name="batch">A <see cref="CatalogCommitItemBatch" />.</param> | ||
/// <param name="task">A <see cref="System.Threading.Tasks.Task" /> tracking completion of | ||
/// <paramref name="batch" /> processing.</param> | ||
/// <exception cref="ArgumentNullException">Thrown if <paramref name="batch" /> is <c>null</c>.</exception> | ||
/// <exception cref="ArgumentException">Thrown if <see cref="CatalogCommitItemBatch.Key" /> is <c>null</c>.</exception> | ||
/// <exception cref="ArgumentNullException">Thrown if <paramref name="task" /> is <c>null</c>.</exception> | ||
public CatalogCommitItemBatchTask(CatalogCommitItemBatch batch, Task task) | ||
{ | ||
if (batch == null) | ||
{ | ||
throw new ArgumentNullException(nameof(batch)); | ||
} | ||
|
||
if (batch.Key == null) | ||
{ | ||
throw new ArgumentException(Strings.ArgumentMustNotBeNull, $"{nameof(batch)}.{nameof(batch.Key)}"); | ||
} | ||
|
||
if (task == null) | ||
{ | ||
throw new ArgumentNullException(nameof(task)); | ||
} | ||
|
||
Batch = batch; | ||
Task = task; | ||
} | ||
|
||
public CatalogCommitItemBatch Batch { get; } | ||
public Task Task { get; } | ||
|
||
public override int GetHashCode() | ||
{ | ||
return Batch.Key.GetHashCode(); | ||
} | ||
|
||
public override bool Equals(object obj) | ||
{ | ||
return Equals(obj as CatalogCommitItemBatchTask); | ||
} | ||
|
||
public bool Equals(CatalogCommitItemBatchTask other) | ||
{ | ||
if (ReferenceEquals(other, null)) | ||
{ | ||
return false; | ||
} | ||
|
||
return string.Equals(Batch.Key, other.Batch.Key); | ||
} | ||
} | ||
} |
Oops, something went wrong.