Skip to content

Commit 45474d3

Browse files
Change Provider APIs to use name and version instead of libraryId
- Separates the data objects from Manifest and LibraryInstallationState - Remove libraryId from from ILibraryInstallationState - Adapt all clients and use cases to use name and version instead of libraryId - Fix all tests to use name and version instead of libraryId
1 parent f5bc313 commit 45474d3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+576
-391
lines changed

src/LibraryManager.Contracts/ILibraryCatalog.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ public interface ILibraryCatalog
2020
Task<CompletionSet> GetLibraryCompletionSetAsync(string value, int caretPosition);
2121

2222
/// <summary>
23-
/// Gets the library group from the specified <paramref name="libraryId"/>.
23+
/// Gets the library group from the specified <paramref name="libraryName"/>.
2424
/// </summary>
25-
/// <param name="libraryId">The unique library identifier.</param>
25+
/// <param name="libraryName">The name of the library.</param>
26+
/// <param name="version">The version of the library</param>
2627
/// <param name="cancellationToken">A token that allows the search to be cancelled.</param>
2728
/// <returns>An instance of <see cref="ILibraryGroup"/> or <code>null</code>.</returns>
28-
Task<ILibrary> GetLibraryAsync(string libraryId, CancellationToken cancellationToken);
29+
Task<ILibrary> GetLibraryAsync(string libraryName, string version, CancellationToken cancellationToken);
2930

3031
/// <summary>
3132
/// Searches the catalog for the specified search term.
@@ -38,10 +39,10 @@ public interface ILibraryCatalog
3839
/// <summary>
3940
/// Gets the latest version of the library.
4041
/// </summary>
41-
/// <param name="libraryId">The library identifier.</param>
42+
/// <param name="libraryName">The library identifier.</param>
4243
/// <param name="includePreReleases">if set to <c>true</c> includes pre-releases.</param>
4344
/// <param name="cancellationToken">A token that allows the search to be cancelled.</param>
4445
/// <returns>The library identifier of the latest released version.</returns>
45-
Task<string> GetLatestVersion(string libraryId, bool includePreReleases, CancellationToken cancellationToken);
46+
Task<string> GetLatestVersion(string libraryName, bool includePreReleases, CancellationToken cancellationToken);
4647
}
4748
}

src/LibraryManager.Contracts/ILibraryGroup.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ public interface ILibraryGroup
2323
string Description { get; }
2424

2525
/// <summary>
26-
/// Gets a list of IDs for the different versions of the library.
26+
/// Gets a list of versions of the library.
2727
/// </summary>
2828
/// <param name="cancellationToken">A token that allows cancellation of the operation.</param>
2929
/// <returns>A list of library IDs used to display library information to the user.</returns>
30-
Task<IEnumerable<string>> GetLibraryIdsAsync(CancellationToken cancellationToken);
30+
Task<IEnumerable<string>> GetLibraryVersions(CancellationToken cancellationToken);
3131
}
32-
}
32+
}

src/LibraryManager.Contracts/ILibraryInstallationState.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ namespace Microsoft.Web.LibraryManager.Contracts
1010
/// </summary>
1111
public interface ILibraryInstallationState
1212
{
13-
/// <summary>
14-
/// The identifyer to uniquely identify the library
15-
/// </summary>
16-
string LibraryId { get; }
17-
1813
/// <summary>
1914
/// The name of the library.
2015
/// </summary>
@@ -39,5 +34,15 @@ public interface ILibraryInstallationState
3934
/// The path relative to the working directory to copy the files to.
4035
/// </summary>
4136
string DestinationPath { get; }
37+
38+
/// <summary>
39+
/// Indicates whether the library is using the default destination
40+
/// </summary>
41+
bool IsUsingDefaultDestination { get; }
42+
43+
/// <summary>
44+
/// Indicates whether the library is using the default provider
45+
/// </summary>
46+
bool IsUsingDefaultProvider { get; }
4247
}
4348
}

src/LibraryManager.Contracts/PredefinedErrors.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,19 @@ public static IError ProviderUnknown(string providerId)
4444
public static IError UnableToResolveSource(string libraryId, string providerId)
4545
=> new Error("LIB002", string.Format(Text.ErrorUnableToResolveSource, libraryId, providerId));
4646

47+
/// <summary>
48+
/// The <see cref="IProvider"/> is unable to resolve the source.
49+
/// </summary>
50+
/// <param name="libraryName">Name of the library</param>
51+
/// <param name="version">Version of the library</param>
52+
/// <param name="providerId">The ID of the <see cref="IProvider"/> that could not resolve the resource.</param>
53+
/// <returns>The error code LIB002</returns>
54+
public static IError UnableToResolveSource(string libraryName, string version, string providerId)
55+
{
56+
string libraryId = string.IsNullOrEmpty(version) ? libraryName : $"{libraryName}@{version}";
57+
return UnableToResolveSource(libraryId, providerId);
58+
}
59+
4760
/// <summary>
4861
/// The <see cref="IProvider"/> failed to write a file in the <see cref="ILibraryInstallationState.Files"/> array.
4962
/// </summary>

src/LibraryManager.Vsix/ErrorList/ErrorList.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.IO;
66
using System.Linq;
77
using Microsoft.Web.LibraryManager.Contracts;
8+
using Microsoft.Web.LibraryManager.LibraryNaming;
89

910
namespace Microsoft.Web.LibraryManager.Vsix
1011
{
@@ -42,7 +43,9 @@ public bool HandleErrors(IEnumerable<ILibraryOperationResult> results)
4243

4344
private static void AddLineAndColumn(IEnumerable<string> lines, ILibraryInstallationState state, DisplayError[] errors)
4445
{
45-
if (string.IsNullOrEmpty(state?.LibraryId))
46+
string libraryId = LibraryIdToNameAndVersionConverter.Instance.GetLibraryId(state?.Name, state?.Version, state?.ProviderId);
47+
48+
if(string.IsNullOrEmpty(libraryId))
4649
{
4750
return;
4851
}
@@ -58,7 +61,7 @@ private static void AddLineAndColumn(IEnumerable<string> lines, ILibraryInstalla
5861
if (line.Trim() == "{")
5962
index = i;
6063

61-
if (line.Contains(state.LibraryId))
64+
if (line.Contains(libraryId))
6265
{
6366
error.Line = index > 0 ? index : i;
6467
break;

src/LibraryManager.Vsix/Json/Completion/FilesCompletionProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ protected override IEnumerable<JSONCompletionEntry> GetEntries(JSONCompletionCon
3939
if (!JsonHelpers.TryGetInstallationState(parent, out ILibraryInstallationState state))
4040
yield break;
4141

42-
if (string.IsNullOrEmpty(state.LibraryId))
42+
if (string.IsNullOrEmpty(state.Name))
4343
yield break;
4444

4545
var dependencies = Dependencies.FromConfigFile(ConfigFilePath);
@@ -49,7 +49,7 @@ protected override IEnumerable<JSONCompletionEntry> GetEntries(JSONCompletionCon
4949
if (catalog == null)
5050
yield break;
5151

52-
Task<ILibrary> task = catalog.GetLibraryAsync(state.LibraryId, CancellationToken.None);
52+
Task<ILibrary> task = catalog.GetLibraryAsync(state.Name, state.Version, CancellationToken.None);
5353
FrameworkElement presenter = GetPresenter(context);
5454
IEnumerable<string> usedFiles = GetUsedFiles(context);
5555

src/LibraryManager.Vsix/Json/JsonHelpers.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Microsoft.JSON.Core.Parser;
77
using Microsoft.JSON.Core.Parser.TreeItems;
88
using Microsoft.Web.LibraryManager.Contracts;
9+
using Microsoft.Web.LibraryManager.Json;
910

1011
namespace Microsoft.Web.LibraryManager.Vsix
1112
{
@@ -64,7 +65,7 @@ internal static int FindInsertIndex(JSONParseItemList jsonParseItems, int rangeS
6465
return max + 1;
6566
}
6667

67-
public static bool TryGetInstallationState(JSONObject parent, out ILibraryInstallationState installationState)
68+
public static bool TryGetInstallationState(JSONObject parent, out ILibraryInstallationState installationState, string defaultProvider = null)
6869
{
6970
installationState = null;
7071

@@ -73,7 +74,7 @@ public static bool TryGetInstallationState(JSONObject parent, out ILibraryInstal
7374
return false;
7475
}
7576

76-
var state = new LibraryInstallationState();
77+
var state = new LibraryInstallationStateOnDisk();
7778

7879
foreach (JSONMember child in parent.Children.OfType<JSONMember>())
7980
{
@@ -124,7 +125,8 @@ public static bool TryGetInstallationState(JSONObject parent, out ILibraryInstal
124125
}
125126
}
126127

127-
installationState = state;
128+
var converter = new LibraryStateToFileConverter(defaultProvider, defaultDestination: null);
129+
installationState = converter.ConvertToLibraryInstallationState(state);
128130

129131
return !string.IsNullOrEmpty(installationState.ProviderId);
130132
}

src/LibraryManager.Vsix/Json/SuggestedActions/SuggestedActionProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public bool HasSuggestedActions(ITextView textView, ITextBuffer textBuffer, int
6363
ConfigFilePath = doc.FilePath;
6464
LibraryObject = parent;
6565

66-
return !string.IsNullOrEmpty(InstallationState.LibraryId);
66+
return !string.IsNullOrEmpty(InstallationState.Name);
6767
}
6868
}
6969
}

src/LibraryManager.Vsix/Json/SuggestedActions/UninstallSuggestedActions.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
using System.Threading;
1010
using Microsoft.VisualStudio.Shell;
1111
using Microsoft.JSON.Core.Parser;
12+
using Microsoft.Web.LibraryManager.Contracts;
13+
using Microsoft.Web.LibraryManager.LibraryNaming;
1214

1315
namespace Microsoft.Web.LibraryManager.Vsix
1416
{
@@ -29,7 +31,8 @@ public UninstallSuggestedAction(SuggestedActionProvider provider, ILibraryComman
2931

3032
private static string GetDisplayText(SuggestedActionProvider provider)
3133
{
32-
string cleanId = provider.InstallationState.LibraryId;
34+
ILibraryInstallationState state = provider.InstallationState;
35+
string cleanId = LibraryIdToNameAndVersionConverter.Instance.GetLibraryId(state.Name, state.Version, state.ProviderId);
3336

3437
if (cleanId.Length > _maxlength + 10)
3538
{
@@ -44,7 +47,9 @@ public override async void Invoke(CancellationToken cancellationToken)
4447
try
4548
{
4649
Telemetry.TrackUserTask("Invoke-UninstallFromSuggestedAction");
47-
await _libraryCommandService.UninstallAsync(_provider.ConfigFilePath, _provider.InstallationState.LibraryId, cancellationToken).ConfigureAwait(false);
50+
var state = _provider.InstallationState;
51+
await _libraryCommandService.UninstallAsync(_provider.ConfigFilePath, state.Name, state.Version, state.ProviderId, cancellationToken)
52+
.ConfigureAwait(false);
4853

4954
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
5055
using (ITextEdit edit = TextBuffer.CreateEdit())

src/LibraryManager.Vsix/Json/SuggestedActions/UpdateSuggestedActionSet.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,23 +76,23 @@ private async Task<IEnumerable<SuggestedActionSet>> GetActionSetAsync()
7676
private async Task<List<ISuggestedAction>> GetListOfActionsAsync(ILibraryCatalog catalog, CancellationToken cancellationToken)
7777
{
7878
var list = new List<ISuggestedAction>();
79-
string latestStableVersion = await catalog.GetLatestVersion(_provider.InstallationState.LibraryId, false, cancellationToken).ConfigureAwait(false);
79+
string latestStableVersion = await catalog.GetLatestVersion(_provider.InstallationState.Name, false, cancellationToken).ConfigureAwait(false);
8080
string latestStable = LibraryIdToNameAndVersionConverter.Instance.GetLibraryId(
8181
_provider.InstallationState.Name,
8282
latestStableVersion,
8383
_provider.InstallationState.ProviderId);
8484

85-
if (!string.IsNullOrEmpty(latestStableVersion) && latestStable != _provider.InstallationState.LibraryId)
85+
if (!string.IsNullOrEmpty(latestStableVersion) && latestStableVersion != _provider.InstallationState.Version)
8686
{
8787
list.Add(new UpdateSuggestedAction(_provider, latestStable, $"Stable: {latestStable}"));
8888
}
8989

90-
string latestPreVersion = await catalog.GetLatestVersion(_provider.InstallationState.LibraryId, true, cancellationToken).ConfigureAwait(false);
90+
string latestPreVersion = await catalog.GetLatestVersion(_provider.InstallationState.Name, true, cancellationToken).ConfigureAwait(false);
9191
string latestPre = LibraryIdToNameAndVersionConverter.Instance.GetLibraryId(_provider.InstallationState.Name,
9292
latestPreVersion,
9393
_provider.InstallationState.ProviderId);
9494

95-
if (!string.IsNullOrEmpty(latestPreVersion) && latestPre != _provider.InstallationState.LibraryId && latestPre != latestStable)
95+
if (!string.IsNullOrEmpty(latestPreVersion) && latestPreVersion != _provider.InstallationState.Version && latestPre != latestStable)
9696
{
9797
list.Add(new UpdateSuggestedAction(_provider, latestPre, $"Pre-release: {latestPre}"));
9898
}

0 commit comments

Comments
 (0)