license_finder 1.0.0.0-java → 1.1.1-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. data/.force-build +0 -0
  3. data/.travis.yml +8 -7
  4. data/CHANGELOG.rdoc +29 -1
  5. data/Rakefile +2 -2
  6. data/db/migrate/201311192003_reassociate_manual_approval.rb +2 -3
  7. data/db/migrate/201403181732_rename_manual_fields.rb +10 -0
  8. data/db/migrate/201403190028_add_manual_approvals.rb +22 -0
  9. data/db/migrate/201403191419_add_timestamps_to_manual_approvals.rb +15 -0
  10. data/db/migrate/201403191645_remove_license_aliases.rb +23 -0
  11. data/features/cli.feature +21 -20
  12. data/features/cocoapods_dependencies.feature +10 -0
  13. data/features/configure_bundler_groups.feature +23 -0
  14. data/features/configure_ignore_dependencies.feature +16 -0
  15. data/features/{project_name.feature → configure_project_name.feature} +1 -1
  16. data/features/{whitelist.feature → configure_whitelist.feature} +6 -6
  17. data/features/manually_added.feature +19 -0
  18. data/features/{approve_dependencies.feature → manually_approved.feature} +2 -2
  19. data/features/manually_assigned_license.feature +16 -0
  20. data/features/{text_report.feature → report_csv.feature} +2 -2
  21. data/features/{html_report.feature → report_html.feature} +2 -2
  22. data/features/step_definitions/cli_steps.rb +22 -32
  23. data/features/step_definitions/cocoapod_steps.rb +8 -0
  24. data/features/step_definitions/configure_bundler_groups_steps.rb +30 -0
  25. data/features/step_definitions/configure_ignore_dependencies.rb +35 -0
  26. data/features/step_definitions/{project_name_steps.rb → configure_project_name_steps.rb} +0 -0
  27. data/features/step_definitions/configure_whitelist_steps.rb +45 -0
  28. data/features/step_definitions/gradle_steps.rb +2 -2
  29. data/features/step_definitions/manually_added_steps.rb +28 -0
  30. data/features/step_definitions/manually_approved_steps.rb +24 -0
  31. data/features/step_definitions/manually_assigned_license_steps.rb +34 -0
  32. data/features/step_definitions/maven_steps.rb +2 -2
  33. data/features/step_definitions/node_steps.rb +2 -2
  34. data/features/step_definitions/python_steps.rb +1 -1
  35. data/features/step_definitions/report_csv_steps.rb +20 -0
  36. data/features/step_definitions/report_html_steps.rb +60 -0
  37. data/features/step_definitions/shared_steps.rb +125 -104
  38. data/{files/license_finder.yml → lib/data/license_finder.example.yml} +3 -0
  39. data/lib/license_finder.rb +3 -2
  40. data/lib/license_finder/cli.rb +94 -49
  41. data/lib/license_finder/configuration.rb +21 -14
  42. data/lib/license_finder/dependency_manager.rb +27 -19
  43. data/lib/license_finder/license.rb +33 -19
  44. data/lib/license_finder/license/definitions.rb +153 -104
  45. data/lib/license_finder/license/matcher.rb +6 -1
  46. data/lib/license_finder/license/none_matcher.rb +9 -0
  47. data/lib/license_finder/license/text.rb +1 -0
  48. data/lib/license_finder/package.rb +30 -6
  49. data/lib/license_finder/package_managers/bower.rb +2 -2
  50. data/lib/license_finder/package_managers/bower_package.rb +2 -2
  51. data/lib/license_finder/package_managers/bundler.rb +9 -17
  52. data/lib/license_finder/package_managers/bundler_package.rb +1 -1
  53. data/lib/license_finder/package_managers/cocoa_pods.rb +35 -0
  54. data/lib/license_finder/package_managers/cocoa_pods_package.rb +19 -0
  55. data/lib/license_finder/package_managers/gradle.rb +9 -5
  56. data/lib/license_finder/package_managers/gradle_package.rb +4 -4
  57. data/lib/license_finder/package_managers/maven.rb +7 -3
  58. data/lib/license_finder/package_managers/maven_package.rb +5 -5
  59. data/lib/license_finder/package_managers/npm.rb +2 -2
  60. data/lib/license_finder/package_managers/npm_package.rb +2 -2
  61. data/lib/license_finder/package_managers/pip.rb +2 -2
  62. data/lib/license_finder/package_managers/pip_package.rb +7 -11
  63. data/lib/license_finder/package_saver.rb +12 -10
  64. data/lib/license_finder/possible_license_file.rb +1 -1
  65. data/lib/license_finder/possible_license_files.rb +11 -15
  66. data/lib/license_finder/reports/formatted_report.rb +25 -6
  67. data/lib/license_finder/reports/html_report.rb +2 -1
  68. data/lib/license_finder/reports/reporter.rb +3 -3
  69. data/lib/license_finder/tables.rb +6 -4
  70. data/lib/license_finder/tables/dependency.rb +36 -16
  71. data/lib/license_finder/tables/manual_approval.rb +13 -0
  72. data/lib/license_finder/yml_to_sql.rb +12 -9
  73. data/lib/templates/html_report.erb +68 -74
  74. data/lib/templates/markdown_report.erb +20 -21
  75. data/license_finder.gemspec +7 -7
  76. data/readme.md +76 -79
  77. data/spec/fixtures/Podfile +3 -0
  78. data/spec/lib/license_finder/cli_spec.rb +71 -23
  79. data/spec/lib/license_finder/configuration_spec.rb +61 -21
  80. data/spec/lib/license_finder/dependency_manager_spec.rb +52 -33
  81. data/spec/lib/license_finder/license/definitions_spec.rb +30 -14
  82. data/spec/lib/license_finder/license_spec.rb +55 -12
  83. data/spec/lib/license_finder/package_managers/bower_package_spec.rb +38 -19
  84. data/spec/lib/license_finder/package_managers/bower_spec.rb +10 -16
  85. data/spec/lib/license_finder/package_managers/bundler_package_spec.rb +39 -15
  86. data/spec/lib/license_finder/package_managers/bundler_spec.rb +10 -22
  87. data/spec/lib/license_finder/package_managers/cocoa_pods_package_spec.rb +44 -0
  88. data/spec/lib/license_finder/package_managers/cocoa_pods_spec.rb +79 -0
  89. data/spec/lib/license_finder/package_managers/gradle_package_spec.rb +4 -5
  90. data/spec/lib/license_finder/package_managers/gradle_spec.rb +26 -20
  91. data/spec/lib/license_finder/package_managers/maven_package_spec.rb +4 -5
  92. data/spec/lib/license_finder/package_managers/maven_spec.rb +16 -19
  93. data/spec/lib/license_finder/package_managers/npm_package_spec.rb +39 -19
  94. data/spec/lib/license_finder/package_managers/npm_spec.rb +10 -16
  95. data/spec/lib/license_finder/package_managers/pip_package_spec.rb +8 -8
  96. data/spec/lib/license_finder/package_managers/pip_spec.rb +10 -16
  97. data/spec/lib/license_finder/package_saver_spec.rb +27 -3
  98. data/spec/lib/license_finder/possible_license_file_spec.rb +25 -23
  99. data/spec/lib/license_finder/reports/detailed_text_report_spec.rb +6 -8
  100. data/spec/lib/license_finder/reports/html_report_spec.rb +45 -44
  101. data/spec/lib/license_finder/reports/markdown_report_spec.rb +8 -9
  102. data/spec/lib/license_finder/reports/reporter_spec.rb +1 -1
  103. data/spec/lib/license_finder/reports/text_report_spec.rb +6 -8
  104. data/spec/lib/license_finder/tables/dependency_spec.rb +57 -41
  105. data/spec/lib/license_finder/yml_to_sql_spec.rb +94 -92
  106. data/spec/spec_helper.rb +1 -0
  107. data/spec/support/stdout_helpers.rb +25 -0
  108. metadata +86 -69
  109. data/MIT.LICENSE +0 -20
  110. data/features/ignore_bundle_groups.feature +0 -23
  111. data/features/manually_managed_dependencies.feature +0 -19
  112. data/features/set_license.feature +0 -10
  113. data/features/step_definitions/approve_dependencies_steps.rb +0 -25
  114. data/features/step_definitions/html_report_steps.rb +0 -62
  115. data/features/step_definitions/ignore_bundle_groups_steps.rb +0 -29
  116. data/features/step_definitions/manually_managed_steps.rb +0 -33
  117. data/features/step_definitions/set_license_steps.rb +0 -20
  118. data/features/step_definitions/text_report_steps.rb +0 -19
  119. data/features/step_definitions/whitelist_steps.rb +0 -45
  120. data/files/dependency_breakdown.png +0 -0
  121. data/files/report_breakdown.png +0 -0
  122. data/lib/license_finder/license_url.rb +0 -9
  123. data/lib/license_finder/tables/license_alias.rb +0 -22
  124. data/spec/lib/license_finder/license_url_spec.rb +0 -16
  125. data/spec/lib/license_finder/tables/license_alias_spec.rb +0 -37
  126. data/spec/support/silence_stdout.rb +0 -13
@@ -0,0 +1,8 @@
1
+ Given(/^A Podfile with dependencies$/) do
2
+ @user = ::DSL::User.new
3
+ @user.create_cocoapods_app
4
+ end
5
+
6
+ Then(/^I should see a CocoaPods dependency with a license$/) do
7
+ @user.should be_seeing_line "ABTest, 0.0.5, MIT"
8
+ end
@@ -0,0 +1,30 @@
1
+ Given(/^I have an app that depends on a gem in the test bundler group$/) do
2
+ @user = ::DSL::User.new
3
+ @user.create_ruby_app
4
+ @user.create_gem 'gpl_gem', license: 'GPL'
5
+ @user.depend_on_local_gem 'gpl_gem', groups: ['test']
6
+ end
7
+
8
+ When(/^I ignore the test group$/) do
9
+ @user.execute_command('license_finder ignored_bundler_group add test')
10
+ end
11
+
12
+ When(/^I stop ignoring the test group$/) do
13
+ @user.execute_command('license_finder ignored_bundler_group remove test')
14
+ end
15
+
16
+ When(/^I get the ignored groups$/) do
17
+ @user.execute_command('license_finder ignored_bundler_group list')
18
+ end
19
+
20
+ Then(/^I should not see the test gem in the output$/) do
21
+ @user.should_not be_seeing 'gpl_gem'
22
+ end
23
+
24
+ Then(/^I should see the test group in the output$/) do
25
+ @user.should be_seeing 'test'
26
+ end
27
+
28
+ Then(/^I should not see the test group in the output$/) do
29
+ @user.should_not be_seeing 'test'
30
+ end
@@ -0,0 +1,35 @@
1
+ Given(/^I have an app that depends on bundler$/) do
2
+ @user = ::DSL::User.new
3
+ @user.create_ruby_app
4
+ @user.create_gem 'bundler_faker', license: 'Whatever'
5
+ @user.depend_on_local_gem 'bundler_faker', groups: ['test', 'development', 'production']
6
+ @user.create_gem 'gpl_gem', license: 'GPL'
7
+ @user.depend_on_local_gem 'gpl_gem', groups: ['test']
8
+ end
9
+
10
+ Given(/^I ignore the bundler dependency$/) do
11
+ @user.execute_command('license_finder ignored_dependencies add bundler_faker')
12
+ end
13
+
14
+ When(/^I get the ignored dependencies$/) do
15
+ @user.execute_command('license_finder ignored_dependencies list')
16
+ end
17
+
18
+ Then(/^I should see 'bundler' in the output$/) do
19
+ expect(@user).to be_seeing 'bundler_faker'
20
+ end
21
+
22
+ Then(/^the bundler dependency is not listed as an action item$/) do
23
+ @user.execute_command('license_finder > /dev/null')
24
+ @user.execute_command('license_finder action_items')
25
+ expect(@user).not_to be_seeing 'bundler_faker'
26
+ end
27
+
28
+ Then(/^I should not see 'bundler' in the dependency docs$/)do
29
+ @user.execute_command('license_finder')
30
+ dependencies_csv_path = @user.app_path.join('doc', 'dependencies.csv')
31
+ dependencies_csv = File.open(dependencies_csv_path, 'r')
32
+
33
+ expect(dependencies_csv.read).not_to match /bundler_faker/
34
+ end
35
+
@@ -0,0 +1,45 @@
1
+ Given(/^I have an app that depends on an MIT license$/) do
2
+ @user = ::DSL::User.new
3
+ @user.create_ruby_app
4
+ @user.create_and_depend_on_gem 'mit_gem', license: 'MIT'
5
+ end
6
+
7
+ Given(/^I have an app that depends on an BSD license$/) do
8
+ @user = ::DSL::User.new
9
+ @user.create_ruby_app
10
+ @user.create_and_depend_on_gem 'bsd_gem', license: 'BSD'
11
+ end
12
+
13
+ When(/^I whitelist the BSD license$/) do
14
+ @user.execute_command 'license_finder whitelist add BSD'
15
+ end
16
+
17
+ When(/^I whitelist the Expat license$/) do
18
+ @user.execute_command 'license_finder whitelist add Expat'
19
+ end
20
+
21
+ When(/^I view the whitelisted licenses$/) do
22
+ @user.execute_command 'license_finder whitelist list'
23
+ end
24
+
25
+ When(/^I remove Expat from the whitelist$/) do
26
+ @user.execute_command 'license_finder whitelist remove Expat'
27
+ end
28
+
29
+ Then(/^I should not see a MIT licensed gem unapproved$/) do
30
+ @user.execute_command 'license_finder --quiet'
31
+ @user.should_not be_seeing 'mit_gem'
32
+ end
33
+
34
+ Then(/^I should see Expat in the output$/) do
35
+ @user.should be_seeing 'Expat'
36
+ end
37
+
38
+ Then(/^I should not see Expat in the output$/) do
39
+ @user.should_not be_seeing 'Expat'
40
+ end
41
+
42
+ Then(/^I should not see a BSD licensed gem unapproved$/) do
43
+ @user.execute_command 'license_finder --quiet'
44
+ @user.should_not be_seeing 'bsd_gem'
45
+ end
@@ -4,5 +4,5 @@ Given(/^A build.gradle file with dependencies$/) do
4
4
  end
5
5
 
6
6
  Then(/^I should see a Gradle dependency with a license$/) do
7
- @output.should =~ /^junit, 4.11, Common Public License Version 1.0$/
8
- end
7
+ @user.should be_seeing_line "junit, 4.11, Common Public License Version 1.0"
8
+ end
@@ -0,0 +1,28 @@
1
+ Given(/^I have an app and a JS dependency$/) do
2
+ @user = ::DSL::User.new
3
+ @user.create_ruby_app
4
+ @user.execute_command 'license_finder dependencies add MIT my_js_dep 1.2.3'
5
+ end
6
+
7
+ When(/^I add my JS dependency$/) do
8
+ @user.execute_command 'license_finder dependencies add MIT my_js_dep 1.2.3'
9
+ end
10
+
11
+ When(/^I add my JS dependency with an approval flag$/) do
12
+ @user.execute_command 'license_finder dependencies add --approve MIT my_js_dep 1.2.3'
13
+ @user.should be_seeing "The my_js_dep dependency has been added and approved"
14
+ end
15
+
16
+ When(/^I remove my JS dependency$/) do
17
+ @user.execute_command 'license_finder dependencies remove my_js_dep'
18
+ end
19
+
20
+ Then(/^I should see the JS dependency in the console output$/) do
21
+ @user.execute_command 'license_finder --quiet'
22
+ @user.should be_seeing 'my_js_dep, 1.2.3, MIT'
23
+ end
24
+
25
+ Then(/^I should not see the JS dependency in the console output$/) do
26
+ @user.execute_command 'license_finder --quiet'
27
+ @user.should_not be_seeing 'my_js_dep, 1.2.3, MIT'
28
+ end
@@ -0,0 +1,24 @@
1
+ Given(/^I have an app that depends on a GPL licensed gem$/) do
2
+ @user = ::DSL::User.new
3
+ @user.create_ruby_app
4
+ @user.create_and_depend_on_gem "gpl_gem", license: "GPL"
5
+ end
6
+
7
+ When(/^I approve that gem$/) do
8
+ @user.execute_command "license_finder"
9
+ @user.should be_seeing "gpl_gem"
10
+ @user.execute_command "license_finder approve gpl_gem --approver 'Julian' --message 'We really need this'"
11
+ @user.execute_command "license_finder --quiet"
12
+ end
13
+
14
+ Then(/^I should not see that gem in the console output$/) do
15
+ @user.should_not be_seeing "gpl_gem"
16
+ end
17
+
18
+ Then(/^I should see that gem approved in dependencies\.html$/) do
19
+ @user.in_gem_html("gpl_gem") do |gpl_gem|
20
+ gpl_gem[:class].split(' ').should include "approved"
21
+ gpl_gem.should have_content "Julian"
22
+ gpl_gem.should have_content "We really need this"
23
+ end
24
+ end
@@ -0,0 +1,34 @@
1
+ Given(/^I have an app that depends on a few gems without known licenses$/) do
2
+ @user = ::DSL::User.new
3
+ @user.create_ruby_app
4
+ @user.create_and_depend_on_gem 'other_gem', version: '1.0', license: 'other'
5
+ @user.create_and_depend_on_gem 'control_gem', version: '1.0', license: 'other'
6
+ end
7
+
8
+ When(/^I set one gem's license to MIT from the command line$/) do
9
+ @user.execute_command 'license_finder --quiet'
10
+ @user.execute_command 'license_finder license MIT other_gem'
11
+ @user.execute_command 'license_finder --quiet'
12
+ end
13
+
14
+ Then(/^I should see that gem's license set to MIT$/) do
15
+ @user.should be_seeing 'other_gem, 1.0, MIT'
16
+ end
17
+
18
+ Then(/^I should see other gems have not changed their licenses$/) do
19
+ @user.should be_seeing 'control_gem, 1.0, other'
20
+ end
21
+
22
+ Given(/^I have an app that depends on a manually licensed gem$/) do
23
+ @user = ::DSL::User.new
24
+ @user.create_ruby_app
25
+ @user.create_and_depend_on_gem 'changed_gem', license: 'MIT'
26
+ @user.execute_command "license_finder --quiet"
27
+ @user.execute_command "license_finder license Ruby changed_gem"
28
+ @user.should be_seeing_something_like /changed_gem.*Ruby/
29
+ end
30
+
31
+ Then(/^the gem should keep its manually assigned license$/) do
32
+ @user.should be_seeing_something_like /changed_gem.*ruby/
33
+ end
34
+
@@ -4,5 +4,5 @@ Given(/^A pom file with dependencies$/) do
4
4
  end
5
5
 
6
6
  Then(/^I should see a Maven dependency with a license$/) do
7
- @output.should =~ /^junit, 4.11, Common Public License Version 1.0$/
8
- end
7
+ @user.should be_seeing_line "junit, 4.11, Common Public License Version 1.0"
8
+ end
@@ -4,5 +4,5 @@ Given(/^A package file with dependencies$/) do
4
4
  end
5
5
 
6
6
  Then(/^I should see a Node dependency with a license$/) do
7
- @output.should =~ /^http-server, 0.6.1, MIT$/
8
- end
7
+ @user.should be_seeing_line "http-server, 0.6.1, MIT"
8
+ end
@@ -4,5 +4,5 @@ Given(/^A requirements file with dependencies$/) do
4
4
  end
5
5
 
6
6
  Then(/^I should see a Python dependency with a license$/) do
7
- @output.should =~ /^argparse, 1.2.1, Python Software Foundation License$/
7
+ @user.should be_seeing_line "argparse, 1.2.1, Python Software Foundation License"
8
8
  end
@@ -0,0 +1,20 @@
1
+ Given(/^I have an app that depends on a gem with license and version details$/) do
2
+ @user = ::DSL::User.new
3
+ @user.create_ruby_app
4
+ @user.create_and_depend_on_gem('info_gem', license: 'MIT', version: '1.1.1')
5
+ end
6
+
7
+ Given(/^I have a dependencies\.txt file$/) do
8
+ @user.app_path("doc").mkpath
9
+
10
+ @user.app_path("doc/dependencies.txt").open('w+') { |file| file.puts("Legacy text file") }
11
+ end
12
+
13
+ Then(/^I should see those version and license details in the dependencies\.csv file$/) do
14
+ @user.app_path("doc/dependencies.csv").read.should include "info_gem, 1.1.1, MIT"
15
+ end
16
+
17
+ Then(/^I should see dependencies\.txt replaced by dependencies\.csv$/) do
18
+ @user.app_path("doc/dependencies.txt").should_not be_exist
19
+ @user.app_path("doc/dependencies.csv").should be_exist
20
+ end
@@ -0,0 +1,60 @@
1
+ Given(/^my app depends on a gem with specific details$/) do
2
+ @gem_name = "mit_licensed_gem"
3
+ @gem_homepage = "http://mit_licensed_gem.github.com"
4
+ @table = {
5
+ license: "MIT",
6
+ summary: "mit is cool",
7
+ description: "seriously",
8
+ version: "0.0.1",
9
+ bundler_group: "test"
10
+ }
11
+ @user.create_gem(@gem_name,
12
+ license: @table[:license],
13
+ summary: @table[:summary],
14
+ description: @table[:description],
15
+ version: @table[:version],
16
+ homepage: @gem_homepage,
17
+ )
18
+ @user.depend_on_local_gem(@gem_name, groups: [@table[:bundler_group]])
19
+ end
20
+
21
+ Given(/^my app depends on MIT and GPL licensed gems$/) do
22
+ @user.create_and_depend_on_gem 'gpl_licensed_gem', license: "GPL"
23
+ @user.create_and_depend_on_gem 'mit_licensed_gem', license: "MIT"
24
+ end
25
+
26
+ When(/^I whitelist the MIT license$/) do
27
+ @user.configure_license_finder_whitelist ["MIT"]
28
+ @user.execute_command "license_finder --quiet"
29
+ end
30
+
31
+ Then(/^I should see my specific gem details listed in the html$/) do
32
+ @user.in_gem_html(@gem_name) do |section|
33
+ section.find("a[href='#{@gem_homepage}']", text: @gem_name).should be
34
+ @table.values.each do |property_value|
35
+ section.should have_content property_value
36
+ end
37
+ end
38
+ end
39
+
40
+ Then(/^I should see the GPL gem unapproved in html$/) do
41
+ is_html_status?('gpl_licensed_gem', 'unapproved')
42
+ end
43
+
44
+ Then(/^the MIT gem approved in html$/) do
45
+ is_html_status?('mit_licensed_gem', 'approved')
46
+ end
47
+
48
+ Then(/^I should see only see GPL liceneses as unapproved in the html$/) do
49
+ @user.in_html do |page|
50
+ page.should have_content '1 GPL'
51
+ action_items = page.find('.action-items')
52
+ action_items.should have_content '(GPL)'
53
+ end
54
+ end
55
+
56
+ def is_html_status?(gem, approval)
57
+ @user.in_gem_html(gem) do |gpl_gem|
58
+ gpl_gem[:class].split(' ').should include approval
59
+ end
60
+ end
@@ -5,26 +5,26 @@ require 'capybara'
5
5
 
6
6
  ########## COMMON STEPS ##########
7
7
 
8
- Given(/^I have an app with license finder$/) do
8
+ Given(/^I have an app$/) do
9
9
  @user = ::DSL::User.new
10
- @user.create_nonrails_app
10
+ @user.create_ruby_app
11
11
  end
12
12
 
13
13
  When(/^I run license_finder$/) do
14
- @output = @user.execute_command "license_finder --quiet"
14
+ @user.execute_command "license_finder --quiet"
15
15
  end
16
16
 
17
- When(/^I whitelist MIT, New BSD, Apache 2.0, Ruby, and other licenses$/) do
17
+ When(/^I whitelist everything I can think of$/) do
18
18
  @user.configure_license_finder_whitelist ["MIT","other","New BSD","Apache 2.0","Ruby"]
19
- @output = @user.execute_command "license_finder --quiet"
19
+ @user.execute_command "license_finder --quiet"
20
20
  end
21
21
 
22
22
  Then(/^I should see the project name (\w+) in the html$/) do |project_name|
23
- html = File.read(@user.dependencies_html_path)
24
- page = Capybara.string(html)
25
- title = page.find("h1")
23
+ @user.in_html do |page|
24
+ title = page.find("h1")
26
25
 
27
- title.should have_content project_name
26
+ title.should have_content project_name
27
+ end
28
28
  end
29
29
 
30
30
 
@@ -33,8 +33,8 @@ module DSL
33
33
  def create_python_app
34
34
  reset_projects!
35
35
 
36
- `mkdir -p #{app_path}`
37
- `cd #{app_path} && touch requirements.txt`
36
+ app_path.mkpath
37
+ shell_out("cd #{app_path} && touch requirements.txt")
38
38
 
39
39
  add_pip_dependency('argparse==1.2.1')
40
40
 
@@ -44,8 +44,8 @@ module DSL
44
44
  def create_node_app
45
45
  reset_projects!
46
46
 
47
- `mkdir -p #{app_path}`
48
- `cd #{app_path} && touch package.json`
47
+ app_path.mkpath
48
+ shell_out("cd #{app_path} && touch package.json")
49
49
 
50
50
  add_npm_dependency('http-server', '0.6.1')
51
51
 
@@ -55,10 +55,9 @@ module DSL
55
55
  def create_maven_app
56
56
  reset_projects!
57
57
 
58
- path = File.expand_path("spec/fixtures/pom.xml")
58
+ app_path.mkpath
59
59
 
60
- `mkdir -p #{app_path}`
61
- `cd #{app_path} && cp #{path} .`
60
+ add_maven_dependency
62
61
 
63
62
  mvn_install
64
63
  end
@@ -66,125 +65,129 @@ module DSL
66
65
  def create_gradle_app
67
66
  reset_projects!
68
67
 
69
- path = File.expand_path("spec/fixtures/build.gradle")
68
+ app_path.mkpath
70
69
 
71
- `mkdir -p #{app_path}`
72
- `cd #{app_path} && cp #{path} .`
73
- `gradle dependencies`
70
+ add_gradle_dependency
74
71
  end
75
72
 
76
- def create_nonrails_app
73
+ def create_ruby_app
77
74
  reset_projects!
78
75
 
79
- `cd #{projects_path} && bundle gem #{app_name}`
76
+ shell_out("cd #{projects_path} && bundle gem #{app_name}")
80
77
 
81
- add_gem_dependency('license_finder', :path => root_path)
78
+ add_gem_dependency('license_finder', path: root_path.to_s)
82
79
 
83
- bundle_app
80
+ bundle_install
84
81
  end
85
82
 
86
- def create_rails_app
83
+ def create_cocoapods_app
87
84
  reset_projects!
88
85
 
89
- `bundle exec rails new #{app_path} --skip-bundle`
90
-
91
- add_gem_dependency('license_finder', :path => root_path)
92
-
93
- bundle_app
94
- end
95
-
96
- def update_gem(name, attrs)
97
- file_contents = YAML.load(File.read(dependencies_file_path))
86
+ app_path.mkpath
98
87
 
99
- index = file_contents.index { |gem| gem['name'] == name }
100
- file_contents[index].merge!(attrs)
88
+ add_pod_dependency
101
89
 
102
- File.open(dependencies_file_path, "w") do |f|
103
- f.puts file_contents.to_yaml
104
- end
90
+ pod_install
105
91
  end
106
92
 
107
- def append_to_file(filename, text)
108
- File.open(File.join(app_path, filename), "a") do |f|
109
- f.puts text
110
- end
93
+ def create_and_depend_on_gem(gem_name, options)
94
+ create_gem(gem_name, options)
95
+ depend_on_local_gem(gem_name)
111
96
  end
112
97
 
113
- def add_dependency_to_app(gem_name, options={})
114
- license = options.fetch(:license)
115
- summary = options.fetch(:summary, "")
116
- description = options.fetch(:description, "")
117
- bundler_groups = options.fetch(:bundler_groups, "").to_s.split(',').map(&:strip)
118
- version = options[:version] || "0.0.0"
119
- homepage = options[:homepage]
98
+ def create_gem(gem_name, options)
99
+ gem_dir = projects_path.join(gem_name)
120
100
 
121
- gem_dir = File.join(projects_path, gem_name)
122
-
123
- FileUtils.mkdir(gem_dir)
124
- File.open(File.join(gem_dir, "#{gem_name}.gemspec"), 'w') do |file|
125
- file.write <<-GEMSPEC
126
- Gem::Specification.new do |s|
127
- s.name = "#{gem_name}"
128
- s.version = "#{version}"
129
- s.author = "Cucumber"
130
- s.summary = "#{summary}"
131
- s.license = "#{license}"
132
- s.description = "#{description}"
133
- s.homepage = "#{homepage}"
134
- end
135
- GEMSPEC
101
+ gem_dir.mkpath
102
+ gem_dir.join("#{gem_name}.gemspec").open('w') do |file|
103
+ file.write gemspec_string(gem_name, options)
136
104
  end
105
+ end
137
106
 
138
- gem_options = {}
139
- gem_options[:path] = File.join(projects_path, gem_name)
140
- gem_options[:groups] = bundler_groups unless bundler_groups.empty?
107
+ def depend_on_local_gem(gem_name, options={})
108
+ gem_dir = projects_path.join(gem_name)
109
+ options[:path] = gem_dir.to_s
141
110
 
142
- add_gem_dependency(gem_name, gem_options)
111
+ add_gem_dependency(gem_name, options)
143
112
 
144
- bundle_app
113
+ bundle_install
145
114
  end
146
115
 
147
116
  def configure_license_finder_whitelist(whitelisted_licenses=[])
148
- FileUtils.mkdir_p(config_path)
149
- File.open(File.join(config_path, "license_finder.yml"), "w") do |f|
117
+ config_path.mkpath
118
+ config_file.open("w") do |f|
150
119
  f.write({'whitelist' => whitelisted_licenses}.to_yaml)
151
120
  end
152
121
  end
153
122
 
154
123
  def execute_command(command)
155
124
  ::Bundler.with_clean_env do
156
- @output = `cd #{app_path} && bundle exec #{command}`
125
+ @output = shell_out("cd #{app_path} && bundle exec #{command}", true)
157
126
  end
127
+ end
128
+
129
+ def seeing?(content)
130
+ @output.include? content
131
+ end
132
+
133
+ def seeing_line?(content)
134
+ seeing_something_like? /^#{Regexp.escape content}$/
135
+ end
158
136
 
159
- @output
137
+ def seeing_something_like?(regex)
138
+ @output =~ regex
160
139
  end
161
140
 
162
141
  def app_path(sub_directory = nil)
163
- path = app_path = Pathname.new(File.join(projects_path, app_name)).cleanpath.to_s
142
+ path = base_path = projects_path.join(app_name).cleanpath
164
143
 
165
144
  if sub_directory
166
- path = Pathname.new(File.join(app_path, sub_directory)).cleanpath.to_s
145
+ path = base_path.join(sub_directory).cleanpath
167
146
 
168
- raise "#{name} is outside of the app" unless path =~ %r{^#{app_path}/}
147
+ raise "#{sub_directory} is outside of the app" unless path.to_s =~ %r{^#{base_path}/}
169
148
  end
170
149
 
171
150
  path
172
151
  end
173
152
 
174
153
  def config_path
175
- File.join(app_path, 'config')
154
+ app_path('config')
155
+ end
156
+
157
+ def config_file
158
+ config_path.join("license_finder.yml")
176
159
  end
177
160
 
178
- def doc_path
179
- File.join(app_path, 'doc')
161
+ def in_html
162
+ yield Capybara.string(app_path('doc/dependencies.html').read)
180
163
  end
181
164
 
182
- def dependencies_file_path
183
- File.join(doc_path, 'dependencies.yml')
165
+ def in_gem_html(gem_name)
166
+ in_html do |page|
167
+ yield page.find("##{gem_name}")
168
+ end
184
169
  end
185
170
 
186
- def dependencies_html_path
187
- File.join(doc_path, 'dependencies.html')
171
+ private
172
+
173
+ def gemspec_string(gem_name, options)
174
+ license = options.fetch(:license)
175
+ summary = options.fetch(:summary, "")
176
+ description = options.fetch(:description, "")
177
+ version = options[:version] || "0.0.0"
178
+ homepage = options[:homepage]
179
+
180
+ <<-GEMSPEC
181
+ Gem::Specification.new do |s|
182
+ s.name = "#{gem_name}"
183
+ s.version = "#{version}"
184
+ s.author = "Cucumber"
185
+ s.summary = "#{summary}"
186
+ s.license = "#{license}"
187
+ s.description = "#{description}"
188
+ s.homepage = "#{homepage}"
189
+ end
190
+ GEMSPEC
188
191
  end
189
192
 
190
193
  def add_gem_dependency(name, options = {})
@@ -204,41 +207,53 @@ module DSL
204
207
  add_to_package(line)
205
208
  end
206
209
 
207
- def bundle_app
210
+ def add_maven_dependency
211
+ path = fixtures_path.join("pom.xml")
212
+ shell_out("cp #{path} #{app_path}")
213
+ end
214
+
215
+ def add_gradle_dependency
216
+ path = fixtures_path.join("build.gradle")
217
+ shell_out("cd #{app_path} && cp #{path} .")
218
+ end
219
+
220
+ def add_pod_dependency
221
+ path = fixtures_path.join("Podfile")
222
+ shell_out("cp #{path} #{app_path}")
223
+ end
224
+
225
+ def bundle_install
208
226
  ::Bundler.with_clean_env do
209
- `bundle install --gemfile=#{File.join(app_path, "Gemfile")} --path=#{bundle_path}`
227
+ shell_out("bundle install --gemfile=#{app_path.join("Gemfile")} --path=#{sandbox_path.join("bundle")}")
210
228
  end
211
229
  end
212
230
 
213
231
  def pip_install
214
- `cd #{app_path} && pip install -r requirements.txt`
232
+ shell_out("cd #{app_path} && pip install -r requirements.txt")
215
233
  end
216
234
 
217
235
  def npm_install
218
- `cd #{app_path} && npm install 2>/dev/null`
236
+ shell_out("cd #{app_path} && npm install 2>/dev/null")
219
237
  end
220
238
 
221
239
  def mvn_install
222
- `cd #{app_path} && mvn install`
240
+ shell_out("cd #{app_path} && mvn install")
223
241
  end
224
242
 
225
- def modifying_dependencies_file
226
- FileUtils.mkdir_p(File.dirname(dependencies_file_path))
227
- File.open(dependencies_file_path, 'w+') { |f| yield f }
243
+ def pod_install
244
+ shell_out("cd #{app_path} && pod install --no-integrate")
228
245
  end
229
246
 
230
- private
231
-
232
247
  def add_to_gemfile(line)
233
- `echo #{line.inspect} >> #{File.join(app_path, "Gemfile")}`
248
+ shell_out("echo #{line.inspect} >> #{app_path.join("Gemfile")}")
234
249
  end
235
250
 
236
251
  def add_to_requirements(line)
237
- `echo #{line.inspect} >> #{File.join(app_path, "requirements.txt")}`
252
+ shell_out("echo #{line.inspect} >> #{app_path.join("requirements.txt")}")
238
253
  end
239
254
 
240
255
  def add_to_package(line)
241
- `echo #{line.inspect} >> #{File.join(app_path, "package.json")}`
256
+ shell_out("echo #{line.inspect} >> #{app_path.join("package.json")}")
242
257
  end
243
258
 
244
259
  def app_name
@@ -246,24 +261,30 @@ module DSL
246
261
  end
247
262
 
248
263
  def sandbox_path
249
- File.join(root_path, "tmp")
264
+ root_path.join("tmp")
250
265
  end
251
266
 
252
267
  def projects_path
253
- File.join(sandbox_path, "projects")
268
+ sandbox_path.join("projects")
254
269
  end
255
270
 
256
- def bundle_path
257
- File.join(sandbox_path, "bundle")
271
+ def fixtures_path
272
+ root_path.join("spec", "fixtures")
258
273
  end
259
274
 
260
275
  def reset_projects!
261
- `rm -rf #{projects_path}`
262
- `mkdir -p #{projects_path}`
276
+ shell_out("rm -rf #{projects_path}")
277
+ projects_path.mkpath
263
278
  end
264
279
 
265
280
  def root_path
266
- Pathname.new(File.join(File.dirname(__FILE__), "..", "..")).realpath.to_s
281
+ Pathname.new(__FILE__).dirname.join("..", "..").realpath
282
+ end
283
+
284
+ def shell_out(command, allow_failures = false)
285
+ output = `#{command}`
286
+ raise RuntimeError.new("command failed #{command}") unless $?.success? || allow_failures
287
+ output
267
288
  end
268
289
  end
269
290
  end