bibliothecary 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 27c5f2c6e7c8a86659db4ec13a4b7068f864a01e
4
- data.tar.gz: 71bc2a31d0137d9e41e5b645489c5317cc152316
3
+ metadata.gz: 4ff29254b4b1268e9918db8491344bf0711d7e91
4
+ data.tar.gz: 94432e857d325e1027090256a4c7a1c988f34249
5
5
  SHA512:
6
- metadata.gz: d11ce1f103ed476d0feb33379872e079c3139748e4f13e236b8e4e2b4e11aa7fa02f9948a7f628a07514dd19264ec6358e2d18ca47df7f154f03a23ecca5633e
7
- data.tar.gz: 86ef971a46ba1c859f5272c1ccd90fae9e149dffed024b48c439ee82a0cfa9fa8b4e8b45efb962552afbfe0f3f2c21d873e80011c7735ae6fcdb572d16eefa88
6
+ metadata.gz: 063ebc1e296edddf39c00b451186deabf69594f9430e8a80e0d49a00b47ebdbdf302c14e0f1ec953b17580575dbf265c456ef0979cd9c0105e5b21eedc5995fe
7
+ data.tar.gz: b23f49b418ed67fd59e49cf83875e8fad372891272825b7e04f3d1a74ce38af5c315da30d7e40387d319b4cd12961852e3bdf41ef0b9eff62bbdb73742676460
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.add_dependency "toml-rb", "~> 0.3.9"
22
22
  spec.add_dependency "librariesio-gem-parser"
23
23
  spec.add_dependency "rogdl"
24
+ spec.add_dependency "ox"
24
25
 
25
26
  spec.add_development_dependency "bundler", "~> 1.11"
26
27
  spec.add_development_dependency "rake", "~> 11.0"
@@ -1,2 +1,90 @@
1
- # pom.xml
2
- # ivy.xml
1
+ require 'ox'
2
+
3
+ module Bibliothecary
4
+ module Parsers
5
+ class Maven
6
+ PLATFORM_NAME = 'Maven'
7
+
8
+ def self.parse(filename, file_contents)
9
+ if filename.match(/^ivy\.xml$/i)
10
+ xml = Ox.parse file_contents
11
+ parse_ivy_manifest(xml)
12
+ elsif filename.match(/^pom\.xml$/i)
13
+ xml = Ox.parse file_contents
14
+ parse_pom_manifest(xml)
15
+ else
16
+ []
17
+ end
18
+ end
19
+
20
+ def self.analyse(folder_path, file_list)
21
+ [analyse_pom(folder_path, file_list),
22
+ analyse_ivy(folder_path, file_list)]
23
+ end
24
+
25
+ def self.analyse_pom(folder_path, file_list)
26
+ path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^pom\.xml$/i) }
27
+ return unless path
28
+
29
+ manifest = Ox.parse File.open(path).read
30
+
31
+ {
32
+ platform: PLATFORM_NAME,
33
+ path: path,
34
+ dependencies: parse_pom_manifest(manifest)
35
+ }
36
+ end
37
+
38
+ def self.analyse_ivy(folder_path, file_list)
39
+ path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^ivy.xml$/i) }
40
+ return unless path
41
+ p path
42
+ manifest = Ox.parse File.open(path).read
43
+
44
+ {
45
+ platform: PLATFORM_NAME,
46
+ path: path,
47
+ dependencies: parse_ivy_manifest(manifest)
48
+ }
49
+ end
50
+
51
+ def self.parse_ivy_manifest(manifest)
52
+ manifest.dependencies.locate('dependency').map do |dependency|
53
+ attrs = dependency.attributes
54
+ {
55
+ name: "#{attrs[:org]}:#{attrs[:name]}",
56
+ requirement: attrs[:rev],
57
+ type: 'runtime'
58
+ }
59
+ end
60
+ end
61
+
62
+ def self.parse_pom_manifest(manifest)
63
+ manifest.project.dependencies.locate('dependency').map do |dependency|
64
+
65
+ {
66
+ name: "#{extract_pom_dep_info(manifest, dependency, 'groupId')}:#{extract_pom_dep_info(manifest, dependency, 'artifactId')}",
67
+ requirement: extract_pom_dep_info(manifest, dependency, 'version'),
68
+ type: extract_pom_dep_info(manifest, dependency, 'scope') || 'runtime'
69
+ }
70
+ end
71
+ end
72
+
73
+ def self.extract_pom_dep_info(manifest, dependency, name)
74
+ field = dependency.locate(name).first
75
+ return nil if field.nil?
76
+ value = field.nodes.first
77
+ if match = value.match(/^\$\{(.+)\}/)
78
+ prop_field = manifest.project.properties.locate(match[1]).first
79
+ if prop_field
80
+ return prop_field.nodes.first
81
+ else
82
+ return value
83
+ end
84
+ else
85
+ return value
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
@@ -1,3 +1,3 @@
1
1
  module Bibliothecary
2
- VERSION = "0.4.1"
2
+ VERSION = "0.5.0"
3
3
  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: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Nesbitt
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-06-25 00:00:00.000000000 Z
11
+ date: 2016-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: toml-rb
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: ox
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: bundler
57
71
  requirement: !ruby/object:Gem::Requirement