deriving_license 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ service_name: travis-ci
data/README.md CHANGED
@@ -9,7 +9,7 @@ Strategies:
9
9
  * from\_scraping\_homepage
10
10
  * from\_parsing\_readme
11
11
 
12
- [![Build Status](https://travis-ci.org/Schwolop/deriving_license.png)](https://travis-ci.org/Schwolop/deriving_license)
12
+ [![Build Status](https://travis-ci.org/Schwolop/deriving_license.png)](https://travis-ci.org/Schwolop/deriving_license) [![Coverage Status](https://coveralls.io/repos/Schwolop/deriving_license/badge.png)](https://coveralls.io/r/Schwolop/deriving_license) [![Code Climate](https://codeclimate.com/github/Schwolop/deriving_license.png)](https://codeclimate.com/github/Schwolop/deriving_license)
13
13
 
14
14
  Example output:
15
15
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'deriving_license'
3
- s.version = '0.3.0'
3
+ s.version = '0.3.1'
4
4
  s.summary = "Deriving Licence finds the license agreements for all gems in your Gemfile"
5
5
  s.description = "Deriving Licence finds the license agreements for all gems in your Gemfile if included in your project, or in a Gemfile passed to the included binary"
6
6
  s.authors = ["Tom Allen"]
@@ -16,5 +16,5 @@ Gem::Specification.new do |s|
16
16
  s.add_runtime_dependency "gemnasium-parser"
17
17
  s.add_runtime_dependency "safe_yaml"
18
18
  s.add_runtime_dependency "curb"
19
- s.add_development_dependency "simplecov"
19
+ s.add_development_dependency "coveralls"
20
20
  end
@@ -42,7 +42,7 @@ class DerivingLicense
42
42
 
43
43
  @specs_cache = {} # Cache of gem specifications previously fetched.
44
44
 
45
- def self.run(path=nil, strategies=nil)
45
+ def self.run(path=nil, strategies=[])
46
46
  unless path
47
47
  raise ArgumentError.new("Path to Gemfile or Gemspec required")
48
48
  end
@@ -57,71 +57,17 @@ class DerivingLicense
57
57
  raise "Invalid path to gemfile or gemspec."
58
58
  end
59
59
 
60
- strategies.each do |s|
61
- unless @strategies.include?(s)
62
- raise "Supplied strategies must be from the following list: [#{@strategies.join(', ')}]"
63
- end
64
- end unless strategies.nil?
65
- available_strategies = strategies.nil? ? @strategies : strategies
60
+ available_strategies = strategies.select{|s| @strategies.include?(s)}
61
+ raise "Supplied strategies must be from the following list: [#{@strategies.join(', ')}]" if available_strategies.count != strategies.count
62
+ available_strategies = @strategies if strategies.empty?
66
63
 
67
- gemspec_content = ""
68
- deps = []
69
- if /gemspec/.match(path.downcase) # Gemspecs...
70
- deps = Gemnasium::Parser::Gemspec.new(content).dependencies
71
- else # Gemfiles...
72
- content = Gemnasium::Parser::Gemfile.new(content)
73
- if content.gemspec? # If the gemfile sources a gemspec.
74
- begin
75
- gemspec_content = File.open(content.gemspec, "r").read
76
- rescue # If we fail to read the gemspec, search current directory
77
- possible_gemspec_files = Find.find( File.dirname(content.gemspec) )
78
- if possible_gemspec_files.count == 1
79
- begin
80
- gemspec_content = File.open(possible_gemspec_files[0], "r").read
81
- rescue
82
- raise "Could not open gemspec file \"#{possible_gemspec_files[0]}\" that was called by gemfile."
83
- end
84
- else
85
- raise "Gemfile calls out to unnamed gemspec, but multiple gemspec files found in gemfile's directory. Tell the developer to name their sources!"
86
- end
87
- end
88
- end
89
- deps = content.dependencies
90
- deps += Gemnasium::Parser::Gemspec.new(gemspec_content).dependencies unless gemspec_content.empty?
91
- end
64
+ deps = find_deps(path, content)
92
65
  detected_licenses = Hash.new(0)
93
66
  detected_licenses["custom"]=[]
94
67
 
95
68
  # For each dependency specified...
96
- licenses = []
97
- deps.each do |d|
98
- print "Determining license for #{d.name}:\n"
99
- # Try each license finding strategy...
100
- available_strategies.each do |s|
101
- print "\tTrying #{s} strategy..."
102
- licenses = eval("#{s}(\"#{d.name}\")")
103
- unless licenses.empty? # and break out of the search if successful
104
- if licenses.count == 1 and licenses[0] == "custom"
105
- print "CUSTOM\n"
106
- else
107
- print "SUCCESS\n"
108
- end
109
- break
110
- end
111
- print "FAILED\n"
112
- end
113
- licenses.each do |l| # add each detected license to the results
114
- unless l == "custom"
115
- detected_licenses[l]+=1
116
- else
117
- detected_licenses["custom"] << "#{d.name}" # the 'custom' key is
118
- # special and holds an array of the deps with custom licenses.
119
- end
120
- end
121
- end
122
- if detected_licenses["custom"].empty?
123
- detected_licenses.delete("custom")
124
- end
69
+ determine_licenses(deps,detected_licenses,available_strategies)
70
+
125
71
  detected_licenses
126
72
  end
127
73
 
@@ -155,6 +101,60 @@ class DerivingLicense
155
101
  end
156
102
  end
157
103
 
104
+ def self.find_deps(path, content)
105
+ deps = []
106
+ if /gemspec/.match(path.downcase) # Gemspecs...
107
+ deps = Gemnasium::Parser::Gemspec.new(content).dependencies
108
+ else # Gemfiles...
109
+ content = Gemnasium::Parser::Gemfile.new(content)
110
+ gemspec_content = ""
111
+ begin
112
+ gemspec_content = File.open(content.gemspec, "r").read
113
+ rescue # If we fail to read the gemspec, search current directory
114
+ possible_gemspec_files = Find.find( File.dirname(content.gemspec) )
115
+ raise "Gemfile calls out to unnamed gemspec, but multiple gemspec files found in gemfile's directory. Tell the developer to name their sources!" unless possible_gemspec_files.count == 1
116
+ begin
117
+ gemspec_content = File.open(possible_gemspec_files[0], "r").read
118
+ rescue
119
+ raise "Could not open gemspec file \"#{possible_gemspec_files[0]}\" that was called by gemfile."
120
+ end
121
+ end if content.gemspec? # If the gemfile sources a gemspec.
122
+ deps = content.dependencies
123
+ deps += Gemnasium::Parser::Gemspec.new(gemspec_content).dependencies unless gemspec_content.empty?
124
+ end
125
+ deps
126
+ end
127
+
128
+ def self.determine_licenses(deps,detected_licenses,available_strategies)
129
+ licenses = []
130
+ deps.each do |d|
131
+ print "Determining license for #{d.name}:\n"
132
+ # Try each license finding strategy...
133
+ available_strategies.each do |s|
134
+ print "\tTrying #{s} strategy..."
135
+ licenses = eval("#{s}(\"#{d.name}\")")
136
+ unless licenses.empty? # and break out of the search if successful
137
+ print "#{licenses.count == 1 and licenses[0] == "custom" ? "CUSTOM\n" : "SUCCESS\n"}"
138
+ break
139
+ end
140
+ print "FAILED\n"
141
+ end
142
+ add_to_detected_licenses(licenses,detected_licenses,d.name)
143
+ end
144
+ detected_licenses.delete("custom") if detected_licenses["custom"].empty?
145
+ end
146
+
147
+ def self.add_to_detected_licenses(licenses,detected_licenses,dep_name)
148
+ licenses.each do |l| # add each detected license to the results
149
+ if l == "custom"
150
+ detected_licenses["custom"] << "#{dep_name}" # the 'custom' key is
151
+ # special and holds an array of the deps with custom licenses.
152
+ else
153
+ detected_licenses[l]+=1
154
+ end
155
+ end
156
+ end
157
+
158
158
  def self.get_gem_spec(dep)
159
159
  # Check spec cache first.
160
160
  spec = @specs_cache[dep]
@@ -1,5 +1,5 @@
1
- require 'simplecov'
2
- SimpleCov.start
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
3
 
4
4
  require 'test/unit'
5
5
  require 'deriving_license'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deriving_license
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-07 00:00:00.000000000 Z
12
+ date: 2013-05-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: gemnasium-parser
@@ -60,7 +60,7 @@ dependencies:
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  - !ruby/object:Gem::Dependency
63
- name: simplecov
63
+ name: coveralls
64
64
  requirement: !ruby/object:Gem::Requirement
65
65
  none: false
66
66
  requirements:
@@ -83,6 +83,7 @@ executables:
83
83
  extensions: []
84
84
  extra_rdoc_files: []
85
85
  files:
86
+ - .coveralls.yml
86
87
  - .gitignore
87
88
  - .travis.yml
88
89
  - Gemfile