license_finder 0.9.5.1-java → 1.0.0.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +9 -0
  4. data/CHANGELOG.rdoc +9 -0
  5. data/MIT.LICENSE +20 -0
  6. data/db/migrate/201401302113_re_reassociate_license.rb +23 -0
  7. data/features/gradle_dependencies.feature +9 -0
  8. data/features/maven_dependencies.feature +9 -0
  9. data/features/step_definitions/gradle_steps.rb +8 -0
  10. data/features/step_definitions/maven_steps.rb +8 -0
  11. data/features/step_definitions/node_steps.rb +1 -1
  12. data/features/step_definitions/set_license_steps.rb +0 -1
  13. data/features/step_definitions/shared_steps.rb +26 -13
  14. data/lib/license_finder.rb +6 -1
  15. data/lib/license_finder/cli.rb +13 -9
  16. data/lib/license_finder/configuration.rb +113 -72
  17. data/lib/license_finder/dependency_manager.rb +12 -7
  18. data/lib/license_finder/license.rb +39 -65
  19. data/lib/license_finder/license/any_matcher.rb +13 -0
  20. data/lib/license_finder/license/definitions.rb +106 -0
  21. data/lib/license_finder/license/header_matcher.rb +10 -0
  22. data/lib/license_finder/license/matcher.rb +17 -0
  23. data/lib/license_finder/license/template.rb +16 -0
  24. data/lib/license_finder/license/text.rb +19 -0
  25. data/lib/license_finder/license_url.rb +1 -4
  26. data/lib/license_finder/package.rb +18 -2
  27. data/lib/license_finder/package_managers/bower_package.rb +3 -17
  28. data/lib/license_finder/package_managers/bundler_package.rb +2 -2
  29. data/lib/license_finder/package_managers/gradle.rb +29 -0
  30. data/lib/license_finder/package_managers/gradle_package.rb +41 -0
  31. data/lib/license_finder/package_managers/maven.rb +31 -0
  32. data/lib/license_finder/package_managers/maven_package.rb +46 -0
  33. data/lib/license_finder/package_managers/npm_package.rb +2 -16
  34. data/lib/license_finder/package_managers/pip_package.rb +7 -7
  35. data/lib/license_finder/package_saver.rb +1 -1
  36. data/lib/license_finder/possible_license_file.rb +1 -5
  37. data/lib/license_finder/possible_license_files.rb +4 -2
  38. data/lib/license_finder/reports/dependency_report.rb +5 -1
  39. data/lib/license_finder/reports/detailed_text_report.rb +0 -1
  40. data/lib/license_finder/reports/formatted_report.rb +21 -0
  41. data/lib/license_finder/reports/html_report.rb +1 -21
  42. data/lib/license_finder/reports/markdown_report.rb +1 -21
  43. data/lib/license_finder/reports/reporter.rb +8 -7
  44. data/lib/license_finder/reports/text_report.rb +0 -2
  45. data/lib/license_finder/tables.rb +1 -1
  46. data/lib/license_finder/tables/dependency.rb +12 -12
  47. data/lib/license_finder/yml_to_sql.rb +4 -4
  48. data/license_finder.gemspec +3 -2
  49. data/readme.md +10 -1
  50. data/release/publish.sh +10 -7
  51. data/spec/fixtures/build.gradle +24 -0
  52. data/spec/fixtures/pom.xml +19 -0
  53. data/spec/lib/license_finder/cli_spec.rb +13 -3
  54. data/spec/lib/license_finder/configuration_spec.rb +121 -74
  55. data/spec/lib/license_finder/dependency_manager_spec.rb +34 -16
  56. data/spec/lib/license_finder/license/{new_bsd_spec.rb → definitions_spec.rb} +93 -7
  57. data/spec/lib/license_finder/license_spec.rb +72 -26
  58. data/spec/lib/license_finder/license_url_spec.rb +10 -14
  59. data/spec/lib/license_finder/package_managers/bower_package_spec.rb +17 -5
  60. data/spec/lib/license_finder/package_managers/bundler_package_spec.rb +2 -2
  61. data/spec/lib/license_finder/package_managers/gradle_package_spec.rb +66 -0
  62. data/spec/lib/license_finder/package_managers/gradle_spec.rb +89 -0
  63. data/spec/lib/license_finder/package_managers/maven_package_spec.rb +72 -0
  64. data/spec/lib/license_finder/package_managers/maven_spec.rb +115 -0
  65. data/spec/lib/license_finder/package_managers/npm_package_spec.rb +17 -3
  66. data/spec/lib/license_finder/package_managers/pip_package_spec.rb +27 -5
  67. data/spec/lib/license_finder/possible_license_file_spec.rb +2 -2
  68. data/spec/lib/license_finder/{detailed_text_report_spec.rb → reports/detailed_text_report_spec.rb} +0 -0
  69. data/spec/lib/license_finder/{html_report_spec.rb → reports/html_report_spec.rb} +0 -0
  70. data/spec/lib/license_finder/{markdown_report_spec.rb → reports/markdown_report_spec.rb} +0 -0
  71. data/spec/lib/license_finder/reports/reporter_spec.rb +33 -0
  72. data/spec/lib/license_finder/{text_report_spec.rb → reports/text_report_spec.rb} +0 -0
  73. data/spec/lib/license_finder/tables/dependency_spec.rb +1 -2
  74. data/spec/lib/license_finder/tables/license_alias_spec.rb +1 -2
  75. data/spec/lib/license_finder/yml_to_sql_spec.rb +10 -11
  76. data/spec/lib/license_finder_spec.rb +5 -71
  77. metadata +64 -53
  78. data/features/rails_rake.feature +0 -9
  79. data/features/step_definitions/rails_rake_steps.rb +0 -12
  80. data/lib/license_finder/license/apache2.rb +0 -8
  81. data/lib/license_finder/license/bsd.rb +0 -4
  82. data/lib/license_finder/license/gplv2.rb +0 -4
  83. data/lib/license_finder/license/isc.rb +0 -3
  84. data/lib/license_finder/license/lgpl.rb +0 -4
  85. data/lib/license_finder/license/mit.rb +0 -23
  86. data/lib/license_finder/license/new_bsd.rb +0 -27
  87. data/lib/license_finder/license/python.rb +0 -8
  88. data/lib/license_finder/license/ruby.rb +0 -11
  89. data/lib/license_finder/license/simplified_bsd.rb +0 -8
  90. data/lib/license_finder/railtie.rb +0 -7
  91. data/lib/tasks/license_finder.rake +0 -7
  92. data/spec/lib/license_finder/license/apache_spec.rb +0 -7
  93. data/spec/lib/license_finder/license/bsd_spec.rb +0 -41
  94. data/spec/lib/license_finder/license/gplv2_spec.rb +0 -7
  95. data/spec/lib/license_finder/license/isc_spec.rb +0 -7
  96. data/spec/lib/license_finder/license/lgpl_spec.rb +0 -7
  97. data/spec/lib/license_finder/license/mit_spec.rb +0 -33
  98. data/spec/lib/license_finder/license/python_spec.rb +0 -7
  99. data/spec/lib/license_finder/license/ruby_spec.rb +0 -19
  100. data/spec/lib/license_finder/license/simplified_bsd_spec.rb +0 -7
  101. data/spec/lib/license_finder/reporter_spec.rb +0 -46
  102. data/spec/support/license_examples.rb +0 -30
@@ -1,12 +1,68 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe LicenseFinder::License::NewBSD do
4
- subject { LicenseFinder::License::NewBSD.new("") }
3
+ describe LicenseFinder::License, "Apache2" do
4
+ it "should be findable" do |e|
5
+ described_class.find_by_name("Apache2").should be
6
+ end
7
+ end
8
+
9
+ describe LicenseFinder::License, "BSD" do
10
+ it "should be findable" do |e|
11
+ described_class.find_by_name("BSD").should be
12
+ end
13
+ end
14
+
15
+ describe LicenseFinder::License, "GPLv2" do
16
+ it "should be findable" do
17
+ described_class.find_by_name("GPLv2").should be
18
+ end
19
+ end
20
+
21
+ describe LicenseFinder::License, "ISC" do
22
+ it "should be findable" do
23
+ described_class.find_by_name("ISC").should be
24
+ end
25
+ end
26
+
27
+ describe LicenseFinder::License, "LGPL" do
28
+ it "should be findable" do
29
+ described_class.find_by_name("LGPL").should be
30
+ end
31
+ end
32
+
33
+ describe LicenseFinder::License, "MIT" do
34
+ subject { described_class.find_by_name "MIT" }
35
+
36
+ describe "#matches_text?" do
37
+ it "should return true if the text contains the MIT url" do
38
+ subject.should be_matches_text "MIT License is awesome http://opensource.org/licenses/mit-license"
39
+
40
+ subject.should be_matches_text "MIT Licence is awesome http://www.opensource.org/licenses/mit-license"
41
+
42
+ subject.should_not be_matches_text "MIT Licence is awesome http://www!opensource!org/licenses/mit-license"
43
+ end
44
+
45
+ it "should return true if the text begins with 'The MIT License'" do
46
+ subject.should be_matches_text "The MIT License"
5
47
 
6
- it_behaves_like "a license matcher"
48
+ subject.should be_matches_text "The MIT Licence"
49
+
50
+ subject.should_not be_matches_text "Something else\nThe MIT License"
51
+ end
52
+
53
+ it "should return true if the text contains 'is released under the MIT license'" do
54
+ subject.should be_matches_text "is released under the MIT license"
55
+
56
+ subject.should be_matches_text "is released under the MIT licence"
57
+ end
58
+ end
59
+ end
60
+
61
+ describe LicenseFinder::License, "NewBSD" do
62
+ subject { described_class.find_by_name "NewBSD" }
7
63
 
8
64
  it "should match regardless of organization or copyright holder names" do
9
- license = LicenseFinder::License::NewBSD.new <<-LICENSE
65
+ license = <<-LICENSE
10
66
  Redistribution and use in source and binary forms, with or without
11
67
  modification, are permitted provided that the following conditions are met:
12
68
  * Redistributions of source code must retain the above copyright
@@ -30,11 +86,11 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30
86
  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
87
  LICENSE
32
88
 
33
- license.should be_matches
89
+ subject.should be_matches_text license
34
90
  end
35
91
 
36
92
  it "should match with the alternate wording of third clause" do
37
- license = LicenseFinder::License::NewBSD.new <<-LICENSE
93
+ license = <<-LICENSE
38
94
  Redistribution and use in source and binary forms, with or without
39
95
  modification, are permitted provided that the following conditions are met:
40
96
  * Redistributions of source code must retain the above copyright
@@ -58,6 +114,36 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
58
114
  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59
115
  LICENSE
60
116
 
61
- license.should be_matches
117
+ subject.should be_matches_text license
118
+ end
119
+ end
120
+
121
+ describe LicenseFinder::License, "Python" do
122
+ it "should be findable" do
123
+ described_class.find_by_name("Python").should be
124
+ end
125
+ end
126
+
127
+ describe LicenseFinder::License, "Ruby" do
128
+ subject { described_class.find_by_name "Ruby" }
129
+
130
+ describe "#matches?" do
131
+ it "should return true when the Ruby license URL is present" do
132
+ subject.should be_matches_text "This gem is available under the following license:\nhttp://www.ruby-lang.org/en/LICENSE.txt\nOkay?"
133
+ end
134
+
135
+ it "should return false when the Ruby License URL is not present" do
136
+ subject.should_not be_matches_text "This gem is available under the following license:\nhttp://www.example.com\nOkay?"
137
+ end
138
+
139
+ it "should return false for pathological licenses" do
140
+ subject.should_not be_matches_text "This gem is available under the following license:\nhttp://wwwzruby-langzorg/en/LICENSEztxt\nOkay?"
141
+ end
142
+ end
143
+ end
144
+
145
+ describe LicenseFinder::License, "SimplifiedBSD" do
146
+ it "should be findable" do
147
+ described_class.find_by_name("SimplifiedBSD").should be
62
148
  end
63
149
  end
@@ -1,45 +1,91 @@
1
1
  require 'spec_helper'
2
2
 
3
- class FooLicense < LicenseFinder::License::Base
4
- self.alternative_names = ["the foo license"]
5
- self.license_url = "http://foo.license.com"
6
-
7
- def self.pretty_name
8
- "Ye Ole Foo License"
9
- end
10
- end
11
-
12
3
  module LicenseFinder
13
4
  describe License do
14
5
  describe ".find_by_name" do
15
- it "should match on demodulized names" do
16
- License.find_by_name("FooLicense").should == FooLicense
6
+ it "should find a registered license" do
7
+ License.find_by_name("Apache2").should be_a License
8
+ end
9
+
10
+ context "when license not found" do
11
+ it "should return UnknownLicense with the name" do
12
+ license = License.find_by_name("New License")
13
+
14
+ expect(license).to be_a UnknownLicense
15
+ expect(license.pretty_name).to eq "New License"
16
+ end
17
17
  end
18
+ end
19
+
20
+ describe ".find_by_text" do
21
+ it "should find a registered license" do
22
+ License.find_by_text('This gem is released under the MIT license').should be_a License
23
+ end
24
+
25
+ it "returns UnknownLicense with nil name if not found" do
26
+ license = License.find_by_text("foo")
18
27
 
19
- it "should match on pretty names" do
20
- License.find_by_name("Ye Ole Foo License").should == FooLicense
28
+ expect(license).to be_a UnknownLicense
29
+ expect(license.pretty_name).to be_nil
30
+ end
31
+ end
32
+
33
+ def make_license(settings = {})
34
+ described_class.new({
35
+ short_name: "Default Short Name",
36
+ url: "http://example.com/license",
37
+ matcher: License::Matcher.from_text('Default Matcher')
38
+ }.merge(settings))
39
+ end
40
+
41
+ describe "#matches_name?" do
42
+ it "should match on short_name" do
43
+ make_license(short_name: "Foo").should be_matches_name "Foo"
44
+ end
45
+
46
+ it "should match on pretty name" do
47
+ make_license(pretty_name: "Foo").should be_matches_name "Foo"
21
48
  end
22
49
 
23
50
  it "should match on alternative names" do
24
- License.find_by_name("the foo license").should == FooLicense
51
+ license = make_license(other_names: ["Foo", "Bar"])
52
+ license.should be_matches_name "Foo"
53
+ license.should be_matches_name "Bar"
25
54
  end
26
55
 
27
- it "should return nil if no match" do
28
- License.find_by_name(:unknown).should be_nil
56
+ it "should ignore case" do
57
+ make_license(pretty_name: "Foo").should be_matches_name "foo"
58
+ make_license(pretty_name: "foo").should be_matches_name "Foo"
59
+ end
60
+
61
+ it "should not fail if pretty_name or other_names are omitted" do
62
+ make_license.should be_matches_name "Default Short Name"
29
63
  end
30
64
  end
31
- end
32
- end
33
65
 
34
- describe LicenseFinder::License::Base do
35
- describe ".names" do
36
- subject do
37
- Class.new(LicenseFinder::License::Base) do
38
- def self.demodulized_name; "FooLicense"; end
39
- self.alternative_names = ["foo license"]
40
- end.names
66
+ describe ".matches_text?" do
67
+ it "should match on text" do
68
+ license = make_license(matcher: License::Matcher.new(/The license text/))
69
+ license.should be_matches_text "The license text"
70
+ license.should_not be_matches_text "Some other text"
71
+ end
72
+
73
+ it "should match regardless of placeholder names, whitespace, or quotes" do
74
+ license_text = <<-LICENSE
75
+ The "company" of <company name> shall not be
76
+ held `responsible` for 'anything'.
77
+ LICENSE
78
+ license = make_license(matcher: License::Matcher.from_text(License::Text.normalize_punctuation(license_text)))
79
+
80
+ license.should be_matches_text <<-FILE
81
+ The ''company'' of foo bar *%*%*%*%
82
+ shall not be held "responsible" for `anything`.
83
+ FILE
84
+ end
41
85
  end
42
86
 
43
- it { should =~ ["FooLicense", "foo license"] }
87
+ it "should default pretty_name to short_name" do
88
+ make_license.pretty_name.should == "Default Short Name"
89
+ end
44
90
  end
45
91
  end
@@ -1,20 +1,16 @@
1
1
  require "spec_helper"
2
2
 
3
- class FooLicense < LicenseFinder::License::Base
4
- self.alternative_names = ["the foo license"]
5
- self.license_url = "http://foo.license.com"
6
- end
7
-
8
- describe LicenseFinder::LicenseUrl do
9
- describe ".find_by_name" do
10
- subject { LicenseFinder::LicenseUrl }
3
+ module LicenseFinder
4
+ describe LicenseUrl do
5
+ describe ".find_by_name" do
6
+ subject { LicenseUrl }
11
7
 
12
- specify { subject.find_by_name("FooLicense").should == "http://foo.license.com" }
13
- specify { subject.find_by_name("fOolICENse").should == "http://foo.license.com" }
14
- specify { subject.find_by_name("the foo license").should == "http://foo.license.com" }
8
+ before do
9
+ License.stub(:find_by_name).with("Foo").
10
+ and_return(double(:foo_license, url: "http://foo.license.com"))
11
+ end
15
12
 
16
- specify { subject.find_by_name(nil).should be_nil }
17
- specify { subject.find_by_name("").should be_nil }
18
- specify { subject.find_by_name("unknown license").should be_nil }
13
+ specify { subject.find_by_name("Foo").should == "http://foo.license.com" }
14
+ end
19
15
  end
20
16
  end
@@ -31,12 +31,12 @@ module LicenseFinder
31
31
  PossibleLicenseFiles.stub(:find).with("/path/to/thing").and_return(license_files)
32
32
  end
33
33
 
34
- let(:package1) { { "pkgMeta" => {"license" => "MIT"} } }
35
- let(:package2) { { "pkgMeta" => {"licenses" => [{"type" => "BSD", "url" => "github.github/github"}]} } }
36
- let(:package3) { { "pkgMeta" => {"license" => {"type" => "PSF", "url" => "github.github/github"}} } }
37
- let(:package4) { { "pkgMeta" => {"licenses" => ["MIT"]} } }
34
+ let(:package1) { { "pkgMeta" => {"license" => "MIT"}, "canonicalDir" => "/some/path" } }
35
+ let(:package2) { { "pkgMeta" => {"licenses" => [{"type" => "BSD", "url" => "github.github/github"}]}, "canonicalDir" => "/some/path" } }
36
+ let(:package3) { { "pkgMeta" => {"license" => {"type" => "PSF", "url" => "github.github/github"}}, "canonicalDir" => "/some/path" } }
37
+ let(:package4) { { "pkgMeta" => {"licenses" => ["MIT"]}, "canonicalDir" => "/some/path" } }
38
38
 
39
- it 'finds the license for both license structures' do
39
+ it 'finds the license for both license structures' do
40
40
  BowerPackage.new(package1).license.should eq("MIT")
41
41
  BowerPackage.new(package2).license.should eq("BSD")
42
42
  BowerPackage.new(package3).license.should eq("PSF")
@@ -49,6 +49,18 @@ module LicenseFinder
49
49
  subject.license.should == "Detected License"
50
50
  end
51
51
 
52
+ it "returns other if there's more than one license" do
53
+ package = BowerPackage.new({ "pkgMeta" => {"licenses" => ["MIT", "BSD"]}, "canonicalDir" => "/some/path" })
54
+ expect(package.license).to eq("other")
55
+ end
56
+
57
+ it "returns other if the license from spec and license from files are different" do
58
+ stub_license_files [double(:file, license: 'Detected License')]
59
+ package = BowerPackage.new({ "pkgMeta" => {"licenses" => ["MIT"]}, "canonicalDir" => "/path/to/thing" })
60
+
61
+ expect(package.license).to eq("other")
62
+ end
63
+
52
64
  it "returns 'other' otherwise" do
53
65
  stub_license_files []
54
66
 
@@ -37,10 +37,10 @@ module LicenseFinder
37
37
  subject.license.should == "Gemspec License"
38
38
  end
39
39
 
40
- it "returns the first license if the gemspec provides many" do
40
+ it "returns 'other' if the gemspec provides many" do
41
41
  gemspec.licenses = ['First Gemspec License', 'Second Gemspec License']
42
42
 
43
- subject.license.should == "First Gemspec License"
43
+ subject.license.should == "other"
44
44
  end
45
45
 
46
46
  it "returns a license in a file if detected" do
@@ -0,0 +1,66 @@
1
+ require 'spec_helper'
2
+
3
+ module LicenseFinder
4
+ describe GradlePackage do
5
+ subject do
6
+ described_class.new(
7
+ {
8
+ "name" => "ch.qos.logback:logback-classic:1.1.1",
9
+ "file" => ["logback-classic-1.1.1.jar"],
10
+ "license" => [
11
+ { "name" => "Eclipse Public License - v 1.0", "url"=>"http://www.eclipse.org/legal/epl-v10.html"}
12
+ ]
13
+ }
14
+ )
15
+ end
16
+
17
+ it_behaves_like "it conforms to interface required by PackageSaver"
18
+
19
+ its(:name) { should == "logback-classic" }
20
+ its(:version) { should == "1.1.1" }
21
+ its(:description) { should == "" }
22
+ its(:licenses_from_spec) { should == ["Eclipse Public License - v 1.0"] }
23
+
24
+ describe "#license" do
25
+ it "returns the license if found" do
26
+ subject.license.should == "Eclipse Public License - v 1.0"
27
+ end
28
+
29
+ context "when there are multiple licenses" do
30
+ subject do
31
+ described_class.new(
32
+ {
33
+ "name" => "ch.qos.logback:logback-classic:1.1.1",
34
+ "file" => ["logback-classic-1.1.1.jar"],
35
+ "license" => [
36
+ { "name" => "Eclipse Public License - v 1.0", "url"=>"http://www.eclipse.org/legal/epl-v10.html"},
37
+ { "name"=>"GNU Lesser General Public License", "url"=>"http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html"}
38
+ ]
39
+ }
40
+ )
41
+ end
42
+
43
+ it "returns 'other'" do
44
+ subject.license.should == 'other'
45
+ end
46
+ end
47
+
48
+ context "when the license is not found" do
49
+ subject do
50
+ described_class.new(
51
+ {
52
+ "name" => "ch.qos.logback:logback-classic:1.1.1",
53
+ "file" => ["logback-classic-1.1.1.jar"],
54
+ "license" => []
55
+ }
56
+ )
57
+ end
58
+
59
+ it "returns 'other' otherwise" do
60
+ subject.license.should == "other"
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+
@@ -0,0 +1,89 @@
1
+ require 'spec_helper'
2
+
3
+ module LicenseFinder
4
+ describe Gradle do
5
+ def license_xml(xml)
6
+ <<-resp
7
+ <dependencies>
8
+ #{xml}
9
+ </dependencies>
10
+ resp
11
+ end
12
+
13
+ describe '.current_packages' do
14
+ before do
15
+ expect(described_class).to receive(:`).with(/gradle downloadLicenses/)
16
+ end
17
+
18
+ it 'lists all the current packages' do
19
+ license_xml = license_xml("""
20
+ <dependency name='org.springframework:spring-aop:4.0.1.RELEASE'>
21
+ <file>spring-aop-4.0.1.RELEASE.jar</file>
22
+ <license name='The Apache Software License, Version 2.0' url='http://www.apache.org/licenses/LICENSE-2.0.txt' />
23
+ </dependency>
24
+ <dependency name='org.springframework:spring-core:4.0.1.RELEASE'>
25
+ <file>spring-core-4.0.1.RELEASE.jar</file>
26
+ <license name='The Apache Software License, Version 2.0' url='http://www.apache.org/licenses/LICENSE-2.0.txt' />
27
+ </dependency>
28
+ """)
29
+ allow(File).to receive(:read).with("build/reports/license/dependency-license.xml").and_return(license_xml)
30
+
31
+ current_packages = described_class.current_packages
32
+
33
+ expect(current_packages.size).to eq(2)
34
+ expect(current_packages.first).to be_a(Package)
35
+ end
36
+
37
+ it "handles multiple licenses" do
38
+ license_xml = license_xml("""
39
+ <dependency>
40
+ <license name='License 1'/>
41
+ <license name='License 2'/>
42
+ </dependency>
43
+ """)
44
+
45
+ allow(File).to receive(:read).with("build/reports/license/dependency-license.xml").and_return(license_xml)
46
+
47
+ GradlePackage.should_receive(:new).with("license" => [{"name" => "License 1"}, {"name" => "License 2"}])
48
+ Gradle.current_packages
49
+ end
50
+
51
+ it "handles no licenses" do
52
+ license_xml = license_xml("""
53
+ <dependency>
54
+ <license name='No license found' />
55
+ </dependency>
56
+ """)
57
+
58
+ allow(File).to receive(:read).with("build/reports/license/dependency-license.xml").and_return(license_xml)
59
+
60
+ GradlePackage.should_receive(:new).with("license" => [])
61
+ Gradle.current_packages
62
+ end
63
+ end
64
+
65
+ describe '.active?' do
66
+ let(:package) { Pathname.new('build.gradle').expand_path }
67
+
68
+ context 'with a build.gradle file' do
69
+ before :each do
70
+ allow(File).to receive(:exists?).with(package).and_return(true)
71
+ end
72
+
73
+ it 'returns true' do
74
+ expect(Gradle.active?).to eq(true)
75
+ end
76
+ end
77
+
78
+ context 'without a build.gradle file' do
79
+ before :each do
80
+ allow(File).to receive(:exists?).with(package).and_return(false)
81
+ end
82
+
83
+ it 'returns false' do
84
+ expect(Gradle.active?).to eq(false)
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end