Skip to content

Commit 26dd67c

Browse files
Merge pull request #794 from jimmylewis/state
Broadly adopt LibraryInstallationGoalState
2 parents f7b231a + 5e58a14 commit 26dd67c

Some content is hidden

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

45 files changed

+667
-933
lines changed

src/LibraryManager.Build/RestoreTask.cs

+7-12
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public override bool Execute()
6969
return false;
7070
}
7171

72-
IEnumerable<ILibraryOperationResult> validationResults = manifest.GetValidationResultsAsync(token).Result;
72+
IEnumerable<OperationResult<LibraryInstallationGoalState>> validationResults = manifest.GetValidationResultsAsync(token).Result;
7373
if (!validationResults.All(r => r.Success))
7474
{
7575
sw.Stop();
@@ -78,7 +78,7 @@ public override bool Execute()
7878
return false;
7979
}
8080

81-
IEnumerable<ILibraryOperationResult> results = manifest.RestoreAsync(token).Result;
81+
IList<OperationResult<LibraryInstallationGoalState>> results = manifest.RestoreAsync(token).Result;
8282

8383
sw.Stop();
8484
FlushLogger(logger);
@@ -103,7 +103,7 @@ private void FlushLogger(Logger logger)
103103
}
104104
}
105105

106-
private void LogResults(Stopwatch sw, IEnumerable<ILibraryOperationResult> results)
106+
private void LogResults(Stopwatch sw, IEnumerable<OperationResult<LibraryInstallationGoalState>> results)
107107
{
108108
bool hasErrors = results.Any(r => !r.Success);
109109

@@ -136,19 +136,14 @@ private void LogErrors(IEnumerable<IError> errors)
136136
Log.LogMessage(MessageImportance.High, Environment.NewLine + text + Environment.NewLine);
137137
}
138138

139-
private void PopulateFilesWritten(IEnumerable<ILibraryOperationResult> results, Dependencies dependencies)
139+
private void PopulateFilesWritten(IEnumerable<OperationResult<LibraryInstallationGoalState>> results, Dependencies dependencies)
140140
{
141-
IEnumerable<ILibraryInstallationState> states = results.Where(r => r.Success).Select(r => r.InstallationState);
141+
IEnumerable<LibraryInstallationGoalState> goalStates = results.Where(r => r.Success).Select(r => r.Result);
142142
var list = new List<ITaskItem>();
143143

144-
foreach (ILibraryInstallationState state in states)
144+
foreach (LibraryInstallationGoalState goalState in goalStates)
145145
{
146-
IProvider provider = dependencies.GetProvider(state.ProviderId);
147-
OperationResult<LibraryInstallationGoalState> goalStateResult = provider.GetInstallationGoalStateAsync(state, CancellationToken.None).Result;
148-
if (goalStateResult.Success)
149-
{
150-
list.AddRange(goalStateResult.Result.InstalledFiles.Select(f => new TaskItem(f.Key)));
151-
}
146+
list.AddRange(goalState.InstalledFiles.Select(f => new TaskItem(f.Key)));
152147
}
153148

154149
FilesWritten = list.ToArray();

src/LibraryManager.Contracts/ILibraryOperationResult.cs

-44
This file was deleted.

src/LibraryManager.Contracts/IProvider.cs

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System;
45
using System.Threading;
56
using System.Threading.Tasks;
67

@@ -44,16 +45,8 @@ public interface IProvider
4445
/// </summary>
4546
/// <param name="desiredState">The details about the library to install.</param>
4647
/// <param name="cancellationToken">A token that allows for the operation to be cancelled.</param>
47-
/// <returns>The <see cref="ILibraryOperationResult"/> from the installation process.</returns>
48-
Task<ILibraryOperationResult> InstallAsync(ILibraryInstallationState desiredState, CancellationToken cancellationToken);
49-
50-
/// <summary>
51-
/// Updates library state using catalog if needed
52-
/// </summary>
53-
/// <param name="desiredState"></param>
54-
/// <param name="cancellationToken"></param>
55-
/// <returns></returns>
56-
Task<ILibraryOperationResult> UpdateStateAsync(ILibraryInstallationState desiredState, CancellationToken cancellationToken);
48+
/// <returns>The <see cref="OperationResult{LibraryInstallationGoalState}"/> from the installation process.</returns>
49+
Task<OperationResult<LibraryInstallationGoalState>> InstallAsync(ILibraryInstallationState desiredState, CancellationToken cancellationToken);
5750

5851
/// <summary>
5952
/// Gets the <see cref="ILibraryCatalog"/> for the <see cref="IProvider"/>. May be <code>null</code> if no catalog is supported.

src/LibraryManager.Contracts/InvalidLibraryException.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace Microsoft.Web.LibraryManager.Contracts
1515
/// For instance, if a <see cref="ILibraryInstallationState"/> with an id that isn't
1616
/// recognized by the <see cref="IProvider"/> is being passed to <see cref="Contracts.IProvider.InstallAsync"/>,
1717
/// this exception could be thrown so it can be handled inside <see cref="Contracts.IProvider.InstallAsync"/>
18-
/// and an <see cref="IError"/> added to the <see cref="ILibraryOperationResult.Errors"/> collection.
18+
/// and an <see cref="IError"/> added to the <see cref="OperationResult{LibraryInstallationGoalState}.Errors"/> collection.
1919
/// </remarks>
2020
[Serializable]
2121
public class InvalidLibraryException : Exception

src/LibraryManager.Vsix/Contracts/Logger.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public static void LogEventsFooter(OperationType operationType, TimeSpan elapsed
7777
/// <param name="operationType"></param>
7878
/// <param name="elapsedTime"></param>
7979
/// <param name="endOfMessage"></param>
80-
public static void LogEventsSummary(IEnumerable<ILibraryOperationResult> totalResults, OperationType operationType, TimeSpan elapsedTime, bool endOfMessage = true)
80+
public static void LogEventsSummary(IEnumerable<OperationResult<LibraryInstallationGoalState>> totalResults, OperationType operationType, TimeSpan elapsedTime, bool endOfMessage = true)
8181
{
8282
LogErrors(totalResults);
8383
LogEvent(LogMessageGenerator.GetSummaryHeaderString(operationType), LogLevel.Task);
@@ -116,7 +116,7 @@ public static void LogErrorsSummary(IEnumerable<string> errorMessages, Operation
116116
/// <param name="results">Operation results</param>
117117
/// <param name="operationType"><see cref="OperationType"/></param>
118118
/// <param name="endOfMessage">Whether or not to log end of message lines</param>
119-
public static void LogErrorsSummary(IEnumerable<ILibraryOperationResult> results, OperationType operationType, bool endOfMessage = true)
119+
public static void LogErrorsSummary(IEnumerable<OperationResult<LibraryInstallationGoalState>> results, OperationType operationType, bool endOfMessage = true)
120120
{
121121
List<string> errorStrings = GetErrorStrings(results);
122122
LogErrorsSummary(errorStrings, operationType, endOfMessage);
@@ -271,7 +271,7 @@ private static bool EnsurePane()
271271
return OutputWindowPaneValue != null;
272272
}
273273

274-
private static void LogOperationSummary(IEnumerable<ILibraryOperationResult> totalResults, OperationType operation, TimeSpan elapsedTime)
274+
private static void LogOperationSummary(IEnumerable<OperationResult<LibraryInstallationGoalState>> totalResults, OperationType operation, TimeSpan elapsedTime)
275275
{
276276
string messageText = LogMessageGenerator.GetOperationSummaryString(totalResults, operation, elapsedTime);
277277

@@ -281,9 +281,9 @@ private static void LogOperationSummary(IEnumerable<ILibraryOperationResult> tot
281281
}
282282
}
283283

284-
private static void LogErrors(IEnumerable<ILibraryOperationResult> results)
284+
private static void LogErrors(IEnumerable<OperationResult<LibraryInstallationGoalState>> results)
285285
{
286-
foreach (ILibraryOperationResult result in results)
286+
foreach (OperationResult<LibraryInstallationGoalState> result in results)
287287
{
288288
foreach (IError error in result.Errors)
289289
{
@@ -292,11 +292,11 @@ private static void LogErrors(IEnumerable<ILibraryOperationResult> results)
292292
}
293293
}
294294

295-
private static List<string> GetErrorStrings(IEnumerable<ILibraryOperationResult> results)
295+
private static List<string> GetErrorStrings(IEnumerable<OperationResult<LibraryInstallationGoalState>> results)
296296
{
297297
List<string> errorStrings = new List<string>();
298298

299-
foreach (ILibraryOperationResult result in results)
299+
foreach (OperationResult<LibraryInstallationGoalState> result in results)
300300
{
301301
foreach (IError error in result.Errors)
302302
{

src/LibraryManager.Vsix/ErrorList/ErrorListPropagator.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ public ErrorListPropagator(string projectName, string configFileName)
2323
public string ConfigFileName { get; set; }
2424
public List<DisplayError> Errors { get; }
2525

26-
public bool HandleErrors(IEnumerable<ILibraryOperationResult> results)
26+
public bool HandleErrors(IEnumerable<OperationResult<LibraryInstallationGoalState>> results)
2727
{
2828
string[] jsonLines = File.Exists(ConfigFileName) ? File.ReadLines(ConfigFileName).ToArray() : Array.Empty<string>();
2929

30-
foreach (ILibraryOperationResult result in results)
30+
foreach (OperationResult<LibraryInstallationGoalState> goalStateResult in results)
3131
{
32-
if (!result.Success)
32+
if (!goalStateResult.Success)
3333
{
34-
DisplayError[] displayErrors = result.Errors.Select(error => new DisplayError(error)).ToArray();
35-
AddLineAndColumn(jsonLines, result.InstallationState, displayErrors);
34+
DisplayError[] displayErrors = goalStateResult.Errors.Select(error => new DisplayError(error)).ToArray();
35+
AddLineAndColumn(jsonLines, goalStateResult.Result?.InstallationState, displayErrors);
3636

3737
Errors.AddRange(displayErrors);
3838
}

src/LibraryManager.Vsix/Json/TextviewCreationListener.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public void VsTextViewCreated(IVsTextView textViewAdapter)
8080

8181
_ = Task.Run(async () =>
8282
{
83-
IEnumerable<ILibraryOperationResult> results = await LibrariesValidator.GetManifestErrorsAsync(_manifest, dependencies, CancellationToken.None).ConfigureAwait(false);
83+
IEnumerable<OperationResult<LibraryInstallationGoalState>> results = await LibrariesValidator.GetManifestErrorsAsync(_manifest, dependencies, CancellationToken.None).ConfigureAwait(false);
8484
if (!results.All(r => r.Success))
8585
{
8686
AddErrorsToList(results);
@@ -108,7 +108,7 @@ async Task DoRestoreOnSaveAsync()
108108
{
109109
IDependencies dependencies = DependenciesFactory.FromConfigFile(textDocument.FilePath);
110110
var newManifest = Manifest.FromJson(textDocument.TextBuffer.CurrentSnapshot.GetText(), dependencies);
111-
IEnumerable<ILibraryOperationResult> results = await LibrariesValidator.GetManifestErrorsAsync(newManifest, dependencies, CancellationToken.None).ConfigureAwait(false);
111+
IEnumerable<OperationResult<LibraryInstallationGoalState>> results = await LibrariesValidator.GetManifestErrorsAsync(newManifest, dependencies, CancellationToken.None).ConfigureAwait(false);
112112

113113
if (!results.All(r => r.Success))
114114
{
@@ -170,7 +170,7 @@ private void OnViewClosed(object sender, EventArgs e)
170170
_errorList?.ClearErrors();
171171
}
172172

173-
private void AddErrorsToList(IEnumerable<ILibraryOperationResult> errors)
173+
private void AddErrorsToList(IEnumerable<OperationResult<LibraryInstallationGoalState>> errors)
174174
{
175175
_errorList = new ErrorListPropagator(_project?.Name, _manifestPath);
176176
_errorList.HandleErrors(errors);

src/LibraryManager.Vsix/Shared/LibraryCommandService.cs

+15-17
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,11 @@ private async Task CleanLibrariesAsync(ProjectItem configProjectItem, Cancellati
182182
Project project = VsHelpers.GetDTEProjectFromConfig(configFileName);
183183

184184
Manifest manifest = await Manifest.FromFileAsync(configFileName, dependencies, CancellationToken.None).ConfigureAwait(false);
185-
IEnumerable<ILibraryOperationResult> results = new List<ILibraryOperationResult>();
185+
IEnumerable<OperationResult<LibraryInstallationGoalState>> results = new List<OperationResult<LibraryInstallationGoalState>>();
186186

187187
if (manifest != null)
188188
{
189-
IEnumerable<ILibraryOperationResult> validationResults = await LibrariesValidator.GetManifestErrorsAsync(manifest, dependencies, cancellationToken).ConfigureAwait(false);
189+
IEnumerable<OperationResult<LibraryInstallationGoalState>> validationResults = await LibrariesValidator.GetManifestErrorsAsync(manifest, dependencies, cancellationToken).ConfigureAwait(false);
190190

191191
if (!validationResults.All(r => r.Success))
192192
{
@@ -234,7 +234,7 @@ private async Task RestoreInternalAsync(IDictionary<string, Manifest> manifests,
234234

235235
Logger.LogEvent(string.Format(LibraryManager.Resources.Text.Restore_LibrariesForProject, project?.Name), LogLevel.Operation);
236236

237-
IEnumerable<ILibraryOperationResult> validationResults = await LibrariesValidator.GetManifestErrorsAsync(manifest.Value, dependencies, cancellationToken).ConfigureAwait(false);
237+
IEnumerable<OperationResult<LibraryInstallationGoalState>> validationResults = await LibrariesValidator.GetManifestErrorsAsync(manifest.Value, dependencies, cancellationToken).ConfigureAwait(false);
238238
if (!validationResults.All(r => r.Success))
239239
{
240240
swLocal.Stop();
@@ -244,7 +244,7 @@ private async Task RestoreInternalAsync(IDictionary<string, Manifest> manifests,
244244
}
245245
else
246246
{
247-
IEnumerable<ILibraryOperationResult> results = await RestoreLibrariesAsync(manifest.Value, cancellationToken).ConfigureAwait(false);
247+
var results = await RestoreLibrariesAsync(manifest.Value, cancellationToken).ConfigureAwait(false);
248248
await AddFilesToProjectAsync(manifest.Key, project, results.Where(r =>r.Success && !r.UpToDate), cancellationToken).ConfigureAwait(false);
249249

250250
swLocal.Stop();
@@ -264,7 +264,7 @@ private async Task RestoreInternalAsync(IDictionary<string, Manifest> manifests,
264264
}
265265
}
266266

267-
private async Task<IEnumerable<ILibraryOperationResult>> RestoreLibrariesAsync(Manifest manifest, CancellationToken cancellationToken)
267+
private async Task<IEnumerable<OperationResult<LibraryInstallationGoalState>>> RestoreLibrariesAsync(Manifest manifest, CancellationToken cancellationToken)
268268
{
269269
return await manifest.RestoreAsync(cancellationToken).ConfigureAwait(false);
270270
}
@@ -281,11 +281,11 @@ private async Task UninstallLibraryAsync(string configFilePath, string libraryNa
281281

282282
var dependencies = _dependenciesFactory.FromConfigFile(configFilePath);
283283
Manifest manifest = await Manifest.FromFileAsync(configFilePath, dependencies, cancellationToken).ConfigureAwait(false);
284-
ILibraryOperationResult result = null;
284+
OperationResult<LibraryInstallationGoalState> result = null;
285285

286286
if (manifest == null)
287287
{
288-
result = LibraryOperationResult.FromError(PredefinedErrors.ManifestMalformed());
288+
result = OperationResult<LibraryInstallationGoalState>.FromError(PredefinedErrors.ManifestMalformed());
289289
}
290290
else
291291
{
@@ -297,14 +297,14 @@ private async Task UninstallLibraryAsync(string configFilePath, string libraryNa
297297

298298
if (result.Errors.Any())
299299
{
300-
Logger.LogErrorsSummary(new List<ILibraryOperationResult> { result }, OperationType.Uninstall);
300+
Logger.LogErrorsSummary(new List<OperationResult<LibraryInstallationGoalState>> { result }, OperationType.Uninstall);
301301
}
302302
else
303303
{
304-
Logger.LogEventsSummary(new List<ILibraryOperationResult> { result }, OperationType.Uninstall, sw.Elapsed);
304+
Logger.LogEventsSummary(new List<OperationResult<LibraryInstallationGoalState>> { result }, OperationType.Uninstall, sw.Elapsed);
305305
}
306306

307-
Telemetry.LogEventsSummary(new List<ILibraryOperationResult> { result }, OperationType.Uninstall, sw.Elapsed);
307+
Telemetry.LogEventsSummary(new List<OperationResult<LibraryInstallationGoalState>> { result }, OperationType.Uninstall, sw.Elapsed);
308308
}
309309
catch (OperationCanceledException ex)
310310
{
@@ -333,26 +333,24 @@ private string GetTaskTitle(OperationType operation, string libraryId)
333333
return string.Empty;
334334
}
335335

336-
private void AddErrorsToErrorList(string projectName, string configFile, IEnumerable<ILibraryOperationResult> results)
336+
private void AddErrorsToErrorList(string projectName, string configFile, IEnumerable<OperationResult<LibraryInstallationGoalState>> results)
337337
{
338338
var errorList = new ErrorListPropagator(projectName, configFile);
339339
errorList.HandleErrors(results);
340340
}
341341

342-
private async Task AddFilesToProjectAsync(string configFilePath, Project project, IEnumerable<ILibraryOperationResult> results, CancellationToken cancellationToken)
342+
private async Task AddFilesToProjectAsync(string configFilePath, Project project, IEnumerable<OperationResult<LibraryInstallationGoalState>> results, CancellationToken cancellationToken)
343343
{
344344
string workingDirectory = Path.GetDirectoryName(configFilePath);
345345
var files = new List<string>();
346346

347347
if (project != null)
348348
{
349-
foreach (ILibraryOperationResult state in results)
349+
foreach (OperationResult<LibraryInstallationGoalState> goalStateResult in results)
350350
{
351-
if (state.Success && !state.UpToDate && state.InstallationState.Files != null)
351+
if (goalStateResult.Success && !goalStateResult.UpToDate && goalStateResult.Result.InstallationState.Files != null)
352352
{
353-
IEnumerable<string> absoluteFiles = state.InstallationState.Files
354-
.Select(file => Path.Combine(workingDirectory, state.InstallationState.DestinationPath, file)
355-
.Replace('/', Path.DirectorySeparatorChar));
353+
IEnumerable<string> absoluteFiles = goalStateResult.Result.InstalledFiles.Keys;
356354
files.AddRange(absoluteFiles);
357355
}
358356
}

0 commit comments

Comments
 (0)