Skip to content

Commit 4bc08c2

Browse files
authored
Merge pull request #33 from nexB/no-medatata-fail
Do not fail on missing medatata
2 parents c7586b4 + 4d8988a commit 4bc08c2

File tree

137 files changed

+81958
-105455
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+81958
-105455
lines changed

CHANGELOG.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ This is a major feature update release with these updates and API breaking chang
1717

1818
* Ensure we do not fail with a Package reference with no version.
1919

20+
* Ensure we do not fail when a package detailed metadata cannot be fetched when
21+
using the --with-details option.
22+
2023

2124
v0.9.7
2225
-------

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ dotnet publish \
1717
--runtime linux-x64 \
1818
--self-contained true \
1919
--configuration Release \
20-
-p:Version=0.9.8-beta1 \
20+
-p:Version=0.9.8 \
2121
--output build \
2222
src/nuget-inspector/nuget-inspector.csproj

release.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
rm -rf release/
1717
mkdir release
1818

19-
VERSION=0.9.8-beta1
19+
VERSION=0.9.8
2020

2121
TARGET_BASE=nuget-inspector-$(git describe)
2222

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[bumpversion]
22
commit = False
33
tag = False
4-
current_version = 0.9.8-beta1
4+
current_version = 0.9.8
55
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+))?
66
serialize =
77
{major}.{minor}.{patch}-{release}

src/nuget-inspector/Config.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ public static class Config
99
public static bool TRACE_DEEP = false;
1010
public static bool TRACE_META = false;
1111
public static bool TRACE_OUTPUT = false;
12-
public const string NUGET_INSPECTOR_VERSION = "0.9.8-beta1";
12+
public const string NUGET_INSPECTOR_VERSION = "0.9.8";
1313
#pragma warning restore CA2211
1414
}

src/nuget-inspector/NugetApi.cs

Lines changed: 64 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class NugetApi
3030
};
3131
private readonly GatherCache gather_cache = new();
3232

33-
private readonly Dictionary<string, JObject> catalog_entry_by_catalog_url = new();
33+
private readonly Dictionary<string, JObject?> catalog_entry_by_catalog_url = new();
3434
private readonly Dictionary<string, List<PackageSearchMetadataRegistration>> psmrs_by_package_name = new();
3535
private readonly Dictionary<PackageIdentity, PackageSearchMetadataRegistration?> psmr_by_identity = new();
3636
private readonly Dictionary<(PackageIdentity, NuGetFramework), PackageDownload?> download_by_identity = new();
@@ -120,12 +120,12 @@ private List<PackageSearchMetadataRegistration> FindPackageVersionsThroughCache(
120120
public PackageSearchMetadataRegistration? FindPackageVersion(PackageIdentity pid)
121121
{
122122
if (Config.TRACE)
123-
Console.WriteLine($"FindPackageVersion: {pid}");
123+
Console.WriteLine($"Fetching package metadata for: {pid}");
124124

125125
if (psmr_by_identity.TryGetValue(key: pid, out PackageSearchMetadataRegistration? psmr))
126126
{
127127
if (Config.TRACE)
128-
Console.WriteLine($" Metadata Cache hit for '{pid}'");
128+
Console.WriteLine($" Metadata Cache hit for '{pid}'");
129129
return psmr;
130130
}
131131

@@ -145,7 +145,7 @@ private List<PackageSearchMetadataRegistration> FindPackageVersionsThroughCache(
145145
if (psmr != null)
146146
{
147147
if (Config.TRACE)
148-
Console.WriteLine($" Found metadata for '{pid}' from: {metadata_resources}");
148+
Console.WriteLine($" Found metadata for '{pid}' from: {metadata_resource}");
149149
psmr_by_identity[pid] = psmr;
150150
return psmr;
151151
}
@@ -398,8 +398,8 @@ public IEnumerable<PackageDependency> GetPackageDependenciesForPackage(PackageId
398398
return spdi;
399399
}
400400

401-
if (Config.TRACE_DEEP)
402-
Console.WriteLine($" GetPackageInfo: {identity} framework: {framework}");
401+
if (Config.TRACE)
402+
Console.WriteLine($" GetPackageInfo: {identity} framework: {framework}");
403403

404404
foreach (var dir in dependency_info_resources)
405405
{
@@ -415,10 +415,13 @@ public IEnumerable<PackageDependency> GetPackageDependenciesForPackage(PackageId
415415
spdi = infoTask.Result;
416416

417417
if (Config.TRACE && spdi != null)
418-
Console.WriteLine($" url: {spdi.DownloadUri} hash: {spdi.PackageHash}");
418+
Console.WriteLine($" Found download URL: {spdi.DownloadUri} hash: {spdi.PackageHash}");
419419

420420
if (spdi != null)
421-
spdi_by_identity[(identity, project_framework)] = spdi;
421+
{
422+
spdi_by_identity[(identity, project_framework)] = spdi;
423+
return spdi;
424+
}
422425
}
423426
catch (Exception e)
424427
{
@@ -462,19 +465,18 @@ public IEnumerable<PackageDependency> GetPackageDependenciesForPackage(PackageId
462465
var spdi = GetResolvedSourcePackageDependencyInfo(
463466
identity: identity,
464467
framework: project_framework);
468+
if (Config.TRACE)
469+
Console.WriteLine($" Info available for package '{spdi}'");
465470

466471
if (spdi != null)
467472
{
468473
download = PackageDownload.FromSpdi(spdi);
469474
download_by_identity[(identity, project_framework)] = download;
470475
}
471-
else
472-
{
473-
if (Config.TRACE)
474-
Console.WriteLine($" No download info available for package '{identity}'");
475-
476-
download_by_identity[(identity, project_framework)] = download;
477-
}
476+
// else
477+
// {
478+
// download_by_identity[(identity, project_framework)] = download;
479+
// }
478480
}
479481

480482
if (!with_details || (with_details && download?.IsEnhanced() == true))
@@ -501,35 +503,49 @@ public IEnumerable<PackageDependency> GetPackageDependenciesForPackage(PackageId
501503
if (Config.TRACE_NET)
502504
Console.WriteLine($" Fetching catalog for package_catalog_url: {package_catalog_url}");
503505

504-
JObject catalog_entry;
506+
JObject? catalog_entry;
505507
if (catalog_entry_by_catalog_url.ContainsKey(package_catalog_url))
506508
{
507509
catalog_entry = catalog_entry_by_catalog_url[package_catalog_url];
508510
}
509511
else
510512
{
511513
// note: this is caching accross runs
512-
RequestCachePolicy policy = new(RequestCacheLevel.Default);
513-
WebRequest request = WebRequest.Create(package_catalog_url);
514-
request.CachePolicy = policy;
515-
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
516-
string catalog = new StreamReader(response.GetResponseStream()).ReadToEnd();
517-
catalog_entry = JObject.Parse(catalog);
518-
// note: this is caching accross calls in a run
519-
catalog_entry_by_catalog_url[package_catalog_url] = catalog_entry;
514+
try
515+
{
516+
RequestCachePolicy policy = new(RequestCacheLevel.Default);
517+
WebRequest request = WebRequest.Create(package_catalog_url);
518+
request.CachePolicy = policy;
519+
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
520+
string catalog = new StreamReader(response.GetResponseStream()).ReadToEnd();
521+
catalog_entry = JObject.Parse(catalog);
522+
// note: this is caching accross calls in a run
523+
catalog_entry_by_catalog_url[package_catalog_url] = catalog_entry;
524+
}
525+
catch (Exception ex)
526+
{
527+
if (Config.TRACE_NET)
528+
Console.WriteLine($" failed to fetch metadata details for: {package_catalog_url}: {ex}");
529+
catalog_entry_by_catalog_url[package_catalog_url] = null;
530+
return null;
531+
}
520532
}
521-
522-
string hash = catalog_entry["packageHash"]!.ToString();
523-
if (download != null)
533+
if (catalog_entry != null)
524534
{
525-
download.hash = Convert.ToHexString(Convert.FromBase64String(hash));
526-
download.hash_algorithm = catalog_entry["packageHashAlgorithm"]!.ToString();
527-
download.size = (int)catalog_entry["packageSize"]!;
535+
string hash = catalog_entry["packageHash"]
536+
!.ToString();
537+
if (download != null)
538+
{
539+
download.hash = Convert.ToHexString(Convert.FromBase64String(hash));
540+
download.hash_algorithm = catalog_entry["packageHashAlgorithm"]!.ToString();
541+
download.size = (int)catalog_entry["packageSize"]!;
542+
}
543+
if (Config.TRACE_NET)
544+
Console.WriteLine($" download: {download}");
545+
download_by_identity[(identity, project_framework)] = download;
546+
return download;
528547
}
529-
if (Config.TRACE_NET)
530-
Console.WriteLine($" download: {download}");
531-
download_by_identity[(identity, project_framework)] = download;
532-
return download;
548+
return null;
533549
}
534550

535551
/// <summary>
@@ -714,8 +730,8 @@ public HashSet<SourcePackageDependencyInfo> ResolveDependenciesForPackageReferen
714730

715731
foreach (GraphNode<RemoteResolveResult> inner in resolved_graph.InnerNodes)
716732
{
717-
if (Config.TRACE)
718-
Console.WriteLine($" inner.Key.TypeConstraint: {inner.Key.TypeConstraint} name: {inner.Item.Key.Name} version: {inner.Item.Key.Version}");
733+
if (Config.TRACE_DEEP)
734+
Console.WriteLine($" Resolved direct dependency: {inner.Item.Key.Name}@{inner.Item.Key.Version}");
719735

720736
FlattenGraph(inner, resolved_package_info_by_package_id);
721737
}
@@ -724,10 +740,12 @@ public HashSet<SourcePackageDependencyInfo> ResolveDependenciesForPackageReferen
724740
foreach (KeyValuePair<PackageId, ResolvedPackageInfo> item in resolved_package_info_by_package_id)
725741
{
726742
var dependency = item.Key;
727-
var dpi = item.Value;
728-
var source_repo = dpi.remote_match?.Provider.Source;
729-
if (Config.TRACE)
730-
Console.WriteLine($" flat_dependency: {dependency.Name} {dependency.Version} repo: {source_repo?.SourceUri}");
743+
if (Config.TRACE_DEEP)
744+
{
745+
var dpi = item.Value;
746+
var source_repo = dpi.remote_match?.Provider?.Source;
747+
Console.WriteLine($" flat_dependency: {dependency.Name} {dependency.Version} repo: {source_repo?.SourceUri}");
748+
}
731749

732750
var spdi = new SourcePackageDependencyInfo(
733751
id: dependency.Name,
@@ -756,7 +774,7 @@ public static void FlattenGraph(
756774
GraphItem<RemoteResolveResult> item = node.Item;
757775
if (item == null)
758776
{
759-
string message = $"FlattenGraph: node Item is null '{node}'";
777+
string message = $" FlattenGraph: node Item is null '{node}'";
760778
if (Config.TRACE)
761779
{
762780
Console.WriteLine($" {message}");
@@ -767,8 +785,8 @@ public static void FlattenGraph(
767785
string name = key.Name;
768786
string version = key.Version.ToNormalizedString();
769787
bool isPrerelease = key.Version.IsPrerelease;
770-
if (Config.TRACE)
771-
Console.WriteLine($" FlattenGraph: node.Item {node.Item} LibraryId: {key}");
788+
if (Config.TRACE_DEEP)
789+
Console.WriteLine($" FlattenGraph: node.Item {node.Item} LibraryId: {key}");
772790

773791
var pid = new PackageId(
774792
id: name,
@@ -780,8 +798,10 @@ public static void FlattenGraph(
780798
package_id = pid,
781799
remote_match = (RemoteMatch?)item.Data.Match
782800
};
783-
if (Config.TRACE)
801+
802+
if (Config.TRACE_DEEP)
784803
Console.WriteLine($" FlattenGraph: {pid} Library: {item.Data.Match.Library}");
804+
785805
if (!resolved_package_info_by_package_id.ContainsKey(resolved_package_info.package_id))
786806
resolved_package_info_by_package_id.Add(resolved_package_info.package_id, resolved_package_info);
787807

src/nuget-inspector/Program.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -213,21 +213,22 @@ static void PrintWarnings(ScanResult scan_result, BasePackage project_package)
213213
static void PrintErrors(ScanResult scan_result, BasePackage project_package)
214214
{
215215
if (scan_result.errors.Any())
216-
Console.WriteLine(" ERROR: " + string.Join(", ", scan_result.errors));
216+
Console.WriteLine("\nERROR: " + string.Join(", ", scan_result.errors));
217217

218-
Console.WriteLine(" Errors at the package level");
219-
Console.WriteLine($" {project_package.name}@{project_package.version} with purl: {project_package.purl}");
220218
if (project_package.errors.Any())
221-
Console.WriteLine(" ERROR: " + string.Join(", ", project_package.errors));
219+
{
220+
Console.WriteLine("\nERRORS at the package level:");
221+
Console.WriteLine($" {project_package.name}@{project_package.version} with purl: {project_package.purl}");
222+
Console.WriteLine(" ERROR: " + string.Join(", ", project_package.errors));
223+
}
222224

223-
Console.WriteLine(" Errors at the dependencies level");
225+
Console.WriteLine("\nERRORS at the dependencies level:");
224226
foreach (var dep in project_package.GetFlatDependencies())
225227
{
226228
if (dep.errors.Any())
227229
{
228-
Console.WriteLine($" {dep.name}@{dep.version} with purl: {dep.purl}");
229-
if (dep.errors.Any())
230-
Console.WriteLine(" ERROR: " + string.Join(", ", dep.errors));
230+
Console.WriteLine($" ERRORS for dependency: {dep.name}@{dep.version} with purl: {dep.purl}");
231+
Console.WriteLine(" ERROR: " + string.Join(", ", dep.errors));
231232
}
232233
}
233234
}

src/nuget-inspector/ProjectFileProcessor.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public virtual List<PackageReference> GetPackageReferences()
124124
if (Config.TRACE)
125125
Console.WriteLine($"ProjectFileProcessor.GetPackageReferences: ProjectPath {ProjectPath}");
126126

127-
var references = new List<PackageReference>();
127+
List<PackageReference> references = new();
128128

129129
// TODO: consider reading global.json if present?
130130
Dictionary<string, string> properties = new();
@@ -399,7 +399,7 @@ public DependencyResolution ResolveUseGather()
399399
DependencyResolution resolution = new(success: true);
400400
foreach (SourcePackageDependencyInfo resolved_dep in resolved_deps)
401401
{
402-
if (Config.TRACE)
402+
if (Config.TRACE_DEEP)
403403
{
404404
Console.WriteLine($" resolved: {resolved_dep.Id}@{resolved_dep.Version}");
405405
foreach (var subdep in resolved_dep.Dependencies)
@@ -427,30 +427,29 @@ public DependencyResolution ResolveUsingLib()
427427
if (references.Count == 0)
428428
{
429429
if (Config.TRACE)
430-
Console.WriteLine(" no references");
430+
Console.WriteLine(" No references found.");
431431

432432
return new DependencyResolution(success: true);
433433
}
434434
else if (Config.TRACE)
435435
{
436-
foreach (var reference in references)
437-
Console.WriteLine($" found reference: {reference}");
436+
Console.WriteLine($" Found #{references.Count} references");
438437
}
439438

440439
references = DeduplicateReferences(references);
441-
if (Config.TRACE)
440+
if (Config.TRACE_DEEP)
442441
{
443442
foreach (var reference in references)
444-
Console.WriteLine($" found dedup reference: {reference}");
443+
Console.WriteLine($" Deduped reference: {reference}");
445444
}
446445
HashSet<SourcePackageDependencyInfo> resolved_deps = nugetApi.ResolveDependenciesForPackageReference(target_references: references);
447446

448447
DependencyResolution resolution = new(success: true);
449448
foreach (SourcePackageDependencyInfo resolved_dep in resolved_deps)
450449
{
451-
if (Config.TRACE)
450+
if (Config.TRACE_DEEP)
452451
{
453-
Console.WriteLine($" resolved: {resolved_dep.Id}@{resolved_dep.Version}");
452+
Console.WriteLine($" resolved: {resolved_dep.Id}@{resolved_dep.Version}");
454453
foreach (var subdep in resolved_dep.Dependencies)
455454
Console.WriteLine($" subdep: {subdep.Id}@{subdep.VersionRange}");
456455
}

src/nuget-inspector/ProjectScanner.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,10 @@ public ScanResult RunScan()
312312
}
313313
catch (Exception ex)
314314
{
315-
string message = $"Failed to process project file: {ScannerOptions.ProjectFilePath} with: {ex}";
315+
string message = $"Failed to process project file: {ScannerOptions.ProjectFilePath} with:\n{ex}";
316316
scan_result.errors.Add(message);
317317
scan_result.Status = ScanResult.ResultStatus.Error;
318-
if (Config.TRACE) Console.WriteLine($" {message}");
318+
if (Config.TRACE) Console.WriteLine($"\nERROR: {message}\n");
319319
}
320320

321321
if (!ScannerOptions.WithFallback)
@@ -354,10 +354,10 @@ public ScanResult RunScan()
354354
}
355355
catch (Exception ex)
356356
{
357-
string message = $"Failed to process *.*proj project file as bare XML: {ScannerOptions.ProjectFilePath} with: {ex}";
357+
string message = $"Failed to process *.*proj project file as bare XML: {ScannerOptions.ProjectFilePath} with:\n{ex}";
358358
scan_result.errors.Add(message);
359359
scan_result.Status = ScanResult.ResultStatus.Error;
360-
if (Config.TRACE) Console.WriteLine($" {message}");
360+
if (Config.TRACE) Console.WriteLine($"\nERROR: {message}\n");
361361
}
362362

363363
return scan_result;

src/nuget-inspector/nuget-inspector.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<PackageId>nuget-inspector</PackageId>
2424
<Product>nuget-inspector</Product>
2525
<AssemblyName>nuget-inspector</AssemblyName>
26-
<Version>0.9.8-beta1</Version>
26+
<Version>0.9.8</Version>
2727
<Authors>nexB Inc.</Authors>
2828
<Company>nexB Inc</Company>
2929
<AssemblyVersion>0.9.8.0</AssemblyVersion>

0 commit comments

Comments
 (0)