Class: Licensed::Sources::NuGet
- Defined in:
- lib/licensed/sources/nuget.rb
Overview
Only supports ProjectReference (project.assets.json) style restore used in .NET Core. Does not currently support packages.config style restore.
Defined Under Namespace
Classes: NuGetDependency
Instance Attribute Summary
Attributes inherited from Source
Class Method Summary collapse
Instance Method Summary collapse
- #enabled? ⇒ Boolean
-
#enumerate_dependencies ⇒ Object
Inspect project.assets.json files for package references.
- #project_assets_file ⇒ Object
- #project_assets_file_path ⇒ Object
Methods inherited from Source
#dependencies, #ignored?, inherited, #initialize
Constructor Details
This class inherits a constructor from Licensed::Sources::Source
Class Method Details
.type ⇒ Object
10 11 12 |
# File 'lib/licensed/sources/nuget.rb', line 10 def self.type "nuget" end |
Instance Method Details
#enabled? ⇒ Boolean
175 176 177 |
# File 'lib/licensed/sources/nuget.rb', line 175 def enabled? File.exist?(project_assets_file_path) end |
#enumerate_dependencies ⇒ Object
Inspect project.assets.json files for package references. Ideally we’d use ‘dotnet list package` instead, but its output isn’t easily machine readable and doesn’t contain everything we need.
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/licensed/sources/nuget.rb', line 182 def enumerate_dependencies json = JSON.parse(project_assets_file) nuget_packages_dir = json["project"]["restore"]["packagesPath"] json["targets"].each_with_object({}) do |(_, target), dependencies| target.each do |reference_key, reference| # Ignore project references next unless reference["type"] == "package" package_id_parts = reference_key.partition("/") name = package_id_parts[0] version = package_id_parts[-1] id = "#{name}-#{version}" # Already know this package from another target next if dependencies.key?(id) path = File.join(nuget_packages_dir, json["libraries"][reference_key]["path"]) dependencies[id] = NuGetDependency.new( name: id, version: version, path: path, metadata: { "type" => NuGet.type, "name" => name } ) end end.values end |
#project_assets_file ⇒ Object
170 171 172 173 |
# File 'lib/licensed/sources/nuget.rb', line 170 def project_assets_file return @project_assets_file if defined?(@project_assets_file) @project_assets_file = File.read(project_assets_file_path) end |
#project_assets_file_path ⇒ Object
166 167 168 |
# File 'lib/licensed/sources/nuget.rb', line 166 def project_assets_file_path File.join(config.pwd, "project.assets.json") end |