Skip to content

Commit

Permalink
Merge pull request #744 from pivotal/nuget-version-support
Browse files Browse the repository at this point in the history
[ADDED] Support legacy nuget projects [#172950097]
  • Loading branch information
pivotal-pmital authored Jun 1, 2020
2 parents f0bd72f + 0cccbcf commit 9012f2c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E03280
echo "deb https://download.mono-project.com/repo/ubuntu stable-xenial main" | sudo tee /etc/apt/sources.list.d/mono-official-stable.list &&\
apt-get update &&\
apt-get install -y mono-complete &&\
curl -o /usr/local/bin/nuget.exe https://dist.nuget.org/win-x86-commandline/latest/nuget.exe &&\
echo "alias nuget=\"mono /usr/local/bin/nuget.exe\"" >> ~/.bash_aliases
curl -o "/usr/local/bin/nuget.exe" "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" &&\
curl -o "/usr/local/bin/nugetv3.5.0.exe" "https://dist.nuget.org/win-x86-commandline/v3.5.0/nuget.exe"

# install dotnet core
WORKDIR /tmp
Expand Down
14 changes: 12 additions & 2 deletions lib/license_finder/package_managers/nuget.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,20 @@ def dependencies
assemblies.flat_map(&:dependencies)
end

def nuget_binary
legacy_vcproj = Dir['**/*.vcproj'].any?

if legacy_vcproj
'/usr/local/bin/nugetv3.5.0.exe'
else
'/usr/local/bin/nuget.exe'
end
end

def package_management_command
return 'nuget' if LicenseFinder::Platform.windows?

'mono /usr/local/bin/nuget.exe'
"mono #{nuget_binary}"
end

def prepare_command
Expand All @@ -96,7 +106,7 @@ def installed?(logger = Core.default_logger)
def nuget_check
return 'where nuget' if LicenseFinder::Platform.windows?

'which mono && ls /usr/local/bin/nuget.exe'
"which mono && ls #{nuget_binary}"
end

def self.nuspec_license_urls(specfile_content)
Expand Down
21 changes: 18 additions & 3 deletions spec/lib/license_finder/package_managers/nuget_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,22 @@ module LicenseFinder
end

describe '.package_management_command' do
it 'returns the correct package management command' do
nuget = Nuget.new project_path: Pathname.new('app')
expect(nuget.package_management_command).to eq(nuget_cmd)
context 'no .vcproj file found' do
it 'returns the correct package management command' do
nuget = Nuget.new project_path: Pathname.new('app')
expect(nuget.package_management_command).to eq(nuget_cmd)
end
end

context '.vcproj file found' do
include FakeFS::SpecHelpers

it 'returns the correct package management command' do
FileUtils.mkdir_p 'app'
FileUtils.touch 'app/legacy-project.vcproj'
nuget = Nuget.new project_path: Pathname.new('app')
expect(nuget.package_management_command).to eq(nuget_legacy_cmd)
end
end
end

Expand Down Expand Up @@ -267,6 +280,7 @@ module LicenseFinder
end

let(:nuget_cmd) { 'mono /usr/local/bin/nuget.exe' }
let(:nuget_legacy_cmd) { 'mono /usr/local/bin/nugetv3.5.0.exe' }
let(:nuget_check) { 'which mono && ls /usr/local/bin/nuget.exe' }
let(:nuget_location) { "/usr/local/mono\n/usr/local/bin/nuget.exe" }

Expand All @@ -279,6 +293,7 @@ module LicenseFinder
end

let(:nuget_cmd) { 'nuget' }
let(:nuget_legacy_cmd) { 'nuget' }
let(:nuget_check) { 'where nuget' }
let(:nuget_location) { 'C:\\ProgramData\\chocolatey\\bin\\NuGet.exe' }

Expand Down

0 comments on commit 9012f2c

Please sign in to comment.