bibliothecary 1.4.2 → 2.0.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8f8a50e840d707f085b11ff12f9033303546f4d6
4
- data.tar.gz: 6b0f613937fd994c4d90eceaa16e30fba3d2a9ec
3
+ metadata.gz: f73395b523e5d1053eb00fdbfaefddb0cfdfe414
4
+ data.tar.gz: e738b7e775f7da5ac6d6f03765cea1364a2aad4a
5
5
  SHA512:
6
- metadata.gz: 9276e5d2594eedc7ad89f972f870efdbf096ad2c7a36840f4fa3a43d249ad8fc8d66792d0fcaf047276210b7babf51a393576e12b24d12e22e32d34640425e70
7
- data.tar.gz: 8f3db5617d6ef3e3344404f88af15d2838873b193a7e434e881119c173969a56decde5145b6063b2929334bb283bf4cf103f590a5940038777d701500589254a
6
+ metadata.gz: 90314f4a57cdce6a1609a94fcac4f97c171bf18668ed35996863a5d3d763cc9fb22526d3ba55e8879df0313ae0cb3476984553a4906c6d1858f8d36519b8f237
7
+ data.tar.gz: 07197d551b8d917b594447af58a2bb32241fda1f3e3c1c204e6a7dbfb6a9f92c00b83436f54e2090b90e0de987e70a17ac10d268e1c482ba6f31e8106987e8e0
data/lib/bibliothecary.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "bibliothecary/version"
2
+ require "bibliothecary/analyser"
2
3
 
3
4
  Dir[File.expand_path('../bibliothecary/parsers/*.rb', __FILE__)].each do |file|
4
5
  require file
@@ -0,0 +1,37 @@
1
+ module Bibliothecary
2
+ module Analyser
3
+ def self.included(base)
4
+ base.extend(ClassMethods)
5
+ end
6
+ module ClassMethods
7
+ def platform_name
8
+ self.name.to_s.split('::').last.downcase
9
+ end
10
+
11
+ def analyse(folder_path, file_list)
12
+ file_list.map do |path|
13
+ file_contents = File.open(path).read
14
+ filename = path.gsub(folder_path, '').gsub(/^\//, '')
15
+ analyse_file(filename, file_contents, path)
16
+ end.compact
17
+ end
18
+
19
+ def analyse_file(filename, file_contents, path)
20
+ begin
21
+ dependencies = parse(filename, file_contents)
22
+ if dependencies.any?
23
+ {
24
+ platform: platform_name,
25
+ path: path,
26
+ dependencies: dependencies
27
+ }
28
+ else
29
+ nil
30
+ end
31
+ rescue
32
+ nil
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -3,32 +3,17 @@ require 'json'
3
3
  module Bibliothecary
4
4
  module Parsers
5
5
  class Bower
6
- PLATFORM_NAME = 'bower'
6
+ include Bibliothecary::Analyser
7
7
 
8
8
  def self.parse(filename, file_contents)
9
- json = JSON.parse(file_contents)
10
9
  if filename.match(/^bower\.json$/)
10
+ json = JSON.parse(file_contents)
11
11
  parse_manifest(json)
12
12
  else
13
13
  []
14
14
  end
15
15
  end
16
16
 
17
- def self.analyse(folder_path, file_list)
18
- path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^bower\.json$/) }
19
- return unless path
20
-
21
- manifest = JSON.parse File.open(path).read
22
-
23
- {
24
- platform: PLATFORM_NAME,
25
- path: path,
26
- dependencies: parse_manifest(manifest)
27
- }
28
- rescue
29
- []
30
- end
31
-
32
17
  def self.parse_manifest(manifest)
33
18
  map_dependencies(manifest, 'dependencies', 'runtime') +
34
19
  map_dependencies(manifest, 'devDependencies', 'development')
@@ -3,41 +3,20 @@ require 'toml'
3
3
  module Bibliothecary
4
4
  module Parsers
5
5
  class Cargo
6
- PLATFORM_NAME = 'cargo'
6
+ include Bibliothecary::Analyser
7
7
 
8
8
  def self.parse(filename, file_contents)
9
- toml = TOML.parse(file_contents)
10
9
  if filename.match(/Cargo\.toml$/)
10
+ toml = TOML.parse(file_contents)
11
11
  parse_manifest(toml)
12
12
  elsif filename.match(/Cargo\.lock$/)
13
+ toml = TOML.parse(file_contents)
13
14
  parse_lockfile(toml)
14
15
  else
15
16
  []
16
17
  end
17
18
  end
18
19
 
19
- def self.analyse(folder_path, file_list)
20
- [analyse_cargo_toml(folder_path, file_list),
21
- analyse_cargo_lock(folder_path, file_list)].flatten
22
- end
23
-
24
- def self.analyse_cargo_toml(folder_path, file_list)
25
- paths = file_list.select{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/Cargo\.toml$/) }
26
- return unless paths.any?
27
-
28
- paths.map do |path|
29
- manifest = TOML.load_file(path)
30
-
31
- {
32
- platform: PLATFORM_NAME,
33
- path: path,
34
- dependencies: parse_manifest(manifest)
35
- }
36
- end
37
- rescue
38
- []
39
- end
40
-
41
20
  def self.parse_manifest(manifest)
42
21
  manifest.fetch('dependencies', []).map do |name, requirement|
43
22
  {
@@ -1,7 +1,7 @@
1
1
  module Bibliothecary
2
2
  module Parsers
3
3
  class Carthage
4
- PLATFORM_NAME = 'Carthage'
4
+ include Bibliothecary::Analyser
5
5
 
6
6
  def self.parse(filename, file_contents)
7
7
  if filename.match(/^Cartfile$/)
@@ -15,59 +15,6 @@ module Bibliothecary
15
15
  end
16
16
  end
17
17
 
18
- def self.analyse(folder_path, file_list)
19
- [
20
- analyse_cartfile(folder_path, file_list),
21
- analyse_cartfile_private(folder_path, file_list),
22
- analyse_cartfile_resolved(folder_path, file_list)
23
- ]
24
- end
25
-
26
- def self.analyse_cartfile(folder_path, file_list)
27
- path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^Cartfile$/) }
28
- return unless path
29
-
30
- manifest = parse_cartfile(File.open(path).read)
31
-
32
- {
33
- platform: PLATFORM_NAME,
34
- path: path,
35
- dependencies: manifest.dependencies
36
- }
37
- rescue
38
- []
39
- end
40
-
41
- def self.analyse_cartfile_private(folder_path, file_list)
42
- path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^Cartfile\.private$/) }
43
- return unless path
44
-
45
- manifest = parse_cartfile_private(File.open(path).read)
46
-
47
- {
48
- platform: PLATFORM_NAME,
49
- path: path,
50
- dependencies: manifest.dependencies
51
- }
52
- rescue
53
- []
54
- end
55
-
56
- def self.analyse_cartfile_resolved(folder_path, file_list)
57
- path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^Cartfile\.resolved$/) }
58
- return unless path
59
-
60
- manifest = parse_cartfile_resolved(File.open(path).read)
61
-
62
- {
63
- platform: PLATFORM_NAME,
64
- path: path,
65
- dependencies: manifest.dependencies
66
- }
67
- rescue
68
- []
69
- end
70
-
71
18
  def self.parse_cartfile(manifest)
72
19
  response = Typhoeus.post("https://carthageparser.herokuapp.com/cartfile", params: {body: manifest})
73
20
  json = JSON.parse(response.body)
@@ -4,7 +4,7 @@ require 'typhoeus'
4
4
  module Bibliothecary
5
5
  module Parsers
6
6
  class Clojars
7
- PLATFORM_NAME = 'clojars'
7
+ include Bibliothecary::Analyser
8
8
 
9
9
  def self.parse(filename, file_contents)
10
10
  if filename.match(/^project\.clj$/)
@@ -14,25 +14,6 @@ module Bibliothecary
14
14
  end
15
15
  end
16
16
 
17
- def self.analyse(folder_path, file_list)
18
- [analyse_manifest(folder_path, file_list)]
19
- end
20
-
21
- def self.analyse_manifest(folder_path, file_list)
22
- path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^project\.clj$/) }
23
- return unless path
24
-
25
- manifest = JSON.parse File.open(path).read
26
-
27
- {
28
- platform: PLATFORM_NAME,
29
- path: path,
30
- dependencies: parse_json_manifest(manifest)
31
- }
32
- rescue
33
- []
34
- end
35
-
36
17
  def self.parse_manifest(manifest)
37
18
  response = Typhoeus.post("https://clojars-json.herokuapp.com/project.clj", body: manifest)
38
19
  json = JSON.parse response.body
@@ -4,13 +4,12 @@ require 'yaml'
4
4
  module Bibliothecary
5
5
  module Parsers
6
6
  class CocoaPods
7
+ include Bibliothecary::Analyser
8
+
7
9
  NAME_VERSION = '(?! )(.*?)(?: \(([^-]*)(?:-(.*))?\))?'.freeze
8
10
  NAME_VERSION_4 = /^ {4}#{NAME_VERSION}$/
9
11
 
10
- PLATFORM_NAME = 'CocoaPods'
11
-
12
12
  def self.parse(filename, file_contents)
13
-
14
13
  if filename.match(/^Podfile$/)
15
14
  manifest = Gemnasium::Parser.send(:podfile, file_contents)
16
15
  parse_manifest(manifest)
@@ -28,79 +27,6 @@ module Bibliothecary
28
27
  end
29
28
  end
30
29
 
31
- def self.analyse(folder_path, file_list)
32
- [
33
- analyse_podfile(folder_path, file_list),
34
- analyse_podspec(folder_path, file_list),
35
- analyse_podfile_lock(folder_path, file_list),
36
- analyse_podspec_json(folder_path, file_list)
37
- ].flatten
38
- end
39
-
40
- def self.analyse_podfile(folder_path, file_list)
41
- path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^Podfile$/) }
42
- return unless path
43
-
44
- manifest = Gemnasium::Parser.send(:podfile, File.open(path).read)
45
-
46
- {
47
- platform: PLATFORM_NAME,
48
- path: path,
49
- dependencies: parse_manifest(manifest)
50
- }
51
- rescue
52
- []
53
- end
54
-
55
- def self.analyse_podspec(folder_path, file_list)
56
- paths = file_list.select{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^[A-Za-z0-9_-]+\.podspec$/) }
57
- return unless paths.any?
58
-
59
- paths.map do |path|
60
- manifest = Gemnasium::Parser.send(:podspec, File.open(path).read)
61
-
62
- {
63
- platform: PLATFORM_NAME,
64
- path: path,
65
- dependencies: parse_manifest(manifest)
66
- }
67
- end
68
- rescue
69
- []
70
- end
71
-
72
- def self.analyse_podspec_json(folder_path, file_list)
73
- paths = file_list.select{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^[A-Za-z0-9_-]+\.podspec.json$/) }
74
- return unless paths.any?
75
-
76
- paths.map do |path|
77
- manifest = JSON.parse File.open(path).read
78
-
79
- {
80
- platform: PLATFORM_NAME,
81
- path: path,
82
- dependencies: parse_json_manifest(manifest)
83
- }
84
- end
85
- rescue
86
- []
87
- end
88
-
89
- def self.analyse_podfile_lock(folder_path, file_list)
90
- path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^Podfile\.lock$/) }
91
- return unless path
92
-
93
- manifest = YAML.load File.open(path).read
94
-
95
- {
96
- platform: PLATFORM_NAME,
97
- path: path,
98
- dependencies: parse_podfile_lock(manifest)
99
- }
100
- rescue
101
- []
102
- end
103
-
104
30
  def self.parse_podfile_lock(manifest)
105
31
  manifest['PODS'].map do |row|
106
32
  pod = row.is_a?(String) ? row : row.keys.first
@@ -4,7 +4,7 @@ require 'json'
4
4
  module Bibliothecary
5
5
  module Parsers
6
6
  class CPAN
7
- PLATFORM_NAME = 'cpan'
7
+ include Bibliothecary::Analyser
8
8
 
9
9
  def self.parse(filename, file_contents)
10
10
  if filename.match(/^META\.json$/i)
@@ -18,41 +18,6 @@ module Bibliothecary
18
18
  end
19
19
  end
20
20
 
21
- def self.analyse(folder_path, file_list)
22
- [analyse_json(folder_path, file_list),
23
- analyse_yaml(folder_path, file_list)]
24
- end
25
-
26
- def self.analyse_json(folder_path, file_list)
27
- path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^META\.json$/i) }
28
- return unless path
29
-
30
- manifest = JSON.parse File.open(path).read
31
-
32
- {
33
- platform: PLATFORM_NAME,
34
- path: path,
35
- dependencies: parse_json_manifest(manifest)
36
- }
37
- rescue
38
- []
39
- end
40
-
41
- def self.analyse_yaml(folder_path, file_list)
42
- path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^META\.yml$/i) }
43
- return unless path
44
-
45
- manifest = YAML.load File.open(path).read
46
-
47
- {
48
- platform: PLATFORM_NAME,
49
- path: path,
50
- dependencies: parse_yaml_manifest(manifest)
51
- }
52
- rescue
53
- []
54
- end
55
-
56
21
  def self.parse_json_manifest(manifest)
57
22
  manifest['prereqs'].map do |group, deps|
58
23
  map_dependencies(deps, 'requires', 'runtime')
@@ -3,7 +3,8 @@ require 'deb_control'
3
3
  module Bibliothecary
4
4
  module Parsers
5
5
  class CRAN
6
- PLATFORM_NAME = 'cran'
6
+ include Bibliothecary::Analyser
7
+
7
8
  REQUIRE_REGEXP = /([a-zA-Z0-9\-_\.]+)\s?\(?([><=\s\d\.,]+)?\)?/
8
9
 
9
10
  def self.parse(filename, file_contents)
@@ -15,25 +16,6 @@ module Bibliothecary
15
16
  end
16
17
  end
17
18
 
18
- def self.analyse(folder_path, file_list)
19
- [analyse_description(folder_path, file_list)]
20
- end
21
-
22
- def self.analyse_description(folder_path, file_list)
23
- path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^DESCRIPTION$/i) }
24
- return unless path
25
-
26
- manifest = DebControl::ControlFileBase.parse File.open(path).read
27
-
28
- {
29
- platform: PLATFORM_NAME,
30
- path: path,
31
- dependencies: parse_description(manifest)
32
- }
33
- rescue
34
- []
35
- end
36
-
37
19
  def self.parse_description(manifest)
38
20
  parse_section(manifest, 'Depends') +
39
21
  parse_section(manifest, 'Imports') +
@@ -4,7 +4,7 @@ require 'sdl_parser'
4
4
  module Bibliothecary
5
5
  module Parsers
6
6
  class Dub
7
- PLATFORM_NAME = 'dub'
7
+ include Bibliothecary::Analyser
8
8
 
9
9
  def self.parse(filename, file_contents)
10
10
  if filename.match(/^dub\.json$/)
@@ -17,41 +17,6 @@ module Bibliothecary
17
17
  end
18
18
  end
19
19
 
20
- def self.analyse(folder_path, file_list)
21
- [analyse_json(folder_path, file_list),
22
- analyse_sdl(folder_path, file_list)]
23
- end
24
-
25
- def self.analyse_json(folder_path, file_list)
26
- path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^dub\.json$/) }
27
- return unless path
28
-
29
- manifest = JSON.parse File.open(path).read
30
-
31
- {
32
- platform: PLATFORM_NAME,
33
- path: path,
34
- dependencies: parse_manifest(manifest)
35
- }
36
- rescue
37
- []
38
- end
39
-
40
- def self.analyse_sdl(folder_path, file_list)
41
- path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^dub\.sdl$/) }
42
- return unless path
43
-
44
- manifest = File.open(path).read
45
-
46
- {
47
- platform: PLATFORM_NAME,
48
- path: path,
49
- dependencies: parse_sdl_manifest(manifest)
50
- }
51
- rescue
52
- []
53
- end
54
-
55
20
  def self.parse_manifest(manifest)
56
21
  map_dependencies(manifest, 'dependencies', 'runtime')
57
22
  end
@@ -3,7 +3,7 @@ require 'json'
3
3
  module Bibliothecary
4
4
  module Parsers
5
5
  class Elm
6
- PLATFORM_NAME = 'elm'
6
+ include Bibliothecary::Analyser
7
7
 
8
8
  def self.parse(filename, file_contents)
9
9
  if filename.match(/^elm-package\.json$|^elm_dependencies\.json$/)
@@ -4,7 +4,7 @@ require 'json'
4
4
  module Bibliothecary
5
5
  module Parsers
6
6
  class Go
7
- PLATFORM_NAME = 'go'
7
+ include Bibliothecary::Analyser
8
8
 
9
9
  def self.parse(filename, file_contents)
10
10
  if filename.match(/^glide\.yaml$/)
@@ -24,73 +24,6 @@ module Bibliothecary
24
24
  end
25
25
  end
26
26
 
27
- def self.analyse(folder_path, file_list)
28
- [analyse_glide_yaml(folder_path, file_list),
29
- analyse_glide_lockfile(folder_path, file_list),
30
- analyse_godep_json(folder_path, file_list),
31
- analyse_gb_manifest(folder_path, file_list)]
32
- end
33
-
34
- def self.analyse_godep_json(folder_path, file_list)
35
- path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^Godeps\/Godeps\.json$/) }
36
- return unless path
37
-
38
- manifest = JSON.parse File.open(path).read
39
-
40
- {
41
- platform: PLATFORM_NAME,
42
- path: path,
43
- dependencies: parse_godep_json(manifest)
44
- }
45
- rescue
46
- []
47
- end
48
-
49
- def self.analyse_gb_manifest(folder_path, file_list)
50
- path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^vendor\/manifest$/) }
51
- return unless path
52
-
53
- manifest = JSON.parse File.open(path).read
54
-
55
- {
56
- platform: PLATFORM_NAME,
57
- path: path,
58
- dependencies: parse_gb_manifest(manifest)
59
- }
60
- rescue
61
- []
62
- end
63
-
64
- def self.analyse_glide_yaml(folder_path, file_list)
65
- path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^glide\.yaml$/) }
66
- return unless path
67
-
68
- manifest = YAML.load File.open(path).read
69
-
70
- {
71
- platform: PLATFORM_NAME,
72
- path: path,
73
- dependencies: parse_glide_yaml(manifest)
74
- }
75
- rescue
76
- []
77
- end
78
-
79
- def self.analyse_glide_lockfile(folder_path, file_list)
80
- path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^glide\.lock$/) }
81
- return unless path
82
-
83
- manifest = YAML.load File.open(path).read
84
-
85
- {
86
- platform: PLATFORM_NAME,
87
- path: path,
88
- dependencies: parse_glide_lockfile(manifest)
89
- }
90
- rescue
91
- []
92
- end
93
-
94
27
  def self.parse_godep_json(manifest)
95
28
  manifest.fetch('Deps',[]).map do |dependency|
96
29
  {
@@ -3,7 +3,7 @@ require 'json'
3
3
  module Bibliothecary
4
4
  module Parsers
5
5
  class Hex
6
- PLATFORM_NAME = 'hex'
6
+ include Bibliothecary::Analyser
7
7
 
8
8
  def self.parse(filename, file_contents)
9
9
  if filename.match(/^mix\.exs$/)
@@ -15,37 +15,6 @@ module Bibliothecary
15
15
  end
16
16
  end
17
17
 
18
- def self.analyse(folder_path, file_list)
19
- [analyse_mix(folder_path, file_list),
20
- analyse_mix_lock(folder_path, file_list)]
21
- end
22
-
23
- def self.analyse_mix(folder_path, file_list)
24
- path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^mix\.exs$/) }
25
- return unless path
26
-
27
- manifest = File.open(path).read
28
-
29
- {
30
- platform: PLATFORM_NAME,
31
- path: path,
32
- dependencies: parse_mix(manifest)
33
- }
34
- end
35
-
36
- def self.analyse_mix_lock(folder_path, file_list)
37
- path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^mix\.lock$/) }
38
- return unless path
39
-
40
- manifest = File.open(path).read
41
-
42
- {
43
- platform: PLATFORM_NAME,
44
- path: path,
45
- dependencies: parse_mix_lock(manifest)
46
- }
47
- end
48
-
49
18
  def self.parse_mix(manifest)
50
19
  response = Typhoeus.post("https://mix-deps-json.herokuapp.com/", body: manifest)
51
20
  json = JSON.parse response.body
@@ -1,7 +1,7 @@
1
1
  module Bibliothecary
2
2
  module Parsers
3
3
  class Julia
4
- PLATFORM_NAME = 'julia'
4
+ include Bibliothecary::Analyser
5
5
 
6
6
  def self.parse(filename, file_contents)
7
7
  if filename.match(/^REQUIRE$/i)
@@ -11,25 +11,6 @@ module Bibliothecary
11
11
  end
12
12
  end
13
13
 
14
- def self.analyse(folder_path, file_list)
15
- [analyse_json(folder_path, file_list)]
16
- end
17
-
18
- def self.analyse_json(folder_path, file_list)
19
- path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^REQUIRE$/i) }
20
- return unless path
21
-
22
- manifest = File.open(path).read
23
-
24
- {
25
- platform: PLATFORM_NAME,
26
- path: path,
27
- dependencies: parse_require(manifest)
28
- }
29
- rescue
30
- []
31
- end
32
-
33
14
  def self.parse_require(manifest)
34
15
  manifest.split("\n").map do |line|
35
16
  match = line.split(/\s/)
@@ -3,7 +3,7 @@ require 'ox'
3
3
  module Bibliothecary
4
4
  module Parsers
5
5
  class Maven
6
- PLATFORM_NAME = 'Maven'
6
+ include Bibliothecary::Analyser
7
7
 
8
8
  def self.parse(filename, file_contents)
9
9
  if filename.match(/ivy\.xml$/i)
@@ -19,65 +19,6 @@ module Bibliothecary
19
19
  end
20
20
  end
21
21
 
22
- def self.analyse(folder_path, file_list)
23
- [
24
- analyse_pom(folder_path, file_list),
25
- analyse_ivy(folder_path, file_list),
26
- analyse_gradle(folder_path, file_list),
27
- ].flatten
28
- end
29
-
30
- def self.analyse_pom(folder_path, file_list)
31
- paths = file_list.select{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/pom\.xml$/i) }
32
- return unless paths.any?
33
-
34
- paths.map do |path|
35
- manifest = Ox.parse File.open(path).read
36
-
37
- {
38
- platform: PLATFORM_NAME,
39
- path: path,
40
- dependencies: parse_pom_manifest(manifest)
41
- }
42
- end
43
- rescue
44
- []
45
- end
46
-
47
- def self.analyse_ivy(folder_path, file_list)
48
- paths = file_list.select{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/ivy\.xml$/i) }
49
- return unless paths.any?
50
-
51
- paths.map do |path|
52
- manifest = Ox.parse File.open(path).read
53
-
54
- {
55
- platform: PLATFORM_NAME,
56
- path: path,
57
- dependencies: parse_ivy_manifest(manifest)
58
- }
59
- end
60
- rescue
61
- []
62
- end
63
-
64
- def self.analyse_gradle(folder_path, file_list)
65
- paths = file_list.select{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/build\.gradle$/i) }
66
- return unless paths.any?
67
-
68
- paths.map do |path|
69
- manifest = File.open(path).read
70
-
71
- {
72
- platform: PLATFORM_NAME,
73
- path: path,
74
- dependencies: parse_gradle(manifest)
75
- }
76
- end
77
- rescue
78
- []
79
- end
80
-
81
22
  def self.parse_ivy_manifest(manifest)
82
23
  manifest.dependencies.locate('dependency').map do |dependency|
83
24
  attrs = dependency.attributes
@@ -3,32 +3,17 @@ require 'json'
3
3
  module Bibliothecary
4
4
  module Parsers
5
5
  class Meteor
6
- PLATFORM_NAME = 'meteor'
6
+ include Bibliothecary::Analyser
7
7
 
8
8
  def self.parse(filename, file_contents)
9
- json = JSON.parse(file_contents)
10
9
  if filename.match(/^versions\.json$/)
10
+ json = JSON.parse(file_contents)
11
11
  parse_manifest(json)
12
12
  else
13
13
  []
14
14
  end
15
15
  end
16
16
 
17
- def self.analyse(folder_path, file_list)
18
- path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^versions\.json$/) }
19
- return unless path
20
-
21
- manifest = JSON.parse File.open(path).read
22
-
23
- {
24
- platform: PLATFORM_NAME,
25
- path: path,
26
- dependencies: parse_manifest(manifest)
27
- }
28
- rescue
29
- []
30
- end
31
-
32
17
  def self.parse_manifest(manifest)
33
18
  map_dependencies(manifest, 'dependencies', 'runtime')
34
19
  end
@@ -3,54 +3,20 @@ require 'json'
3
3
  module Bibliothecary
4
4
  module Parsers
5
5
  class NPM
6
- PLATFORM_NAME = 'npm'
6
+ include Bibliothecary::Analyser
7
7
 
8
8
  def self.parse(filename, file_contents)
9
- json = JSON.parse(file_contents)
10
9
  if filename.match(/^package\.json$/)
10
+ json = JSON.parse(file_contents)
11
11
  parse_manifest(json)
12
12
  elsif filename.match(/^npm-shrinkwrap\.json$/)
13
+ json = JSON.parse(file_contents)
13
14
  parse_shrinkwrap(json)
14
15
  else
15
16
  []
16
17
  end
17
18
  end
18
19
 
19
- def self.analyse(folder_path, file_list)
20
- [analyse_package_json(folder_path, file_list),
21
- analyse_shrinkwrap(folder_path, file_list)]
22
- end
23
-
24
- def self.analyse_package_json(folder_path, file_list)
25
- path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^package\.json$/) }
26
- return unless path
27
-
28
- manifest = JSON.parse File.open(path).read
29
-
30
- {
31
- platform: PLATFORM_NAME,
32
- path: path,
33
- dependencies: parse_manifest(manifest)
34
- }
35
- rescue
36
- []
37
- end
38
-
39
- def self.analyse_shrinkwrap(folder_path, file_list)
40
- path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^npm-shrinkwrap\.json$/) }
41
- return unless path
42
-
43
- manifest = JSON.parse File.open(path).read
44
-
45
- {
46
- platform: PLATFORM_NAME,
47
- path: path,
48
- dependencies: parse_shrinkwrap(manifest)
49
- }
50
- rescue
51
- []
52
- end
53
-
54
20
  def self.parse_shrinkwrap(manifest)
55
21
  manifest.fetch('dependencies',[]).map do |name, requirement|
56
22
  {
@@ -4,7 +4,7 @@ require 'json'
4
4
  module Bibliothecary
5
5
  module Parsers
6
6
  class Nuget
7
- PLATFORM_NAME = 'nuget'
7
+ include Bibliothecary::Analyser
8
8
 
9
9
  def self.parse(filename, file_contents)
10
10
  if filename.match(/Project\.json$/)
@@ -26,98 +26,6 @@ module Bibliothecary
26
26
  end
27
27
  end
28
28
 
29
- def self.analyse(folder_path, file_list)
30
- [analyse_project_json(folder_path, file_list),
31
- analyse_project_lock_json(folder_path, file_list),
32
- analyse_packages_config(folder_path, file_list),
33
- analyse_nuspec(folder_path, file_list),
34
- analyse_paket_lock(folder_path, file_list)].flatten
35
- end
36
-
37
- def self.analyse_project_json(folder_path, file_list)
38
- paths = file_list.select{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/Project\.json$/i) }
39
- return unless paths.any?
40
-
41
- paths.map do |path|
42
- manifest = JSON.parse File.open(path).read
43
-
44
- {
45
- platform: PLATFORM_NAME,
46
- path: path,
47
- dependencies: parse_project_json(manifest)
48
- }
49
- end
50
- rescue
51
- []
52
- end
53
-
54
- def self.analyse_project_lock_json(folder_path, file_list)
55
- paths = file_list.select{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/Project\.lock\.json$/) }
56
- return unless paths.any?
57
-
58
- paths.map do |path|
59
- manifest = JSON.parse File.open(path).read
60
-
61
- {
62
- platform: PLATFORM_NAME,
63
- path: path,
64
- dependencies: parse_project_lock_json(manifest)
65
- }
66
- end
67
- rescue
68
- []
69
- end
70
-
71
- def self.analyse_packages_config(folder_path, file_list)
72
- paths = file_list.select{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/packages\.config$/) }
73
- return unless paths.any?
74
-
75
- paths.map do |path|
76
- manifest = Ox.parse File.open(path).read
77
-
78
- {
79
- platform: PLATFORM_NAME,
80
- path: path,
81
- dependencies: parse_packages_config(manifest)
82
- }
83
- end
84
- rescue
85
- []
86
- end
87
-
88
- def self.analyse_nuspec(folder_path, file_list)
89
- paths = file_list.select{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^[A-Za-z0-9_-]+\.nuspec$/) }
90
- return unless paths.any?
91
-
92
- paths.map do |path|
93
- manifest = Ox.parse File.open(path).read
94
-
95
- {
96
- platform: PLATFORM_NAME,
97
- path: path,
98
- dependencies: parse_nuspec(manifest)
99
- }
100
- end
101
- rescue
102
- []
103
- end
104
-
105
- def self.analyse_paket_lock(folder_path, file_list)
106
- paths = file_list.select{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/paket\.lock$/) }
107
- return unless paths.any?
108
-
109
- paths.map do |path|
110
- lines = File.readlines(path)
111
- {
112
- platform: PLATFORM_NAME,
113
- path: path,
114
- dependencies: parse_paket_lock(lines)
115
- }
116
- end
117
- rescue
118
- []
119
- end
120
-
121
29
  def self.parse_project_json(manifest)
122
30
  manifest.fetch('dependencies',[]).map do |name, requirement|
123
31
  {
@@ -3,54 +3,20 @@ require 'json'
3
3
  module Bibliothecary
4
4
  module Parsers
5
5
  class Packagist
6
- PLATFORM_NAME = 'Packagist'
6
+ include Bibliothecary::Analyser
7
7
 
8
8
  def self.parse(filename, file_contents)
9
- json = JSON.parse(file_contents)
10
9
  if filename.match(/^composer\.json$/)
10
+ json = JSON.parse(file_contents)
11
11
  parse_manifest(json)
12
12
  elsif filename.match(/^composer\.lock$/)
13
+ json = JSON.parse(file_contents)
13
14
  parse_lockfile(json)
14
15
  else
15
16
  []
16
17
  end
17
18
  end
18
19
 
19
- def self.analyse(folder_path, file_list)
20
- [analyse_composer_json(folder_path, file_list),
21
- analyse_composer_lock(folder_path, file_list)]
22
- end
23
-
24
- def self.analyse_composer_json(folder_path, file_list)
25
- path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^composer\.json$/) }
26
- return unless path
27
-
28
- manifest = JSON.parse File.open(path).read
29
-
30
- {
31
- platform: PLATFORM_NAME,
32
- path: path,
33
- dependencies: parse_manifest(manifest)
34
- }
35
- rescue
36
- []
37
- end
38
-
39
- def self.analyse_composer_lock(folder_path, file_list)
40
- path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^composer\.lock$/) }
41
- return unless path
42
-
43
- manifest = JSON.parse File.open(path).read
44
-
45
- {
46
- platform: PLATFORM_NAME,
47
- path: path,
48
- dependencies: parse_lockfile(manifest)
49
- }
50
- rescue
51
- []
52
- end
53
-
54
20
  def self.parse_lockfile(manifest)
55
21
  manifest.fetch('packages',[]).map do |dependency|
56
22
  {
@@ -3,56 +3,20 @@ require 'yaml'
3
3
  module Bibliothecary
4
4
  module Parsers
5
5
  class Pub
6
- PLATFORM_NAME = 'Pub'
6
+ include Bibliothecary::Analyser
7
7
 
8
8
  def self.parse(filename, file_contents)
9
- yaml = YAML.load file_contents
10
9
  if filename.match(/^pubspec\.yaml$/i)
10
+ yaml = YAML.load file_contents
11
11
  parse_yaml_manifest(yaml)
12
12
  elsif filename.match(/^pubspec\.lock$/i)
13
+ yaml = YAML.load file_contents
13
14
  parse_yaml_lockfile(yaml)
14
15
  else
15
16
  []
16
17
  end
17
18
  end
18
19
 
19
- def self.analyse(folder_path, file_list)
20
- [
21
- analyse_yaml(folder_path, file_list),
22
- analyse_lockfile(folder_path, file_list)
23
- ]
24
- end
25
-
26
- def self.analyse_yaml(folder_path, file_list)
27
- path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^pubspec\.yaml$/i) }
28
- return unless path
29
-
30
- manifest = YAML.load File.open(path).read
31
-
32
- {
33
- platform: PLATFORM_NAME,
34
- path: path,
35
- dependencies: parse_yaml_manifest(manifest)
36
- }
37
- rescue
38
- []
39
- end
40
-
41
- def self.analyse_lockfile(folder_path, file_list)
42
- path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^pubspec\.lock$/i) }
43
- return unless path
44
-
45
- manifest = YAML.load File.open(path).read
46
-
47
- {
48
- platform: PLATFORM_NAME,
49
- path: path,
50
- dependencies: parse_yaml_lockfile(manifest)
51
- }
52
- rescue
53
- []
54
- end
55
-
56
20
  def self.parse_yaml_manifest(manifest)
57
21
  map_dependencies(manifest, 'dependencies', 'runtime') +
58
22
  map_dependencies(manifest, 'dev_dependencies', 'development')
@@ -1,7 +1,8 @@
1
1
  module Bibliothecary
2
2
  module Parsers
3
3
  class Pypi
4
- PLATFORM_NAME = 'pypi'
4
+ include Bibliothecary::Analyser
5
+
5
6
  INSTALL_REGEXP = /install_requires\s*=\s*\[([\s\S]*?)\]/
6
7
  REQUIRE_REGEXP = /([a-zA-Z0-9]+[a-zA-Z0-9\-_\.]+)([><=\d\.,]+)?/
7
8
  REQUIREMENTS_REGEXP = /^#{REQUIRE_REGEXP}/
@@ -17,48 +18,6 @@ module Bibliothecary
17
18
  end
18
19
  end
19
20
 
20
- def self.analyse(folder_path, file_list)
21
- [analyse_requirements_txt(folder_path, file_list),
22
- analyse_setup_py(folder_path, file_list)].flatten
23
- end
24
-
25
- def self.analyse_requirements_txt(folder_path, file_list)
26
- paths = file_list.select do |path|
27
- p = path.gsub(folder_path, '').gsub(/^\//, '')
28
- p.match(/require.*\.(txt|pip)$/) && !path.match(/^node_modules/)
29
- end
30
- return unless paths.any?
31
-
32
- paths.map do |path|
33
- manifest = File.open(path).read
34
-
35
- {
36
- platform: PLATFORM_NAME,
37
- path: path,
38
- dependencies: parse_requirements_txt(manifest)
39
- }
40
- end
41
- rescue
42
- []
43
- end
44
-
45
- def self.analyse_setup_py(folder_path, file_list)
46
- paths = file_list.select{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/setup\.py$/) }
47
- return unless paths.any?
48
-
49
- paths.map do |path|
50
- manifest = File.open(path).read
51
-
52
- {
53
- platform: PLATFORM_NAME,
54
- path: path,
55
- dependencies: parse_setup_py(manifest)
56
- }
57
- end
58
- rescue
59
- []
60
- end
61
-
62
21
  def self.parse_setup_py(manifest)
63
22
  match = manifest.match(INSTALL_REGEXP)
64
23
  return [] unless match
@@ -3,9 +3,10 @@ require 'gemnasium/parser'
3
3
  module Bibliothecary
4
4
  module Parsers
5
5
  class Rubygems
6
+ include Bibliothecary::Analyser
7
+
6
8
  NAME_VERSION = '(?! )(.*?)(?: \(([^-]*)(?:-(.*))?\))?'.freeze
7
9
  NAME_VERSION_4 = /^ {4}#{NAME_VERSION}$/
8
- PLATFORM_NAME = 'Rubygems'
9
10
 
10
11
  def self.parse(filename, file_contents)
11
12
  if filename.match(/^Gemfile$|^gems\.rb$/)
@@ -21,61 +22,6 @@ module Bibliothecary
21
22
  end
22
23
  end
23
24
 
24
- def self.analyse(folder_path, file_list)
25
- [
26
- analyse_gemfile(folder_path, file_list),
27
- analyse_gemspec(folder_path, file_list),
28
- analyse_gemfile_lock(folder_path, file_list)
29
- ].flatten
30
- end
31
-
32
- def self.analyse_gemfile(folder_path, file_list)
33
- path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^Gemfile$|^gems\.rb$/) }
34
- return unless path
35
-
36
- manifest = Gemnasium::Parser.send(:gemfile, File.open(path).read)
37
-
38
- {
39
- platform: PLATFORM_NAME,
40
- path: path,
41
- dependencies: parse_manifest(manifest)
42
- }
43
- rescue
44
- []
45
- end
46
-
47
- def self.analyse_gemspec(folder_path, file_list)
48
- paths = file_list.select{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/[A-Za-z0-9_-]+\.gemspec$/) }
49
- return unless paths.any?
50
-
51
- paths.map do |path|
52
- manifest = Gemnasium::Parser.send(:gemspec, File.open(path).read)
53
-
54
- {
55
- platform: PLATFORM_NAME,
56
- path: path,
57
- dependencies: parse_manifest(manifest)
58
- }
59
- end
60
- rescue
61
- []
62
- end
63
-
64
- def self.analyse_gemfile_lock(folder_path, file_list)
65
- path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^Gemfile\.lock$|^gems\.locked$/) }
66
- return unless path
67
-
68
- manifest = File.open(path).read
69
-
70
- {
71
- platform: PLATFORM_NAME,
72
- path: path,
73
- dependencies: parse_gemfile_lock(manifest)
74
- }
75
- rescue
76
- []
77
- end
78
-
79
25
  def self.parse_gemfile_lock(manifest)
80
26
  manifest.split("\n").map do |line|
81
27
  match = line.match(NAME_VERSION_4)
@@ -3,7 +3,7 @@ require 'yaml'
3
3
  module Bibliothecary
4
4
  module Parsers
5
5
  class Shard
6
- PLATFORM_NAME = 'shard'
6
+ include Bibliothecary::Analyser
7
7
 
8
8
  def self.parse(filename, file_contents)
9
9
  if filename.match(/^shard\.yml$/i)
@@ -17,41 +17,6 @@ module Bibliothecary
17
17
  end
18
18
  end
19
19
 
20
- def self.analyse(folder_path, file_list)
21
- [analyse_yaml_manifest(folder_path, file_list),
22
- analyse_yaml_lockfile(folder_path, file_list)]
23
- end
24
-
25
- def self.analyse_yaml_manifest(folder_path, file_list)
26
- path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^shard\.yml$/i) }
27
- return unless path
28
-
29
- manifest = YAML.load File.open(path).read
30
-
31
- {
32
- platform: PLATFORM_NAME,
33
- path: path,
34
- dependencies: parse_yaml_manifest(manifest)
35
- }
36
- rescue
37
- []
38
- end
39
-
40
- def self.analyse_yaml_lockfile(folder_path, file_list)
41
- path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^shard\.lock$/i) }
42
- return unless path
43
-
44
- manifest = YAML.load File.open(path).read
45
-
46
- {
47
- platform: PLATFORM_NAME,
48
- path: path,
49
- dependencies: parse_yaml_lockfile(manifest)
50
- }
51
- rescue
52
- []
53
- end
54
-
55
20
  def self.parse_yaml_lockfile(manifest)
56
21
  map_dependencies(manifest, 'shards', 'runtime')
57
22
  end
@@ -1,7 +1,7 @@
1
1
  module Bibliothecary
2
2
  module Parsers
3
3
  class Swift
4
- PLATFORM_NAME = 'swift'
4
+ include Bibliothecary::Analyser
5
5
 
6
6
  def self.parse(filename, file_contents)
7
7
  if filename.match(/^Package\.swift$/i)
@@ -11,25 +11,6 @@ module Bibliothecary
11
11
  end
12
12
  end
13
13
 
14
- def self.analyse(folder_path, file_list)
15
- [analyse_package_swift(folder_path, file_list)]
16
- end
17
-
18
- def self.analyse_package_swift(folder_path, file_list)
19
- path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^Package\.swift$/i) }
20
- return unless path
21
-
22
- manifest = File.open(path).read
23
-
24
- {
25
- platform: PLATFORM_NAME,
26
- path: path,
27
- dependencies: parse_package_swift(manifest)
28
- }
29
- rescue
30
- []
31
- end
32
-
33
14
  def self.parse_package_swift(manifest)
34
15
  response = Typhoeus.post("http://192.241.154.173/to-json", body: manifest)
35
16
  json = JSON.parse(response.body)
@@ -1,3 +1,3 @@
1
1
  module Bibliothecary
2
- VERSION = "1.4.2"
2
+ VERSION = "2.0.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bibliothecary
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Nesbitt
@@ -156,6 +156,7 @@ files:
156
156
  - bin/console
157
157
  - bin/setup
158
158
  - lib/bibliothecary.rb
159
+ - lib/bibliothecary/analyser.rb
159
160
  - lib/bibliothecary/parsers/bower.rb
160
161
  - lib/bibliothecary/parsers/cargo.rb
161
162
  - lib/bibliothecary/parsers/carthage.rb