Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
matkoch committed May 15, 2023
1 parent a796255 commit 7f44bf5
Show file tree
Hide file tree
Showing 29 changed files with 62 additions and 38 deletions.
1 change: 1 addition & 0 deletions source/Nuke.Build.Shared/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace Nuke.Common;
/// <summary>
/// Set of constants shared between libraries and IDE extensions.
/// </summary>
[UsedImplicitly]
internal static class Constants
{
internal const string NukeFileName = NukeDirectoryName;
Expand Down
8 changes: 4 additions & 4 deletions source/Nuke.Build/Execution/ParameterService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,22 @@ public static string GetParameterMemberName<T>(Expression<Func<T>> expression)

public static string GetParameterMemberName(MemberInfo member)
{
var attribute = member.GetCustomAttribute<ParameterAttribute>();
var attribute = member.GetCustomAttribute<ParameterAttribute>().NotNull();
var prefix = member.DeclaringType.NotNull().GetCustomAttribute<ParameterPrefixAttribute>()?.Prefix;
return prefix + (attribute.Name ?? member.Name);
}

[CanBeNull]
public static string GetParameterDescription(MemberInfo member)
{
var attribute = member.GetCustomAttribute<ParameterAttribute>();
var attribute = member.GetCustomAttribute<ParameterAttribute>().NotNull();
return attribute.Description?.TrimEnd('.');
}

[CanBeNull]
public static IEnumerable<(string Text, object Object)> GetParameterValueSet(MemberInfo member, object instance)
{
var attribute = member.GetCustomAttribute<ParameterAttribute>();
var attribute = member.GetCustomAttribute<ParameterAttribute>().NotNull();
var memberType = member.GetMemberType().GetScalarType();

IEnumerable<(string Text, object Object)> TryGetFromValueProvider()
Expand Down Expand Up @@ -131,7 +131,7 @@ public static string GetParameterDescription(MemberInfo member)
[CanBeNull]
public static object GetFromMemberInfo(MemberInfo member, [CanBeNull] Type destinationType, Func<string, Type, char?, object> provider)
{
var attribute = member.GetCustomAttribute<ParameterAttribute>();
var attribute = member.GetCustomAttribute<ParameterAttribute>().NotNull();
var separator = (attribute.Separator ?? string.Empty).SingleOrDefault();
return provider.Invoke(GetParameterMemberName(member), destinationType ?? member.GetMemberType(), separator);
}
Expand Down
2 changes: 2 additions & 0 deletions source/Nuke.Build/Host.Activation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using JetBrains.Annotations;
using Nuke.Common.Execution;
using Nuke.Common.Utilities;

namespace Nuke.Common;

[UsedImplicitly(ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature)]
public partial class Host
{
internal static Host Instance { get; private set; }
Expand Down
1 change: 1 addition & 0 deletions source/Nuke.Build/INukeBuild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

namespace Nuke.Common;

[PublicAPI]
public interface INukeBuild
{
void ReportSummary(Configure<IDictionary<string, string>> configurator = null);
Expand Down
5 changes: 5 additions & 0 deletions source/Nuke.Build/Terminal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@

using System;
using System.Linq;
using JetBrains.Annotations;
using Nuke.Common.Utilities;

namespace Nuke.Common.Execution;

public class Terminal : Host
{
[UsedImplicitly]
public static bool IsRunningTerminal => true;
}

public class Rider : Terminal
{
[UsedImplicitly]
internal static bool IsRunningRider
=> !Environment.GetEnvironmentVariable("IDEA_INITIAL_DIRECTORY").IsNullOrEmpty() ||
(Environment.GetEnvironmentVariable("XPC_SERVICE_NAME")?.ContainsOrdinalIgnoreCase("com.jetbrains.rider") ?? false) ||
Expand All @@ -23,13 +26,15 @@ internal static bool IsRunningRider

public class VSCode : Terminal
{
[UsedImplicitly]
internal static bool IsRunningVSCode
=> !Environment.GetEnvironmentVariable("VSCODE_GIT_IPC_HANDLE").IsNullOrEmpty() ||
!Environment.GetEnvironmentVariable("VSCODE_PID").IsNullOrEmpty();
}

public class VisualStudio : Terminal
{
[UsedImplicitly]
internal static bool IsRunningVisualStudio
=> !Environment.GetEnvironmentVariable("VisualStudioVersion").IsNullOrEmpty();
}
1 change: 1 addition & 0 deletions source/Nuke.Common/CI/AppVeyor/AppVeyor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public partial class AppVeyor : Host, IBuildServer

public static int MessageLimit = 500;

[UsedImplicitly]
internal static bool IsRunningAppVeyor => EnvironmentInfo.HasVariable("APPVEYOR");

private readonly Lazy<Tool> _cli = Lazy.Create(() => IsRunningAppVeyor ? ToolResolver.GetEnvironmentOrPathTool("appveyor") : null);
Expand Down
1 change: 1 addition & 0 deletions source/Nuke.Common/CI/AzurePipelines/AzurePipelines.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public partial class AzurePipelines : Host, IBuildServer
{
public new static AzurePipelines Instance => Host.Instance as AzurePipelines;

[UsedImplicitly]
internal static bool IsRunningAzurePipelines => EnvironmentInfo.HasVariable("TF_BUILD");

private readonly Action<string> _messageSink;
Expand Down
1 change: 1 addition & 0 deletions source/Nuke.Common/CI/Bamboo/Bamboo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class Bamboo : Host, IBuildServer
{
public new static Bamboo Instance => Host.Instance as Bamboo;

[UsedImplicitly]
internal static bool IsRunningBamboo => EnvironmentInfo.HasVariable("bamboo_planKey");

internal Bamboo()
Expand Down
1 change: 1 addition & 0 deletions source/Nuke.Common/CI/Bitbucket/Bitbucket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class Bitbucket : Host, IBuildServer
{
public new static Bitbucket Instance => Host.Instance as Bitbucket;

[UsedImplicitly]
internal static bool IsRunningBitbucket => EnvironmentInfo.HasVariable("BITBUCKET_PIPELINE_UUID");

internal Bitbucket()
Expand Down
1 change: 1 addition & 0 deletions source/Nuke.Common/CI/Bitrise/Bitrise.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class Bitrise : Host, IBuildServer
{
public new static Bitrise Instance => Host.Instance as Bitrise;

[UsedImplicitly]
internal static bool IsRunningBitrise => EnvironmentInfo.HasVariable("BITRISE_BUILD_URL");

private static DateTime ConvertUnixTimestamp(long timestamp)
Expand Down
1 change: 1 addition & 0 deletions source/Nuke.Common/CI/GitHubActions/GitHubActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace Nuke.Common.CI.GitHubActions;
[ExcludeFromCodeCoverage]
public partial class GitHubActions : Host, IBuildServer
{
[UsedImplicitly]
internal static bool IsRunningGitHubActions => EnvironmentInfo.HasVariable("GITHUB_ACTIONS");

public new static GitHubActions Instance => Host.Instance as GitHubActions;
Expand Down
1 change: 1 addition & 0 deletions source/Nuke.Common/CI/GitLab/GitLab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public partial class GitLab : Host, IBuildServer
{
public new static GitLab Instance => Host.Instance as GitLab;

[UsedImplicitly]
internal static bool IsRunningGitLab => EnvironmentInfo.HasVariable("GITLAB_CI");

private const string SectionStartSequence = "\u001b[0K";
Expand Down
1 change: 1 addition & 0 deletions source/Nuke.Common/CI/Jenkins/Jenkins.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class Jenkins : Host, IBuildServer
{
public new static Jenkins Instance => Host.Instance as Jenkins;

[UsedImplicitly]
internal static bool IsRunningJenkins => EnvironmentInfo.HasVariable("JENKINS_HOME");

internal Jenkins()
Expand Down
1 change: 1 addition & 0 deletions source/Nuke.Common/CI/SpaceAutomation/SpaceAutomation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public partial class SpaceAutomation : Host, IBuildServer
{
public new static SpaceAutomation Instance => Host.Instance as SpaceAutomation;

[UsedImplicitly]
internal static bool IsRunningSpaceAutomation => EnvironmentInfo.HasVariable("JB_SPACE_PROJECT_KEY");

string IBuildServer.Branch => GitBranch;
Expand Down
1 change: 1 addition & 0 deletions source/Nuke.Common/CI/TeamCity/TeamCity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public partial class TeamCity : Host, IBuildServer
{
public new static TeamCity Instance => Host.Instance as TeamCity;

[UsedImplicitly]
internal static bool IsRunningTeamCity => EnvironmentInfo.HasVariable("TEAMCITY_VERSION");

[CanBeNull]
Expand Down
4 changes: 2 additions & 2 deletions source/Nuke.Common/CI/TeamCity/TeamCityAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ protected virtual TeamCityParameter GetParameter(MemberInfo member, bool require
{
var attribute = member.GetCustomAttribute<ParameterAttribute>();
var valueSet = ParameterService.GetParameterValueSet(member, Build);
var valueSeparator = attribute.Separator ?? " ";
var valueSeparator = attribute.NotNull().Separator ?? " ";

// TODO: Abstract AbsolutePath/Solution/Project etc.
var defaultValue = !member.HasCustomAttribute<SecretAttribute>() ? member.GetValue(Build) : default(string);
Expand All @@ -284,7 +284,7 @@ protected virtual TeamCityParameter GetParameter(MemberInfo member, bool require
(member.GetMemberType() == typeof(AbsolutePath) ||
member.GetMemberType() == typeof(Solution) ||
member.GetMemberType() == typeof(Project)))
defaultValue = (UnixRelativePath) GetRelativePath(Build.RootDirectory, defaultValue.ToString());
defaultValue = Build.RootDirectory.GetUnixRelativePathTo(defaultValue.ToString());

TeamCityParameterType GetParameterType()
{
Expand Down
1 change: 1 addition & 0 deletions source/Nuke.Common/CI/TravisCI/TravisCI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public partial class TravisCI : Host, IBuildServer
{
public new static TravisCI Instance => Host.Instance as TravisCI;

[UsedImplicitly]
internal static bool IsRunningTravisCI => EnvironmentInfo.HasVariable("TRAVIS");

internal TravisCI()
Expand Down
7 changes: 1 addition & 6 deletions source/Nuke.Common/ChangeLog/ChangeLogTasks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public static ChangeLog ReadChangelog(string changelogFile)
return new ChangeLog(changelogFile, unreleased.First(), releaseNotes);
}

Assert.True(releaseNotes.Count(x => !x.Unreleased) >= 1, "Changelog should have at lease one released version section");
Assert.True(releaseNotes.Any(x => !x.Unreleased), "Changelog should have at lease one released version section");
return new ChangeLog(changelogFile, releaseNotes);
}

Expand Down Expand Up @@ -178,11 +178,6 @@ internal static IEnumerable<ReleaseSection> GetReleaseSections(List<string> cont
static bool IsReleaseHead(string str)
=> str.StartsWith("## ");

static bool IsReleaseContent(string str) => str.StartsWith("###")
|| str.Trim().StartsWith("-")
|| str.Trim().StartsWith("*")
|| str.Trim().StartsWith("+");

static string GetCaption(string str)
=> str
.TrimStart('#', ' ', '[')
Expand Down
7 changes: 3 additions & 4 deletions source/Nuke.GlobalTool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,13 @@ private static int Handle(string[] args, [CanBeNull] AbsolutePath rootDirectory,
Assert.Fail($"No command specified. Usage is: nuke {CommandPrefix}<command> [args]");

var availableCommands = typeof(Program).GetMethods(ReflectionUtility.Static).Where(x => x.ReturnType == typeof(int)).ToList();
var commandHandler = availableCommands.SingleOrDefault(x => x.Name.EqualsOrdinalIgnoreCase(command));
Assert.NotNull(commandHandler,
new[] { $"Command '{command}' is not supported, available commands are:" }
var commandHandler = availableCommands.SingleOrDefault(x => x.Name.EqualsOrdinalIgnoreCase(command))
.NotNull(new[] { $"Command '{command}' is not supported, available commands are:" }
.Concat(availableCommands.Where(x => x.IsPublic).Select(x => $" - {x.Name}").OrderBy(x => x)).JoinNewLine());
// TODO: add assertions about return type and parameters

var commandArguments = new object[] { args.Skip(count: 1).ToArray(), rootDirectory, buildScript };
return (int)commandHandler.Invoke(obj: null, commandArguments);
return (int)commandHandler.Invoke(obj: null, commandArguments).NotNull($"Command '{command}' did not return exit code");
}

if (rootDirectory == null || buildScript == null)
Expand Down
4 changes: 2 additions & 2 deletions source/Nuke.MSBuildTasks/CodeGenerationTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ namespace Nuke.MSBuildTasks;
[UsedImplicitly]
public class CodeGenerationTask : ContextAwareTask
{
[Microsoft.Build.Framework.Required]
[Required]
public ITaskItem[] SpecificationFiles { get; set; }

[Microsoft.Build.Framework.Required]
[Required]
public string BaseDirectory { get; set; }

public bool UseNestedNamespaces { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion source/Nuke.SolutionModel/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ public override string ToString()
return Path;
}

internal override string RelativePath => PathConstruction.GetRelativePath(Solution.Directory, Path);
internal override string RelativePath => Solution.Directory.GetRelativePathTo(Path);
}
2 changes: 1 addition & 1 deletion source/Nuke.SolutionModel/Solution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ SolutionFolder GetParentFolder(PrimitiveProject solutionFolder) =>

IDictionary<string, string> GetItems(SolutionFolder solutionFolder)
=> solutionFolder.Items.Keys
.Select(x => (string) PathConstruction.GetWinRelativePath(Directory, solution.Directory / x))
.Select(x => (string) Directory.GetWinRelativePathTo(solution.Directory / x))
.ToDictionary(x => x, x => x);

solution.AllSolutionFolders.ForEach(x => AddSolutionFolder(x.Name, x.ProjectId, GetParentFolder(x) ?? folder));
Expand Down
6 changes: 6 additions & 0 deletions source/Nuke.SolutionModel/SolutionFolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,18 @@ public SolutionFolder(
public IReadOnlyCollection<SolutionFolder> SolutionFolders => Solution.AllSolutionFolders.Where(x => x.SolutionFolder == this).ToList();
public IReadOnlyCollection<Project> Projects => Solution.AllProjects.Where(x => x.SolutionFolder == this).ToList();

/// <summary>
/// Gets a solution folder by its name.
/// </summary>
[CanBeNull]
public SolutionFolder GetSolutionFolder(string name)
{
return SolutionFolders.SingleOrDefault(x => name.Equals(x.Name, StringComparison.Ordinal));
}

/// <summary>
/// Gets a project by its name.
/// </summary>
[CanBeNull]
public Project GetProject(string name)
{
Expand Down
2 changes: 2 additions & 0 deletions source/Nuke.Tooling/Arguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Nuke.Common.Tooling;

[PublicAPI]
public interface IArguments
{
string FilterSecrets(string text);
Expand All @@ -19,6 +20,7 @@ public interface IArguments
}

// TODO: extract {value} and {key} into constants
[PublicAPI]
public sealed class Arguments : IArguments
{
internal const string Redacted = "[REDACTED]";
Expand Down
2 changes: 2 additions & 0 deletions source/Nuke.Tooling/ToolingExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

using System;
using System.Linq;
using JetBrains.Annotations;
using Nuke.Common.IO;
using Nuke.Common.Utilities.Collections;

namespace Nuke.Common.Tooling;

[PublicAPI]
public static class ToolingExtensions
{
public static AbsolutePath SetExecutable(this AbsolutePath path, bool updateVcsIndex = false)
Expand Down
2 changes: 1 addition & 1 deletion source/Nuke.Utilities/EnvironmentInfo.Platform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public static bool IsWsl
/// Indicates the target framework of the current process.
/// </summary>
public static FrameworkName Framework
=> new(Assembly.GetEntryAssembly().NotNull().GetCustomAttribute<TargetFrameworkAttribute>().FrameworkName);
=> new(Assembly.GetEntryAssembly().NotNull().GetCustomAttribute<TargetFrameworkAttribute>().NotNull().FrameworkName);

/// <summary>
/// Indicates the operating-system platform.
Expand Down
2 changes: 1 addition & 1 deletion source/Nuke.Utilities/Reflection/Assembly.Versioning.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ public static string GetVersionText(this Assembly assembly)

private static string GetAssemblyInformationalVersion(this Assembly assembly)
{
return assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;
return assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>().NotNull().InformationalVersion;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static TResult GetValueNonVirtual<TResult>(this MemberInfo member, object
{
Assert.True(member is PropertyInfo or MethodInfo);
var method = member is PropertyInfo property
? property.GetMethod
? property.GetMethod.NotNull()
: (MethodInfo) member;

var funcType = Expression.GetFuncType(method.GetParameters().Select(x => x.ParameterType)
Expand Down Expand Up @@ -87,7 +87,7 @@ public static void SetValue(this MemberInfo member, object instance, object valu
else
{
Assert.True(property.SetMethod != null, $"Property '{member.Name}' is not settable");
property.SetValue(property.GetMethod.IsStatic ? null : instance, value);
property.SetValue(property.IsStatic() ? null : instance, value);
}
}
}
Expand Down
Loading

0 comments on commit 7f44bf5

Please sign in to comment.