summaryrefslogtreecommitdiff
path: root/lib/license/finder/ext/dotnet.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/license/finder/ext/dotnet.rb')
-rw-r--r--lib/license/finder/ext/dotnet.rb57
1 files changed, 56 insertions, 1 deletions
diff --git a/lib/license/finder/ext/dotnet.rb b/lib/license/finder/ext/dotnet.rb
index 1b98881..c5ff485 100644
--- a/lib/license/finder/ext/dotnet.rb
+++ b/lib/license/finder/ext/dotnet.rb
@@ -2,10 +2,65 @@
module LicenseFinder
class Dotnet
+ def possible_package_paths
+ project_path.glob('*.sln') +
+ project_path.glob('*.csproj') +
+ project_path.glob('*.vbproj') +
+ project_path.glob('*.fsproj')
+ end
+
def prepare
shell.execute(['apt-get', :update, '-q'])
shell.execute(['apt-get', :install, '-y', '--no-install-recommends', 'dotnet-sdk-3.1'])
- shell.execute([:dotnet, :restore])
+ shell.execute([:mkdir, '-p', vendor_path.to_s]) unless vendor_path.exist?
+ shell.execute([
+ :dotnet,
+ :restore, detected_package_path.to_s,
+ '--no-cache',
+ '--packages', vendor_path.to_s,
+ '--locked-mode',
+ '--verbosity', :detailed
+ ])
+ end
+
+ def current_packages
+ asset_files.flat_map do |file|
+ json = JSON.parse(IO.read(file))
+ json.fetch('libraries', []).map do |slug, data|
+ name, version = slug.split('/')
+ map_from(name, version, data)
+ end
+ end
+ end
+
+ private
+
+ def vendor_path
+ @vendor_path ||= Pathname.pwd.join('.gitlab', 'cache', 'vendor')
+ end
+
+ def map_from(name, version, data)
+ Dependency.new(
+ 'NuGet',
+ name,
+ version,
+ spec_licenses: licenses_from(data['path'], data.fetch('files', [])),
+ detection_path: detected_package_path,
+ install_path: vendor_path.join(data['path'])
+ )
+ end
+
+ def nuspec_path_from(path, files)
+ install_path = vendor_path.join(path)
+ nuspec_filename = files.find { |x| x.end_with?('.nuspec') }
+ return install_path.join(nuspec_filename) if nuspec_filename
+ end
+
+ def licenses_from(path, files)
+ nuspec = nuspec_path_from(path, files)
+ return [] if nuspec.nil? || !nuspec.exist?
+
+ ::License::Management::Nuspec.new(nuspec.read).licenses
end
end
end