Skip to content

Commit

Permalink
(cake-build#3641)(cake-build#3642) Add DotNetNuGetHasSource aliases (…
Browse files Browse the repository at this point in the history
…synonym to DotNetCoreNuGetHasSource)
  • Loading branch information
augustoproiete committed Nov 5, 2021
1 parent 66b748f commit e356895
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 11 deletions.
50 changes: 50 additions & 0 deletions src/Cake.Common/Tools/DotNet/DotNetAliases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,56 @@ public static void DotNetNuGetEnableSource(this ICakeContext context, string nam
sourcer.EnableSource(name, settings ?? new DotNetNuGetSourceSettings());
}

/// <summary>
/// Determines whether the specified NuGet source exists.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="name">The name of the source.</param>
/// <returns>Whether the specified NuGet source exists.</returns>
/// <example>
/// <code>
/// var exists = DotNetNuGetHasSource("example");
/// </code>
/// </example>
[CakeMethodAlias]
[CakeAliasCategory("NuGet")]
[CakeNamespaceImport("Cake.Common.Tools.DotNet.NuGet.Source")]
public static bool DotNetNuGetHasSource(this ICakeContext context, string name)
{
return context.DotNetNuGetHasSource(name, null);
}

/// <summary>
/// Determines whether the specified NuGet source exists.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="name">The name of the source.</param>
/// <param name="settings">The settings.</param>
/// <returns>Whether the specified NuGet source exists.</returns>
/// <example>
/// <code>
/// var settings = new DotNetNuGetSourceSettings
/// {
/// ConfigFile = "NuGet.config"
/// };
///
/// var exists = DotNetNuGetHasSource("example", settings);
/// </code>
/// </example>
[CakeMethodAlias]
[CakeAliasCategory("NuGet")]
[CakeNamespaceImport("Cake.Common.Tools.DotNet.NuGet.Source")]
public static bool DotNetNuGetHasSource(this ICakeContext context, string name, DotNetNuGetSourceSettings settings)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}

var sourcer = new DotNetCoreNuGetSourcer(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools);
return sourcer.HasSource(name, settings ?? new DotNetNuGetSourceSettings());
}

/// <summary>
/// Package all projects.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 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.NuGet.Source;

namespace Cake.Common.Tools.DotNet.NuGet.Source
{
/// <summary>
/// Contains settings used by <see cref="DotNetCoreNuGetSourcer" /> for checking if a NuGet source exists.
/// </summary>
public class DotNetNuGetHasSourceSettings : DotNetNuGetSourceSettings
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 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.NuGet.Source;

namespace Cake.Common.Tools.DotNet.NuGet.Source
{
/// <summary>
/// Contains settings used by <see cref="DotNetCoreNuGetSourcer" /> for listing NuGet sources.
/// </summary>
public class DotNetNuGetListSourceSettings : DotNetNuGetSourceSettings
{
}
}
14 changes: 6 additions & 8 deletions src/Cake.Common/Tools/DotNetCore/DotNetCoreAliases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,7 @@ public static void DotNetCoreNuGetEnableSource(this ICakeContext context, string
}

/// <summary>
/// [deprecated] DotNetCoreNuGetHasSource is obsolete and will be removed in a future release. Use <see cref="DotNetAliases.DotNetNuGetHasSource(ICakeContext, string)" /> instead.
/// Determines whether the specified NuGet source exists.
/// </summary>
/// <param name="context">The context.</param>
Expand All @@ -1022,12 +1023,14 @@ public static void DotNetCoreNuGetEnableSource(this ICakeContext context, string
[CakeMethodAlias]
[CakeAliasCategory("NuGet")]
[CakeNamespaceImport("Cake.Common.Tools.DotNetCore.NuGet.Source")]
[Obsolete("DotNetCoreNuGetHasSource is obsolete and will be removed in a future release. Use DotNetNuGetHasSource instead.")]
public static bool DotNetCoreNuGetHasSource(this ICakeContext context, string name)
{
return context.DotNetCoreNuGetHasSource(name, null);
return context.DotNetNuGetHasSource(name);
}

/// <summary>
/// [deprecated] DotNetCoreNuGetHasSource is obsolete and will be removed in a future release. Use <see cref="DotNetAliases.DotNetNuGetHasSource(ICakeContext, string, DotNetNuGetSourceSettings)" /> instead.
/// Determines whether the specified NuGet source exists.
/// </summary>
/// <param name="context">The context.</param>
Expand All @@ -1047,15 +1050,10 @@ public static bool DotNetCoreNuGetHasSource(this ICakeContext context, string na
[CakeMethodAlias]
[CakeAliasCategory("NuGet")]
[CakeNamespaceImport("Cake.Common.Tools.DotNetCore.NuGet.Source")]
[Obsolete("DotNetCoreNuGetHasSource is obsolete and will be removed in a future release. Use DotNetNuGetHasSource instead.")]
public static bool DotNetCoreNuGetHasSource(this ICakeContext context, string name, DotNetCoreNuGetSourceSettings settings)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}

var sourcer = new DotNetCoreNuGetSourcer(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools);
return sourcer.HasSource(name, settings ?? new DotNetCoreNuGetSourceSettings());
return context.DotNetNuGetHasSource(name, settings);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public void EnableSource(string name, DotNetNuGetSourceSettings settings)
/// <param name="name">The name of the source.</param>
/// <param name="settings">The settings.</param>
/// <returns>Whether the specified NuGet source exists.</returns>
public bool HasSource(string name, DotNetCoreNuGetSourceSettings settings)
public bool HasSource(string name, DotNetNuGetSourceSettings settings)
{
if (string.IsNullOrWhiteSpace(name))
{
Expand All @@ -130,7 +130,7 @@ public bool HasSource(string name, DotNetCoreNuGetSourceSettings settings)
/// <param name="format">The output format. Accepts two values: detailed (the default) and short.</param>
/// <param name="settings">The settings.</param>
/// <returns>The NuGet sources.</returns>
public string ListSource(string format, DotNetCoreNuGetSourceSettings settings)
public string ListSource(string format, DotNetNuGetSourceSettings settings)
{
if (settings == null)
{
Expand Down Expand Up @@ -245,7 +245,7 @@ private ProcessArgumentBuilder GetEnableSourceArguments(string name, DotNetNuGet
return builder;
}

private ProcessArgumentBuilder GetListSourceArguments(string format, DotNetCoreNuGetSourceSettings settings)
private ProcessArgumentBuilder GetListSourceArguments(string format, DotNetNuGetSourceSettings settings)
{
var builder = CreateArgumentBuilder(settings);

Expand Down

0 comments on commit e356895

Please sign in to comment.