Skip to content

Commit

Permalink
Only choose latest of version line if no requested exists
Browse files Browse the repository at this point in the history
[#150757043]

Signed-off-by: Victoria Henry <[email protected]>
  • Loading branch information
dgodd authored and TisVictress committed Sep 5, 2017
1 parent 1c35ed3 commit ffaf29c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
14 changes: 14 additions & 0 deletions cf_spec/unit/buildpack/compile/dotnet_framework_version_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,20 @@
end
end

context 'dotnet restore detected frameworks that do and do not exist in available' do
before do
FileUtils.mkdir_p(File.join(nuget_cache_dir, 'packages', 'Microsoft.NETCore.App', '1.0.3'))
FileUtils.mkdir_p(File.join(nuget_cache_dir, 'packages', 'Microsoft.NETCore.App', '1.0.4'))
end

it 'returns the latest patch version for each restored major/minor line' do
allow_any_instance_of(AspNetCoreBuildpack::DotnetFrameworkVersion).to receive(:available_versions).and_return(%w[1.0.4 1.0.5])
expect_any_instance_of(AspNetCoreBuildpack::Out).to receive(:print).with(
"Detected .NET Core runtime version(s) 1.0.4 required according to 'dotnet restore'")
expect(subject.versions).to eq( ['1.0.4'] )
end
end

context 'dotnet restore detected no framework versions' do
it 'throws an exception with a helpful message' do
expect { subject.versions }.to raise_error(RuntimeError, "Unable to determine .NET Core runtime version(s) to install")
Expand Down
4 changes: 2 additions & 2 deletions lib/buildpack/compile/dotnet_cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ def node_modules_paths(dir = @build_dir)
end
end

project_dirs.map do |dir|
File.join(dir, 'node_modules', '.bin')
project_dirs.map do |project_dir|
File.join(project_dir, 'node_modules', '.bin')
end.compact.join(':')
end

Expand Down
15 changes: 8 additions & 7 deletions lib/buildpack/compile/dotnet_framework_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,16 @@ def needed_framework_versions
major, minor, = ver.split('.')
version_line = "#{major}.#{minor}"

if version_hash[version_line].nil?
version_hash[version_line] = available_versions.include?(ver) ? [ver] : [get_version_from_version_line(version_line)]
else
version_hash[version_line].push available_versions.include?(ver) ? ver : get_version_from_version_line(version_line)
end
version_hash[version_line] ||= []
version_hash[version_line].push ver if available_versions.include?(ver)
end

required_versions = version_hash.values.map do |v|
v.sort_by { |a| gem_version_parse(a) }.last
required_versions = version_hash.map do |version_line, versions|
if !versions.empty?
versions.sort_by { |a| gem_version_parse(a) }.last
else
get_version_from_version_line(version_line)
end
end

required_versions += runtime_framework_versions if msbuild?
Expand Down

0 comments on commit ffaf29c

Please sign in to comment.