polisher 0.7.1 → 0.8.1

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.
@@ -5,7 +5,7 @@
5
5
 
6
6
  SPEC_DIR = File.expand_path File.dirname(__FILE__)
7
7
 
8
- require 'polisher/rpmspec'
8
+ require 'polisher/rpm/spec'
9
9
  require 'polisher/gem_cache'
10
10
 
11
11
  RSpec.configure do |config|
@@ -67,34 +67,34 @@ module Polisher
67
67
  :name => "activesupport",
68
68
  :version => "4.0.0",
69
69
  :release => "1%{?dist}",
70
- :requires => [Polisher::RPMSpec::Requirement.parse("ruby(rubygems)"),
71
- Polisher::RPMSpec::Requirement.parse("ruby(release)"),
72
- Polisher::RPMSpec::Requirement.parse("rubygem(bigdecimal)"),
73
- Polisher::RPMSpec::Requirement.parse("rubygem(dalli)"),
74
- Polisher::RPMSpec::Requirement.parse("rubygem(i18n) >= 0.6"),
75
- Polisher::RPMSpec::Requirement.parse("rubygem(i18n) < 1.0"),
76
- Polisher::RPMSpec::Requirement.parse("rubygem(minitest) >= 4.2"),
77
- Polisher::RPMSpec::Requirement.parse("rubygem(minitest) < 5"),
78
- Polisher::RPMSpec::Requirement.parse("rubygem(multi_json) >= 1.0"),
79
- Polisher::RPMSpec::Requirement.parse("rubygem(multi_json) < 2"),
80
- Polisher::RPMSpec::Requirement.parse("rubygem(rack)"),
81
- Polisher::RPMSpec::Requirement.parse("rubygem(thread_safe)"),
82
- Polisher::RPMSpec::Requirement.parse("rubygem(tzinfo) >= 0.3.37"),
83
- Polisher::RPMSpec::Requirement.parse("rubygem(tzinfo) < 0.4.0")],
84
- :build_requires => [Polisher::RPMSpec::Requirement.parse("rubygems-devel"),
85
- Polisher::RPMSpec::Requirement.parse("rubygem(bigdecimal)"),
86
- Polisher::RPMSpec::Requirement.parse("rubygem(builder)"),
87
- Polisher::RPMSpec::Requirement.parse("rubygem(dalli)"),
88
- Polisher::RPMSpec::Requirement.parse("rubygem(i18n) >= 0.6"),
89
- Polisher::RPMSpec::Requirement.parse("rubygem(i18n) < 1.0"),
90
- Polisher::RPMSpec::Requirement.parse("rubygem(minitest)"),
91
- Polisher::RPMSpec::Requirement.parse("rubygem(mocha)"),
92
- Polisher::RPMSpec::Requirement.parse("rubygem(multi_json) >= 1.0"),
93
- Polisher::RPMSpec::Requirement.parse("rubygem(multi_json) < 2"),
94
- Polisher::RPMSpec::Requirement.parse("rubygem(rack)"),
95
- Polisher::RPMSpec::Requirement.parse("rubygem(thread_safe)"),
96
- Polisher::RPMSpec::Requirement.parse("rubygem(tzinfo) >= 0.3.37"),
97
- Polisher::RPMSpec::Requirement.parse("rubygem(tzinfo) < 0.4.0")],
70
+ :requires => [Polisher::RPM::Requirement.parse("ruby(rubygems)"),
71
+ Polisher::RPM::Requirement.parse("ruby(release)"),
72
+ Polisher::RPM::Requirement.parse("rubygem(bigdecimal)"),
73
+ Polisher::RPM::Requirement.parse("rubygem(dalli)"),
74
+ Polisher::RPM::Requirement.parse("rubygem(i18n) >= 0.6"),
75
+ Polisher::RPM::Requirement.parse("rubygem(i18n) < 1.0"),
76
+ Polisher::RPM::Requirement.parse("rubygem(minitest) >= 4.2"),
77
+ Polisher::RPM::Requirement.parse("rubygem(minitest) < 5"),
78
+ Polisher::RPM::Requirement.parse("rubygem(multi_json) >= 1.0"),
79
+ Polisher::RPM::Requirement.parse("rubygem(multi_json) < 2"),
80
+ Polisher::RPM::Requirement.parse("rubygem(rack)"),
81
+ Polisher::RPM::Requirement.parse("rubygem(thread_safe)"),
82
+ Polisher::RPM::Requirement.parse("rubygem(tzinfo) >= 0.3.37"),
83
+ Polisher::RPM::Requirement.parse("rubygem(tzinfo) < 0.4.0")],
84
+ :build_requires => [Polisher::RPM::Requirement.parse("rubygems-devel"),
85
+ Polisher::RPM::Requirement.parse("rubygem(bigdecimal)"),
86
+ Polisher::RPM::Requirement.parse("rubygem(builder)"),
87
+ Polisher::RPM::Requirement.parse("rubygem(dalli)"),
88
+ Polisher::RPM::Requirement.parse("rubygem(i18n) >= 0.6"),
89
+ Polisher::RPM::Requirement.parse("rubygem(i18n) < 1.0"),
90
+ Polisher::RPM::Requirement.parse("rubygem(minitest)"),
91
+ Polisher::RPM::Requirement.parse("rubygem(mocha)"),
92
+ Polisher::RPM::Requirement.parse("rubygem(multi_json) >= 1.0"),
93
+ Polisher::RPM::Requirement.parse("rubygem(multi_json) < 2"),
94
+ Polisher::RPM::Requirement.parse("rubygem(rack)"),
95
+ Polisher::RPM::Requirement.parse("rubygem(thread_safe)"),
96
+ Polisher::RPM::Requirement.parse("rubygem(tzinfo) >= 0.3.37"),
97
+ Polisher::RPM::Requirement.parse("rubygem(tzinfo) < 0.4.0")],
98
98
  :changelog => "",
99
99
  :files => {"activesupport"=>["%{gem_instdir}", "CHANGELOG.md", "lib", "MIT-LICENSE", "README.rdoc", "%{gem_docdir}", "%{gem_cache}", "%{gem_spec}", "test"]}
100
100
  }
@@ -0,0 +1,41 @@
1
+ # Polisher Vendor Specs
2
+ #
3
+ # Licensed under the MIT license
4
+ # Copyright (C) 2014 Red Hat, Inc.
5
+
6
+ require 'spec_helper'
7
+
8
+ require 'polisher/vendor'
9
+
10
+ module Polisher
11
+ describe HasVendoredDeps do
12
+ before(:each) do
13
+ @obj = Object.new
14
+ @obj.extend(HasVendoredDeps)
15
+ end
16
+
17
+ describe "#vendored_file_paths" do
18
+ it "returns file marks in gem marked as vendored" do
19
+ expected = [ 'vendor/foo.rb', 'vendor/bar/foo.rb']
20
+ paths = ['foo.rb'] + expected
21
+ gem = Polisher::Gem.new
22
+ gem.should_receive(:file_paths).and_return(paths)
23
+ gem.vendored_file_paths.should == expected
24
+ end
25
+ end
26
+
27
+ describe "#vendored" do
28
+ it "returns list of vendored modules in gem" do
29
+ gem = Polisher::Gem.new
30
+ vendored = ['vendor/thor.rb', 'vendor/thor/foo.rb', 'vendor/biz/baz.rb']
31
+ gem.should_receive(:vendored_file_paths).and_return(vendored)
32
+ gem.vendored.should == {'thor' => nil, 'biz' => nil}
33
+ end
34
+
35
+ context "vendored module has VERSION.rb file" do
36
+ it "returns version of vendored gems"
37
+ end
38
+ end
39
+
40
+ end
41
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polisher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Frey
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2014-02-12 00:00:00.000000000 Z
14
+ date: 2014-02-27 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: json
@@ -192,16 +192,20 @@ files:
192
192
  - lib/polisher/errata.rb
193
193
  - lib/polisher/git_cache.rb
194
194
  - lib/polisher/gem.rb
195
+ - lib/polisher/rpm/spec.rb
196
+ - lib/polisher/rpm/patch.rb
197
+ - lib/polisher/rpm/requirement.rb
195
198
  - lib/polisher/git.rb
199
+ - lib/polisher/error.rb
196
200
  - lib/polisher/upstream.rb
197
201
  - lib/polisher/bugzilla.rb
198
202
  - lib/polisher/gemfile.rb
199
- - lib/polisher/formatter.rb
203
+ - lib/polisher/git/project.rb
204
+ - lib/polisher/git/pkg.rb
205
+ - lib/polisher/git/repo.rb
200
206
  - lib/polisher/koji.rb
201
- - lib/polisher/rpmspec.rb
202
207
  - lib/polisher/gem_cache.rb
203
208
  - lib/polisher/rhn.rb
204
- - lib/polisher/gemspec.rb
205
209
  - lib/polisher/yum.rb
206
210
  - lib/polisher.rb
207
211
  - spec/git_spec.rb
@@ -214,6 +218,7 @@ files:
214
218
  - spec/yum_spec.rb
215
219
  - spec/upstream_spec.rb
216
220
  - spec/rpmspec_spec.rb
221
+ - spec/vendor_spec.rb
217
222
  - spec/fedora_spec.rb
218
223
  - spec/core_spec.rb
219
224
  - spec/data/rails.json
@@ -1 +0,0 @@
1
- # TODO
@@ -1,32 +0,0 @@
1
- # Polisher Gemspec Represenation
2
- #
3
- # Licensed under the MIT license
4
- # Copyright (C) 2013-2014 Red Hat, Inc.
5
-
6
- require 'polisher/version_checker'
7
-
8
- module Polisher
9
- class Gemspec
10
- include VersionedDependencies
11
-
12
- attr_accessor :deps
13
-
14
- def initialize(args={})
15
- @deps = args[:deps]
16
- end
17
-
18
- # Parse the specified gemspec & return new Gemspec instance from metadata
19
- #
20
- # @param [String] path to gemspec to parse
21
- # @return [Polisher::Gemspec] gemspec instantiated from parsed metadata
22
- def self.parse(path)
23
- parser = Gemnasium::Parser.gemspec(File.read(path))
24
- metadata = {:deps => [], :dev_deps => []}
25
- parser.dependencies.each { |dep|
26
- metadata[:deps] << dep.name
27
- }
28
-
29
- self.new metadata
30
- end
31
- end
32
- end
@@ -1,512 +0,0 @@
1
- # Polisher RPM Spec Represenation
2
- #
3
- # Licensed under the MIT license
4
- # Copyright (C) 2013-2014 Red Hat, Inc.
5
-
6
- require 'gem2rpm'
7
- require 'versionomy'
8
- require 'active_support/core_ext'
9
-
10
- require 'polisher/core'
11
- require 'polisher/gem'
12
-
13
- module Polisher
14
- class RPMSpec
15
- class Requirement
16
- # Bool indiciating if req is a BR
17
- attr_accessor :br
18
-
19
- # Name of requirement
20
- attr_accessor :name
21
-
22
- # Condition, eg >=, =, etc
23
- attr_accessor :condition
24
-
25
- # Version number
26
- attr_accessor :version
27
-
28
- # Requirement string
29
- def str
30
- sp = self.specifier
31
- sp.nil? ? "#{@name}" : "#{@name} #{sp}"
32
- end
33
-
34
- # Specified string
35
- def specifier
36
- @version.nil? ? nil : "#{@condition} #{@version}"
37
- end
38
-
39
- def self.parse(str, opts={})
40
- stra = str.split
41
- br = str.include?('BuildRequires')
42
- name = condition = version = nil
43
-
44
- if str.include?('Requires')
45
- name = stra[1]
46
- condition = stra[2]
47
- version = stra[3]
48
-
49
- else
50
- name = stra[0]
51
- condition = stra[1]
52
- version = stra[2]
53
-
54
- end
55
-
56
- req = self.new({:name => name,
57
- :condition => condition,
58
- :version => version,
59
- :br => br}.merge(opts))
60
- req
61
- end
62
-
63
- def initialize(args={})
64
- @br = args[:br] || false
65
- @name = args[:name]
66
- @condition = args[:condition]
67
- @version = args[:version]
68
-
69
- @name.strip! unless @name.nil?
70
- @condition.strip! unless @condition.nil?
71
- @version.strip! unless @version.nil?
72
- end
73
-
74
- def ==(other)
75
- @br == other.br &&
76
- @name == other.name &&
77
- @condition == other.condition &&
78
- @version == other.version
79
- end
80
-
81
- # Greatest Common Denominator,
82
- # Max version in list that is less than the local version
83
- def gcd(versions)
84
- lversion = Versionomy.parse(self.version)
85
- versions.collect { |v| Versionomy.parse(v) }.
86
- sort { |a,b| a <=> b }.reverse.
87
- find { |v| v < lversion }.to_s
88
- end
89
-
90
- # Minimum gem version which satisfies this dependency
91
- def min_satisfying_version
92
- return "0.0" if self.version.nil? ||
93
- self.condition == '<' ||
94
- self.condition == '<='
95
- return self.version if self.condition == '=' ||
96
- self.condition == '>='
97
- Versionomy.parse(self.version).bump(:tiny).to_s # self.condition == '>'
98
- end
99
-
100
- # Max gem version which satisfies this dependency
101
- #
102
- # Can't automatically deduce in '<' case, so if that is the conditional
103
- # we require a version list, and will return the gcd from it
104
- def max_satisfying_version(versions=nil)
105
- return Float::INFINITY if self.version.nil? ||
106
- self.condition == '>' ||
107
- self.condition == '>='
108
- return self.version if self.condition == '=' ||
109
- self.condition == '<='
110
-
111
- raise ArgumentError if versions.nil?
112
- self.gcd(versions)
113
- end
114
-
115
- # Minimum gem version for which this dependency fails
116
- def min_failing_version
117
- raise ArgumentError if self.version.nil?
118
- return "0.0" if self.condition == '>' ||
119
- self.condition == '>='
120
- return self.version if self.condition == '<'
121
- Versionomy.parse(self.version).bump(:tiny).to_s # self.condition == '<=' and '='
122
- end
123
-
124
- # Max gem version for which this dependency fails
125
- #
126
- # Can't automatically deduce in '>=', and '=' cases, so if that is the
127
- # conditional we require a version list, and will return the gcd from it
128
- def max_failing_version(versions=nil)
129
- raise ArgumentError if self.version.nil? ||
130
- self.condition == '<=' ||
131
- self.condition == '<'
132
- return self.version if self.condition == '>'
133
-
134
- raise ArgumentError if versions.nil?
135
- self.gcd(versions)
136
- end
137
-
138
- def matches?(dep)
139
- return self == dep if dep.is_a?(self.class)
140
- raise ArgumentError unless dep.is_a?(::Gem::Dependency)
141
-
142
- return false if !self.gem? || self.gem_name != dep.name
143
- return true if self.version.nil?
144
-
145
- Gem2Rpm::Helpers.expand_requirement([dep.requirement.to_s.split]).
146
- any?{ |req|
147
- req.first == self.condition && req.last.to_s == self.version
148
- }
149
- end
150
-
151
- def gem?
152
- !!(self.str =~ SPEC_GEM_REQ_MATCHER)
153
- end
154
-
155
- def gem_name
156
- # XXX need to explicitly run regex here to get $1
157
- !!(self.str =~ SPEC_GEM_REQ_MATCHER) ? $1 : nil
158
- end
159
- end
160
-
161
- AUTHOR = "#{ENV['USER']} <#{ENV['USER']}@localhost.localdomain>"
162
-
163
- COMMENT_MATCHER = /^\s*#.*/
164
- GEM_NAME_MATCHER = /^%global\s*gem_name\s(.*)$/
165
- SPEC_NAME_MATCHER = /^Name:\s*rubygem-(.*)$/
166
- SPEC_VERSION_MATCHER = /^Version:\s*(.*)$/
167
- SPEC_RELEASE_MATCHER = /^Release:\s*(.*)$/
168
- SPEC_REQUIRES_MATCHER = /^Requires:\s*(.*)$/
169
- SPEC_BUILD_REQUIRES_MATCHER = /^BuildRequires:\s*(.*)$/
170
- SPEC_GEM_REQ_MATCHER = /^.*\s*rubygem\((.*)\)(\s*(.*))?$/
171
- SPEC_SUBPACKAGE_MATCHER = /^%package\s(.*)$/
172
- SPEC_CHANGELOG_MATCHER = /^%changelog$/
173
- SPEC_FILES_MATCHER = /^%files$/
174
- SPEC_SUBPKG_FILES_MATCHER = /^%files\s*(.*)$/
175
- SPEC_CHECK_MATCHER = /^%check$/
176
-
177
- FILE_MACRO_MATCHERS =
178
- [/^%doc\s/, /^%config\s/, /^%attr\s/,
179
- /^%verify\s/, /^%docdir.*/, /^%dir\s/,
180
- /^%defattr.*/, /^%exclude\s/, /^%{gem_instdir}\/+/]
181
-
182
- FILE_MACRO_REPLACEMENTS =
183
- {"%{_bindir}" => 'bin',
184
- "%{gem_libdir}" => 'lib'}
185
-
186
- attr_accessor :metadata
187
-
188
- # Return the currently configured author
189
- def self.current_author
190
- ENV['POLISHER_AUTHOR'] || AUTHOR
191
- end
192
-
193
- def initialize(metadata={})
194
- @metadata = metadata
195
- end
196
-
197
- # Dispatch all missing methods to lookup calls in rpm spec metadata
198
- def method_missing(method, *args, &block)
199
- # proxy to metadata
200
- if @metadata.has_key?(method)
201
- @metadata[method]
202
-
203
- else
204
- super(method, *args, &block)
205
- end
206
- end
207
-
208
- def has_check?
209
- @metadata.has_key?(:has_check) && @metadata[:has_check]
210
- end
211
-
212
- # Return all the requirements for the specified gem
213
- def requirements_for_gem(gem_name)
214
- @metadata[:requires].nil? ? [] :
215
- @metadata[:requires].select { |r| r.gem_name == gem_name }
216
- end
217
-
218
- # Return bool indicating if this spec specifies all the
219
- # requirements in the specified gem dependency
220
- def has_all_requirements_for?(gem_dep)
221
- reqs = self.requirements_for_gem gem_dep.name
222
- # create a spec requirement dependency for each expanded subrequirement,
223
- # verify we can find a match for that
224
- gem_dep.requirement.to_s.split(',').all? { |greq|
225
- Gem2Rpm::Helpers.expand_requirement([greq.split]).all? { |ereq|
226
- tereq = Requirement.new :name => "rubygem(#{gem_dep.name})",
227
- :condition => ereq.first,
228
- :version => ereq.last.to_s
229
- reqs.any? { |req| req.matches?(tereq)}
230
- }
231
- }
232
- end
233
-
234
- # Parse the specified rpm spec and return new RPMSpec instance from metadata
235
- #
236
- # @param [String] string contents of spec to parse
237
- # @return [Polisher::RPMSpec] spec instantiated from rpmspec metadata
238
- def self.parse(spec)
239
- in_subpackage = false
240
- in_changelog = false
241
- in_files = false
242
- subpkg_name = nil
243
- meta = {:contents => spec}
244
- spec.each_line { |l|
245
- if l =~ COMMENT_MATCHER
246
- ;
247
-
248
- # TODO support optional gem prefix
249
- elsif l =~ GEM_NAME_MATCHER
250
- meta[:gem_name] = $1.strip
251
- meta[:gem_name] = $1.strip
252
-
253
- elsif l =~ SPEC_NAME_MATCHER &&
254
- $1.strip != "%{gem_name}"
255
- meta[:gem_name] = $1.strip
256
-
257
- elsif l =~ SPEC_VERSION_MATCHER
258
- meta[:version] = $1.strip
259
-
260
- elsif l =~ SPEC_RELEASE_MATCHER
261
- meta[:release] = $1.strip
262
-
263
- elsif l =~ SPEC_SUBPACKAGE_MATCHER
264
- subpkg_name = $1.strip
265
- in_subpackage = true
266
-
267
- elsif l =~ SPEC_REQUIRES_MATCHER &&
268
- !in_subpackage
269
- meta[:requires] ||= []
270
- meta[:requires] << RPMSpec::Requirement.parse($1.strip)
271
-
272
- elsif l =~ SPEC_BUILD_REQUIRES_MATCHER &&
273
- !in_subpackage
274
- meta[:build_requires] ||= []
275
- meta[:build_requires] << RPMSpec::Requirement.parse($1.strip)
276
-
277
- elsif l =~ SPEC_CHANGELOG_MATCHER
278
- in_changelog = true
279
-
280
- elsif l =~ SPEC_FILES_MATCHER
281
- subpkg_name = nil
282
- in_files = true
283
-
284
- elsif l =~ SPEC_SUBPKG_FILES_MATCHER
285
- subpkg_name = $1.strip
286
- in_files = true
287
-
288
- elsif l =~ SPEC_CHECK_MATCHER
289
- meta[:has_check] = true
290
-
291
- elsif in_changelog
292
- meta[:changelog] ||= ""
293
- meta[:changelog] << l
294
-
295
- elsif in_files
296
- tgt = subpkg_name.nil? ? meta[:gem_name] : subpkg_name
297
- meta[:files] ||= {}
298
- meta[:files][tgt] ||= []
299
-
300
- sl = l.strip.unrpmize
301
- meta[:files][tgt] << sl unless sl.blank?
302
- end
303
- }
304
-
305
- meta[:changelog_entries] = meta[:changelog] ?
306
- meta[:changelog].split("\n\n") : []
307
- meta[:changelog_entries].collect! { |c| c.strip }.compact!
308
-
309
- self.new meta
310
- end
311
-
312
- # Update RPMSpec metadata to new gem
313
- #
314
- # TODO add option to enable/disable certain aspects
315
- # from being updates
316
- #
317
- # @param [Polisher::Gem] new_source new gem to update rpmspec to
318
- def update_to(new_source)
319
- update_deps_from(new_source)
320
- update_files_from(new_source)
321
- update_metadata_from(new_source)
322
- end
323
-
324
- private
325
-
326
- def update_deps_from(new_source)
327
- non_gem_requires = []
328
- non_gem_brequires = []
329
- extra_gem_requires = []
330
- extra_gem_brequires = []
331
-
332
- @metadata[:requires] ||= []
333
- @metadata[:requires].each { |r|
334
- if !r.gem?
335
- non_gem_requires << r
336
- elsif !new_source.deps.any? { |d| d.name == r.gem_name }
337
- extra_gem_requires << r
338
- #else
339
- # spec_version = $2
340
- end
341
- }
342
-
343
- @metadata[:build_requires] ||= []
344
- @metadata[:build_requires].each { |r|
345
- if !r.gem?
346
- non_gem_brequires << r
347
- elsif !new_source.deps.any? { |d| d.name == r.gem_name }
348
- extra_gem_brequires << r
349
- #else
350
- # spec_version = $2
351
- end
352
- }
353
-
354
- # TODO detect if req is same as @version, swap out w/ %{version} macro ?
355
-
356
- @metadata[:requires] =
357
- non_gem_requires + extra_gem_requires +
358
- new_source.deps.collect { |r|
359
- r.requirement.to_s.split(',').collect { |req|
360
- expanded = Gem2Rpm::Helpers.expand_requirement [req.split]
361
- expanded.collect { |e|
362
- RPMSpec::Requirement.new :name => "rubygem(#{r.name})",
363
- :condition => e.first.to_s,
364
- :version => e.last.to_s,
365
- :br => false
366
- }
367
- }
368
- }.flatten
369
-
370
- @metadata[:build_requires] =
371
- non_gem_brequires + extra_gem_brequires +
372
- new_source.dev_deps.collect { |r|
373
- r.requirement.to_s.split(',').collect { |req|
374
- expanded = Gem2Rpm::Helpers.expand_requirement [req.split]
375
- expanded.collect { |e|
376
- RPMSpec::Requirement.new :name => "rubygem(#{r.name})",
377
- :condition => e.first.to_s,
378
- :version => e.last.to_s,
379
- :br => true
380
- }
381
- }
382
- }.flatten
383
- end
384
-
385
- def update_files_from(new_source)
386
- to_add = new_source.file_paths
387
- @metadata[:files] ||= {}
388
- @metadata[:files].each { |pkg,spec_files|
389
- (new_source.file_paths & to_add).each { |gem_file|
390
- # skip files already included in spec or in dir in spec
391
- has_file = spec_files.any? { |sf|
392
- gem_file.gsub(sf,'') != gem_file
393
- }
394
-
395
- to_add.delete(gem_file)
396
- to_add << gem_file.rpmize if !has_file &&
397
- !Gem.ignorable_file?(gem_file)
398
- }
399
- }
400
-
401
- @metadata[:new_files] = to_add
402
- end
403
-
404
- def update_metadata_from(new_source)
405
- # update to new version
406
- @metadata[:version] = new_source.version
407
- @metadata[:release] = "1%{?dist}"
408
-
409
- # add changelog entry
410
- changelog_entry = <<EOS
411
- * #{Time.now.strftime("%a %b %d %Y")} #{RPMSpec.current_author} - #{@metadata[:version]}-1
412
- - Update to version #{new_source.version}
413
- EOS
414
- @metadata[:changelog_entries] ||= []
415
- @metadata[:changelog_entries].unshift changelog_entry.rstrip
416
- end
417
-
418
- public
419
-
420
- # Return properly formatted rpmspec as string
421
- #
422
- # @return [String] string representation of rpm spec
423
- def to_string
424
- contents = @metadata[:contents]
425
-
426
- # replace version / release
427
- contents.gsub!(SPEC_VERSION_MATCHER, "Version: #{@metadata[:version]}")
428
- contents.gsub!(SPEC_RELEASE_MATCHER, "Release: #{@metadata[:release]}")
429
-
430
- # add changelog entry
431
- cp = contents.index SPEC_CHANGELOG_MATCHER
432
- cpn = contents.index "\n", cp
433
- contents = contents[0...cpn+1] +
434
- @metadata[:changelog_entries].join("\n\n")
435
-
436
- # update requires/build requires
437
- rp = contents.index SPEC_REQUIRES_MATCHER
438
- brp = contents.index SPEC_BUILD_REQUIRES_MATCHER
439
- tp = rp < brp ? rp : brp
440
-
441
- pp = contents.index SPEC_SUBPACKAGE_MATCHER
442
- pp = -1 if pp.nil?
443
-
444
- lrp = contents.rindex SPEC_REQUIRES_MATCHER, pp
445
- lbrp = contents.rindex SPEC_BUILD_REQUIRES_MATCHER, pp
446
- ltp = lrp > lbrp ? lrp : lbrp
447
-
448
- ltpn = contents.index "\n", ltp
449
-
450
- contents.slice!(tp...ltpn)
451
- contents.insert tp,
452
- (@metadata[:requires].collect { |r| "Requires: #{r.str}" } +
453
- @metadata[:build_requires].collect { |r| "BuildRequires: #{r.str}" }).join("\n")
454
-
455
- # add new files
456
- fp = contents.index SPEC_FILES_MATCHER
457
- lfp = contents.index SPEC_SUBPKG_FILES_MATCHER, fp + 1
458
- lfp = contents.index SPEC_CHANGELOG_MATCHER if lfp.nil?
459
-
460
- contents.insert lfp - 1, @metadata[:new_files].join("\n") + "\n"
461
-
462
- # return new contents
463
- contents
464
- end
465
-
466
- def compare(upstream_source)
467
- same = {}
468
- diff = {}
469
- upstream_source.deps.each do |d|
470
- spec_reqs = self.requirements_for_gem(d.name)
471
- spec_reqs_specifier = spec_reqs.empty? ? nil :
472
- spec_reqs.collect { |req| req.specifier }
473
-
474
- if spec_reqs.nil?
475
- diff[d.name] = {:spec => nil,
476
- :upstream => d.requirement.to_s}
477
-
478
- elsif !spec_reqs.any? { |req| req.matches?(d) } ||
479
- !self.has_all_requirements_for?(d)
480
- diff[d.name] = {:spec => spec_reqs_specifier,
481
- :upstream => d.requirement.to_s}
482
-
483
- elsif !diff.has_key?(d.name)
484
- same[d.name] = {:spec => spec_reqs_specifier,
485
- :upstream => d.requirement.to_s }
486
- end
487
- end
488
-
489
- @metadata[:requires].each do |req|
490
- next unless req.gem?
491
-
492
- upstream_dep = upstream_source.deps.find { |d| d.name == req.gem_name }
493
-
494
- if upstream_dep.nil?
495
- diff[req.gem_name] = {:spec => req.specifier,
496
- :upstream => nil}
497
-
498
- elsif !req.matches?(upstream_dep)
499
- diff[req.gem_name] = {:spec => req.specifier,
500
- :upstream => upstream_dep.requirement.to_s }
501
-
502
- elsif !diff.has_key?(req.gem_name)
503
- same[req.gem_name] = {:spec => req.specifier,
504
- :upstream => upstream_dep.requirement.to_s }
505
- end
506
- end unless @metadata[:requires].nil?
507
-
508
- {:same => same, :diff => diff}
509
- end
510
-
511
- end # class RPMSpec
512
- end # module Polisher