Skip to content

Commit

Permalink
[Added] install path for nuget dependencies [#172251374]
Browse files Browse the repository at this point in the history
Signed-off-by: Vikram Yadav <vyadav@pivotal.io>
  • Loading branch information
Pivotal-Jeff-Jun committed May 13, 2020
1 parent c4cc6b8 commit ad73c94
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/license_finder/package_managers/nuget.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ def assemblies
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)
path = Dir.glob("#{Dir.home}/.nuget/packages/#{dep.name.downcase}/#{dep.version}").first

memo[dep.name] ||= NugetPackage.new(dep.name, dep.version, spec_licenses: licenses, install_path: path)
memo[dep.name].groups << dep.assembly unless memo[dep.name].groups.include? dep.assembly
end.values
end
Expand Down
14 changes: 13 additions & 1 deletion spec/lib/license_finder/package_managers/nuget_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ module LicenseFinder
FileUtils.mkdir_p 'app/Assembly1/'
FileUtils.mkdir_p 'app/Assembly1.Tests/'
FileUtils.mkdir_p 'app/Assembly2/'
FileUtils.mkdir_p '.nuget/packages/gotodependency/4.84.4790.14417'
FileUtils.mkdir_p '.nuget/packages/obscuredependency/1.3.15'

FileUtils.touch 'app/Assembly1/packages.config'
FileUtils.touch 'app/Assembly1.Tests/packages.config'
FileUtils.touch 'app/Assembly2/packages.config'
Expand Down Expand Up @@ -139,16 +142,25 @@ module LicenseFinder
File.write('app/Assembly1/packages.config', assembly_1_packages)
File.write('app/Assembly1.Tests/packages.config', assembly_1_tests_packages)
File.write('app/Assembly2/packages.config', assembly_2_packages)

allow(Dir).to receive(:home).and_return('.')
end

it 'lists all the packages used in an assembly' do
it 'lists all the packages used in an assembly with install paths' do
nuget = Nuget.new project_path: Pathname.new('app')
deps = %w[GoToDependency
ObscureDependency
OtherObscureDependency
TestFramework
CoolNewDependency]
install_paths = [
'/.nuget/packages/gotodependency/4.84.4790.14417',
'/.nuget/packages/obscuredependency/1.3.15',
nil
]

expect(nuget.current_packages.map(&:name).uniq).to match_array(deps)
expect(nuget.current_packages.map(&:install_path).uniq).to match_array(install_paths)
end

# cannot run on JRuby due to https://github.com/fakefs/fakefs/issues/303
Expand Down

0 comments on commit ad73c94

Please sign in to comment.