polisher 0.10.2 → 0.11.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (180) hide show
  1. checksums.yaml +4 -4
  2. data/bin/binary_gem_resolver.rb +2 -2
  3. data/bin/bundler2yum.rb +51 -0
  4. data/bin/check_ruby_spec.rb +32 -0
  5. data/bin/gem_dependency_checker.rb +13 -242
  6. data/bin/gem_mapper.rb +27 -0
  7. data/bin/gems2update.rb +27 -0
  8. data/bin/git_gem_diff.rb +48 -0
  9. data/bin/git_gem_updater.rb +3 -3
  10. data/bin/missing_deps.rb +29 -0
  11. data/bin/polisher-config.rb +17 -0
  12. data/bin/ruby_rpm_spec_updater.rb +23 -2
  13. data/lib/polisher.rb +5 -12
  14. data/lib/polisher/adaptors/checker_loader.rb +78 -0
  15. data/lib/polisher/{upstream.rb → adaptors/upstream.rb} +1 -0
  16. data/lib/polisher/adaptors/version_checker.rb +57 -0
  17. data/lib/polisher/adaptors/version_checker/bodhi.rb +29 -0
  18. data/lib/polisher/adaptors/version_checker/errata.rb +29 -0
  19. data/lib/polisher/adaptors/version_checker/fedora.rb +29 -0
  20. data/lib/polisher/adaptors/version_checker/gem.rb +27 -0
  21. data/lib/polisher/adaptors/version_checker/git.rb +29 -0
  22. data/lib/polisher/adaptors/version_checker/koji.rb +29 -0
  23. data/lib/polisher/adaptors/version_checker/yum.rb +29 -0
  24. data/lib/polisher/cli/all.rb +22 -0
  25. data/lib/polisher/cli/bin/gem_dependency_checker.rb +85 -0
  26. data/lib/polisher/cli/bin/gem_mapper.rb +37 -0
  27. data/lib/polisher/cli/bin/gems2update.rb +86 -0
  28. data/lib/polisher/cli/bin/missing_deps.rb +35 -0
  29. data/lib/polisher/cli/conf.rb +18 -0
  30. data/lib/polisher/cli/default.rb +25 -0
  31. data/lib/polisher/cli/format.rb +130 -0
  32. data/lib/polisher/cli/sources.rb +106 -0
  33. data/lib/polisher/cli/specifier.rb +30 -0
  34. data/lib/polisher/cli/status.rb +50 -0
  35. data/lib/polisher/cli/targets.rb +88 -0
  36. data/lib/polisher/gem.rb +41 -338
  37. data/lib/polisher/gem/attributes.rb +20 -0
  38. data/lib/polisher/gem/dependencies.rb +63 -0
  39. data/lib/polisher/gem/diff.rb +39 -0
  40. data/lib/polisher/gem/files.rb +111 -0
  41. data/lib/polisher/gem/parser.rb +85 -0
  42. data/lib/polisher/gem/retriever.rb +137 -0
  43. data/lib/polisher/{gem_state.rb → gem/state.rb} +6 -6
  44. data/lib/polisher/gem/versions.rb +131 -0
  45. data/lib/polisher/gemfile.rb +20 -89
  46. data/lib/polisher/gemfile/attributes.rb +19 -0
  47. data/lib/polisher/gemfile/deps.rb +43 -0
  48. data/lib/polisher/gemfile/parser.rb +45 -0
  49. data/lib/polisher/git/pkg.rb +33 -238
  50. data/lib/polisher/git/pkg/attributes.rb +60 -0
  51. data/lib/polisher/git/pkg/builder.rb +47 -0
  52. data/lib/polisher/git/pkg/repo.rb +82 -0
  53. data/lib/polisher/git/pkg/updater.rb +53 -0
  54. data/lib/polisher/git/pkg/versions.rb +40 -0
  55. data/lib/polisher/git/project.rb +1 -1
  56. data/lib/polisher/git/repo.rb +79 -76
  57. data/lib/polisher/{vendor.rb → mixins/vendored_deps.rb} +4 -7
  58. data/lib/polisher/mixins/versioned_dependencies.rb +86 -0
  59. data/lib/polisher/record.rb +2 -0
  60. data/lib/polisher/rpm.rb +23 -0
  61. data/lib/polisher/rpm/patch.rb +10 -8
  62. data/lib/polisher/rpm/requirement.rb +33 -189
  63. data/lib/polisher/rpm/requirement/attributes.rb +43 -0
  64. data/lib/polisher/rpm/requirement/comparison.rb +97 -0
  65. data/lib/polisher/rpm/requirement/gem_reference.rb +46 -0
  66. data/lib/polisher/rpm/requirement/parser.rb +41 -0
  67. data/lib/polisher/rpm/spec.rb +97 -436
  68. data/lib/polisher/rpm/spec/check.rb +14 -0
  69. data/lib/polisher/rpm/spec/comparison.rb +64 -0
  70. data/lib/polisher/rpm/spec/files.rb +15 -0
  71. data/lib/polisher/rpm/spec/gem_files.rb +65 -0
  72. data/lib/polisher/rpm/spec/gem_reference.rb +59 -0
  73. data/lib/polisher/rpm/spec/gem_requirements.rb +73 -0
  74. data/lib/polisher/rpm/spec/parser.rb +106 -0
  75. data/lib/polisher/rpm/spec/requirements.rb +31 -0
  76. data/lib/polisher/rpm/spec/subpackages.rb +23 -0
  77. data/lib/polisher/rpm/spec/updater.rb +268 -0
  78. data/lib/polisher/specifier.rb +13 -0
  79. data/lib/polisher/targets.rb +36 -0
  80. data/lib/polisher/{apt.rb → targets/apt.rb} +1 -1
  81. data/lib/polisher/targets/bodhi.rb +43 -0
  82. data/lib/polisher/{bugzilla.rb → targets/bugzilla.rb} +1 -1
  83. data/lib/polisher/targets/errata.rb +55 -0
  84. data/lib/polisher/targets/errata/build.rb +24 -0
  85. data/lib/polisher/targets/fedora.rb +47 -0
  86. data/lib/polisher/targets/koji.rb +39 -0
  87. data/lib/polisher/targets/koji/builder.rb +38 -0
  88. data/lib/polisher/targets/koji/diff.rb +39 -0
  89. data/lib/polisher/targets/koji/rpc.rb +43 -0
  90. data/lib/polisher/targets/koji/versions.rb +67 -0
  91. data/lib/polisher/targets/rhn.rb +12 -0
  92. data/lib/polisher/targets/yum.rb +36 -0
  93. data/lib/polisher/{component.rb → util/component.rb} +3 -3
  94. data/lib/polisher/util/conf_helpers.rb +77 -0
  95. data/lib/polisher/util/config.rb +45 -0
  96. data/lib/polisher/util/core_ext.rb +59 -0
  97. data/lib/polisher/{error.rb → util/error.rb} +0 -0
  98. data/lib/polisher/{gem_cache.rb → util/gem_cache.rb} +1 -1
  99. data/lib/polisher/{git_cache.rb → util/git_cache.rb} +0 -0
  100. data/lib/polisher/{logger.rb → util/logger.rb} +2 -0
  101. data/lib/polisher/{tag_mapper.rb → util/tag_mapper.rb} +1 -1
  102. data/lib/polisher/version.rb +1 -1
  103. data/spec/{upstream_spec.rb → adaptors/upstream_spec.rb} +1 -1
  104. data/spec/{version_checker_spec.rb → adaptors/version_checker_spec.rb} +1 -6
  105. data/spec/data/activesupport-4.1.4.gem +0 -0
  106. data/spec/data/rubygem-activesupport-with-doc.spec +247 -0
  107. data/spec/data/rubygem-activesupport-without-requires.spec +232 -0
  108. data/spec/data/rubygem-activesupport.spec +0 -122
  109. data/spec/fixtures/gem_json.rb +49 -0
  110. data/spec/fixtures/gem_spec.rb +13 -0
  111. data/spec/fixtures/gemfile.rb +10 -0
  112. data/spec/fixtures/local_gem.rb +62 -0
  113. data/spec/fixtures/rpm_spec.rb +91 -0
  114. data/spec/gem/attributes_spec.rb +17 -0
  115. data/spec/gem/diff_spec.rb +80 -0
  116. data/spec/gem/files_spec.rb +171 -0
  117. data/spec/gem/parser_spec.rb +44 -0
  118. data/spec/gem/retriever_spec.rb +124 -0
  119. data/spec/gem/state_spec.rb +79 -0
  120. data/spec/gem/versions_spec.rb +148 -0
  121. data/spec/gem_spec.rb +5 -347
  122. data/spec/gemfile/deps_spec.rb +20 -0
  123. data/spec/gemfile/parser_spec.rb +26 -0
  124. data/spec/gemfile_spec.rb +0 -34
  125. data/spec/git/pkg/attributes_spec.rb +128 -0
  126. data/spec/git/pkg/builder_spec.rb +63 -0
  127. data/spec/git/pkg/repo_spec.rb +146 -0
  128. data/spec/git/pkg/updater_spec.rb +86 -0
  129. data/spec/git/pkg/versions_spec.rb +42 -0
  130. data/spec/git/pkg_spec.rb +21 -0
  131. data/spec/git/project_spec.rb +21 -0
  132. data/spec/git/repo_spec.rb +160 -0
  133. data/spec/{vendor_spec.rb → mixins/vendored_deps_spec.rb} +2 -4
  134. data/spec/mixins/versioned_dependencies_spec.rb +48 -0
  135. data/spec/rpm/patch_spec.rb +48 -0
  136. data/spec/rpm/requirement/attributes_spec.rb +34 -0
  137. data/spec/rpm/requirement/comparison_spec.rb +286 -0
  138. data/spec/rpm/requirement/gem_spec.rb +49 -0
  139. data/spec/rpm/requirement/parser_spec.rb +31 -0
  140. data/spec/rpm/requirement_spec.rb +8 -334
  141. data/spec/rpm/spec/check_spec.rb +25 -0
  142. data/spec/rpm/spec/comparison_spec.rb +55 -0
  143. data/spec/rpm/spec/files_spec.rb +17 -0
  144. data/spec/rpm/spec/gem_files_spec.rb +112 -0
  145. data/spec/rpm/spec/gem_reference_spec.rb +99 -0
  146. data/spec/rpm/spec/gem_requirement_spec.rb +38 -0
  147. data/spec/rpm/spec/parser_spec.rb +64 -0
  148. data/spec/rpm/spec/requirements_spec.rb +10 -0
  149. data/spec/rpm/spec/subpackages_spec.rb +38 -0
  150. data/spec/rpm/spec/updater_spec.rb +486 -0
  151. data/spec/rpm/spec_spec.rb +27 -174
  152. data/spec/spec_helper.rb +7 -107
  153. data/spec/support/coveralls.rb +10 -0
  154. data/spec/support/fixtures.rb +8 -0
  155. data/spec/support/paths.rb +20 -0
  156. data/spec/support/rspec.rb +20 -0
  157. data/spec/support/vcr.rb +11 -0
  158. data/spec/{bodhi_spec.rb → targets/bodhi_spec.rb} +3 -1
  159. data/spec/{errata_spec.rb → targets/errata_spec.rb} +2 -2
  160. data/spec/{fedora_spec.rb → targets/fedora_spec.rb} +3 -3
  161. data/spec/targets/koji/builder_spec.rb +48 -0
  162. data/spec/targets/koji/diff_spec.rb +36 -0
  163. data/spec/targets/koji/rpc_spec.rb +28 -0
  164. data/spec/{koji_spec.rb → targets/koji/versions_spec.rb} +1 -59
  165. data/spec/targets/koji_spec.rb +11 -0
  166. data/spec/{yum_spec.rb → targets/yum_spec.rb} +1 -1
  167. data/spec/{component_spec.rb → util/component_spec.rb} +1 -1
  168. data/spec/{core_spec.rb → util/core_ext_spec.rb} +2 -3
  169. metadata +278 -88
  170. data/lib/polisher/bodhi.rb +0 -23
  171. data/lib/polisher/config.rb +0 -32
  172. data/lib/polisher/core.rb +0 -101
  173. data/lib/polisher/errata.rb +0 -75
  174. data/lib/polisher/fedora.rb +0 -46
  175. data/lib/polisher/git.rb +0 -8
  176. data/lib/polisher/koji.rb +0 -159
  177. data/lib/polisher/rhn.rb +0 -15
  178. data/lib/polisher/version_checker.rb +0 -177
  179. data/lib/polisher/yum.rb +0 -37
  180. data/spec/git_spec.rb +0 -445
@@ -4,21 +4,18 @@
4
4
  # Copyright (C) 2013-2014 Red Hat, Inc.
5
5
 
6
6
  module Polisher
7
- class Vendor
8
- end
9
-
10
7
  module HasVendoredDeps
11
8
  # Return list of file paths marked as vendored
12
9
  #
13
10
  # Scope which this module is being mixed into
14
11
  # must defined 'file_paths'
15
12
  def vendored_file_paths
16
- self.file_paths.select { |f| f.include?('vendor/') }
13
+ file_paths.select { |f| f.include?('vendor/') }
17
14
  end
18
15
 
19
16
  # Return list of vendered gems in file list
20
17
  def vendored
21
- vendored_file_paths.inject({}) do |v,fp|
18
+ vendored_file_paths.inject({}) do |v, fp|
22
19
  vendored_file = fp.split('/')
23
20
  vendor_index = vendored_file.index('vendor')
24
21
 
@@ -27,8 +24,8 @@ module Polisher
27
24
 
28
25
  vname = vendored_file[vendor_index + 1]
29
26
  vversion = nil
30
- # TODO set vversion from version.rb:
31
- #vf.last.downcase == 'version.rb'
27
+ # TODO: set vversion from version.rb:
28
+ # vf.last.downcase == 'version.rb'
32
29
  v[vname] = vversion
33
30
  v
34
31
  end
@@ -0,0 +1,86 @@
1
+ # VersionedDependencies Mixin
2
+ #
3
+ # Licensed under the MIT license
4
+ # Copyright (C) 2013-2014 Red Hat, Inc.
5
+
6
+ module Polisher
7
+ # Mixin included in components that contain lists of dependencies
8
+ # which include version information
9
+ #
10
+ # Requires module define 'deps' method which returns list
11
+ # of gem names representing component dependencies. List
12
+ # will be iterated over, versions will be looked up
13
+ # recursively and returned
14
+ module VersionedDependencies
15
+ # Return specified dependency
16
+ def dependency_for(name)
17
+ deps.detect { |dep| dep.name == name }
18
+ end
19
+
20
+ # Return list of versions of dependencies of component.
21
+ def dependency_versions(args = {}, &bl)
22
+ versions = {}
23
+ args = {:recursive => true, :dev_deps => true, :versions => versions}.merge(args)
24
+ deps.each do |dep|
25
+ gem = Polisher::Gem.retrieve(dep.name)
26
+ versions.merge!(gem.versions(args, &bl))
27
+ end
28
+ versions
29
+ end
30
+
31
+ # Return mapping of gems to dependency versions
32
+ def dependency_tree(args = {}, &bl)
33
+ dependencies = {}
34
+ args = {:recursive => true,
35
+ :dev_deps => true,
36
+ :matching => :latest,
37
+ :dependencies => dependencies}.merge(args)
38
+
39
+ process = []
40
+ deps.each do |dep|
41
+ resolved = nil
42
+ begin
43
+ resolved = Polisher::Gem.matching(dep, args[:matching])
44
+ rescue
45
+ end
46
+ yield self, dep, resolved
47
+ process << resolved unless resolved.nil?
48
+ end
49
+
50
+ process.each { |dep|
51
+ dependencies.merge!(dep.dependency_tree(args, &bl))
52
+ }
53
+
54
+ dependencies
55
+ end
56
+
57
+ # Return missing dependencies
58
+ def missing_dependencies
59
+ missing = []
60
+ dependency_versions(:recursive => false).each do |pkg, target_versions|
61
+ found = false
62
+ target_versions.each do |_target, versions|
63
+ dependency = dependency_for(pkg)
64
+ found = versions.any? { |version| dependency.match?(pkg, version) }
65
+ end
66
+ missing << pkg unless found
67
+ end
68
+ missing
69
+ end
70
+
71
+ # Return bool indicating if all dependencies are satisfied
72
+ def dependencies_satisfied?
73
+ missing_dependencies.empty?
74
+ end
75
+
76
+ # Return list of states which gem dependencies are in
77
+ def dependency_states
78
+ states = {}
79
+ deps.each do |dep|
80
+ gem = Polisher::Gem.new :name => dep.name
81
+ states.merge dep.name => gem.state(:check => dep)
82
+ end
83
+ states
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,2 @@
1
+ # TODO use vcr / camcorder to record all requests & playback when needed
2
+ # (to optimize testing, development, w/ large data sets etc)
@@ -0,0 +1,23 @@
1
+ # RPM Module
2
+ #
3
+ # Licensed under the MIT license
4
+ # Copyright (C) 2013-2014 Red Hat, Inc.
5
+
6
+ require 'polisher/rpm/spec'
7
+
8
+ module Polisher
9
+ module RPM
10
+ # Use rpmdev-packager if it's available
11
+ def self.packager
12
+ require 'awesome_spawn'
13
+
14
+ @packager ||= AwesomeSpawn.run('/usr/bin/rpmdev-packager').output.chop
15
+ rescue AwesomeSpawn::NoSuchFileError
16
+ end
17
+
18
+ # Return the currently configured author
19
+ def self.current_author
20
+ ENV['POLISHER_AUTHOR'] || packager || Spec::AUTHOR
21
+ end
22
+ end # module RPM
23
+ end # module Polisher
@@ -9,35 +9,37 @@ module Polisher
9
9
  attr_accessor :title
10
10
  attr_accessor :content
11
11
 
12
- def initialize(args={})
12
+ def initialize(args = {})
13
13
  @title = args[:title]
14
14
  @content = args[:content]
15
15
  end
16
16
 
17
- def spec_line(n=0)
17
+ def spec_line(n = 0)
18
18
  "Patch#{n}: #{title}"
19
19
  end
20
20
 
21
21
  def self.from(diff)
22
- return diff.collect { |d| self.from(d) } if diff.is_a?(Array)
22
+ return diff.collect { |d| from(d) } if diff.is_a?(Array)
23
23
 
24
24
  result = {}
25
25
 
26
+
26
27
  in_diff = nil
28
+ diff_lines = ''
27
29
  diff.each_line do |line|
28
30
  if line =~ /diff -r ([^\s]+)+ ([^\s]+)+$/
29
- result[in_diff] = diff if in_diff
31
+ result[in_diff] = diff_lines if in_diff
30
32
  in_diff = $1.gsub(/a\//, '')
31
- diff = ''
33
+ diff_lines = ''
32
34
  elsif line =~ /Only in.*$/
33
- in_diff = nil
34
35
 
35
36
  else
36
- diff += line
37
+ diff_lines += line
37
38
  end
38
39
  end
40
+ result[in_diff] = diff_lines if in_diff
39
41
 
40
- result.collect { |t,c| self.new :title => t, :content => c }
42
+ result.collect { |t, c| new :title => t, :content => c }
41
43
  end
42
44
  end
43
45
  end
@@ -1,197 +1,41 @@
1
- # Polisher RPM Requirement Represenation
1
+ # Polisher RPM Requirement
2
2
  #
3
3
  # Licensed under the MIT license
4
4
  # Copyright (C) 2013-2014 Red Hat, Inc.
5
5
 
6
- require 'polisher/gem'
7
- require 'polisher/core'
8
- require 'polisher/component'
6
+ require 'polisher/util/conf_helpers'
9
7
 
10
- module Polisher
11
- deps = ['gem2rpm', 'versionomy', 'active_support/core_ext']
12
- Component.verify("RPM::Requirement", *deps) do
13
- module RPM
14
- class Requirement
15
- include ConfHelpers
16
-
17
- conf_attr :rubygem_prefix, 'rubygem'
18
- conf_attr :scl_prefix, '' # set to %{?scl_prefix} to enable scl's
19
-
20
- def self.prefix
21
- "#{scl_prefix}#{rubygem_prefix}"
22
- end
23
-
24
- # Bool indiciating if req is a BR
25
- attr_accessor :br
26
-
27
- # Name of requirement
28
- attr_accessor :name
29
-
30
- # Condition, eg >=, =, etc
31
- attr_accessor :condition
32
-
33
- # Version number
34
- attr_accessor :version
35
-
36
- # Requirement string
37
- def str
38
- sp = self.specifier
39
- sp.nil? ? "#{@name}" : "#{@name} #{sp}"
40
- end
41
-
42
- # Specified string
43
- def specifier
44
- @version.nil? ? nil : "#{@condition} #{@version}"
45
- end
46
-
47
- # Instantiate / return new rpm spec requirements from string
48
- def self.parse(str, opts={})
49
- stra = str.split
50
- br = str.include?('BuildRequires')
51
- name = condition = version = nil
52
-
53
- if str.include?('Requires')
54
- name = stra[1]
55
- condition = stra[2]
56
- version = stra[3]
57
-
58
- else
59
- name = stra[0]
60
- condition = stra[1]
61
- version = stra[2]
62
-
63
- end
64
-
65
- req = self.new({:name => name,
66
- :condition => condition,
67
- :version => version,
68
- :br => br}.merge(opts))
69
- req
70
- end
71
-
72
- # Instantiate / return new rpm spec requirements from gem dependency.
73
- #
74
- # Because a gem dependency may result in multiple spec requirements
75
- # this will always return an array of Requirement instances
76
- def self.from_gem_dep(gem_dep, br=false)
77
- gem_dep.requirement.to_s.split(',').collect { |req|
78
- expanded = Gem2Rpm::Helpers.expand_requirement [req.split]
79
- expanded.collect { |e|
80
- new :name => "#{prefix}(#{gem_dep.name})",
81
- :condition => e.first.to_s,
82
- :version => e.last.to_s,
83
- :br => br
84
- }
85
- }.flatten
86
- end
8
+ require 'polisher/rpm/requirement/attributes'
9
+ require 'polisher/rpm/requirement/parser'
10
+ require 'polisher/rpm/requirement/comparison'
87
11
 
88
- def initialize(args={})
89
- @br = args[:br] || false
90
- @name = args[:name]
91
- @condition = args[:condition]
92
- @version = args[:version]
12
+ require 'polisher/rpm/requirement/gem_reference'
93
13
 
94
- @name.strip! unless @name.nil?
95
- @condition.strip! unless @condition.nil?
96
- @version.strip! unless @version.nil?
97
- end
98
-
99
- def ==(other)
100
- @br == other.br &&
101
- @name == other.name &&
102
- @condition == other.condition &&
103
- @version == other.version
104
- end
105
-
106
- # Greatest Common Denominator,
107
- # Max version in list that is less than the local version
108
- def gcd(versions)
109
- lversion = Versionomy.parse(self.version)
110
- versions.collect { |v| Versionomy.parse(v) }.
111
- sort { |a,b| a <=> b }.reverse.
112
- find { |v| v < lversion }.to_s
113
- end
114
-
115
- # Minimum gem version which satisfies this dependency
116
- def min_satisfying_version
117
- return "0.0" if self.version.nil? ||
118
- self.condition == '<' ||
119
- self.condition == '<='
120
- return self.version if self.condition == '=' ||
121
- self.condition == '>='
122
- Versionomy.parse(self.version).bump(:tiny).to_s # self.condition == '>'
123
- end
124
-
125
- # Max gem version which satisfies this dependency
126
- #
127
- # Can't automatically deduce in '<' case, so if that is the conditional
128
- # we require a version list, and will return the gcd from it
129
- def max_satisfying_version(versions=nil)
130
- return Float::INFINITY if self.version.nil? ||
131
- self.condition == '>' ||
132
- self.condition == '>='
133
- return self.version if self.condition == '=' ||
134
- self.condition == '<='
135
-
136
- raise ArgumentError if versions.nil?
137
- self.gcd(versions)
138
- end
139
-
140
- # Minimum gem version for which this dependency fails
141
- def min_failing_version
142
- raise ArgumentError if self.version.nil?
143
- return "0.0" if self.condition == '>' ||
144
- self.condition == '>='
145
- return self.version if self.condition == '<'
146
- Versionomy.parse(self.version).bump(:tiny).to_s # self.condition == '<=' and '='
147
- end
148
-
149
- # Max gem version for which this dependency fails
150
- #
151
- # Can't automatically deduce in '>=', and '=' cases, so if that is the
152
- # conditional we require a version list, and will return the gcd from it
153
- def max_failing_version(versions=nil)
154
- raise ArgumentError if self.version.nil? ||
155
- self.condition == '<=' ||
156
- self.condition == '<'
157
- return self.version if self.condition == '>'
158
-
159
- raise ArgumentError if versions.nil?
160
- self.gcd(versions)
161
- end
162
-
163
- # Return bool indicating if requirement matches specified
164
- # depedency.
165
- #
166
- # Comparison mechanism will depend on type of class
167
- # passed to this. Valid types include
168
- # - Polisher::RPM::Requirements
169
- # - ::Gem::Dependency
170
- def matches?(dep)
171
- return self == dep if dep.is_a?(self.class)
172
- raise ArgumentError unless dep.is_a?(::Gem::Dependency)
173
-
174
- return false if !self.gem? || self.gem_name != dep.name
175
- return true if self.version.nil?
176
-
177
- Gem2Rpm::Helpers.expand_requirement([dep.requirement.to_s.split]).
178
- any?{ |req|
179
- req.first == self.condition && req.last.to_s == self.version
180
- }
181
- end
182
-
183
- # Whether or not this requirement specified a ruby gem dependency
184
- def gem?
185
- !!(self.str =~ RPM::Spec::SPEC_GEM_REQ_MATCHER)
186
- end
187
-
188
- # Return the name of the gem which this requirement is for.
189
- # Returns nil if this is not a gem requirement
190
- def gem_name
191
- # XXX need to explicitly run regex here to get $1
192
- !!(self.str =~ RPM::Spec::SPEC_GEM_REQ_MATCHER) ? $1 : nil
193
- end
194
- end # class Requirement
195
- end # module RPM
196
- end # Component.verify("RPM::Requirement")
14
+ module Polisher
15
+ module RPM
16
+ class Requirement
17
+ include ConfHelpers
18
+
19
+ include RequirementAttributes
20
+ include RequirementParser
21
+ include RequirementComparison
22
+
23
+ # TODO: make this mixin optional depending on if requirement corresponds to gem
24
+ include RequirementGemReference
25
+
26
+ conf_attr :rubygem_prefix, 'rubygem'
27
+ conf_attr :scl_prefix, '' # set to %{?scl_prefix} to enable scl's
28
+
29
+ def initialize(args = {})
30
+ @br = args[:br] || false
31
+ @name = args[:name]
32
+ @condition = args[:condition]
33
+ @version = args[:version]
34
+
35
+ @name.strip! unless @name.nil?
36
+ @condition.strip! unless @condition.nil?
37
+ @version.strip! unless @version.nil?
38
+ end
39
+ end # class Requirement
40
+ end # module RPM
197
41
  end # module Polisher
@@ -0,0 +1,43 @@
1
+ # Polisher RPM Requirement Attributes Mixin
2
+ #
3
+ # Licensed under the MIT license
4
+ # Copyright (C) 2013-2014 Red Hat, Inc.
5
+
6
+ module Polisher
7
+ module RPM
8
+ module RequirementAttributes
9
+ def self.included(base)
10
+ base.extend(ClassMethods)
11
+ end
12
+
13
+ module ClassMethods
14
+ def prefix
15
+ "#{scl_prefix}#{rubygem_prefix}"
16
+ end
17
+ end
18
+
19
+ # Bool indiciating if req is a BR
20
+ attr_accessor :br
21
+
22
+ # Name of requirement
23
+ attr_accessor :name
24
+
25
+ # Condition, eg >=, =, etc
26
+ attr_accessor :condition
27
+
28
+ # Version number
29
+ attr_accessor :version
30
+
31
+ # Requirement string
32
+ def str
33
+ sp = specifier
34
+ sp.nil? ? "#{@name}" : "#{@name} #{sp}"
35
+ end
36
+
37
+ # Specified string
38
+ def specifier
39
+ @version.nil? ? nil : "#{@condition} #{@version}"
40
+ end
41
+ end # module RequirementAttributes
42
+ end # module RPM
43
+ end # module Polisher