5
5
using System . Linq ;
6
6
using System . Security . Cryptography ;
7
7
using System . Text ;
8
- using System . Text . RegularExpressions ;
9
8
using System . Threading . Tasks ;
10
9
11
10
using Semmle . Util ;
@@ -91,9 +90,9 @@ public DependencyManager(string srcDir, ILogger logger)
91
90
this . generatedSources = new ( ) ;
92
91
var allProjects = allNonBinaryFiles . SelectFileNamesByExtension ( ".csproj" ) . ToList ( ) ;
93
92
var allSolutions = allNonBinaryFiles . SelectFileNamesByExtension ( ".sln" ) . ToList ( ) ;
94
- var dllPaths = allFiles . SelectFileNamesByExtension ( ".dll" ) . Select ( x => new AssemblyLookupLocation ( x ) ) . ToHashSet ( ) ;
93
+ var dllLocations = allFiles . SelectFileNamesByExtension ( ".dll" ) . Select ( x => new AssemblyLookupLocation ( x ) ) . ToHashSet ( ) ;
95
94
96
- logger . LogInfo ( $ "Found { allFiles . Count } files, { nonGeneratedSources . Count } source files, { allProjects . Count } project files, { allSolutions . Count } solution files, { dllPaths . Count } DLLs.") ;
95
+ logger . LogInfo ( $ "Found { allFiles . Count } files, { nonGeneratedSources . Count } source files, { allProjects . Count } project files, { allSolutions . Count } solution files, { dllLocations . Count } DLLs.") ;
97
96
98
97
void startCallback ( string s , bool silent )
99
98
{
@@ -122,12 +121,12 @@ void exitCallback(int ret, string msg, bool silent)
122
121
throw ;
123
122
}
124
123
125
- RestoreNugetPackages ( allNonBinaryFiles , allProjects , allSolutions , dllPaths ) ;
124
+ RestoreNugetPackages ( allNonBinaryFiles , allProjects , allSolutions , dllLocations ) ;
126
125
// Find DLLs in the .Net / Asp.Net Framework
127
126
// This needs to come after the nuget restore, because the nuget restore might fetch the .NET Core/Framework reference assemblies.
128
- var frameworkLocations = AddFrameworkDlls ( dllPaths ) ;
127
+ var frameworkLocations = AddFrameworkDlls ( dllLocations ) ;
129
128
130
- assemblyCache = new AssemblyCache ( dllPaths , frameworkLocations , logger ) ;
129
+ assemblyCache = new AssemblyCache ( dllLocations , frameworkLocations , logger ) ;
131
130
AnalyseSolutions ( allSolutions ) ;
132
131
133
132
foreach ( var filename in assemblyCache . AllAssemblies . Select ( a => a . Filename ) )
@@ -192,17 +191,17 @@ void exitCallback(int ret, string msg, bool silent)
192
191
] ) ;
193
192
}
194
193
195
- private HashSet < string > AddFrameworkDlls ( HashSet < AssemblyLookupLocation > dllPaths )
194
+ private HashSet < string > AddFrameworkDlls ( HashSet < AssemblyLookupLocation > dllLocations )
196
195
{
197
196
var frameworkLocations = new HashSet < string > ( ) ;
198
197
199
198
var frameworkReferences = Environment . GetEnvironmentVariable ( EnvironmentVariableNames . DotnetFrameworkReferences ) ;
200
199
var useSubfolders = EnvironmentVariables . GetBoolean ( EnvironmentVariableNames . DotnetFrameworkReferencesUseSubfolders ) ;
201
200
if ( ! string . IsNullOrWhiteSpace ( frameworkReferences ) )
202
201
{
203
- RemoveFrameworkNugetPackages ( dllPaths ) ;
204
- RemoveNugetPackageReference ( FrameworkPackageNames . AspNetCoreFramework , dllPaths ) ;
205
- RemoveNugetPackageReference ( FrameworkPackageNames . WindowsDesktopFramework , dllPaths ) ;
202
+ RemoveFrameworkNugetPackages ( dllLocations ) ;
203
+ RemoveNugetPackageReference ( FrameworkPackageNames . AspNetCoreFramework , dllLocations ) ;
204
+ RemoveNugetPackageReference ( FrameworkPackageNames . WindowsDesktopFramework , dllLocations ) ;
206
205
207
206
var frameworkPaths = frameworkReferences . Split ( Path . PathSeparator , StringSplitOptions . RemoveEmptyEntries ) ;
208
207
@@ -214,16 +213,16 @@ private HashSet<string> AddFrameworkDlls(HashSet<AssemblyLookupLocation> dllPath
214
213
continue ;
215
214
}
216
215
217
- dllPaths . Add ( new AssemblyLookupLocation ( path , _ => true , useSubfolders ) ) ;
216
+ dllLocations . Add ( new AssemblyLookupLocation ( path , _ => true , useSubfolders ) ) ;
218
217
frameworkLocations . Add ( path ) ;
219
218
}
220
219
221
220
return frameworkLocations ;
222
221
}
223
222
224
- AddNetFrameworkDlls ( dllPaths , frameworkLocations ) ;
225
- AddAspNetCoreFrameworkDlls ( dllPaths , frameworkLocations ) ;
226
- AddMicrosoftWindowsDesktopDlls ( dllPaths , frameworkLocations ) ;
223
+ AddNetFrameworkDlls ( dllLocations , frameworkLocations ) ;
224
+ AddAspNetCoreFrameworkDlls ( dllLocations , frameworkLocations ) ;
225
+ AddMicrosoftWindowsDesktopDlls ( dllLocations , frameworkLocations ) ;
227
226
228
227
return frameworkLocations ;
229
228
}
@@ -263,7 +262,7 @@ private void RemoveNugetAnalyzerReferences()
263
262
}
264
263
}
265
264
266
- private void SelectNewestFrameworkPath ( string frameworkPath , string frameworkType , ISet < AssemblyLookupLocation > dllPaths , ISet < string > frameworkLocations )
265
+ private void SelectNewestFrameworkPath ( string frameworkPath , string frameworkType , ISet < AssemblyLookupLocation > dllLocations , ISet < string > frameworkLocations )
267
266
{
268
267
var versionFolders = GetPackageVersionSubDirectories ( frameworkPath ) ;
269
268
if ( versionFolders . Length > 1 )
@@ -279,7 +278,7 @@ private void SelectNewestFrameworkPath(string frameworkPath, string frameworkTyp
279
278
selectedFrameworkFolder = frameworkPath ;
280
279
}
281
280
282
- dllPaths . Add ( selectedFrameworkFolder ) ;
281
+ dllLocations . Add ( selectedFrameworkFolder ) ;
283
282
frameworkLocations . Add ( selectedFrameworkFolder ) ;
284
283
logger . LogInfo ( $ "Found { frameworkType } DLLs in NuGet packages at { selectedFrameworkFolder } .") ;
285
284
}
@@ -292,16 +291,16 @@ private static DirectoryInfo[] GetPackageVersionSubDirectories(string packagePat
292
291
. ToArray ( ) ;
293
292
}
294
293
295
- private void RemoveFrameworkNugetPackages ( ISet < AssemblyLookupLocation > dllPaths , int fromIndex = 0 )
294
+ private void RemoveFrameworkNugetPackages ( ISet < AssemblyLookupLocation > dllLocations , int fromIndex = 0 )
296
295
{
297
296
var packagesInPrioOrder = FrameworkPackageNames . NetFrameworks ;
298
297
for ( var i = fromIndex ; i < packagesInPrioOrder . Length ; i ++ )
299
298
{
300
- RemoveNugetPackageReference ( packagesInPrioOrder [ i ] , dllPaths ) ;
299
+ RemoveNugetPackageReference ( packagesInPrioOrder [ i ] , dllLocations ) ;
301
300
}
302
301
}
303
302
304
- private void AddNetFrameworkDlls ( ISet < AssemblyLookupLocation > dllPaths , ISet < string > frameworkLocations )
303
+ private void AddNetFrameworkDlls ( ISet < AssemblyLookupLocation > dllLocations , ISet < string > frameworkLocations )
305
304
{
306
305
// Multiple dotnet framework packages could be present.
307
306
// The order of the packages is important, we're adding the first one that is present in the nuget cache.
@@ -321,8 +320,8 @@ private void AddNetFrameworkDlls(ISet<AssemblyLookupLocation> dllPaths, ISet<str
321
320
dotnetFrameworkVersionVariantCount += GetPackageVersionSubDirectories ( fp . Path ! ) . Length ;
322
321
}
323
322
324
- SelectNewestFrameworkPath ( frameworkPath . Path , ".NET Framework" , dllPaths , frameworkLocations ) ;
325
- RemoveFrameworkNugetPackages ( dllPaths , frameworkPath . Index + 1 ) ;
323
+ SelectNewestFrameworkPath ( frameworkPath . Path , ".NET Framework" , dllLocations , frameworkLocations ) ;
324
+ RemoveFrameworkNugetPackages ( dllLocations , frameworkPath . Index + 1 ) ;
326
325
return ;
327
326
}
328
327
@@ -350,18 +349,18 @@ private void AddNetFrameworkDlls(ISet<AssemblyLookupLocation> dllPaths, ISet<str
350
349
if ( runtimeLocation is null )
351
350
{
352
351
runtimeLocation ??= Runtime . ExecutingRuntime ;
353
- dllPaths . Add ( new AssemblyLookupLocation ( runtimeLocation , name => ! name . StartsWith ( "Semmle." ) ) ) ;
352
+ dllLocations . Add ( new AssemblyLookupLocation ( runtimeLocation , name => ! name . StartsWith ( "Semmle." ) ) ) ;
354
353
}
355
354
else
356
355
{
357
- dllPaths . Add ( runtimeLocation ) ;
356
+ dllLocations . Add ( runtimeLocation ) ;
358
357
}
359
358
360
359
logger . LogInfo ( $ ".NET runtime location selected: { runtimeLocation } ") ;
361
360
frameworkLocations . Add ( runtimeLocation ) ;
362
361
}
363
362
364
- private void RemoveNugetPackageReference ( string packagePrefix , ISet < AssemblyLookupLocation > dllPaths )
363
+ private void RemoveNugetPackageReference ( string packagePrefix , ISet < AssemblyLookupLocation > dllLocations )
365
364
{
366
365
var packageFolder = packageDirectory . DirInfo . FullName . ToLowerInvariant ( ) ;
367
366
if ( packageFolder == null )
@@ -370,10 +369,10 @@ private void RemoveNugetPackageReference(string packagePrefix, ISet<AssemblyLook
370
369
}
371
370
372
371
var packagePathPrefix = Path . Combine ( packageFolder , packagePrefix . ToLowerInvariant ( ) ) ;
373
- var toRemove = dllPaths . Where ( s => s . Path . StartsWith ( packagePathPrefix , StringComparison . InvariantCultureIgnoreCase ) ) ;
372
+ var toRemove = dllLocations . Where ( s => s . Path . StartsWith ( packagePathPrefix , StringComparison . InvariantCultureIgnoreCase ) ) ;
374
373
foreach ( var path in toRemove )
375
374
{
376
- dllPaths . Remove ( path ) ;
375
+ dllLocations . Remove ( path ) ;
377
376
logger . LogInfo ( $ "Removed reference { path } ") ;
378
377
}
379
378
}
@@ -383,7 +382,7 @@ private bool IsAspNetCoreDetected()
383
382
return fileContent . IsNewProjectStructureUsed && fileContent . UseAspNetCoreDlls ;
384
383
}
385
384
386
- private void AddAspNetCoreFrameworkDlls ( ISet < AssemblyLookupLocation > dllPaths , ISet < string > frameworkLocations )
385
+ private void AddAspNetCoreFrameworkDlls ( ISet < AssemblyLookupLocation > dllLocations , ISet < string > frameworkLocations )
387
386
{
388
387
if ( ! IsAspNetCoreDetected ( ) )
389
388
{
@@ -393,23 +392,23 @@ private void AddAspNetCoreFrameworkDlls(ISet<AssemblyLookupLocation> dllPaths, I
393
392
// First try to find ASP.NET Core assemblies in the NuGet packages
394
393
if ( GetPackageDirectory ( FrameworkPackageNames . AspNetCoreFramework , packageDirectory ) is string aspNetCorePackage )
395
394
{
396
- SelectNewestFrameworkPath ( aspNetCorePackage , "ASP.NET Core" , dllPaths , frameworkLocations ) ;
395
+ SelectNewestFrameworkPath ( aspNetCorePackage , "ASP.NET Core" , dllLocations , frameworkLocations ) ;
397
396
return ;
398
397
}
399
398
400
399
if ( Runtime . AspNetCoreRuntime is string aspNetCoreRuntime )
401
400
{
402
401
logger . LogInfo ( $ "ASP.NET runtime location selected: { aspNetCoreRuntime } ") ;
403
- dllPaths . Add ( aspNetCoreRuntime ) ;
402
+ dllLocations . Add ( aspNetCoreRuntime ) ;
404
403
frameworkLocations . Add ( aspNetCoreRuntime ) ;
405
404
}
406
405
}
407
406
408
- private void AddMicrosoftWindowsDesktopDlls ( ISet < AssemblyLookupLocation > dllPaths , ISet < string > frameworkLocations )
407
+ private void AddMicrosoftWindowsDesktopDlls ( ISet < AssemblyLookupLocation > dllLocations , ISet < string > frameworkLocations )
409
408
{
410
409
if ( GetPackageDirectory ( FrameworkPackageNames . WindowsDesktopFramework , packageDirectory ) is string windowsDesktopApp )
411
410
{
412
- SelectNewestFrameworkPath ( windowsDesktopApp , "Windows Desktop App" , dllPaths , frameworkLocations ) ;
411
+ SelectNewestFrameworkPath ( windowsDesktopApp , "Windows Desktop App" , dllLocations , frameworkLocations ) ;
413
412
}
414
413
}
415
414
0 commit comments