refactor: prefix local calls with `this` (#186)

This commit is contained in:
Jamie Magee 2022-08-04 13:24:13 -07:00 коммит произвёл GitHub
Родитель 3220892e99
Коммит a6205c0a19
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
149 изменённых файлов: 2383 добавлений и 2348 удалений

Просмотреть файл

@ -22,7 +22,7 @@ namespace Microsoft.ComponentDetection.Common
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)
{
@ -36,7 +36,7 @@ namespace Microsoft.ComponentDetection.Common
if (result.ExitCode == 0)
{
commandLocatableCache[command] = validCommand = commandToTry;
this.commandLocatableCache[command] = validCommand = commandToTry;
break;
}
}
@ -53,7 +53,7 @@ namespace Microsoft.ComponentDetection.Common
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(
@ -68,7 +68,7 @@ namespace Microsoft.ComponentDetection.Common
using var record = new CommandLineInvocationTelemetryRecord();
var pathToRun = commandLocatableCache[command];
var pathToRun = this.commandLocatableCache[command];
var joinedParameters = string.Join(" ", parameters);
try
{
@ -147,12 +147,12 @@ namespace Microsoft.ComponentDetection.Common
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);
}
}
}
}

Просмотреть файл

@ -14,21 +14,21 @@ namespace Microsoft.ComponentDetection.Common
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)
{
@ -41,7 +41,7 @@ namespace Microsoft.ComponentDetection.Common
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
return this.GetEnumerator();
}
private Stream SafeOpenFile(FileInfo file)
@ -52,13 +52,13 @@ namespace Microsoft.ComponentDetection.Common
}
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;
}
}

Просмотреть файл

@ -18,14 +18,14 @@ namespace Microsoft.ComponentDetection.Common
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);
}
}
}

Просмотреть файл

@ -28,18 +28,18 @@ namespace Microsoft.ComponentDetection.Common.DependencyGraph
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)
@ -69,11 +69,11 @@ namespace Microsoft.ComponentDetection.Common.DependencyGraph
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;
@ -81,12 +81,12 @@ namespace Microsoft.ComponentDetection.Common.DependencyGraph
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);
}
@ -98,7 +98,7 @@ namespace Microsoft.ComponentDetection.Common.DependencyGraph
internal DependencyGraph DependencyGraph { get; }
IDependencyGraph ISingleFileComponentRecorder.DependencyGraph => DependencyGraph;
IDependencyGraph ISingleFileComponentRecorder.DependencyGraph => this.DependencyGraph;
private readonly ConcurrentDictionary<string, DetectedComponent> detectedComponentsInternal = new ConcurrentDictionary<string, DetectedComponent>();
@ -108,15 +108,15 @@ namespace Microsoft.ComponentDetection.Common.DependencyGraph
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;
}
@ -127,7 +127,7 @@ namespace Microsoft.ComponentDetection.Common.DependencyGraph
public IReadOnlyDictionary<string, DetectedComponent> GetDetectedComponents()
{
// Should this be immutable?
return detectedComponentsInternal;
return this.detectedComponentsInternal;
}
public void RegisterUsage(
@ -150,42 +150,42 @@ namespace Microsoft.ComponentDetection.Common.DependencyGraph
#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(
@ -204,7 +204,7 @@ namespace Microsoft.ComponentDetection.Common.DependencyGraph
DependencyScope = dependencyScope,
};
DependencyGraph.AddComponent(componentNode, parentComponentId);
this.DependencyGraph.AddComponent(componentNode, parentComponentId);
}
}
}

Просмотреть файл

@ -21,7 +21,7 @@ namespace Microsoft.ComponentDetection.Common.DependencyGraph
public DependencyGraph(bool enableManualTrackingOfExplicitReferences)
{
componentNodes = new ConcurrentDictionary<string, ComponentRefNode>();
this.componentNodes = new ConcurrentDictionary<string, ComponentRefNode>();
this.enableManualTrackingOfExplicitReferences = enableManualTrackingOfExplicitReferences;
}
@ -37,7 +37,7 @@ namespace Microsoft.ComponentDetection.Common.DependencyGraph
throw new ArgumentNullException(nameof(componentNode.Id));
}
componentNodes.AddOrUpdate(componentNode.Id, componentNode, (key, currentNode) =>
this.componentNodes.AddOrUpdate(componentNode.Id, componentNode, (key, currentNode) =>
{
currentNode.IsExplicitReferencedDependency |= componentNode.IsExplicitReferencedDependency;
@ -55,17 +55,17 @@ namespace Microsoft.ComponentDetection.Common.DependencyGraph
return currentNode;
});
AddDependency(componentNode.Id, parentComponentId);
this.AddDependency(componentNode.Id, parentComponentId);
}
public bool Contains(string componentId)
{
return componentNodes.ContainsKey(componentId);
return this.componentNodes.ContainsKey(componentId);
}
public ICollection<string> GetDependenciesForComponent(string componentId)
{
return componentNodes[componentId].DependencyIds;
return this.componentNodes[componentId].DependencyIds;
}
public ICollection<string> GetExplicitReferencedDependencyIds(string componentId)
@ -75,53 +75,53 @@ namespace Microsoft.ComponentDetection.Common.DependencyGraph
throw new ArgumentNullException(nameof(componentId));
}
if (!componentNodes.TryGetValue(componentId, out var componentRef))
if (!this.componentNodes.TryGetValue(componentId, out var componentRef))
{
throw new ArgumentException(string.Format(Resources.MissingNodeInDependencyGraph, componentId), paramName: nameof(componentId));
}
IList<string> explicitReferencedDependencyIds = new List<string>();
GetExplicitReferencedDependencies(componentRef, explicitReferencedDependencyIds, new HashSet<string>());
this.GetExplicitReferencedDependencies(componentRef, explicitReferencedDependencyIds, new HashSet<string>());
return explicitReferencedDependencyIds;
}
public void AddAdditionalRelatedFile(string additionalRelatedFile)
{
AdditionalRelatedFiles.AddOrUpdate(additionalRelatedFile, 0, (notUsed, notUsed2) => 0);
this.AdditionalRelatedFiles.AddOrUpdate(additionalRelatedFile, 0, (notUsed, notUsed2) => 0);
}
public HashSet<string> GetAdditionalRelatedFiles()
{
return AdditionalRelatedFiles.Keys.ToImmutableHashSet().ToHashSet();
return this.AdditionalRelatedFiles.Keys.ToImmutableHashSet().ToHashSet();
}
public bool HasComponents()
{
return componentNodes.Count > 0;
return this.componentNodes.Count > 0;
}
public bool? IsDevelopmentDependency(string componentId)
{
return componentNodes[componentId].IsDevelopmentDependency;
return this.componentNodes[componentId].IsDevelopmentDependency;
}
public DependencyScope? GetDependencyScope(string componentId)
{
return componentNodes[componentId].DependencyScope;
return this.componentNodes[componentId].DependencyScope;
}
public IEnumerable<string> GetAllExplicitlyReferencedComponents()
{
return componentNodes.Values
.Where(componentRefNode => IsExplicitReferencedDependency(componentRefNode))
return this.componentNodes.Values
.Where(componentRefNode => this.IsExplicitReferencedDependency(componentRefNode))
.Select(componentRefNode => componentRefNode.Id);
}
private void GetExplicitReferencedDependencies(ComponentRefNode component, IList<string> explicitReferencedDependencyIds, ISet<string> visited)
{
if (IsExplicitReferencedDependency(component))
if (this.IsExplicitReferencedDependency(component))
{
explicitReferencedDependencyIds.Add(component.Id);
}
@ -132,15 +132,15 @@ namespace Microsoft.ComponentDetection.Common.DependencyGraph
{
if (!visited.Contains(parentId))
{
GetExplicitReferencedDependencies(componentNodes[parentId], explicitReferencedDependencyIds, visited);
this.GetExplicitReferencedDependencies(this.componentNodes[parentId], explicitReferencedDependencyIds, visited);
}
}
}
private bool IsExplicitReferencedDependency(ComponentRefNode component)
{
return (enableManualTrackingOfExplicitReferences && component.IsExplicitReferencedDependency) ||
(!enableManualTrackingOfExplicitReferences && !component.DependedOnByIds.Any());
return (this.enableManualTrackingOfExplicitReferences && component.IsExplicitReferencedDependency) ||
(!this.enableManualTrackingOfExplicitReferences && !component.DependedOnByIds.Any());
}
private void AddDependency(string componentId, string parentComponentId)
@ -150,28 +150,28 @@ namespace Microsoft.ComponentDetection.Common.DependencyGraph
return;
}
if (!componentNodes.TryGetValue(parentComponentId, out var parentComponentRefNode))
if (!this.componentNodes.TryGetValue(parentComponentId, out var parentComponentRefNode))
{
throw new ArgumentException(string.Format(Resources.MissingNodeInDependencyGraph, parentComponentId), nameof(parentComponentId));
}
parentComponentRefNode.DependencyIds.Add(componentId);
componentNodes[componentId].DependedOnByIds.Add(parentComponentId);
this.componentNodes[componentId].DependedOnByIds.Add(parentComponentId);
}
IEnumerable<string> IDependencyGraph.GetDependenciesForComponent(string componentId)
{
return GetDependenciesForComponent(componentId).ToImmutableList();
return this.GetDependenciesForComponent(componentId).ToImmutableList();
}
IEnumerable<string> IDependencyGraph.GetComponents()
{
return componentNodes.Keys.ToImmutableList();
return this.componentNodes.Keys.ToImmutableList();
}
bool IDependencyGraph.IsComponentExplicitlyReferenced(string componentId)
{
return IsExplicitReferencedDependency(componentNodes[componentId]);
return this.IsExplicitReferencedDependency(this.componentNodes[componentId]);
}
internal class ComponentRefNode
@ -190,8 +190,8 @@ namespace Microsoft.ComponentDetection.Common.DependencyGraph
internal ComponentRefNode()
{
DependencyIds = new HashSet<string>();
DependedOnByIds = new HashSet<string>();
this.DependencyIds = new HashSet<string>();
this.DependedOnByIds = new HashSet<string>();
}
}
}

Просмотреть файл

@ -37,7 +37,7 @@ namespace Microsoft.ComponentDetection.Common
}
catch (Exception e)
{
Logger.LogException(e, false);
this.Logger.LogException(e, false);
return false;
}
}
@ -45,7 +45,7 @@ namespace Microsoft.ComponentDetection.Common
public async Task<bool> CanRunLinuxContainersAsync(CancellationToken cancellationToken = default)
{
using var record = new DockerServiceSystemInfoTelemetryRecord();
if (!await CanPingDockerAsync(cancellationToken))
if (!await this.CanPingDockerAsync(cancellationToken))
{
return false;
}
@ -165,7 +165,7 @@ namespace Microsoft.ComponentDetection.Common
Image = image,
Command = JsonConvert.SerializeObject(command),
};
await TryPullImageAsync(image, cancellationToken);
await this.TryPullImageAsync(image, cancellationToken);
var container = await CreateContainerAsync(image, command, cancellationToken);
record.Container = JsonConvert.SerializeObject(container);
var stream = await AttachContainerAsync(container.ID, cancellationToken);

Просмотреть файл

@ -10,7 +10,7 @@ namespace Microsoft.ComponentDetection.Common
{
public bool DoesEnvironmentVariableExist(string name)
{
return GetEnvironmentVariable(name) != null;
return this.GetEnvironmentVariable(name) != null;
}
public string GetEnvironmentVariable(string name)
@ -27,7 +27,7 @@ namespace Microsoft.ComponentDetection.Common
public bool IsEnvironmentVariableValueTrue(string name)
{
_ = bool.TryParse(GetEnvironmentVariable(name), out bool result);
_ = bool.TryParse(this.GetEnvironmentVariable(name), out bool result);
return result;
}
}

Просмотреть файл

@ -34,7 +34,7 @@ namespace Microsoft.ComponentDetection.Common
{
if (!root.Exists)
{
Logger?.LogError($"Root directory doesn't exist: {root.FullName}");
this.Logger?.LogError($"Root directory doesn't exist: {root.FullName}");
s.OnCompleted();
return Task.CompletedTask;
}
@ -52,7 +52,7 @@ namespace Microsoft.ComponentDetection.Common
var sw = Stopwatch.StartNew();
Logger?.LogInfo($"Starting enumeration of {root.FullName}");
this.Logger?.LogInfo($"Starting enumeration of {root.FullName}");
var fileCount = 0;
var directoryCount = 0;
@ -73,7 +73,7 @@ namespace Microsoft.ComponentDetection.Common
if (di.Attributes.HasFlag(FileAttributes.ReparsePoint))
{
var realPath = PathUtilityService.ResolvePhysicalPath(di.FullName);
var realPath = this.PathUtilityService.ResolvePhysicalPath(di.FullName);
realDirectory = new DirectoryInfo(realPath);
}
@ -91,7 +91,7 @@ namespace Microsoft.ComponentDetection.Common
return true;
});
var initialIterator = new FileSystemEnumerable<FileSystemInfo>(root.FullName, Transform, new EnumerationOptions()
var initialIterator = new FileSystemEnumerable<FileSystemInfo>(root.FullName, this.Transform, new EnumerationOptions()
{
RecurseSubdirectories = false,
IgnoreInaccessible = true,
@ -145,7 +145,7 @@ namespace Microsoft.ComponentDetection.Common
var scan = new ActionBlock<DirectoryInfo>(
di =>
{
var enumerator = new FileSystemEnumerable<FileSystemInfo>(di.FullName, Transform, new EnumerationOptions()
var enumerator = new FileSystemEnumerable<FileSystemInfo>(di.FullName, this.Transform, new EnumerationOptions()
{
RecurseSubdirectories = true,
IgnoreInaccessible = true,
@ -188,7 +188,7 @@ namespace Microsoft.ComponentDetection.Common
}, () =>
{
sw.Stop();
Logger?.LogInfo($"Enumerated {fileCount} files and {directoryCount} directories in {sw.Elapsed}");
this.Logger?.LogInfo($"Enumerated {fileCount} files and {directoryCount} directories in {sw.Elapsed}");
s.OnCompleted();
});
});
@ -201,13 +201,13 @@ namespace Microsoft.ComponentDetection.Common
private IObservable<FileSystemInfo> CreateDirectoryWalker(DirectoryInfo di, ExcludeDirectoryPredicate directoryExclusionPredicate, int minimumConnectionCount, IEnumerable<string> filePatterns)
{
return GetDirectoryScanner(di, new ConcurrentDictionary<string, bool>(), directoryExclusionPredicate, filePatterns, true).Replay() // Returns a replay subject which will republish anything found to new subscribers.
return this.GetDirectoryScanner(di, new ConcurrentDictionary<string, bool>(), directoryExclusionPredicate, filePatterns, true).Replay() // Returns a replay subject which will republish anything found to new subscribers.
.AutoConnect(minimumConnectionCount); // Specifies that this connectable observable should start when minimumConnectionCount subscribe.
}
private bool MatchesAnyPattern(FileInfo fi, params string[] searchPatterns)
{
return searchPatterns != null && searchPatterns.Any(sp => PathUtilityService.MatchesPattern(sp, fi.Name));
return searchPatterns != null && searchPatterns.Any(sp => this.PathUtilityService.MatchesPattern(sp, fi.Name));
}
/// <summary>
@ -219,22 +219,22 @@ namespace Microsoft.ComponentDetection.Common
/// <param name="filePatterns">Pattern used to filter files.</param>
public void Initialize(DirectoryInfo root, ExcludeDirectoryPredicate directoryExclusionPredicate, int minimumConnectionCount, IEnumerable<string> filePatterns = null)
{
pendingScans.GetOrAdd(root, new Lazy<IObservable<FileSystemInfo>>(() => CreateDirectoryWalker(root, directoryExclusionPredicate, minimumConnectionCount, filePatterns)));
this.pendingScans.GetOrAdd(root, new Lazy<IObservable<FileSystemInfo>>(() => this.CreateDirectoryWalker(root, directoryExclusionPredicate, minimumConnectionCount, filePatterns)));
}
public IObservable<FileSystemInfo> Subscribe(DirectoryInfo root, IEnumerable<string> patterns)
{
var patternArray = patterns.ToArray();
if (pendingScans.TryGetValue(root, out var scannerObservable))
if (this.pendingScans.TryGetValue(root, out var scannerObservable))
{
Logger.LogVerbose(string.Join(":", patterns));
this.Logger.LogVerbose(string.Join(":", patterns));
var inner = scannerObservable.Value.Where(fsi =>
{
if (fsi is FileInfo fi)
{
return MatchesAnyPattern(fi, patternArray);
return this.MatchesAnyPattern(fi, patternArray);
}
else
{
@ -250,7 +250,7 @@ namespace Microsoft.ComponentDetection.Common
public IObservable<ProcessRequest> GetFilteredComponentStreamObservable(DirectoryInfo root, IEnumerable<string> patterns, IComponentRecorder componentRecorder)
{
var observable = Subscribe(root, patterns).OfType<FileInfo>().SelectMany(f => patterns.Select(sp => new
var observable = this.Subscribe(root, patterns).OfType<FileInfo>().SelectMany(f => patterns.Select(sp => new
{
SearchPattern = sp,
File = f,
@ -259,11 +259,11 @@ namespace Microsoft.ComponentDetection.Common
var searchPattern = x.SearchPattern;
var fileName = x.File.Name;
return PathUtilityService.MatchesPattern(searchPattern, fileName);
return this.PathUtilityService.MatchesPattern(searchPattern, fileName);
}).Where(x => x.File.Exists)
.Select(x =>
{
var lazyComponentStream = new LazyComponentStream(x.File, x.SearchPattern, Logger);
var lazyComponentStream = new LazyComponentStream(x.File, x.SearchPattern, this.Logger);
return new ProcessRequest
{
ComponentStream = lazyComponentStream,
@ -276,7 +276,7 @@ namespace Microsoft.ComponentDetection.Common
public void StartScan(DirectoryInfo root)
{
if (pendingScans.TryRemove(root, out var scannerObservable))
if (this.pendingScans.TryRemove(root, out var scannerObservable))
{
// scannerObservable.Connect();
}
@ -286,7 +286,7 @@ namespace Microsoft.ComponentDetection.Common
public void Reset()
{
pendingScans.Clear();
this.pendingScans.Clear();
}
}
}
}

Просмотреть файл

@ -23,14 +23,14 @@ namespace Microsoft.ComponentDetection.Common
throw new InvalidUserInputException($"The path {basePath} does not exist.", new DirectoryNotFoundException());
}
BasePath = string.IsNullOrEmpty(basePath) ? Path.GetTempPath() : basePath;
this.BasePath = string.IsNullOrEmpty(basePath) ? Path.GetTempPath() : basePath;
}
public void AppendToFile(string relativeFilePath, string text)
{
relativeFilePath = ResolveFilePath(relativeFilePath);
relativeFilePath = this.ResolveFilePath(relativeFilePath);
lock (lockObject)
lock (this.lockObject)
{
File.AppendAllText(relativeFilePath, text);
}
@ -38,9 +38,9 @@ namespace Microsoft.ComponentDetection.Common
public void WriteFile(string relativeFilePath, string text)
{
relativeFilePath = ResolveFilePath(relativeFilePath);
relativeFilePath = this.ResolveFilePath(relativeFilePath);
lock (lockObject)
lock (this.lockObject)
{
File.WriteAllText(relativeFilePath, text);
}
@ -53,19 +53,19 @@ namespace Microsoft.ComponentDetection.Common
public string ResolveFilePath(string relativeFilePath)
{
EnsureInit();
this.EnsureInit();
if (relativeFilePath.Contains("{timestamp}"))
{
relativeFilePath = relativeFilePath.Replace("{timestamp}", timestamp);
relativeFilePath = relativeFilePath.Replace("{timestamp}", this.timestamp);
}
relativeFilePath = Path.Combine(BasePath, relativeFilePath);
relativeFilePath = Path.Combine(this.BasePath, relativeFilePath);
return relativeFilePath;
}
private void EnsureInit()
{
if (string.IsNullOrEmpty(BasePath))
if (string.IsNullOrEmpty(this.BasePath))
{
throw new InvalidOperationException("Base path has not yet been initialized in File Writing Service!");
}

Просмотреть файл

@ -14,21 +14,21 @@ namespace Microsoft.ComponentDetection.Common
{
try
{
using var fs = fileInfo.OpenRead();
using var fs = this.fileInfo.OpenRead();
var buffer = new byte[fileInfo.Length];
fs.Read(buffer, 0, (int)fileInfo.Length);
var buffer = new byte[this.fileInfo.Length];
fs.Read(buffer, 0, (int)this.fileInfo.Length);
return buffer;
}
catch (UnauthorizedAccessException)
{
logger?.LogWarning($"Unauthorized access exception caught when trying to open {fileInfo.FullName}");
this.logger?.LogWarning($"Unauthorized access exception caught when trying to open {this.fileInfo.FullName}");
}
catch (Exception e)
{
logger?.LogWarning($"Unhandled exception caught when trying to open {fileInfo.FullName}");
logger?.LogException(e, isError: false);
this.logger?.LogWarning($"Unhandled exception caught when trying to open {this.fileInfo.FullName}");
this.logger?.LogException(e, isError: false);
}
return new byte[0];
@ -36,14 +36,14 @@ namespace Microsoft.ComponentDetection.Common
public LazyComponentStream(FileInfo fileInfo, string pattern, ILogger logger)
{
Pattern = pattern;
Location = fileInfo.FullName;
this.Pattern = pattern;
this.Location = fileInfo.FullName;
this.fileInfo = fileInfo;
this.logger = logger;
fileBuffer = new Lazy<byte[]>(SafeOpenFile);
this.fileBuffer = new Lazy<byte[]>(this.SafeOpenFile);
}
public Stream Stream => new MemoryStream(fileBuffer.Value);
public Stream Stream => new MemoryStream(this.fileBuffer.Value);
public string Pattern { get; set; }

Просмотреть файл

@ -27,45 +27,45 @@ namespace Microsoft.ComponentDetection.Common
public void Init(VerbosityMode verbosity)
{
WriteToFile = true;
Verbosity = verbosity;
this.WriteToFile = true;
this.Verbosity = verbosity;
try
{
FileWritingService.WriteFile(LogRelativePath, string.Empty);
LogInfo($"Log file: {FileWritingService.ResolveFilePath(LogRelativePath)}");
this.FileWritingService.WriteFile(LogRelativePath, string.Empty);
this.LogInfo($"Log file: {this.FileWritingService.ResolveFilePath(LogRelativePath)}");
}
catch (Exception)
{
WriteToFile = false;
LogError("There was an issue writing to the log file, for the remainder of execution verbose output will be written to the console.");
Verbosity = VerbosityMode.Verbose;
this.WriteToFile = false;
this.LogError("There was an issue writing to the log file, for the remainder of execution verbose output will be written to the console.");
this.Verbosity = VerbosityMode.Verbose;
}
}
public void LogCreateLoggingGroup()
{
PrintToConsole(NewLine, VerbosityMode.Normal);
AppendToFile(NewLine);
this.PrintToConsole(NewLine, VerbosityMode.Normal);
this.AppendToFile(NewLine);
}
public void LogWarning(string message)
{
LogInternal("WARN", message);
this.LogInternal("WARN", message);
}
public void LogInfo(string message)
{
LogInternal("INFO", message);
this.LogInternal("INFO", message);
}
public void LogVerbose(string message)
{
LogInternal("VERBOSE", message, VerbosityMode.Verbose);
this.LogInternal("VERBOSE", message, VerbosityMode.Verbose);
}
public void LogError(string message)
{
LogInternal("ERROR", message, VerbosityMode.Quiet);
this.LogInternal("ERROR", message, VerbosityMode.Quiet);
}
private void LogInternal(string prefix, string message, VerbosityMode verbosity = VerbosityMode.Normal)
@ -73,15 +73,15 @@ namespace Microsoft.ComponentDetection.Common
var formattedPrefix = string.IsNullOrWhiteSpace(prefix) ? string.Empty : $"[{prefix}] ";
var text = $"{formattedPrefix}{message} {NewLine}";
PrintToConsole(text, verbosity);
AppendToFile(text);
this.PrintToConsole(text, verbosity);
this.AppendToFile(text);
}
public void LogFailedReadingFile(string filePath, Exception e)
{
PrintToConsole(NewLine, VerbosityMode.Verbose);
LogFailedProcessingFile(filePath);
LogException(e, isError: false);
this.PrintToConsole(NewLine, VerbosityMode.Verbose);
this.LogFailedProcessingFile(filePath);
this.LogException(e, isError: false);
using var record = new FailedReadingFileRecord
{
FilePath = filePath,
@ -109,45 +109,45 @@ namespace Microsoft.ComponentDetection.Common
if (isError)
{
PrintToConsole(consoleText, VerbosityMode.Quiet);
this.PrintToConsole(consoleText, VerbosityMode.Quiet);
}
else
{
PrintToConsole(consoleText, VerbosityMode.Verbose);
this.PrintToConsole(consoleText, VerbosityMode.Verbose);
}
AppendToFile(fullExceptionText);
this.AppendToFile(fullExceptionText);
}
// TODO: All these vso specific logs should go away
public void LogBuildWarning(string message)
{
PrintToConsole($"##vso[task.LogIssue type=warning;]{message}{NewLine}", VerbosityMode.Quiet);
this.PrintToConsole($"##vso[task.LogIssue type=warning;]{message}{NewLine}", VerbosityMode.Quiet);
}
public void LogBuildError(string message)
{
PrintToConsole($"##vso[task.LogIssue type=error;]{message}{NewLine}", VerbosityMode.Quiet);
this.PrintToConsole($"##vso[task.LogIssue type=error;]{message}{NewLine}", VerbosityMode.Quiet);
}
private void LogFailedProcessingFile(string filePath)
{
LogVerbose($"Could not read component details from file {filePath} {NewLine}");
this.LogVerbose($"Could not read component details from file {filePath} {NewLine}");
}
private void AppendToFile(string text)
{
if (WriteToFile)
if (this.WriteToFile)
{
FileWritingService.AppendToFile(LogRelativePath, text);
this.FileWritingService.AppendToFile(LogRelativePath, text);
}
}
private void PrintToConsole(string text, VerbosityMode minVerbosity)
{
if (Verbosity >= minVerbosity)
if (this.Verbosity >= minVerbosity)
{
ConsoleWriter.Write(text);
this.ConsoleWriter.Write(text);
}
}
}

Просмотреть файл

@ -34,18 +34,18 @@ namespace Microsoft.ComponentDetection.Common
{
get
{
if (!isRunningOnWindowsContainer.HasValue)
if (!this.isRunningOnWindowsContainer.HasValue)
{
lock (isRunningOnWindowsContainerLock)
lock (this.isRunningOnWindowsContainerLock)
{
if (!isRunningOnWindowsContainer.HasValue)
if (!this.isRunningOnWindowsContainer.HasValue)
{
isRunningOnWindowsContainer = CheckIfRunningOnWindowsContainer();
this.isRunningOnWindowsContainer = this.CheckIfRunningOnWindowsContainer();
}
}
}
return isRunningOnWindowsContainer.Value;
return this.isRunningOnWindowsContainer.Value;
}
}
@ -113,11 +113,11 @@ namespace Microsoft.ComponentDetection.Common
{
if (IsWindows)
{
return ResolvePhysicalPathWindows(path);
return this.ResolvePhysicalPathWindows(path);
}
else if (IsLinux)
{
return ResolvePhysicalPathLinux(path);
return this.ResolvePhysicalPathLinux(path);
}
return path;
@ -130,12 +130,12 @@ namespace Microsoft.ComponentDetection.Common
throw new PlatformNotSupportedException("Attempted to call a function that makes windows-only SDK calls");
}
if (IsRunningOnWindowsContainer)
if (this.IsRunningOnWindowsContainer)
{
return path;
}
if (resolvedPaths.TryGetValue(path, out string cachedPath))
if (this.resolvedPaths.TryGetValue(path, out string cachedPath))
{
return cachedPath;
}
@ -168,7 +168,7 @@ namespace Microsoft.ComponentDetection.Common
result = result.StartsWith(LongPathPrefix) ? result.Substring(LongPathPrefix.Length) : result;
resolvedPaths.TryAdd(path, result);
this.resolvedPaths.TryAdd(path, result);
return result;
}
@ -197,7 +197,7 @@ namespace Microsoft.ComponentDetection.Common
}
catch (Exception ex)
{
Logger.LogException(ex, isError: false, printException: true);
this.Logger.LogException(ex, isError: false, printException: true);
return path;
}
finally
@ -244,7 +244,7 @@ namespace Microsoft.ComponentDetection.Common
if (sb.ToString().Contains("Container Execution Agent"))
{
Logger.LogWarning("Detected execution in a Windows container. Currently windows containers < 1809 do not support symlinks well, so disabling symlink resolution/dedupe behavior");
this.Logger.LogWarning("Detected execution in a Windows container. Currently windows containers < 1809 do not support symlinks well, so disabling symlink resolution/dedupe behavior");
return true;
}
else

Просмотреть файл

@ -12,11 +12,11 @@ namespace Microsoft.ComponentDetection.Common
public static FilePatternMatcher GetFilePatternMatcher(IEnumerable<string> patterns)
{
var ordinalComparison = Expression.Constant(System.StringComparison.Ordinal, typeof(System.StringComparison));
var asSpan = typeof(System.MemoryExtensions).GetMethod("AsSpan", BindingFlags.Public | BindingFlags.Static, null, CallingConventions.Standard, new[] { typeof(string) }, new ParameterModifier[0]);
var equals = typeof(System.MemoryExtensions).GetMethod("Equals", BindingFlags.Public | BindingFlags.Static, null, CallingConventions.Standard, new[] { typeof(ReadOnlySpan<char>), typeof(ReadOnlySpan<char>), typeof(System.StringComparison) }, new ParameterModifier[0]);
var startsWith = typeof(System.MemoryExtensions).GetMethod("StartsWith", BindingFlags.Public | BindingFlags.Static, null, CallingConventions.Standard, new[] { typeof(ReadOnlySpan<char>), typeof(ReadOnlySpan<char>), typeof(System.StringComparison) }, new ParameterModifier[0]);
var endsWith = typeof(System.MemoryExtensions).GetMethod("EndsWith", BindingFlags.Public | BindingFlags.Static, null, CallingConventions.Standard, new[] { typeof(ReadOnlySpan<char>), typeof(ReadOnlySpan<char>), typeof(System.StringComparison) }, new ParameterModifier[0]);
var ordinalComparison = Expression.Constant(StringComparison.Ordinal, typeof(StringComparison));
var asSpan = typeof(MemoryExtensions).GetMethod("AsSpan", BindingFlags.Public | BindingFlags.Static, null, CallingConventions.Standard, new[] { typeof(string) }, new ParameterModifier[0]);
var equals = typeof(MemoryExtensions).GetMethod("Equals", BindingFlags.Public | BindingFlags.Static, null, CallingConventions.Standard, new[] { typeof(ReadOnlySpan<char>), typeof(ReadOnlySpan<char>), typeof(StringComparison) }, new ParameterModifier[0]);
var startsWith = typeof(MemoryExtensions).GetMethod("StartsWith", BindingFlags.Public | BindingFlags.Static, null, CallingConventions.Standard, new[] { typeof(ReadOnlySpan<char>), typeof(ReadOnlySpan<char>), typeof(StringComparison) }, new ParameterModifier[0]);
var endsWith = typeof(MemoryExtensions).GetMethod("EndsWith", BindingFlags.Public | BindingFlags.Static, null, CallingConventions.Standard, new[] { typeof(ReadOnlySpan<char>), typeof(ReadOnlySpan<char>), typeof(StringComparison) }, new ParameterModifier[0]);
var predicates = new List<Expression>();
var left = Expression.Parameter(typeof(ReadOnlySpan<char>), "fileName");
@ -53,4 +53,4 @@ namespace Microsoft.ComponentDetection.Common
return func;
}
}
}
}

Просмотреть файл

@ -29,9 +29,9 @@ namespace Microsoft.ComponentDetection.Common
this.directoryExclusionPredicate = directoryExclusionPredicate;
this.recursivelyScanDirectories = recursivelyScanDirectories;
this.pathUtilityService = pathUtilityService;
enumeratedDirectories = previouslyEnumeratedDirectories;
this.enumeratedDirectories = previouslyEnumeratedDirectories;
enumerationOptions = new EnumerationOptions()
this.enumerationOptions = new EnumerationOptions()
{
IgnoreInaccessible = true,
RecurseSubdirectories = this.recursivelyScanDirectories,
@ -48,9 +48,9 @@ namespace Microsoft.ComponentDetection.Common
public IEnumerator<MatchedFile> GetEnumerator()
{
var previouslyEnumeratedDirectories = enumeratedDirectories ?? new HashSet<string>();
var previouslyEnumeratedDirectories = this.enumeratedDirectories ?? new HashSet<string>();
var fse = new FileSystemEnumerable<MatchedFile>(directory.FullName, (ref FileSystemEntry entry) =>
var fse = new FileSystemEnumerable<MatchedFile>(this.directory.FullName, (ref FileSystemEntry entry) =>
{
if (!(entry.ToFileSystemInfo() is FileInfo fi))
{
@ -58,7 +58,7 @@ namespace Microsoft.ComponentDetection.Common
}
var foundPattern = entry.FileName.ToString();
foreach (var searchPattern in searchPatterns)
foreach (var searchPattern in this.searchPatterns)
{
if (PathUtilityService.MatchesPattern(searchPattern, ref entry))
{
@ -67,7 +67,7 @@ namespace Microsoft.ComponentDetection.Common
}
return new MatchedFile() { File = fi, Pattern = foundPattern };
}, enumerationOptions)
}, this.enumerationOptions)
{
ShouldIncludePredicate = (ref FileSystemEntry entry) =>
{
@ -76,7 +76,7 @@ namespace Microsoft.ComponentDetection.Common
return false;
}
foreach (var searchPattern in searchPatterns)
foreach (var searchPattern in this.searchPatterns)
{
if (PathUtilityService.MatchesPattern(searchPattern, ref entry))
{
@ -88,7 +88,7 @@ namespace Microsoft.ComponentDetection.Common
},
ShouldRecursePredicate = (ref FileSystemEntry entry) =>
{
if (!recursivelyScanDirectories)
if (!this.recursivelyScanDirectories)
{
return false;
}
@ -99,7 +99,7 @@ namespace Microsoft.ComponentDetection.Common
if (entry.Attributes.HasFlag(FileAttributes.ReparsePoint))
{
var realPath = pathUtilityService.ResolvePhysicalPath(targetPath);
var realPath = this.pathUtilityService.ResolvePhysicalPath(targetPath);
seenPreviously = previouslyEnumeratedDirectories.Contains(realPath);
previouslyEnumeratedDirectories.Add(realPath);
@ -118,12 +118,12 @@ namespace Microsoft.ComponentDetection.Common
if (seenPreviously)
{
logger.LogVerbose($"Encountered real path {targetPath} before. Short-Circuiting directory traversal");
this.logger.LogVerbose($"Encountered real path {targetPath} before. Short-Circuiting directory traversal");
return false;
}
// This is actually a *directory* name (not FileName) and the directory containing that directory.
if (entry.IsDirectory && directoryExclusionPredicate != null && directoryExclusionPredicate(entry.FileName, entry.Directory))
if (entry.IsDirectory && this.directoryExclusionPredicate != null && this.directoryExclusionPredicate(entry.FileName, entry.Directory))
{
return false;
}
@ -134,7 +134,7 @@ namespace Microsoft.ComponentDetection.Common
foreach (var file in fse)
{
if (fileMatchingPredicate == null || fileMatchingPredicate(file.File))
if (this.fileMatchingPredicate == null || this.fileMatchingPredicate(file.File))
{
yield return file;
}
@ -143,7 +143,7 @@ namespace Microsoft.ComponentDetection.Common
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
return this.GetEnumerator();
}
}
}
}

Просмотреть файл

@ -17,7 +17,7 @@ namespace Microsoft.ComponentDetection.Common
public IEnumerable<MatchedFile> CreateSafeFileEnumerable(DirectoryInfo directory, IEnumerable<string> searchPatterns, ExcludeDirectoryPredicate directoryExclusionPredicate)
{
return new SafeFileEnumerable(directory, searchPatterns, Logger, PathUtilityService, directoryExclusionPredicate);
return new SafeFileEnumerable(directory, searchPatterns, this.Logger, this.PathUtilityService, directoryExclusionPredicate);
}
}
}
}

Просмотреть файл

@ -19,7 +19,7 @@ namespace Microsoft.ComponentDetection.Common
public TabularStringFormat(IList<Column> columns, char horizontalLineChar = DefaultHorizontalLineChar, char verticalLineChar = DefaultVerticalLineChar, string tableTitle = null)
{
this.columns = columns;
totalWidth = columns.Count + 1 + columns.Sum(x => x.Width);
this.totalWidth = columns.Count + 1 + columns.Sum(x => x.Width);
this.horizontalLineChar = horizontalLineChar;
this.verticalLineChar = verticalLineChar;
this.tableTitle = tableTitle;
@ -28,39 +28,39 @@ namespace Microsoft.ComponentDetection.Common
public string GenerateString(IEnumerable<IList<object>> rows)
{
StringBuilder sb = new StringBuilder();
if (!string.IsNullOrWhiteSpace(tableTitle))
if (!string.IsNullOrWhiteSpace(this.tableTitle))
{
PrintTitleSection(sb);
this.PrintTitleSection(sb);
}
else
{
WriteFlatLine(sb, false);
this.WriteFlatLine(sb, false);
}
sb.Append(verticalLineChar);
foreach (var column in columns)
sb.Append(this.verticalLineChar);
foreach (var column in this.columns)
{
sb.Append(column.Header.PadRight(column.Width));
sb.Append(verticalLineChar);
sb.Append(this.verticalLineChar);
}
WriteFlatLine(sb);
this.WriteFlatLine(sb);
foreach (var row in rows)
{
sb.Append(verticalLineChar);
if (row.Count != columns.Count)
sb.Append(this.verticalLineChar);
if (row.Count != this.columns.Count)
{
throw new InvalidOperationException("All rows must have length equal to the number of columns present.");
}
for (var i = 0; i < columns.Count; i++)
for (var i = 0; i < this.columns.Count; i++)
{
var dataString = columns[i].Format != null ? string.Format(columns[i].Format, row[i]) : row[i].ToString();
sb.Append(dataString.PadRight(columns[i].Width));
sb.Append(verticalLineChar);
var dataString = this.columns[i].Format != null ? string.Format(this.columns[i].Format, row[i]) : row[i].ToString();
sb.Append(dataString.PadRight(this.columns[i].Width));
sb.Append(this.verticalLineChar);
}
WriteFlatLine(sb);
this.WriteFlatLine(sb);
}
return sb.ToString();
@ -68,37 +68,37 @@ namespace Microsoft.ComponentDetection.Common
private void PrintTitleSection(StringBuilder sb)
{
WriteFlatLine(sb, false);
var tableWidth = columns.Sum(column => column.Width);
sb.Append(verticalLineChar);
sb.Append(tableTitle.PadRight(tableWidth + columns.Count - 1));
sb.Append(verticalLineChar);
this.WriteFlatLine(sb, false);
var tableWidth = this.columns.Sum(column => column.Width);
sb.Append(this.verticalLineChar);
sb.Append(this.tableTitle.PadRight(tableWidth + this.columns.Count - 1));
sb.Append(this.verticalLineChar);
sb.AppendLine();
sb.Append(verticalLineChar);
for (var i = 0; i < columns.Count - 1; i++)
sb.Append(this.verticalLineChar);
for (var i = 0; i < this.columns.Count - 1; i++)
{
sb.Append(string.Empty.PadRight(columns[i].Width, horizontalLineChar));
sb.Append(horizontalLineChar);
sb.Append(string.Empty.PadRight(this.columns[i].Width, this.horizontalLineChar));
sb.Append(this.horizontalLineChar);
}
sb.Append(string.Empty.PadRight(columns[columns.Count - 1].Width, horizontalLineChar));
sb.Append(verticalLineChar);
sb.Append(string.Empty.PadRight(this.columns[this.columns.Count - 1].Width, this.horizontalLineChar));
sb.Append(this.verticalLineChar);
sb.AppendLine();
}
private void WriteFlatLine(StringBuilder sb, bool withPipes = true)
{
var splitCharacter = withPipes ? verticalLineChar : horizontalLineChar;
var splitCharacter = withPipes ? this.verticalLineChar : this.horizontalLineChar;
sb.AppendLine();
sb.Append(splitCharacter);
for (var i = 0; i < columns.Count; i++)
for (var i = 0; i < this.columns.Count; i++)
{
sb.Append(string.Empty.PadRight(columns[i].Width, horizontalLineChar));
sb.Append(string.Empty.PadRight(this.columns[i].Width, this.horizontalLineChar));
sb.Append(splitCharacter);
}
sb.AppendLine();
}
}
}
}

Просмотреть файл

@ -8,7 +8,7 @@ namespace Microsoft.ComponentDetection.Common.Telemetry.Attributes
public TelemetryServiceAttribute(string serviceType)
{
ServiceType = serviceType;
this.ServiceType = serviceType;
}
}
}

Просмотреть файл

@ -27,12 +27,12 @@ namespace Microsoft.ComponentDetection.Common.Telemetry
public void Flush()
{
FileWritingService.WriteFile(TelemetryRelativePath, JsonConvert.SerializeObject(records));
this.FileWritingService.WriteFile(TelemetryRelativePath, JsonConvert.SerializeObject(records));
}
public void PostRecord(IDetectionTelemetryRecord record)
{
if (telemetryMode != TelemetryMode.Disabled)
if (this.telemetryMode != TelemetryMode.Disabled)
{
var jsonRecord = JObject.FromObject(record);
jsonRecord.Add("Timestamp", DateTime.UtcNow);
@ -40,16 +40,16 @@ namespace Microsoft.ComponentDetection.Common.Telemetry
records.Enqueue(jsonRecord);
if (telemetryMode == TelemetryMode.Debug)
if (this.telemetryMode == TelemetryMode.Debug)
{
Logger.LogInfo(jsonRecord.ToString());
this.Logger.LogInfo(jsonRecord.ToString());
}
}
}
public void SetMode(TelemetryMode mode)
{
telemetryMode = mode;
this.telemetryMode = mode;
}
}
}

Просмотреть файл

@ -15,15 +15,15 @@ namespace Microsoft.ComponentDetection.Common.Telemetry.Records
protected BaseDetectionTelemetryRecord()
{
stopwatch.Start();
this.stopwatch.Start();
}
public void StopExecutionTimer()
{
if (stopwatch.IsRunning)
if (this.stopwatch.IsRunning)
{
stopwatch.Stop();
ExecutionTime = stopwatch.Elapsed;
this.stopwatch.Stop();
this.ExecutionTime = this.stopwatch.Elapsed;
}
}
@ -31,21 +31,21 @@ namespace Microsoft.ComponentDetection.Common.Telemetry.Records
protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
if (!this.disposedValue)
{
if (disposing)
{
StopExecutionTimer();
this.StopExecutionTimer();
TelemetryRelay.Instance.PostTelemetryRecord(this);
}
disposedValue = true;
this.disposedValue = true;
}
}
public void Dispose()
{
Dispose(true);
this.Dispose(true);
}
}
}

Просмотреть файл

@ -19,23 +19,23 @@ namespace Microsoft.ComponentDetection.Common.Telemetry.Records
internal void Track(CommandLineExecutionResult result, string path, string parameters)
{
ExitCode = result.ExitCode;
StandardError = result.StdErr;
TrackCommon(path, parameters);
this.ExitCode = result.ExitCode;
this.StandardError = result.StdErr;
this.TrackCommon(path, parameters);
}
internal void Track(Exception ex, string path, string parameters)
{
ExitCode = -1;
UnhandledException = ex.ToString();
TrackCommon(path, parameters);
this.ExitCode = -1;
this.UnhandledException = ex.ToString();
this.TrackCommon(path, parameters);
}
private void TrackCommon(string path, string parameters)
{
PathThatWasRan = path;
Parameters = parameters;
StopExecutionTimer();
this.PathThatWasRan = path;
this.Parameters = parameters;
this.StopExecutionTimer();
}
}
}

Просмотреть файл

@ -11,7 +11,7 @@ namespace Microsoft.ComponentDetection.Common.Telemetry.Records
[MethodImpl(MethodImplOptions.Synchronized)]
public void IncrementProvidedScopeCount()
{
MavenProvidedScopeCount++;
this.MavenProvidedScopeCount++;
}
}
}

Просмотреть файл

@ -16,20 +16,20 @@ namespace Microsoft.ComponentDetection.Common.Telemetry.Records
protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
if (!this.disposedValue)
{
if (disposing)
{
TelemetryRelay.Instance.PostTelemetryRecord(this);
}
disposedValue = true;
this.disposedValue = true;
}
}
public void Dispose()
{
Dispose(true);
this.Dispose(true);
}
}
}

Просмотреть файл

@ -39,7 +39,7 @@ namespace Microsoft.ComponentDetection.Contracts.BcdeModels
JToken jo = JToken.Load(reader);
var value = (ComponentType)Enum.Parse(typeof(ComponentType), (string)jo["type"]);
var targetType = componentTypesToTypes[value];
var targetType = this.componentTypesToTypes[value];
var instanceOfTypedComponent = Activator.CreateInstance(targetType, true);
serializer.Populate(jo.CreateReader(), instanceOfTypedComponent);

Просмотреть файл

@ -17,22 +17,22 @@ namespace Microsoft.ComponentDetection.Contracts
/// <param name="containerLayerId">Id of the layer the component was found, this is only necessary if the component was found inside a container.</param>
public DetectedComponent(TypedComponent.TypedComponent component, IComponentDetector detector = null, int? containerDetailsId = null, int? containerLayerId = null)
{
Component = component;
FilePaths = new HashSet<string>();
DetectedBy = detector;
ContainerDetailIds = new HashSet<int>();
ContainerLayerIds = new Dictionary<int, IEnumerable<int>>();
this.Component = component;
this.FilePaths = new HashSet<string>();
this.DetectedBy = detector;
this.ContainerDetailIds = new HashSet<int>();
this.ContainerLayerIds = new Dictionary<int, IEnumerable<int>>();
if (containerDetailsId.HasValue)
{
ContainerDetailIds.Add(containerDetailsId.Value);
this.ContainerDetailIds.Add(containerDetailsId.Value);
if (containerLayerId.HasValue)
{
ContainerLayerIds.Add(containerDetailsId.Value, new List<int>() { containerLayerId.Value });
this.ContainerLayerIds.Add(containerDetailsId.Value, new List<int>() { containerLayerId.Value });
}
}
}
private string DebuggerDisplay => $"{Component.DebuggerDisplay}";
private string DebuggerDisplay => $"{this.Component.DebuggerDisplay}";
/// <summary>
/// Gets or sets the detector that detected this component.
@ -65,9 +65,9 @@ namespace Microsoft.ComponentDetection.Contracts
/// <param name="filePath">The file path to add to the hashset.</param>
public void AddComponentFilePath(string filePath)
{
lock (hashLock)
lock (this.hashLock)
{
FilePaths.Add(filePath);
this.FilePaths.Add(filePath);
}
}
}

Просмотреть файл

@ -97,14 +97,14 @@ namespace Microsoft.ComponentDetection.Contracts
public override string ToString()
{
return $"{Digest}";
return $"{this.Digest}";
}
public override TypedComponent.DockerReferenceComponent ToTypedDockerReferenceComponent()
{
return new TypedComponent.DockerReferenceComponent(this)
{
Digest = Digest,
Digest = this.Digest,
};
}
}
@ -122,16 +122,16 @@ namespace Microsoft.ComponentDetection.Contracts
public override string ToString()
{
return $"{Domain}/{Repository}@${Digest}";
return $"{this.Domain}/{this.Repository}@${this.Digest}";
}
public override TypedComponent.DockerReferenceComponent ToTypedDockerReferenceComponent()
{
return new TypedComponent.DockerReferenceComponent(this)
{
Domain = Domain,
Digest = Digest,
Repository = Repository,
Domain = this.Domain,
Digest = this.Digest,
Repository = this.Repository,
};
}
}
@ -147,15 +147,15 @@ namespace Microsoft.ComponentDetection.Contracts
public override string ToString()
{
return $"{Repository}";
return $"{this.Repository}";
}
public override TypedComponent.DockerReferenceComponent ToTypedDockerReferenceComponent()
{
return new TypedComponent.DockerReferenceComponent(this)
{
Domain = Domain,
Repository = Repository,
Domain = this.Domain,
Repository = this.Repository,
};
}
}
@ -173,16 +173,16 @@ namespace Microsoft.ComponentDetection.Contracts
public override string ToString()
{
return $"{Domain}/{Repository}:${Tag}";
return $"{this.Domain}/{this.Repository}:${this.Tag}";
}
public override TypedComponent.DockerReferenceComponent ToTypedDockerReferenceComponent()
{
return new TypedComponent.DockerReferenceComponent(this)
{
Domain = Domain,
Tag = Tag,
Repository = Repository,
Domain = this.Domain,
Tag = this.Tag,
Repository = this.Repository,
};
}
}
@ -202,18 +202,18 @@ namespace Microsoft.ComponentDetection.Contracts
public override string ToString()
{
return $"{Domain}/{Repository}:${Tag}@${Digest}";
return $"{this.Domain}/{this.Repository}:${this.Tag}@${this.Digest}";
}
public override TypedComponent.DockerReferenceComponent ToTypedDockerReferenceComponent()
{
return new TypedComponent.DockerReferenceComponent(this)
{
Domain = Domain,
Digest = Digest,
Tag = Tag,
Repository = Repository,
Domain = this.Domain,
Digest = this.Digest,
Tag = this.Tag,
Repository = this.Repository,
};
}
}
}
}

Просмотреть файл

@ -63,20 +63,20 @@ namespace Microsoft.ComponentDetection.Contracts
/// <inheritdoc />
public async virtual Task<IndividualDetectorScanResult> ExecuteDetectorAsync(ScanRequest request)
{
ComponentRecorder = request.ComponentRecorder;
Scanner.Initialize(request.SourceDirectory, request.DirectoryExclusionPredicate, 1);
return await ScanDirectoryAsync(request);
this.ComponentRecorder = request.ComponentRecorder;
this.Scanner.Initialize(request.SourceDirectory, request.DirectoryExclusionPredicate, 1);
return await this.ScanDirectoryAsync(request);
}
/// <inheritdoc />
private Task<IndividualDetectorScanResult> ScanDirectoryAsync(ScanRequest request)
{
CurrentScanRequest = request;
this.CurrentScanRequest = request;
var filteredObservable = Scanner.GetFilteredComponentStreamObservable(request.SourceDirectory, SearchPatterns, request.ComponentRecorder);
var filteredObservable = this.Scanner.GetFilteredComponentStreamObservable(request.SourceDirectory, this.SearchPatterns, request.ComponentRecorder);
Logger?.LogVerbose($"Registered {GetType().FullName}");
return ProcessAsync(filteredObservable, request.DetectorArgs);
this.Logger?.LogVerbose($"Registered {this.GetType().FullName}");
return this.ProcessAsync(filteredObservable, request.DetectorArgs);
}
/// <summary>
@ -87,14 +87,14 @@ namespace Microsoft.ComponentDetection.Contracts
/// <returns></returns>
protected Task<IEnumerable<IComponentStream>> GetFileStreamsAsync(DirectoryInfo sourceDirectory, ExcludeDirectoryPredicate exclusionPredicate)
{
return Task.FromResult(ComponentStreamEnumerableFactory.GetComponentStreams(sourceDirectory, SearchPatterns, exclusionPredicate));
return Task.FromResult(this.ComponentStreamEnumerableFactory.GetComponentStreams(sourceDirectory, this.SearchPatterns, exclusionPredicate));
}
private async Task<IndividualDetectorScanResult> ProcessAsync(IObservable<ProcessRequest> processRequests, IDictionary<string, string> detectorArgs)
{
var processor = new ActionBlock<ProcessRequest>(async processRequest => await OnFileFound(processRequest, detectorArgs));
var processor = new ActionBlock<ProcessRequest>(async processRequest => await this.OnFileFound(processRequest, detectorArgs));
var preprocessedObserbable = await OnPrepareDetection(processRequests, detectorArgs);
var preprocessedObserbable = await this.OnPrepareDetection(processRequests, detectorArgs);
await preprocessedObserbable.ForEachAsync(processRequest => processor.Post(processRequest));
@ -102,12 +102,12 @@ namespace Microsoft.ComponentDetection.Contracts
await processor.Completion;
await OnDetectionFinished();
await this.OnDetectionFinished();
return new IndividualDetectorScanResult
{
ResultCode = ProcessingResultCode.Success,
AdditionalTelemetryDetails = Telemetry,
AdditionalTelemetryDetails = this.Telemetry,
};
}
@ -123,4 +123,4 @@ namespace Microsoft.ComponentDetection.Contracts
return Task.CompletedTask;
}
}
}
}

Просмотреть файл

@ -6,8 +6,8 @@ namespace Microsoft.ComponentDetection.Contracts.Internal
{
public NpmAuthor(string name, string email = null)
{
Name = name ?? throw new ArgumentNullException(nameof(name));
Email = string.IsNullOrEmpty(email) ? null : email;
this.Name = name ?? throw new ArgumentNullException(nameof(name));
this.Email = string.IsNullOrEmpty(email) ? null : email;
}
public string Name { get; set; }

Просмотреть файл

@ -15,11 +15,11 @@ namespace Microsoft.ComponentDetection.Contracts
/// <param name="componentRecorder">Detector component recorder.</param>
public ScanRequest(DirectoryInfo sourceDirectory, ExcludeDirectoryPredicate directoryExclusionPredicate, ILogger logger, IDictionary<string, string> detectorArgs, IEnumerable<string> imagesToScan, IComponentRecorder componentRecorder)
{
SourceDirectory = sourceDirectory;
DirectoryExclusionPredicate = directoryExclusionPredicate;
DetectorArgs = detectorArgs;
ImagesToScan = imagesToScan;
ComponentRecorder = componentRecorder;
this.SourceDirectory = sourceDirectory;
this.DirectoryExclusionPredicate = directoryExclusionPredicate;
this.DetectorArgs = detectorArgs;
this.ImagesToScan = imagesToScan;
this.ComponentRecorder = componentRecorder;
}
/// <summary> Gets the source directory to consider the working directory for the detection operation.</summary>

Просмотреть файл

@ -11,8 +11,8 @@ namespace Microsoft.ComponentDetection.Contracts.TypedComponent
public CargoComponent(string name, string version)
{
Name = ValidateRequiredInput(name, nameof(Name), nameof(ComponentType.Cargo));
Version = ValidateRequiredInput(version, nameof(Version), nameof(ComponentType.Cargo));
this.Name = this.ValidateRequiredInput(name, nameof(this.Name), nameof(ComponentType.Cargo));
this.Version = this.ValidateRequiredInput(version, nameof(this.Version), nameof(ComponentType.Cargo));
}
public string Name { get; set; }
@ -21,8 +21,8 @@ namespace Microsoft.ComponentDetection.Contracts.TypedComponent
public override ComponentType Type => ComponentType.Cargo;
public override string Id => $"{Name} {Version} - {Type}";
public override string Id => $"{this.Name} {this.Version} - {this.Type}";
public override PackageURL PackageUrl => new PackageURL("cargo", string.Empty, Name, Version, null, string.Empty);
public override PackageURL PackageUrl => new PackageURL("cargo", string.Empty, this.Name, this.Version, null, string.Empty);
}
}

Просмотреть файл

@ -9,14 +9,14 @@
public CondaComponent(string name, string version, string build, string channel, string subdir, string @namespace, string url, string md5)
{
Name = ValidateRequiredInput(name, nameof(Name), nameof(ComponentType.Conda));
Version = ValidateRequiredInput(version, nameof(Version), nameof(ComponentType.Conda));
Build = build;
Channel = channel;
Subdir = subdir;
Namespace = @namespace;
Url = url;
MD5 = md5;
this.Name = this.ValidateRequiredInput(name, nameof(this.Name), nameof(ComponentType.Conda));
this.Version = this.ValidateRequiredInput(version, nameof(this.Version), nameof(ComponentType.Conda));
this.Build = build;
this.Channel = channel;
this.Subdir = subdir;
this.Namespace = @namespace;
this.Url = url;
this.MD5 = md5;
}
public string Build { get; set; }
@ -37,6 +37,6 @@
public override ComponentType Type => ComponentType.Conda;
public override string Id => $"{Name} {Version} {Build} {Channel} {Subdir} {Namespace} {Url} {MD5} - {Type}";
public override string Id => $"{this.Name} {this.Version} {this.Build} {this.Channel} {this.Subdir} {this.Namespace} {this.Url} {this.MD5} - {this.Type}";
}
}

Просмотреть файл

@ -9,9 +9,9 @@ namespace Microsoft.ComponentDetection.Contracts.TypedComponent
public DockerImageComponent(string hash, string name = null, string tag = null)
{
Digest = ValidateRequiredInput(hash, nameof(Digest), nameof(ComponentType.DockerImage));
Name = name;
Tag = tag;
this.Digest = this.ValidateRequiredInput(hash, nameof(this.Digest), nameof(ComponentType.DockerImage));
this.Name = name;
this.Tag = tag;
}
public string Name { get; set; }
@ -22,6 +22,6 @@ namespace Microsoft.ComponentDetection.Contracts.TypedComponent
public override ComponentType Type => ComponentType.DockerImage;
public override string Id => $"{Name} {Tag} {Digest}";
public override string Id => $"{this.Name} {this.Tag} {this.Digest}";
}
}

Просмотреть файл

@ -9,9 +9,9 @@ namespace Microsoft.ComponentDetection.Contracts.TypedComponent
public DockerReferenceComponent(string hash, string repository = null, string tag = null)
{
Digest = ValidateRequiredInput(hash, nameof(Digest), nameof(ComponentType.DockerReference));
Repository = repository;
Tag = tag;
this.Digest = this.ValidateRequiredInput(hash, nameof(this.Digest), nameof(ComponentType.DockerReference));
this.Repository = repository;
this.Tag = tag;
}
public DockerReferenceComponent(DockerReference reference)
@ -32,10 +32,10 @@ namespace Microsoft.ComponentDetection.Contracts.TypedComponent
{
get
{
return DockerReference.CreateDockerReference(Repository, Domain, Digest, Tag);
return DockerReference.CreateDockerReference(this.Repository, this.Domain, this.Digest, this.Tag);
}
}
public override string Id => $"{Repository} {Tag} {Digest}";
public override string Id => $"{this.Repository} {this.Tag} {this.Digest}";
}
}
}

Просмотреть файл

@ -11,14 +11,14 @@ namespace Microsoft.ComponentDetection.Contracts.TypedComponent
public GitComponent(Uri repositoryUrl, string commitHash)
{
RepositoryUrl = ValidateRequiredInput(repositoryUrl, nameof(RepositoryUrl), nameof(ComponentType.Git));
CommitHash = ValidateRequiredInput(commitHash, nameof(CommitHash), nameof(ComponentType.Git));
this.RepositoryUrl = this.ValidateRequiredInput(repositoryUrl, nameof(this.RepositoryUrl), nameof(ComponentType.Git));
this.CommitHash = this.ValidateRequiredInput(commitHash, nameof(this.CommitHash), nameof(ComponentType.Git));
}
public GitComponent(Uri repositoryUrl, string commitHash, string tag)
: this(repositoryUrl, commitHash)
{
Tag = tag;
this.Tag = tag;
}
public Uri RepositoryUrl { get; set; }
@ -29,6 +29,6 @@ namespace Microsoft.ComponentDetection.Contracts.TypedComponent
public override ComponentType Type => ComponentType.Git;
public override string Id => $"{RepositoryUrl} : {CommitHash} - {Type}";
public override string Id => $"{this.RepositoryUrl} : {this.CommitHash} - {this.Type}";
}
}

Просмотреть файл

@ -12,16 +12,16 @@ namespace Microsoft.ComponentDetection.Contracts.TypedComponent
public GoComponent(string name, string version)
{
Name = ValidateRequiredInput(name, nameof(Name), nameof(ComponentType.Go));
Version = ValidateRequiredInput(version, nameof(Version), nameof(ComponentType.Go));
Hash = string.Empty;
this.Name = this.ValidateRequiredInput(name, nameof(this.Name), nameof(ComponentType.Go));
this.Version = this.ValidateRequiredInput(version, nameof(this.Version), nameof(ComponentType.Go));
this.Hash = string.Empty;
}
public GoComponent(string name, string version, string hash)
{
Name = ValidateRequiredInput(name, nameof(Name), nameof(ComponentType.Go));
Version = ValidateRequiredInput(version, nameof(Version), nameof(ComponentType.Go));
Hash = ValidateRequiredInput(hash, nameof(Hash), nameof(ComponentType.Go));
this.Name = this.ValidateRequiredInput(name, nameof(this.Name), nameof(ComponentType.Go));
this.Version = this.ValidateRequiredInput(version, nameof(this.Version), nameof(ComponentType.Go));
this.Hash = this.ValidateRequiredInput(hash, nameof(this.Hash), nameof(ComponentType.Go));
}
public string Name { get; set; }
@ -32,12 +32,12 @@ namespace Microsoft.ComponentDetection.Contracts.TypedComponent
public override ComponentType Type => ComponentType.Go;
public override string Id => $"{Name} {Version} - {Type}";
public override string Id => $"{this.Name} {this.Version} - {this.Type}";
public override bool Equals(object other)
{
GoComponent otherComponent = other as GoComponent;
return otherComponent != null && Equals(otherComponent);
return otherComponent != null && this.Equals(otherComponent);
}
public bool Equals(GoComponent other)
@ -47,18 +47,16 @@ namespace Microsoft.ComponentDetection.Contracts.TypedComponent
return false;
}
return Name == other.Name &&
Version == other.Version &&
Hash == other.Hash;
return this.Name == other.Name && this.Version == other.Version && this.Hash == other.Hash;
}
public override int GetHashCode()
{
return Name.GetHashCode() ^ Version.GetHashCode() ^ Hash.GetHashCode();
return this.Name.GetHashCode() ^ this.Version.GetHashCode() ^ this.Hash.GetHashCode();
}
// Commit should be used in place of version when available
// https://github.com/package-url/purl-spec/blame/180c46d266c45aa2bd81a2038af3f78e87bb4a25/README.rst#L610
public override PackageURL PackageUrl => new PackageURL("golang", null, Name, string.IsNullOrWhiteSpace(Hash) ? Version : Hash, null, null);
public override PackageURL PackageUrl => new PackageURL("golang", null, this.Name, string.IsNullOrWhiteSpace(this.Hash) ? this.Version : this.Hash, null, null);
}
}

Просмотреть файл

@ -11,10 +11,10 @@ namespace Microsoft.ComponentDetection.Contracts.TypedComponent
public LinuxComponent(string distribution, string release, string name, string version)
{
Distribution = ValidateRequiredInput(distribution, nameof(Distribution), nameof(ComponentType.Linux));
Release = ValidateRequiredInput(release, nameof(Release), nameof(ComponentType.Linux));
Name = ValidateRequiredInput(name, nameof(Name), nameof(ComponentType.Linux));
Version = ValidateRequiredInput(version, nameof(Version), nameof(ComponentType.Linux));
this.Distribution = this.ValidateRequiredInput(distribution, nameof(this.Distribution), nameof(ComponentType.Linux));
this.Release = this.ValidateRequiredInput(release, nameof(this.Release), nameof(ComponentType.Linux));
this.Name = this.ValidateRequiredInput(name, nameof(this.Name), nameof(ComponentType.Linux));
this.Version = this.ValidateRequiredInput(version, nameof(this.Version), nameof(ComponentType.Linux));
}
public string Distribution { get; set; }
@ -27,7 +27,7 @@ namespace Microsoft.ComponentDetection.Contracts.TypedComponent
public override ComponentType Type => ComponentType.Linux;
public override string Id => $"{Distribution} {Release} {Name} {Version} - {Type}";
public override string Id => $"{this.Distribution} {this.Release} {this.Name} {this.Version} - {this.Type}";
public override PackageURL PackageUrl
{
@ -35,18 +35,18 @@ namespace Microsoft.ComponentDetection.Contracts.TypedComponent
{
string packageType = null;
if (IsUbuntu() || IsDebian())
if (this.IsUbuntu() || this.IsDebian())
{
packageType = "deb";
}
else if (IsCentOS() || IsFedora() || IsRHEL())
else if (this.IsCentOS() || this.IsFedora() || this.IsRHEL())
{
packageType = "rpm";
}
if (packageType != null)
{
return new PackageURL(packageType, Distribution, Name, Version, null, null);
return new PackageURL(packageType, this.Distribution, this.Name, this.Version, null, null);
}
return null;
@ -55,27 +55,27 @@ namespace Microsoft.ComponentDetection.Contracts.TypedComponent
private bool IsUbuntu()
{
return Distribution.ToLowerInvariant() == "ubuntu";
return this.Distribution.ToLowerInvariant() == "ubuntu";
}
private bool IsDebian()
{
return Distribution.ToLowerInvariant() == "debian";
return this.Distribution.ToLowerInvariant() == "debian";
}
private bool IsCentOS()
{
return Distribution.ToLowerInvariant() == "centos";
return this.Distribution.ToLowerInvariant() == "centos";
}
private bool IsFedora()
{
return Distribution.ToLowerInvariant() == "fedora";
return this.Distribution.ToLowerInvariant() == "fedora";
}
private bool IsRHEL()
{
return Distribution.ToLowerInvariant() == "red hat enterprise linux";
return this.Distribution.ToLowerInvariant() == "red hat enterprise linux";
}
}
}

Просмотреть файл

@ -11,9 +11,9 @@ namespace Microsoft.ComponentDetection.Contracts.TypedComponent
public MavenComponent(string groupId, string artifactId, string version)
{
GroupId = ValidateRequiredInput(groupId, nameof(GroupId), nameof(ComponentType.Maven));
ArtifactId = ValidateRequiredInput(artifactId, nameof(ArtifactId), nameof(ComponentType.Maven));
Version = ValidateRequiredInput(version, nameof(Version), nameof(ComponentType.Maven));
this.GroupId = this.ValidateRequiredInput(groupId, nameof(this.GroupId), nameof(ComponentType.Maven));
this.ArtifactId = this.ValidateRequiredInput(artifactId, nameof(this.ArtifactId), nameof(ComponentType.Maven));
this.Version = this.ValidateRequiredInput(version, nameof(this.Version), nameof(ComponentType.Maven));
}
public string GroupId { get; set; }
@ -24,8 +24,8 @@ namespace Microsoft.ComponentDetection.Contracts.TypedComponent
public override ComponentType Type => ComponentType.Maven;
public override string Id => $"{GroupId} {ArtifactId} {Version} - {Type}";
public override string Id => $"{this.GroupId} {this.ArtifactId} {this.Version} - {this.Type}";
public override PackageURL PackageUrl => new PackageURL("maven", GroupId, ArtifactId, Version, null, null);
public override PackageURL PackageUrl => new PackageURL("maven", this.GroupId, this.ArtifactId, this.Version, null, null);
}
}

Просмотреть файл

@ -12,10 +12,10 @@ namespace Microsoft.ComponentDetection.Contracts.TypedComponent
public NpmComponent(string name, string version, string hash = null, NpmAuthor author = null)
{
Name = ValidateRequiredInput(name, nameof(Name), nameof(ComponentType.Npm));
Version = ValidateRequiredInput(version, nameof(Version), nameof(ComponentType.Npm));
Hash = hash; // Not required; only found in package-lock.json, not package.json
Author = author;
this.Name = this.ValidateRequiredInput(name, nameof(this.Name), nameof(ComponentType.Npm));
this.Version = this.ValidateRequiredInput(version, nameof(this.Version), nameof(ComponentType.Npm));
this.Hash = hash; // Not required; only found in package-lock.json, not package.json
this.Author = author;
}
public string Name { get; set; }
@ -28,8 +28,8 @@ namespace Microsoft.ComponentDetection.Contracts.TypedComponent
public override ComponentType Type => ComponentType.Npm;
public override string Id => $"{Name} {Version} - {Type}";
public override string Id => $"{this.Name} {this.Version} - {this.Type}";
public override PackageURL PackageUrl => new PackageURL("npm", null, Name, Version, null, null);
public override PackageURL PackageUrl => new PackageURL("npm", null, this.Name, this.Version, null, null);
}
}

Просмотреть файл

@ -11,9 +11,9 @@ namespace Microsoft.ComponentDetection.Contracts.TypedComponent
public NuGetComponent(string name, string version, string[] authors = null)
{
Name = ValidateRequiredInput(name, nameof(Name), nameof(ComponentType.NuGet));
Version = ValidateRequiredInput(version, nameof(Version), nameof(ComponentType.NuGet));
Authors = authors;
this.Name = this.ValidateRequiredInput(name, nameof(this.Name), nameof(ComponentType.NuGet));
this.Version = this.ValidateRequiredInput(version, nameof(this.Version), nameof(ComponentType.NuGet));
this.Authors = authors;
}
public string Name { get; set; }
@ -24,8 +24,8 @@ namespace Microsoft.ComponentDetection.Contracts.TypedComponent
public override ComponentType Type => ComponentType.NuGet;
public override string Id => $"{Name} {Version} - {Type}";
public override string Id => $"{this.Name} {this.Version} - {this.Type}";
public override PackageURL PackageUrl => new PackageURL("nuget", null, Name, Version, null, null);
public override PackageURL PackageUrl => new PackageURL("nuget", null, this.Name, this.Version, null, null);
}
}

Просмотреть файл

@ -11,10 +11,10 @@ namespace Microsoft.ComponentDetection.Contracts.TypedComponent
public OtherComponent(string name, string version, Uri downloadUrl, string hash)
{
Name = ValidateRequiredInput(name, nameof(Name), nameof(ComponentType.Other));
Version = ValidateRequiredInput(version, nameof(Version), nameof(ComponentType.Other));
DownloadUrl = ValidateRequiredInput(downloadUrl, nameof(DownloadUrl), nameof(ComponentType.Other));
Hash = hash;
this.Name = this.ValidateRequiredInput(name, nameof(this.Name), nameof(ComponentType.Other));
this.Version = this.ValidateRequiredInput(version, nameof(this.Version), nameof(ComponentType.Other));
this.DownloadUrl = this.ValidateRequiredInput(downloadUrl, nameof(this.DownloadUrl), nameof(ComponentType.Other));
this.Hash = hash;
}
public string Name { get; set; }
@ -27,6 +27,6 @@ namespace Microsoft.ComponentDetection.Contracts.TypedComponent
public override ComponentType Type => ComponentType.Other;
public override string Id => $"{Name} {Version} {DownloadUrl} - {Type}";
public override string Id => $"{this.Name} {this.Version} {this.DownloadUrl} - {this.Type}";
}
}
}

Просмотреть файл

@ -11,8 +11,8 @@ namespace Microsoft.ComponentDetection.Contracts.TypedComponent
public PipComponent(string name, string version)
{
Name = ValidateRequiredInput(name, nameof(Name), nameof(ComponentType.Pip));
Version = ValidateRequiredInput(version, nameof(Version), nameof(ComponentType.Pip));
this.Name = this.ValidateRequiredInput(name, nameof(this.Name), nameof(ComponentType.Pip));
this.Version = this.ValidateRequiredInput(version, nameof(this.Version), nameof(ComponentType.Pip));
}
public string Name { get; set; }
@ -21,8 +21,8 @@ namespace Microsoft.ComponentDetection.Contracts.TypedComponent
public override ComponentType Type => ComponentType.Pip;
public override string Id => $"{Name} {Version} - {Type}".ToLowerInvariant();
public override string Id => $"{this.Name} {this.Version} - {this.Type}".ToLowerInvariant();
public override PackageURL PackageUrl => new PackageURL("pypi", null, Name, Version, null, null);
public override PackageURL PackageUrl => new PackageURL("pypi", null, this.Name, this.Version, null, null);
}
}

Просмотреть файл

@ -12,9 +12,9 @@ namespace Microsoft.ComponentDetection.Contracts.TypedComponent
public PodComponent(string name, string version, string specRepo = "")
{
Name = ValidateRequiredInput(name, nameof(Name), nameof(ComponentType.Pod));
Version = ValidateRequiredInput(version, nameof(Version), nameof(ComponentType.Pod));
SpecRepo = specRepo;
this.Name = this.ValidateRequiredInput(name, nameof(this.Name), nameof(ComponentType.Pod));
this.Version = this.ValidateRequiredInput(version, nameof(this.Version), nameof(ComponentType.Pod));
this.SpecRepo = specRepo;
}
public string Name { get; set; }
@ -25,19 +25,19 @@ namespace Microsoft.ComponentDetection.Contracts.TypedComponent
public override ComponentType Type => ComponentType.Pod;
public override string Id => $"{Name} {Version} - {Type}";
public override string Id => $"{this.Name} {this.Version} - {this.Type}";
public override PackageURL PackageUrl
{
get
{
var qualifiers = new SortedDictionary<string, string>();
if (!string.IsNullOrWhiteSpace(SpecRepo))
if (!string.IsNullOrWhiteSpace(this.SpecRepo))
{
qualifiers.Add("repository_url", SpecRepo);
qualifiers.Add("repository_url", this.SpecRepo);
}
return new PackageURL("cocoapods", null, Name, Version, qualifiers, null);
return new PackageURL("cocoapods", null, this.Name, this.Version, qualifiers, null);
}
}
}

Просмотреть файл

@ -11,9 +11,9 @@ namespace Microsoft.ComponentDetection.Contracts.TypedComponent
public RubyGemsComponent(string name, string version, string source = "")
{
Name = ValidateRequiredInput(name, nameof(Name), nameof(ComponentType.RubyGems));
Version = ValidateRequiredInput(version, nameof(Version), nameof(ComponentType.RubyGems));
Source = source;
this.Name = this.ValidateRequiredInput(name, nameof(this.Name), nameof(ComponentType.RubyGems));
this.Version = this.ValidateRequiredInput(version, nameof(this.Version), nameof(ComponentType.RubyGems));
this.Source = source;
}
public string Name { get; set; }
@ -24,8 +24,8 @@ namespace Microsoft.ComponentDetection.Contracts.TypedComponent
public override ComponentType Type => ComponentType.RubyGems;
public override string Id => $"{Name} {Version} - {Type}";
public override string Id => $"{this.Name} {this.Version} - {this.Type}";
public override PackageURL PackageUrl => new PackageURL("gem", null, Name, Version, null, null);
public override PackageURL PackageUrl => new PackageURL("gem", null, this.Name, this.Version, null, null);
}
}

Просмотреть файл

@ -12,13 +12,12 @@ namespace Microsoft.ComponentDetection.Contracts.TypedComponent
public SpdxComponent(string spdxVersion, Uri documentNamespace, string name, string checksum,
string rootElementId, string path)
{
SpdxVersion = ValidateRequiredInput(spdxVersion, nameof(SpdxVersion), nameof(ComponentType.Spdx));
DocumentNamespace =
ValidateRequiredInput(documentNamespace, nameof(DocumentNamespace), nameof(ComponentType.Spdx));
Name = ValidateRequiredInput(name, nameof(Name), nameof(ComponentType.Spdx));
Checksum = ValidateRequiredInput(checksum, nameof(Checksum), nameof(ComponentType.Spdx));
RootElementId = ValidateRequiredInput(rootElementId, nameof(RootElementId), nameof(ComponentType.Spdx));
Path = ValidateRequiredInput(path, nameof(Path), nameof(ComponentType.Spdx));
this.SpdxVersion = this.ValidateRequiredInput(spdxVersion, nameof(this.SpdxVersion), nameof(ComponentType.Spdx));
this.DocumentNamespace = this.ValidateRequiredInput(documentNamespace, nameof(this.DocumentNamespace), nameof(ComponentType.Spdx));
this.Name = this.ValidateRequiredInput(name, nameof(this.Name), nameof(ComponentType.Spdx));
this.Checksum = this.ValidateRequiredInput(checksum, nameof(this.Checksum), nameof(ComponentType.Spdx));
this.RootElementId = this.ValidateRequiredInput(rootElementId, nameof(this.RootElementId), nameof(ComponentType.Spdx));
this.Path = this.ValidateRequiredInput(path, nameof(this.Path), nameof(ComponentType.Spdx));
}
public override ComponentType Type => ComponentType.Spdx;
@ -35,6 +34,6 @@ namespace Microsoft.ComponentDetection.Contracts.TypedComponent
public string Path { get; }
public override string Id => $"{Name}-{SpdxVersion}-{Checksum}";
public override string Id => $"{this.Name}-{this.SpdxVersion}-{this.Checksum}";
}
}
}

Просмотреть файл

@ -28,19 +28,19 @@ namespace Microsoft.ComponentDetection.Contracts.TypedComponent
public virtual PackageURL PackageUrl { get; }
[JsonIgnore]
internal string DebuggerDisplay => $"{Id}";
internal string DebuggerDisplay => $"{this.Id}";
protected string ValidateRequiredInput(string input, string fieldName, string componentType)
{
return string.IsNullOrWhiteSpace(input)
? throw new ArgumentNullException(fieldName, NullPropertyExceptionMessage(fieldName, componentType))
? throw new ArgumentNullException(fieldName, this.NullPropertyExceptionMessage(fieldName, componentType))
: input;
}
protected T ValidateRequiredInput<T>(T input, string fieldName, string componentType)
{
// Null coalescing for generic types is not available until C# 8
return EqualityComparer<T>.Default.Equals(input, default(T)) ? throw new ArgumentNullException(fieldName, NullPropertyExceptionMessage(fieldName, componentType)) : input;
return EqualityComparer<T>.Default.Equals(input, default(T)) ? throw new ArgumentNullException(fieldName, this.NullPropertyExceptionMessage(fieldName, componentType)) : input;
}
protected string NullPropertyExceptionMessage(string propertyName, string componentType)

Просмотреть файл

@ -13,13 +13,13 @@ namespace Microsoft.ComponentDetection.Contracts.TypedComponent
{
int.TryParse(portVersion, out var port);
SPDXID = ValidateRequiredInput(spdxid, nameof(SPDXID), nameof(ComponentType.Vcpkg));
Name = ValidateRequiredInput(name, nameof(Name), nameof(ComponentType.Vcpkg));
Version = version;
PortVersion = port;
Triplet = triplet;
Description = description;
DownloadLocation = downloadLocation;
this.SPDXID = this.ValidateRequiredInput(spdxid, nameof(this.SPDXID), nameof(ComponentType.Vcpkg));
this.Name = this.ValidateRequiredInput(name, nameof(this.Name), nameof(ComponentType.Vcpkg));
this.Version = version;
this.PortVersion = port;
this.Triplet = triplet;
this.Description = description;
this.DownloadLocation = downloadLocation;
}
public string SPDXID { get; set; }
@ -42,13 +42,13 @@ namespace Microsoft.ComponentDetection.Contracts.TypedComponent
{
get
{
if (PortVersion > 0)
if (this.PortVersion > 0)
{
return $"{Name} {Version}#{PortVersion} - {Type}";
return $"{this.Name} {this.Version}#{this.PortVersion} - {this.Type}";
}
else
{
return $"{Name} {Version} - {Type}";
return $"{this.Name} {this.Version} - {this.Type}";
}
}
}
@ -57,17 +57,17 @@ namespace Microsoft.ComponentDetection.Contracts.TypedComponent
{
get
{
if (PortVersion > 0)
if (this.PortVersion > 0)
{
return new PackageURL($"pkg:vcpkg/{Name}@{Version}?port_version={PortVersion}");
return new PackageURL($"pkg:vcpkg/{this.Name}@{this.Version}?port_version={this.PortVersion}");
}
else if (Version != null)
else if (this.Version != null)
{
return new PackageURL($"pkg:vcpkg/{Name}@{Version}");
return new PackageURL($"pkg:vcpkg/{this.Name}@{this.Version}");
}
else
{
return new PackageURL($"pkg:vcpkg/{Name}");
return new PackageURL($"pkg:vcpkg/{this.Name}");
}
}
}

Просмотреть файл

@ -35,9 +35,9 @@ namespace Microsoft.ComponentDetection.Detectors.CocoaPods
public IList<PodDependency> Dependencies { get; set; }
public string Podspec => Name.Split('/', 2)[0];
public string Podspec => this.Name.Split('/', 2)[0];
public bool IsSubspec => Name != Podspec;
public bool IsSubspec => this.Name != this.Podspec;
public void Read(IParser parser, Type expectedType, ObjectDeserializer nestedObjectDeserializer)
{
@ -49,18 +49,18 @@ namespace Microsoft.ComponentDetection.Detectors.CocoaPods
var podInfo = parser.Consume<Scalar>();
var components = podInfo.Value.Split(new char[] { '(', ')' }, StringSplitOptions.RemoveEmptyEntries);
Name = components[0].Trim();
Version = components[1].Trim();
this.Name = components[0].Trim();
this.Version = components[1].Trim();
if (hasDependencies)
{
Dependencies = (IList<PodDependency>)nestedObjectDeserializer(typeof(IList<PodDependency>));
this.Dependencies = (IList<PodDependency>)nestedObjectDeserializer(typeof(IList<PodDependency>));
parser.Consume<MappingEnd>();
}
else
{
Dependencies = Array.Empty<PodDependency>();
this.Dependencies = Array.Empty<PodDependency>();
}
}
@ -76,16 +76,16 @@ namespace Microsoft.ComponentDetection.Detectors.CocoaPods
public string PodVersion { get; set; }
public string Podspec => PodName.Split('/', 2)[0];
public string Podspec => this.PodName.Split('/', 2)[0];
public bool IsSubspec => PodName != Podspec;
public bool IsSubspec => this.PodName != this.Podspec;
public void Read(IParser parser, Type expectedType, ObjectDeserializer nestedObjectDeserializer)
{
var scalar = parser.Consume<Scalar>();
var components = scalar.Value.Split(new char[] { '(', ')' }, StringSplitOptions.RemoveEmptyEntries);
PodName = components[0].Trim();
PodVersion = components.Length > 1 ? components[1].Trim() : null;
this.PodName = components[0].Trim();
this.PodVersion = components.Length > 1 ? components[1].Trim() : null;
}
public void Write(IEmitter emitter, ObjectSerializer nestedObjectSerializer)
@ -122,17 +122,17 @@ namespace Microsoft.ComponentDetection.Detectors.CocoaPods
public PodfileLock()
{
Dependencies = Array.Empty<PodDependency>();
PodspecRepositories = new Dictionary<string, IList<string>>();
PodspecChecksums = new Dictionary<string, string>();
ExternalSources = new Dictionary<string, IDictionary<string, string>>();
CheckoutOptions = new Dictionary<string, IDictionary<string, string>>();
Pods = Array.Empty<Pod>();
this.Dependencies = Array.Empty<PodDependency>();
this.PodspecRepositories = new Dictionary<string, IList<string>>();
this.PodspecChecksums = new Dictionary<string, string>();
this.ExternalSources = new Dictionary<string, IDictionary<string, string>>();
this.CheckoutOptions = new Dictionary<string, IDictionary<string, string>>();
this.Pods = Array.Empty<Pod>();
}
public string GetSpecRepositoryOfSpec(string specName)
{
foreach (var repository in PodspecRepositories)
foreach (var repository in this.PodspecRepositories)
{
if (repository.Value.Contains(specName))
{
@ -159,17 +159,17 @@ namespace Microsoft.ComponentDetection.Detectors.CocoaPods
var singleFileComponentRecorder = processRequest.SingleFileComponentRecorder;
var file = processRequest.ComponentStream;
Logger.LogVerbose($"Found {file.Pattern}: {file.Location}");
this.Logger.LogVerbose($"Found {file.Pattern}: {file.Location}");
try
{
var podfileLock = await ParsePodfileLock(file);
ProcessPodfileLock(singleFileComponentRecorder, podfileLock);
this.ProcessPodfileLock(singleFileComponentRecorder, podfileLock);
}
catch (Exception e)
{
Logger.LogFailedReadingFile(file.Location, e);
this.Logger.LogFailedReadingFile(file.Location, e);
}
}
@ -311,7 +311,7 @@ namespace Microsoft.ComponentDetection.Detectors.CocoaPods
}
else
{
Logger.LogWarning($"Missing podspec declaration. podspec={dependency.Podspec}, version={dependency.PodVersion}");
this.Logger.LogWarning($"Missing podspec declaration. podspec={dependency.Podspec}, version={dependency.PodVersion}");
}
}
}

Просмотреть файл

@ -39,7 +39,7 @@ namespace Microsoft.ComponentDetection.Detectors.Dockerfile
var singleFileComponentRecorder = processRequest.SingleFileComponentRecorder;
var file = processRequest.ComponentStream;
var filePath = file.Location;
Logger.LogInfo($"Discovered dockerfile: {file.Location}");
this.Logger.LogInfo($"Discovered dockerfile: {file.Location}");
string contents;
using (var reader = new StreamReader(file.Stream))
@ -48,7 +48,7 @@ namespace Microsoft.ComponentDetection.Detectors.Dockerfile
}
var stageNameMap = new Dictionary<string, string>();
var dockerFileComponent = ParseDockerFile(contents, file.Location, singleFileComponentRecorder, stageNameMap);
var dockerFileComponent = this.ParseDockerFile(contents, file.Location, singleFileComponentRecorder, stageNameMap);
}
private Task ParseDockerFile(string fileContents, string fileLocation, ISingleFileComponentRecorder singleFileComponentRecorder, Dictionary<string, string> stageNameMap)
@ -57,7 +57,7 @@ namespace Microsoft.ComponentDetection.Detectors.Dockerfile
var instructions = dockerfileModel.Items;
foreach (var instruction in instructions)
{
var imageReference = ProcessDockerfileConstruct(instruction, dockerfileModel.EscapeChar, stageNameMap);
var imageReference = this.ProcessDockerfileConstruct(instruction, dockerfileModel.EscapeChar, stageNameMap);
if (imageReference != null)
{
singleFileComponentRecorder.RegisterUsage(new DetectedComponent(imageReference.ToTypedDockerReferenceComponent()));
@ -79,10 +79,10 @@ namespace Microsoft.ComponentDetection.Detectors.Dockerfile
switch (constructType)
{
case "FromInstruction":
baseImage = ParseFromInstruction(construct, escapeChar, stageNameMap);
baseImage = this.ParseFromInstruction(construct, escapeChar, stageNameMap);
break;
case "CopyInstruction":
baseImage = ParseCopyInstruction(construct, escapeChar, stageNameMap);
baseImage = this.ParseCopyInstruction(construct, escapeChar, stageNameMap);
break;
default:
break;
@ -92,8 +92,8 @@ namespace Microsoft.ComponentDetection.Detectors.Dockerfile
return baseImage;
} catch (Exception e)
{
Logger.LogError($"Failed to detect a DockerReference component, the component will not be registered. \n Error Message: <{e.Message}>");
Logger.LogException(e, isError: true, printException: true);
this.Logger.LogError($"Failed to detect a DockerReference component, the component will not be registered. \n Error Message: <{e.Message}>");
this.Logger.LogException(e, isError: true, printException: true);
return null;
}
}
@ -102,7 +102,7 @@ namespace Microsoft.ComponentDetection.Detectors.Dockerfile
{
var tokens = construct.Tokens.ToArray();
var resolvedFromStatement = construct.ResolveVariables(escapeChar).TrimEnd();
var fromInstruction = (Valleysoft.DockerfileModel.FromInstruction)construct;
var fromInstruction = (FromInstruction)construct;
string reference = fromInstruction.ImageName;
if (string.IsNullOrWhiteSpace(resolvedFromStatement) || string.IsNullOrEmpty(reference))
{
@ -126,7 +126,7 @@ namespace Microsoft.ComponentDetection.Detectors.Dockerfile
if (!string.IsNullOrEmpty(stageNameReference))
{
if (HasUnresolvedVariables(stageNameReference))
if (this.HasUnresolvedVariables(stageNameReference))
{
return null;
}
@ -134,7 +134,7 @@ namespace Microsoft.ComponentDetection.Detectors.Dockerfile
return DockerReferenceUtility.ParseFamiliarName(stageNameReference);
}
if (HasUnresolvedVariables(reference))
if (this.HasUnresolvedVariables(reference))
{
return null;
}
@ -145,7 +145,7 @@ namespace Microsoft.ComponentDetection.Detectors.Dockerfile
private DockerReference ParseCopyInstruction(DockerfileConstruct construct, char escapeChar, Dictionary<string, string> stageNameMap)
{
var resolvedCopyStatement = construct.ResolveVariables(escapeChar).TrimEnd();
var copyInstruction = (Valleysoft.DockerfileModel.CopyInstruction)construct;
var copyInstruction = (CopyInstruction)construct;
var reference = copyInstruction.FromStageName;
if (string.IsNullOrWhiteSpace(resolvedCopyStatement) || string.IsNullOrWhiteSpace(reference))
{
@ -155,7 +155,7 @@ namespace Microsoft.ComponentDetection.Detectors.Dockerfile
stageNameMap.TryGetValue(reference, out var stageNameReference);
if (!string.IsNullOrEmpty(stageNameReference))
{
if (HasUnresolvedVariables(stageNameReference))
if (this.HasUnresolvedVariables(stageNameReference))
{
return null;
}
@ -165,7 +165,7 @@ namespace Microsoft.ComponentDetection.Detectors.Dockerfile
}
}
if (HasUnresolvedVariables(reference))
if (this.HasUnresolvedVariables(reference))
{
return null;
}

Просмотреть файл

@ -44,7 +44,7 @@ namespace Microsoft.ComponentDetection.Detectors.Go
var file = processRequest.ComponentStream;
var projectRootDirectory = Directory.GetParent(file.Location);
if (projectRoots.Any(path => projectRootDirectory.FullName.StartsWith(path)))
if (this.projectRoots.Any(path => projectRootDirectory.FullName.StartsWith(path)))
{
return;
}
@ -52,26 +52,26 @@ namespace Microsoft.ComponentDetection.Detectors.Go
var wasGoCliScanSuccessful = false;
try
{
if (!IsGoCliManuallyDisabled())
if (!this.IsGoCliManuallyDisabled())
{
wasGoCliScanSuccessful = await UseGoCliToScan(file.Location, singleFileComponentRecorder);
wasGoCliScanSuccessful = await this.UseGoCliToScan(file.Location, singleFileComponentRecorder);
}
else
{
Logger.LogInfo("Go cli scan was manually disabled, fallback strategy performed." +
" More info: https://github.com/microsoft/component-detection/blob/main/docs/detectors/go.md#fallback-detection-strategy");
this.Logger.LogInfo("Go cli scan was manually disabled, fallback strategy performed." +
" More info: https://github.com/microsoft/component-detection/blob/main/docs/detectors/go.md#fallback-detection-strategy");
}
}
catch (Exception ex)
{
Logger.LogError($"Failed to detect components using go cli. Location: {file.Location}");
Logger.LogException(ex, isError: true, printException: true);
this.Logger.LogError($"Failed to detect components using go cli. Location: {file.Location}");
this.Logger.LogException(ex, isError: true, printException: true);
}
finally
{
if (wasGoCliScanSuccessful)
{
projectRoots.Add(projectRootDirectory.FullName);
this.projectRoots.Add(projectRootDirectory.FullName);
}
else
{
@ -80,15 +80,15 @@ namespace Microsoft.ComponentDetection.Detectors.Go
{
case ".mod":
{
Logger.LogVerbose("Found Go.mod: " + file.Location);
ParseGoModFile(singleFileComponentRecorder, file);
this.Logger.LogVerbose("Found Go.mod: " + file.Location);
this.ParseGoModFile(singleFileComponentRecorder, file);
break;
}
case ".sum":
{
Logger.LogVerbose("Found Go.sum: " + file.Location);
ParseGoSumFile(singleFileComponentRecorder, file);
this.Logger.LogVerbose("Found Go.sum: " + file.Location);
this.ParseGoSumFile(singleFileComponentRecorder, file);
break;
}
@ -109,32 +109,32 @@ namespace Microsoft.ComponentDetection.Detectors.Go
var projectRootDirectory = Directory.GetParent(location);
record.ProjectRoot = projectRootDirectory.FullName;
var isGoAvailable = await CommandLineInvocationService.CanCommandBeLocated("go", null, workingDirectory: projectRootDirectory, new[] { "version" });
var isGoAvailable = await this.CommandLineInvocationService.CanCommandBeLocated("go", null, workingDirectory: projectRootDirectory, new[] { "version" });
record.IsGoAvailable = isGoAvailable;
if (!isGoAvailable)
{
Logger.LogInfo("Go CLI was not found in the system");
this.Logger.LogInfo("Go CLI was not found in the system");
return false;
}
Logger.LogInfo("Go CLI was found in system and will be used to generate dependency graph. " +
"Detection time may be improved by activating fallback strategy (https://github.com/microsoft/component-detection/blob/main/docs/detectors/go.md#fallback-detection-strategy). " +
"But, it will introduce noise into the detected components.");
var goDependenciesProcess = await CommandLineInvocationService.ExecuteCommand("go", null, workingDirectory: projectRootDirectory, new[] { "list", "-m", "-json", "all" });
this.Logger.LogInfo("Go CLI was found in system and will be used to generate dependency graph. " +
"Detection time may be improved by activating fallback strategy (https://github.com/microsoft/component-detection/blob/main/docs/detectors/go.md#fallback-detection-strategy). " +
"But, it will introduce noise into the detected components.");
var goDependenciesProcess = await this.CommandLineInvocationService.ExecuteCommand("go", null, workingDirectory: projectRootDirectory, new[] { "list", "-m", "-json", "all" });
if (goDependenciesProcess.ExitCode != 0)
{
Logger.LogError($"Go CLI command \"go list -m -json all\" failed with error:\n {goDependenciesProcess.StdErr}");
Logger.LogError($"Go CLI could not get dependency build list at location: {location}. Fallback go.sum/go.mod parsing will be used.");
this.Logger.LogError($"Go CLI command \"go list -m -json all\" failed with error:\n {goDependenciesProcess.StdErr}");
this.Logger.LogError($"Go CLI could not get dependency build list at location: {location}. Fallback go.sum/go.mod parsing will be used.");
return false;
}
RecordBuildDependencies(goDependenciesProcess.StdOut, singleFileComponentRecorder);
this.RecordBuildDependencies(goDependenciesProcess.StdOut, singleFileComponentRecorder);
var generateGraphProcess = await CommandLineInvocationService.ExecuteCommand("go", null, workingDirectory: projectRootDirectory, new List<string> { "mod", "graph" }.ToArray());
var generateGraphProcess = await this.CommandLineInvocationService.ExecuteCommand("go", null, workingDirectory: projectRootDirectory, new List<string> { "mod", "graph" }.ToArray());
if (generateGraphProcess.ExitCode == 0)
{
PopulateDependencyGraph(generateGraphProcess.StdOut, singleFileComponentRecorder);
this.PopulateDependencyGraph(generateGraphProcess.StdOut, singleFileComponentRecorder);
record.WasGraphSuccessful = true;
}
@ -156,13 +156,13 @@ namespace Microsoft.ComponentDetection.Detectors.Go
// Stopping at the first ) restrict the detection to only the require section.
while ((line = reader.ReadLine()) != null && !line.EndsWith(")"))
{
if (TryToCreateGoComponentFromModLine(line, out var goComponent))
if (this.TryToCreateGoComponentFromModLine(line, out var goComponent))
{
singleFileComponentRecorder.RegisterUsage(new DetectedComponent(goComponent));
}
else
{
Logger.LogWarning($"Line could not be parsed for component [{line.Trim()}]");
this.Logger.LogWarning($"Line could not be parsed for component [{line.Trim()}]");
}
}
}
@ -195,13 +195,13 @@ namespace Microsoft.ComponentDetection.Detectors.Go
string line;
while ((line = reader.ReadLine()) != null)
{
if (TryToCreateGoComponentFromSumLine(line, out var goComponent))
if (this.TryToCreateGoComponentFromSumLine(line, out var goComponent))
{
singleFileComponentRecorder.RegisterUsage(new DetectedComponent(goComponent));
}
else
{
Logger.LogWarning($"Line could not be parsed for component [{line.Trim()}]");
this.Logger.LogWarning($"Line could not be parsed for component [{line.Trim()}]");
}
}
}
@ -238,16 +238,16 @@ namespace Microsoft.ComponentDetection.Detectors.Go
continue;
}
Logger.LogWarning("Unexpected relationship output from go mod graph:");
Logger.LogWarning(relationship);
this.Logger.LogWarning("Unexpected relationship output from go mod graph:");
this.Logger.LogWarning(relationship);
continue;
}
GoComponent parentComponent;
GoComponent childComponent;
var isParentParsed = TryCreateGoComponentFromRelationshipPart(components[0], out parentComponent);
var isChildParsed = TryCreateGoComponentFromRelationshipPart(components[1], out childComponent);
var isParentParsed = this.TryCreateGoComponentFromRelationshipPart(components[0], out parentComponent);
var isChildParsed = this.TryCreateGoComponentFromRelationshipPart(components[1], out childComponent);
if (!isParentParsed)
{
@ -257,14 +257,14 @@ namespace Microsoft.ComponentDetection.Detectors.Go
if (isChildParsed)
{
if (IsModuleInBuildList(componentRecorder, parentComponent) && IsModuleInBuildList(componentRecorder, childComponent))
if (this.IsModuleInBuildList(componentRecorder, parentComponent) && this.IsModuleInBuildList(componentRecorder, childComponent))
{
componentRecorder.RegisterUsage(new DetectedComponent(childComponent), parentComponentId: parentComponent.Id);
}
}
else
{
Logger.LogWarning($"Failed to parse components from relationship string {relationship}");
this.Logger.LogWarning($"Failed to parse components from relationship string {relationship}");
}
}
}
@ -324,7 +324,7 @@ namespace Microsoft.ComponentDetection.Detectors.Go
private bool IsGoCliManuallyDisabled()
{
return EnvVarService.IsEnvironmentVariableValueTrue("DisableGoCliScan");
return this.EnvVarService.IsEnvironmentVariableValueTrue("DisableGoCliScan");
}
private class GoBuildModule

Просмотреть файл

@ -31,8 +31,8 @@ namespace Microsoft.ComponentDetection.Detectors.Gradle
var singleFileComponentRecorder = processRequest.SingleFileComponentRecorder;
var file = processRequest.ComponentStream;
Logger.LogVerbose("Found Gradle lockfile: " + file.Location);
ParseLockfile(singleFileComponentRecorder, file);
this.Logger.LogVerbose("Found Gradle lockfile: " + file.Location);
this.ParseLockfile(singleFileComponentRecorder, file);
return Task.CompletedTask;
}
@ -52,14 +52,14 @@ namespace Microsoft.ComponentDetection.Detectors.Gradle
var line = lines[0].Trim();
lines.RemoveAt(0);
if (!StartsWithLetter(line))
if (!this.StartsWithLetter(line))
{
continue;
}
if (line.Split(":").Length == 3)
{
var detectedMavenComponent = new DetectedComponent(CreateMavenComponentFromFileLine(line));
var detectedMavenComponent = new DetectedComponent(this.CreateMavenComponentFromFileLine(line));
singleFileComponentRecorder.RegisterUsage(detectedMavenComponent);
}
}

Просмотреть файл

@ -60,12 +60,12 @@ namespace Microsoft.ComponentDetection.Detectors.Ivy
protected override async Task<IObservable<ProcessRequest>> OnPrepareDetection(IObservable<ProcessRequest> processRequests, IDictionary<string, string> detectorArgs)
{
if (await IsAntLocallyAvailableAsync())
if (await this.IsAntLocallyAvailableAsync())
{
return processRequests;
}
Logger.LogVerbose("Skipping Ivy detection as ant is not available in the local PATH.");
this.Logger.LogVerbose("Skipping Ivy detection as ant is not available in the local PATH.");
return Enumerable.Empty<ProcessRequest>().ToObservable();
}
@ -80,18 +80,18 @@ namespace Microsoft.ComponentDetection.Detectors.Ivy
{
if (File.Exists(ivySettingsFilePath))
{
Logger.LogInfo($"Processing {ivyXmlFile.Location} and ivysettings.xml.");
await ProcessIvyAndIvySettingsFilesAsync(singleFileComponentRecorder, ivyXmlFile.Location, ivySettingsFilePath);
this.Logger.LogInfo($"Processing {ivyXmlFile.Location} and ivysettings.xml.");
await this.ProcessIvyAndIvySettingsFilesAsync(singleFileComponentRecorder, ivyXmlFile.Location, ivySettingsFilePath);
}
else
{
Logger.LogInfo($"Processing {ivyXmlFile.Location}.");
await ProcessIvyAndIvySettingsFilesAsync(singleFileComponentRecorder, ivyXmlFile.Location, null);
this.Logger.LogInfo($"Processing {ivyXmlFile.Location}.");
await this.ProcessIvyAndIvySettingsFilesAsync(singleFileComponentRecorder, ivyXmlFile.Location, null);
}
}
else
{
Logger.LogError($"File {ivyXmlFile.Location} passed to OnFileFound, but does not exist!");
this.Logger.LogError($"File {ivyXmlFile.Location} passed to OnFileFound, but does not exist!");
}
}
@ -103,27 +103,27 @@ namespace Microsoft.ComponentDetection.Detectors.Ivy
try
{
string workingDirectory = Path.Combine(Path.GetTempPath(), "ComponentDetection_Ivy");
Logger.LogVerbose($"Preparing temporary Ivy project in {workingDirectory}");
this.Logger.LogVerbose($"Preparing temporary Ivy project in {workingDirectory}");
if (Directory.Exists(workingDirectory))
{
Directory.Delete(workingDirectory, recursive: true);
}
InitTemporaryAntProject(workingDirectory, ivyXmlFile, ivySettingsXmlFile);
if (await RunAntToDetectDependenciesAsync(workingDirectory))
this.InitTemporaryAntProject(workingDirectory, ivyXmlFile, ivySettingsXmlFile);
if (await this.RunAntToDetectDependenciesAsync(workingDirectory))
{
string instructionsFile = Path.Combine(workingDirectory, "target", "RegisterUsage.json");
RegisterUsagesFromFile(singleFileComponentRecorder, instructionsFile);
this.RegisterUsagesFromFile(singleFileComponentRecorder, instructionsFile);
}
Directory.Delete(workingDirectory, recursive: true);
}
catch (Exception e)
{
Logger.LogError("Exception occurred during Ivy file processing: " + e);
this.Logger.LogError("Exception occurred during Ivy file processing: " + e);
// If something went wrong, just ignore the file
Logger.LogFailedReadingFile(ivyXmlFile, e);
this.Logger.LogFailedReadingFile(ivyXmlFile, e);
}
}
@ -156,40 +156,40 @@ namespace Microsoft.ComponentDetection.Detectors.Ivy
{
// Note: calling CanCommandBeLocated populates a cache of valid commands. If it is not called before ExecuteCommand,
// ExecuteCommand calls CanCommandBeLocated with no arguments, which fails.
return await CommandLineInvocationService.CanCommandBeLocated(PrimaryCommand, AdditionalValidCommands, AntVersionArgument);
return await this.CommandLineInvocationService.CanCommandBeLocated(PrimaryCommand, AdditionalValidCommands, AntVersionArgument);
}
private async Task<bool> RunAntToDetectDependenciesAsync(string workingDirectory)
{
bool ret = false;
Logger.LogVerbose($"Executing command `ant resolve-dependencies` in directory {workingDirectory}");
CommandLineExecutionResult result = await CommandLineInvocationService.ExecuteCommand(PrimaryCommand, additionalCandidateCommands: AdditionalValidCommands, "-buildfile", workingDirectory, "resolve-dependencies");
this.Logger.LogVerbose($"Executing command `ant resolve-dependencies` in directory {workingDirectory}");
CommandLineExecutionResult result = await this.CommandLineInvocationService.ExecuteCommand(PrimaryCommand, additionalCandidateCommands: AdditionalValidCommands, "-buildfile", workingDirectory, "resolve-dependencies");
if (result.ExitCode == 0)
{
Logger.LogVerbose("Ant command succeeded");
this.Logger.LogVerbose("Ant command succeeded");
ret = true;
}
else
{
Logger.LogError($"Ant command failed with return code {result.ExitCode}");
this.Logger.LogError($"Ant command failed with return code {result.ExitCode}");
}
if (string.IsNullOrWhiteSpace(result.StdOut))
{
Logger.LogVerbose("Ant command wrote nothing to stdout.");
this.Logger.LogVerbose("Ant command wrote nothing to stdout.");
}
else
{
Logger.LogVerbose("Ant command stdout:\n" + result.StdOut);
this.Logger.LogVerbose("Ant command stdout:\n" + result.StdOut);
}
if (string.IsNullOrWhiteSpace(result.StdErr))
{
Logger.LogVerbose("Ant command wrote nothing to stderr.");
this.Logger.LogVerbose("Ant command wrote nothing to stderr.");
}
else
{
Logger.LogWarning("Ant command stderr:\n" + result.StdErr);
this.Logger.LogWarning("Ant command stderr:\n" + result.StdErr);
}
return ret;
@ -228,7 +228,7 @@ namespace Microsoft.ComponentDetection.Detectors.Ivy
}
else
{
Logger.LogWarning($"Dependency \"{component.Id}\" could not be resolved by Ivy, and so has not been recorded by Component Detection.");
this.Logger.LogWarning($"Dependency \"{component.Id}\" could not be resolved by Ivy, and so has not been recorded by Component Detection.");
}
}
}

Просмотреть файл

@ -313,7 +313,7 @@ namespace Microsoft.ComponentDetection.Detectors.Linux.Contracts
public static implicit operator ConfigurationUnion(double Double) => new ConfigurationUnion { Double = Double };
public static implicit operator ConfigurationUnion(long Integer) => new ConfigurationUnion { Integer = Integer };
public static implicit operator ConfigurationUnion(string String) => new ConfigurationUnion { String = String };
public bool IsNull => AnythingArray == null && Bool == null && Double == null && Integer == null && AnythingMap == null && String == null;
public bool IsNull => this.AnythingArray == null && this.Bool == null && this.Double == null && this.Integer == null && this.AnythingMap == null && this.String == null;
}
public partial struct Author

Просмотреть файл

@ -46,26 +46,26 @@ namespace Microsoft.ComponentDetection.Detectors.Linux
if (imagesToProcess == null || !imagesToProcess.Any())
{
Logger.LogInfo("No instructions received to scan docker images.");
this.Logger.LogInfo("No instructions received to scan docker images.");
return EmptySuccessfulScan();
}
var cancellationTokenSource = new CancellationTokenSource(GetTimeout(request.DetectorArgs));
if (!await DockerService.CanRunLinuxContainersAsync(cancellationTokenSource.Token))
if (!await this.DockerService.CanRunLinuxContainersAsync(cancellationTokenSource.Token))
{
using var record = new LinuxContainerDetectorUnsupportedOs
{
Os = RuntimeInformation.OSDescription,
};
Logger.LogInfo("Linux containers are not available on this host.");
this.Logger.LogInfo("Linux containers are not available on this host.");
return EmptySuccessfulScan();
}
var results = Enumerable.Empty<ImageScanningResult>();
try
{
results = await ProcessImagesAsync(imagesToProcess, request.ComponentRecorder, cancellationTokenSource.Token);
results = await this.ProcessImagesAsync(imagesToProcess, request.ComponentRecorder, cancellationTokenSource.Token);
}
catch (OperationCanceledException)
{
@ -91,15 +91,15 @@ namespace Microsoft.ComponentDetection.Detectors.Linux
try
{
// Check image exists locally. Try docker pull if not
if (!(await DockerService.ImageExistsLocallyAsync(image, cancellationToken) ||
await DockerService.TryPullImageAsync(image, cancellationToken)))
if (!(await this.DockerService.ImageExistsLocallyAsync(image, cancellationToken) ||
await this.DockerService.TryPullImageAsync(image, cancellationToken)))
{
throw new InvalidUserInputException(
$"Docker image {image} could not be found locally and could not be pulled. Verify the image is either available locally or through docker pull.",
null);
}
var imageDetails = await DockerService.InspectImageAsync(image, cancellationToken);
var imageDetails = await this.DockerService.InspectImageAsync(image, cancellationToken);
// Unable to fetch image details
if (imageDetails == null)
@ -111,7 +111,7 @@ namespace Microsoft.ComponentDetection.Detectors.Linux
}
catch (Exception e)
{
Logger.LogWarning($"Processing of image {image} failed with exception: {e.Message}");
this.Logger.LogWarning($"Processing of image {image} failed with exception: {e.Message}");
using var record = new LinuxContainerDetectorImageDetectionFailed
{
ExceptionType = e.GetType().ToString(),
@ -130,7 +130,7 @@ namespace Microsoft.ComponentDetection.Detectors.Linux
{
var internalContainerDetails = kvp.Value;
var image = kvp.Key;
int baseImageLayerCount = await GetBaseImageLayerCount(internalContainerDetails, image, cancellationToken);
int baseImageLayerCount = await this.GetBaseImageLayerCount(internalContainerDetails, image, cancellationToken);
//Update the layer information to specify if a layer was fond in the specified baseImage
internalContainerDetails.Layers = internalContainerDetails.Layers.Select(layer => new DockerLayer
@ -140,7 +140,7 @@ namespace Microsoft.ComponentDetection.Detectors.Linux
IsBaseImage = layer.LayerIndex < baseImageLayerCount,
});
var layers = await LinuxScanner.ScanLinuxAsync(kvp.Value.ImageId, internalContainerDetails.Layers, baseImageLayerCount, cancellationToken);
var layers = await this.LinuxScanner.ScanLinuxAsync(kvp.Value.ImageId, internalContainerDetails.Layers, baseImageLayerCount, cancellationToken);
var components = layers.SelectMany(layer => layer.LinuxComponents.Select(linuxComponent => new DetectedComponent(linuxComponent, null, internalContainerDetails.Id, layer.DockerLayer.LayerIndex)));
internalContainerDetails.Layers = layers.Select(layer => layer.DockerLayer);
@ -154,7 +154,7 @@ namespace Microsoft.ComponentDetection.Detectors.Linux
}
catch (Exception e)
{
Logger.LogWarning($"Scanning of image {kvp.Key} failed with exception: {e.Message}");
this.Logger.LogWarning($"Scanning of image {kvp.Key} failed with exception: {e.Message}");
using var record = new LinuxContainerDetectorImageDetectionFailed
{
ExceptionType = e.GetType().ToString(),
@ -212,11 +212,11 @@ namespace Microsoft.ComponentDetection.Detectors.Linux
if (string.IsNullOrEmpty(scannedImageDetails.BaseImageRef))
{
record.BaseImageLayerMessage = $"Base image annotations not found on image {image}, Results will not be mapped to base image layers";
Logger.LogInfo(record.BaseImageLayerMessage);
this.Logger.LogInfo(record.BaseImageLayerMessage);
return 0;
} else if (scannedImageDetails.BaseImageRef == "scratch") {
record.BaseImageLayerMessage = $"{image} has no base image";
Logger.LogInfo(record.BaseImageLayerMessage);
this.Logger.LogInfo(record.BaseImageLayerMessage);
return 0;
}
@ -225,19 +225,19 @@ namespace Microsoft.ComponentDetection.Detectors.Linux
record.BaseImageDigest = baseImageDigest;
record.BaseImageRef = scannedImageDetails.BaseImageRef;
if (!(await DockerService.ImageExistsLocallyAsync(refWithDigest, cancellationToken) ||
await DockerService.TryPullImageAsync(refWithDigest, cancellationToken)))
if (!(await this.DockerService.ImageExistsLocallyAsync(refWithDigest, cancellationToken) ||
await this.DockerService.TryPullImageAsync(refWithDigest, cancellationToken)))
{
record.BaseImageLayerMessage = $"Base image {refWithDigest} could not be found locally and could not be pulled. Results will not be mapped to base image layers";
Logger.LogInfo(record.BaseImageLayerMessage);
this.Logger.LogInfo(record.BaseImageLayerMessage);
return 0;
}
var baseImageDetails = await DockerService.InspectImageAsync(refWithDigest, cancellationToken);
if (!ValidateBaseImageLayers(scannedImageDetails, baseImageDetails))
var baseImageDetails = await this.DockerService.InspectImageAsync(refWithDigest, cancellationToken);
if (!this.ValidateBaseImageLayers(scannedImageDetails, baseImageDetails))
{
record.BaseImageLayerMessage = $"Docker image {image} was set to have base image {refWithDigest} but is not built off of it. Results will not be mapped to base image layers";
Logger.LogInfo(record.BaseImageLayerMessage);
this.Logger.LogInfo(record.BaseImageLayerMessage);
return 0;
}

Просмотреть файл

@ -58,19 +58,19 @@ namespace Microsoft.ComponentDetection.Detectors.Linux
try
{
var command = new List<string> { imageHash }.Concat(CmdParameters).ToList();
(stdout, stderr) = await DockerService.CreateAndRunContainerAsync(ScannerImage, command, cancellationToken);
(stdout, stderr) = await this.DockerService.CreateAndRunContainerAsync(ScannerImage, command, cancellationToken);
}
catch (Exception e)
{
syftTelemetryRecord.Exception = JsonConvert.SerializeObject(e);
Logger.LogException(e, false);
this.Logger.LogException(e, false);
throw;
}
}
else
{
record.SemaphoreFailure = true;
Logger.LogWarning($"Failed to enter the docker semaphore for image {imageHash}");
this.Logger.LogWarning($"Failed to enter the docker semaphore for image {imageHash}");
}
}
finally

Просмотреть файл

@ -10,7 +10,7 @@ namespace Microsoft.ComponentDetection.Detectors.Maven
{
public GraphNode(T value)
{
Value = value;
this.Value = value;
}
public T Value { get; set; }

Просмотреть файл

@ -29,18 +29,18 @@ namespace Microsoft.ComponentDetection.Detectors.Maven
public async Task<bool> MavenCLIExists()
{
return await CommandLineInvocationService.CanCommandBeLocated(PrimaryCommand, AdditionalValidCommands, MvnVersionArgument);
return await this.CommandLineInvocationService.CanCommandBeLocated(PrimaryCommand, AdditionalValidCommands, MvnVersionArgument);
}
public async Task GenerateDependenciesFile(ProcessRequest processRequest)
{
var pomFile = processRequest.ComponentStream;
var cliParameters = new[] { "dependency:tree", "-B", $"-DoutputFile={BcdeMvnDependencyFileName}", "-DoutputType=text", $"-f{pomFile.Location}" };
var result = await CommandLineInvocationService.ExecuteCommand(PrimaryCommand, AdditionalValidCommands, cliParameters);
var cliParameters = new[] { "dependency:tree", "-B", $"-DoutputFile={this.BcdeMvnDependencyFileName}", "-DoutputType=text", $"-f{pomFile.Location}" };
var result = await this.CommandLineInvocationService.ExecuteCommand(PrimaryCommand, AdditionalValidCommands, cliParameters);
if (result.ExitCode != 0)
{
Logger.LogVerbose($"Mvn execution failed for pom file: {pomFile.Location}");
Logger.LogError(string.IsNullOrEmpty(result.StdErr) ? result.StdOut : result.StdErr);
this.Logger.LogVerbose($"Mvn execution failed for pom file: {pomFile.Location}");
this.Logger.LogError(string.IsNullOrEmpty(result.StdErr) ? result.StdOut : result.StdErr);
}
}
@ -49,7 +49,7 @@ namespace Microsoft.ComponentDetection.Detectors.Maven
using StreamReader sr = new StreamReader(processRequest.ComponentStream.Stream);
var lines = sr.ReadToEnd().Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
ParserService.Parse(lines, processRequest.SingleFileComponentRecorder);
this.ParserService.Parse(lines, processRequest.SingleFileComponentRecorder);
}
}
}

Просмотреть файл

@ -21,12 +21,12 @@ namespace Microsoft.ComponentDetection.Detectors.Maven
private void StartDependencyCategory(string categoryName)
{
if (DependencyCategory != null)
if (this.DependencyCategory != null)
{
throw new InvalidOperationException("Current category must be finished before starting new category.");
}
DependencyCategory = new GraphNode<string>(categoryName);
this.DependencyCategory = new GraphNode<string>(categoryName);
}
public GraphNode<string> Parse(string[] lines)
@ -34,21 +34,21 @@ namespace Microsoft.ComponentDetection.Detectors.Maven
foreach (var line in lines)
{
var localLine = line.Trim(TrimCharacters);
if (!string.IsNullOrWhiteSpace(localLine) && DependencyCategory == null)
if (!string.IsNullOrWhiteSpace(localLine) && this.DependencyCategory == null)
{
StartDependencyCategory(localLine);
this.StartDependencyCategory(localLine);
}
else
{
var splitterOrDefault = ComponentSplitters.FirstOrDefault(x => localLine.Contains(x));
if (splitterOrDefault != null)
{
TrackDependency(line.IndexOf(splitterOrDefault), localLine.Split(new[] { splitterOrDefault }, StringSplitOptions.None)[1].Trim());
this.TrackDependency(line.IndexOf(splitterOrDefault), localLine.Split(new[] { splitterOrDefault }, StringSplitOptions.None)[1].Trim());
}
}
}
return DependencyCategory;
return this.DependencyCategory;
}
public void Parse(string[] lines, ISingleFileComponentRecorder singleFileComponentRecorder)
@ -56,10 +56,10 @@ namespace Microsoft.ComponentDetection.Detectors.Maven
foreach (var line in lines)
{
var localLine = line.Trim(TrimCharacters);
if (!string.IsNullOrWhiteSpace(localLine) && topLevelComponent == null)
if (!string.IsNullOrWhiteSpace(localLine) && this.topLevelComponent == null)
{
var topLevelMavenStringInfo = MavenParsingUtilities.GenerateDetectedComponentAndMetadataFromMavenString(localLine);
topLevelComponent = topLevelMavenStringInfo.Component;
this.topLevelComponent = topLevelMavenStringInfo.Component;
singleFileComponentRecorder.RegisterUsage(
topLevelMavenStringInfo.Component,
isDevelopmentDependency: topLevelMavenStringInfo.IsDevelopmentDependency,
@ -71,7 +71,7 @@ namespace Microsoft.ComponentDetection.Detectors.Maven
if (splitterOrDefault != null)
{
RecordDependencies(line.IndexOf(splitterOrDefault), localLine.Split(new[] { splitterOrDefault }, StringSplitOptions.None)[1].Trim(), singleFileComponentRecorder);
this.RecordDependencies(line.IndexOf(splitterOrDefault), localLine.Split(new[] { splitterOrDefault }, StringSplitOptions.None)[1].Trim(), singleFileComponentRecorder);
}
}
}
@ -79,40 +79,40 @@ namespace Microsoft.ComponentDetection.Detectors.Maven
private void TrackDependency(int position, string versionedComponent)
{
while (stack.Count > 0 && stack.Peek().ParseLevel >= position)
while (this.stack.Count > 0 && this.stack.Peek().ParseLevel >= position)
{
stack.Pop();
this.stack.Pop();
}
var myNode = new GraphNodeAtLevel<string>(position, versionedComponent);
if (stack.Count > 0)
if (this.stack.Count > 0)
{
var parent = stack.Peek();
var parent = this.stack.Peek();
parent.Children.Add(myNode);
myNode.Parents.Add(parent);
}
else
{
DependencyCategory.Children.Add(myNode);
this.DependencyCategory.Children.Add(myNode);
}
stack.Push(myNode);
this.stack.Push(myNode);
}
private void RecordDependencies(int position, string versionedComponent, ISingleFileComponentRecorder componentRecorder)
{
while (tupleStack.Count > 0 && tupleStack.Peek().ParseLevel >= position)
while (this.tupleStack.Count > 0 && this.tupleStack.Peek().ParseLevel >= position)
{
tupleStack.Pop();
this.tupleStack.Pop();
}
var componentAndDevDependencyTuple = MavenParsingUtilities.GenerateDetectedComponentAndMetadataFromMavenString(versionedComponent);
var newTuple = (ParseLevel: position, componentAndDevDependencyTuple.Component);
if (tupleStack.Count > 0)
if (this.tupleStack.Count > 0)
{
var parent = tupleStack.Peek().Component;
var parent = this.tupleStack.Peek().Component;
componentRecorder.RegisterUsage(parent);
componentRecorder.RegisterUsage(
newTuple.Component,
@ -125,12 +125,12 @@ namespace Microsoft.ComponentDetection.Detectors.Maven
componentRecorder.RegisterUsage(
newTuple.Component,
isExplicitReferencedDependency: true,
parentComponentId: topLevelComponent.Component.Id,
parentComponentId: this.topLevelComponent.Component.Id,
isDevelopmentDependency: componentAndDevDependencyTuple.IsDevelopmentDependency,
dependencyScope: componentAndDevDependencyTuple.dependencyScope);
}
tupleStack.Push(newTuple);
this.tupleStack.Push(newTuple);
}
private class GraphNodeAtLevel<T> : GraphNode<T>
@ -140,7 +140,7 @@ namespace Microsoft.ComponentDetection.Detectors.Maven
public GraphNodeAtLevel(int level, T value)
: base(value)
{
ParseLevel = level;
this.ParseLevel = level;
}
}
}

Просмотреть файл

@ -32,15 +32,15 @@ namespace Microsoft.ComponentDetection.Detectors.Maven
protected override async Task<IObservable<ProcessRequest>> OnPrepareDetection(IObservable<ProcessRequest> processRequests, IDictionary<string, string> detectorArgs)
{
if (!await MavenCommandService.MavenCLIExists())
if (!await this.MavenCommandService.MavenCLIExists())
{
Logger.LogVerbose("Skipping maven detection as maven is not available in the local PATH.");
this.Logger.LogVerbose("Skipping maven detection as maven is not available in the local PATH.");
return Enumerable.Empty<ProcessRequest>().ToObservable();
}
var processPomFile = new ActionBlock<ProcessRequest>(MavenCommandService.GenerateDependenciesFile);
var processPomFile = new ActionBlock<ProcessRequest>(this.MavenCommandService.GenerateDependenciesFile);
await RemoveNestedPomXmls(processRequests).ForEachAsync(processRequest =>
await this.RemoveNestedPomXmls(processRequests).ForEachAsync(processRequest =>
{
processPomFile.Post(processRequest);
});
@ -49,7 +49,8 @@ namespace Microsoft.ComponentDetection.Detectors.Maven
await processPomFile.Completion;
return ComponentStreamEnumerableFactory.GetComponentStreams(CurrentScanRequest.SourceDirectory, new[] { MavenCommandService.BcdeMvnDependencyFileName }, CurrentScanRequest.DirectoryExclusionPredicate)
return this.ComponentStreamEnumerableFactory.GetComponentStreams(this.CurrentScanRequest.SourceDirectory, new[] {
this.MavenCommandService.BcdeMvnDependencyFileName }, this.CurrentScanRequest.DirectoryExclusionPredicate)
.Select(componentStream =>
{
// The file stream is going to be disposed after the iteration is finished
@ -64,7 +65,7 @@ namespace Microsoft.ComponentDetection.Detectors.Maven
Location = componentStream.Location,
Pattern = componentStream.Pattern,
},
SingleFileComponentRecorder = ComponentRecorder.CreateSingleFileComponentRecorder(
SingleFileComponentRecorder = this.ComponentRecorder.CreateSingleFileComponentRecorder(
Path.Combine(Path.GetDirectoryName(componentStream.Location), "pom.xml")),
};
})
@ -73,7 +74,7 @@ namespace Microsoft.ComponentDetection.Detectors.Maven
protected override async Task OnFileFound(ProcessRequest processRequest, IDictionary<string, string> detectorArgs)
{
MavenCommandService.ParseDependenciesFile(processRequest);
this.MavenCommandService.ParseDependenciesFile(processRequest);
File.Delete(processRequest.ComponentStream.Location);
@ -135,7 +136,7 @@ namespace Microsoft.ComponentDetection.Detectors.Maven
if (last != null && current.Files.FirstOrDefault(x => string.Equals(Path.GetFileName(x.Location), "pom.xml", StringComparison.OrdinalIgnoreCase)) != null)
{
Logger.LogVerbose($"Ignoring pom.xml at {item.Location}, as it has a parent pom.xml that will be processed at {current.Name}\\pom.xml .");
this.Logger.LogVerbose($"Ignoring pom.xml at {item.Location}, as it has a parent pom.xml that will be processed at {current.Name}\\pom.xml .");
break;
}

Просмотреть файл

@ -43,16 +43,16 @@ namespace Microsoft.ComponentDetection.Detectors.Npm
contents = await reader.ReadToEndAsync();
}
await SafeProcessAllPackageJTokens(filePath, contents, (token) =>
await this.SafeProcessAllPackageJTokens(filePath, contents, (token) =>
{
if (token["name"] == null || token["version"] == null)
{
Logger.LogInfo($"{filePath} does not contain a name and/or version. These are required fields for a valid package.json file." +
$"It and its dependencies will not be registered.");
this.Logger.LogInfo($"{filePath} does not contain a name and/or version. These are required fields for a valid package.json file." +
$"It and its dependencies will not be registered.");
return false;
}
return ProcessIndividualPackageJTokens(filePath, singleFileComponentRecorder, token);
return this.ProcessIndividualPackageJTokens(filePath, singleFileComponentRecorder, token);
});
}
@ -60,13 +60,13 @@ namespace Microsoft.ComponentDetection.Detectors.Npm
{
try
{
await ProcessAllPackageJTokensAsync(contents, jtokenProcessor);
await this.ProcessAllPackageJTokensAsync(contents, jtokenProcessor);
}
catch (Exception e)
{
// If something went wrong, just ignore the component
Logger.LogBuildWarning($"Could not parse Jtokens from file {sourceFilePath}.");
Logger.LogFailedReadingFile(sourceFilePath, e);
this.Logger.LogBuildWarning($"Could not parse Jtokens from file {sourceFilePath}.");
this.Logger.LogFailedReadingFile(sourceFilePath, e);
return;
}
}
@ -86,11 +86,11 @@ namespace Microsoft.ComponentDetection.Detectors.Npm
if (!SemanticVersion.TryParse(version, out _))
{
Logger.LogWarning($"Unable to parse version \"{version}\" for package \"{name}\" found at path \"{filePath}\". This may indicate an invalid npm package component and it will not be registered.");
this.Logger.LogWarning($"Unable to parse version \"{version}\" for package \"{name}\" found at path \"{filePath}\". This may indicate an invalid npm package component and it will not be registered.");
return false;
}
NpmComponent npmComponent = new NpmComponent(name, version, author: GetAuthor(authorToken, name, filePath));
NpmComponent npmComponent = new NpmComponent(name, version, author: this.GetAuthor(authorToken, name, filePath));
singleFileComponentRecorder.RegisterUsage(new DetectedComponent(npmComponent));
return true;
@ -135,13 +135,13 @@ namespace Microsoft.ComponentDetection.Detectors.Npm
}
else
{
Logger.LogWarning($"Unable to parse author:[{authorString}] for package:[{packageName}] found at path:[{filePath}]. This may indicate an invalid npm package author, and author will not be registered.");
this.Logger.LogWarning($"Unable to parse author:[{authorString}] for package:[{packageName}] found at path:[{filePath}]. This may indicate an invalid npm package author, and author will not be registered.");
return null;
}
if (string.IsNullOrEmpty(authorName))
{
Logger.LogWarning($"Unable to parse author:[{authorString}] for package:[{packageName}] found at path:[{filePath}]. This may indicate an invalid npm package author, and author will not be registered.");
this.Logger.LogWarning($"Unable to parse author:[{authorString}] for package:[{packageName}] found at path:[{filePath}]. This may indicate an invalid npm package author, and author will not be registered.");
return null;
}

Просмотреть файл

@ -49,15 +49,15 @@ namespace Microsoft.ComponentDetection.Detectors.Npm
protected override Task<IObservable<ProcessRequest>> OnPrepareDetection(IObservable<ProcessRequest> processRequests, IDictionary<string, string> detectorArgs)
{
return Task.FromResult(RemoveNodeModuleNestedFiles(processRequests)
return Task.FromResult(this.RemoveNodeModuleNestedFiles(processRequests)
.Where(pr =>
{
if (pr.ComponentStream.Pattern.Equals(LernaSearchPattern))
{
// Lock LernaFiles so we don't add while we are enumerating in processFiles
lock (lernaFilesLock)
lock (this.lernaFilesLock)
{
LernaFiles.Add(pr);
this.LernaFiles.Add(pr);
return false;
}
}
@ -72,15 +72,15 @@ namespace Microsoft.ComponentDetection.Detectors.Npm
var singleFileComponentRecorder = processRequest.SingleFileComponentRecorder;
var file = processRequest.ComponentStream;
IEnumerable<IComponentStream> packageJsonComponentStream = ComponentStreamEnumerableFactory.GetComponentStreams(new FileInfo(file.Location).Directory, packageJsonPattern, (name, directoryName) => false, false);
IEnumerable<IComponentStream> packageJsonComponentStream = this.ComponentStreamEnumerableFactory.GetComponentStreams(new FileInfo(file.Location).Directory, packageJsonPattern, (name, directoryName) => false, false);
bool foundUnderLerna = false;
IList<ProcessRequest> lernaFilesClone;
// ToList LernaFiles to generate a copy we can act on without holding the lock for a long time
lock (lernaFilesLock)
lock (this.lernaFilesLock)
{
lernaFilesClone = LernaFiles.ToList();
lernaFilesClone = this.LernaFiles.ToList();
}
foreach (var lernaProcessRequest in lernaFilesClone)
@ -88,23 +88,23 @@ namespace Microsoft.ComponentDetection.Detectors.Npm
var lernaFile = lernaProcessRequest.ComponentStream;
// We have extra validation on lock files not found below a lerna.json
if (PathUtilityService.IsFileBelowAnother(lernaFile.Location, file.Location))
if (this.PathUtilityService.IsFileBelowAnother(lernaFile.Location, file.Location))
{
foundUnderLerna = true;
break;
}
}
await SafeProcessAllPackageJTokens(file, (token) =>
await this.SafeProcessAllPackageJTokens(file, (token) =>
{
if (!foundUnderLerna && (token["name"] == null || token["version"] == null || string.IsNullOrWhiteSpace(token["name"].Value<string>()) || string.IsNullOrWhiteSpace(token["version"].Value<string>())))
{
Logger.LogInfo($"{file.Location} does not contain a valid name and/or version. These are required fields for a valid package-lock.json file." +
$"It and its dependencies will not be registered.");
this.Logger.LogInfo($"{file.Location} does not contain a valid name and/or version. These are required fields for a valid package-lock.json file." +
$"It and its dependencies will not be registered.");
return false;
}
ProcessIndividualPackageJTokens(singleFileComponentRecorder, token, packageJsonComponentStream, skipValidation: foundUnderLerna);
this.ProcessIndividualPackageJTokens(singleFileComponentRecorder, token, packageJsonComponentStream, skipValidation: foundUnderLerna);
return true;
});
}
@ -124,7 +124,7 @@ namespace Microsoft.ComponentDetection.Detectors.Npm
DirectoryItemFacade last = null;
do
{
currentDir = PathUtilityService.GetParentDirectory(currentDir);
currentDir = this.PathUtilityService.GetParentDirectory(currentDir);
// We've reached the top / root
if (currentDir == null)
@ -135,7 +135,7 @@ namespace Microsoft.ComponentDetection.Detectors.Npm
directoryItemFacades.Add(last);
}
string skippedFolder = SkippedFolders.FirstOrDefault(folder => item.Location.Contains(folder));
string skippedFolder = this.SkippedFolders.FirstOrDefault(folder => item.Location.Contains(folder));
// When node_modules is part of the path down to a given item, we skip the item. Otherwise, we yield the item.
if (string.IsNullOrEmpty(skippedFolder))
@ -144,7 +144,7 @@ namespace Microsoft.ComponentDetection.Detectors.Npm
}
else
{
Logger.LogVerbose($"Ignoring package-lock.json at {item.Location}, as it is inside a {skippedFolder} folder.");
this.Logger.LogVerbose($"Ignoring package-lock.json at {item.Location}, as it is inside a {skippedFolder} folder.");
}
break;
@ -186,13 +186,13 @@ namespace Microsoft.ComponentDetection.Detectors.Npm
{
try
{
await ProcessAllPackageJTokensAsync(componentStream, jtokenProcessor);
await this.ProcessAllPackageJTokensAsync(componentStream, jtokenProcessor);
}
catch (Exception e)
{
// If something went wrong, just ignore the component
Logger.LogBuildWarning($"Could not parse Jtokens from {componentStream.Location} file.");
Logger.LogFailedReadingFile(componentStream.Location, e);
this.Logger.LogBuildWarning($"Could not parse Jtokens from {componentStream.Location} file.");
this.Logger.LogFailedReadingFile(componentStream.Location, e);
return;
}
}
@ -208,8 +208,8 @@ namespace Microsoft.ComponentDetection.Detectors.Npm
}
catch (Exception ex)
{
Logger.LogBuildWarning($"Could not read {componentStream.Location} file.");
Logger.LogFailedReadingFile(componentStream.Location, ex);
this.Logger.LogBuildWarning($"Could not read {componentStream.Location} file.");
this.Logger.LogFailedReadingFile(componentStream.Location, ex);
return Task.CompletedTask;
}
@ -234,8 +234,8 @@ namespace Microsoft.ComponentDetection.Detectors.Npm
using JsonTextReader reader = new JsonTextReader(file);
var packageJsonToken = JToken.ReadFrom(reader);
bool enqueued = TryEnqueueFirstLevelDependencies(topLevelDependencies, packageJsonToken["dependencies"], dependencyLookup, skipValidation: skipValidation);
enqueued = enqueued && TryEnqueueFirstLevelDependencies(topLevelDependencies, packageJsonToken["devDependencies"], dependencyLookup, skipValidation: skipValidation);
bool enqueued = this.TryEnqueueFirstLevelDependencies(topLevelDependencies, packageJsonToken["dependencies"], dependencyLookup, skipValidation: skipValidation);
enqueued = enqueued && this.TryEnqueueFirstLevelDependencies(topLevelDependencies, packageJsonToken["devDependencies"], dependencyLookup, skipValidation: skipValidation);
if (!enqueued)
{
// This represents a mismatch between lock file and package.json, break out and do not register anything for these files
@ -248,7 +248,7 @@ namespace Microsoft.ComponentDetection.Detectors.Npm
throw new InvalidOperationException(string.Format("InvalidPackageJson -- There must be a package.json file at '{0}' for components to be registered", singleFileComponentRecorder.ManifestFileLocation));
}
TraverseRequirementAndDependencyTree(topLevelDependencies, dependencyLookup, singleFileComponentRecorder);
this.TraverseRequirementAndDependencyTree(topLevelDependencies, dependencyLookup, singleFileComponentRecorder);
}
private void TraverseRequirementAndDependencyTree(IEnumerable<(JProperty, TypedComponent)> topLevelDependencies, IDictionary<string, JProperty> dependencyLookup, ISingleFileComponentRecorder singleFileComponentRecorder)
@ -256,7 +256,7 @@ namespace Microsoft.ComponentDetection.Detectors.Npm
// iterate through everything for a top level dependency with a single explicitReferencedDependency value
foreach (var (currentDependency, _) in topLevelDependencies)
{
var typedComponent = NpmComponentUtilities.GetTypedComponent(currentDependency, NpmRegistryHost, Logger);
var typedComponent = NpmComponentUtilities.GetTypedComponent(currentDependency, NpmRegistryHost, this.Logger);
if (typedComponent == null)
{
continue;
@ -266,14 +266,14 @@ namespace Microsoft.ComponentDetection.Detectors.Npm
Queue<(JProperty, TypedComponent)> subQueue = new Queue<(JProperty, TypedComponent)>();
NpmComponentUtilities.TraverseAndRecordComponents(currentDependency, singleFileComponentRecorder, typedComponent, explicitReferencedDependency: typedComponent);
EnqueueDependencies(subQueue, currentDependency.Value["dependencies"], parentComponent: typedComponent);
TryEnqueueFirstLevelDependencies(subQueue, currentDependency.Value["requires"], dependencyLookup, parentComponent: typedComponent);
this.EnqueueDependencies(subQueue, currentDependency.Value["dependencies"], parentComponent: typedComponent);
this.TryEnqueueFirstLevelDependencies(subQueue, currentDependency.Value["requires"], dependencyLookup, parentComponent: typedComponent);
while (subQueue.Count != 0)
{
var (currentSubDependency, parentComponent) = subQueue.Dequeue();
var typedSubComponent = NpmComponentUtilities.GetTypedComponent(currentSubDependency, NpmRegistryHost, Logger);
var typedSubComponent = NpmComponentUtilities.GetTypedComponent(currentSubDependency, NpmRegistryHost, this.Logger);
// only process components that we haven't seen before that have been brought in by the same explicitReferencedDependency, resolves circular npm 'requires' loop
if (typedSubComponent == null || previouslyAddedComponents.Contains(typedSubComponent.Id))
@ -285,8 +285,8 @@ namespace Microsoft.ComponentDetection.Detectors.Npm
NpmComponentUtilities.TraverseAndRecordComponents(currentSubDependency, singleFileComponentRecorder, typedSubComponent, explicitReferencedDependency: typedComponent, parentComponent.Id);
EnqueueDependencies(subQueue, currentSubDependency.Value["dependencies"], parentComponent: typedSubComponent);
TryEnqueueFirstLevelDependencies(subQueue, currentSubDependency.Value["requires"], dependencyLookup, parentComponent: typedSubComponent);
this.EnqueueDependencies(subQueue, currentSubDependency.Value["dependencies"], parentComponent: typedSubComponent);
this.TryEnqueueFirstLevelDependencies(subQueue, currentSubDependency.Value["requires"], dependencyLookup, parentComponent: typedSubComponent);
}
}
}
@ -336,4 +336,4 @@ namespace Microsoft.ComponentDetection.Detectors.Npm
return isValid;
}
}
}
}

Просмотреть файл

@ -40,11 +40,11 @@ namespace Microsoft.ComponentDetection.Detectors.NuGet
if (NugetConfigFileName.Equals(stream.Pattern, StringComparison.OrdinalIgnoreCase))
{
await ProcessAdditionalDirectory(processRequest, ignoreNugetConfig);
await this.ProcessAdditionalDirectory(processRequest, ignoreNugetConfig);
}
else
{
await ProcessFile(processRequest);
await this.ProcessFile(processRequest);
}
}
@ -55,21 +55,21 @@ namespace Microsoft.ComponentDetection.Detectors.NuGet
if (!ignoreNugetConfig)
{
var additionalPaths = GetRepositoryPathsFromNugetConfig(stream);
Uri rootPath = new Uri(CurrentScanRequest.SourceDirectory.FullName + Path.DirectorySeparatorChar);
var additionalPaths = this.GetRepositoryPathsFromNugetConfig(stream);
Uri rootPath = new Uri(this.CurrentScanRequest.SourceDirectory.FullName + Path.DirectorySeparatorChar);
foreach (var additionalPath in additionalPaths)
{
// Only paths outside of our sourceDirectory need to be added
if (!rootPath.IsBaseOf(new Uri(additionalPath.FullName + Path.DirectorySeparatorChar)))
{
Logger.LogInfo($"Found path override in nuget configuration file. Adding {additionalPath} to the package search path.");
Logger.LogWarning($"Path {additionalPath} is not rooted in the source tree. More components may be detected than expected if this path is shared across code projects.");
this.Logger.LogInfo($"Found path override in nuget configuration file. Adding {additionalPath} to the package search path.");
this.Logger.LogWarning($"Path {additionalPath} is not rooted in the source tree. More components may be detected than expected if this path is shared across code projects.");
Scanner.Initialize(additionalPath, (name, directoryName) => false, 1);
this.Scanner.Initialize(additionalPath, (name, directoryName) => false, 1);
await Scanner.GetFilteredComponentStreamObservable(additionalPath, SearchPatterns.Where(sp => !NugetConfigFileName.Equals(sp)), singleFileComponentRecorder.GetParentComponentRecorder())
.ForEachAsync(async fi => await ProcessFile(fi));
await this.Scanner.GetFilteredComponentStreamObservable(additionalPath, this.SearchPatterns.Where(sp => !NugetConfigFileName.Equals(sp)), singleFileComponentRecorder.GetParentComponentRecorder())
.ForEachAsync(async fi => await this.ProcessFile(fi));
}
}
}
@ -112,7 +112,7 @@ namespace Microsoft.ComponentDetection.Detectors.NuGet
if (!NuGetVersion.TryParse(version, out NuGetVersion parsedVer))
{
Logger.LogInfo($"Version '{version}' from {stream.Location} could not be parsed as a NuGet version");
this.Logger.LogInfo($"Version '{version}' from {stream.Location} could not be parsed as a NuGet version");
return;
}
@ -126,7 +126,7 @@ namespace Microsoft.ComponentDetection.Detectors.NuGet
catch (Exception e)
{
// If something went wrong, just ignore the component
Logger.LogFailedReadingFile(stream.Location, e);
this.Logger.LogFailedReadingFile(stream.Location, e);
}
}
@ -149,7 +149,7 @@ namespace Microsoft.ComponentDetection.Detectors.NuGet
foreach (var entry in config.Elements())
{
if (entry.Attributes().Any(x => repositoryPathKeyNames.Contains(x.Value.ToLower())))
if (entry.Attributes().Any(x => this.repositoryPathKeyNames.Contains(x.Value.ToLower())))
{
string value = entry.Attributes().SingleOrDefault(x => string.Equals(x.Name.LocalName, "value", StringComparison.OrdinalIgnoreCase))?.Value;
@ -174,13 +174,13 @@ namespace Microsoft.ComponentDetection.Detectors.NuGet
{
path = new DirectoryInfo(Path.GetFullPath(potentialPath));
}
else if (IsValidPath(componentStream.Location))
else if (this.IsValidPath(componentStream.Location))
{
path = new DirectoryInfo(Path.GetFullPath(Path.Combine(Path.GetDirectoryName(componentStream.Location), potentialPath)));
}
else
{
Logger.LogWarning($"Excluding discovered path {potentialPath} from location {componentStream.Location} as it could not be determined to be valid.");
this.Logger.LogWarning($"Excluding discovered path {potentialPath} from location {componentStream.Location} as it could not be determined to be valid.");
continue;
}

Просмотреть файл

@ -52,10 +52,9 @@ namespace Microsoft.ComponentDetection.Detectors.NuGet
throw new FormatException("Lockfile did not contain a PackageSpec");
}
HashSet<string> frameworkComponents = GetFrameworkComponents(lockFile);
var explicitReferencedDependencies =
GetTopLevelLibraries(lockFile)
.Select(x => GetLibraryComponentWithDependencyLookup(lockFile.Libraries, x.name, x.version, x.versionRange))
HashSet<string> frameworkComponents = this.GetFrameworkComponents(lockFile);
var explicitReferencedDependencies = this.GetTopLevelLibraries(lockFile)
.Select(x => this.GetLibraryComponentWithDependencyLookup(lockFile.Libraries, x.name, x.version, x.versionRange))
.ToList();
var explicitlyReferencedComponentIds =
explicitReferencedDependencies
@ -63,20 +62,20 @@ namespace Microsoft.ComponentDetection.Detectors.NuGet
.ToHashSet();
// Since we report projects as the location, we ignore the passed in single file recorder.
var singleFileComponentRecorder = ComponentRecorder.CreateSingleFileComponentRecorder(lockFile.PackageSpec.RestoreMetadata.ProjectPath);
var singleFileComponentRecorder = this.ComponentRecorder.CreateSingleFileComponentRecorder(lockFile.PackageSpec.RestoreMetadata.ProjectPath);
foreach (var target in lockFile.Targets)
{
// This call to GetTargetLibrary is not guarded, because if this can't be resolved then something is fundamentally broken (e.g. an explicit dependency reference not being in the list of libraries)
foreach (var library in explicitReferencedDependencies.Select(x => target.GetTargetLibrary(x.Name)).Where(x => x != null))
{
NavigateAndRegister(target, explicitlyReferencedComponentIds, singleFileComponentRecorder, library, null, frameworkComponents);
this.NavigateAndRegister(target, explicitlyReferencedComponentIds, singleFileComponentRecorder, library, null, frameworkComponents);
}
}
}
catch (Exception e)
{
// If something went wrong, just ignore the package
Logger.LogFailedReadingFile(processRequest.ComponentStream.Location, e);
this.Logger.LogFailedReadingFile(processRequest.ComponentStream.Location, e);
}
return Task.CompletedTask;
@ -84,7 +83,7 @@ namespace Microsoft.ComponentDetection.Detectors.NuGet
protected override Task OnDetectionFinished()
{
Telemetry.Add(OmittedFrameworkComponentsTelemetryKey, JsonConvert.SerializeObject(frameworkComponentsThatWereOmmittedWithCount));
this.Telemetry.Add(OmittedFrameworkComponentsTelemetryKey, JsonConvert.SerializeObject(this.frameworkComponentsThatWereOmmittedWithCount));
return Task.CompletedTask;
}
@ -98,8 +97,8 @@ namespace Microsoft.ComponentDetection.Detectors.NuGet
HashSet<string> dotnetRuntimePackageNames,
HashSet<string> visited = null)
{
if (IsAFrameworkComponent(dotnetRuntimePackageNames, library.Name, library.Dependencies)
|| library.Type == ProjectDependencyType)
if (this.IsAFrameworkComponent(dotnetRuntimePackageNames, library.Name, library.Dependencies)
|| library.Type == ProjectDependencyType)
{
return;
}
@ -127,7 +126,7 @@ namespace Microsoft.ComponentDetection.Detectors.NuGet
else
{
visited.Add(dependency.Id);
NavigateAndRegister(target, explicitlyReferencedComponentIds, singleFileComponentRecorder, targetLibrary, libraryComponent.Component.Id, dotnetRuntimePackageNames, visited);
this.NavigateAndRegister(target, explicitlyReferencedComponentIds, singleFileComponentRecorder, targetLibrary, libraryComponent.Component.Id, dotnetRuntimePackageNames, visited);
}
}
}
@ -138,14 +137,14 @@ namespace Microsoft.ComponentDetection.Detectors.NuGet
if (isAFrameworkComponent)
{
frameworkComponentsThatWereOmmittedWithCount.AddOrUpdate(libraryName, 1, (name, existing) => existing + 1);
this.frameworkComponentsThatWereOmmittedWithCount.AddOrUpdate(libraryName, 1, (name, existing) => existing + 1);
if (dependencies != null)
{
// Also track shallow children if this is a top level library so we have a rough count of how many things have been ommitted + root relationships
foreach (var item in dependencies)
{
frameworkComponentsThatWereOmmittedWithCount.AddOrUpdate(item.Id, 1, (name, existing) => existing + 1);
this.frameworkComponentsThatWereOmmittedWithCount.AddOrUpdate(item.Id, 1, (name, existing) => existing + 1);
}
}
}
@ -219,10 +218,10 @@ namespace Microsoft.ComponentDetection.Detectors.NuGet
{
matchingLibrary = matchingLibraryNames.First();
string logMessage = $"Couldn't satisfy lookup for {(versionRange != null ? versionRange.ToNormalizedString() : version.ToString())}. Falling back to first found component for {matchingLibrary.Name}, resolving to version {matchingLibrary.Version}.";
if (!alreadyLoggedWarnings.Contains(logMessage))
if (!this.alreadyLoggedWarnings.Contains(logMessage))
{
Logger.LogWarning(logMessage);
alreadyLoggedWarnings.Add(logMessage);
this.Logger.LogWarning(logMessage);
this.alreadyLoggedWarnings.Add(logMessage);
}
}
@ -234,24 +233,24 @@ namespace Microsoft.ComponentDetection.Detectors.NuGet
var frameworkDependencies = new HashSet<string>();
foreach (var projectFileDependencyGroup in lockFile.ProjectFileDependencyGroups)
{
var topLevelLibraries = GetTopLevelLibraries(lockFile);
var topLevelLibraries = this.GetTopLevelLibraries(lockFile);
foreach (var (name, version, versionRange) in topLevelLibraries)
{
if (netCoreFrameworkNames.Contains(name))
if (this.netCoreFrameworkNames.Contains(name))
{
frameworkDependencies.Add(name);
foreach (var target in lockFile.Targets)
{
var matchingLibrary = target.Libraries.FirstOrDefault(x => x.Name == name);
HashSet<string> dependencyComponents = GetDependencyComponentIds(lockFile, target, matchingLibrary.Dependencies);
HashSet<string> dependencyComponents = this.GetDependencyComponentIds(lockFile, target, matchingLibrary.Dependencies);
frameworkDependencies.UnionWith(dependencyComponents);
}
}
}
}
foreach (var netstandardDep in netStandardDependencies)
foreach (var netstandardDep in this.netStandardDependencies)
{
frameworkDependencies.Add(netstandardDep);
}
@ -279,7 +278,7 @@ namespace Microsoft.ComponentDetection.Detectors.NuGet
else
{
visited.Add(dependency.Id);
currentComponents.UnionWith(GetDependencyComponentIds(lockFile, target, libraryToExpand.Dependencies, visited));
currentComponents.UnionWith(this.GetDependencyComponentIds(lockFile, target, libraryToExpand.Dependencies, visited));
}
}

Просмотреть файл

@ -63,7 +63,7 @@ namespace Microsoft.ComponentDetection.Detectors.Pip
public PyPiClient()
{
cacheTelemetry = new PypiCacheTelemetryRecord()
this.cacheTelemetry = new PypiCacheTelemetryRecord()
{
NumCacheHits = 0,
FinalCacheSize = 0,
@ -72,8 +72,8 @@ namespace Microsoft.ComponentDetection.Detectors.Pip
~PyPiClient()
{
cacheTelemetry.FinalCacheSize = cachedResponses.Count;
cacheTelemetry.Dispose();
this.cacheTelemetry.FinalCacheSize = this.cachedResponses.Count;
this.cacheTelemetry.Dispose();
}
/// <summary>
@ -84,23 +84,23 @@ namespace Microsoft.ComponentDetection.Detectors.Pip
/// <returns>The cached response or a new result from PyPi.</returns>
private async Task<HttpResponseMessage> GetAndCachePyPiResponse(string uri)
{
if (!checkedMaxEntriesVariable)
if (!this.checkedMaxEntriesVariable)
{
InitializeNonDefaultMemoryCache();
this.InitializeNonDefaultMemoryCache();
}
if (cachedResponses.TryGetValue(uri, out HttpResponseMessage result))
if (this.cachedResponses.TryGetValue(uri, out HttpResponseMessage result))
{
cacheTelemetry.NumCacheHits++;
Logger.LogVerbose("Retrieved cached Python data from " + uri);
this.cacheTelemetry.NumCacheHits++;
this.Logger.LogVerbose("Retrieved cached Python data from " + uri);
return result;
}
Logger.LogInfo("Getting Python data from " + uri);
this.Logger.LogInfo("Getting Python data from " + uri);
var response = await HttpClient.GetAsync(uri);
// The `first - wins` response accepted into the cache. This might be different from the input if another caller wins the race.
return await cachedResponses.GetOrCreateAsync(uri, cacheEntry =>
return await this.cachedResponses.GetOrCreateAsync(uri, cacheEntry =>
{
cacheEntry.SlidingExpiration = TimeSpan.FromSeconds(CACHEINTERVALSECONDS); // This entry will expire after CACHEINTERVALSECONDS seconds from last use
cacheEntry.Size = 1; // Specify a size of 1 so a set number of entries can always be in the cache
@ -114,14 +114,14 @@ namespace Microsoft.ComponentDetection.Detectors.Pip
/// </summary>
private void InitializeNonDefaultMemoryCache()
{
var maxEntriesVariable = EnvironmentVariableService.GetEnvironmentVariable("PyPiMaxCacheEntries");
var maxEntriesVariable = this.EnvironmentVariableService.GetEnvironmentVariable("PyPiMaxCacheEntries");
if (!string.IsNullOrEmpty(maxEntriesVariable) && long.TryParse(maxEntriesVariable, out var maxEntries))
{
Logger.LogInfo($"Setting IPyPiClient max cache entries to {maxEntries}");
cachedResponses = new MemoryCache(new MemoryCacheOptions { SizeLimit = maxEntries });
this.Logger.LogInfo($"Setting IPyPiClient max cache entries to {maxEntries}");
this.cachedResponses = new MemoryCache(new MemoryCacheOptions { SizeLimit = maxEntries });
}
checkedMaxEntriesVariable = true;
this.checkedMaxEntriesVariable = true;
}
public async Task<IList<PipDependencySpecification>> FetchPackageDependencies(string name, string version, PythonProjectRelease release)
@ -129,11 +129,11 @@ namespace Microsoft.ComponentDetection.Detectors.Pip
var dependencies = new List<PipDependencySpecification>();
var uri = release.Url.ToString();
var response = await GetAndCachePyPiResponse(uri);
var response = await this.GetAndCachePyPiResponse(uri);
if (!response.IsSuccessStatusCode)
{
Logger.LogWarning($"Http GET at {release.Url} failed with status code {response.StatusCode}");
this.Logger.LogWarning($"Http GET at {release.Url} failed with status code {response.StatusCode}");
return dependencies;
}
@ -197,25 +197,25 @@ namespace Microsoft.ComponentDetection.Detectors.Pip
{
using var r = new PypiRetryTelemetryRecord { Name = spec.Name, DependencySpecifiers = spec.DependencySpecifiers?.ToArray(), StatusCode = result.Result.StatusCode };
Logger.LogWarning($"Received {(int)result.Result.StatusCode} {result.Result.ReasonPhrase} from {requestUri}. Waiting {timeSpan} before retry attempt {retryCount}");
this.Logger.LogWarning($"Received {(int)result.Result.StatusCode} {result.Result.ReasonPhrase} from {requestUri}. Waiting {timeSpan} before retry attempt {retryCount}");
Interlocked.Increment(ref retries);
Interlocked.Increment(ref this.retries);
})
.ExecuteAsync(() =>
{
if (Interlocked.Read(ref retries) >= MAXRETRIES)
if (Interlocked.Read(ref this.retries) >= MAXRETRIES)
{
return Task.FromResult<HttpResponseMessage>(null);
}
return GetAndCachePyPiResponse(requestUri);
return this.GetAndCachePyPiResponse(requestUri);
});
if (request == null)
{
using var r = new PypiMaxRetriesReachedTelemetryRecord { Name = spec.Name, DependencySpecifiers = spec.DependencySpecifiers?.ToArray() };
Logger.LogWarning($"Call to pypi.org failed, but no more retries allowed!");
this.Logger.LogWarning($"Call to pypi.org failed, but no more retries allowed!");
return new SortedDictionary<string, IList<PythonProjectRelease>>();
}
@ -224,7 +224,7 @@ namespace Microsoft.ComponentDetection.Detectors.Pip
{
using var r = new PypiFailureTelemetryRecord { Name = spec.Name, DependencySpecifiers = spec.DependencySpecifiers?.ToArray(), StatusCode = request.StatusCode };
Logger.LogWarning($"Received {(int)request.StatusCode} {request.ReasonPhrase} from {requestUri}");
this.Logger.LogWarning($"Received {(int)request.StatusCode} {request.ReasonPhrase} from {requestUri}");
return new SortedDictionary<string, IList<PythonProjectRelease>>();
}
@ -247,8 +247,8 @@ namespace Microsoft.ComponentDetection.Detectors.Pip
}
catch (ArgumentException ae)
{
Logger.LogError($"Component {release.Key} : {JsonConvert.SerializeObject(release.Value)} could not be added to the sorted list of pip components for spec={spec.Name}. Usually this happens with unexpected PyPi version formats (e.g. prerelease/dev versions). Error details follow:");
Logger.LogException(ae, true);
this.Logger.LogError($"Component {release.Key} : {JsonConvert.SerializeObject(release.Value)} could not be added to the sorted list of pip components for spec={spec.Name}. Usually this happens with unexpected PyPi version formats (e.g. prerelease/dev versions). Error details follow:");
this.Logger.LogException(ae, true);
continue;
}
}

Просмотреть файл

@ -31,10 +31,10 @@ namespace Microsoft.ComponentDetection.Detectors.Pip
protected override async Task<IObservable<ProcessRequest>> OnPrepareDetection(IObservable<ProcessRequest> processRequests, IDictionary<string, string> detectorArgs)
{
CurrentScanRequest.DetectorArgs.TryGetValue("Pip.PythonExePath", out string pythonExePath);
if (!await PythonCommandService.PythonExists(pythonExePath))
this.CurrentScanRequest.DetectorArgs.TryGetValue("Pip.PythonExePath", out string pythonExePath);
if (!await this.PythonCommandService.PythonExists(pythonExePath))
{
Logger.LogInfo($"No python found on system. Python detection will not run.");
this.Logger.LogInfo($"No python found on system. Python detection will not run.");
return Enumerable.Empty<ProcessRequest>().ToObservable();
}
@ -44,13 +44,13 @@ namespace Microsoft.ComponentDetection.Detectors.Pip
protected override async Task OnFileFound(ProcessRequest processRequest, IDictionary<string, string> detectorArgs)
{
CurrentScanRequest.DetectorArgs.TryGetValue("Pip.PythonExePath", out string pythonExePath);
this.CurrentScanRequest.DetectorArgs.TryGetValue("Pip.PythonExePath", out string pythonExePath);
var singleFileComponentRecorder = processRequest.SingleFileComponentRecorder;
var file = processRequest.ComponentStream;
try
{
var initialPackages = await PythonCommandService.ParseFile(file.Location, pythonExePath);
var initialPackages = await this.PythonCommandService.ParseFile(file.Location, pythonExePath);
var listedPackage = initialPackages.Where(tuple => tuple.Item1 != null)
.Select(tuple => tuple.Item1)
.Where(x => !string.IsNullOrWhiteSpace(x))
@ -58,7 +58,7 @@ namespace Microsoft.ComponentDetection.Detectors.Pip
.Where(x => !x.PackageIsUnsafe())
.ToList();
var roots = await PythonResolver.ResolveRoots(listedPackage);
var roots = await this.PythonResolver.ResolveRoots(listedPackage);
RecordComponents(
singleFileComponentRecorder,
@ -71,7 +71,7 @@ namespace Microsoft.ComponentDetection.Detectors.Pip
}
catch (Exception e)
{
Logger.LogFailedReadingFile(file.Location, e);
this.Logger.LogFailedReadingFile(file.Location, e);
}
}
@ -121,4 +121,4 @@ namespace Microsoft.ComponentDetection.Detectors.Pip
}
}
}
}
}

Просмотреть файл

@ -11,7 +11,7 @@ namespace Microsoft.ComponentDetection.Detectors.Pip
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class PipDependencySpecification
{
private string DebuggerDisplay => $"{Name} ({string.Join(';', DependencySpecifiers)})";
private string DebuggerDisplay => $"{this.Name} ({string.Join(';', this.DependencySpecifiers)})";
/// <summary>
/// Gets or sets the package <see cref="Name"/> (ex: pyyaml).
@ -58,7 +58,7 @@ namespace Microsoft.ComponentDetection.Detectors.Pip
/// <returns></returns>
public bool PackageIsUnsafe()
{
return PackagesToIgnore.Contains(Name);
return PackagesToIgnore.Contains(this.Name);
}
/// <summary>
@ -86,13 +86,13 @@ namespace Microsoft.ComponentDetection.Detectors.Pip
continue;
}
if (string.IsNullOrWhiteSpace(Name))
if (string.IsNullOrWhiteSpace(this.Name))
{
Name = distMatch.Groups[i].Value;
this.Name = distMatch.Groups[i].Value;
}
else
{
DependencySpecifiers = distMatch.Groups[i].Value.Split(',');
this.DependencySpecifiers = distMatch.Groups[i].Value.Split(',');
}
}
}
@ -103,20 +103,20 @@ namespace Microsoft.ComponentDetection.Detectors.Pip
if (nameMatches.Captures.Count > 0)
{
Name = nameMatches.Captures[0].Value;
this.Name = nameMatches.Captures[0].Value;
}
else
{
Name = packageString;
this.Name = packageString;
}
if (versionMatches.Captures.Count > 0)
{
DependencySpecifiers = versionMatches.Captures[0].Value.Split(',');
this.DependencySpecifiers = versionMatches.Captures[0].Value.Split(',');
}
}
DependencySpecifiers = DependencySpecifiers.Where(x => !x.Contains("python_version")).ToList();
this.DependencySpecifiers = this.DependencySpecifiers.Where(x => !x.Contains("python_version")).ToList();
}
}
}
}

Просмотреть файл

@ -11,7 +11,7 @@ namespace Microsoft.ComponentDetection.Detectors.Pip
{
public PipGraphNode(PipComponent value)
{
Value = value;
this.Value = value;
}
public PipComponent Value { get; set; }
@ -20,4 +20,4 @@ namespace Microsoft.ComponentDetection.Detectors.Pip
public List<PipGraphNode> Parents { get; } = new List<PipGraphNode>();
}
}
}

Просмотреть файл

@ -18,7 +18,7 @@ namespace Microsoft.ComponentDetection.Detectors.Pip
public async Task<bool> PythonExists(string pythonPath = null)
{
return !string.IsNullOrEmpty(await ResolvePython(pythonPath));
return !string.IsNullOrEmpty(await this.ResolvePython(pythonPath));
}
public async Task<IList<(string, GitComponent)>> ParseFile(string filePath, string pythonPath = null)
@ -30,13 +30,13 @@ namespace Microsoft.ComponentDetection.Detectors.Pip
if (filePath.EndsWith(".py"))
{
return (await ParseSetupPyFile(filePath, pythonPath))
return (await this.ParseSetupPyFile(filePath, pythonPath))
.Select<string, (string, GitComponent)>(component => (component, null))
.ToList();
}
else if (filePath.EndsWith(".txt"))
{
return ParseRequirementsTextFile(filePath);
return this.ParseRequirementsTextFile(filePath);
}
else
{
@ -46,7 +46,7 @@ namespace Microsoft.ComponentDetection.Detectors.Pip
private async Task<IList<string>> ParseSetupPyFile(string filePath, string pythonExePath = null)
{
var pythonExecutable = await ResolvePython(pythonExePath);
var pythonExecutable = await this.ResolvePython(pythonExePath);
if (string.IsNullOrEmpty(pythonExecutable))
{
@ -55,7 +55,7 @@ namespace Microsoft.ComponentDetection.Detectors.Pip
// This calls out to python and prints out an array like: [ packageA, packageB, packageC ]
// We need to have python interpret this file because install_requires can be composed at runtime
var command = await CommandLineInvocationService.ExecuteCommand(pythonExecutable, null, $"-c \"import distutils.core; setup=distutils.core.run_setup('{filePath.Replace('\\', '/')}'); print(setup.install_requires)\"");
var command = await this.CommandLineInvocationService.ExecuteCommand(pythonExecutable, null, $"-c \"import distutils.core; setup=distutils.core.run_setup('{filePath.Replace('\\', '/')}'); print(setup.install_requires)\"");
if (command.ExitCode != 0)
{
@ -130,7 +130,7 @@ namespace Microsoft.ComponentDetection.Detectors.Pip
{
string pythonCommand = string.IsNullOrEmpty(pythonPath) ? "python" : pythonPath;
if (await CanCommandBeLocated(pythonCommand))
if (await this.CanCommandBeLocated(pythonCommand))
{
return pythonCommand;
}
@ -140,7 +140,7 @@ namespace Microsoft.ComponentDetection.Detectors.Pip
private async Task<bool> CanCommandBeLocated(string pythonPath)
{
return await CommandLineInvocationService.CanCommandBeLocated(pythonPath, new List<string> { "python3", "python2" }, "--version");
return await this.CommandLineInvocationService.CanCommandBeLocated(pythonPath, new List<string> { "python3", "python2" }, "--version");
}
}
}

Просмотреть файл

@ -32,7 +32,7 @@ namespace Microsoft.ComponentDetection.Detectors.Pip
// If we have it, we probably just want to skip at this phase as this indicates duplicates
if (!state.ValidVersionMap.TryGetValue(rootPackage.Name, out _))
{
var result = await PypiClient.GetReleases(rootPackage);
var result = await this.PypiClient.GetReleases(rootPackage);
if (result.Keys.Any())
{
@ -52,13 +52,13 @@ namespace Microsoft.ComponentDetection.Detectors.Pip
}
else
{
Logger.LogWarning($"Root dependency {rootPackage.Name} not found on pypi. Skipping package.");
this.Logger.LogWarning($"Root dependency {rootPackage.Name} not found on pypi. Skipping package.");
}
}
}
// Now queue packages for processing
return await ProcessQueue(state) ?? new List<PipGraphNode>();
return await this.ProcessQueue(state) ?? new List<PipGraphNode>();
}
private async Task<IList<PipGraphNode>> ProcessQueue(PythonResolverState state)
@ -68,7 +68,7 @@ namespace Microsoft.ComponentDetection.Detectors.Pip
var (root, currentNode) = state.ProcessingQueue.Dequeue();
// gather all dependencies for the current node
var dependencies = (await FetchPackageDependencies(state, currentNode)).Where(x => !x.PackageIsUnsafe());
var dependencies = (await this.FetchPackageDependencies(state, currentNode)).Where(x => !x.PackageIsUnsafe());
foreach (var dependencyNode in dependencies)
{
@ -81,13 +81,13 @@ namespace Microsoft.ComponentDetection.Detectors.Pip
}
else if (node != null)
{
Logger.LogWarning($"Candidate version ({node.Value.Id}) for {dependencyNode.Name} already exists in map and the version is NOT valid.");
Logger.LogWarning($"Specifiers: {string.Join(',', dependencyNode.DependencySpecifiers)} for package {currentNode.Name} caused this.");
this.Logger.LogWarning($"Candidate version ({node.Value.Id}) for {dependencyNode.Name} already exists in map and the version is NOT valid.");
this.Logger.LogWarning($"Specifiers: {string.Join(',', dependencyNode.DependencySpecifiers)} for package {currentNode.Name} caused this.");
// The currently selected version is invalid, try to see if there is another valid version available
if (!await InvalidateAndReprocessAsync(state, node, dependencyNode))
if (!await this.InvalidateAndReprocessAsync(state, node, dependencyNode))
{
Logger.LogWarning($"Version Resolution for {dependencyNode.Name} failed, assuming last valid version is used.");
this.Logger.LogWarning($"Version Resolution for {dependencyNode.Name} failed, assuming last valid version is used.");
// there is no valid version available for the node, dependencies are incompatible,
}
@ -95,7 +95,7 @@ namespace Microsoft.ComponentDetection.Detectors.Pip
else
{
// We haven't encountered this package before, so let's fetch it and find a candidate
var result = await PypiClient.GetReleases(dependencyNode);
var result = await this.PypiClient.GetReleases(dependencyNode);
if (result.Keys.Any())
{
@ -103,13 +103,13 @@ namespace Microsoft.ComponentDetection.Detectors.Pip
var candidateVersion = state.ValidVersionMap[dependencyNode.Name].Keys.Any()
? state.ValidVersionMap[dependencyNode.Name].Keys.Last() : null;
AddGraphNode(state, state.NodeReferences[currentNode.Name], dependencyNode.Name, candidateVersion);
this.AddGraphNode(state, state.NodeReferences[currentNode.Name], dependencyNode.Name, candidateVersion);
state.ProcessingQueue.Enqueue((root, dependencyNode));
}
else
{
Logger.LogWarning($"Dependency Package {dependencyNode.Name} not found in Pypi. Skipping package");
this.Logger.LogWarning($"Dependency Package {dependencyNode.Name} not found in Pypi. Skipping package");
}
}
}
@ -146,7 +146,7 @@ namespace Microsoft.ComponentDetection.Detectors.Pip
node.Value = new PipComponent(pipComponent.Name, candidateVersion);
var dependencies = (await FetchPackageDependencies(state, newSpec)).ToDictionary(x => x.Name, x => x);
var dependencies = (await this.FetchPackageDependencies(state, newSpec)).ToDictionary(x => x.Name, x => x);
var toRemove = new List<PipGraphNode>();
foreach (var child in node.Children)
@ -159,7 +159,7 @@ namespace Microsoft.ComponentDetection.Detectors.Pip
}
else if (!PythonVersionUtilities.VersionValidForSpec(pipChild.Version, newDependency.DependencySpecifiers))
{
if (!await InvalidateAndReprocessAsync(state, child, newDependency))
if (!await this.InvalidateAndReprocessAsync(state, child, newDependency))
{
return false;
}
@ -187,7 +187,7 @@ namespace Microsoft.ComponentDetection.Detectors.Pip
return new List<PipDependencySpecification>();
}
return await PypiClient.FetchPackageDependencies(spec.Name, candidateVersion, packageToFetch);
return await this.PypiClient.FetchPackageDependencies(spec.Name, candidateVersion, packageToFetch);
}
private void AddGraphNode(PythonResolverState state, PipGraphNode parent, string name, string version)

Просмотреть файл

@ -16,7 +16,7 @@ namespace Microsoft.ComponentDetection.Detectors.Pip
public bool Valid { get; set; }
public bool IsReleasedPackage => string.IsNullOrEmpty(PreReleaseLabel) && !PreReleaseNumber.HasValue && !DevNumber.HasValue;
public bool IsReleasedPackage => string.IsNullOrEmpty(this.PreReleaseLabel) && !this.PreReleaseNumber.HasValue && !this.DevNumber.HasValue;
public int Epoch { get; set; }
@ -41,60 +41,60 @@ namespace Microsoft.ComponentDetection.Detectors.Pip
var toOperate = version;
if (version.EndsWith(".*"))
{
Floating = true;
this.Floating = true;
toOperate = toOperate.Replace(".*", string.Empty);
}
match = PythonVersionRegex.Match(version);
this.match = PythonVersionRegex.Match(version);
if (!match.Success || !string.Equals(match.Value, toOperate, StringComparison.OrdinalIgnoreCase))
if (!this.match.Success || !string.Equals(this.match.Value, toOperate, StringComparison.OrdinalIgnoreCase))
{
Valid = false;
this.Valid = false;
return;
}
var groups = match.Groups;
var groups = this.match.Groups;
// Epoch is optional, implicitly 0 if not present
if (groups["epoch"].Success && int.TryParse(groups["epoch"].Value, out int epoch))
{
Epoch = epoch;
this.Epoch = epoch;
}
else
{
Epoch = 0;
this.Epoch = 0;
}
Release = groups["release"].Success ? groups["release"].Value : string.Empty;
PreReleaseLabel = groups["pre_l"].Success ? groups["pre_l"].Value : string.Empty;
this.Release = groups["release"].Success ? groups["release"].Value : string.Empty;
this.PreReleaseLabel = groups["pre_l"].Success ? groups["pre_l"].Value : string.Empty;
if (groups["pre_n"].Success && int.TryParse(groups["pre_n"].Value, out int preReleaseNumber))
{
PreReleaseNumber = preReleaseNumber;
this.PreReleaseNumber = preReleaseNumber;
}
if (groups["post_n1"].Success && int.TryParse(groups["post_n1"].Value, out int postRelease1))
{
PostNumber = postRelease1;
this.PostNumber = postRelease1;
}
if (groups["post_n2"].Success && int.TryParse(groups["post_n2"].Value, out int postRelease2))
{
PostNumber = postRelease2;
this.PostNumber = postRelease2;
}
if (groups["dev_l"].Success)
{
DevLabel = groups["dev_l"].Value;
DevNumber = 0;
this.DevLabel = groups["dev_l"].Value;
this.DevNumber = 0;
}
if (groups["dev_n"].Success && int.TryParse(groups["dev_n"].Value, out int devNumber))
{
DevNumber = devNumber;
this.DevNumber = devNumber;
}
Valid = true;
this.Valid = true;
}
public static bool operator >(PythonVersion operand1, PythonVersion operand2)
@ -124,16 +124,16 @@ namespace Microsoft.ComponentDetection.Detectors.Pip
return 1;
}
if (Epoch > other.Epoch)
if (this.Epoch > other.Epoch)
{
return 1;
}
else if (Epoch < other.Epoch)
else if (this.Epoch < other.Epoch)
{
return -1;
}
if (!string.Equals(Release, other.Release, StringComparison.OrdinalIgnoreCase))
if (!string.Equals(this.Release, other.Release, StringComparison.OrdinalIgnoreCase))
{
int result = CompareReleaseVersions(this, other);
if (result != 0)
@ -327,4 +327,4 @@ namespace Microsoft.ComponentDetection.Detectors.Pip
return lengthCompare;
}
}
}
}

Просмотреть файл

@ -17,7 +17,7 @@ namespace Microsoft.ComponentDetection.Detectors.Pnpm
public override string ToString()
{
return name;
return this.name;
}
}
#pragma warning restore SA1300

Просмотреть файл

@ -27,7 +27,7 @@ namespace Microsoft.ComponentDetection.Detectors.Pnpm
public PnpmComponentDetector()
{
NeedsAutomaticRootDependencyCalculation = true;
this.NeedsAutomaticRootDependencyCalculation = true;
}
protected override async Task OnFileFound(ProcessRequest processRequest, IDictionary<string, string> detectorArgs)
@ -35,21 +35,21 @@ namespace Microsoft.ComponentDetection.Detectors.Pnpm
var singleFileComponentRecorder = processRequest.SingleFileComponentRecorder;
var file = processRequest.ComponentStream;
Logger.LogVerbose("Found yaml file: " + file.Location);
string skippedFolder = SkippedFolders.FirstOrDefault(folder => file.Location.Contains(folder));
this.Logger.LogVerbose("Found yaml file: " + file.Location);
string skippedFolder = this.SkippedFolders.FirstOrDefault(folder => file.Location.Contains(folder));
if (!string.IsNullOrEmpty(skippedFolder))
{
Logger.LogVerbose($"Skipping found file, it was detected as being within a {skippedFolder} folder.");
this.Logger.LogVerbose($"Skipping found file, it was detected as being within a {skippedFolder} folder.");
}
try
{
var pnpmYaml = await PnpmParsingUtilities.DeserializePnpmYamlFile(file);
RecordDependencyGraphFromFile(pnpmYaml, singleFileComponentRecorder);
this.RecordDependencyGraphFromFile(pnpmYaml, singleFileComponentRecorder);
}
catch (Exception e)
{
Logger.LogFailedReadingFile(file.Location, e);
this.Logger.LogFailedReadingFile(file.Location, e);
}
}
@ -73,12 +73,12 @@ namespace Microsoft.ComponentDetection.Detectors.Pnpm
foreach (var dependency in packageKeyValue.Value.dependencies)
{
// Ignore local packages.
if (IsLocalDependency(dependency))
if (this.IsLocalDependency(dependency))
{
continue;
}
var childDetectedComponent = PnpmParsingUtilities.CreateDetectedComponentFromPnpmPath(pnpmPackagePath: CreatePnpmPackagePathFromDependency(dependency.Key, dependency.Value));
var childDetectedComponent = PnpmParsingUtilities.CreateDetectedComponentFromPnpmPath(pnpmPackagePath: this.CreatePnpmPackagePathFromDependency(dependency.Key, dependency.Value));
// Older code used the root's dev dependency value. We're leaving this null until we do a second pass to look at each components' top level referrers.
singleFileComponentRecorder.RegisterUsage(childDetectedComponent, parentComponentId: parentDetectedComponent.Component.Id, isDevelopmentDependency: null);
@ -110,4 +110,4 @@ namespace Microsoft.ComponentDetection.Detectors.Pnpm
return dependencyVersion.Contains('/') ? dependencyVersion : $"/{dependencyName}/{dependencyVersion}";
}
}
}
}

Просмотреть файл

@ -28,7 +28,7 @@ namespace Microsoft.ComponentDetection.Detectors.Poetry
{
var singleFileComponentRecorder = processRequest.SingleFileComponentRecorder;
var poetryLockFile = processRequest.ComponentStream;
Logger.LogVerbose("Found Poetry lockfile: " + poetryLockFile);
this.Logger.LogVerbose("Found Poetry lockfile: " + poetryLockFile);
var poetryLock = StreamTomlSerializer.Deserialize(poetryLockFile.Stream, TomlSettings.Create()).Get<PoetryLock>();
poetryLock.package.ToList().ForEach(package =>

Просмотреть файл

@ -67,18 +67,18 @@ namespace Microsoft.ComponentDetection.Detectors.Ruby
public string Location { get; }
public string Id => $"{Name}:{Location}";
public string Id => $"{this.Name}:{this.Location}";
public Dependency(string name, string location)
{
Name = name;
Location = location;
this.Name = name;
this.Location = location;
}
}
public RubyComponentDetector()
{
NeedsAutomaticRootDependencyCalculation = true;
this.NeedsAutomaticRootDependencyCalculation = true;
}
protected override Task OnFileFound(ProcessRequest processRequest, IDictionary<string, string> detectorArgs)
@ -86,8 +86,8 @@ namespace Microsoft.ComponentDetection.Detectors.Ruby
var singleFileComponentRecorder = processRequest.SingleFileComponentRecorder;
var file = processRequest.ComponentStream;
Logger.LogVerbose("Found Gemfile.lock: " + file.Location);
ParseGemLockFile(singleFileComponentRecorder, file);
this.Logger.LogVerbose("Found Gemfile.lock: " + file.Location);
this.ParseGemLockFile(singleFileComponentRecorder, file);
return Task.CompletedTask;
}
@ -129,13 +129,13 @@ namespace Microsoft.ComponentDetection.Detectors.Ruby
switch (heading)
{
case "GIT":
ParseSection(SectionType.GIT, sublines, components, dependencies, file);
this.ParseSection(SectionType.GIT, sublines, components, dependencies, file);
break;
case "GEM":
ParseSection(SectionType.GEM, sublines, components, dependencies, file);
this.ParseSection(SectionType.GEM, sublines, components, dependencies, file);
break;
case "PATH":
ParseSection(SectionType.PATH, sublines, components, dependencies, file);
this.ParseSection(SectionType.PATH, sublines, components, dependencies, file);
break;
case "BUNDLED WITH":
var line = sublines[0].Trim();
@ -154,8 +154,8 @@ namespace Microsoft.ComponentDetection.Detectors.Ruby
else
{
// Throw this line away. Is this malformed? We were expecting a header
Logger.LogVerbose(lines[0]);
Logger.LogVerbose("Appears to be malformed/is not expected here. Expected heading.");
this.Logger.LogVerbose(lines[0]);
this.Logger.LogVerbose("Appears to be malformed/is not expected here. Expected heading.");
lines.RemoveAt(0);
}
}
@ -230,9 +230,9 @@ namespace Microsoft.ComponentDetection.Detectors.Ruby
var version = splits[1].Substring(1, splits[1].Length - 2);
TypedComponent newComponent;
if (IsVersionRelative(version))
if (this.IsVersionRelative(version))
{
Logger.LogWarning($"Found component with invalid version, name = {name} and version = {version}");
this.Logger.LogWarning($"Found component with invalid version, name = {name} and version = {version}");
wasParentDependencyExcluded = true;
continue;
}

Просмотреть файл

@ -14,10 +14,10 @@ namespace Microsoft.ComponentDetection.Detectors.Rust
public CargoDependencyData()
{
CargoWorkspaces = new HashSet<string>();
CargoWorkspaceExclusions = new HashSet<string>();
NonDevDependencies = new List<DependencySpecification>();
DevDependencies = new List<DependencySpecification>();
this.CargoWorkspaces = new HashSet<string>();
this.CargoWorkspaceExclusions = new HashSet<string>();
this.NonDevDependencies = new List<DependencySpecification>();
this.DevDependencies = new List<DependencySpecification>();
}
}
}

Просмотреть файл

@ -29,16 +29,14 @@ namespace Microsoft.ComponentDetection.Detectors.Rust.Contracts
public override bool Equals(object obj)
{
var package = obj as CargoPackage;
return package != null &&
name.Equals(package.name) &&
version.Equals(package.version, StringComparison.OrdinalIgnoreCase);
return package != null && this.name.Equals(package.name) && this.version.Equals(package.version, StringComparison.OrdinalIgnoreCase);
}
public override int GetHashCode()
{
var hashCode = -2143789899;
hashCode = (hashCode * -1521134295) + EqualityComparer<string>.Default.GetHashCode(name);
hashCode = (hashCode * -1521134295) + EqualityComparer<string>.Default.GetHashCode(version.ToLowerInvariant());
hashCode = (hashCode * -1521134295) + EqualityComparer<string>.Default.GetHashCode(this.name);
hashCode = (hashCode * -1521134295) + EqualityComparer<string>.Default.GetHashCode(this.version.ToLowerInvariant());
return hashCode;
}
}

Просмотреть файл

@ -13,7 +13,7 @@ namespace Microsoft.ComponentDetection.Detectors.Rust
public DependencySpecification()
{
dependencies = new Dictionary<string, ISet<ISet<Range>>>();
this.dependencies = new Dictionary<string, ISet<ISet<Range>>>();
}
public void Add(string name, string cargoVersionSpecifier)
@ -25,22 +25,22 @@ namespace Microsoft.ComponentDetection.Detectors.Rust
ranges.Add(new Range(specifier.Trim()));
}
if (!dependencies.ContainsKey(name))
if (!this.dependencies.ContainsKey(name))
{
dependencies.Add(name, new HashSet<ISet<Range>>());
this.dependencies.Add(name, new HashSet<ISet<Range>>());
}
dependencies[name].Add(ranges);
this.dependencies[name].Add(ranges);
}
public bool MatchesPackage(CargoPackage package)
{
if (!dependencies.ContainsKey(package.name))
if (!this.dependencies.ContainsKey(package.name))
{
return false;
}
foreach (var ranges in dependencies[package.name])
foreach (var ranges in this.dependencies[package.name])
{
var allSatisfied = true;
foreach (var range in ranges)

Просмотреть файл

@ -37,12 +37,12 @@ namespace Microsoft.ComponentDetection.Detectors.Rust
// This makes sure we're only trying to parse Cargo.lock v1 formats
if (cargoLock.metadata == null)
{
Logger.LogInfo($"Cargo.lock file at {cargoLockFile.Location} contains no metadata section so we're parsing it as the v2 format. The v1 detector will not process it.");
this.Logger.LogInfo($"Cargo.lock file at {cargoLockFile.Location} contains no metadata section so we're parsing it as the v2 format. The v1 detector will not process it.");
return Task.CompletedTask;
}
FileInfo lockFileInfo = new FileInfo(cargoLockFile.Location);
IEnumerable<IComponentStream> cargoTomlComponentStream = ComponentStreamEnumerableFactory.GetComponentStreams(lockFileInfo.Directory, new List<string> { RustCrateUtilities.CargoTomlSearchPattern }, (name, directoryName) => false, recursivelyScanDirectories: false);
IEnumerable<IComponentStream> cargoTomlComponentStream = this.ComponentStreamEnumerableFactory.GetComponentStreams(lockFileInfo.Directory, new List<string> { RustCrateUtilities.CargoTomlSearchPattern }, (name, directoryName) => false, recursivelyScanDirectories: false);
CargoDependencyData cargoDependencyData = RustCrateUtilities.ExtractRootDependencyAndWorkspaceSpecifications(cargoTomlComponentStream, singleFileComponentRecorder);
@ -53,7 +53,7 @@ namespace Microsoft.ComponentDetection.Detectors.Rust
{
string rootCargoTomlLocation = Path.Combine(lockFileInfo.DirectoryName, "Cargo.toml");
IEnumerable<IComponentStream> cargoTomlWorkspaceComponentStreams = ComponentStreamEnumerableFactory.GetComponentStreams(
IEnumerable<IComponentStream> cargoTomlWorkspaceComponentStreams = this.ComponentStreamEnumerableFactory.GetComponentStreams(
lockFileInfo.Directory,
new List<string> { RustCrateUtilities.CargoTomlSearchPattern },
RustCrateUtilities.BuildExcludeDirectoryPredicateFromWorkspaces(lockFileInfo, cargoDependencyData.CargoWorkspaces, cargoDependencyData.CargoWorkspaceExclusions),
@ -68,14 +68,14 @@ namespace Microsoft.ComponentDetection.Detectors.Rust
// Even though we can't read the file streams, we still have the enumerable!
if (!cargoTomlComponentStream.Any() || cargoTomlComponentStream.Count() > 1)
{
Logger.LogWarning($"We are expecting exactly 1 accompanying Cargo.toml file next to the cargo.lock file found at {cargoLockFile.Location}");
this.Logger.LogWarning($"We are expecting exactly 1 accompanying Cargo.toml file next to the cargo.lock file found at {cargoLockFile.Location}");
return Task.CompletedTask;
}
// If there is a mismatch between the number of expected and found workspaces, exit
if (expectedWorkspaceTomlCount > numWorkspaceComponentStreams)
{
Logger.LogWarning($"We are expecting at least {expectedWorkspaceTomlCount} accompanying Cargo.toml file(s) from workspaces outside of the root directory {lockFileInfo.DirectoryName}, but found {numWorkspaceComponentStreams}");
this.Logger.LogWarning($"We are expecting at least {expectedWorkspaceTomlCount} accompanying Cargo.toml file(s) from workspaces outside of the root directory {lockFileInfo.DirectoryName}, but found {numWorkspaceComponentStreams}");
return Task.CompletedTask;
}
@ -85,7 +85,7 @@ namespace Microsoft.ComponentDetection.Detectors.Rust
catch (Exception e)
{
// If something went wrong, just ignore the file
Logger.LogFailedReadingFile(cargoLockFile.Location, e);
this.Logger.LogFailedReadingFile(cargoLockFile.Location, e);
}
return Task.CompletedTask;

Просмотреть файл

@ -56,18 +56,18 @@ namespace Microsoft.ComponentDetection.Detectors.Rust
singleFileComponentRecorder.AddAdditionalRelatedFile(cargoTomlFile.Location);
// Extract the workspaces present, if any
if (cargoToml.ContainsKey(RustCrateUtilities.WorkspaceKey))
if (cargoToml.ContainsKey(WorkspaceKey))
{
TomlTable workspaces = cargoToml.Get<TomlTable>(RustCrateUtilities.WorkspaceKey);
TomlTable workspaces = cargoToml.Get<TomlTable>(WorkspaceKey);
TomlObject workspaceMembers = workspaces.ContainsKey(RustCrateUtilities.WorkspaceMemberKey) ? workspaces[RustCrateUtilities.WorkspaceMemberKey] : null;
TomlObject workspaceExclusions = workspaces.ContainsKey(RustCrateUtilities.WorkspaceExcludeKey) ? workspaces[RustCrateUtilities.WorkspaceExcludeKey] : null;
TomlObject workspaceMembers = workspaces.ContainsKey(WorkspaceMemberKey) ? workspaces[WorkspaceMemberKey] : null;
TomlObject workspaceExclusions = workspaces.ContainsKey(WorkspaceExcludeKey) ? workspaces[WorkspaceExcludeKey] : null;
if (workspaceMembers != null)
{
if (workspaceMembers.TomlType != TomlObjectType.Array)
{
throw new InvalidRustTomlFileException($"In accompanying Cargo.toml file expected {RustCrateUtilities.WorkspaceMemberKey} within {RustCrateUtilities.WorkspaceKey} to be of type Array, but found {workspaceMembers.TomlType}");
throw new InvalidRustTomlFileException($"In accompanying Cargo.toml file expected {WorkspaceMemberKey} within {WorkspaceKey} to be of type Array, but found {workspaceMembers.TomlType}");
}
// TomlObject arrays do not natively implement a HashSet get, so add from a list
@ -78,14 +78,14 @@ namespace Microsoft.ComponentDetection.Detectors.Rust
{
if (workspaceExclusions.TomlType != TomlObjectType.Array)
{
throw new InvalidRustTomlFileException($"In accompanying Cargo.toml file expected {RustCrateUtilities.WorkspaceExcludeKey} within {RustCrateUtilities.WorkspaceKey} to be of type Array, but found {workspaceExclusions.TomlType}");
throw new InvalidRustTomlFileException($"In accompanying Cargo.toml file expected {WorkspaceExcludeKey} within {WorkspaceKey} to be of type Array, but found {workspaceExclusions.TomlType}");
}
cargoDependencyData.CargoWorkspaceExclusions.UnionWith(workspaceExclusions.Get<List<string>>());
}
}
RustCrateUtilities.GenerateDependencies(cargoToml, cargoDependencyData.NonDevDependencies, cargoDependencyData.DevDependencies);
GenerateDependencies(cargoToml, cargoDependencyData.NonDevDependencies, cargoDependencyData.DevDependencies);
break;
}
@ -110,7 +110,7 @@ namespace Microsoft.ComponentDetection.Detectors.Rust
singleFileComponentRecorder.AddAdditionalRelatedFile(cargoTomlFile.Location);
RustCrateUtilities.GenerateDependencies(cargoToml, nonDevDependencySpecifications, devDependencySpecifications);
GenerateDependencies(cargoToml, nonDevDependencySpecifications, devDependencySpecifications);
}
}
@ -122,8 +122,8 @@ namespace Microsoft.ComponentDetection.Detectors.Rust
/// <param name="devDependencySpecifications">Current list of development dependencies.</param>
private static void GenerateDependencies(TomlTable cargoToml, IList<DependencySpecification> nonDevDependencySpecifications, IList<DependencySpecification> devDependencySpecifications)
{
var dependencySpecification = RustCrateUtilities.GenerateDependencySpecifications(cargoToml, RustCrateUtilities.NonDevDependencyKeys);
var devDependencySpecification = RustCrateUtilities.GenerateDependencySpecifications(cargoToml, RustCrateUtilities.DevDependencyKeys);
var dependencySpecification = GenerateDependencySpecifications(cargoToml, NonDevDependencyKeys);
var devDependencySpecification = GenerateDependencySpecifications(cargoToml, DevDependencyKeys);
// If null, this indicates the toml is an internal file that should not be tracked as a component.
if (dependencySpecification != null)

Просмотреть файл

@ -37,12 +37,12 @@ namespace Microsoft.ComponentDetection.Detectors.Rust
// This makes sure we're only trying to parse Cargo.lock v2 formats
if (cargoLock.metadata != null)
{
Logger.LogInfo($"Cargo.lock file at {cargoLockFile.Location} contains a metadata section so we're parsing it as the v1 format. The v2 detector will no process it.");
this.Logger.LogInfo($"Cargo.lock file at {cargoLockFile.Location} contains a metadata section so we're parsing it as the v1 format. The v2 detector will no process it.");
return Task.CompletedTask;
}
FileInfo lockFileInfo = new FileInfo(cargoLockFile.Location);
IEnumerable<IComponentStream> cargoTomlComponentStream = ComponentStreamEnumerableFactory.GetComponentStreams(lockFileInfo.Directory, new List<string> { RustCrateUtilities.CargoTomlSearchPattern }, (name, directoryName) => false, recursivelyScanDirectories: false);
IEnumerable<IComponentStream> cargoTomlComponentStream = this.ComponentStreamEnumerableFactory.GetComponentStreams(lockFileInfo.Directory, new List<string> { RustCrateUtilities.CargoTomlSearchPattern }, (name, directoryName) => false, recursivelyScanDirectories: false);
CargoDependencyData cargoDependencyData = RustCrateUtilities.ExtractRootDependencyAndWorkspaceSpecifications(cargoTomlComponentStream, singleFileComponentRecorder);
@ -53,7 +53,7 @@ namespace Microsoft.ComponentDetection.Detectors.Rust
{
string rootCargoTomlLocation = Path.Combine(lockFileInfo.DirectoryName, "Cargo.toml");
IEnumerable<IComponentStream> cargoTomlWorkspaceComponentStreams = ComponentStreamEnumerableFactory.GetComponentStreams(
IEnumerable<IComponentStream> cargoTomlWorkspaceComponentStreams = this.ComponentStreamEnumerableFactory.GetComponentStreams(
lockFileInfo.Directory,
new List<string> { RustCrateUtilities.CargoTomlSearchPattern },
RustCrateUtilities.BuildExcludeDirectoryPredicateFromWorkspaces(lockFileInfo, cargoDependencyData.CargoWorkspaces, cargoDependencyData.CargoWorkspaceExclusions),
@ -68,14 +68,14 @@ namespace Microsoft.ComponentDetection.Detectors.Rust
// Even though we can't read the file streams, we still have the enumerable!
if (!cargoTomlComponentStream.Any() || cargoTomlComponentStream.Count() > 1)
{
Logger.LogWarning($"We are expecting exactly 1 accompanying Cargo.toml file next to the cargo.lock file found at {cargoLockFile.Location}");
this.Logger.LogWarning($"We are expecting exactly 1 accompanying Cargo.toml file next to the cargo.lock file found at {cargoLockFile.Location}");
return Task.CompletedTask;
}
// If there is a mismatch between the number of expected and found workspaces, exit
if (expectedWorkspaceTomlCount > numWorkspaceComponentStreams)
{
Logger.LogWarning($"We are expecting at least {expectedWorkspaceTomlCount} accompanying Cargo.toml file(s) from workspaces outside of the root directory {lockFileInfo.DirectoryName}, but found {numWorkspaceComponentStreams}");
this.Logger.LogWarning($"We are expecting at least {expectedWorkspaceTomlCount} accompanying Cargo.toml file(s) from workspaces outside of the root directory {lockFileInfo.DirectoryName}, but found {numWorkspaceComponentStreams}");
return Task.CompletedTask;
}
@ -85,7 +85,7 @@ namespace Microsoft.ComponentDetection.Detectors.Rust
catch (Exception e)
{
// If something went wrong, just ignore the file
Logger.LogFailedReadingFile(cargoLockFile.Location, e);
this.Logger.LogFailedReadingFile(cargoLockFile.Location, e);
}
return Task.CompletedTask;

Просмотреть файл

@ -39,65 +39,65 @@ namespace Microsoft.ComponentDetection.Detectors.Rust.SemVer
throw new ArgumentException(string.Format("Invalid comparator string: {0}", input));
}
ComparatorType = ParseComparatorType(match.Groups[1].Value);
this.ComparatorType = ParseComparatorType(match.Groups[1].Value);
var partialVersion = new PartialVersion(match.Groups[2].Value);
if (!partialVersion.IsFull())
{
// For Operator.Equal, partial versions are handled by the StarRange
// desugarer, and desugar to multiple comparators.
switch (ComparatorType)
switch (this.ComparatorType)
{
// For <= with a partial version, eg. <=1.2.x, this
// means the same as < 1.3.0, and <=1.x means <2.0
case Operator.LessThanOrEqual:
ComparatorType = Operator.LessThan;
this.ComparatorType = Operator.LessThan;
if (!partialVersion.Major.HasValue)
{
// <=* means >=0.0.0
ComparatorType = Operator.GreaterThanOrEqual;
Version = new SemVersion(0, 0, 0);
this.ComparatorType = Operator.GreaterThanOrEqual;
this.Version = new SemVersion(0, 0, 0);
}
else if (!partialVersion.Minor.HasValue)
{
Version = new SemVersion(partialVersion.Major.Value + 1, 0, 0);
this.Version = new SemVersion(partialVersion.Major.Value + 1, 0, 0);
}
else
{
Version = new SemVersion(partialVersion.Major.Value, partialVersion.Minor.Value + 1, 0);
this.Version = new SemVersion(partialVersion.Major.Value, partialVersion.Minor.Value + 1, 0);
}
break;
case Operator.GreaterThan:
ComparatorType = Operator.GreaterThanOrEqual;
this.ComparatorType = Operator.GreaterThanOrEqual;
if (!partialVersion.Major.HasValue)
{
// >* is unsatisfiable, so use <0.0.0
ComparatorType = Operator.LessThan;
Version = new SemVersion(0, 0, 0);
this.ComparatorType = Operator.LessThan;
this.Version = new SemVersion(0, 0, 0);
}
else if (!partialVersion.Minor.HasValue)
{
// eg. >1.x -> >=2.0
Version = new SemVersion(partialVersion.Major.Value + 1, 0, 0);
this.Version = new SemVersion(partialVersion.Major.Value + 1, 0, 0);
}
else
{
// eg. >1.2.x -> >=1.3
Version = new SemVersion(partialVersion.Major.Value, partialVersion.Minor.Value + 1, 0);
this.Version = new SemVersion(partialVersion.Major.Value, partialVersion.Minor.Value + 1, 0);
}
break;
default:
// <1.2.x means <1.2.0
// >=1.2.x means >=1.2.0
Version = partialVersion.ToZeroVersion();
this.Version = partialVersion.ToZeroVersion();
break;
}
}
else
{
Version = partialVersion.ToZeroVersion();
this.Version = partialVersion.ToZeroVersion();
}
}
@ -108,8 +108,8 @@ namespace Microsoft.ComponentDetection.Detectors.Rust.SemVer
throw new NullReferenceException("Null comparator version");
}
ComparatorType = comparatorType;
Version = comparatorVersion;
this.ComparatorType = comparatorType;
this.Version = comparatorVersion;
}
public static Tuple<int, Comparator> TryParse(string input)
@ -145,18 +145,18 @@ namespace Microsoft.ComponentDetection.Detectors.Rust.SemVer
public bool IsSatisfied(SemVersion version)
{
switch (ComparatorType)
switch (this.ComparatorType)
{
case Operator.Equal:
return version == Version;
return version == this.Version;
case Operator.LessThan:
return version < Version;
return version < this.Version;
case Operator.LessThanOrEqual:
return version <= Version;
return version <= this.Version;
case Operator.GreaterThan:
return version > Version;
return version > this.Version;
case Operator.GreaterThanOrEqual:
return version >= Version;
return version >= this.Version;
default:
throw new InvalidOperationException("Comparator type not recognised.");
}
@ -175,17 +175,17 @@ namespace Microsoft.ComponentDetection.Detectors.Rust.SemVer
c.ComparatorType == Operator.Equal ||
c.ComparatorType == Operator.LessThanOrEqual;
if (Version > other.Version && (operatorIsLessThan(this) || operatorIsGreaterThan(other)))
if (this.Version > other.Version && (operatorIsLessThan(this) || operatorIsGreaterThan(other)))
{
return true;
}
if (Version < other.Version && (operatorIsGreaterThan(this) || operatorIsLessThan(other)))
if (this.Version < other.Version && (operatorIsGreaterThan(this) || operatorIsLessThan(other)))
{
return true;
}
if (Version == other.Version && (
if (this.Version == other.Version && (
(operatorIncludesEqual(this) && operatorIncludesEqual(other)) ||
(operatorIsLessThan(this) && operatorIsLessThan(other)) ||
(operatorIsGreaterThan(this) && operatorIsGreaterThan(other))))
@ -208,7 +208,7 @@ namespace Microsoft.ComponentDetection.Detectors.Rust.SemVer
public override string ToString()
{
string operatorString = null;
switch (ComparatorType)
switch (this.ComparatorType)
{
case Operator.Equal:
operatorString = "=";
@ -229,7 +229,7 @@ namespace Microsoft.ComponentDetection.Detectors.Rust.SemVer
throw new InvalidOperationException("Comparator type not recognised.");
}
return string.Format("{0}{1}", operatorString, Version);
return string.Format("{0}{1}", operatorString, this.Version);
}
public bool Equals(Comparator other)
@ -239,17 +239,17 @@ namespace Microsoft.ComponentDetection.Detectors.Rust.SemVer
return false;
}
return ComparatorType == other.ComparatorType && Version == other.Version;
return this.ComparatorType == other.ComparatorType && this.Version == other.Version;
}
public override bool Equals(object other)
{
return Equals(other as Comparator);
return this.Equals(other as Comparator);
}
public override int GetHashCode()
{
return ToString().GetHashCode();
return this.ToString().GetHashCode();
}
}
}

Просмотреть файл

@ -20,7 +20,7 @@ namespace Microsoft.ComponentDetection.Detectors.Rust.SemVer
public ComparatorSet(string spec)
{
comparators = new List<Comparator> { };
this.comparators = new List<Comparator> { };
spec = spec.Trim();
if (spec == string.Empty)
@ -50,7 +50,7 @@ namespace Microsoft.ComponentDetection.Detectors.Rust.SemVer
if (result != null)
{
position += result.Item1;
comparators.AddRange(result.Item2);
this.comparators.AddRange(result.Item2);
}
}
@ -59,7 +59,7 @@ namespace Microsoft.ComponentDetection.Detectors.Rust.SemVer
if (comparatorResult != null)
{
position += comparatorResult.Item1;
comparators.Add(comparatorResult.Item2);
this.comparators.Add(comparatorResult.Item2);
}
if (position == iterStartPosition)
@ -77,13 +77,13 @@ namespace Microsoft.ComponentDetection.Detectors.Rust.SemVer
public bool IsSatisfied(SemVersion version)
{
bool satisfied = comparators.All(c => c.IsSatisfied(version));
bool satisfied = this.comparators.All(c => c.IsSatisfied(version));
if (version.Prerelease != string.Empty)
{
// If the version is a pre-release, then one of the
// comparators must have the same version and also include
// a pre-release tag.
return satisfied && comparators.Any(c =>
return satisfied && this.comparators.Any(c =>
c.Version.Prerelease != string.Empty &&
c.Version.Major == version.Major &&
c.Version.Minor == version.Minor &&
@ -170,25 +170,25 @@ namespace Microsoft.ComponentDetection.Detectors.Rust.SemVer
return false;
}
var thisSet = new HashSet<Comparator>(comparators);
var thisSet = new HashSet<Comparator>(this.comparators);
return thisSet.SetEquals(other.comparators);
}
public override bool Equals(object other)
{
return Equals(other as ComparatorSet);
return this.Equals(other as ComparatorSet);
}
public override string ToString()
{
return string.Join(" ", comparators.Select(c => c.ToString()).ToArray());
return string.Join(" ", this.comparators.Select(c => c.ToString()).ToArray());
}
public override int GetHashCode()
{
// XOR is commutative, so this hash code is independent
// of the order of comparators.
return comparators.Aggregate(0, (accum, next) => accum ^ next.GetHashCode());
return this.comparators.Aggregate(0, (accum, next) => accum ^ next.GetHashCode());
}
}
}

Просмотреть файл

@ -61,22 +61,22 @@ namespace Microsoft.ComponentDetection.Detectors.Rust.SemVer
if (xValues.Contains(match.Groups[1].Value))
{
Major = null;
this.Major = null;
}
else
{
Major = int.Parse(match.Groups[1].Value);
this.Major = int.Parse(match.Groups[1].Value);
}
if (match.Groups[2].Success)
{
if (xValues.Contains(match.Groups[3].Value))
{
Minor = null;
this.Minor = null;
}
else
{
Minor = int.Parse(match.Groups[3].Value);
this.Minor = int.Parse(match.Groups[3].Value);
}
}
@ -84,32 +84,28 @@ namespace Microsoft.ComponentDetection.Detectors.Rust.SemVer
{
if (xValues.Contains(match.Groups[5].Value))
{
Patch = null;
this.Patch = null;
}
else
{
Patch = int.Parse(match.Groups[5].Value);
this.Patch = int.Parse(match.Groups[5].Value);
}
}
if (match.Groups[6].Success)
{
PreRelease = match.Groups[7].Value;
this.PreRelease = match.Groups[7].Value;
}
}
public SemVersion ToZeroVersion()
{
return new SemVersion(
Major ?? 0,
Minor ?? 0,
Patch ?? 0,
PreRelease);
return new SemVersion(this.Major ?? 0, this.Minor ?? 0, this.Patch ?? 0, this.PreRelease);
}
public bool IsFull()
{
return Major.HasValue && Minor.HasValue && Patch.HasValue;
return this.Major.HasValue && this.Minor.HasValue && this.Patch.HasValue;
}
}
}

Просмотреть файл

@ -33,13 +33,13 @@ namespace Microsoft.ComponentDetection.Detectors.Rust.SemVer
{
this.rangeSpec = rangeSpec;
var comparatorSetSpecs = rangeSpec.Split(new[] { "||" }, StringSplitOptions.None);
comparatorSets = comparatorSetSpecs.Select(s => new ComparatorSet(s)).ToArray();
this.comparatorSets = comparatorSetSpecs.Select(s => new ComparatorSet(s)).ToArray();
}
private Range(IEnumerable<ComparatorSet> comparatorSets)
{
this.comparatorSets = comparatorSets.ToArray();
rangeSpec = string.Join(" || ", comparatorSets.Select(cs => cs.ToString()).ToArray());
this.rangeSpec = string.Join(" || ", comparatorSets.Select(cs => cs.ToString()).ToArray());
}
/// <summary>
@ -49,7 +49,7 @@ namespace Microsoft.ComponentDetection.Detectors.Rust.SemVer
/// <returns>true if the range is satisfied by the version.</returns>
public bool IsSatisfied(SemVersion version)
{
return comparatorSets.Any(s => s.IsSatisfied(version));
return this.comparatorSets.Any(s => s.IsSatisfied(version));
}
/// <summary>
@ -64,7 +64,7 @@ namespace Microsoft.ComponentDetection.Detectors.Rust.SemVer
try
{
SemVersion.TryParse(versionString, out SemVersion version, loose);
return IsSatisfied(version);
return this.IsSatisfied(version);
}
catch (ArgumentException)
{
@ -79,7 +79,7 @@ namespace Microsoft.ComponentDetection.Detectors.Rust.SemVer
/// <returns>An IEnumerable of satisfying versions.</returns>
public IEnumerable<SemVersion> Satisfying(IEnumerable<SemVersion> versions)
{
return versions.Where(IsSatisfied);
return versions.Where(this.IsSatisfied);
}
/// <summary>
@ -91,7 +91,7 @@ namespace Microsoft.ComponentDetection.Detectors.Rust.SemVer
/// <returns>An IEnumerable of satisfying version strings.</returns>
public IEnumerable<string> Satisfying(IEnumerable<string> versions, bool loose = false)
{
return versions.Where(v => IsSatisfied(v, loose));
return versions.Where(v => this.IsSatisfied(v, loose));
}
/// <summary>
@ -101,7 +101,7 @@ namespace Microsoft.ComponentDetection.Detectors.Rust.SemVer
/// <returns>The maximum satisfying version, or null if no versions satisfied this range.</returns>
public SemVersion MaxSatisfying(IEnumerable<SemVersion> versions)
{
return Satisfying(versions).Max();
return this.Satisfying(versions).Max();
}
/// <summary>
@ -112,8 +112,8 @@ namespace Microsoft.ComponentDetection.Detectors.Rust.SemVer
/// <returns>The maximum satisfying version string, or null if no versions satisfied this range.</returns>
public string MaxSatisfying(IEnumerable<string> versionStrings, bool loose = false)
{
var versions = ValidVersions(versionStrings, loose);
var maxVersion = MaxSatisfying(versions);
var versions = this.ValidVersions(versionStrings, loose);
var maxVersion = this.MaxSatisfying(versions);
return maxVersion == null ? null : maxVersion.ToString();
}
@ -124,7 +124,7 @@ namespace Microsoft.ComponentDetection.Detectors.Rust.SemVer
/// <returns>The Range intersection.</returns>
public Range Intersect(Range other)
{
var allIntersections = comparatorSets.SelectMany(
var allIntersections = this.comparatorSets.SelectMany(
thisCs => other.comparatorSets.Select(thisCs.Intersect))
.Where(cs => cs != null).ToList();
@ -142,7 +142,7 @@ namespace Microsoft.ComponentDetection.Detectors.Rust.SemVer
/// <returns>The range string.</returns>
public override string ToString()
{
return rangeSpec;
return this.rangeSpec;
}
public bool Equals(Range other)
@ -152,13 +152,13 @@ namespace Microsoft.ComponentDetection.Detectors.Rust.SemVer
return false;
}
var thisSet = new HashSet<ComparatorSet>(comparatorSets);
var thisSet = new HashSet<ComparatorSet>(this.comparatorSets);
return thisSet.SetEquals(other.comparatorSets);
}
public override bool Equals(object other)
{
return Equals(other as Range);
return this.Equals(other as Range);
}
public static bool operator ==(Range a, Range b)
@ -180,7 +180,7 @@ namespace Microsoft.ComponentDetection.Detectors.Rust.SemVer
{
// XOR is commutative, so this hash code is independent
// of the order of comparators.
return comparatorSets.Aggregate(0, (accum, next) => accum ^ next.GetHashCode());
return this.comparatorSets.Aggregate(0, (accum, next) => accum ^ next.GetHashCode());
}
// Static convenience methods

Просмотреть файл

@ -35,12 +35,12 @@ namespace Microsoft.ComponentDetection.Detectors.Spdx
protected override Task OnFileFound(ProcessRequest processRequest, IDictionary<string, string> detectorArgs)
{
Logger.LogVerbose($"Discovered SPDX2.2 manifest file at: {processRequest.ComponentStream.Location}");
this.Logger.LogVerbose($"Discovered SPDX2.2 manifest file at: {processRequest.ComponentStream.Location}");
var file = processRequest.ComponentStream;
try
{
var hash = GetSHA1HashFromStream(file.Stream);
var hash = this.GetSHA1HashFromStream(file.Stream);
// Reset buffer to starting position after hash generation.
file.Stream.Seek(0, SeekOrigin.Begin);
@ -54,35 +54,35 @@ namespace Microsoft.ComponentDetection.Detectors.Spdx
var document = serializer.Deserialize<JObject>(reader);
if (document != null)
{
if (IsSPDXVersionSupported(document))
if (this.IsSPDXVersionSupported(document))
{
var sbomComponent = ConvertJObjectToSbomComponent(processRequest, document, hash);
var sbomComponent = this.ConvertJObjectToSbomComponent(processRequest, document, hash);
processRequest.SingleFileComponentRecorder.RegisterUsage(new DetectedComponent(sbomComponent));
}
else
{
Logger.LogWarning($"Discovered SPDX at {processRequest.ComponentStream.Location} is not SPDX-2.2 document, skipping");
this.Logger.LogWarning($"Discovered SPDX at {processRequest.ComponentStream.Location} is not SPDX-2.2 document, skipping");
}
}
else
{
Logger.LogWarning($"Discovered SPDX file at {processRequest.ComponentStream.Location} is not a valid document, skipping");
this.Logger.LogWarning($"Discovered SPDX file at {processRequest.ComponentStream.Location} is not a valid document, skipping");
}
}
catch (JsonReaderException)
{
Logger.LogWarning($"Unable to parse file at {processRequest.ComponentStream.Location}, skipping");
this.Logger.LogWarning($"Unable to parse file at {processRequest.ComponentStream.Location}, skipping");
}
}
catch (Exception e)
{
Logger.LogFailedReadingFile(file.Location, e);
this.Logger.LogFailedReadingFile(file.Location, e);
}
return Task.CompletedTask;
}
private bool IsSPDXVersionSupported(JObject document) => supportedSPDXVersions.Contains(document["spdxVersion"]?.ToString(), StringComparer.OrdinalIgnoreCase);
private bool IsSPDXVersionSupported(JObject document) => this.supportedSPDXVersions.Contains(document["spdxVersion"]?.ToString(), StringComparer.OrdinalIgnoreCase);
private SpdxComponent ConvertJObjectToSbomComponent(ProcessRequest processRequest, JObject document, string fileHash)
{
@ -93,12 +93,12 @@ namespace Microsoft.ComponentDetection.Detectors.Spdx
if (rootElements != null && rootElements.Count() > 1)
{
Logger.LogWarning($"SPDX file at {processRequest.ComponentStream.Location} has more than one element in documentDescribes, first will be selected as root element.");
this.Logger.LogWarning($"SPDX file at {processRequest.ComponentStream.Location} has more than one element in documentDescribes, first will be selected as root element.");
}
if (rootElements != null && rootElements.Any())
{
Logger.LogWarning($"SPDX file at {processRequest.ComponentStream.Location} does not have root elements in documentDescribes section, considering SPDXRef-Document as a root element.");
this.Logger.LogWarning($"SPDX file at {processRequest.ComponentStream.Location} does not have root elements in documentDescribes section, considering SPDXRef-Document as a root element.");
}
var rootElementId = rootElements?.FirstOrDefault() ?? "SPDXRef-Document";

Просмотреть файл

@ -38,15 +38,15 @@ namespace Microsoft.ComponentDetection.Detectors.Vcpkg
var singleFileComponentRecorder = processRequest.SingleFileComponentRecorder;
var file = processRequest.ComponentStream;
Logger.LogWarning($"vcpkg detector found {file}");
this.Logger.LogWarning($"vcpkg detector found {file}");
var projectRootDirectory = Directory.GetParent(file.Location);
if (projectRoots.Any(path => projectRootDirectory.FullName.StartsWith(path)))
if (this.projectRoots.Any(path => projectRootDirectory.FullName.StartsWith(path)))
{
return;
}
await ParseSpdxFile(singleFileComponentRecorder, file);
await this.ParseSpdxFile(singleFileComponentRecorder, file);
}
private async Task ParseSpdxFile(
@ -78,7 +78,7 @@ namespace Microsoft.ComponentDetection.Detectors.Vcpkg
continue;
}
Logger.LogWarning($"parsed package {item.Name}");
this.Logger.LogWarning($"parsed package {item.Name}");
if (item.SPDXID == "SPDXRef-port")
{
var split = item.VersionInfo.Split('#');
@ -107,7 +107,7 @@ namespace Microsoft.ComponentDetection.Detectors.Vcpkg
}
catch (Exception)
{
Logger.LogWarning($"failed while handling {item.Name}");
this.Logger.LogWarning($"failed while handling {item.Name}");
}
}
}

Просмотреть файл

@ -55,16 +55,16 @@ namespace Microsoft.ComponentDetection.Detectors.Yarn.Parsers
private YarnBlockFile(IList<string> parsedFileLines)
{
fileLines = parsedFileLines;
this.fileLines = parsedFileLines;
if (fileLines.Count > 0)
if (this.fileLines.Count > 0)
{
ReadVersionHeader();
this.ReadVersionHeader();
}
else
{
VersionHeader = string.Empty;
YarnLockVersion = YarnLockVersion.Invalid;
this.VersionHeader = string.Empty;
this.YarnLockVersion = YarnLockVersion.Invalid;
}
}
@ -89,9 +89,9 @@ namespace Microsoft.ComponentDetection.Detectors.Yarn.Parsers
public IEnumerator<YarnBlock> GetEnumerator()
{
while (ReadToNextMajorBlock())
while (this.ReadToNextMajorBlock())
{
yield return ParseBlock();
yield return this.ParseBlock();
}
yield break;
@ -99,38 +99,38 @@ namespace Microsoft.ComponentDetection.Detectors.Yarn.Parsers
private void ReadVersionHeader()
{
YarnLockVersion = YarnLockVersion.Invalid;
this.YarnLockVersion = YarnLockVersion.Invalid;
do
{
if (fileLines[fileLineIndex].StartsWith("#"))
if (this.fileLines[this.fileLineIndex].StartsWith("#"))
{
if (fileLines[fileLineIndex].Contains("yarn lockfile"))
if (this.fileLines[this.fileLineIndex].Contains("yarn lockfile"))
{
YarnLockVersion = YarnLockVersion.V1;
VersionHeader = fileLines[fileLineIndex];
this.YarnLockVersion = YarnLockVersion.V1;
this.VersionHeader = this.fileLines[this.fileLineIndex];
break;
}
}
else if (string.IsNullOrEmpty(fileLines[fileLineIndex]))
else if (string.IsNullOrEmpty(this.fileLines[this.fileLineIndex]))
{
// If the comment header does not specify V1, a V2 metadata block will follow a line break
if (IncrementIndex())
if (this.IncrementIndex())
{
if (fileLines[fileLineIndex].StartsWith("__metadata:"))
if (this.fileLines[this.fileLineIndex].StartsWith("__metadata:"))
{
VersionHeader = fileLines[fileLineIndex];
YarnLockVersion = YarnLockVersion.V2;
this.VersionHeader = this.fileLines[this.fileLineIndex];
this.YarnLockVersion = YarnLockVersion.V2;
YarnBlock metadataBlock = ParseBlock();
YarnBlock metadataBlock = this.ParseBlock();
if (metadataBlock.Values.ContainsKey("version") && metadataBlock.Values.ContainsKey("cacheKey"))
{
break;
}
VersionHeader = null;
YarnLockVersion = YarnLockVersion.Invalid;
this.VersionHeader = null;
this.YarnLockVersion = YarnLockVersion.Invalid;
}
}
}
@ -139,7 +139,7 @@ namespace Microsoft.ComponentDetection.Detectors.Yarn.Parsers
break;
}
}
while (IncrementIndex());
while (this.IncrementIndex());
}
/// <summary>
@ -156,27 +156,27 @@ namespace Microsoft.ComponentDetection.Detectors.Yarn.Parsers
}
// Assuming the pointer has been set up to a block
YarnBlock block = new YarnBlock { Title = fileLines[fileLineIndex].TrimEnd(':').Trim('\"').Trim() };
YarnBlock block = new YarnBlock { Title = this.fileLines[this.fileLineIndex].TrimEnd(':').Trim('\"').Trim() };
while (IncrementIndex())
while (this.IncrementIndex())
{
if (!fileLines[fileLineIndex].StartsWith(currentLevelDelimiter) || string.IsNullOrWhiteSpace(fileLines[fileLineIndex]))
if (!this.fileLines[this.fileLineIndex].StartsWith(currentLevelDelimiter) || string.IsNullOrWhiteSpace(this.fileLines[this.fileLineIndex]))
{
break;
}
if (fileLines[fileLineIndex].EndsWith(":"))
if (this.fileLines[this.fileLineIndex].EndsWith(":"))
{
block.Children.Add(ParseBlock(level + 1));
fileLineIndex--;
block.Children.Add(this.ParseBlock(level + 1));
this.fileLineIndex--;
}
else
{
string toParse = fileLines[fileLineIndex].Trim();
string toParse = this.fileLines[this.fileLineIndex].Trim();
// Yarn V1 and V2 have slightly different formats, where V2 adds a : between property name and value
// Match on the specified version
var matches = YarnLockVersion == YarnLockVersion.V1 ? YarnV1Regex.Match(toParse) : YarnV2Regex.Match(toParse);
var matches = this.YarnLockVersion == YarnLockVersion.V1 ? YarnV1Regex.Match(toParse) : YarnV2Regex.Match(toParse);
if (matches.Groups.Count != 3) // Whole group + two captures
{
@ -186,7 +186,7 @@ namespace Microsoft.ComponentDetection.Detectors.Yarn.Parsers
block.Values.Add(matches.Groups[1].Value.Trim('\"'), matches.Groups[2].Value.Trim('\"'));
}
if (!Peek() || !fileLines[fileLineIndex].StartsWith(currentLevelDelimiter) || string.IsNullOrWhiteSpace(fileLines[fileLineIndex]))
if (!this.Peek() || !this.fileLines[this.fileLineIndex].StartsWith(currentLevelDelimiter) || string.IsNullOrWhiteSpace(this.fileLines[this.fileLineIndex]))
{
break;
}
@ -197,7 +197,7 @@ namespace Microsoft.ComponentDetection.Detectors.Yarn.Parsers
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
return this.GetEnumerator();
}
/// <summary>
@ -209,13 +209,13 @@ namespace Microsoft.ComponentDetection.Detectors.Yarn.Parsers
string line;
do
{
if (!IncrementIndex())
if (!this.IncrementIndex())
{
return false;
}
else
{
line = fileLines[fileLineIndex];
line = this.fileLines[this.fileLineIndex];
}
}
while (string.IsNullOrWhiteSpace(line) || line.StartsWith(" ") || line.StartsWith("\t") || line.StartsWith("#"));
@ -225,9 +225,9 @@ namespace Microsoft.ComponentDetection.Detectors.Yarn.Parsers
private bool IncrementIndex()
{
fileLineIndex++;
this.fileLineIndex++;
return Peek();
return this.Peek();
}
/// <summary>
@ -236,7 +236,7 @@ namespace Microsoft.ComponentDetection.Detectors.Yarn.Parsers
/// <returns></returns>
private bool Peek()
{
if (fileLineIndex >= fileLines.Count)
if (this.fileLineIndex >= this.fileLines.Count)
{
return false;
}

Просмотреть файл

@ -40,11 +40,11 @@ namespace Microsoft.ComponentDetection.Detectors.Yarn.Parsers
{
YarnEntry yarnEntry = new YarnEntry();
var satisfiedPackages = block.Title.Split(',').Select(x => x.Trim())
.Select(GenerateBlockTitleNormalizer(block));
.Select(this.GenerateBlockTitleNormalizer(block));
foreach (var package in satisfiedPackages)
{
if (!TryReadNameAndSatisfiedVersion(package, out Tuple<string, string> parsed))
if (!this.TryReadNameAndSatisfiedVersion(package, out Tuple<string, string> parsed))
{
continue;
}
@ -117,10 +117,10 @@ namespace Microsoft.ComponentDetection.Detectors.Yarn.Parsers
return blockTitleMember;
}
var versionValue = block.Values.FirstOrDefault(x => string.Equals(x.Key, YarnLockParser.VersionString, StringComparison.OrdinalIgnoreCase));
var versionValue = block.Values.FirstOrDefault(x => string.Equals(x.Key, VersionString, StringComparison.OrdinalIgnoreCase));
if (default(KeyValuePair<string, string>).Equals(versionValue))
{
Logger.LogWarning("Block without version detected");
this.Logger.LogWarning("Block without version detected");
return blockTitleMember;
}

Просмотреть файл

@ -2,7 +2,7 @@
{
public class YarnDependency
{
public string LookupKey => $"{Name}@{Version}";
public string LookupKey => $"{this.Name}@{this.Version}";
public string Name { get; set; }

Просмотреть файл

@ -4,7 +4,7 @@ namespace Microsoft.ComponentDetection.Detectors.Yarn
{
public class YarnEntry
{
public string LookupKey => $"{Name}@{Version}";
public string LookupKey => $"{this.Name}@{this.Version}";
/// <summary>
/// Gets or sets the non-version qualified name of the entry.

Просмотреть файл

@ -35,24 +35,24 @@ namespace Microsoft.ComponentDetection.Detectors.Yarn
var singleFileComponentRecorder = processRequest.SingleFileComponentRecorder;
var file = processRequest.ComponentStream;
string skippedFolder = SkippedFolders.FirstOrDefault(folder => file.Location.Contains(folder));
string skippedFolder = this.SkippedFolders.FirstOrDefault(folder => file.Location.Contains(folder));
if (!string.IsNullOrEmpty(skippedFolder))
{
Logger.LogInfo($"Yarn.Lock file {file.Location} was found in a {skippedFolder} folder and will be skipped.");
this.Logger.LogInfo($"Yarn.Lock file {file.Location} was found in a {skippedFolder} folder and will be skipped.");
return;
}
Logger.LogInfo($"Processing file {file.Location}");
this.Logger.LogInfo($"Processing file {file.Location}");
try
{
var parsed = await YarnLockFileFactory.ParseYarnLockFileAsync(file.Stream, Logger);
DetectComponents(parsed, file.Location, singleFileComponentRecorder);
var parsed = await YarnLockFileFactory.ParseYarnLockFileAsync(file.Stream, this.Logger);
this.DetectComponents(parsed, file.Location, singleFileComponentRecorder);
}
catch (Exception ex)
{
Logger.LogBuildWarning($"Could not read components from file {file.Location}.");
Logger.LogFailedReadingFile(file.Location, ex);
this.Logger.LogBuildWarning($"Could not read components from file {file.Location}.");
this.Logger.LogFailedReadingFile(file.Location, ex);
}
}
@ -73,12 +73,12 @@ namespace Microsoft.ComponentDetection.Detectors.Yarn
var addSuccessful = yarnPackages.TryAdd(key, entry);
if (!addSuccessful)
{
Logger.LogWarning($"Found duplicate entry {key} in {location}");
this.Logger.LogWarning($"Found duplicate entry {key} in {location}");
}
}
}
if (yarnPackages.Count == 0 || !TryReadPeerPackageJsonRequestsAsYarnEntries(location, yarnPackages, out List<YarnEntry> yarnRoots))
if (yarnPackages.Count == 0 || !this.TryReadPeerPackageJsonRequestsAsYarnEntries(location, yarnPackages, out List<YarnEntry> yarnRoots))
{
return;
}
@ -86,7 +86,7 @@ namespace Microsoft.ComponentDetection.Detectors.Yarn
foreach (var dependency in yarnRoots)
{
var root = new DetectedComponent(new NpmComponent(dependency.Name, dependency.Version));
AddDetectedComponentToGraph(root, null, singleFileComponentRecorder, isRootComponent: true);
this.AddDetectedComponentToGraph(root, null, singleFileComponentRecorder, isRootComponent: true);
}
// It's important that all of the root dependencies get registered *before* we start processing any non-root
@ -94,7 +94,7 @@ namespace Microsoft.ComponentDetection.Detectors.Yarn
// transitive dependencies.
foreach (var dependency in yarnRoots)
{
ParseTreeWithAssignedRoot(dependency, yarnPackages, singleFileComponentRecorder);
this.ParseTreeWithAssignedRoot(dependency, yarnPackages, singleFileComponentRecorder);
}
// Catch straggler top level packages in the yarn.lock file that aren't in the package.lock file for whatever reason
@ -103,7 +103,7 @@ namespace Microsoft.ComponentDetection.Detectors.Yarn
var component = new DetectedComponent(new NpmComponent(entry.Name, entry.Version));
if (singleFileComponentRecorder.GetComponent(component.Component.Id) == null)
{
AddDetectedComponentToGraph(component, parentComponent: null, singleFileComponentRecorder);
this.AddDetectedComponentToGraph(component, parentComponent: null, singleFileComponentRecorder);
}
}
}
@ -124,18 +124,18 @@ namespace Microsoft.ComponentDetection.Detectors.Yarn
while (queue.Count > 0)
{
var (currentEntry, parentEntry) = queue.Dequeue();
DetectedComponent currentComponent = singleFileComponentRecorder.GetComponent(YarnEntryToComponentId(currentEntry));
DetectedComponent parentComponent = parentEntry != null ? singleFileComponentRecorder.GetComponent(YarnEntryToComponentId(parentEntry)) : null;
DetectedComponent currentComponent = singleFileComponentRecorder.GetComponent(this.YarnEntryToComponentId(currentEntry));
DetectedComponent parentComponent = parentEntry != null ? singleFileComponentRecorder.GetComponent(this.YarnEntryToComponentId(parentEntry)) : null;
if (currentComponent != null)
{
AddDetectedComponentToGraph(currentComponent, parentComponent, singleFileComponentRecorder, isDevDependency: root.DevDependency);
this.AddDetectedComponentToGraph(currentComponent, parentComponent, singleFileComponentRecorder, isDevDependency: root.DevDependency);
}
else
{
// If this is the first time we've seen a component...
var detectedComponent = new DetectedComponent(new NpmComponent(currentEntry.Name, currentEntry.Version));
AddDetectedComponentToGraph(detectedComponent, parentComponent, singleFileComponentRecorder, isDevDependency: root.DevDependency);
this.AddDetectedComponentToGraph(detectedComponent, parentComponent, singleFileComponentRecorder, isDevDependency: root.DevDependency);
}
// Ensure that we continue to parse the tree for dependencies
@ -156,7 +156,7 @@ namespace Microsoft.ComponentDetection.Detectors.Yarn
}
else
{
Logger.LogInfo($"Failed to find resolved dependency for {newDependency.LookupKey}");
this.Logger.LogInfo($"Failed to find resolved dependency for {newDependency.LookupKey}");
}
}
}
@ -175,7 +175,7 @@ namespace Microsoft.ComponentDetection.Detectors.Yarn
{
yarnRoots = new List<YarnEntry>();
var pkgJsons = ComponentStreamEnumerableFactory.GetComponentStreams(new FileInfo(location).Directory, new List<string> { "package.json" }, (name, directoryName) => false, recursivelyScanDirectories: false);
var pkgJsons = this.ComponentStreamEnumerableFactory.GetComponentStreams(new FileInfo(location).Directory, new List<string> { "package.json" }, (name, directoryName) => false, recursivelyScanDirectories: false);
IDictionary<string, IDictionary<string, bool>> combinedDependencies = new Dictionary<string, IDictionary<string, bool>>();
@ -190,13 +190,13 @@ namespace Microsoft.ComponentDetection.Detectors.Yarn
if (pkgJsonCount != 1)
{
Logger.LogWarning($"No package.json was found for file at {location}. It will not be registered.");
this.Logger.LogWarning($"No package.json was found for file at {location}. It will not be registered.");
return false;
}
if (yarnWorkspaces.Count > 0)
{
GetWorkspaceDependencies(yarnWorkspaces, new FileInfo(location).Directory, combinedDependencies);
this.GetWorkspaceDependencies(yarnWorkspaces, new FileInfo(location).Directory, combinedDependencies);
}
// Convert all of the dependencies we retrieved from package.json
@ -209,7 +209,7 @@ namespace Microsoft.ComponentDetection.Detectors.Yarn
var entryKey = $"{name}@npm:{version.Key}";
if (!yarnEntries.ContainsKey(entryKey))
{
Logger.LogWarning($"A package was requested in the package.json file that was a peer of {location} but was not contained in the lockfile. {name} - {version.Key}");
this.Logger.LogWarning($"A package was requested in the package.json file that was a peer of {location} but was not contained in the lockfile. {name} - {version.Key}");
continue;
}
@ -240,16 +240,16 @@ namespace Microsoft.ComponentDetection.Detectors.Yarn
{
var glob = Glob.Parse($"{root.FullName.Replace('\\', '/')}/{workspacePattern}/package.json", globOptions);
var componentStreams = ComponentStreamEnumerableFactory.GetComponentStreams(root, (file) => glob.IsMatch(file.FullName.Replace('\\', '/')), null, true);
var componentStreams = this.ComponentStreamEnumerableFactory.GetComponentStreams(root, (file) => glob.IsMatch(file.FullName.Replace('\\', '/')), null, true);
foreach (var stream in componentStreams)
{
Logger.LogInfo($"{stream.Location} found for workspace {workspacePattern}");
this.Logger.LogInfo($"{stream.Location} found for workspace {workspacePattern}");
var combinedDependencies = NpmComponentUtilities.TryGetAllPackageJsonDependencies(stream.Stream, out _);
foreach (var dependency in combinedDependencies)
{
ProcessWorkspaceDependency(dependencies, dependency);
this.ProcessWorkspaceDependency(dependencies, dependency);
}
}
}

Просмотреть файл

@ -14,12 +14,12 @@ namespace Microsoft.ComponentDetection.Orchestrator
public ArgumentHelper()
{
ArgumentSets = Enumerable.Empty<IScanArguments>();
this.ArgumentSets = Enumerable.Empty<IScanArguments>();
}
public ParserResult<object> ParseArguments(string[] args)
{
return Parser.Default.ParseArguments(args, ArgumentSets.Select(x => x.GetType()).ToArray());
return Parser.Default.ParseArguments(args, this.ArgumentSets.Select(x => x.GetType()).ToArray());
}
public ParserResult<T> ParseArguments<T>(string[] args, bool ignoreInvalidArgs = false)

Просмотреть файл

@ -20,7 +20,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.ArgumentSets
[Option("AdditionalPluginDirectories", Separator = ';', Required = false, Hidden = true, HelpText = "Semi-colon delimited list of directories to search for plugins")]
public IEnumerable<DirectoryInfo> AdditionalPluginDirectories { get; set; }
public IEnumerable<string> AdditionalPluginDirectoriesSerialized => AdditionalPluginDirectories?.Select(x => x.ToString()) ?? new List<string>();
public IEnumerable<string> AdditionalPluginDirectoriesSerialized => this.AdditionalPluginDirectories?.Select(x => x.ToString()) ?? new List<string>();
[Option("CorrelationId", Required = false, HelpText = "Identifier used to correlate all telemetry for a given execution. If not provided, a new GUID will be generated.")]
public Guid CorrelationId { get; set; }

Просмотреть файл

@ -20,13 +20,13 @@ namespace Microsoft.ComponentDetection.Orchestrator.ArgumentSets
[Option("SourceDirectory", Required = true, HelpText = "Directory to operate on.")]
public DirectoryInfo SourceDirectory { get; set; }
public string SourceDirectorySerialized => SourceDirectory?.ToString();
public string SourceDirectorySerialized => this.SourceDirectory?.ToString();
[JsonIgnore]
[Option("SourceFileRoot", Required = false, HelpText = "Directory where source files can be found.")]
public DirectoryInfo SourceFileRoot { get; set; }
public string SourceFileRootSerialized => SourceFileRoot?.ToString();
public string SourceFileRootSerialized => this.SourceFileRoot?.ToString();
[Option("DetectorArgs", Separator = ',', Required = false, HelpText = "Comma separated list of properties that can affect the detectors execution, like EnableIfDefaultOff that allows a specific detector that is in beta to run, the format for this property is " +
"DetectorId=EnableIfDefaultOff, for example Pip=EnableIfDefaultOff.")]
@ -43,7 +43,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.ArgumentSets
[Option("ManifestFile", Required = false, HelpText = "The file to write scan results to.")]
public FileInfo ManifestFile { get; set; }
public string ManifestFileSerialized => ManifestFile?.ToString();
public string ManifestFileSerialized => this.ManifestFile?.ToString();
[Option("DockerImagesToScan", Required = false, Separator = ',', HelpText = "Comma separated list of docker image names or hashes to execute container scanning on, ex: ubuntu:16.04, 56bab49eef2ef07505f6a1b0d5bd3a601dfc3c76ad4460f24c91d6fa298369ab")]
public IEnumerable<string> DockerImagesToScan { get; set; }

Просмотреть файл

@ -9,7 +9,7 @@ namespace Microsoft.ComponentDetection.Orchestrator
{
public CommandLineArgumentsExporter()
{
DelayedInjectionLazy = new Lazy<IScanArguments>(() => ArgumentsForDelayedInjection);
this.DelayedInjectionLazy = new Lazy<IScanArguments>(() => ArgumentsForDelayedInjection);
}
[Export("InjectableDetectionArguments")]

Просмотреть файл

@ -68,7 +68,7 @@ namespace Microsoft.ComponentDetection.Orchestrator
var returnResult = BcdeExecutionTelemetryRecord.Track(
(record) =>
{
var executionResult = HandleCommand(args, record);
var executionResult = this.HandleCommand(args, record);
if (executionResult.ResultCode == ProcessingResultCode.PartialSuccess)
{
shouldFailureBeSuppressed = true;
@ -139,18 +139,18 @@ namespace Microsoft.ComponentDetection.Orchestrator
// Don't set production telemetry if we are running the build task in DevFabric. 0.36.0 is set in the task.json for the build task in development, but is calculated during deployment for production.
TelemetryConstants.CorrelationId = argumentSet.CorrelationId;
telemetryRecord.Command = GetVerb(argumentSet);
telemetryRecord.Command = this.GetVerb(argumentSet);
scanResult = SafelyExecute(telemetryRecord, () =>
scanResult = this.SafelyExecute(telemetryRecord, () =>
{
GenerateEnvironmentSpecificTelemetry(telemetryRecord);
this.GenerateEnvironmentSpecificTelemetry(telemetryRecord);
telemetryRecord.Arguments = JsonConvert.SerializeObject(argumentSet);
FileWritingService.Init(argumentSet.Output);
Logger.Init(argumentSet.Verbosity);
Logger.LogInfo($"Run correlation id: {TelemetryConstants.CorrelationId.ToString()}");
return Dispatch(argumentSet, CancellationToken.None).GetAwaiter().GetResult();
return this.Dispatch(argumentSet, CancellationToken.None).GetAwaiter().GetResult();
});
})
.WithNotParsed(errors =>

Просмотреть файл

@ -23,7 +23,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Services
// Run BCDE with the given arguments
var detectionArguments = arguments as BcdeArguments;
var result = await BcdeScanExecutionService.ExecuteScanAsync(detectionArguments);
var result = await this.BcdeScanExecutionService.ExecuteScanAsync(detectionArguments);
var detectedComponents = result.ComponentsFound.ToList();
foreach (var detectedComponent in detectedComponents)
{

Просмотреть файл

@ -27,8 +27,8 @@ namespace Microsoft.ComponentDetection.Orchestrator.Services
public async Task<ScanResult> Handle(IScanArguments arguments)
{
BcdeArguments bcdeArguments = (BcdeArguments)arguments;
var result = await BcdeScanExecutionService.ExecuteScanAsync(bcdeArguments);
WriteComponentManifest(bcdeArguments, result);
var result = await this.BcdeScanExecutionService.ExecuteScanAsync(bcdeArguments);
this.WriteComponentManifest(bcdeArguments, result);
return result;
}
@ -38,21 +38,21 @@ namespace Microsoft.ComponentDetection.Orchestrator.Services
if (detectionArguments.ManifestFile != null)
{
Logger.LogInfo($"Scan Manifest file: {detectionArguments.ManifestFile.FullName}");
this.Logger.LogInfo($"Scan Manifest file: {detectionArguments.ManifestFile.FullName}");
userRequestedManifestPath = detectionArguments.ManifestFile;
}
else
{
Logger.LogInfo($"Scan Manifest file: {FileWritingService.ResolveFilePath(ManifestRelativePath)}");
this.Logger.LogInfo($"Scan Manifest file: {this.FileWritingService.ResolveFilePath(ManifestRelativePath)}");
}
if (userRequestedManifestPath == null)
{
FileWritingService.AppendToFile(ManifestRelativePath, JsonConvert.SerializeObject(scanResult, Formatting.Indented));
this.FileWritingService.AppendToFile(ManifestRelativePath, JsonConvert.SerializeObject(scanResult, Formatting.Indented));
}
else
{
FileWritingService.WriteFile(userRequestedManifestPath, JsonConvert.SerializeObject(scanResult, Formatting.Indented));
this.FileWritingService.WriteFile(userRequestedManifestPath, JsonConvert.SerializeObject(scanResult, Formatting.Indented));
}
}
}

Просмотреть файл

@ -47,23 +47,23 @@ namespace Microsoft.ComponentDetection.Orchestrator.Services
public async Task<ScanResult> ExecuteScanAsync(IDetectionArguments detectionArguments)
{
Logger.LogCreateLoggingGroup();
var initialDetectors = DetectorRegistryService.GetDetectors(detectionArguments.AdditionalPluginDirectories, detectionArguments.AdditionalDITargets).ToImmutableList();
this.Logger.LogCreateLoggingGroup();
var initialDetectors = this.DetectorRegistryService.GetDetectors(detectionArguments.AdditionalPluginDirectories, detectionArguments.AdditionalDITargets).ToImmutableList();
if (!initialDetectors.Any())
{
throw new NoDetectorsFoundException();
}
DetectorRestrictions detectorRestrictions = GetDetectorRestrictions(detectionArguments);
var detectors = DetectorRestrictionService.ApplyRestrictions(detectorRestrictions, initialDetectors).ToImmutableList();
DetectorRestrictions detectorRestrictions = this.GetDetectorRestrictions(detectionArguments);
var detectors = this.DetectorRestrictionService.ApplyRestrictions(detectorRestrictions, initialDetectors).ToImmutableList();
Logger.LogVerbose($"Finished applying restrictions to detectors.");
Logger.LogCreateLoggingGroup();
this.Logger.LogVerbose($"Finished applying restrictions to detectors.");
this.Logger.LogCreateLoggingGroup();
var processingResult = await DetectorProcessingService.ProcessDetectorsAsync(detectionArguments, detectors, detectorRestrictions);
var processingResult = await this.DetectorProcessingService.ProcessDetectorsAsync(detectionArguments, detectors, detectorRestrictions);
var graphTranslationService = GraphTranslationServices.OrderBy(gts => gts.Metadata.Priority).Last().Value;
var graphTranslationService = this.GraphTranslationServices.OrderBy(gts => gts.Metadata.Priority).Last().Value;
var scanResult = graphTranslationService.GenerateScanResultFromProcessingResult(processingResult, detectionArguments);

Просмотреть файл

@ -20,7 +20,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Services
public async Task<ScanResult> Handle(IScanArguments arguments)
{
await ListDetectorsAsync(arguments as IListDetectionArgs);
await this.ListDetectorsAsync(arguments as IListDetectionArgs);
return new ScanResult()
{
ResultCode = ProcessingResultCode.Success,
@ -29,12 +29,12 @@ namespace Microsoft.ComponentDetection.Orchestrator.Services
private async Task<ProcessingResultCode> ListDetectorsAsync(IScanArguments listArguments)
{
var detectors = DetectorRegistryService.GetDetectors(listArguments.AdditionalPluginDirectories, listArguments.AdditionalDITargets);
var detectors = this.DetectorRegistryService.GetDetectors(listArguments.AdditionalPluginDirectories, listArguments.AdditionalDITargets);
if (detectors.Any())
{
foreach (var detector in detectors)
{
Logger.LogInfo($"{detector.Id}");
this.Logger.LogInfo($"{detector.Id}");
}
}

Просмотреть файл

@ -35,8 +35,8 @@ namespace Microsoft.ComponentDetection.Orchestrator.Services
public async Task<DetectorProcessingResult> ProcessDetectorsAsync(IDetectionArguments detectionArguments, IEnumerable<IComponentDetector> detectors, DetectorRestrictions detectorRestrictions)
{
Logger.LogCreateLoggingGroup();
Logger.LogInfo($"Finding components...");
this.Logger.LogCreateLoggingGroup();
this.Logger.LogInfo($"Finding components...");
Stopwatch stopwatch = Stopwatch.StartNew();
var exitCode = ProcessingResultCode.Success;
@ -45,9 +45,9 @@ namespace Microsoft.ComponentDetection.Orchestrator.Services
ConcurrentDictionary<string, DetectorRunResult> providerElapsedTime = new ConcurrentDictionary<string, DetectorRunResult>();
var detectorArguments = GetDetectorArgs(detectionArguments.DetectorArgs);
ExcludeDirectoryPredicate exclusionPredicate = IsOSLinuxOrMac()
? GenerateDirectoryExclusionPredicate(detectionArguments.SourceDirectory.ToString(), detectionArguments.DirectoryExclusionList, detectionArguments.DirectoryExclusionListObsolete, allowWindowsPaths: false, ignoreCase: false)
: GenerateDirectoryExclusionPredicate(detectionArguments.SourceDirectory.ToString(), detectionArguments.DirectoryExclusionList, detectionArguments.DirectoryExclusionListObsolete, allowWindowsPaths: true, ignoreCase: true);
ExcludeDirectoryPredicate exclusionPredicate = this.IsOSLinuxOrMac()
? this.GenerateDirectoryExclusionPredicate(detectionArguments.SourceDirectory.ToString(), detectionArguments.DirectoryExclusionList, detectionArguments.DirectoryExclusionListObsolete, allowWindowsPaths: false, ignoreCase: false)
: this.GenerateDirectoryExclusionPredicate(detectionArguments.SourceDirectory.ToString(), detectionArguments.DirectoryExclusionList, detectionArguments.DirectoryExclusionListObsolete, allowWindowsPaths: true, ignoreCase: true);
IEnumerable<Task<(IndividualDetectorScanResult, ComponentRecorder, IComponentDetector)>> scanTasks = detectors
.Select(async detector =>
@ -55,7 +55,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Services
Stopwatch providerStopwatch = new Stopwatch();
providerStopwatch.Start();
var componentRecorder = new ComponentRecorder(Logger, !detector.NeedsAutomaticRootDependencyCalculation);
var componentRecorder = new ComponentRecorder(this.Logger, !detector.NeedsAutomaticRootDependencyCalculation);
var isExperimentalDetector = detector is IExperimentalDetector && !(detectorRestrictions.ExplicitlyEnabledDetectorIds?.Contains(detector.Id)).GetValueOrDefault();
@ -65,13 +65,13 @@ namespace Microsoft.ComponentDetection.Orchestrator.Services
IndividualDetectorScanResult result;
using (var record = new DetectorExecutionTelemetryRecord())
{
result = await WithExperimentalScanGuards(
() => detector.ExecuteDetectorAsync(new ScanRequest(detectionArguments.SourceDirectory, exclusionPredicate, Logger, detectorArguments, detectionArguments.DockerImagesToScan, componentRecorder)),
result = await this.WithExperimentalScanGuards(
() => detector.ExecuteDetectorAsync(new ScanRequest(detectionArguments.SourceDirectory, exclusionPredicate, this.Logger, detectorArguments, detectionArguments.DockerImagesToScan, componentRecorder)),
isExperimentalDetector,
record);
// Make sure top level enumerables are at least empty and not null.
result = CoalesceResult(result);
result = this.CoalesceResult(result);
detectedComponents = componentRecorder.GetDetectedComponents();
resultCode = result.ResultCode;
@ -118,13 +118,13 @@ namespace Microsoft.ComponentDetection.Orchestrator.Services
var results = await Task.WhenAll(scanTasks);
DetectorProcessingResult detectorProcessingResult = ConvertDetectorResultsIntoResult(results, exitCode);
DetectorProcessingResult detectorProcessingResult = this.ConvertDetectorResultsIntoResult(results, exitCode);
var totalElapsedTime = stopwatch.Elapsed.TotalSeconds;
LogTabularOutput(Logger, providerElapsedTime, totalElapsedTime);
this.LogTabularOutput(this.Logger, providerElapsedTime, totalElapsedTime);
Logger.LogCreateLoggingGroup();
Logger.LogInfo($"Detection time: {totalElapsedTime} seconds.");
this.Logger.LogCreateLoggingGroup();
this.Logger.LogInfo($"Detection time: {totalElapsedTime} seconds.");
return detectorProcessingResult;
}
@ -219,9 +219,9 @@ namespace Microsoft.ComponentDetection.Orchestrator.Services
});
foreach (var line in tsf.GenerateString(rows)
.Split(new string[] { Environment.NewLine }, StringSplitOptions.None))
.Split(new string[] { NewLine }, StringSplitOptions.None))
{
Logger.LogInfo(line);
this.Logger.LogInfo(line);
}
}
@ -283,7 +283,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Services
&& (pathOfParentOfDirectoryToConsider.Equals(pathOfParentOfDirectoryToExclude, StringComparison.Ordinal)
|| pathOfParentOfDirectoryToConsider.ToString().Equals(valueTuple.rootedLinuxSymlinkCompatibleRelativePathToExclude, StringComparison.Ordinal)))
{
Logger.LogVerbose($"Excluding folder {Path.Combine(pathOfParentOfDirectoryToConsider.ToString(), nameOfDirectoryToConsider.ToString())}.");
this.Logger.LogVerbose($"Excluding folder {Path.Combine(pathOfParentOfDirectoryToConsider.ToString(), nameOfDirectoryToConsider.ToString())}.");
return true;
}
}
@ -315,7 +315,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Services
{
if (minimatcherKeyValue.Value.IsMatch(path))
{
Logger.LogVerbose($"Excluding folder {path} because it matched glob {minimatcherKeyValue.Key}.");
this.Logger.LogVerbose($"Excluding folder {path} because it matched glob {minimatcherKeyValue.Key}.");
return true;
}

Просмотреть файл

@ -34,24 +34,24 @@ namespace Microsoft.ComponentDetection.Orchestrator.Services
directoriesToSearch.AddRange(additionalSearchDirectories);
}
ComponentDetectors = GetComponentDetectors(directoriesToSearch, extraDetectorAssemblies);
this.ComponentDetectors = this.GetComponentDetectors(directoriesToSearch, extraDetectorAssemblies);
if (!ComponentDetectors.Any())
if (!this.ComponentDetectors.Any())
{
Logger.LogError($"No component detectors were found in {searchPath} or other provided search paths.");
this.Logger.LogError($"No component detectors were found in {searchPath} or other provided search paths.");
}
return ComponentDetectors;
return this.ComponentDetectors;
}
public IEnumerable<IComponentDetector> GetDetectors(Assembly assemblyToSearch, IEnumerable<string> extraDetectorAssemblies)
{
Logger.LogInfo($"Attempting to load component detectors from {assemblyToSearch.FullName}");
this.Logger.LogInfo($"Attempting to load component detectors from {assemblyToSearch.FullName}");
var loadedDetectors = LoadComponentDetectorsFromAssemblies(new List<Assembly> { assemblyToSearch }, extraDetectorAssemblies);
var loadedDetectors = this.LoadComponentDetectorsFromAssemblies(new List<Assembly> { assemblyToSearch }, extraDetectorAssemblies);
var pluralPhrase = loadedDetectors.Count == 1 ? "detector was" : "detectors were";
Logger.LogInfo($"{loadedDetectors.Count} {pluralPhrase} found in {assemblyToSearch.FullName}\n");
this.Logger.LogInfo($"{loadedDetectors.Count} {pluralPhrase} found in {assemblyToSearch.FullName}\n");
return loadedDetectors;
}
@ -62,14 +62,14 @@ namespace Microsoft.ComponentDetection.Orchestrator.Services
using (var record = new LoadComponentDetectorsTelemetryRecord())
{
Logger.LogInfo($"Attempting to load default detectors");
this.Logger.LogInfo($"Attempting to load default detectors");
var assembly = Assembly.GetAssembly(typeof(IComponentGovernanceOwnedDetectors));
var loadedDetectors = LoadComponentDetectorsFromAssemblies(new[] { assembly }, extraDetectorAssemblies);
var loadedDetectors = this.LoadComponentDetectorsFromAssemblies(new[] { assembly }, extraDetectorAssemblies);
var pluralPhrase = loadedDetectors.Count == 1 ? "detector was" : "detectors were";
Logger.LogInfo($"{loadedDetectors.Count} {pluralPhrase} found in {assembly.GetName().Name}\n");
this.Logger.LogInfo($"{loadedDetectors.Count} {pluralPhrase} found in {assembly.GetName().Name}\n");
detectors.AddRange(loadedDetectors);
@ -80,20 +80,20 @@ namespace Microsoft.ComponentDetection.Orchestrator.Services
{
if (!searchPath.Exists)
{
Logger.LogWarning($"Provided search path {searchPath.FullName} does not exist.");
this.Logger.LogWarning($"Provided search path {searchPath.FullName} does not exist.");
continue;
}
using var record = new LoadComponentDetectorsTelemetryRecord();
Logger.LogInfo($"Attempting to load component detectors from {searchPath}");
this.Logger.LogInfo($"Attempting to load component detectors from {searchPath}");
var assemblies = SafeLoadAssemblies(searchPath.GetFiles("*.dll", SearchOption.AllDirectories).Select(x => x.FullName));
var assemblies = this.SafeLoadAssemblies(searchPath.GetFiles("*.dll", SearchOption.AllDirectories).Select(x => x.FullName));
var loadedDetectors = LoadComponentDetectorsFromAssemblies(assemblies, extraDetectorAssemblies);
var loadedDetectors = this.LoadComponentDetectorsFromAssemblies(assemblies, extraDetectorAssemblies);
var pluralPhrase = loadedDetectors.Count == 1 ? "detector was" : "detectors were";
Logger.LogInfo($"{loadedDetectors.Count} {pluralPhrase} found in {searchPath}\n");
this.Logger.LogInfo($"{loadedDetectors.Count} {pluralPhrase} found in {searchPath}\n");
detectors.AddRange(loadedDetectors);
@ -105,7 +105,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Services
private IList<IComponentDetector> LoadComponentDetectorsFromAssemblies(IEnumerable<Assembly> assemblies, IEnumerable<string> extraDetectorAssemblies)
{
new InjectionParameters(DetectorDependencies);
new InjectionParameters(this.DetectorDependencies);
var configuration = new ContainerConfiguration()
.WithAssemblies(assemblies);

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше