Skip to content

Commit

Permalink
Merge pull request #495 from pivotal-legacy/project_paths
Browse files Browse the repository at this point in the history
[ADDED] Add project roots command to list paths to scan
  • Loading branch information
xtreme-shane-lattanzio authored Jun 5, 2018
2 parents 9822f79 + 60da2d2 commit b7a22ea
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 5 deletions.
26 changes: 26 additions & 0 deletions features/features/cli/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,30 @@
expect(developer).to_not be_seeing('MIT')
end
end

describe 'running project_roots' do
before do
@project = LicenseFinder::TestingDSL::CompositeProject.create
end

context 'with --recursive flag' do
let(:license_finder_command) { 'license_finder project_roots --recursive' }

specify 'returns all project paths' do
developer.execute_command(license_finder_command)

expect(developer).to be_seeing_something_like %r{\"#{Regexp.escape(@project.project_dir.to_s)}/multi-module-gradle\"}
expect(developer).to be_seeing_something_like %r{\"#{Regexp.escape(@project.project_dir.to_s)}/single-module-gradle\"}
end
end

context 'without flags' do
let(:license_finder_command) { 'license_finder project_roots' }

specify 'returns current path' do
developer.execute_command(license_finder_command)
expect(developer).to be_seeing_something_like /^#{Regexp.escape(@project.project_dir.to_s)}$/
end
end
end
end
10 changes: 9 additions & 1 deletion lib/license_finder/cli/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ def self.shared_options
type: :array
end

desc 'project_roots', 'List project directories to be scanned'
shared_options
def project_roots
config.strict_matching = true
aggregate_paths
end

desc 'action_items', 'List unapproved dependencies (the default action for `license_finder`)'
shared_options
format_option
Expand Down Expand Up @@ -162,7 +169,8 @@ def aggregate_paths
check_valid_project_path
aggregate_paths = config.aggregate_paths
project_path = config.project_path || Pathname.pwd
aggregate_paths = ProjectFinder.new(project_path).find_projects if config.recursive
aggregate_paths = ProjectFinder.new(project_path, config.strict_matching).find_projects if config.recursive
say(aggregate_paths || project_path) if config.strict_matching
return aggregate_paths unless aggregate_paths.nil? || aggregate_paths.empty?
[config.project_path] unless config.project_path.nil?
end
Expand Down
4 changes: 4 additions & 0 deletions lib/license_finder/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ def sbt_include_groups
get(:sbt_include_groups)
end

attr_writer :strict_matching

attr_reader :strict_matching

protected

attr_accessor :primary_config
Expand Down
3 changes: 2 additions & 1 deletion lib/license_finder/package_managers/go_workspace.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'json'

module LicenseFinder
class GoWorkspace < PackageManager
Submodule = Struct.new :install_path, :revision
Expand All @@ -8,6 +7,7 @@ class GoWorkspace < PackageManager
def initialize(options = {})
super
@full_version = options[:go_full_version]
@strict_matching = options[:strict_matching]
end

def self.package_management_command
Expand Down Expand Up @@ -38,6 +38,7 @@ def possible_package_paths
end

def active?
return false if @strict_matching
godep = LicenseFinder::GoDep.new(project_path: Pathname(project_path))
# go workspace is only active if GoDep wasn't. There are some projects
# that will use the .envrc and have a Godep folder as well.
Expand Down
5 changes: 3 additions & 2 deletions lib/license_finder/project_finder.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
module LicenseFinder
class ProjectFinder
def initialize(main_project_path)
def initialize(main_project_path, strict_matching = false)
@package_managers = LicenseFinder::Scanner::PACKAGE_MANAGERS
@strict_matching = strict_matching
@main_project_path = main_project_path
end

Expand Down Expand Up @@ -41,7 +42,7 @@ def project_root?(pathname)

def active_project?(project_path)
active_project = @package_managers.map do |pm|
pm.new(project_path: project_path).active?
pm.new(project_path: project_path, strict_matching: @strict_matching).active?
end
active_project.include?(true)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/license_finder/cli/main_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ module CLI

it 'passes the config options to the new LicenseFinder::LicenseAggregator instance' do
stubs = { valid_project_path?: true, project_path: Pathname('../other_project'),
decisions_file_path: Pathname('../other_project'), aggregate_paths: nil, recursive: false, format: nil, columns: nil }
decisions_file_path: Pathname('../other_project'), aggregate_paths: nil, recursive: false, format: nil, columns: nil, strict_matching: false }
configuration = double(:configuration, stubs)
allow(LicenseFinder::Configuration).to receive(:with_optional_saved_config).and_return(configuration)
expect(LicenseFinder::LicenseAggregator).to receive(:new).with(configuration, anything).and_return(license_finder_instance)
Expand Down

0 comments on commit b7a22ea

Please sign in to comment.