-
-
Notifications
You must be signed in to change notification settings - Fork 55
feat: Re-resolve extension dependencies on Beutl version change #1611
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8039ddd
feat: re-resolve extension dependencies when Beutl version changes
yuto-trd a49f7d2
fix: handle package loading failures due to dependency re-resolution
yuto-trd c77773a
fix: change logging level from Trace to Debug for Minimal log level
yuto-trd 1a6175b
fix: remove invisible character from LoggerAdapter.cs
yuto-trd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| using Microsoft.Extensions.Logging; | ||
| using NuGet.Common; | ||
| using LogLevel = NuGet.Common.LogLevel; | ||
|
|
||
| namespace Beutl.Api.Services; | ||
|
|
||
| public class LoggerAdapter(Microsoft.Extensions.Logging.ILogger logger) : LoggerBase | ||
| { | ||
| private readonly Microsoft.Extensions.Logging.ILogger _logger = logger; | ||
|
|
||
| public override void Log(ILogMessage message) | ||
| { | ||
| switch (message.Level) | ||
| { | ||
| case LogLevel.Debug: | ||
| _logger.LogDebug(message.ToString()); | ||
| break; | ||
| case LogLevel.Information: | ||
| _logger.LogInformation(message.ToString()); | ||
| break; | ||
| case LogLevel.Warning: | ||
| _logger.LogWarning(message.ToString()); | ||
| break; | ||
| case LogLevel.Error: | ||
| _logger.LogError(message.ToString()); | ||
| break; | ||
| case LogLevel.Verbose: | ||
| _logger.LogTrace(message.ToString()); | ||
| break; | ||
| case LogLevel.Minimal: | ||
| _logger.LogTrace(message.ToString()); | ||
| break; | ||
| default: | ||
| _logger.LogInformation(message.ToString()); | ||
yuto-trd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| break; | ||
| } | ||
| } | ||
|
|
||
| public override Task LogAsync(ILogMessage message) | ||
| { | ||
| Log(message); | ||
| return Task.CompletedTask; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/Beutl/Services/StartupTasks/ResolvePackageDependenciesTask.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| using System.Collections.Concurrent; | ||
|
|
||
| using Beutl.Api.Services; | ||
| using Beutl.Logging; | ||
|
|
||
| using Microsoft.Extensions.Logging; | ||
|
|
||
| using NuGet.Common; | ||
| using NuGet.Packaging.Core; | ||
|
|
||
| namespace Beutl.Services.StartupTasks; | ||
|
|
||
| public sealed class ResolvePackageDependenciesTask : StartupTask | ||
| { | ||
| private readonly ILogger<ResolvePackageDependenciesTask> _logger = | ||
| Log.CreateLogger<ResolvePackageDependenciesTask>(); | ||
|
|
||
| public ResolvePackageDependenciesTask( | ||
| InstalledPackageRepository repository, | ||
| PackageInstaller installer) | ||
| { | ||
| Task = Task.Run(async () => | ||
| { | ||
| using (Activity? activity = Telemetry.StartActivity("ResolvePackageDependenciesTask")) | ||
| { | ||
| PackageIdentity[] packages = repository.GetPackagesNeedingDependencyReResolution(); | ||
|
|
||
| if (packages.Length == 0) | ||
| { | ||
| _logger.LogInformation( | ||
| "All installed packages were resolved under the current Beutl version. No re-resolution needed."); | ||
| return; | ||
| } | ||
|
|
||
| _logger.LogInformation( | ||
| "Beutl version changed. Re-resolving dependencies for {Count} package(s).", | ||
| packages.Length); | ||
|
|
||
| foreach (PackageIdentity package in packages) | ||
| { | ||
| try | ||
| { | ||
| activity?.AddEvent(new ActivityEvent( | ||
| $"Re-resolving {package.Id} {package.Version}")); | ||
|
|
||
| await installer.ReResolveDependencies( | ||
| package, null, CancellationToken.None); | ||
|
|
||
| repository.SetResolvedBeutlVersion( | ||
| package.Id, BeutlApplication.Version); | ||
|
|
||
yuto-trd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| _logger.LogInformation( | ||
| "Successfully re-resolved dependencies for {PackageId} {PackageVersion}.", | ||
| package.Id, package.Version); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| activity?.SetStatus(ActivityStatusCode.Error); | ||
| _logger.LogError(ex, | ||
| "Failed to re-resolve dependencies for {PackageId} {PackageVersion}.", | ||
| package.Id, package.Version); | ||
| Failures.Add((package, ex)); | ||
| } | ||
| } | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| public override Task Task { get; } | ||
|
|
||
| public ConcurrentBag<(PackageIdentity Package, Exception Error)> Failures { get; } = []; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.