license_finder 2.0.4 → 2.1.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +6 -4
  3. data/.travis/install_godep.sh +6 -0
  4. data/.travis/install_gradle.sh +1 -1
  5. data/.travis/install_rebar.sh +7 -5
  6. data/CHANGELOG.rdoc +13 -0
  7. data/CONTRIBUTING.md +16 -2
  8. data/README.md +41 -4
  9. data/Rakefile +8 -2
  10. data/features/features/{cli_spec.rb → cli/cli_spec.rb} +24 -18
  11. data/features/features/configure/add_dependencies_spec.rb +18 -1
  12. data/features/features/configure/approve_dependencies_spec.rb +31 -1
  13. data/features/features/configure/assign_licenses_spec.rb +18 -3
  14. data/features/features/configure/blacklist_licenses_spec.rb +30 -0
  15. data/features/features/configure/ignore_dependencies_spec.rb +1 -1
  16. data/features/features/configure/ignore_groups_spec.rb +16 -1
  17. data/features/features/configure/name_project_spec.rb +1 -1
  18. data/features/features/configure/set_project_path_spec.rb +1 -1
  19. data/features/features/configure/whitelist_licenses_spec.rb +1 -3
  20. data/features/features/package_managers/bower_spec.rb +1 -1
  21. data/features/features/package_managers/cocoapods_spec.rb +1 -1
  22. data/features/features/package_managers/godep_spec.rb +17 -0
  23. data/features/features/package_managers/gradle_spec.rb +18 -4
  24. data/features/features/package_managers/maven_spec.rb +1 -1
  25. data/features/features/package_managers/npm_spec.rb +1 -1
  26. data/features/features/package_managers/nuget_spec.rb +14 -0
  27. data/features/features/package_managers/pip_spec.rb +1 -1
  28. data/features/features/package_managers/rebar_spec.rb +1 -1
  29. data/features/features/report/composite_spec.rb +15 -0
  30. data/features/features/report/csv_spec.rb +1 -1
  31. data/features/features/report/diff_spec.rb +190 -0
  32. data/features/features/report/html_spec.rb +1 -1
  33. data/features/features/report/subproject_spec.rb +52 -0
  34. data/features/fixtures/file-based-libs-gradle/build.gradle +18 -0
  35. data/features/fixtures/file-based-libs-gradle/libs/data.json-0.2.3.jar +0 -0
  36. data/features/fixtures/gopath/src/github.com/pivotal/foo/Godeps/Godeps.json +16 -0
  37. data/features/fixtures/gopath/src/github.com/pivotal/foo/Godeps/Readme +5 -0
  38. data/features/fixtures/gopath/src/github.com/pivotal/foo/foo.go +6 -0
  39. data/features/fixtures/multi-module-gradle/build.gradle +18 -0
  40. data/features/fixtures/multi-module-gradle/module1/build.gradle +3 -0
  41. data/features/fixtures/multi-module-gradle/module2/build.gradle +3 -0
  42. data/features/fixtures/multi-module-gradle/settings.gradle +1 -0
  43. data/features/fixtures/nuget/Fun.Test/packages.config +4 -0
  44. data/features/fixtures/nuget/Fun/packages.config +5 -0
  45. data/features/fixtures/nuget/packages/Microsoft.AspNet.Mvc.4.0.30506.0/.keep +0 -0
  46. data/features/fixtures/nuget/packages/NUnit.2.6.4/.keep +0 -0
  47. data/features/fixtures/nuget/packages/Ninject.MVC4.3.2.1.0/.keep +0 -0
  48. data/features/fixtures/nuget/packages/repositories.config +6 -0
  49. data/features/fixtures/{build.gradle → single-module-gradle/build.gradle} +0 -0
  50. data/{spec → features/support}/feature_helper.rb +5 -1
  51. data/features/support/testing_dsl.rb +297 -212
  52. data/lib/license_finder/cli.rb +1 -0
  53. data/lib/license_finder/cli/base.rb +16 -3
  54. data/lib/license_finder/cli/blacklist.rb +30 -0
  55. data/lib/license_finder/cli/main.rb +62 -4
  56. data/lib/license_finder/configuration.rb +39 -8
  57. data/lib/license_finder/core.rb +13 -10
  58. data/lib/license_finder/decision_applier.rb +14 -9
  59. data/lib/license_finder/decisions.rb +24 -6
  60. data/lib/license_finder/diff.rb +47 -0
  61. data/lib/license_finder/license_aggregator.rb +25 -0
  62. data/lib/license_finder/package.rb +39 -6
  63. data/lib/license_finder/package_delta.rb +65 -0
  64. data/lib/license_finder/package_manager.rb +10 -3
  65. data/lib/license_finder/package_managers/bower.rb +3 -1
  66. data/lib/license_finder/package_managers/bundler.rb +18 -9
  67. data/lib/license_finder/package_managers/bundler_package.rb +6 -2
  68. data/lib/license_finder/package_managers/go_dep.rb +25 -0
  69. data/lib/license_finder/package_managers/go_package.rb +19 -0
  70. data/lib/license_finder/package_managers/go_workspace.rb +35 -0
  71. data/lib/license_finder/package_managers/gradle.rb +16 -17
  72. data/lib/license_finder/package_managers/gradle_dependency_finder.rb +13 -0
  73. data/lib/license_finder/package_managers/gradle_package.rb +6 -1
  74. data/lib/license_finder/package_managers/maven.rb +3 -1
  75. data/lib/license_finder/package_managers/merged_package.rb +43 -0
  76. data/lib/license_finder/package_managers/npm.rb +42 -24
  77. data/lib/license_finder/package_managers/nuget.rb +50 -0
  78. data/lib/license_finder/package_managers/nuget_package.rb +4 -0
  79. data/lib/license_finder/package_managers/pip_package.rb +1 -0
  80. data/lib/license_finder/package_managers/rebar.rb +2 -6
  81. data/lib/license_finder/platform.rb +4 -1
  82. data/lib/license_finder/project_finder.rb +56 -0
  83. data/lib/license_finder/report.rb +3 -2
  84. data/lib/license_finder/reports/csv_report.rb +6 -2
  85. data/lib/license_finder/reports/diff_report.rb +33 -0
  86. data/lib/license_finder/reports/merged_report.rb +13 -0
  87. data/lib/license_finder/version.rb +1 -1
  88. data/license_finder.gemspec +6 -2
  89. data/spec/dummy_app/Gemfile +6 -0
  90. data/spec/fixtures/all_pms/.envrc +0 -0
  91. data/spec/fixtures/all_pms/Godeps/Godeps.json +0 -0
  92. data/spec/fixtures/all_pms/packages/.keep +0 -0
  93. data/spec/fixtures/composite/Gemfile +0 -0
  94. data/spec/fixtures/composite/nested_project/.envrc +8 -0
  95. data/spec/fixtures/composite/nested_project/src/github.com/pivotal/foo/Godeps/Godeps.json +16 -0
  96. data/spec/fixtures/composite/nested_project/src/github.com/pivotal/foo/Godeps/Readme +5 -0
  97. data/spec/fixtures/composite/nested_project/src/github.com/pivotal/foo/foo.go +6 -0
  98. data/spec/fixtures/composite/not_a_project/DONTREADME.md +0 -0
  99. data/spec/fixtures/composite/project1/Gemfile +0 -0
  100. data/spec/fixtures/composite/project2/package.json +0 -0
  101. data/spec/lib/license_finder/cli/approvals_spec.rb +1 -1
  102. data/spec/lib/license_finder/cli/blacklist_spec.rb +58 -0
  103. data/spec/lib/license_finder/cli/dependencies_spec.rb +1 -1
  104. data/spec/lib/license_finder/cli/ignored_dependencies_spec.rb +1 -1
  105. data/spec/lib/license_finder/cli/ignored_groups_spec.rb +1 -1
  106. data/spec/lib/license_finder/cli/licenses_spec.rb +1 -1
  107. data/spec/lib/license_finder/cli/main_spec.rb +113 -7
  108. data/spec/lib/license_finder/cli/project_name_spec.rb +1 -1
  109. data/spec/lib/license_finder/cli/whitelist_spec.rb +1 -1
  110. data/spec/lib/license_finder/configuration_spec.rb +63 -4
  111. data/spec/lib/license_finder/core_spec.rb +49 -0
  112. data/spec/lib/license_finder/decision_applier_spec.rb +101 -1
  113. data/spec/lib/license_finder/decisions_spec.rb +62 -0
  114. data/spec/lib/license_finder/diff_spec.rb +106 -0
  115. data/spec/lib/license_finder/license_aggregator_spec.rb +61 -0
  116. data/spec/lib/license_finder/package_delta_spec.rb +18 -0
  117. data/spec/lib/license_finder/package_managers/bower_spec.rb +8 -6
  118. data/spec/lib/license_finder/package_managers/bundler_package_spec.rb +4 -2
  119. data/spec/lib/license_finder/package_managers/go_dep_spec.rb +72 -0
  120. data/spec/lib/license_finder/package_managers/go_workspace_spec.rb +69 -0
  121. data/spec/lib/license_finder/package_managers/gradle_package_spec.rb +9 -0
  122. data/spec/lib/license_finder/package_managers/gradle_spec.rb +94 -44
  123. data/spec/lib/license_finder/package_managers/maven_spec.rb +8 -6
  124. data/spec/lib/license_finder/package_managers/merged_package_spec.rb +52 -0
  125. data/spec/lib/license_finder/package_managers/npm_spec.rb +59 -20
  126. data/spec/lib/license_finder/package_managers/nuget_spec.rb +82 -0
  127. data/spec/lib/license_finder/package_managers/pip_package_spec.rb +1 -0
  128. data/spec/lib/license_finder/package_managers/rebar_spec.rb +12 -12
  129. data/spec/lib/license_finder/package_spec.rb +59 -2
  130. data/spec/lib/license_finder/project_finder_spec.rb +33 -0
  131. data/spec/lib/license_finder/reports/csv_report_spec.rb +9 -3
  132. data/spec/lib/license_finder/reports/diff_report_spec.rb +56 -0
  133. data/spec/lib/license_finder/reports/merged_report_spec.rb +21 -0
  134. metadata +82 -9
  135. data/.travis/install_virtualenv.sh +0 -9
@@ -8,6 +8,7 @@ module LicenseFinder
8
8
  Gem::Specification.new do |s|
9
9
  s.name = 'spec_name'
10
10
  s.version = '2.1.3'
11
+ s.authors = ['first', 'second']
11
12
  s.summary = 'summary'
12
13
  s.description = 'description'
13
14
  s.homepage = 'homepage'
@@ -17,14 +18,15 @@ module LicenseFinder
17
18
  end
18
19
  end
19
20
 
20
- let(:bundler_dependency) { double(:dependency, groups: [1, 2, 3]) }
21
+ let(:bundler_dependency) { double(:dependency, groups: [:staging, :assets]) }
21
22
 
22
23
  its(:name) { should == 'spec_name' }
23
24
  its(:version) { should == '2.1.3' }
25
+ its(:authors) { should == 'first, second' }
24
26
  its(:summary) { should == "summary" }
25
27
  its(:description) { should == "description" }
26
28
  its(:homepage) { should == "homepage" }
27
- its(:groups) { should == [1, 2, 3] }
29
+ its(:groups) { should == %w[staging assets] }
28
30
  its(:children) { should == ['foo'] }
29
31
  its(:license_names_from_spec) { should eq ['MIT', 'GPL'] }
30
32
  its(:install_path) { should =~ /spec_name-2\.1\.3\z/ }
@@ -0,0 +1,72 @@
1
+ require 'spec_helper'
2
+
3
+ module LicenseFinder
4
+ describe GoDep do
5
+ subject { GoDep.new(project_path: Pathname('/fake/path')) }
6
+
7
+ it_behaves_like 'a PackageManager'
8
+
9
+ describe '#current_packages' do
10
+ let(:content) do
11
+ '{
12
+ "ImportPath": "github.com/pivotal/foo",
13
+ "GoVersion": "go1.4.2",
14
+ "Deps": [
15
+ {
16
+ "ImportPath": "github.com/pivotal/foo",
17
+ "Rev": "61164e49940b423ba1f12ddbdf01632ac793e5e9"
18
+ },
19
+ {
20
+ "ImportPath": "github.com/pivotal/bar",
21
+ "Rev": "3245708abcdef234589450649872346783298736"
22
+ }
23
+ ]
24
+ }'
25
+ end
26
+
27
+ before do
28
+ allow(IO).to receive(:read).with('/fake/path/Godeps/Godeps.json').and_return(content.to_s)
29
+ end
30
+
31
+ context 'when dependencies are vendored' do
32
+ before do
33
+ allow(FileTest).to receive(:exist?).with('/fake/path/Godeps/_workspace').and_return(true)
34
+ end
35
+
36
+ it 'should return an array of packages' do
37
+ packages = subject.current_packages
38
+ expect(packages.map(&:name)).to include('github.com/pivotal/foo', 'github.com/pivotal/bar')
39
+ expect(packages.map(&:version)).to include('61164e4', '3245708')
40
+ end
41
+
42
+ it 'should set the install_path to the vendored directory' do
43
+ packages = subject.current_packages
44
+ expect(packages[0].install_path).to eq('/fake/path/Godeps/_workspace/src/github.com/pivotal/foo')
45
+ expect(packages[1].install_path).to eq('/fake/path/Godeps/_workspace/src/github.com/pivotal/bar')
46
+ end
47
+ end
48
+
49
+ context 'when dependencies are not vendored' do
50
+ before do
51
+ ENV['GOPATH'] = '/fake/go/path'
52
+ end
53
+
54
+ after do
55
+ ENV['GOPATH'] = nil
56
+ end
57
+
58
+ it 'should return an array of packages' do
59
+ packages = subject.current_packages
60
+ expect(packages.map(&:name)).to include('github.com/pivotal/foo', 'github.com/pivotal/bar')
61
+ expect(packages.map(&:version)).to include('61164e4', '3245708')
62
+ end
63
+
64
+ it 'should set the install_path to the GOPATH' do
65
+ packages = subject.current_packages
66
+ expect(packages[0].install_path).to eq('/fake/go/path/src/github.com/pivotal/foo')
67
+ expect(packages[1].install_path).to eq('/fake/go/path/src/github.com/pivotal/bar')
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ module LicenseFinder
4
+ describe GoWorkspace do
5
+ let(:logger) { double(:logger, active: nil) }
6
+ subject { GoWorkspace.new(project_path: Pathname('/Users/pivotal/workspace/loggregator'), logger: logger) }
7
+
8
+ describe '#current_packages' do
9
+ let(:content) {
10
+ '_/Users/pivotal/workspace/loggregator/src/bitbucket.org/kardianos/osext
11
+ _/Users/pivotal/workspace/loggregator/src/deaagent
12
+ _/Users/pivotal/workspace/loggregator/src/deaagent/deaagent
13
+ _/Users/pivotal/workspace/loggregator/src/deaagent/domain
14
+ _/Users/pivotal/workspace/loggregator/src/doppler
15
+ _/Users/pivotal/workspace/loggregator/src/doppler/config
16
+ _/Users/pivotal/workspace/loggregator/src/doppler/groupedsinks
17
+ _/Users/pivotal/workspace/loggregator/src/doppler/groupedsinks/firehose_group
18
+ _/Users/pivotal/workspace/loggregator/src/doppler/groupedsinks/sink_wrapper'
19
+ }
20
+
21
+ before do
22
+ allow(Dir).to receive(:chdir).with(Pathname('/Users/pivotal/workspace/loggregator')) { |&block| block.call }
23
+ allow(subject).to receive(:capture).with('go list -f "{{.ImportPath}} " ./...').and_return([content.to_s, true])
24
+ end
25
+
26
+ describe 'should return an array of go packages' do
27
+ it 'provides package names' do
28
+ packages = subject.current_packages
29
+ first_package = packages.first
30
+ expect(first_package.name).to eq 'bitbucket.org/kardianos/osext'
31
+ expect(first_package.version).to eq 'unknown'
32
+ expect(first_package.install_path).to eq '/Users/pivotal/workspace/loggregator/src/bitbucket.org/kardianos/osext'
33
+ end
34
+ end
35
+ end
36
+
37
+ describe '#package_path' do
38
+ it 'returns the package_path' do
39
+ expect(subject.package_path).to eq Pathname('/Users/pivotal/workspace/loggregator/.envrc')
40
+ end
41
+ end
42
+
43
+ describe '#active?' do
44
+ let(:envrc) { '/Users/pivotal/workspace/loggregator/.envrc' }
45
+
46
+ it 'returns true when .envrc contains GOPATH' do
47
+ allow(FileTest).to receive(:exist?).with(envrc).and_return(true)
48
+ allow(IO).to receive(:read).with(Pathname(envrc)).and_return('export GOPATH=/foo/bar')
49
+ expect(subject.active?).to eq(true)
50
+ end
51
+
52
+ it 'returns false when .envrc does not contain GOPATH' do
53
+ allow(FileTest).to receive(:exist?).with(envrc).and_return(true)
54
+ allow(IO).to receive(:read).with(Pathname(envrc)).and_return('this is not an envrc file')
55
+ expect(subject.active?).to eq(false)
56
+ end
57
+
58
+ it 'returns false when .envrc does not exist' do
59
+ allow(FileTest).to receive(:exist?).with(envrc).and_return(false)
60
+ expect(subject.active?).to eq(false)
61
+ end
62
+
63
+ it 'logs the active state' do
64
+ expect(logger).to receive(:active)
65
+ subject.active?
66
+ end
67
+ end
68
+ end
69
+ end
@@ -11,6 +11,7 @@ module LicenseFinder
11
11
 
12
12
  its(:name) { should == "logback-classic" }
13
13
  its(:version) { should == "1.1.1" }
14
+ its(:authors) { should == "" }
14
15
  its(:summary) { should == "" }
15
16
  its(:description) { should == "" }
16
17
  its(:homepage) { should == "" }
@@ -18,6 +19,14 @@ module LicenseFinder
18
19
  its(:children) { should == [] } # no way to get children from gradle?
19
20
  its(:install_path) { should be_nil }
20
21
 
22
+ describe "when file name has a funny format, possibly because it is a jar saved in the project" do
23
+ it "uses a reasonable name and default version" do
24
+ subject = described_class.new("name" => "data.json-0.2.3.jar")
25
+ expect(subject.name).to eq "data.json-0.2.3.jar"
26
+ expect(subject.version).to eq "unknown"
27
+ end
28
+ end
29
+
21
30
  describe "#license_names_from_spec" do
22
31
  it "returns the license" do
23
32
  expect(subject.license_names_from_spec).to eq ["MIT"]
@@ -2,64 +2,114 @@ require 'spec_helper'
2
2
 
3
3
  module LicenseFinder
4
4
  describe Gradle do
5
- let(:gradle) { Gradle.new }
6
- it_behaves_like "a PackageManager"
5
+ subject { Gradle.new(project_path: Pathname('/fake/path')) }
6
+
7
+ let(:content) { [] }
7
8
 
8
- def license_xml(xml)
9
- <<-resp
10
- <dependencies>
11
- #{xml}
12
- </dependencies>
13
- resp
14
- end
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
9
+ it_behaves_like 'a PackageManager'
21
10
 
22
- describe '.current_packages' do
11
+ describe '#current_packages' do
23
12
  before do
24
- allow(gradle).to receive('`').with(/gradle downloadLicenses/)
13
+ allow(Dir).to receive(:chdir).with(Pathname('/fake/path')).and_return(['', true])
14
+ dependencies = double(:subject_dependency_file, dependencies: content)
15
+ expect(GradleDependencyFinder).to receive(:new).and_return(dependencies)
16
+ end
17
+
18
+ it 'uses custom subject command, if provided' do
19
+ subject = Gradle.new(gradle_command: 'subjectfoo', project_path: Pathname('/fake/path'))
20
+ expect(Dir).to receive(:chdir).with(Pathname('/fake/path')) { |&block| block.call }
21
+ expect(subject).to receive(:capture).with('subjectfoo downloadLicenses').and_return(['', true])
22
+ subject.current_packages
25
23
  end
26
24
 
27
- it "uses custom gradle command, if provided" do
28
- gradle = Gradle.new(gradle_command: "gradlefoo")
29
- stub_license_report("", gradle)
30
- expect(gradle).to receive('`').with(/gradlefoo downloadLicenses/)
31
- gradle.current_packages
25
+ it 'sets the working directory to project_path, if provided' do
26
+ subject = Gradle.new(project_path: Pathname('/Users/foo/bar'))
27
+ expect(Dir).to receive(:chdir).with(Pathname('/Users/foo/bar')) { |&block| block.call }
28
+ expect(subject).to receive(:capture).with('gradle downloadLicenses').and_return(['', true])
29
+ subject.current_packages
32
30
  end
33
31
 
34
- it 'lists all the current packages' do
35
- stub_license_report("
36
- <dependency name='org.springframework:spring-aop:4.0.1.RELEASE'>
37
- </dependency>
38
- <dependency name='org.springframework:spring-core:4.0.1.RELEASE'>
39
- </dependency>
40
- ")
32
+ context 'when dependencies are found' do
33
+ let(:content) do
34
+ [
35
+ "<dependencies>
36
+ <dependency name='org.springframework:spring-aop:4.0.1.RELEASE'></dependency>
37
+ <dependency name='org.springframework:spring-core:4.0.1.RELEASE'></dependency>
38
+ </dependencies>"
39
+ ]
40
+ end
41
41
 
42
- expect(gradle.current_packages.map(&:name)).to eq ['spring-aop', 'spring-core']
42
+ it 'lists all dependencies' do
43
+ expect(subject.current_packages.map(&:name)).to eq ['spring-aop', 'spring-core']
44
+ end
43
45
  end
44
46
 
45
- it "handles multiple licenses" do
46
- stub_license_report("
47
- <dependency name=''>
48
- <license name='License 1'/>
49
- <license name='License 2'/>
50
- </dependency>
51
- ")
47
+ context 'when multiple licenses exist' do
48
+ let(:content) do
49
+ [
50
+ "<dependencies>
51
+ <dependency name=''>
52
+ <license name='License 1'/>
53
+ <license name='License 2'/>
54
+ </dependency>
55
+ </dependencies>"
56
+ ]
57
+ end
52
58
 
53
- expect(gradle.current_packages.first.licenses.map(&:name)).to eq ["License 1", "License 2"]
59
+ it 'lists all dependencies' do
60
+ expect(subject.current_packages.first.licenses.map(&:name)).to eq ['License 1', 'License 2']
61
+ end
54
62
  end
55
63
 
56
- it "handles an empty list of licenses" do
57
- stub_license_report("
58
- <dependency name=''>
59
- </dependency>
60
- ")
64
+ context 'when no licenses exist' do
65
+ let(:content) do
66
+ [
67
+ "<dependencies>
68
+ <dependency name=''></dependency>
69
+ </dependencies>"
70
+ ]
71
+ end
72
+
73
+ it 'returns unknown' do
74
+ expect(subject.current_packages.first.licenses.map(&:name)).to eq ['unknown']
75
+ end
76
+ end
77
+
78
+ context 'when multiple license files exist' do
79
+ let(:content) do
80
+ [
81
+ "<dependencies>
82
+ <dependency name='junit:junit:4.12'></dependency>
83
+ </dependencies>",
84
+ "<dependencies>
85
+ <dependency name='org.mockito:mockito-core:1.9.5'></dependency>
86
+ </dependencies>"
87
+ ]
88
+ end
89
+
90
+ it 'lists all dependencies' do
91
+ expect(subject.current_packages.map(&:name)).to eq ['junit', 'mockito-core']
92
+ end
93
+
94
+ context 'and there are duplicate dependencies' do
95
+ let(:content) do
96
+ [
97
+ "<dependencies>
98
+ <dependency name='junit:junit:4.12'></dependency>
99
+ </dependencies>",
100
+ "<dependencies>
101
+ <dependency name='org.mockito:mockito-core:1.9.5'></dependency>
102
+ </dependencies>",
103
+ "<dependencies>
104
+ <dependency name='org.mockito:mockito-core:1.9.5'></dependency>
105
+ </dependencies>"
106
+ ]
107
+ end
61
108
 
62
- expect(gradle.current_packages.first.licenses.map(&:name)).to eq ['unknown']
109
+ it 'removes duplicates' do
110
+ expect(subject.current_packages.map(&:name)).to eq ['junit', 'mockito-core']
111
+ end
112
+ end
63
113
  end
64
114
  end
65
115
  end
@@ -2,7 +2,8 @@ require 'spec_helper'
2
2
 
3
3
  module LicenseFinder
4
4
  describe Maven do
5
- let(:maven) { Maven.new }
5
+ subject { Maven.new(project_path: Pathname('/fake/path')) }
6
+
6
7
  it_behaves_like "a PackageManager"
7
8
 
8
9
  def license_xml(xml)
@@ -18,12 +19,13 @@ module LicenseFinder
18
19
 
19
20
  describe '.current_packages' do
20
21
  before do
21
- allow(maven).to receive('`').with(/mvn/)
22
+ allow(Dir).to receive(:chdir).with(Pathname('/fake/path')) { |&block| block.call }
23
+ allow(subject).to receive(:capture).with('mvn license:download-licenses').and_return(['', true])
22
24
  end
23
25
 
24
26
  def stub_license_report(deps)
25
27
  fake_file = double(:license_report, read: license_xml(deps))
26
- allow(maven).to receive(:license_report).and_return(fake_file)
28
+ allow(subject).to receive(:license_report).and_return(fake_file)
27
29
  end
28
30
 
29
31
  it 'lists all the current packages' do
@@ -38,7 +40,7 @@ module LicenseFinder
38
40
  </dependency>
39
41
  ")
40
42
 
41
- expect(maven.current_packages.map { |p| [p.name, p.version] }).to eq [
43
+ expect(subject.current_packages.map { |p| [p.name, p.version] }).to eq [
42
44
  ["junit", "4.11"],
43
45
  ["hamcrest-core", "1.3"]
44
46
  ]
@@ -58,7 +60,7 @@ module LicenseFinder
58
60
  </dependency>
59
61
  ")
60
62
 
61
- expect(maven.current_packages.first.licenses.map(&:name)).to eq ['License 1', 'License 2']
63
+ expect(subject.current_packages.first.licenses.map(&:name)).to eq ['License 1', 'License 2']
62
64
  end
63
65
 
64
66
  it "handles no licenses" do
@@ -67,7 +69,7 @@ module LicenseFinder
67
69
  </dependency>
68
70
  ")
69
71
 
70
- expect(maven.current_packages.first.licenses.map(&:name)).to eq ['unknown']
72
+ expect(subject.current_packages.first.licenses.map(&:name)).to eq ['unknown']
71
73
  end
72
74
  end
73
75
  end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ module LicenseFinder
4
+ describe MergedPackage do
5
+ let(:package) { Package.new('foo', '1.0.0', spec_licenses: ['MIT']) }
6
+ let(:subproject_paths) { 'path/to/project/with/foo' }
7
+
8
+ subject { MergedPackage.new(package, [subproject_paths]) }
9
+
10
+ it 'returns the package name' do
11
+ expect(subject.name).to eq(package.name)
12
+ end
13
+
14
+ it 'returns the package version' do
15
+ expect(subject.version).to eq(package.version)
16
+ end
17
+
18
+ it 'returns the package licenses' do
19
+ expect(subject.licenses).to eq(package.licenses)
20
+ end
21
+
22
+ it 'returns the project path' do
23
+ expect(subject.subproject_paths.length).to eq(1)
24
+ expect(subject.subproject_paths[0]).to end_with(subproject_paths)
25
+ end
26
+
27
+ describe '#eql?' do
28
+ it 'returns true when the package names are equal' do
29
+ p1 = MergedPackage.new(Package.new('foo', '1.0.0'), ['/path/to/package1'])
30
+ p2 = MergedPackage.new(Package.new('foo', '2.0.0'), ['/path/to/package2'])
31
+ p3 = MergedPackage.new(Package.new('bar', '1.0.0'), ['/path/to/package3'])
32
+ expect(p1.eql?(p2)).to eq(true)
33
+ expect(p1.eql?(p3)).not_to eq(true)
34
+ end
35
+
36
+ it 'can handle merged packages that contain other merged packages' do
37
+ p1 = MergedPackage.new(Package.new('foo', '1.0.0'), ['/path/to/package1'])
38
+ p2 = MergedPackage.new(Package.new('foo', '2.0.0'), ['/path/to/package2'])
39
+ p3 = MergedPackage.new(p2, ['/path/to/package3', '/path/to/package2'])
40
+ expect(p1.eql?(p3)).to eq(true)
41
+ end
42
+ end
43
+
44
+ describe 'hash' do
45
+ it 'returns equal hash codes for packages that are equal' do
46
+ p1 = MergedPackage.new(Package.new('foo', '1.0.0'), ['/path/to/package1'])
47
+ p2 = MergedPackage.new(Package.new('foo', '2.0.0'), ['/path/to/package2'])
48
+ expect(p1.hash).to eq(p2.hash)
49
+ end
50
+ end
51
+ end
52
+ end