Skip to content

Commit

Permalink
Merge pull request #567 from pivotal-legacy/restore-vendor-bundler-re…
Browse files Browse the repository at this point in the history
…vert

Revert "Revert "Fixes bundler env configuration for vendored gems""
  • Loading branch information
osis committed May 6, 2019
2 parents 721f75c + cd0f063 commit 014efa7
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ci/scripts/run-tests.sh
Expand Up @@ -19,6 +19,6 @@ pushd "$PROJECT_ROOT"

bundle exec rake install
bundle exec rake spec
bundle exec rake features

bundle exec rake features
popd
6 changes: 6 additions & 0 deletions features/features/configure/set_project_path_spec.rb
Expand Up @@ -16,4 +16,10 @@
developer.execute_command_outside_project("license_finder --quiet --project_path #{project.project_dir}")
expect(developer).to be_seeing 'mitlicensed_dep, 1.2.3, MIT'
end

specify 'works with vendored bundle and a project_path' do
project = LicenseFinder::TestingDSL::VendorBundlerProject.create
developer.execute_command_outside_project("license_finder --quiet --project_path #{project.project_dir}")
expect(developer).to be_seeing_line 'rake, 12.3.0, MIT'
end
end
22 changes: 22 additions & 0 deletions features/features/package_managers/bundler_spec.rb
@@ -0,0 +1,22 @@
# frozen_string_literal: true

require_relative '../../support/feature_helper'
require_relative '../../../lib/license_finder/version'

describe 'Bundler Dependencies' do
let(:bundler_developer) { LicenseFinder::TestingDSL::User.new }

specify 'are shown in reports' do
LicenseFinder::TestingDSL::BundlerProject.create
puts 'bundler project created'
bundler_developer.run_license_finder
expect(bundler_developer).to be_seeing_something_like /bundler.*MIT/
end

specify 'works with vendored bundle' do
LicenseFinder::TestingDSL::VendorBundlerProject.create
puts 'bundler project created'
bundler_developer.run_license_finder
expect(bundler_developer).to be_seeing_something_like /rake.*MIT/
end
end
37 changes: 33 additions & 4 deletions features/support/testing_dsl.rb
Expand Up @@ -35,7 +35,7 @@ def execute_command(command)
end

def execute_command_outside_project(command)
execute_command_in_path(command, Paths.root)
execute_command_in_path(command, Paths.tmpdir)
end

def seeing?(content)
Expand Down Expand Up @@ -427,11 +427,13 @@ def add_dep
class BundlerProject < Project
def add_dep
add_to_gemfile("source 'https://rubygems.org'")
add_gem_to_gemfile('license_finder', path: Paths.root.to_s)
add_to_gemfile("gem 'license_finder'")
end

def install
shell_out('bundle install')
::Bundler.with_original_env do
shell_out('bundle install')
end
end

def depend_on(gem, bundler_options = {})
Expand All @@ -450,6 +452,29 @@ def add_to_gemfile(content)
end
end

class VendorBundlerProject < Project
def add_dep
add_to_gemfile("source 'https://rubygems.org'")
add_gem_to_gemfile('rake', '12.3.0')
end

def install
::Bundler.with_original_env do
shell_out('bundle install --path="vendor/bundle"')
end
end

private

def add_gem_to_gemfile(gem_name, options)
add_to_gemfile("gem #{gem_name.inspect}, #{options.inspect}")
end

def add_to_gemfile(content)
add_to_file('Gemfile', content)
end
end

# lives adjacent to a BundlerProject, so has a different lifecycle from other Projects and doesn't inherit
class GemProject
def self.create(name, options)
Expand Down Expand Up @@ -581,8 +606,12 @@ def fixtures
root.join('features', 'fixtures')
end

def tmpdir
ProjectDir.new(Pathname.new(Dir.tmpdir))
end

def projects
ProjectDir.new(Pathname.new(Dir.tmpdir)).join('projects')
tmpdir.join('projects')
end

def project(name = 'my_app')
Expand Down
11 changes: 11 additions & 0 deletions lib/license_finder/package_managers/bundler.rb
Expand Up @@ -37,6 +37,9 @@ def possible_package_paths

def definition
# DI
ENV['BUNDLE_PATH'] = project_path.to_s
ENV['BUNDLE_GEMFILE'] = "#{project_path}/Gemfile"

@definition ||= ::Bundler::Definition.build(detected_package_path, lockfile_path, nil)
end

Expand All @@ -52,6 +55,10 @@ def gem_details

# clear gem paths before runninng specs_for
Gem.clear_paths
if File.exist?(bundler_config_path)
::Bundler.reset!
::Bundler.configure
end
@gem_details = definition.specs_for(included_groups)
end

Expand All @@ -67,6 +74,10 @@ def lockfile_path
project_path.join('Gemfile.lock')
end

def bundler_config_path
project_path.join('.bundle')
end

def log_package_dependencies(package)
dependencies = package.children
if dependencies.empty?
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/license_finder/package_managers/bundler_spec.rb
Expand Up @@ -34,7 +34,7 @@ def build_gemspec(name, version, dependency = nil)

describe '.current_packages' do
subject do
Bundler.new(ignored_groups: %w[dev test], definition: definition).current_packages
Bundler.new(ignored_groups: %w[dev test], project_path: Pathname.new('.'), definition: definition).current_packages
end

it 'should have 2 dependencies' do
Expand Down

0 comments on commit 014efa7

Please sign in to comment.