Skip to content

Commit 522e921

Browse files
authored
Merge pull request #28 from nexB/errors-and-nuget-config
Process Errors and nuget config Also implement a new nuget resolver for PackageReferences
2 parents 4c1338f + 5a2ba71 commit 522e921

File tree

525 files changed

+548446
-301263
lines changed

Some content is hidden

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

525 files changed

+548446
-301263
lines changed

CHANGELOG.rst

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,47 @@ Changelog
33

44

55

6+
v0.9.7
7+
-------
8+
9+
This is a major feature update release with these updates and API breaking changes:
10+
11+
* Use the full tree of nuget.config files that exist, including any package
12+
mappings. See details on how to create nuget config files:
13+
14+
* https://learn.microsoft.com/en-us/nuget/reference/nuget-config-file
15+
* https://learn.microsoft.com/en-us/nuget/consume-packages/configuring-nuget-behavior
16+
17+
* Report and fail on errors. We now collect errors and warnings in the JSON
18+
output at the top level or at the dependency level and fail the execution if
19+
there is a problem reported.
20+
21+
* Add new dependency resolver that works best for modern PackageReference-based
22+
projects.
23+
24+
* Remove the "--nuget-url" command line option to configure an alternative
25+
NuGet API URL. A nuget.config should be used instead, either the standard one,
26+
or a provided one with the proper NuGet API repository sources
27+
28+
* Add new "--with-details" command line option to optionally include package
29+
metadata details (such as checksum and size) when available.
30+
The SHA512 and size are no longer automatically provided. These are
31+
expensive API calls that are not used by NuGet as explained in this issue
32+
https://github.com/NuGet/NuGetGallery/issues/9433
33+
34+
* Add new "--with-fallback" command line option to optionally use a plain XML
35+
project file parser as fallback from failures." when parsing a project file
36+
using the NuGet and MSBuild APIs and this parsing fails. As a result the
37+
processing of some project file will fail without this option.
38+
39+
* Improve caching of NuGet API calls.
40+
41+
* Drop one-at-a-time dependency resolution which is mostly useless in practice.
42+
43+
* Use a cleaner build that does not include path to the original build machine
44+
in the binaries: we strip paths from the build now.
45+
46+
647
v0.9.6
748
-------
849

README.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ Portions Copyright (c) 2018 Black Duck Software, Inc.
6262

6363
Portions Copyright (c) Mario Rivis https://github.com/dxworks
6464

65+
Portions Copyright (c) 2016 Andrei Marukovich https://github.com/Dropcraft/Dropcraft
66+
6567
SPDX-License-Identifier: Apache-2.0 AND MIT
6668

6769

@@ -113,6 +115,8 @@ Here are credits for some of these key projects without which it would not exist
113115
https://github.com/veracode/verademo-dotnet
114116
https://github.com/veracode/verademo-dotnetcore
115117

118+
- ``dropcraft`` from Andrei Marukovich
119+
https://github.com/Dropcraft/Dropcraft
116120

117121
These projects are used either in the built executables, at build time or for
118122
testing. The built executables are designed to be self-contained exes that do

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.6 \
20+
-p:Version=0.9.7 \
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.6
19+
VERSION=0.9.7
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.6
4+
current_version = 0.9.7
55
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+))?
66
serialize =
77
{major}.{minor}.{patch}-{release}

src/Directory.Build.props

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<Project>
2+
<PropertyGroup>
3+
<Deterministic>true</Deterministic>
4+
<DeterministicSourcePaths>true</DeterministicSourcePaths>
5+
<PathMap>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)'))=./</PathMap>
6+
</PropertyGroup>
7+
</Project>

src/nuget-inspector/Config.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ namespace NugetInspector;
22

33
public static class Config
44
{
5+
#pragma warning disable CA2211
56
public static bool TRACE = false;
7+
public static bool TRACE_ARGS = false;
68
public static bool TRACE_NET = false;
79
public static bool TRACE_DEEP = false;
810
public static bool TRACE_META = false;
9-
public static string NUGET_INSPECTOR_VERSION = "0.9.6";
11+
public const string NUGET_INSPECTOR_VERSION = "0.9.7";
12+
#pragma warning restore CA2211
1013
}

src/nuget-inspector/DependencyResolution.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,22 @@
33
internal interface IDependencyProcessor
44
{
55
/// <summary>
6-
/// RProcess and resolve dependencies and return a DependencyResolution
6+
/// Process and resolve dependencies and return a DependencyResolution
77
/// </summary>
88
/// <returns>DependencyResolution</returns>
99
DependencyResolution Resolve();
1010
}
1111

1212
public class DependencyResolution
1313
{
14+
public bool Success { get; set; } = true;
15+
public List<BasePackage> Dependencies { get; set; } = new();
16+
1417
public DependencyResolution() {}
1518

16-
public DependencyResolution(bool Success)
19+
public DependencyResolution(bool success)
1720
{
18-
this.Success = Success;
21+
Success = success;
1922
}
2023

21-
public bool Success { get; set; } = true;
22-
public string? ProjectVersion { get; set; }
23-
public string? ErrorMessage { get; set; } = "";
24-
public List<BasePackage> Dependencies { get; set; } = new();
2524
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
using System.Xml;
2+
using NuGet.Frameworks;
3+
4+
namespace NugetInspector;
5+
6+
/// <summary>
7+
/// Helper module to fidn the proper project frameworj
8+
/// </summary>
9+
public static class FrameworkFinder
10+
{
11+
/// <summary>
12+
/// Return a tuple of (warning message or null, NuGetFramework) using either
13+
/// the requested framework or a found framework or a fallback to "any".
14+
/// </summary>
15+
public static (string?, NuGetFramework) GetFramework(string? RequestedFramework, string ProjectFilePath)
16+
{
17+
string? framework_warning = null;
18+
NuGetFramework project_framework;
19+
// Force using the provided framework if present
20+
if (!string.IsNullOrWhiteSpace(RequestedFramework))
21+
{
22+
project_framework = NuGetFramework.ParseFolder(folderName: RequestedFramework.ToLower());
23+
if (project_framework == NuGetFramework.UnsupportedFramework)
24+
{
25+
framework_warning = $"Unsupported framework requested: {RequestedFramework}, falling back to 'any' framework.";
26+
project_framework = NuGetFramework.AnyFramework;
27+
}
28+
}
29+
else
30+
{
31+
// TODO: Use the project model instead to obtain the framework
32+
// Or use the first framework found in the project
33+
string framework_moniker;
34+
(framework_moniker, project_framework) = FindProjectTargetFramework(ProjectFilePath);
35+
if (project_framework == NuGetFramework.UnsupportedFramework)
36+
{
37+
project_framework = NuGetFramework.AnyFramework;
38+
framework_warning =
39+
$"Unsupported framework found: {framework_moniker} in {ProjectFilePath}, " +
40+
$"falling back to '{project_framework.GetShortFolderName()}' framework.";
41+
}
42+
}
43+
44+
if (Config.TRACE)
45+
Console.WriteLine($"Effective project framework: {project_framework.GetShortFolderName()} {framework_warning}");
46+
47+
return (framework_warning, project_framework);
48+
}
49+
50+
/// <summary>
51+
/// Return the first NuGetFramework found in the *.*proj XML file or Any.
52+
/// Handles new and legacy style target framework references.
53+
/// </summary>
54+
/// <param name="project_file_path"></param>
55+
/// <returns></returns>
56+
public static (string, NuGetFramework) FindProjectTargetFramework(string project_file_path)
57+
{
58+
var doc = new XmlDocument();
59+
doc.Load(filename: project_file_path);
60+
61+
var target_framework = doc.GetElementsByTagName(name: "TargetFramework");
62+
foreach (XmlNode tf in target_framework)
63+
{
64+
var framework_moniker = tf.InnerText.Trim();
65+
if (!string.IsNullOrWhiteSpace(framework_moniker))
66+
{
67+
return (framework_moniker, NuGetFramework.ParseFolder(framework_moniker));
68+
}
69+
}
70+
71+
var target_framework_version = doc.GetElementsByTagName(name: "TargetFrameworkVersion");
72+
foreach (XmlNode tfv in target_framework_version)
73+
{
74+
var framework_version = tfv.InnerText.Trim();
75+
if (!string.IsNullOrWhiteSpace(framework_version))
76+
{
77+
var version = Version.Parse(framework_version.Trim('v', 'V'));
78+
return (framework_version, new NuGetFramework(FrameworkConstants.FrameworkIdentifiers.Net, version));
79+
}
80+
}
81+
82+
var target_frameworks = doc.GetElementsByTagName(name: "TargetFrameworks");
83+
foreach (XmlNode tf in target_frameworks)
84+
{
85+
var framework_monikers = tf.InnerText.Trim();
86+
if (!string.IsNullOrWhiteSpace(framework_monikers))
87+
{
88+
var monikers = framework_monikers.Split(";", StringSplitOptions.RemoveEmptyEntries);
89+
foreach (var moniker in monikers)
90+
{
91+
if (!string.IsNullOrWhiteSpace(moniker))
92+
return (moniker, NuGetFramework.ParseFolder(moniker.Trim()));
93+
}
94+
}
95+
}
96+
// fallback to any if none are specified
97+
return ("any", NuGetFramework.AnyFramework);
98+
}
99+
}

0 commit comments

Comments
 (0)