Skip to content

Commit

Permalink
SLVS-1403 Add DeleteBinding method to ISolutionBindingRepository (#5873)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriela-trutan-sonarsource authored and vnaskos-sonar committed Dec 18, 2024
1 parent e0315c3 commit f1360a1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
35 changes: 17 additions & 18 deletions src/ConnectedMode/Persistence/SolutionBindingRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
using SonarLint.VisualStudio.ConnectedMode.Binding;
using SonarLint.VisualStudio.Core;
using SonarLint.VisualStudio.Core.Binding;
using SonarLint.VisualStudio.SLCore.Service.Project.Models;

namespace SonarLint.VisualStudio.ConnectedMode.Persistence;

Expand All @@ -31,15 +30,16 @@ namespace SonarLint.VisualStudio.ConnectedMode.Persistence;
[PartCreationPolicy(CreationPolicy.Shared)]
internal class SolutionBindingRepository : ISolutionBindingRepository, ILegacySolutionBindingRepository
{
private readonly ISolutionBindingFileLoader solutionBindingFileLoader;
private readonly ISolutionBindingCredentialsLoader credentialsLoader;
private readonly IUnintrusiveBindingPathProvider unintrusiveBindingPathProvider;
private readonly IServerConnectionsRepository serverConnectionsRepository;
private readonly IBindingJsonModelConverter bindingJsonModelConverter;
private readonly ISolutionBindingCredentialsLoader credentialsLoader;
private readonly ILogger logger;
private readonly IServerConnectionsRepository serverConnectionsRepository;
private readonly ISolutionBindingFileLoader solutionBindingFileLoader;
private readonly IUnintrusiveBindingPathProvider unintrusiveBindingPathProvider;

[ImportingConstructor]
public SolutionBindingRepository(IUnintrusiveBindingPathProvider unintrusiveBindingPathProvider,
public SolutionBindingRepository(
IUnintrusiveBindingPathProvider unintrusiveBindingPathProvider,
IBindingJsonModelConverter bindingJsonModelConverter,
IServerConnectionsRepository serverConnectionsRepository,
ICredentialStoreService credentialStoreService,
Expand All @@ -53,7 +53,8 @@ public SolutionBindingRepository(IUnintrusiveBindingPathProvider unintrusiveBind
{
}

internal /* for testing */ SolutionBindingRepository(IUnintrusiveBindingPathProvider unintrusiveBindingPathProvider,
internal /* for testing */ SolutionBindingRepository(
IUnintrusiveBindingPathProvider unintrusiveBindingPathProvider,
IBindingJsonModelConverter bindingJsonModelConverter,
IServerConnectionsRepository serverConnectionsRepository,
ISolutionBindingFileLoader solutionBindingFileLoader,
Expand All @@ -78,10 +79,7 @@ BoundSonarQubeProject ILegacySolutionBindingRepository.Read(string configFilePat
};
}

public BoundServerProject Read(string configFilePath)
{
return Convert(ReadBindingFile(configFilePath), configFilePath);
}
public BoundServerProject Read(string configFilePath) => Convert(ReadBindingFile(configFilePath), configFilePath);

public bool Write(string configFilePath, BoundServerProject binding)
{
Expand All @@ -98,10 +96,12 @@ public bool Write(string configFilePath, BoundServerProject binding)
}

BindingUpdated?.Invoke(this, EventArgs.Empty);

return true;
}

public bool DeleteBinding(string configFilePath) => throw new NotImplementedException();

public event EventHandler BindingUpdated;

public IEnumerable<BoundServerProject> List()
Expand All @@ -110,7 +110,7 @@ public IEnumerable<BoundServerProject> List()
{
throw new InvalidOperationException("Could not retrieve all connections.");
}

var bindingConfigPaths = unintrusiveBindingPathProvider.GetBindingPaths();

foreach (var bindingConfigPath in bindingConfigPaths)
Expand All @@ -123,7 +123,7 @@ public IEnumerable<BoundServerProject> List()
continue;
}

if (connections.FirstOrDefault(c => c.Id == bindingJsonModel.ServerConnectionId) is not {} serverConnection)
if (connections.FirstOrDefault(c => c.Id == bindingJsonModel.ServerConnectionId) is not { } serverConnection)
{
logger.LogVerbose($"Skipped {bindingConfigPath} because connection {bindingJsonModel.ServerConnectionId} doesn't exist");
continue;
Expand All @@ -134,7 +134,7 @@ public IEnumerable<BoundServerProject> List()
yield return boundServerProject;
}
}

private BindingJsonModel ReadBindingFile(string configFilePath)
{
var bound = solutionBindingFileLoader.Load(configFilePath);
Expand All @@ -144,18 +144,17 @@ private BindingJsonModel ReadBindingFile(string configFilePath)
return null;
}

Debug.Assert(!bound.Profiles?.ContainsKey(Core.Language.Unknown) ?? true,
Debug.Assert(!bound.Profiles?.ContainsKey(Language.Unknown) ?? true,
"Not expecting the deserialized binding config to contain the profile for an unknown language");

return bound;

}

private BoundServerProject Convert(BindingJsonModel bindingJsonModel, string configFilePath) =>
bindingJsonModel is not null && serverConnectionsRepository.TryGet(bindingJsonModel.ServerConnectionId, out var connection)
? Convert(bindingJsonModel, connection, configFilePath)
: null;

private BoundServerProject Convert(BindingJsonModel bindingJsonModel, ServerConnection connection, string configFilePath) =>
private BoundServerProject Convert(BindingJsonModel bindingJsonModel, ServerConnection connection, string configFilePath) =>
bindingJsonModelConverter.ConvertFromModel(bindingJsonModel, connection, unintrusiveBindingPathProvider.GetBindingKeyFromPath(configFilePath));
}
8 changes: 7 additions & 1 deletion src/Core/Binding/ISolutionBindingRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@ public interface ISolutionBindingRepository
bool Write(string configFilePath, BoundServerProject binding);

/// <summary>
/// Raises when <see cref="Write"/> operation completes successfully
/// Deletes the binding information
/// </summary>
/// <returns>If binding has been deleted</returns>
bool DeleteBinding(string configFilePath);

/// <summary>
/// Raises when <see cref="Write" /> operation completes successfully
/// </summary>
event EventHandler BindingUpdated;

Expand Down

0 comments on commit f1360a1

Please sign in to comment.