55using System . Linq ;
66using System . Security . Cryptography ;
77using System . Text ;
8- using System . Text . RegularExpressions ;
98using System . Threading . Tasks ;
109
1110using Semmle . Util ;
@@ -91,9 +90,9 @@ public DependencyManager(string srcDir, ILogger logger)
9190 this . generatedSources = new ( ) ;
9291 var allProjects = allNonBinaryFiles . SelectFileNamesByExtension ( ".csproj" ) . ToList ( ) ;
9392 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 ( ) ;
9594
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.") ;
9796
9897 void startCallback ( string s , bool silent )
9998 {
@@ -122,12 +121,12 @@ void exitCallback(int ret, string msg, bool silent)
122121 throw ;
123122 }
124123
125- RestoreNugetPackages ( allNonBinaryFiles , allProjects , allSolutions , dllPaths ) ;
124+ RestoreNugetPackages ( allNonBinaryFiles , allProjects , allSolutions , dllLocations ) ;
126125 // Find DLLs in the .Net / Asp.Net Framework
127126 // 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 ) ;
129128
130- assemblyCache = new AssemblyCache ( dllPaths , frameworkLocations , logger ) ;
129+ assemblyCache = new AssemblyCache ( dllLocations , frameworkLocations , logger ) ;
131130 AnalyseSolutions ( allSolutions ) ;
132131
133132 foreach ( var filename in assemblyCache . AllAssemblies . Select ( a => a . Filename ) )
@@ -192,17 +191,17 @@ void exitCallback(int ret, string msg, bool silent)
192191 ] ) ;
193192 }
194193
195- private HashSet < string > AddFrameworkDlls ( HashSet < AssemblyLookupLocation > dllPaths )
194+ private HashSet < string > AddFrameworkDlls ( HashSet < AssemblyLookupLocation > dllLocations )
196195 {
197196 var frameworkLocations = new HashSet < string > ( ) ;
198197
199198 var frameworkReferences = Environment . GetEnvironmentVariable ( EnvironmentVariableNames . DotnetFrameworkReferences ) ;
200199 var useSubfolders = EnvironmentVariables . GetBoolean ( EnvironmentVariableNames . DotnetFrameworkReferencesUseSubfolders ) ;
201200 if ( ! string . IsNullOrWhiteSpace ( frameworkReferences ) )
202201 {
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 ) ;
206205
207206 var frameworkPaths = frameworkReferences . Split ( Path . PathSeparator , StringSplitOptions . RemoveEmptyEntries ) ;
208207
@@ -214,16 +213,16 @@ private HashSet<string> AddFrameworkDlls(HashSet<AssemblyLookupLocation> dllPath
214213 continue ;
215214 }
216215
217- dllPaths . Add ( new AssemblyLookupLocation ( path , _ => true , useSubfolders ) ) ;
216+ dllLocations . Add ( new AssemblyLookupLocation ( path , _ => true , useSubfolders ) ) ;
218217 frameworkLocations . Add ( path ) ;
219218 }
220219
221220 return frameworkLocations ;
222221 }
223222
224- AddNetFrameworkDlls ( dllPaths , frameworkLocations ) ;
225- AddAspNetCoreFrameworkDlls ( dllPaths , frameworkLocations ) ;
226- AddMicrosoftWindowsDesktopDlls ( dllPaths , frameworkLocations ) ;
223+ AddNetFrameworkDlls ( dllLocations , frameworkLocations ) ;
224+ AddAspNetCoreFrameworkDlls ( dllLocations , frameworkLocations ) ;
225+ AddMicrosoftWindowsDesktopDlls ( dllLocations , frameworkLocations ) ;
227226
228227 return frameworkLocations ;
229228 }
@@ -263,7 +262,7 @@ private void RemoveNugetAnalyzerReferences()
263262 }
264263 }
265264
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 )
267266 {
268267 var versionFolders = GetPackageVersionSubDirectories ( frameworkPath ) ;
269268 if ( versionFolders . Length > 1 )
@@ -279,7 +278,7 @@ private void SelectNewestFrameworkPath(string frameworkPath, string frameworkTyp
279278 selectedFrameworkFolder = frameworkPath ;
280279 }
281280
282- dllPaths . Add ( selectedFrameworkFolder ) ;
281+ dllLocations . Add ( selectedFrameworkFolder ) ;
283282 frameworkLocations . Add ( selectedFrameworkFolder ) ;
284283 logger . LogInfo ( $ "Found { frameworkType } DLLs in NuGet packages at { selectedFrameworkFolder } .") ;
285284 }
@@ -292,16 +291,16 @@ private static DirectoryInfo[] GetPackageVersionSubDirectories(string packagePat
292291 . ToArray ( ) ;
293292 }
294293
295- private void RemoveFrameworkNugetPackages ( ISet < AssemblyLookupLocation > dllPaths , int fromIndex = 0 )
294+ private void RemoveFrameworkNugetPackages ( ISet < AssemblyLookupLocation > dllLocations , int fromIndex = 0 )
296295 {
297296 var packagesInPrioOrder = FrameworkPackageNames . NetFrameworks ;
298297 for ( var i = fromIndex ; i < packagesInPrioOrder . Length ; i ++ )
299298 {
300- RemoveNugetPackageReference ( packagesInPrioOrder [ i ] , dllPaths ) ;
299+ RemoveNugetPackageReference ( packagesInPrioOrder [ i ] , dllLocations ) ;
301300 }
302301 }
303302
304- private void AddNetFrameworkDlls ( ISet < AssemblyLookupLocation > dllPaths , ISet < string > frameworkLocations )
303+ private void AddNetFrameworkDlls ( ISet < AssemblyLookupLocation > dllLocations , ISet < string > frameworkLocations )
305304 {
306305 // Multiple dotnet framework packages could be present.
307306 // 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
321320 dotnetFrameworkVersionVariantCount += GetPackageVersionSubDirectories ( fp . Path ! ) . Length ;
322321 }
323322
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 ) ;
326325 return ;
327326 }
328327
@@ -350,18 +349,18 @@ private void AddNetFrameworkDlls(ISet<AssemblyLookupLocation> dllPaths, ISet<str
350349 if ( runtimeLocation is null )
351350 {
352351 runtimeLocation ??= Runtime . ExecutingRuntime ;
353- dllPaths . Add ( new AssemblyLookupLocation ( runtimeLocation , name => ! name . StartsWith ( "Semmle." ) ) ) ;
352+ dllLocations . Add ( new AssemblyLookupLocation ( runtimeLocation , name => ! name . StartsWith ( "Semmle." ) ) ) ;
354353 }
355354 else
356355 {
357- dllPaths . Add ( runtimeLocation ) ;
356+ dllLocations . Add ( runtimeLocation ) ;
358357 }
359358
360359 logger . LogInfo ( $ ".NET runtime location selected: { runtimeLocation } ") ;
361360 frameworkLocations . Add ( runtimeLocation ) ;
362361 }
363362
364- private void RemoveNugetPackageReference ( string packagePrefix , ISet < AssemblyLookupLocation > dllPaths )
363+ private void RemoveNugetPackageReference ( string packagePrefix , ISet < AssemblyLookupLocation > dllLocations )
365364 {
366365 var packageFolder = packageDirectory . DirInfo . FullName . ToLowerInvariant ( ) ;
367366 if ( packageFolder == null )
@@ -370,10 +369,10 @@ private void RemoveNugetPackageReference(string packagePrefix, ISet<AssemblyLook
370369 }
371370
372371 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 ) ) ;
374373 foreach ( var path in toRemove )
375374 {
376- dllPaths . Remove ( path ) ;
375+ dllLocations . Remove ( path ) ;
377376 logger . LogInfo ( $ "Removed reference { path } ") ;
378377 }
379378 }
@@ -383,7 +382,7 @@ private bool IsAspNetCoreDetected()
383382 return fileContent . IsNewProjectStructureUsed && fileContent . UseAspNetCoreDlls ;
384383 }
385384
386- private void AddAspNetCoreFrameworkDlls ( ISet < AssemblyLookupLocation > dllPaths , ISet < string > frameworkLocations )
385+ private void AddAspNetCoreFrameworkDlls ( ISet < AssemblyLookupLocation > dllLocations , ISet < string > frameworkLocations )
387386 {
388387 if ( ! IsAspNetCoreDetected ( ) )
389388 {
@@ -393,23 +392,23 @@ private void AddAspNetCoreFrameworkDlls(ISet<AssemblyLookupLocation> dllPaths, I
393392 // First try to find ASP.NET Core assemblies in the NuGet packages
394393 if ( GetPackageDirectory ( FrameworkPackageNames . AspNetCoreFramework , packageDirectory ) is string aspNetCorePackage )
395394 {
396- SelectNewestFrameworkPath ( aspNetCorePackage , "ASP.NET Core" , dllPaths , frameworkLocations ) ;
395+ SelectNewestFrameworkPath ( aspNetCorePackage , "ASP.NET Core" , dllLocations , frameworkLocations ) ;
397396 return ;
398397 }
399398
400399 if ( Runtime . AspNetCoreRuntime is string aspNetCoreRuntime )
401400 {
402401 logger . LogInfo ( $ "ASP.NET runtime location selected: { aspNetCoreRuntime } ") ;
403- dllPaths . Add ( aspNetCoreRuntime ) ;
402+ dllLocations . Add ( aspNetCoreRuntime ) ;
404403 frameworkLocations . Add ( aspNetCoreRuntime ) ;
405404 }
406405 }
407406
408- private void AddMicrosoftWindowsDesktopDlls ( ISet < AssemblyLookupLocation > dllPaths , ISet < string > frameworkLocations )
407+ private void AddMicrosoftWindowsDesktopDlls ( ISet < AssemblyLookupLocation > dllLocations , ISet < string > frameworkLocations )
409408 {
410409 if ( GetPackageDirectory ( FrameworkPackageNames . WindowsDesktopFramework , packageDirectory ) is string windowsDesktopApp )
411410 {
412- SelectNewestFrameworkPath ( windowsDesktopApp , "Windows Desktop App" , dllPaths , frameworkLocations ) ;
411+ SelectNewestFrameworkPath ( windowsDesktopApp , "Windows Desktop App" , dllLocations , frameworkLocations ) ;
413412 }
414413 }
415414
0 commit comments