bibliothecary 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -2
  3. data/Gemfile +0 -2
  4. data/bibliothecary.gemspec +1 -1
  5. data/lib/bibliothecary.rb +5 -20
  6. data/lib/bibliothecary/parsers/bower.rb +46 -0
  7. data/lib/bibliothecary/parsers/cargo.rb +71 -0
  8. data/lib/bibliothecary/{carthage.rb → parsers/carthage.rb} +0 -0
  9. data/lib/bibliothecary/{clojars.rb → parsers/clojars.rb} +0 -0
  10. data/lib/bibliothecary/parsers/cocoapods.rb +98 -0
  11. data/lib/bibliothecary/parsers/cpan.rb +73 -0
  12. data/lib/bibliothecary/{dub.rb → parsers/dub.rb} +0 -0
  13. data/lib/bibliothecary/{elm.rb → parsers/elm.rb} +0 -0
  14. data/lib/bibliothecary/{go.rb → parsers/go.rb} +0 -0
  15. data/lib/bibliothecary/{hex.rb → parsers/hex.rb} +0 -0
  16. data/lib/bibliothecary/{julia.rb → parsers/julia.rb} +0 -0
  17. data/lib/bibliothecary/{maven.rb → parsers/maven.rb} +0 -0
  18. data/lib/bibliothecary/parsers/meteor.rb +45 -0
  19. data/lib/bibliothecary/parsers/npm.rb +76 -0
  20. data/lib/bibliothecary/{nuget.rb → parsers/nuget.rb} +0 -0
  21. data/lib/bibliothecary/parsers/packagist.rb +76 -0
  22. data/lib/bibliothecary/parsers/pub.rb +78 -0
  23. data/lib/bibliothecary/{pypi.rb → parsers/pypi.rb} +0 -0
  24. data/lib/bibliothecary/parsers/rubygems.rb +96 -0
  25. data/lib/bibliothecary/version.rb +1 -1
  26. metadata +22 -22
  27. data/lib/bibliothecary/bower.rb +0 -33
  28. data/lib/bibliothecary/cargo.rb +0 -56
  29. data/lib/bibliothecary/cocoapods.rb +0 -78
  30. data/lib/bibliothecary/cpan.rb +0 -57
  31. data/lib/bibliothecary/meteor.rb +0 -32
  32. data/lib/bibliothecary/npm.rb +0 -61
  33. data/lib/bibliothecary/packagist.rb +0 -61
  34. data/lib/bibliothecary/pub.rb +0 -63
  35. data/lib/bibliothecary/rubygems.rb +0 -79
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 65c59d771e14a3bdebce2df1c81abe890d08bd33
4
- data.tar.gz: ec8af4d1651955605c0d665609e2201ad513e331
3
+ metadata.gz: 02faff8131e3124d6ba5ce3a74805c61ccfd5757
4
+ data.tar.gz: 56a75db0780b803b9df037ae13417396a4345804
5
5
  SHA512:
6
- metadata.gz: 89943196ec0463c826854cb5a96e36c3d62cadfccf7c2f72ddb935bdf6d9954fbd8cb2d168ea6200d3b99b5cc53d2bb4be06cfc728893e5fe5642d7499a000cd
7
- data.tar.gz: ac188514b31f06874f2b08c0a71c851fbb80f0208474398808c78ea9df1f8bcdb79ff91032970592aa5f7b809e3bd3c6c1ac11610e05b0f00f018804ea495118
6
+ metadata.gz: 05201570924d5b58d953a6cce071d20d699b25c7009b48b31bc23ff8cc7dc6e642187e48eb1670e7df7d554086e84ad0abfc990c194aa6564128038fc80b90fd
7
+ data.tar.gz: 039dd8629e9ea67d9668f488d40615486f8931639f7ed30ff7af01a538236ebacf6c7ad5f1b5f08c0b928402afee24f5926a39748de82d80c37c8e59e8093d0f
@@ -1,4 +1,4 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.3.0
4
- before_install: gem install bundler -v 1.11.2
3
+ - 2.3.1
4
+ cache: bundler
data/Gemfile CHANGED
@@ -2,5 +2,3 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in bibliothecary.gemspec
4
4
  gemspec
5
-
6
- gem 'gemnasium-parser', github: 'librariesio/gemnasium-parser'
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency "toml-rb", "~> 0.3.9"
22
- spec.add_dependency "gemnasium-parser"
22
+ spec.add_dependency "librariesio-gem-parser"
23
23
 
24
24
  spec.add_development_dependency "bundler", "~> 1.11"
25
25
  spec.add_development_dependency "rake", "~> 11.0"
@@ -1,13 +1,8 @@
1
1
  require "bibliothecary/version"
2
- require "bibliothecary/npm"
3
- require "bibliothecary/bower"
4
- require "bibliothecary/packagist"
5
- require "bibliothecary/cpan"
6
- require "bibliothecary/meteor"
7
- require "bibliothecary/cargo"
8
- require "bibliothecary/pub"
9
- require "bibliothecary/rubygems"
10
- require "bibliothecary/cocoapods"
2
+
3
+ Dir[File.expand_path('../bibliothecary/parsers/*.rb', __FILE__)].each do |file|
4
+ require file
5
+ end
11
6
 
12
7
  module Bibliothecary
13
8
  def self.analyse(path)
@@ -17,17 +12,7 @@ module Bibliothecary
17
12
  end
18
13
 
19
14
  def self.package_managers
20
- [
21
- NPM,
22
- Bower,
23
- Packagist,
24
- CPAN,
25
- Meteor,
26
- Cargo,
27
- Pub,
28
- Rubygems,
29
- CocoaPods
30
- ]
15
+ Bibliothecary::Parsers.constants.map{|c| Bibliothecary::Parsers.const_get(c) }
31
16
  end
32
17
 
33
18
  def self.ignored_files
@@ -0,0 +1,46 @@
1
+ require 'json'
2
+
3
+ module Bibliothecary
4
+ module Parsers
5
+ class Bower
6
+ PLATFORM_NAME = 'bower'
7
+
8
+ def self.parse(filename, file_contents)
9
+ json = JSON.parse(file_contents)
10
+ if filename.match(/^bower\.json$/)
11
+ parse_manifest(json)
12
+ else
13
+ []
14
+ end
15
+ end
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
+ end
29
+
30
+ def self.parse_manifest(manifest)
31
+ map_dependencies(manifest, 'dependencies', 'runtime') +
32
+ map_dependencies(manifest, 'devDependencies', 'development')
33
+ end
34
+
35
+ def self.map_dependencies(hash, key, type)
36
+ hash.fetch(key,[]).map do |name, requirement|
37
+ {
38
+ name: name,
39
+ requirement: requirement,
40
+ type: type
41
+ }
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,71 @@
1
+ require 'toml'
2
+
3
+ module Bibliothecary
4
+ module Parsers
5
+ class Cargo
6
+ PLATFORM_NAME = 'cargo'
7
+
8
+ def self.parse(filename, file_contents)
9
+ toml = TOML.parse(file_contents)
10
+ if filename.match(/^Cargo\.toml$/)
11
+ parse_manifest(toml)
12
+ elsif filename.match(/^Cargo\.lock$/)
13
+ parse_lockfile(toml)
14
+ else
15
+ []
16
+ end
17
+ end
18
+
19
+ def self.analyse(folder_path, file_list)
20
+ [analyse_cargo_toml(folder_path, file_list),
21
+ analyse_cargo_lock(folder_path, file_list)]
22
+ end
23
+
24
+ def self.analyse_cargo_toml(folder_path, file_list)
25
+ path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^Cargo\.toml$/) }
26
+ return unless path
27
+
28
+ manifest = TOML.load_file(path)
29
+
30
+ {
31
+ platform: PLATFORM_NAME,
32
+ path: path,
33
+ dependencies: parse_manifest(manifest)
34
+ }
35
+ end
36
+
37
+ def self.parse_manifest(manifest)
38
+ manifest.fetch('dependencies', []).map do |name, requirement|
39
+ {
40
+ name: name,
41
+ requirement: requirement,
42
+ type: 'runtime'
43
+ }
44
+ end
45
+ end
46
+
47
+ def self.analyse_cargo_lock(folder_path, file_list)
48
+ path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^Cargo\.lock$/) }
49
+ return unless path
50
+
51
+ manifest = TOML.load_file(path)
52
+
53
+ {
54
+ platform: PLATFORM_NAME,
55
+ path: path,
56
+ dependencies: parse_lockfile(manifest)
57
+ }
58
+ end
59
+
60
+ def self.parse_lockfile(manifest)
61
+ manifest.fetch('package',[]).map do |dependency|
62
+ {
63
+ name: dependency['name'],
64
+ requirement: dependency['version'],
65
+ type: 'runtime'
66
+ }
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,98 @@
1
+ require 'gemnasium/parser'
2
+ require 'yaml'
3
+
4
+ module Bibliothecary
5
+ module Parsers
6
+ class CocoaPods
7
+ NAME_VERSION = '(?! )(.*?)(?: \(([^-]*)(?:-(.*))?\))?'.freeze
8
+ NAME_VERSION_4 = /^ {4}#{NAME_VERSION}$/
9
+
10
+ PLATFORM_NAME = 'CocoaPods'
11
+
12
+ def self.parse(filename, file_contents)
13
+
14
+ if filename.match(/^Podfile$/)
15
+ manifest = Gemnasium::Parser.send(:podfile, file_contents)
16
+ parse_manifest(manifest)
17
+ elsif filename.match(/^[A-Za-z0-9_-]+\.podspec$/)
18
+ manifest = Gemnasium::Parser.send(:podspec, file_contents)
19
+ parse_manifest(manifest)
20
+ elsif filename.match(/^Podfile\.lock$/)
21
+ manifest = YAML.load file_contents
22
+ parse_podfile_lock(manifest)
23
+ else
24
+ []
25
+ end
26
+ end
27
+
28
+ def self.analyse(folder_path, file_list)
29
+ [
30
+ analyse_podfile(folder_path, file_list),
31
+ analyse_podspec(folder_path, file_list),
32
+ analyse_podfile_lock(folder_path, file_list)
33
+ ]
34
+ end
35
+
36
+ def self.analyse_podfile(folder_path, file_list)
37
+ path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^Podfile$/) }
38
+ return unless path
39
+
40
+ manifest = Gemnasium::Parser.send(:podfile, File.open(path).read)
41
+
42
+ {
43
+ platform: PLATFORM_NAME,
44
+ path: path,
45
+ dependencies: parse_manifest(manifest)
46
+ }
47
+ end
48
+
49
+ def self.analyse_podspec(folder_path, file_list)
50
+ path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^[A-Za-z0-9_-]+\.podspec$/) }
51
+ return unless path
52
+
53
+ manifest = Gemnasium::Parser.send(:podspec, File.open(path).read)
54
+
55
+ {
56
+ platform: PLATFORM_NAME,
57
+ path: path,
58
+ dependencies: parse_manifest(manifest)
59
+ }
60
+ end
61
+
62
+ def self.analyse_podfile_lock(folder_path, file_list)
63
+ path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^Podfile\.lock$/) }
64
+ return unless path
65
+
66
+ manifest = YAML.load File.open(path).read
67
+
68
+ {
69
+ platform: PLATFORM_NAME,
70
+ path: path,
71
+ dependencies: parse_podfile_lock(manifest)
72
+ }
73
+ end
74
+
75
+ def self.parse_podfile_lock(manifest)
76
+ manifest['PODS'].map do |row|
77
+ pod = row.is_a?(String) ? row : row.keys.first
78
+ match = pod.match(/(.+?)\s\((.+?)\)/i)
79
+ {
80
+ name: match[1].split('/').first,
81
+ requirement: match[2],
82
+ type: 'runtime'
83
+ }
84
+ end.compact
85
+ end
86
+
87
+ def self.parse_manifest(manifest)
88
+ manifest.dependencies.inject([]) do |deps, dep|
89
+ deps.push({
90
+ name: dep.name,
91
+ requirement: dep.requirement.to_s,
92
+ type: dep.type
93
+ })
94
+ end.uniq
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,73 @@
1
+ require 'yaml'
2
+ require 'json'
3
+
4
+ module Bibliothecary
5
+ module Parsers
6
+ class CPAN
7
+ PLATFORM_NAME = 'cpan'
8
+
9
+ def self.parse(filename, file_contents)
10
+ if filename.match(/^META\.json$/i)
11
+ json = JSON.parse file_contents
12
+ parse_json_manifest(json)
13
+ elsif filename.match(/^META\.yml$/i)
14
+ yaml = YAML.load file_contents
15
+ parse_yaml_manifest(yaml)
16
+ else
17
+ []
18
+ end
19
+ end
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
+ end
38
+
39
+ def self.analyse_yaml(folder_path, file_list)
40
+ path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^META\.yml$/i) }
41
+ return unless path
42
+
43
+ manifest = YAML.load File.open(path).read
44
+
45
+ {
46
+ platform: PLATFORM_NAME,
47
+ path: path,
48
+ dependencies: parse_yaml_manifest(manifest)
49
+ }
50
+ end
51
+
52
+ def self.parse_json_manifest(manifest)
53
+ manifest['prereqs'].map do |group, deps|
54
+ map_dependencies(deps, 'requires', 'runtime')
55
+ end.flatten
56
+ end
57
+
58
+ def self.parse_yaml_manifest(manifest)
59
+ map_dependencies(manifest, 'requires', 'runtime')
60
+ end
61
+
62
+ def self.map_dependencies(hash, key, type)
63
+ hash.fetch(key,[]).map do |name, requirement|
64
+ {
65
+ name: name,
66
+ requirement: requirement,
67
+ type: type
68
+ }
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,45 @@
1
+ require 'json'
2
+
3
+ module Bibliothecary
4
+ module Parsers
5
+ class Meteor
6
+ PLATFORM_NAME = 'meteor'
7
+
8
+ def self.parse(filename, file_contents)
9
+ json = JSON.parse(file_contents)
10
+ if filename.match(/^versions\.json$/)
11
+ parse_manifest(json)
12
+ else
13
+ []
14
+ end
15
+ end
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
+ end
29
+
30
+ def self.parse_manifest(manifest)
31
+ map_dependencies(manifest, 'dependencies', 'runtime')
32
+ end
33
+
34
+ def self.map_dependencies(hash, key, type)
35
+ hash.fetch(key,[]).map do |name, requirement|
36
+ {
37
+ name: name,
38
+ requirement: requirement,
39
+ type: type
40
+ }
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,76 @@
1
+ require 'json'
2
+
3
+ module Bibliothecary
4
+ module Parsers
5
+ class NPM
6
+ PLATFORM_NAME = 'npm'
7
+
8
+ def self.parse(filename, file_contents)
9
+ json = JSON.parse(file_contents)
10
+ if filename.match(/^package\.json$/)
11
+ parse_manifest(json)
12
+ elsif filename.match(/^npm-shrinkwrap\.json$/)
13
+ parse_shrinkwrap(json)
14
+ else
15
+ []
16
+ end
17
+ end
18
+
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
+ end
36
+
37
+ def self.analyse_shrinkwrap(folder_path, file_list)
38
+ path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^npm-shrinkwrap\.json$/) }
39
+ return unless path
40
+
41
+ manifest = JSON.parse File.open(path).read
42
+
43
+ {
44
+ platform: PLATFORM_NAME,
45
+ path: path,
46
+ dependencies: parse_shrinkwrap(manifest)
47
+ }
48
+ end
49
+
50
+ def self.parse_shrinkwrap(manifest)
51
+ manifest.fetch('dependencies',[]).map do |name, requirement|
52
+ {
53
+ name: name,
54
+ requirement: requirement["version"],
55
+ type: 'runtime'
56
+ }
57
+ end
58
+ end
59
+
60
+ def self.parse_manifest(manifest)
61
+ map_dependencies(manifest, 'dependencies', 'runtime') +
62
+ map_dependencies(manifest, 'devDependencies', 'development')
63
+ end
64
+
65
+ def self.map_dependencies(hash, key, type)
66
+ hash.fetch(key,[]).map do |name, requirement|
67
+ {
68
+ name: name,
69
+ requirement: requirement,
70
+ type: type
71
+ }
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end