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.
- checksums.yaml +4 -4
- data/.travis.yml +6 -4
- data/.travis/install_godep.sh +6 -0
- data/.travis/install_gradle.sh +1 -1
- data/.travis/install_rebar.sh +7 -5
- data/CHANGELOG.rdoc +13 -0
- data/CONTRIBUTING.md +16 -2
- data/README.md +41 -4
- data/Rakefile +8 -2
- data/features/features/{cli_spec.rb → cli/cli_spec.rb} +24 -18
- data/features/features/configure/add_dependencies_spec.rb +18 -1
- data/features/features/configure/approve_dependencies_spec.rb +31 -1
- data/features/features/configure/assign_licenses_spec.rb +18 -3
- data/features/features/configure/blacklist_licenses_spec.rb +30 -0
- data/features/features/configure/ignore_dependencies_spec.rb +1 -1
- data/features/features/configure/ignore_groups_spec.rb +16 -1
- data/features/features/configure/name_project_spec.rb +1 -1
- data/features/features/configure/set_project_path_spec.rb +1 -1
- data/features/features/configure/whitelist_licenses_spec.rb +1 -3
- data/features/features/package_managers/bower_spec.rb +1 -1
- data/features/features/package_managers/cocoapods_spec.rb +1 -1
- data/features/features/package_managers/godep_spec.rb +17 -0
- data/features/features/package_managers/gradle_spec.rb +18 -4
- data/features/features/package_managers/maven_spec.rb +1 -1
- data/features/features/package_managers/npm_spec.rb +1 -1
- data/features/features/package_managers/nuget_spec.rb +14 -0
- data/features/features/package_managers/pip_spec.rb +1 -1
- data/features/features/package_managers/rebar_spec.rb +1 -1
- data/features/features/report/composite_spec.rb +15 -0
- data/features/features/report/csv_spec.rb +1 -1
- data/features/features/report/diff_spec.rb +190 -0
- data/features/features/report/html_spec.rb +1 -1
- data/features/features/report/subproject_spec.rb +52 -0
- data/features/fixtures/file-based-libs-gradle/build.gradle +18 -0
- data/features/fixtures/file-based-libs-gradle/libs/data.json-0.2.3.jar +0 -0
- data/features/fixtures/gopath/src/github.com/pivotal/foo/Godeps/Godeps.json +16 -0
- data/features/fixtures/gopath/src/github.com/pivotal/foo/Godeps/Readme +5 -0
- data/features/fixtures/gopath/src/github.com/pivotal/foo/foo.go +6 -0
- data/features/fixtures/multi-module-gradle/build.gradle +18 -0
- data/features/fixtures/multi-module-gradle/module1/build.gradle +3 -0
- data/features/fixtures/multi-module-gradle/module2/build.gradle +3 -0
- data/features/fixtures/multi-module-gradle/settings.gradle +1 -0
- data/features/fixtures/nuget/Fun.Test/packages.config +4 -0
- data/features/fixtures/nuget/Fun/packages.config +5 -0
- data/features/fixtures/nuget/packages/Microsoft.AspNet.Mvc.4.0.30506.0/.keep +0 -0
- data/features/fixtures/nuget/packages/NUnit.2.6.4/.keep +0 -0
- data/features/fixtures/nuget/packages/Ninject.MVC4.3.2.1.0/.keep +0 -0
- data/features/fixtures/nuget/packages/repositories.config +6 -0
- data/features/fixtures/{build.gradle → single-module-gradle/build.gradle} +0 -0
- data/{spec → features/support}/feature_helper.rb +5 -1
- data/features/support/testing_dsl.rb +297 -212
- data/lib/license_finder/cli.rb +1 -0
- data/lib/license_finder/cli/base.rb +16 -3
- data/lib/license_finder/cli/blacklist.rb +30 -0
- data/lib/license_finder/cli/main.rb +62 -4
- data/lib/license_finder/configuration.rb +39 -8
- data/lib/license_finder/core.rb +13 -10
- data/lib/license_finder/decision_applier.rb +14 -9
- data/lib/license_finder/decisions.rb +24 -6
- data/lib/license_finder/diff.rb +47 -0
- data/lib/license_finder/license_aggregator.rb +25 -0
- data/lib/license_finder/package.rb +39 -6
- data/lib/license_finder/package_delta.rb +65 -0
- data/lib/license_finder/package_manager.rb +10 -3
- data/lib/license_finder/package_managers/bower.rb +3 -1
- data/lib/license_finder/package_managers/bundler.rb +18 -9
- data/lib/license_finder/package_managers/bundler_package.rb +6 -2
- data/lib/license_finder/package_managers/go_dep.rb +25 -0
- data/lib/license_finder/package_managers/go_package.rb +19 -0
- data/lib/license_finder/package_managers/go_workspace.rb +35 -0
- data/lib/license_finder/package_managers/gradle.rb +16 -17
- data/lib/license_finder/package_managers/gradle_dependency_finder.rb +13 -0
- data/lib/license_finder/package_managers/gradle_package.rb +6 -1
- data/lib/license_finder/package_managers/maven.rb +3 -1
- data/lib/license_finder/package_managers/merged_package.rb +43 -0
- data/lib/license_finder/package_managers/npm.rb +42 -24
- data/lib/license_finder/package_managers/nuget.rb +50 -0
- data/lib/license_finder/package_managers/nuget_package.rb +4 -0
- data/lib/license_finder/package_managers/pip_package.rb +1 -0
- data/lib/license_finder/package_managers/rebar.rb +2 -6
- data/lib/license_finder/platform.rb +4 -1
- data/lib/license_finder/project_finder.rb +56 -0
- data/lib/license_finder/report.rb +3 -2
- data/lib/license_finder/reports/csv_report.rb +6 -2
- data/lib/license_finder/reports/diff_report.rb +33 -0
- data/lib/license_finder/reports/merged_report.rb +13 -0
- data/lib/license_finder/version.rb +1 -1
- data/license_finder.gemspec +6 -2
- data/spec/dummy_app/Gemfile +6 -0
- data/spec/fixtures/all_pms/.envrc +0 -0
- data/spec/fixtures/all_pms/Godeps/Godeps.json +0 -0
- data/spec/fixtures/all_pms/packages/.keep +0 -0
- data/spec/fixtures/composite/Gemfile +0 -0
- data/spec/fixtures/composite/nested_project/.envrc +8 -0
- data/spec/fixtures/composite/nested_project/src/github.com/pivotal/foo/Godeps/Godeps.json +16 -0
- data/spec/fixtures/composite/nested_project/src/github.com/pivotal/foo/Godeps/Readme +5 -0
- data/spec/fixtures/composite/nested_project/src/github.com/pivotal/foo/foo.go +6 -0
- data/spec/fixtures/composite/not_a_project/DONTREADME.md +0 -0
- data/spec/fixtures/composite/project1/Gemfile +0 -0
- data/spec/fixtures/composite/project2/package.json +0 -0
- data/spec/lib/license_finder/cli/approvals_spec.rb +1 -1
- data/spec/lib/license_finder/cli/blacklist_spec.rb +58 -0
- data/spec/lib/license_finder/cli/dependencies_spec.rb +1 -1
- data/spec/lib/license_finder/cli/ignored_dependencies_spec.rb +1 -1
- data/spec/lib/license_finder/cli/ignored_groups_spec.rb +1 -1
- data/spec/lib/license_finder/cli/licenses_spec.rb +1 -1
- data/spec/lib/license_finder/cli/main_spec.rb +113 -7
- data/spec/lib/license_finder/cli/project_name_spec.rb +1 -1
- data/spec/lib/license_finder/cli/whitelist_spec.rb +1 -1
- data/spec/lib/license_finder/configuration_spec.rb +63 -4
- data/spec/lib/license_finder/core_spec.rb +49 -0
- data/spec/lib/license_finder/decision_applier_spec.rb +101 -1
- data/spec/lib/license_finder/decisions_spec.rb +62 -0
- data/spec/lib/license_finder/diff_spec.rb +106 -0
- data/spec/lib/license_finder/license_aggregator_spec.rb +61 -0
- data/spec/lib/license_finder/package_delta_spec.rb +18 -0
- data/spec/lib/license_finder/package_managers/bower_spec.rb +8 -6
- data/spec/lib/license_finder/package_managers/bundler_package_spec.rb +4 -2
- data/spec/lib/license_finder/package_managers/go_dep_spec.rb +72 -0
- data/spec/lib/license_finder/package_managers/go_workspace_spec.rb +69 -0
- data/spec/lib/license_finder/package_managers/gradle_package_spec.rb +9 -0
- data/spec/lib/license_finder/package_managers/gradle_spec.rb +94 -44
- data/spec/lib/license_finder/package_managers/maven_spec.rb +8 -6
- data/spec/lib/license_finder/package_managers/merged_package_spec.rb +52 -0
- data/spec/lib/license_finder/package_managers/npm_spec.rb +59 -20
- data/spec/lib/license_finder/package_managers/nuget_spec.rb +82 -0
- data/spec/lib/license_finder/package_managers/pip_package_spec.rb +1 -0
- data/spec/lib/license_finder/package_managers/rebar_spec.rb +12 -12
- data/spec/lib/license_finder/package_spec.rb +59 -2
- data/spec/lib/license_finder/project_finder_spec.rb +33 -0
- data/spec/lib/license_finder/reports/csv_report_spec.rb +9 -3
- data/spec/lib/license_finder/reports/diff_report_spec.rb +56 -0
- data/spec/lib/license_finder/reports/merged_report_spec.rb +21 -0
- metadata +82 -9
- 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: [
|
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 == [
|
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
|
-
|
6
|
-
|
5
|
+
subject { Gradle.new(project_path: Pathname('/fake/path')) }
|
6
|
+
|
7
|
+
let(:content) { [] }
|
7
8
|
|
8
|
-
|
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 '
|
11
|
+
describe '#current_packages' do
|
23
12
|
before do
|
24
|
-
allow(
|
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
|
28
|
-
|
29
|
-
|
30
|
-
expect(
|
31
|
-
|
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
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
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
|
-
|
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
|
-
|
46
|
-
|
47
|
-
|
48
|
-
<
|
49
|
-
|
50
|
-
|
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
|
-
|
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
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
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
|
-
|
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
|
-
|
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(
|
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(
|
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(
|
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(
|
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(
|
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
|