Skip to content

Commit

Permalink
Fixed code analysis issues
Browse files Browse the repository at this point in the history
  • Loading branch information
credfeto committed Dec 10, 2023
1 parent f78ee38 commit 489ab94
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 69 deletions.
16 changes: 8 additions & 8 deletions src/FunFair.BuildVersion.Detection/VersionDetector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ public NuGetVersion FindVersion(int buildNumber)

private NuGetVersion DetermineLatestReleaseFromPreviousReleaseBranches(int buildNumber)
{
IReadOnlyList<string> branches = this._branchDiscovery.FindBranches();

NuGetVersion? latestVersion = branches.Select(GetReleaseVersion)
.RemoveNulls()
.Max();

return AddBuildNumberToVersion(latestVersion ?? InitialVersion, buildNumber: buildNumber);

NuGetVersion? GetReleaseVersion(string branch)
{
this._logger.LogDebug($" * => {branch}");
Expand All @@ -50,14 +58,6 @@ private NuGetVersion DetermineLatestReleaseFromPreviousReleaseBranches(int build
? version
: null;
}

IReadOnlyList<string> branches = this._branchDiscovery.FindBranches();

NuGetVersion? latestVersion = branches.Select(GetReleaseVersion)
.RemoveNulls()
.Max();

return AddBuildNumberToVersion(latestVersion ?? InitialVersion, buildNumber: buildNumber);
}

private static NuGetVersion AddBuildNumberToVersion(NuGetVersion version, int buildNumber)
Expand Down
62 changes: 2 additions & 60 deletions src/FunFair.BuildVersion/ExecutableVersionInformation.cs
Original file line number Diff line number Diff line change
@@ -1,64 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;

namespace FunFair.BuildVersion;
namespace FunFair.BuildVersion;

internal static class ExecutableVersionInformation
{
public static string ProgramVersion()
{
return CommonVersion(typeof(Program));
}

private static string CommonVersion(Type type)
{
Assembly assembly = type.Assembly;

return GetAssemblyFileVersionFile() ?? GetAssemblyFileVersion(assembly) ?? GetAssemblyVersion(assembly);
}

private static string? GetAssemblyFileVersionFile()
{
IReadOnlyList<string> args = Environment.GetCommandLineArgs();

if (args.Count == 0)
{
return null;
}

string location = args[0];

if (string.IsNullOrWhiteSpace(location) || !File.Exists(location))
{
return null;
}

FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(location);

return fileVersionInfo.ProductVersion!;
}

private static string? GetAssemblyFileVersion(Assembly assembly)
{
AssemblyFileVersionAttribute? fvi = assembly.GetCustomAttributes<AssemblyFileVersionAttribute>()
.FirstOrDefault();

return fvi?.Version;
}

private static string GetAssemblyVersion(Assembly assembly)
{
Console.Write("Finding Assembly Version");
Version? assemblyVersion = assembly.GetName()
.Version;

return assemblyVersion is null
? throw new VersionNotFoundException()
: assemblyVersion.ToString();
}
public const string ProgramVersion = ThisAssembly.Info.FileVersion;
}
1 change: 1 addition & 0 deletions src/FunFair.BuildVersion/FunFair.BuildVersion.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
<PackageReference Include="SmartAnalyzers.CSharpExtensions.Annotations" Version="4.2.8" PrivateAssets="All" ExcludeAssets="runtime" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.15.0.81779" PrivateAssets="All" ExcludeAssets="runtime" />
<PackageReference Include="SourceLink.Create.CommandLine" Version="2.8.3" PrivateAssets="All" ExcludeAssets="runtime" />
<PackageReference Include="ThisAssembly.AssemblyInfo" Version="1.4.1" PrivateAssets="All" ExcludeAssets="runtime"/>
<PackageReference Include="ToStringWithoutOverrideAnalyzer" Version="0.6.0" PrivateAssets="All" ExcludeAssets="runtime" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion src/FunFair.BuildVersion/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static int Main(params string[] args)
{
try
{
Console.WriteLine($"{typeof(Program).Namespace} {ExecutableVersionInformation.ProgramVersion()}");
Console.WriteLine($"{typeof(Program).Namespace} {ExecutableVersionInformation.ProgramVersion}");

return Parser.Default.ParseArguments<Options>(args)
.MapResult(parsedFunc: ParsedOk, notParsedFunc: NotParsed);
Expand Down

0 comments on commit 489ab94

Please sign in to comment.