bibliothecary 7.3.6 → 8.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +1 -1
  3. data/README.md +7 -0
  4. data/bibliothecary.gemspec +1 -0
  5. data/lib/bibliothecary/analyser/analysis.rb +110 -0
  6. data/lib/bibliothecary/analyser/determinations.rb +27 -0
  7. data/lib/bibliothecary/analyser/matchers.rb +64 -0
  8. data/lib/bibliothecary/analyser.rb +32 -188
  9. data/lib/bibliothecary/cli.rb +3 -3
  10. data/lib/bibliothecary/file_info.rb +2 -0
  11. data/lib/bibliothecary/multi_parsers/bundler_like_manifest.rb +22 -0
  12. data/lib/bibliothecary/multi_parsers/cyclonedx.rb +156 -0
  13. data/lib/bibliothecary/multi_parsers/json_runtime.rb +16 -0
  14. data/lib/bibliothecary/parsers/bower.rb +2 -2
  15. data/lib/bibliothecary/parsers/cargo.rb +4 -2
  16. data/lib/bibliothecary/parsers/carthage.rb +6 -6
  17. data/lib/bibliothecary/parsers/clojars.rb +2 -2
  18. data/lib/bibliothecary/parsers/cocoapods.rb +5 -4
  19. data/lib/bibliothecary/parsers/conda.rb +11 -5
  20. data/lib/bibliothecary/parsers/cpan.rb +2 -2
  21. data/lib/bibliothecary/parsers/cran.rb +3 -1
  22. data/lib/bibliothecary/parsers/dub.rb +3 -2
  23. data/lib/bibliothecary/parsers/elm.rb +2 -1
  24. data/lib/bibliothecary/parsers/generic.rb +1 -1
  25. data/lib/bibliothecary/parsers/go.rb +13 -11
  26. data/lib/bibliothecary/parsers/hackage.rb +4 -2
  27. data/lib/bibliothecary/parsers/haxelib.rb +1 -0
  28. data/lib/bibliothecary/parsers/hex.rb +6 -4
  29. data/lib/bibliothecary/parsers/julia.rb +2 -2
  30. data/lib/bibliothecary/parsers/maven.rb +19 -11
  31. data/lib/bibliothecary/parsers/meteor.rb +1 -0
  32. data/lib/bibliothecary/parsers/npm.rb +7 -5
  33. data/lib/bibliothecary/parsers/nuget.rb +10 -7
  34. data/lib/bibliothecary/parsers/packagist.rb +4 -2
  35. data/lib/bibliothecary/parsers/pub.rb +2 -2
  36. data/lib/bibliothecary/parsers/pypi.rb +11 -9
  37. data/lib/bibliothecary/parsers/rubygems.rb +7 -4
  38. data/lib/bibliothecary/parsers/shard.rb +2 -2
  39. data/lib/bibliothecary/parsers/swift_pm.rb +4 -2
  40. data/lib/bibliothecary/runner.rb +8 -3
  41. data/lib/bibliothecary/version.rb +1 -1
  42. data/lib/bibliothecary.rb +3 -0
  43. metadata +22 -2
@@ -33,7 +33,9 @@ module Bibliothecary
33
33
  }
34
34
  end
35
35
 
36
- def self.parse_shrinkwrap(file_contents)
36
+ add_multi_parser(Bibliothecary::MultiParsers::CycloneDX)
37
+
38
+ def self.parse_shrinkwrap(file_contents, options: {})
37
39
  manifest = JSON.parse(file_contents)
38
40
  manifest.fetch('dependencies',[]).map do |name, requirement|
39
41
  {
@@ -44,7 +46,7 @@ module Bibliothecary
44
46
  end
45
47
  end
46
48
 
47
- def self.parse_package_lock(file_contents)
49
+ def self.parse_package_lock(file_contents, options: {})
48
50
  manifest = JSON.parse(file_contents)
49
51
  parse_package_lock_deps_recursively(manifest.fetch('dependencies', []))
50
52
  end
@@ -68,14 +70,14 @@ module Bibliothecary
68
70
  end
69
71
  end
70
72
 
71
- def self.parse_manifest(file_contents)
73
+ def self.parse_manifest(file_contents, options: {})
72
74
  manifest = JSON.parse(file_contents)
73
75
  raise "appears to be a lockfile rather than manifest format" if manifest.key?('lockfileVersion')
74
76
  map_dependencies(manifest, 'dependencies', 'runtime') +
75
77
  map_dependencies(manifest, 'devDependencies', 'development')
76
78
  end
77
79
 
78
- def self.parse_yarn_lock(file_contents)
80
+ def self.parse_yarn_lock(file_contents, options: {})
79
81
  response = Typhoeus.post("#{Bibliothecary.configuration.yarn_parser_host}/parse", body: file_contents)
80
82
 
81
83
  raise Bibliothecary::RemoteParsingError.new("Http Error #{response.response_code} when contacting: #{Bibliothecary.configuration.yarn_parser_host}/parse", response.response_code) unless response.success?
@@ -91,7 +93,7 @@ module Bibliothecary
91
93
  end
92
94
  end
93
95
 
94
- def self.parse_ls(file_contents)
96
+ def self.parse_ls(file_contents, options: {})
95
97
  manifest = JSON.parse(file_contents)
96
98
 
97
99
  transform_tree_to_array(manifest.fetch('dependencies', {}))
@@ -5,6 +5,7 @@ module Bibliothecary
5
5
  module Parsers
6
6
  class Nuget
7
7
  include Bibliothecary::Analyser
8
+ extend Bibliothecary::MultiParsers::JSONRuntime
8
9
 
9
10
  def self.mapping
10
11
  {
@@ -43,7 +44,9 @@ module Bibliothecary
43
44
  }
44
45
  end
45
46
 
46
- def self.parse_project_lock_json(file_contents)
47
+ add_multi_parser(Bibliothecary::MultiParsers::CycloneDX)
48
+
49
+ def self.parse_project_lock_json(file_contents, options: {})
47
50
  manifest = JSON.parse file_contents
48
51
  manifest.fetch('libraries',[]).map do |name, _requirement|
49
52
  dep = name.split('/')
@@ -55,7 +58,7 @@ module Bibliothecary
55
58
  end
56
59
  end
57
60
 
58
- def self.parse_packages_lock_json(file_contents)
61
+ def self.parse_packages_lock_json(file_contents, options: {})
59
62
  manifest = JSON.parse file_contents
60
63
 
61
64
  frameworks = {}
@@ -82,7 +85,7 @@ module Bibliothecary
82
85
  []
83
86
  end
84
87
 
85
- def self.parse_packages_config(file_contents)
88
+ def self.parse_packages_config(file_contents, options: {})
86
89
  manifest = Ox.parse file_contents
87
90
  manifest.packages.locate('package').map do |dependency|
88
91
  {
@@ -95,7 +98,7 @@ module Bibliothecary
95
98
  []
96
99
  end
97
100
 
98
- def self.parse_csproj(file_contents)
101
+ def self.parse_csproj(file_contents, options: {})
99
102
  manifest = Ox.parse file_contents
100
103
 
101
104
  packages = manifest.locate('ItemGroup/PackageReference').map do |dependency|
@@ -115,7 +118,7 @@ module Bibliothecary
115
118
  []
116
119
  end
117
120
 
118
- def self.parse_nuspec(file_contents)
121
+ def self.parse_nuspec(file_contents, options: {})
119
122
  manifest = Ox.parse file_contents
120
123
  manifest.package.metadata.dependencies.locate('dependency').map do |dependency|
121
124
  {
@@ -128,7 +131,7 @@ module Bibliothecary
128
131
  []
129
132
  end
130
133
 
131
- def self.parse_paket_lock(file_contents)
134
+ def self.parse_paket_lock(file_contents, options: {})
132
135
  lines = file_contents.split("\n")
133
136
  package_version_re = /\s+(?<name>\S+)\s\((?<version>\d+\.\d+[\.\d+[\.\d+]*]*)\)/
134
137
  packages = lines.select { |line| package_version_re.match(line) }.map { |line| package_version_re.match(line) }.map do |match|
@@ -142,7 +145,7 @@ module Bibliothecary
142
145
  packages.uniq {|package| package[:name] }
143
146
  end
144
147
 
145
- def self.parse_project_assets_json(file_contents)
148
+ def self.parse_project_assets_json(file_contents, options: {})
146
149
  manifest = JSON.parse file_contents
147
150
 
148
151
  frameworks = {}
@@ -18,7 +18,9 @@ module Bibliothecary
18
18
  }
19
19
  end
20
20
 
21
- def self.parse_lockfile(file_contents)
21
+ add_multi_parser(Bibliothecary::MultiParsers::CycloneDX)
22
+
23
+ def self.parse_lockfile(file_contents, options: {})
22
24
  manifest = JSON.parse file_contents
23
25
  manifest.fetch('packages',[]).map do |dependency|
24
26
  {
@@ -41,7 +43,7 @@ module Bibliothecary
41
43
  end
42
44
  end
43
45
 
44
- def self.parse_manifest(file_contents)
46
+ def self.parse_manifest(file_contents, options: {})
45
47
  manifest = JSON.parse file_contents
46
48
  map_dependencies(manifest, 'require', 'runtime') +
47
49
  map_dependencies(manifest, 'require-dev', 'development')
@@ -18,13 +18,13 @@ module Bibliothecary
18
18
  }
19
19
  end
20
20
 
21
- def self.parse_yaml_manifest(file_contents)
21
+ def self.parse_yaml_manifest(file_contents, options: {})
22
22
  manifest = YAML.load file_contents
23
23
  map_dependencies(manifest, 'dependencies', 'runtime') +
24
24
  map_dependencies(manifest, 'dev_dependencies', 'development')
25
25
  end
26
26
 
27
- def self.parse_yaml_lockfile(file_contents)
27
+ def self.parse_yaml_lockfile(file_contents, options: {})
28
28
  manifest = YAML.load file_contents
29
29
  manifest.fetch('packages', []).map do |name, dep|
30
30
  {
@@ -75,17 +75,19 @@ module Bibliothecary
75
75
  }
76
76
  end
77
77
 
78
- def self.parse_pipfile(file_contents)
78
+ add_multi_parser(Bibliothecary::MultiParsers::CycloneDX)
79
+
80
+ def self.parse_pipfile(file_contents, options: {})
79
81
  manifest = Tomlrb.parse(file_contents)
80
82
  map_dependencies(manifest['packages'], 'runtime') + map_dependencies(manifest['dev-packages'], 'develop')
81
83
  end
82
84
 
83
- def self.parse_poetry(file_contents)
85
+ def self.parse_poetry(file_contents, options: {})
84
86
  manifest = Tomlrb.parse(file_contents)['tool']['poetry']
85
87
  map_dependencies(manifest['dependencies'], 'runtime') + map_dependencies(manifest['dev-dependencies'], 'develop')
86
88
  end
87
89
 
88
- def self.parse_conda(file_contents)
90
+ def self.parse_conda(file_contents, options: {})
89
91
  contents = YAML.safe_load(file_contents)
90
92
  return [] unless contents
91
93
 
@@ -121,7 +123,7 @@ module Bibliothecary
121
123
  end
122
124
  end
123
125
 
124
- def self.parse_pipfile_lock(file_contents)
126
+ def self.parse_pipfile_lock(file_contents, options: {})
125
127
  manifest = JSON.parse(file_contents)
126
128
  deps = []
127
129
  manifest.each do |group, dependencies|
@@ -138,7 +140,7 @@ module Bibliothecary
138
140
  deps
139
141
  end
140
142
 
141
- def self.parse_poetry_lock(file_contents)
143
+ def self.parse_poetry_lock(file_contents, options: {})
142
144
  manifest = Tomlrb.parse(file_contents)
143
145
  deps = []
144
146
  manifest["package"].each do |package|
@@ -159,8 +161,8 @@ module Bibliothecary
159
161
  deps
160
162
  end
161
163
 
162
- def self.parse_setup_py(manifest)
163
- match = manifest.match(INSTALL_REGEXP)
164
+ def self.parse_setup_py(file_contents, options: {})
165
+ match = file_contents.match(INSTALL_REGEXP)
164
166
  return [] unless match
165
167
  deps = []
166
168
  match[1].gsub(/',(\s)?'/, "\n").split("\n").each do |line|
@@ -176,9 +178,9 @@ module Bibliothecary
176
178
  deps
177
179
  end
178
180
 
179
- def self.parse_requirements_txt(manifest)
181
+ def self.parse_requirements_txt(file_contents, options: {})
180
182
  deps = []
181
- manifest.split("\n").each do |line|
183
+ file_contents.split("\n").each do |line|
182
184
  match = line.delete(' ').match(REQUIREMENTS_REGEXP)
183
185
  next unless match
184
186
  deps << {
@@ -4,6 +4,7 @@ module Bibliothecary
4
4
  module Parsers
5
5
  class Rubygems
6
6
  include Bibliothecary::Analyser
7
+ extend Bibliothecary::MultiParsers::BundlerLikeManifest
7
8
 
8
9
  NAME_VERSION = '(?! )(.*?)(?: \(([^-]*)(?:-(.*))?\))?'.freeze
9
10
  NAME_VERSION_4 = /^ {4}#{NAME_VERSION}$/
@@ -28,8 +29,10 @@ module Bibliothecary
28
29
  }
29
30
  end
30
31
 
31
- def self.parse_gemfile_lock(manifest)
32
- manifest.lines(chomp: true).map do |line|
32
+ add_multi_parser(Bibliothecary::MultiParsers::CycloneDX)
33
+
34
+ def self.parse_gemfile_lock(file_contents, options: {})
35
+ file_contents.lines(chomp: true).map do |line|
33
36
  match = line.match(NAME_VERSION_4)
34
37
  next unless match
35
38
  name = match[1]
@@ -42,12 +45,12 @@ module Bibliothecary
42
45
  end.compact
43
46
  end
44
47
 
45
- def self.parse_gemfile(file_contents)
48
+ def self.parse_gemfile(file_contents, options: {})
46
49
  manifest = Gemnasium::Parser.send(:gemfile, file_contents)
47
50
  parse_ruby_manifest(manifest)
48
51
  end
49
52
 
50
- def self.parse_gemspec(file_contents)
53
+ def self.parse_gemspec(file_contents, options: {})
51
54
  manifest = Gemnasium::Parser.send(:gemspec, file_contents)
52
55
  parse_ruby_manifest(manifest)
53
56
  end
@@ -18,12 +18,12 @@ module Bibliothecary
18
18
  }
19
19
  end
20
20
 
21
- def self.parse_yaml_lockfile(file_contents)
21
+ def self.parse_yaml_lockfile(file_contents, options: {})
22
22
  manifest = YAML.load file_contents
23
23
  map_dependencies(manifest, 'shards', 'runtime')
24
24
  end
25
25
 
26
- def self.parse_yaml_manifest(file_contents)
26
+ def self.parse_yaml_manifest(file_contents, options: {})
27
27
  manifest = YAML.load file_contents
28
28
  map_dependencies(manifest, 'dependencies', 'runtime') +
29
29
  map_dependencies(manifest, 'development_dependencies', 'runtime')
@@ -12,8 +12,10 @@ module Bibliothecary
12
12
  }
13
13
  end
14
14
 
15
- def self.parse_package_swift(manifest)
16
- response = Typhoeus.post("#{Bibliothecary.configuration.swift_parser_host}/to-json", body: manifest)
15
+ add_multi_parser(Bibliothecary::MultiParsers::CycloneDX)
16
+
17
+ def self.parse_package_swift(file_contents, options: {})
18
+ response = Typhoeus.post("#{Bibliothecary.configuration.swift_parser_host}/to-json", body: file_contents)
17
19
  raise Bibliothecary::RemoteParsingError.new("Http Error #{response.response_code} when contacting: #{Bibliothecary.configuration.swift_parser_host}/to-json", response.response_code) unless response.success?
18
20
  json = JSON.parse(response.body)
19
21
  json["dependencies"].map do |dependency|
@@ -1,9 +1,14 @@
1
1
  module Bibliothecary
2
- # A class that allows bibliothecary to run with multiple configurations at once, rather than with one global
2
+ # A class that allows bibliothecary to run with multiple configurations at once, rather than with one global.
3
+ # A runner is created every time a file is targeted to be parsed. Don't call
4
+ # parse methods directory! Use a Runner.
3
5
  class Runner
4
6
 
5
7
  def initialize(configuration)
6
8
  @configuration = configuration
9
+ @options = {
10
+ cache: {}
11
+ }
7
12
  end
8
13
 
9
14
  def analyse(path, ignore_unparseable_files: true)
@@ -15,7 +20,7 @@ module Bibliothecary
15
20
  # associate related manifests and lockfiles for example.
16
21
  analyses = package_managers.map do |pm|
17
22
  matching_infos = info_list.select { |info| info.package_manager == pm }
18
- pm.analyse_file_info(matching_infos)
23
+ pm.analyse_file_info(matching_infos, options: @options)
19
24
  end
20
25
  analyses = analyses.flatten.compact
21
26
 
@@ -102,7 +107,7 @@ module Bibliothecary
102
107
 
103
108
  def analyse_file(file_path, contents)
104
109
  package_managers.select { |pm| pm.match?(file_path, contents) }.map do |pm|
105
- pm.analyse_contents(file_path, contents)
110
+ pm.analyse_contents(file_path, contents, options: @options)
106
111
  end.flatten.uniq.compact
107
112
  end
108
113
  alias analyze_file analyse_file
@@ -1,3 +1,3 @@
1
1
  module Bibliothecary
2
- VERSION = "7.3.6"
2
+ VERSION = "8.1.1"
3
3
  end
data/lib/bibliothecary.rb CHANGED
@@ -8,6 +8,9 @@ require "bibliothecary/related_files_info"
8
8
  require "find"
9
9
  require "tomlrb"
10
10
 
11
+ Dir[File.expand_path('../bibliothecary/multi_parsers/*.rb', __FILE__)].each do |file|
12
+ require file
13
+ end
11
14
  Dir[File.expand_path('../bibliothecary/parsers/*.rb', __FILE__)].each do |file|
12
15
  require file
13
16
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bibliothecary
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.3.6
4
+ version: 8.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Nesbitt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-21 00:00:00.000000000 Z
11
+ date: 2022-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tomlrb
@@ -136,6 +136,20 @@ dependencies:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: packageurl-ruby
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
139
153
  - !ruby/object:Gem::Dependency
140
154
  name: pry
141
155
  requirement: !ruby/object:Gem::Requirement
@@ -237,10 +251,16 @@ files:
237
251
  - dependencyci.yml
238
252
  - lib/bibliothecary.rb
239
253
  - lib/bibliothecary/analyser.rb
254
+ - lib/bibliothecary/analyser/analysis.rb
255
+ - lib/bibliothecary/analyser/determinations.rb
256
+ - lib/bibliothecary/analyser/matchers.rb
240
257
  - lib/bibliothecary/cli.rb
241
258
  - lib/bibliothecary/configuration.rb
242
259
  - lib/bibliothecary/exceptions.rb
243
260
  - lib/bibliothecary/file_info.rb
261
+ - lib/bibliothecary/multi_parsers/bundler_like_manifest.rb
262
+ - lib/bibliothecary/multi_parsers/cyclonedx.rb
263
+ - lib/bibliothecary/multi_parsers/json_runtime.rb
244
264
  - lib/bibliothecary/parsers/bower.rb
245
265
  - lib/bibliothecary/parsers/cargo.rb
246
266
  - lib/bibliothecary/parsers/carthage.rb