From 7ff3b373d5e36571eec4cb1009a015a753c82056 Mon Sep 17 00:00:00 2001 From: "C. Augusto Proiete" Date: Mon, 25 Oct 2021 21:54:12 -0300 Subject: [PATCH] (#3553) Add DotNetNuGetPush aliases (synonym to DotNetCoreNuGetPush) --- src/Cake.Common/Tools/DotNet/DotNetAliases.cs | 63 +++++++++++++ .../NuGet/Push/DotNetNuGetPushSettings.cs | 89 +++++++++++++++++++ .../Tools/DotNetCore/DotNetCoreAliases.cs | 20 ++--- .../NuGet/Push/DotNetCoreNuGetPushSettings.cs | 77 +--------------- .../NuGet/Push/DotNetCoreNuGetPusher.cs | 7 +- 5 files changed, 166 insertions(+), 90 deletions(-) create mode 100644 src/Cake.Common/Tools/DotNet/NuGet/Push/DotNetNuGetPushSettings.cs diff --git a/src/Cake.Common/Tools/DotNet/DotNetAliases.cs b/src/Cake.Common/Tools/DotNet/DotNetAliases.cs index dbeb22acbd..271d079b5b 100644 --- a/src/Cake.Common/Tools/DotNet/DotNetAliases.cs +++ b/src/Cake.Common/Tools/DotNet/DotNetAliases.cs @@ -10,6 +10,7 @@ using Cake.Common.Tools.DotNet.Clean; using Cake.Common.Tools.DotNet.Execute; using Cake.Common.Tools.DotNet.MSBuild; +using Cake.Common.Tools.DotNet.NuGet.Push; using Cake.Common.Tools.DotNet.Pack; using Cake.Common.Tools.DotNet.Publish; using Cake.Common.Tools.DotNet.Restore; @@ -22,6 +23,7 @@ using Cake.Common.Tools.DotNetCore.Clean; using Cake.Common.Tools.DotNetCore.Execute; using Cake.Common.Tools.DotNetCore.MSBuild; +using Cake.Common.Tools.DotNetCore.NuGet.Push; using Cake.Common.Tools.DotNetCore.Pack; using Cake.Common.Tools.DotNetCore.Publish; using Cake.Common.Tools.DotNetCore.Restore; @@ -559,6 +561,67 @@ public static void DotNetClean(this ICakeContext context, string project, DotNet cleaner.Clean(project, settings); } + /// + /// Pushes one or more packages to a server. + /// + /// The context. + /// of the package to push. + /// + /// + /// // With FilePath instance + /// var packageFilePath = GetFiles("*.nupkg").Single(); + /// DotNetNuGetPush(packageFilePath); + /// // With string parameter + /// DotNetNuGetPush("foo*.nupkg"); + /// + /// + [CakeMethodAlias] + [CakeAliasCategory("NuGet")] + [CakeNamespaceImport("Cake.Common.Tools.DotNet.NuGet.Push")] + public static void DotNetNuGetPush(this ICakeContext context, FilePath packageFilePath) + { + context.DotNetNuGetPush(packageFilePath, null); + } + + /// + /// Pushes one or more packages to a server using the specified settings. + /// + /// The context. + /// of the package to push. + /// The settings. + /// + /// + /// var settings = new DotNetNuGetPushSettings + /// { + /// Source = "https://www.example.com/nugetfeed", + /// ApiKey = "4003d786-cc37-4004-bfdf-c4f3e8ef9b3a" + /// }; + /// // With FilePath instance + /// var packageFilePath = GetFiles("foo*.nupkg").Single(); + /// DotNetNuGetPush(packageFilePath); + /// // With string parameter + /// DotNetNuGetPush("foo*.nupkg", settings); + /// + /// + [CakeMethodAlias] + [CakeAliasCategory("NuGet")] + [CakeNamespaceImport("Cake.Common.Tools.DotNet.NuGet.Push")] + public static void DotNetNuGetPush(this ICakeContext context, FilePath packageFilePath, DotNetNuGetPushSettings settings) + { + if (context is null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (settings is null) + { + settings = new DotNetNuGetPushSettings(); + } + + var restorer = new DotNetCoreNuGetPusher(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools); + restorer.Push(packageFilePath?.FullPath, settings); + } + /// /// Package all projects. /// diff --git a/src/Cake.Common/Tools/DotNet/NuGet/Push/DotNetNuGetPushSettings.cs b/src/Cake.Common/Tools/DotNet/NuGet/Push/DotNetNuGetPushSettings.cs new file mode 100644 index 0000000000..0b0eac68b1 --- /dev/null +++ b/src/Cake.Common/Tools/DotNet/NuGet/Push/DotNetNuGetPushSettings.cs @@ -0,0 +1,89 @@ +// 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. + +using Cake.Common.Tools.DotNetCore; +using Cake.Common.Tools.DotNetCore.NuGet.Push; + +namespace Cake.Common.Tools.DotNet.NuGet.Push +{ + /// + /// Contains settings used by . + /// + public class DotNetNuGetPushSettings : DotNetCoreSettings + { + /// + /// Gets or sets a value indicating the server URL. + /// + /// + /// This option is required unless DefaultPushSource config value is set in the NuGet config file. + /// + public string Source { get; set; } + + /// + /// Gets or sets a value indicating the symbol server URL. + /// + public string SymbolSource { get; set; } + + /// + /// Gets or sets a value indicating whether to append "api/v2/package" to the source URL. + /// + /// + /// Available since .NET Core 2.1 SDK. + /// + public bool NoServiceEndpoint { get; set; } + + /// + /// Gets or sets a value indicating whether to block and require manual action for operations like authentication. + /// + /// + /// Available since .NET Core 2.2 SDK. + /// + public bool Interactive { get; set; } + + /// + /// Gets or sets a value indicating timeout for pushing to a server in seconds. + /// + /// Defaults to 300 seconds (5 minutes). Specifying 0 (zero seconds) applies the default value. + /// + /// + public int? Timeout { get; set; } + + /// + /// Gets or sets a value indicating the API key for the server. + /// + public string ApiKey { get; set; } + + /// + /// Gets or sets a value indicating the API key for the symbol server. + /// + public string SymbolApiKey { get; set; } + + /// + /// Gets or sets a value indicating whether buffering is disabled when pushing to an HTTP(S) server. + /// + /// + /// This decreases memory usage. + /// + public bool DisableBuffering { get; set; } + + /// + /// Gets or sets a value indicating whether symbols should be not be pushed if present. + /// + public bool IgnoreSymbols { get; set; } + + /// + /// Gets or sets a value indicating whether, when pushing multiple packages to an HTTP(S) server, + /// to treat any 409 Conflict response as a warning so that the push can continue. + /// + /// + /// Available since .NET Core 3.1 SDK. + /// + public bool SkipDuplicate { get; set; } + + /// + /// Gets or sets a value indicating whether to force command-line output in English. + /// + public bool ForceEnglishOutput { get; set; } + } +} \ No newline at end of file diff --git a/src/Cake.Common/Tools/DotNetCore/DotNetCoreAliases.cs b/src/Cake.Common/Tools/DotNetCore/DotNetCoreAliases.cs index 7b75b3312c..b7c249fed5 100644 --- a/src/Cake.Common/Tools/DotNetCore/DotNetCoreAliases.cs +++ b/src/Cake.Common/Tools/DotNetCore/DotNetCoreAliases.cs @@ -11,6 +11,7 @@ using Cake.Common.Tools.DotNet.Clean; using Cake.Common.Tools.DotNet.Execute; using Cake.Common.Tools.DotNet.MSBuild; +using Cake.Common.Tools.DotNet.NuGet.Push; using Cake.Common.Tools.DotNet.Pack; using Cake.Common.Tools.DotNet.Publish; using Cake.Common.Tools.DotNet.Restore; @@ -829,6 +830,7 @@ public static void DotNetCoreNuGetDelete(this ICakeContext context, string packa } /// + /// [deprecated] DotNetCoreNuGetPush is obsolete and will be removed in a future release. Use instead. /// Pushes one or more packages to a server. /// /// The context. @@ -845,12 +847,14 @@ public static void DotNetCoreNuGetDelete(this ICakeContext context, string packa [CakeMethodAlias] [CakeAliasCategory("NuGet")] [CakeNamespaceImport("Cake.Common.Tools.DotNetCore.NuGet.Push")] + [Obsolete("DotNetCoreNuGetPush is obsolete and will be removed in a future release. Use DotNetNuGetPush instead.")] public static void DotNetCoreNuGetPush(this ICakeContext context, FilePath packageFilePath) { - context.DotNetCoreNuGetPush(packageFilePath, null); + context.DotNetNuGetPush(packageFilePath); } /// + /// [deprecated] DotNetCoreNuGetPush is obsolete and will be removed in a future release. Use instead. /// Pushes one or more packages to a server using the specified settings. /// /// The context. @@ -873,20 +877,10 @@ public static void DotNetCoreNuGetPush(this ICakeContext context, FilePath packa [CakeMethodAlias] [CakeAliasCategory("NuGet")] [CakeNamespaceImport("Cake.Common.Tools.DotNetCore.NuGet.Push")] + [Obsolete("DotNetCoreNuGetPush is obsolete and will be removed in a future release. Use DotNetNuGetPush instead.")] public static void DotNetCoreNuGetPush(this ICakeContext context, FilePath packageFilePath, DotNetCoreNuGetPushSettings settings) { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } - - if (settings == null) - { - settings = new DotNetCoreNuGetPushSettings(); - } - - var restorer = new DotNetCoreNuGetPusher(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools); - restorer.Push(packageFilePath?.FullPath, settings); + context.DotNetNuGetPush(packageFilePath, settings); } /// diff --git a/src/Cake.Common/Tools/DotNetCore/NuGet/Push/DotNetCoreNuGetPushSettings.cs b/src/Cake.Common/Tools/DotNetCore/NuGet/Push/DotNetCoreNuGetPushSettings.cs index 128fdc784c..35d0ce0ca5 100644 --- a/src/Cake.Common/Tools/DotNetCore/NuGet/Push/DotNetCoreNuGetPushSettings.cs +++ b/src/Cake.Common/Tools/DotNetCore/NuGet/Push/DotNetCoreNuGetPushSettings.cs @@ -2,85 +2,14 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using Cake.Common.Tools.DotNet.NuGet.Push; + namespace Cake.Common.Tools.DotNetCore.NuGet.Push { /// /// Contains settings used by . /// - public sealed class DotNetCoreNuGetPushSettings : DotNetCoreSettings + public sealed class DotNetCoreNuGetPushSettings : DotNetNuGetPushSettings { - /// - /// Gets or sets a value indicating the server URL. - /// - /// - /// This option is required unless DefaultPushSource config value is set in the NuGet config file. - /// - public string Source { get; set; } - - /// - /// Gets or sets a value indicating the symbol server URL. - /// - public string SymbolSource { get; set; } - - /// - /// Gets or sets a value indicating whether to append "api/v2/package" to the source URL. - /// - /// - /// Available since .NET Core 2.1 SDK. - /// - public bool NoServiceEndpoint { get; set; } - - /// - /// Gets or sets a value indicating whether to block and require manual action for operations like authentication. - /// - /// - /// Available since .NET Core 2.2 SDK. - /// - public bool Interactive { get; set; } - - /// - /// Gets or sets a value indicating timeout for pushing to a server in seconds. - /// - /// Defaults to 300 seconds (5 minutes). Specifying 0 (zero seconds) applies the default value. - /// - /// - public int? Timeout { get; set; } - - /// - /// Gets or sets a value indicating the API key for the server. - /// - public string ApiKey { get; set; } - - /// - /// Gets or sets a value indicating the API key for the symbol server. - /// - public string SymbolApiKey { get; set; } - - /// - /// Gets or sets a value indicating whether buffering is disabled when pushing to an HTTP(S) server. - /// - /// - /// This decreases memory usage. - /// - public bool DisableBuffering { get; set; } - - /// - /// Gets or sets a value indicating whether symbols should be not be pushed if present. - /// - public bool IgnoreSymbols { get; set; } - - /// - /// Gets or sets a value indicating whether, when pushing multiple packages to an HTTP(S) server, - /// to treat any 409 Conflict response as a warning so that the push can continue. - /// - /// - /// Available since .NET Core 3.1 SDK. - /// - public bool SkipDuplicate { get; set; } - - /// - /// Gets or sets a value indicating whether to force command-line output in English. - /// - public bool ForceEnglishOutput { get; set; } } } \ No newline at end of file diff --git a/src/Cake.Common/Tools/DotNetCore/NuGet/Push/DotNetCoreNuGetPusher.cs b/src/Cake.Common/Tools/DotNetCore/NuGet/Push/DotNetCoreNuGetPusher.cs index e30502bbb8..6c296fb33b 100644 --- a/src/Cake.Common/Tools/DotNetCore/NuGet/Push/DotNetCoreNuGetPusher.cs +++ b/src/Cake.Common/Tools/DotNetCore/NuGet/Push/DotNetCoreNuGetPusher.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System; +using Cake.Common.Tools.DotNet.NuGet.Push; using Cake.Core; using Cake.Core.IO; using Cake.Core.Tooling; @@ -12,7 +13,7 @@ namespace Cake.Common.Tools.DotNetCore.NuGet.Push /// /// .NET Core nuget pusher. Pushes a package and its symbols to the server. /// - public sealed class DotNetCoreNuGetPusher : DotNetCoreTool + public sealed class DotNetCoreNuGetPusher : DotNetCoreTool { /// /// Initializes a new instance of the class. @@ -34,7 +35,7 @@ public DotNetCoreNuGetPusher( /// /// The name of the target package. /// The settings. - public void Push(string packageName, DotNetCoreNuGetPushSettings settings) + public void Push(string packageName, DotNetNuGetPushSettings settings) { if (settings == null) { @@ -44,7 +45,7 @@ public void Push(string packageName, DotNetCoreNuGetPushSettings settings) RunCommand(settings, GetArguments(packageName, settings)); } - private ProcessArgumentBuilder GetArguments(string packageName, DotNetCoreNuGetPushSettings settings) + private ProcessArgumentBuilder GetArguments(string packageName, DotNetNuGetPushSettings settings) { if (string.IsNullOrWhiteSpace(packageName)) {