Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public async Task<bool> CanCommandBeLocated(string command, IEnumerable<string>
additionalCandidateCommands = additionalCandidateCommands ?? Enumerable.Empty<string>();
parameters = parameters ?? new string[0];
var allCommands = new[] { command }.Concat(additionalCandidateCommands);
if (!commandLocatableCache.TryGetValue(command, out string validCommand))
if (!this.commandLocatableCache.TryGetValue(command, out string validCommand))
{
foreach (var commandToTry in allCommands)
{
Expand All @@ -36,7 +36,7 @@ public async Task<bool> CanCommandBeLocated(string command, IEnumerable<string>

if (result.ExitCode == 0)
{
commandLocatableCache[command] = validCommand = commandToTry;
this.commandLocatableCache[command] = validCommand = commandToTry;
break;
}
}
Expand All @@ -53,7 +53,7 @@ public async Task<bool> CanCommandBeLocated(string command, IEnumerable<string>

public async Task<CommandLineExecutionResult> ExecuteCommand(string command, IEnumerable<string> additionalCandidateCommands = null, DirectoryInfo workingDirectory = null, params string[] parameters)
{
var isCommandLocatable = await CanCommandBeLocated(command, additionalCandidateCommands);
var isCommandLocatable = await this.CanCommandBeLocated(command, additionalCandidateCommands);
if (!isCommandLocatable)
{
throw new InvalidOperationException(
Expand All @@ -68,7 +68,7 @@ public async Task<CommandLineExecutionResult> ExecuteCommand(string command, IEn

using var record = new CommandLineInvocationTelemetryRecord();

var pathToRun = commandLocatableCache[command];
var pathToRun = this.commandLocatableCache[command];
var joinedParameters = string.Join(" ", parameters);
try
{
Expand Down Expand Up @@ -147,12 +147,12 @@ private static Task<CommandLineExecutionResult> RunProcessAsync(string fileName,

public async Task<bool> CanCommandBeLocated(string command, IEnumerable<string> additionalCandidateCommands = null, params string[] parameters)
{
return await CanCommandBeLocated(command, additionalCandidateCommands, workingDirectory: null, parameters);
return await this.CanCommandBeLocated(command, additionalCandidateCommands, workingDirectory: null, parameters);
}

public async Task<CommandLineExecutionResult> ExecuteCommand(string command, IEnumerable<string> additionalCandidateCommands = null, params string[] parameters)
{
return await ExecuteCommand(command, additionalCandidateCommands, workingDirectory: null, parameters);
return await this.ExecuteCommand(command, additionalCandidateCommands, workingDirectory: null, parameters);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ public class ComponentStreamEnumerable : IEnumerable<IComponentStream>

public ComponentStreamEnumerable(IEnumerable<MatchedFile> fileEnumerable, ILogger logger)
{
ToEnumerate = fileEnumerable;
Logger = logger;
this.ToEnumerate = fileEnumerable;
this.Logger = logger;
}

public IEnumerator<IComponentStream> GetEnumerator()
{
foreach (var filePairing in ToEnumerate)
foreach (var filePairing in this.ToEnumerate)
{
if (!filePairing.File.Exists)
{
Logger.LogWarning($"File {filePairing.File.FullName} does not exist on disk.");
this.Logger.LogWarning($"File {filePairing.File.FullName} does not exist on disk.");
yield break;
}

using var stream = SafeOpenFile(filePairing.File);
using var stream = this.SafeOpenFile(filePairing.File);

if (stream == null)
{
Expand All @@ -41,7 +41,7 @@ public IEnumerator<IComponentStream> GetEnumerator()

IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
return this.GetEnumerator();
}

private Stream SafeOpenFile(FileInfo file)
Expand All @@ -52,13 +52,13 @@ private Stream SafeOpenFile(FileInfo file)
}
catch (UnauthorizedAccessException)
{
Logger.LogWarning($"Unauthorized access exception caught when trying to open {file.FullName}");
this.Logger.LogWarning($"Unauthorized access exception caught when trying to open {file.FullName}");
return null;
}
catch (Exception e)
{
Logger.LogWarning($"Unhandled exception caught when trying to open {file.FullName}");
Logger.LogException(e, isError: false);
this.Logger.LogWarning($"Unhandled exception caught when trying to open {file.FullName}");
this.Logger.LogException(e, isError: false);
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ public class ComponentStreamEnumerableFactory : IComponentStreamEnumerableFactor

public IEnumerable<IComponentStream> GetComponentStreams(DirectoryInfo directory, IEnumerable<string> searchPatterns, ExcludeDirectoryPredicate directoryExclusionPredicate, bool recursivelyScanDirectories = true)
{
SafeFileEnumerable enumerable = new SafeFileEnumerable(directory, searchPatterns, Logger, PathUtilityService, directoryExclusionPredicate, recursivelyScanDirectories);
return new ComponentStreamEnumerable(enumerable, Logger);
SafeFileEnumerable enumerable = new SafeFileEnumerable(directory, searchPatterns, this.Logger, this.PathUtilityService, directoryExclusionPredicate, recursivelyScanDirectories);
return new ComponentStreamEnumerable(enumerable, this.Logger);
}

public IEnumerable<IComponentStream> GetComponentStreams(DirectoryInfo directory, Func<FileInfo, bool> fileMatchingPredicate, ExcludeDirectoryPredicate directoryExclusionPredicate, bool recursivelyScanDirectories = true)
{
SafeFileEnumerable enumerable = new SafeFileEnumerable(directory, fileMatchingPredicate, Logger, PathUtilityService, directoryExclusionPredicate, recursivelyScanDirectories);
return new ComponentStreamEnumerable(enumerable, Logger);
SafeFileEnumerable enumerable = new SafeFileEnumerable(directory, fileMatchingPredicate, this.Logger, this.PathUtilityService, directoryExclusionPredicate, recursivelyScanDirectories);
return new ComponentStreamEnumerable(enumerable, this.Logger);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ public ComponentRecorder(ILogger log = null, bool enableManualTrackingOfExplicit

public TypedComponent GetComponent(string componentId)
{
return singleFileRecorders.Select(x => x.GetComponent(componentId)?.Component).Where(x => x != null).FirstOrDefault();
return this.singleFileRecorders.Select(x => x.GetComponent(componentId)?.Component).Where(x => x != null).FirstOrDefault();
}

public IEnumerable<DetectedComponent> GetDetectedComponents()
{
IEnumerable<DetectedComponent> detectedComponents;
if (singleFileRecorders == null)
if (this.singleFileRecorders == null)
{
return Enumerable.Empty<DetectedComponent>();
}

detectedComponents = singleFileRecorders
detectedComponents = this.singleFileRecorders
.Select(singleFileRecorder => singleFileRecorder.GetDetectedComponents().Values)
.SelectMany(x => x)
.GroupBy(x => x.Component.Id)
Expand Down Expand Up @@ -69,24 +69,24 @@ public ISingleFileComponentRecorder CreateSingleFileComponentRecorder(string loc
throw new ArgumentNullException(nameof(location));
}

var matching = singleFileRecorders.FirstOrDefault(x => x.ManifestFileLocation == location);
var matching = this.singleFileRecorders.FirstOrDefault(x => x.ManifestFileLocation == location);
if (matching == null)
{
matching = new SingleFileComponentRecorder(location, this, enableManualTrackingOfExplicitReferences, log);
singleFileRecorders.Add(matching);
matching = new SingleFileComponentRecorder(location, this, this.enableManualTrackingOfExplicitReferences, this.log);
this.singleFileRecorders.Add(matching);
}

return matching;
}

internal DependencyGraph GetDependencyGraphForLocation(string location)
{
return singleFileRecorders.Single(x => x.ManifestFileLocation == location).DependencyGraph;
return this.singleFileRecorders.Single(x => x.ManifestFileLocation == location).DependencyGraph;
}

public IReadOnlyDictionary<string, IDependencyGraph> GetDependencyGraphsByLocation()
{
return singleFileRecorders.Where(x => x.DependencyGraph.HasComponents())
return this.singleFileRecorders.Where(x => x.DependencyGraph.HasComponents())
.ToImmutableDictionary(x => x.ManifestFileLocation, x => x.DependencyGraph as IDependencyGraph);
}

Expand All @@ -98,7 +98,7 @@ public class SingleFileComponentRecorder : ISingleFileComponentRecorder

internal DependencyGraph DependencyGraph { get; }

IDependencyGraph ISingleFileComponentRecorder.DependencyGraph => DependencyGraph;
IDependencyGraph ISingleFileComponentRecorder.DependencyGraph => this.DependencyGraph;

private readonly ConcurrentDictionary<string, DetectedComponent> detectedComponentsInternal = new ConcurrentDictionary<string, DetectedComponent>();

Expand All @@ -108,15 +108,15 @@ public class SingleFileComponentRecorder : ISingleFileComponentRecorder

public SingleFileComponentRecorder(string location, ComponentRecorder recorder, bool enableManualTrackingOfExplicitReferences, ILogger log)
{
ManifestFileLocation = location;
this.ManifestFileLocation = location;
this.recorder = recorder;
this.log = log;
DependencyGraph = new DependencyGraph(enableManualTrackingOfExplicitReferences);
this.DependencyGraph = new DependencyGraph(enableManualTrackingOfExplicitReferences);
}

public DetectedComponent GetComponent(string componentId)
{
if (detectedComponentsInternal.TryGetValue(componentId, out var detectedComponent))
if (this.detectedComponentsInternal.TryGetValue(componentId, out var detectedComponent))
{
return detectedComponent;
}
Expand All @@ -127,7 +127,7 @@ public DetectedComponent GetComponent(string componentId)
public IReadOnlyDictionary<string, DetectedComponent> GetDetectedComponents()
{
// Should this be immutable?
return detectedComponentsInternal;
return this.detectedComponentsInternal;
}

public void RegisterUsage(
Expand All @@ -150,42 +150,42 @@ public void RegisterUsage(
#if DEBUG
if (detectedComponent.FilePaths?.Any() ?? false)
{
log?.LogWarning("Detector should not populate DetectedComponent.FilePaths!");
this.log?.LogWarning("Detector should not populate DetectedComponent.FilePaths!");
}

if (detectedComponent.DependencyRoots?.Any() ?? false)
{
log?.LogWarning("Detector should not populate DetectedComponent.DependencyRoots!");
this.log?.LogWarning("Detector should not populate DetectedComponent.DependencyRoots!");
}

if (detectedComponent.DevelopmentDependency.HasValue)
{
log?.LogWarning("Detector should not populate DetectedComponent.DevelopmentDependency!");
this.log?.LogWarning("Detector should not populate DetectedComponent.DevelopmentDependency!");
}
#endif

string componentId = detectedComponent.Component.Id;
DetectedComponent storedComponent = null;
lock (registerUsageLock)
lock (this.registerUsageLock)
{
storedComponent = detectedComponentsInternal.GetOrAdd(componentId, detectedComponent);
AddComponentToGraph(ManifestFileLocation, detectedComponent, isExplicitReferencedDependency, parentComponentId, isDevelopmentDependency, dependencyScope);
storedComponent = this.detectedComponentsInternal.GetOrAdd(componentId, detectedComponent);
this.AddComponentToGraph(this.ManifestFileLocation, detectedComponent, isExplicitReferencedDependency, parentComponentId, isDevelopmentDependency, dependencyScope);
}
}

public void AddAdditionalRelatedFile(string relatedFilePath)
{
DependencyGraph.AddAdditionalRelatedFile(relatedFilePath);
this.DependencyGraph.AddAdditionalRelatedFile(relatedFilePath);
}

public IList<string> GetAdditionalRelatedFiles()
{
return DependencyGraph.GetAdditionalRelatedFiles().ToImmutableList();
return this.DependencyGraph.GetAdditionalRelatedFiles().ToImmutableList();
}

public IComponentRecorder GetParentComponentRecorder()
{
return recorder;
return this.recorder;
}

private void AddComponentToGraph(
Expand All @@ -204,7 +204,7 @@ private void AddComponentToGraph(
DependencyScope = dependencyScope,
};

DependencyGraph.AddComponent(componentNode, parentComponentId);
this.DependencyGraph.AddComponent(componentNode, parentComponentId);
}
}
}
Expand Down
Loading