bibliothecary 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bibliothecary/parsers/nuget.rb +129 -0
- data/lib/bibliothecary/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d09609af06ff90acc9e928e6cfac9af9a0e6d62
|
4
|
+
data.tar.gz: 98f3c12650a3aac6c2a960175fd1e82327796846
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44006e900e3cb44762387bf238ba22f773ece9963838ee8713b0631f5478699eb2af8356b8bb5c6daae3cfa417c386696594b30b5cc45a7a7faf363f2dd84fa1
|
7
|
+
data.tar.gz: 5a997a385c0c3eb040ce623ffad8a24d1be20d2ae575d107e70a5571eb01d0191b83a6f357b93a35e37f50e2d82024c6479b62c4287046caf91c52f0735ba433
|
@@ -2,3 +2,132 @@
|
|
2
2
|
# Project.json
|
3
3
|
# Project.lock.json
|
4
4
|
# *.nuspec
|
5
|
+
|
6
|
+
require 'ox'
|
7
|
+
require 'json'
|
8
|
+
|
9
|
+
module Bibliothecary
|
10
|
+
module Parsers
|
11
|
+
class Nuget
|
12
|
+
PLATFORM_NAME = 'nuget'
|
13
|
+
|
14
|
+
def self.parse(filename, file_contents)
|
15
|
+
if filename.match(/Project\.json$/)
|
16
|
+
json = JSON.parse file_contents
|
17
|
+
parse_project_json(json)
|
18
|
+
elsif filename.match(/Project\.lock\.json$/)
|
19
|
+
json = JSON.parse file_contents
|
20
|
+
parse_project_lock_json(json)
|
21
|
+
elsif filename.match(/packages\.config$/)
|
22
|
+
xml = Ox.parse file_contents
|
23
|
+
parse_packages_config(xml)
|
24
|
+
elsif filename.match(/^[A-Za-z0-9_-]+\.nuspec$/)
|
25
|
+
xml = Ox.parse file_contents
|
26
|
+
parse_nuspec(xml)
|
27
|
+
else
|
28
|
+
[]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.analyse(folder_path, file_list)
|
33
|
+
[analyse_project_json(folder_path, file_list),
|
34
|
+
analyse_project_lock_json(folder_path, file_list),
|
35
|
+
analyse_packages_config(folder_path, file_list),
|
36
|
+
analyse_nuspec(folder_path, file_list)]
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.analyse_project_json(folder_path, file_list)
|
40
|
+
path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/Project\.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_project_json(manifest)
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.analyse_project_lock_json(folder_path, file_list)
|
53
|
+
path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/Project\.lock\.json$/) }
|
54
|
+
return unless path
|
55
|
+
|
56
|
+
manifest = JSON.parse File.open(path).read
|
57
|
+
|
58
|
+
{
|
59
|
+
platform: PLATFORM_NAME,
|
60
|
+
path: path,
|
61
|
+
dependencies: parse_project_lock_json(manifest)
|
62
|
+
}
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.analyse_packages_config(folder_path, file_list)
|
66
|
+
path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/packages\.config$/) }
|
67
|
+
return unless path
|
68
|
+
|
69
|
+
manifest = Ox.parse File.open(path).read
|
70
|
+
|
71
|
+
{
|
72
|
+
platform: PLATFORM_NAME,
|
73
|
+
path: path,
|
74
|
+
dependencies: parse_packages_config(manifest)
|
75
|
+
}
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.analyse_nuspec(folder_path, file_list)
|
79
|
+
path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^[A-Za-z0-9_-]+\.nuspec$/) }
|
80
|
+
return unless path
|
81
|
+
|
82
|
+
manifest = Ox.parse File.open(path).read
|
83
|
+
|
84
|
+
{
|
85
|
+
platform: PLATFORM_NAME,
|
86
|
+
path: path,
|
87
|
+
dependencies: parse_nuspec(manifest)
|
88
|
+
}
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.parse_project_json(manifest)
|
92
|
+
manifest.fetch('dependencies',[]).map do |name, requirement|
|
93
|
+
{
|
94
|
+
name: name,
|
95
|
+
requirement: requirement,
|
96
|
+
type: 'runtime'
|
97
|
+
}
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def self.parse_project_lock_json(manifest)
|
102
|
+
manifest.fetch('libraries',[]).map do |name, requirement|
|
103
|
+
dep = name.split('/')
|
104
|
+
{
|
105
|
+
name: dep[0],
|
106
|
+
requirement: dep[1],
|
107
|
+
type: 'runtime'
|
108
|
+
}
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def self.parse_packages_config(manifest)
|
113
|
+
manifest.packages.locate('package').map do |dependency|
|
114
|
+
{
|
115
|
+
name: dependency.id,
|
116
|
+
version: dependency.version,
|
117
|
+
type: 'runtime'
|
118
|
+
}
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def self.parse_nuspec(manifest)
|
123
|
+
manifest.package.metadata.dependencies.locate('dependency').map do |dependency|
|
124
|
+
{
|
125
|
+
name: dependency.id,
|
126
|
+
version: dependency.attributes[:version] || '*',
|
127
|
+
type: 'runtime'
|
128
|
+
}
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|