From ffaf29cab3eec570c8a65070cc2c05df150d58ec Mon Sep 17 00:00:00 2001 From: Dave Goddard Date: Tue, 5 Sep 2017 08:00:24 -0400 Subject: [PATCH] Only choose latest of version line if no requested exists [#150757043] Signed-off-by: Victoria Henry --- .../compile/dotnet_framework_version_spec.rb | 14 ++++++++++++++ lib/buildpack/compile/dotnet_cli.rb | 4 ++-- lib/buildpack/compile/dotnet_framework_version.rb | 15 ++++++++------- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/cf_spec/unit/buildpack/compile/dotnet_framework_version_spec.rb b/cf_spec/unit/buildpack/compile/dotnet_framework_version_spec.rb index 00336c297..79f6c7be0 100644 --- a/cf_spec/unit/buildpack/compile/dotnet_framework_version_spec.rb +++ b/cf_spec/unit/buildpack/compile/dotnet_framework_version_spec.rb @@ -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") diff --git a/lib/buildpack/compile/dotnet_cli.rb b/lib/buildpack/compile/dotnet_cli.rb index 43166b77f..bc473d584 100644 --- a/lib/buildpack/compile/dotnet_cli.rb +++ b/lib/buildpack/compile/dotnet_cli.rb @@ -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 diff --git a/lib/buildpack/compile/dotnet_framework_version.rb b/lib/buildpack/compile/dotnet_framework_version.rb index 7e4091abb..3f73f7309 100644 --- a/lib/buildpack/compile/dotnet_framework_version.rb +++ b/lib/buildpack/compile/dotnet_framework_version.rb @@ -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?