license_finder 1.2 → 2.0.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (220) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -1
  3. data/CHANGELOG.rdoc +27 -0
  4. data/CONTRIBUTING.md +38 -0
  5. data/README.md +139 -159
  6. data/Rakefile +17 -13
  7. data/features/features/cli_spec.rb +43 -0
  8. data/features/features/configure/add_dependencies_spec.rb +37 -0
  9. data/features/features/configure/approve_dependencies_spec.rb +30 -0
  10. data/features/features/configure/assign_licenses_spec.rb +20 -0
  11. data/features/features/configure/ignore_dependencies_spec.rb +35 -0
  12. data/features/features/configure/ignore_groups_spec.rb +31 -0
  13. data/features/features/configure/name_project_spec.rb +32 -0
  14. data/features/features/configure/whitelist_licenses_spec.rb +40 -0
  15. data/features/features/package_managers/bower_spec.rb +14 -0
  16. data/features/features/package_managers/cocoapods_spec.rb +14 -0
  17. data/features/features/package_managers/gradle_spec.rb +14 -0
  18. data/features/features/package_managers/maven_spec.rb +14 -0
  19. data/features/features/package_managers/npm_spec.rb +14 -0
  20. data/features/features/package_managers/pip_spec.rb +14 -0
  21. data/features/features/report/csv_spec.rb +17 -0
  22. data/features/features/report/html_spec.rb +50 -0
  23. data/{spec → features}/fixtures/Podfile +0 -0
  24. data/{spec → features}/fixtures/build.gradle +0 -0
  25. data/{spec → features}/fixtures/pom.xml +0 -0
  26. data/features/support/testing_dsl.rb +295 -0
  27. data/lib/license_finder.rb +16 -50
  28. data/lib/license_finder/cli.rb +13 -253
  29. data/lib/license_finder/cli/approvals.rb +26 -0
  30. data/lib/license_finder/cli/base.rb +20 -0
  31. data/lib/license_finder/cli/dependencies.rb +39 -0
  32. data/lib/license_finder/cli/ignored_dependencies.rb +30 -0
  33. data/lib/license_finder/cli/ignored_groups.rb +30 -0
  34. data/lib/license_finder/cli/licenses.rb +24 -0
  35. data/lib/license_finder/cli/main.rb +82 -0
  36. data/lib/license_finder/cli/makes_decisions.rb +48 -0
  37. data/lib/license_finder/cli/patched_thor.rb +34 -0
  38. data/lib/license_finder/cli/project_name.rb +31 -0
  39. data/lib/license_finder/cli/whitelist.rb +32 -0
  40. data/lib/license_finder/configuration.rb +14 -145
  41. data/lib/license_finder/decision_applier.rb +46 -0
  42. data/lib/license_finder/decisions.rb +174 -0
  43. data/lib/license_finder/license.rb +13 -32
  44. data/lib/license_finder/license/definitions.rb +15 -13
  45. data/lib/license_finder/license/template.rb +1 -1
  46. data/lib/{data/licenses → license_finder/license/templates}/Apache2.txt +0 -0
  47. data/lib/{data/licenses → license_finder/license/templates}/BSD.txt +0 -0
  48. data/lib/{data/licenses → license_finder/license/templates}/GPLv2.txt +0 -0
  49. data/lib/{data/licenses → license_finder/license/templates}/ISC.txt +0 -0
  50. data/lib/{data/licenses → license_finder/license/templates}/LGPL.txt +0 -0
  51. data/lib/{data/licenses → license_finder/license/templates}/MIT.txt +0 -0
  52. data/lib/{data/licenses → license_finder/license/templates}/NewBSD.txt +0 -0
  53. data/lib/{data/licenses → license_finder/license/templates}/Python.txt +0 -0
  54. data/lib/{data/licenses → license_finder/license/templates}/Ruby.txt +0 -0
  55. data/lib/{data/licenses → license_finder/license/templates}/SimplifiedBSD.txt +0 -0
  56. data/lib/license_finder/package.rb +77 -7
  57. data/lib/license_finder/package_manager.rb +43 -0
  58. data/lib/license_finder/package_managers/bower.rb +1 -1
  59. data/lib/license_finder/package_managers/bower_package.rb +23 -44
  60. data/lib/license_finder/package_managers/bundler.rb +4 -7
  61. data/lib/license_finder/package_managers/bundler_package.rb +14 -31
  62. data/lib/license_finder/package_managers/cocoa_pods.rb +1 -1
  63. data/lib/license_finder/package_managers/cocoa_pods_package.rb +2 -10
  64. data/lib/license_finder/package_managers/gradle.rb +6 -2
  65. data/lib/license_finder/package_managers/gradle_package.rb +6 -30
  66. data/lib/license_finder/package_managers/manual_package.rb +25 -0
  67. data/lib/license_finder/package_managers/maven_package.rb +8 -37
  68. data/lib/license_finder/package_managers/npm.rb +16 -4
  69. data/lib/license_finder/package_managers/npm_package.rb +12 -43
  70. data/lib/license_finder/package_managers/pip_package.rb +17 -37
  71. data/lib/license_finder/platform.rb +0 -16
  72. data/lib/license_finder/possible_license_file.rb +9 -14
  73. data/lib/license_finder/possible_license_files.rb +1 -5
  74. data/lib/license_finder/report.rb +26 -0
  75. data/lib/license_finder/reports/csv_report.rb +58 -0
  76. data/lib/license_finder/reports/erb_report.rb +61 -0
  77. data/lib/license_finder/reports/html_report.rb +10 -1
  78. data/lib/license_finder/reports/markdown_report.rb +7 -1
  79. data/lib/license_finder/reports/templates/bootstrap.css +9 -0
  80. data/lib/license_finder/reports/templates/html_report.erb +105 -0
  81. data/lib/{templates → license_finder/reports/templates}/markdown_report.erb +7 -7
  82. data/lib/license_finder/reports/text_report.rb +5 -3
  83. data/lib/license_finder/version.rb +3 -0
  84. data/license_finder.gemspec +2 -6
  85. data/release/instructions.md +8 -0
  86. data/spec/feature_helper.rb +11 -0
  87. data/spec/fixtures/config/license_finder.yml +3 -0
  88. data/spec/fixtures/{nested_readme/vendor/README → license_directory/LICENSE/Apache.txt} +0 -0
  89. data/spec/lib/license_finder/cli/approvals_spec.rb +63 -0
  90. data/spec/lib/license_finder/cli/dependencies_spec.rb +59 -0
  91. data/spec/lib/license_finder/cli/ignored_dependencies_spec.rb +47 -0
  92. data/spec/lib/license_finder/cli/ignored_groups_spec.rb +40 -0
  93. data/spec/lib/license_finder/cli/licenses_spec.rb +60 -0
  94. data/spec/lib/license_finder/cli/main_spec.rb +110 -0
  95. data/spec/lib/license_finder/cli/project_name_spec.rb +40 -0
  96. data/spec/lib/license_finder/cli/whitelist_spec.rb +58 -0
  97. data/spec/lib/license_finder/configuration_spec.rb +46 -191
  98. data/spec/lib/license_finder/decision_applier_spec.rb +65 -0
  99. data/spec/lib/license_finder/decisions_spec.rb +347 -0
  100. data/spec/lib/license_finder/license/definitions_spec.rb +1 -7
  101. data/spec/lib/license_finder/license_spec.rb +2 -30
  102. data/spec/lib/license_finder/package_manager_spec.rb +22 -0
  103. data/spec/lib/license_finder/package_managers/bower_package_spec.rb +33 -66
  104. data/spec/lib/license_finder/package_managers/bundler_package_spec.rb +7 -71
  105. data/spec/lib/license_finder/package_managers/cocoa_pods_package_spec.rb +8 -11
  106. data/spec/lib/license_finder/package_managers/gradle_package_spec.rb +28 -32
  107. data/spec/lib/license_finder/package_managers/gradle_spec.rb +18 -23
  108. data/spec/lib/license_finder/package_managers/maven_package_spec.rb +20 -43
  109. data/spec/lib/license_finder/package_managers/npm_package_spec.rb +22 -73
  110. data/spec/lib/license_finder/package_managers/npm_spec.rb +18 -21
  111. data/spec/lib/license_finder/package_managers/pip_package_spec.rb +24 -63
  112. data/spec/lib/license_finder/package_spec.rb +121 -0
  113. data/spec/lib/license_finder/possible_license_file_spec.rb +2 -3
  114. data/spec/lib/license_finder/possible_license_files_spec.rb +18 -22
  115. data/spec/lib/license_finder/reports/csv_report_spec.rb +26 -0
  116. data/spec/lib/license_finder/reports/html_report_spec.rb +39 -22
  117. data/spec/lib/license_finder/reports/markdown_report_spec.rb +8 -16
  118. data/spec/lib/license_finder/reports/text_report_spec.rb +21 -12
  119. data/spec/spec_helper.rb +1 -4
  120. data/spec/support/shared_examples_for_package.rb +0 -11
  121. data/spec/support/shared_examples_for_package_manager.rb +1 -0
  122. data/spec/support/stdout_helpers.rb +4 -11
  123. metadata +73 -158
  124. data/db/migrate/201303290935_create_dependencies.rb +0 -14
  125. data/db/migrate/201303291155_create_licenses.rb +0 -13
  126. data/db/migrate/201303291402_create_approvals.rb +0 -13
  127. data/db/migrate/201303291456_create_ancestries.rb +0 -9
  128. data/db/migrate/201303291519_create_bundler_groups.rb +0 -13
  129. data/db/migrate/201303291720_move_manual_from_approvals_to_licenses.rb +0 -11
  130. data/db/migrate/201303291753_allow_null_license_names.rb +0 -7
  131. data/db/migrate/201304011027_allow_null_dependency_version.rb +0 -7
  132. data/db/migrate/201304020947_change_table_name_licenses_to_license_aliases.rb +0 -5
  133. data/db/migrate/201304181524_add_manual_to_dependencies.rb +0 -7
  134. data/db/migrate/201307250917_add_license_manual_to_dependencies.rb +0 -7
  135. data/db/migrate/201307251004_data_fix_manual_licenses.rb +0 -15
  136. data/db/migrate/201307251107_reassociate_license.rb +0 -23
  137. data/db/migrate/201307251340_remove_manual_from_license_aliases.rb +0 -7
  138. data/db/migrate/201311192002_add_manually_approved_to_dependencies.rb +0 -7
  139. data/db/migrate/201311192003_reassociate_manual_approval.rb +0 -13
  140. data/db/migrate/201311192010_drop_approvals.rb +0 -5
  141. data/db/migrate/201401302113_re_reassociate_license.rb +0 -23
  142. data/db/migrate/201403181732_rename_manual_fields.rb +0 -10
  143. data/db/migrate/201403190028_add_manual_approvals.rb +0 -22
  144. data/db/migrate/201403191419_add_timestamps_to_manual_approvals.rb +0 -15
  145. data/db/migrate/201403191645_remove_license_aliases.rb +0 -23
  146. data/db/migrate/201410031451_rename_dependency_license_name.rb +0 -6
  147. data/features/cli.feature +0 -37
  148. data/features/cocoapods_dependencies.feature +0 -10
  149. data/features/configure_bundler_groups.feature +0 -23
  150. data/features/configure_ignore_dependencies.feature +0 -16
  151. data/features/configure_project_name.feature +0 -10
  152. data/features/configure_whitelist.feature +0 -27
  153. data/features/gradle_dependencies.feature +0 -9
  154. data/features/manually_added.feature +0 -19
  155. data/features/manually_approved.feature +0 -10
  156. data/features/manually_assigned_license.feature +0 -16
  157. data/features/maven_dependencies.feature +0 -9
  158. data/features/multiple_licenses.feature +0 -9
  159. data/features/node_dependencies.feature +0 -9
  160. data/features/python_dependencies.feature +0 -9
  161. data/features/report_csv.feature +0 -15
  162. data/features/report_html.feature +0 -24
  163. data/features/step_definitions/cli_steps.rb +0 -51
  164. data/features/step_definitions/cocoapod_steps.rb +0 -8
  165. data/features/step_definitions/configure_bundler_groups_steps.rb +0 -30
  166. data/features/step_definitions/configure_ignore_dependencies.rb +0 -35
  167. data/features/step_definitions/configure_project_name_steps.rb +0 -3
  168. data/features/step_definitions/configure_whitelist_steps.rb +0 -45
  169. data/features/step_definitions/gradle_steps.rb +0 -8
  170. data/features/step_definitions/manually_added_steps.rb +0 -28
  171. data/features/step_definitions/manually_approved_steps.rb +0 -24
  172. data/features/step_definitions/manually_assigned_license_steps.rb +0 -34
  173. data/features/step_definitions/maven_steps.rb +0 -8
  174. data/features/step_definitions/multiple_licenses_steps.rb +0 -14
  175. data/features/step_definitions/node_steps.rb +0 -8
  176. data/features/step_definitions/python_steps.rb +0 -8
  177. data/features/step_definitions/report_csv_steps.rb +0 -20
  178. data/features/step_definitions/report_html_steps.rb +0 -60
  179. data/features/step_definitions/shared_steps.rb +0 -307
  180. data/lib/data/license_finder.example.yml +0 -12
  181. data/lib/license_finder/dependency_manager.rb +0 -92
  182. data/lib/license_finder/package_saver.rb +0 -44
  183. data/lib/license_finder/reports/dependency_report.rb +0 -34
  184. data/lib/license_finder/reports/detailed_text_report.rb +0 -19
  185. data/lib/license_finder/reports/formatted_report.rb +0 -40
  186. data/lib/license_finder/reports/reporter.rb +0 -27
  187. data/lib/license_finder/tables.rb +0 -9
  188. data/lib/license_finder/tables/bundler_group.rb +0 -7
  189. data/lib/license_finder/tables/dependency.rb +0 -113
  190. data/lib/license_finder/tables/manual_approval.rb +0 -13
  191. data/lib/license_finder/yml_to_sql.rb +0 -117
  192. data/lib/templates/html_report.erb +0 -117
  193. data/lib/templates/text_report.erb +0 -3
  194. data/release/gem_version.rb +0 -3
  195. data/release/manual_instructions.md +0 -29
  196. data/release/publish.sh +0 -32
  197. data/spec/fixtures/APACHE-2-LICENSE +0 -202
  198. data/spec/fixtures/GPLv2 +0 -339
  199. data/spec/fixtures/ISC-LICENSE +0 -10
  200. data/spec/fixtures/MIT-LICENSE +0 -22
  201. data/spec/fixtures/MIT-LICENSE-with-varied-disclaimer +0 -22
  202. data/spec/fixtures/README-with-MIT-LICENSE +0 -222
  203. data/spec/fixtures/license_directory/LICENSE/BSD-2-Clause.txt +0 -25
  204. data/spec/fixtures/license_directory/LICENSE/GPL-2.0.txt +0 -339
  205. data/spec/fixtures/license_directory/LICENSE/LICENSE +0 -191
  206. data/spec/fixtures/license_directory/LICENSE/MIT.txt +0 -21
  207. data/spec/fixtures/license_directory/LICENSE/RUBY.txt +0 -60
  208. data/spec/fixtures/mit_licensed_gem/LICENSE +0 -22
  209. data/spec/fixtures/other_licensed_gem/LICENSE +0 -3
  210. data/spec/fixtures/readme/Project ReadMe b/data/spec/fixtures/readme/Project → ReadMe +0 -0
  211. data/spec/fixtures/readme/README +0 -0
  212. data/spec/fixtures/readme/Readme.markdown +0 -0
  213. data/spec/lib/license_finder/cli_spec.rb +0 -298
  214. data/spec/lib/license_finder/dependency_manager_spec.rb +0 -198
  215. data/spec/lib/license_finder/package_saver_spec.rb +0 -82
  216. data/spec/lib/license_finder/reports/detailed_text_report_spec.rb +0 -33
  217. data/spec/lib/license_finder/reports/reporter_spec.rb +0 -33
  218. data/spec/lib/license_finder/tables/dependency_spec.rb +0 -196
  219. data/spec/lib/license_finder/yml_to_sql_spec.rb +0 -123
  220. data/spec/lib/license_finder_spec.rb +0 -16
@@ -13,14 +13,26 @@ module LicenseFinder
13
13
  resp
14
14
  end
15
15
 
16
+ def stub_license_report(dependencies, package_manager = gradle)
17
+ license_xml = license_xml(dependencies)
18
+ fake_file = double(:license_report, read: license_xml)
19
+ allow(package_manager).to receive(:license_report).and_return(fake_file)
20
+ end
21
+
16
22
  describe '.current_packages' do
17
23
  before do
18
- allow(LicenseFinder.config).to receive(:gradle_command) { 'gradlefoo' }
24
+ allow(gradle).to receive('`').with(/gradle downloadLicenses/)
25
+ end
26
+
27
+ it "uses custom gradle command, if provided" do
28
+ gradle = Gradle.new(gradle_command: "gradlefoo")
29
+ stub_license_report("", gradle)
19
30
  expect(gradle).to receive('`').with(/gradlefoo downloadLicenses/)
31
+ gradle.current_packages
20
32
  end
21
33
 
22
34
  it 'lists all the current packages' do
23
- license_xml = license_xml("""
35
+ stub_license_report("""
24
36
  <dependency name='org.springframework:spring-aop:4.0.1.RELEASE'>
25
37
  <file>spring-aop-4.0.1.RELEASE.jar</file>
26
38
  <license name='The Apache Software License, Version 2.0' url='http://www.apache.org/licenses/LICENSE-2.0.txt' />
@@ -30,8 +42,6 @@ module LicenseFinder
30
42
  <license name='The Apache Software License, Version 2.0' url='http://www.apache.org/licenses/LICENSE-2.0.txt' />
31
43
  </dependency>
32
44
  """)
33
- fake_file = double(:license_report, read: license_xml)
34
- allow(gradle).to receive(:license_report).and_return(fake_file)
35
45
 
36
46
  current_packages = gradle.current_packages
37
47
 
@@ -40,39 +50,24 @@ module LicenseFinder
40
50
  end
41
51
 
42
52
  it "handles multiple licenses" do
43
- license_xml = license_xml("""
53
+ stub_license_report("""
44
54
  <dependency>
45
55
  <license name='License 1'/>
46
56
  <license name='License 2'/>
47
57
  </dependency>
48
58
  """)
49
59
 
50
- fake_file = double(:license_report, read: license_xml)
51
- allow(gradle).to receive(:license_report).and_return(fake_file)
52
-
53
60
  expect(GradlePackage).to receive(:new).with({"license" => [{"name" => "License 1"}, {"name" => "License 2"}]}, anything)
54
61
  gradle.current_packages
55
62
  end
56
63
 
57
- it "handles no licenses" do
58
- license_xml = license_xml("""
64
+ it "handles an empty list of licenses" do
65
+ stub_license_report("""
59
66
  <dependency>
60
- <license name='No license found' />
61
67
  </dependency>
62
68
  """)
69
+ expect(GradlePackage).to receive(:new).with({}, anything)
63
70
 
64
- fake_file = double(:license_report, read: license_xml)
65
- allow(gradle).to receive(:license_report).and_return(fake_file)
66
-
67
- expect(GradlePackage).to receive(:new).with({"license" => []}, anything)
68
- gradle.current_packages
69
- end
70
-
71
- it "handles an empty list of licenses" do
72
- license_xml = license_xml("")
73
-
74
- fake_file = double(:license_report, read: license_xml)
75
- allow(gradle).to receive(:license_report).and_return(fake_file)
76
71
  gradle.current_packages
77
72
  end
78
73
  end
@@ -4,15 +4,9 @@ module LicenseFinder
4
4
  describe MavenPackage do
5
5
  subject do
6
6
  described_class.new(
7
- {
8
- "groupId" => "org.hamcrest",
9
- "artifactId" => "hamcrest-core",
10
- "version" => "4.11",
11
- "licenses" => [{
12
- "name" => "Common Public License Version 1.0",
13
- "url" => "http://www.opensource.org/licenses/cpl1.0.txt"
14
- }]
15
- }
7
+ "artifactId" => "hamcrest-core",
8
+ "version" => "4.11",
9
+ "licenses" => [{ "name" => "MIT" }]
16
10
  )
17
11
  end
18
12
 
@@ -20,52 +14,35 @@ module LicenseFinder
20
14
 
21
15
  its(:name) { should == "hamcrest-core" }
22
16
  its(:version) { should == "4.11" }
17
+ its(:summary) { should == "" }
23
18
  its(:description) { should == "" }
24
-
25
- describe "#licenses" do
26
- it "returns the license if found" do
27
- expect(subject.licenses.length).to eq 1
28
- expect(subject.licenses.first.name).to eq "Common Public License Version 1.0"
19
+ its(:homepage) { should == "" }
20
+ its(:groups) { should == [] } # no way to get groups from maven?
21
+ its(:children) { should == [] } # no way to get children from maven?
22
+ its(:install_path) { should be_nil }
23
+
24
+ describe "#license_names_from_spec" do
25
+ it "returns the license" do
26
+ expect(subject.license_names_from_spec).to eq ["MIT"]
29
27
  end
30
28
 
31
- context "when there are multiple licenses" do
32
- subject do
33
- described_class.new(
34
- {
35
- "groupId" => "org.hamcrest",
36
- "artifactId" => "hamcrest-core",
37
- "licenses" => [{
38
- "name" => "Common Public License Version 1.0",
39
- "url" => "http://www.opensource.org/licenses/cpl1.0.txt"
40
- },
41
- {
42
- "name" => "Apache 2",
43
- "url" => "http://www.apache.org/licenses/LICENSE-2.0.txt"
44
- }]
45
- }
46
- )
47
- end
29
+ context "when there are no licenses" do
30
+ subject { described_class.new({}) }
48
31
 
49
- it "returns 'multiple licenses'" do
50
- expect(subject.licenses.length).to eq 2
51
- expect(subject.licenses.map(&:name)).to eq ['Common Public License Version 1.0', 'Apache 2']
32
+ it "is empty" do
33
+ expect(subject.license_names_from_spec).to be_empty
52
34
  end
53
35
  end
54
36
 
55
- context "when the license is not found" do
37
+ context "when there are multiple licenses" do
56
38
  subject do
57
39
  described_class.new(
58
- {
59
- "groupId" => "org.hamcrest",
60
- "artifactId" => "hamcrest-core",
61
- "licenses" => {}
62
- }
40
+ "licenses" => [{ "name" => "1" }, { "name" => "2" }]
63
41
  )
64
42
  end
65
43
 
66
- it "returns 'other' otherwise" do
67
- expect(subject.licenses.length).to eq 1
68
- expect(subject.licenses.first.name).to eq "other"
44
+ it "returns multiple licenses" do
45
+ expect(subject.license_names_from_spec).to eq ['1', '2']
69
46
  end
70
47
  end
71
48
  end
@@ -9,7 +9,12 @@ module LicenseFinder
9
9
  "description" => "a description",
10
10
  "readme" => "a readme",
11
11
  "path" => "some/node/package/path",
12
- "homepage" => "a homepage"
12
+ "homepage" => "a homepage",
13
+ "dependencies" => {
14
+ "coffee-script" => {
15
+ "name" => "coffee-script",
16
+ }
17
+ }
13
18
  )
14
19
  end
15
20
 
@@ -17,92 +22,36 @@ module LicenseFinder
17
22
 
18
23
  its(:name) { should == "jasmine-node" }
19
24
  its(:version) { should == "1.3.1" }
20
- its(:summary) { should == "a description" }
21
- its(:description) { should == "a readme" }
25
+ its(:summary) { should eq "" }
26
+ its(:description) { should == "a description" }
22
27
  its(:homepage) { should == "a homepage" }
23
- its(:groups) { should == [] }
24
- its(:children) { should == [] }
25
-
26
- describe '#licenses' do
27
- def stub_license_files(license_files)
28
- allow(PossibleLicenseFiles).to receive(:find).with("some/node/package/path").and_return(license_files)
29
- end
30
-
31
- let(:node_module1) { {"license" => "MIT", "path" => "/some/path"} }
32
- let(:node_module2) { {"licenses" => [{"type" => "BSD"}], "path" => "/some/path"} }
33
- let(:node_module3) { {"license" => {"type" => "PSF"}, "path" => "/some/path"} }
34
- let(:node_module4) { {"licenses" => ["MIT"], "path" => "/some/path"} }
28
+ its(:groups) { should == [] } # TODO: put devDependencies in 'dev' group?
29
+ its(:children) { should == ["coffee-script"] }
30
+ its(:install_path) { should eq "some/node/package/path" }
31
+
32
+ describe '#license_names_from_spec' do
33
+ let(:node_module1) { {"license" => "MIT"} }
34
+ let(:node_module2) { {"licenses" => [{"type" => "BSD"}]} }
35
+ let(:node_module3) { {"license" => {"type" => "PSF"}} }
36
+ let(:node_module4) { {"licenses" => ["MIT"]} }
35
37
  let(:misdeclared_node_module) { {"licenses" => {"type" => "MIT"}} }
36
38
 
37
39
  it 'finds the license for both license structures' do
38
40
  package = NpmPackage.new(node_module1)
39
- expect(package.licenses.length).to eq 1
40
- expect(package.licenses.first.name).to eq("MIT")
41
+ expect(package.license_names_from_spec).to eq ["MIT"]
41
42
 
42
43
  package = NpmPackage.new(node_module2)
43
- expect(package.licenses.length).to eq 1
44
- expect(package.licenses.first.name).to eq("BSD")
44
+ expect(package.license_names_from_spec).to eq ["BSD"]
45
45
 
46
46
  package = NpmPackage.new(node_module3)
47
- expect(package.licenses.length).to eq 1
48
- expect(package.licenses.first.name).to eq("Python Software Foundation License")
47
+ expect(package.license_names_from_spec).to eq ["PSF"]
49
48
 
50
49
  package = NpmPackage.new(node_module4)
51
- expect(package.licenses.length).to eq 1
52
- expect(package.licenses.first.name).to eq("MIT")
50
+ expect(package.license_names_from_spec).to eq ["MIT"]
53
51
 
54
52
  package = NpmPackage.new(misdeclared_node_module)
55
- expect(package.licenses.length).to eq 1
56
- expect(package.licenses.first.name).to eq("MIT")
57
- end
58
-
59
- context "regardless of whether there are licenses in files" do
60
- before do
61
- stub_license_files [double(:file, license: License.find_by_name('Detected License'))]
62
- end
63
-
64
- it "returns the license from the spec if there is only one unique license" do
65
- package = NpmPackage.new({ "licenses" => ["MIT", "Expat"], "path" => "/path/to/thing" })
66
- expect(package.licenses.length).to eq 1
67
- expect(package.licenses.first.name).to eq("MIT")
68
- end
69
-
70
- it "returns 'multiple licenses' if there's more than one license" do
71
- package = NpmPackage.new({ "licenses" => ["MIT", "BSD"], "path" => "/some/path" })
72
- expect(package.licenses.length).to eq 2
73
- expect(package.licenses.map(&:name)).to eq %w(MIT BSD)
74
- end
75
- end
76
-
77
- context "when there is nothing in the spec" do
78
- it "returns a license in a file if only one unique license detected" do
79
- stub_license_files([
80
- double(:first_file, license: License.find_by_name('MIT'), path: "/"),
81
- double(:second_file, license: License.find_by_name('Expat'), path: "/")
82
- ])
83
-
84
- expect(subject.licenses.length).to eq 1
85
- expect(subject.licenses.first.name).to eq "MIT"
86
- end
87
-
88
- it "returns 'other' if there are no licenses in files" do
89
- stub_license_files []
90
-
91
- expect(subject.licenses.length).to eq 1
92
- expect(subject.licenses.first.name).to eq "other"
93
- end
94
-
95
- it "returns 'other' if there are many licenses in files" do
96
- stub_license_files([
97
- double(:first_file, license: License.find_by_name('First Detected License'), path: "/"),
98
- double(:second_file, license: License.find_by_name('Second Detected License'), path: "/")
99
- ])
100
-
101
- expect(subject.licenses.length).to eq 2
102
- expect(subject.licenses.map(&:name)).to eq ["First Detected License", "Second Detected License"]
103
- end
53
+ expect(package.license_names_from_spec).to eq ["MIT"]
104
54
  end
105
55
  end
106
56
  end
107
57
  end
108
-
@@ -17,14 +17,29 @@ module LicenseFinder
17
17
  "version": "1.3.3.7",
18
18
  "description": "description",
19
19
  "readme": "readme",
20
- "path": "/path/to/thing"
20
+ "path": "/path/to/thing",
21
+ "dependencies": {
22
+ "dependency1-1.js": {
23
+ "name": "dep1-1js"
24
+ }
25
+ }
21
26
  },
22
27
  "dependency2.js": {
23
28
  "name": "dep2js",
24
29
  "version": "4.2",
25
30
  "description": "description2",
26
31
  "readme": "readme2",
27
- "path": "/path/to/thing2"
32
+ "path": "/path/to/thing2",
33
+ "dependencies": {
34
+ "dependency2-1.js": {
35
+ "name": "dep2-1js",
36
+ "dependencies": {
37
+ "dependency1-1.js": {
38
+ "name": "dep1-1js"
39
+ }
40
+ }
41
+ }
42
+ }
28
43
  }
29
44
  },
30
45
  "devDependencies": {
@@ -36,24 +51,6 @@ module LicenseFinder
36
51
  "path": "/path/to/thing3"
37
52
  }
38
53
  },
39
- "bundledDependencies": {
40
- "dependency4.js": {
41
- "name": "dep4js",
42
- "version": "4.2",
43
- "description": "description4",
44
- "readme": "readme4",
45
- "path": "/path/to/thing4"
46
- }
47
- },
48
- "bundleDependencies": {
49
- "dependency5.js": {
50
- "name": "dep5js",
51
- "version": "4.2",
52
- "description": "description5",
53
- "readme": "readme5",
54
- "path": "/path/to/thing5"
55
- }
56
- },
57
54
  "notADependency": {
58
55
  "dependency6.js": {
59
56
  "name": "dep6js",
@@ -69,7 +66,7 @@ module LicenseFinder
69
66
 
70
67
  current_packages = npm.current_packages
71
68
 
72
- expect(current_packages.map(&:name)).to eq(["depjs", "dep2js", "dep3js", "dep5js", "dep4js"])
69
+ expect(current_packages.map(&:name)).to eq(["depjs", "dep1-1js", "dep2js", "dep2-1js", "dep3js"])
73
70
  expect(current_packages.first).to be_a(Package)
74
71
  expect(current_packages.first.name).to eq("depjs")
75
72
  end
@@ -2,7 +2,13 @@ require 'spec_helper'
2
2
 
3
3
  module LicenseFinder
4
4
  describe PipPackage do
5
- subject { make_package({}) }
5
+ subject do
6
+ make_package({
7
+ "summary" => "summary",
8
+ "description" => "description",
9
+ "home_page" => "homepage"
10
+ })
11
+ end
6
12
 
7
13
  it_behaves_like "a Package"
8
14
 
@@ -12,52 +18,30 @@ module LicenseFinder
12
18
 
13
19
  its(:name) { should == "jasmine" }
14
20
  its(:version) { should == "1.3.1" }
15
- its(:homepage) { should == nil }
16
- its(:groups) { should == [] }
17
- its(:children) { should == [] }
18
-
19
- describe "#summary" do
20
- it "delegates to pypi def" do
21
- subject = make_package("summary" => "A summary")
22
- expect(subject.summary).to eq("A summary")
23
- end
21
+ its(:summary) { should == "summary" }
22
+ its(:description) { should == "description" }
23
+ its(:homepage) { should == "homepage" }
24
+ its(:groups) { should == [] } # TODO: any way to extract install_requires and tests_require from `pip list` or `pip show`?
25
+ its(:children) { should == [] } # TODO: use pipdeptree or something like it
26
+ its(:install_path) { should eq "jasmine/install/path" }
24
27
 
25
- it "falls back to nothing" do
26
- expect(subject.summary).to eq("")
27
- end
28
- end
29
28
 
30
- describe "#description" do
31
- it "delegates to pypi def" do
32
- subject = make_package("description" => "A description")
33
- expect(subject.description).to eq("A description")
34
- end
29
+ describe '#license_names_from_spec' do
30
+ describe "with no pypi info" do
31
+ it "is empty" do
32
+ subject = make_package({})
35
33
 
36
- it "falls back to nothing" do
37
- expect(subject.description).to eq("")
38
- end
39
- end
40
-
41
- describe "#homepage" do
42
- it "delegates to pypi def" do
43
- subject = make_package("home_page" => "A homepage")
44
- expect(subject.homepage).to eq("A homepage")
34
+ expect(subject.license_names_from_spec).to be_empty
35
+ end
45
36
  end
46
37
 
47
- it "falls back to nothing" do
48
- expect(subject.homepage).to be_nil
49
- end
50
- end
51
-
52
- describe '#licenses' do
53
38
  describe "with valid pypi license" do
54
39
  it "returns the license from 'license' preferentially" do
55
40
  data = { "license" => "MIT", "classifiers" => [ 'License :: OSI Approved :: Apache 2.0 License' ] }
56
41
 
57
42
  subject = make_package(data)
58
43
 
59
- expect(subject.licenses.length).to eq 1
60
- expect(subject.licenses.first.name).to eq('MIT')
44
+ expect(subject.license_names_from_spec).to eq ['MIT']
61
45
  end
62
46
 
63
47
  context "when there's no explicit license" do
@@ -66,51 +50,28 @@ module LicenseFinder
66
50
 
67
51
  subject = make_package(data)
68
52
 
69
- expect(subject.licenses.length).to eq 1
70
- expect(subject.licenses.first.name).to eq('Apache 2.0 License')
53
+ expect(subject.license_names_from_spec).to eq ['Apache 2.0 License']
71
54
  end
72
55
 
73
- it "returns 'multiple licenses' if there are multiple licenses in 'classifiers'" do
56
+ it "returns multiple licenses if there are many in 'classifiers'" do
74
57
  data = { "classifiers" => [ 'License :: OSI Approved :: Apache 2.0 License', 'License :: OSI Approved :: GPL' ] }
75
58
 
76
59
  subject = make_package(data)
77
60
 
78
- expect(subject.licenses.length).to eq 2
79
- expect(subject.licenses.map(&:name)).to eq ['Apache 2.0 License', 'GPL']
61
+ expect(subject.license_names_from_spec).to eq ['Apache 2.0 License', 'GPL']
80
62
  end
81
63
  end
82
64
 
83
-
84
65
  context "with UNKNOWN license" do
85
66
  it "returns the license from the classifier if it exists" do
86
67
  data = { "license" => "UNKNOWN", "classifiers" => [ 'License :: OSI Approved :: Apache 2.0 License' ] }
87
68
 
88
69
  subject = make_package(data)
89
70
 
90
- expect(subject.licenses.length).to eq 1
91
- expect(subject.licenses.first.name).to eq('Apache 2.0 License')
71
+ expect(subject.license_names_from_spec).to eq ['Apache 2.0 License']
92
72
  end
93
73
  end
94
74
  end
95
-
96
-
97
- describe "without pypi license" do
98
- def stub_license_files(license_files)
99
- allow(PossibleLicenseFiles).to receive(:find).with("jasmine/install/path").and_return(license_files)
100
- end
101
-
102
- it 'returns license from file' do
103
- stub_license_files [double(:license_file, license: License.find_by_name('License from file'), path: "/")]
104
- expect(subject.licenses.length).to eq 1
105
- expect(subject.licenses.first.name).to eq('License from file')
106
- end
107
-
108
- it 'returns other if no license can be found' do
109
- stub_license_files []
110
- expect(subject.licenses.length).to eq 1
111
- expect(subject.licenses.first.name).to eq('other')
112
- end
113
- end
114
75
  end
115
76
  end
116
77
  end