|
1 |
| -using System; |
2 |
| -using System.Collections.Generic; |
3 |
| -using System.IO; |
| 1 | +using System.Collections.Generic; |
4 | 2 | using System.Linq;
|
5 | 3 | using Semmle.Util.Logging;
|
6 | 4 |
|
7 | 5 | namespace Semmle.Extraction.CSharp.DependencyFetching
|
8 | 6 | {
|
9 |
| - /// <summary> |
10 |
| - /// Used to represent a path to an assembly or a directory containing assemblies |
11 |
| - /// and a selector function to determine which files to include, when indexing the assemblies. |
12 |
| - /// </summary> |
13 |
| - internal sealed class AssemblyPath(string p, Func<string, bool> includeFileName) |
14 |
| - { |
15 |
| - public string Path => p; |
16 |
| - |
17 |
| - public AssemblyPath(string p) : this(p, _ => true) { } |
18 |
| - |
19 |
| - public static implicit operator AssemblyPath(string path) => new(path); |
20 |
| - |
21 |
| - /// <summary> |
22 |
| - /// Finds all assemblies nested within the directory `path` |
23 |
| - /// and adds them to the a list of assembly names to index. |
24 |
| - /// Indexing is performed at a later stage. This only collects the names. |
25 |
| - /// </summary> |
26 |
| - /// <param name="dir">The directory to index.</param> |
27 |
| - private void AddReferenceDirectory(List<string> dllsToIndex, ILogger logger) |
28 |
| - { |
29 |
| - foreach (var dll in new DirectoryInfo(p).EnumerateFiles("*.dll", SearchOption.AllDirectories)) |
30 |
| - { |
31 |
| - if (includeFileName(dll.Name)) |
32 |
| - { |
33 |
| - dllsToIndex.Add(dll.FullName); |
34 |
| - } |
35 |
| - else |
36 |
| - { |
37 |
| - logger.LogInfo($"AssemblyPath: Skipping {dll.FullName}."); |
38 |
| - } |
39 |
| - } |
40 |
| - } |
41 |
| - |
42 |
| - /// <summary> |
43 |
| - /// Finds all assemblies in `p` that should be indexed and adds them to |
44 |
| - /// the list of assembly names to index. |
45 |
| - /// </summary> |
46 |
| - /// <param name="dllsToIndex">List of assembly names to index.</param> |
47 |
| - /// <param name="logger">Logger</param> |
48 |
| - public void Process(List<string> dllsToIndex, ILogger logger) |
49 |
| - { |
50 |
| - if (File.Exists(p)) |
51 |
| - { |
52 |
| - if (includeFileName(System.IO.Path.GetFileName(p))) |
53 |
| - { |
54 |
| - dllsToIndex.Add(p); |
55 |
| - } |
56 |
| - else |
57 |
| - { |
58 |
| - logger.LogInfo($"AssemblyPath: Skipping {p}."); |
59 |
| - } |
60 |
| - return; |
61 |
| - } |
62 |
| - |
63 |
| - if (Directory.Exists(p)) |
64 |
| - { |
65 |
| - logger.LogInfo($"AssemblyPath: Finding reference DLLs in {p}..."); |
66 |
| - AddReferenceDirectory(dllsToIndex, logger); |
67 |
| - } |
68 |
| - else |
69 |
| - { |
70 |
| - logger.LogInfo("AssemblyCache: Path not found: " + p); |
71 |
| - } |
72 |
| - } |
73 |
| - |
74 |
| - public override bool Equals(object? obj) => |
75 |
| - obj is AssemblyPath ap && p.Equals(ap.Path); |
76 |
| - |
77 |
| - public override int GetHashCode() => p.GetHashCode(); |
78 |
| - |
79 |
| - public override string ToString() => p; |
80 |
| - } |
81 |
| - |
82 | 7 | /// <summary>
|
83 | 8 | /// Manages the set of assemblies.
|
84 | 9 | /// Searches for assembly DLLs, indexes them and provides
|
|
0 commit comments