Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use version of the assembly with the same name as the package ID (for telemetry data) #16544

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/Umbraco.Infrastructure/Services/Implement/PackagingService.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
using System.Diagnostics.CodeAnalysis;

Check notice on line 1 in src/Umbraco.Infrastructure/Services/Implement/PackagingService.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (v14/dev)

ℹ Getting worse: Primitive Obsession

The ratio of primitive types in function arguments increases from 35.71% to 38.64%, threshold = 30.0%. The functions in this file have too many primitive types (e.g. int, double, float) in their function argument lists. Using many primitive types lead to the code smell Primitive Obsession. Avoid adding more primitive arguments.
using System.Reflection;
using System.Runtime.Loader;
using System.Xml.Linq;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;
Expand Down Expand Up @@ -354,8 +357,16 @@

if (!string.IsNullOrEmpty(packageManifest.Version))
{
// Always use package version from manifest
installedPackage.Version = packageManifest.Version;
}
else if (string.IsNullOrEmpty(installedPackage.Version) &&
string.IsNullOrEmpty(installedPackage.PackageId) is false &&

Check warning on line 364 in src/Umbraco.Infrastructure/Services/Implement/PackagingService.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (v14/dev)

❌ New issue: Complex Conditional

GetAllInstalledPackagesAsync has 1 complex conditionals with 2 branches, threshold = 2. A complex conditional is an expression inside a branch (e.g. if, for, while) which consists of multiple, logical operators such as AND/OR. The more logical operators in an expression, the more severe the code smell.
TryGetAssemblyInformationalVersion(installedPackage.PackageId, out string? version))
{
// Use version of the assembly with the same name as the package ID
installedPackage.Version = version;
}

Check notice on line 369 in src/Umbraco.Infrastructure/Services/Implement/PackagingService.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (v14/dev)

ℹ Getting worse: Complex Method

GetAllInstalledPackagesAsync increases in cyclomatic complexity from 19 to 22, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.

Check warning on line 369 in src/Umbraco.Infrastructure/Services/Implement/PackagingService.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (v14/dev)

❌ Getting worse: Bumpy Road Ahead

GetAllInstalledPackagesAsync increases from 4 to 5 logical blocks with deeply nested code, threshold is one single block per function. The Bumpy Road code smell is a function that contains multiple chunks of nested conditional logic. The deeper the nesting and the more bumps, the lower the code health.
}

// Return all packages with an ID or name in the package manifest or package migrations
Expand Down Expand Up @@ -414,4 +425,20 @@

return packageFile.CreateReadStream();
}

private static bool TryGetAssemblyInformationalVersion(string name, [NotNullWhen(true)] out string? version)
{
foreach (Assembly assembly in AssemblyLoadContext.Default.Assemblies)
{
AssemblyName assemblyName = assembly.GetName();
if (string.Equals(assemblyName.Name, name, StringComparison.OrdinalIgnoreCase) &&
assembly.TryGetInformationalVersion(out version))
{
return true;
}
}

version = null;
return false;
}
}
Loading