Class: LicenseFinder::Nuget
Defined Under Namespace
Classes: Assembly, Dependency
Class Method Summary
collapse
Instance Method Summary
collapse
#active?, command_exists?, #current_packages_with_relations, #detected_package_path, #initialize, #prepare, takes_priority_over
Class Method Details
.installed?(logger = Core.default_logger) ⇒ Boolean
81
82
83
84
85
86
87
88
89
|
# File 'lib/license_finder/package_managers/nuget.rb', line 81
def self.installed?(logger = Core.default_logger)
_stdout, _stderr, status = Cmd.run(nuget_check)
if status.success?
logger.debug self, 'is installed', color: :green
else
logger.info self, 'is not installed', color: :red
end
status.success?
end
|
.nuget_check ⇒ Object
91
92
93
94
|
# File 'lib/license_finder/package_managers/nuget.rb', line 91
def self.nuget_check
return 'where nuget' if LicenseFinder::Platform.windows?
'which mono && ls /usr/local/bin/nuget.exe'
end
|
.package_management_command ⇒ Object
72
73
74
75
|
# File 'lib/license_finder/package_managers/nuget.rb', line 72
def self.package_management_command
return 'nuget' if LicenseFinder::Platform.windows?
'mono /usr/local/bin/nuget.exe'
end
|
.prepare_command ⇒ Object
77
78
79
|
# File 'lib/license_finder/package_managers/nuget.rb', line 77
def self.prepare_command
"#{package_management_command} restore"
end
|
Instance Method Details
#assemblies ⇒ Object
41
42
43
44
45
46
47
|
# File 'lib/license_finder/package_managers/nuget.rb', line 41
def assemblies
Dir.glob(project_path.join('**', 'packages.config'), File::FNM_DOTMATCH).map do |d|
path = Pathname.new(d).dirname
name = path.basename.to_s
Assembly.new path, name
end
end
|
#current_packages ⇒ Object
49
50
51
52
53
54
55
|
# File 'lib/license_finder/package_managers/nuget.rb', line 49
def current_packages
dependencies.each_with_object({}) do |dep, memo|
licenses = license_urls(dep)
memo[dep.name] ||= NugetPackage.new(dep.name, dep.version, spec_licenses: licenses)
memo[dep.name].groups << dep.assembly unless memo[dep.name].groups.include? dep.assembly
end.values
end
|
#dependencies ⇒ Object
68
69
70
|
# File 'lib/license_finder/package_managers/nuget.rb', line 68
def dependencies
assemblies.flat_map(&:dependencies)
end
|
#license_urls(dep) ⇒ Object
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/license_finder/package_managers/nuget.rb', line 57
def license_urls(dep)
files = Dir["**/#{dep.name}.#{dep.version}.nupkg"]
return nil if files.empty?
file = files.first
Zip::File.open file do |zipfile|
content = zipfile.read(dep.name + '.nuspec')
xml = REXML::Document.new(content)
REXML::XPath.match(xml, '//metadata//licenseUrl').map(&:get_text).map(&:to_s)
end
end
|
#possible_package_paths ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/license_finder/package_managers/nuget.rb', line 26
def possible_package_paths
path = project_path.join('vendor/*.nupkg')
nuget_dir = Dir[path].map { |pkg| File.dirname(pkg) }.uniq
path = project_path.join('*.sln')
solution_file = Dir[path].first
possible_paths = [project_path.join('packages.config'), project_path.join('.nuget')]
possible_paths.unshift(Pathname(solution_file)) unless solution_file.nil?
possible_paths.unshift(Pathname(nuget_dir.first)) unless nuget_dir.empty?
possible_paths
end
|