core_ex 0.4.0 → 0.5.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. data/ChangeLog +251 -0
  2. data/NEWS +29 -0
  3. data/README +1 -1
  4. data/SPEC.yml +10 -10
  5. data/lib/core_ex/dependencies_ext/constant_load_path.rb +1 -1
  6. data/lib/core_ex/embedded_tests.rb +1 -1
  7. data/lib/core_ex/enumerable.rb +87 -5
  8. data/lib/core_ex/exception.rb +1 -1
  9. data/lib/core_ex/file_utils.rb +1 -1
  10. data/lib/core_ex/lazy_loading.rb +159 -0
  11. data/lib/core_ex/module/attr_once.rb +1 -1
  12. data/lib/core_ex/module/import.rb +4 -6
  13. data/lib/core_ex/module/in_place.rb +1 -1
  14. data/lib/core_ex/module/mix_in_with_args.rb +1 -1
  15. data/lib/core_ex/numeric.rb +46 -0
  16. data/lib/core_ex/object/instance_eval_with_args.rb +1 -1
  17. data/lib/core_ex/object/singleton_class.rb +1 -1
  18. data/lib/core_ex/object/the_first_time.rb +1 -1
  19. data/lib/core_ex/pathname.rb +17 -11
  20. data/lib/core_ex/proc.rb +80 -1
  21. data/lib/core_ex/rakefile_base.rf +192 -296
  22. data/lib/core_ex/require.rb +1 -1
  23. data/lib/core_ex/string.rb +11 -2
  24. data/lib/core_ex/time.rb +1 -1
  25. data/lib/core_ex/try_dup.rb +1 -1
  26. data/lib/core_ex/yaml.rb +101 -79
  27. data/lib/core_ex.rb +129 -128
  28. data/lib/d_time.rb +225 -53
  29. data/lib/dumpable_proc.rb +1 -10
  30. data/lib/path_list.rb +18 -7
  31. data/lib/temp_path.rb +3 -3
  32. data/lib/test/unit/u_i/yaml/test_runner.rb +1 -1
  33. data/lib/version.rb +309 -69
  34. data/lib/yaml_extension.rb +1 -1
  35. data/test/fixtures/lazy_loading/a_b/a/c.rb +6 -0
  36. data/test/fixtures/lazy_loading/a_b/a.rb +2 -0
  37. data/test/fixtures/lazy_loading/a_b/b/c.rb +4 -0
  38. data/test/fixtures/lazy_loading/a_b/b.rb +2 -0
  39. data/test/fixtures/lazy_loading/double/a/bouhou.rb +2 -0
  40. data/test/fixtures/lazy_loading/double/a/foo_bar.rb +5 -0
  41. data/test/fixtures/lazy_loading/double/a/sub/a/suba.rb +7 -0
  42. data/test/fixtures/lazy_loading/double/b/root/sub/b.rb +6 -0
  43. data/test/fixtures/lazy_loading/double/b/root/sub.rb +4 -0
  44. data/test/fixtures/lazy_loading/double/b/root.rb +2 -0
  45. data/test/fixtures/lazy_loading/foo_bars/foo_bar.rb +4 -0
  46. data/test/fixtures/lazy_loading/foo_bars/mods/mod.rb +6 -0
  47. data/test/fixtures/lazy_loading/foo_bars/mods/sub_mod.rb +6 -0
  48. data/test/fixtures/lazy_loading/foo_bars/mods/sub_sub_mod.rb +7 -0
  49. data/test/fixtures/lazy_loading/foo_bars/mods.rb +4 -0
  50. data/test/fixtures/lazy_loading/foo_bars/sub_foo_bar.rb +5 -0
  51. data/test/fixtures/lazy_loading/foo_bars/titis/tutu.rb +6 -0
  52. data/test/fixtures/lazy_loading/foo_bars/totos.rb +6 -0
  53. data/test/fixtures/lazy_loading/foo_bars.rb +4 -0
  54. data/test/lazy_loading/test_already_present_name_absolute.rb +6 -0
  55. data/test/lazy_loading/test_already_present_name_relative.rb +11 -0
  56. data/test/lazy_loading/test_inside_another_module.rb +5 -0
  57. data/test/lazy_loading/test_lazy_loading.rb +179 -0
  58. data/test/sanity/multiple-requires.yml +22 -4
  59. data/test/unit-suite.yml +5 -4
  60. metadata +119 -80
  61. data/SPEC.dyn.yml +0 -10
  62. data/SPEC.gemspec +0 -13
  63. data/test/test-unit-setup.rb +0 -19
  64. /data/test/{resources → fixtures}/require/test_require +0 -0
  65. /data/test/{resources → fixtures}/require/test_require_rb.rb +0 -0
  66. /data/test/{resources → fixtures}/require/test_require_so.so +0 -0
  67. /data/test/{resources → fixtures}/use-from-gems.rb +0 -0
  68. /data/test/{resources → fixtures}/yaml_testrunner/unit_test.rb +0 -0
@@ -1,9 +1,15 @@
1
1
  # Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
2
2
  # Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
3
3
  # License:: Gnu General Public License.
4
- # Revision:: $Id: rakefile_base.rf 386 2005-10-03 00:02:16Z ertai $
4
+ # Revision:: $Id: /w/fey/ruby_ex/trunk/core_ex/lib/core_ex/rakefile_base.rf 22216 2006-02-24T09:02:54.402257Z pouillar $
5
+
6
+ DEFAULT_RUBY_EX_VERSION = ENV['DEFAULT_RUBY_EX_VERSION'] || '~> 0.3'
7
+ DEFAULT_UTTK_VERSION = ENV['DEFAULT_UTTK_VERSION'] || '~> 0.3'
8
+
9
+ raise "Need a rake version >= 0.6.2" if RAKEVERSION < '0.6.2'
5
10
 
6
11
  require 'core_ex'
12
+ require 'version'
7
13
  require 'ostruct'
8
14
  require 'date'
9
15
  require 'rbconfig'
@@ -17,12 +23,12 @@ suppress(LoadError) { require 'highline/import' }
17
23
 
18
24
  PathList.import!
19
25
 
20
-
26
+ HOME = Pathname.new(ENV['HOME'])
21
27
  AUTHORS = Pathname.new('AUTHORS')
22
28
  SPEC_YML = Pathname.new('SPEC.yml')
23
- SPEC_DYN_YML = Pathname.new('SPEC.dyn.yml')
24
29
  GEM_SPEC = Pathname.new('SPEC.gemspec')
25
30
  VENDOR = Pathname.new('vendor')
31
+ PKG = Pathname.new('pkg')
26
32
  RakefileBase = __FILE__
27
33
  EDITOR = ENV['EDITOR'] || 'vi'
28
34
 
@@ -31,16 +37,8 @@ EDITOR = ENV['EDITOR'] || 'vi'
31
37
  #
32
38
 
33
39
  def edit ( aPathname )
34
- sh EDITOR, aPathname.to_s
35
- end
36
-
37
- class MiniSvn
38
- def method_missing ( meth, *args )
39
- sh 'svn', meth.to_s, *args
40
- end
40
+ sh EDITOR, '--', aPathname.to_s
41
41
  end
42
- svn = MiniSvn.new
43
-
44
42
 
45
43
  def clean_task ( arg, &block )
46
44
  if arg.is_a? Hash
@@ -50,19 +48,22 @@ def clean_task ( arg, &block )
50
48
  end
51
49
  clobber_name = :"clobber_#{name}"
52
50
  task clobber_name => deps do
53
- Task[name].instance_eval { @already_invoked = false }
51
+ say "Clobber #{name}"
52
+ Rake::Task[name].instance_eval { @already_invoked = false }
54
53
  block[] unless block.nil?
55
54
  end
56
55
  task :clobber => clobber_name
57
56
  end
58
57
 
59
58
 
60
- class Task
61
- alias enhance_old enhance
62
- def enhance(deps=nil, &block)
63
- deps.each { |dep| @prerequisites << dep } if deps
64
- @actions << block if block_given?
65
- self
59
+ module Rake
60
+ class Task
61
+ alias enhance_old enhance
62
+ def enhance(deps=nil, &block)
63
+ deps.each { |dep| @prerequisites << dep } if deps
64
+ @actions << block if block_given?
65
+ self
66
+ end
66
67
  end
67
68
  end
68
69
 
@@ -72,13 +73,14 @@ end
72
73
  #
73
74
 
74
75
 
75
- desc 'Default Task (check)'
76
- task :default => [ :check ]
77
-
76
+ desc 'Default task'
77
+ task :default do
78
+ say 'Default task: use rake -T to see all tasks'
79
+ end
78
80
 
79
81
 
80
82
  task :ruby_ex => [ :spec ] do
81
- require_gem('ruby_ex', SPEC.ruby_ex_version || '~> 0.2.0')
83
+ require_gem('ruby_ex', SPEC.ruby_ex_version || DEFAULT_RUBY_EX_VERSION)
82
84
  require 'ruby_ex'
83
85
  Commands.import!
84
86
  $runner = Commands::Runners::System.new
@@ -89,21 +91,21 @@ end
89
91
 
90
92
  # desc 'Setup the uttk command'
91
93
  task :uttk => [ :spec, :ruby_ex ] do
92
- require_gem('uttk', SPEC.uttk_version || '~> 0.3.0')
94
+ require_gem('uttk', SPEC.uttk_version || DEFAULT_UTTK_VERSION)
93
95
  require 'uttk'
94
96
  def uttk ( *a, &b )
95
97
  cmd = Uttk.bin[*a]
96
98
  cmd.input = b[] if b
97
99
  cmd.output = STDOUT
98
100
  cmd.error = STDERR
99
- raise unless cmd.system.status == 0
101
+ raise unless cmd.system(:v).status == 0
100
102
  end
101
103
  end
102
104
 
103
105
 
104
106
 
105
107
  desc 'Launch all test suites'
106
- task :check => [ :uttk, :spec, :dyn_spec ] do
108
+ task :check => [ :uttk, :spec ] do
107
109
  uttk '-l', 'check-log', '-S', 'url: file://<<pwd>>', '-C',
108
110
  SPEC.root_test_suite
109
111
  end
@@ -116,7 +118,7 @@ end
116
118
  desc 'Check generated packages'
117
119
  task :distcheck => [ :uttk, :package ] do
118
120
  urls = []
119
- Pathname.glob('pkg/*') do |path|
121
+ Pathname.glob(PKG + '*') do |path|
120
122
  next unless path.file?
121
123
  urls << "file://#{path.expand_path}"
122
124
  end
@@ -136,53 +138,17 @@ clean_task :distcheck do
136
138
  end
137
139
 
138
140
 
139
-
140
141
  # desc "Load the #{SPEC_YML} file"
141
142
  task :spec => [ SPEC_YML.to_s ] do
142
143
  Kernel.const_set(:SPEC, OpenStruct.new(YAML.load(SPEC_YML.read)))
143
- task :spec_pkg_files => SPEC.pkg_files
144
+ pkg_files = SPEC.pkg_files.dup
145
+ pkg_files.delete_if { |x| x.basename.to_s =~ /SPEC/ }
146
+ task :spec_pkg_files => pkg_files
144
147
  end
145
148
  task :spec_pkg_files
146
149
 
147
150
 
148
151
 
149
- def update_dyn_spec
150
- svn_info = YAML::load(`svn info`)
151
- revision = svn_info['Revision']
152
- if SPEC_DYN_YML.exist?
153
- SPEC.dyn = YAML::load(SPEC_DYN_YML.read)
154
- SPEC.dyn.version.revision = revision
155
- else
156
- SPEC.dyn = OpenStruct.new('version' => Version.new(0, 0, 0, revision))
157
- end
158
- SPEC.dyn.date = /\((.*)\)/.match(svn_info['Last Changed Date'])[1]
159
- SPEC.dyn.url = svn_info['URL']
160
- SPEC_DYN_YML.open('w') do |out|
161
- out.puts(SPEC.dyn.to_yaml)
162
- end
163
- end
164
-
165
-
166
-
167
- # desc "Update the #{SPEC_DYN_YML} file"
168
- file SPEC_DYN_YML.to_s => [ :spec ] do
169
- update_dyn_spec
170
- end
171
-
172
-
173
-
174
- task :update_dyn_spec => [ SPEC_DYN_YML.to_s ] do
175
- update_dyn_spec
176
- end
177
-
178
-
179
-
180
- task :dyn_spec => [ SPEC_DYN_YML.to_s ] do
181
- SPEC.dyn = YAML::load(SPEC_DYN_YML.read)
182
- end
183
-
184
-
185
-
186
152
  desc 'Generate the full documentation'
187
153
  task :doc => [ :rdoc_spec, :rdoc_real ]
188
154
 
@@ -191,26 +157,28 @@ clean_task :doc => [ :rdoc_spec, :clobber_rdoc_real ]
191
157
  task :redoc => [ :clobber_doc, :doc ]
192
158
 
193
159
 
194
- task :tarballs => [ :dyn_spec, :vendor ] do
195
- Rake::PackageTask.new(SPEC.name, SPEC.dyn.version.to_s) do |p|
160
+ task :tarballs => [ :spec, :vendor ] do
161
+ Rake::PackageTask.new(SPEC.version.short_string, :noversion) do |p|
196
162
  p.need_tar_gz = true
197
163
  p.need_tar_bz2 = true
198
164
  p.package_files = (SPEC.pkg_files + PathList['vendor/**/*']).map { |x| x.to_s }
199
165
  end
200
166
  end
201
167
 
202
-
203
168
  desc 'Generate all packages'
204
169
  task :package => [ :tarballs, :gem_spec, :gem ]
205
170
 
206
- clean_task :package => [ :spec, :clobber_vendor, :clobber_gem_spec ]
171
+ clean_task :package => [ :spec, :clobber_vendor, :clobber_gem_spec ] do
172
+ say "rm -Rf #{PKG}"
173
+ PKG.rm_rf
174
+ end
207
175
 
208
176
  desc 'Re-generate all packages'
209
177
  task :repackage => [ :clobber_package, :package ]
210
178
 
211
179
 
212
180
 
213
- desc 'Generate a GEM package'
181
+ desc 'Generate the GEM package'
214
182
  task :gem => [ :gem_spec ]
215
183
 
216
184
  # desc 'Remove the GEM package file'
@@ -218,9 +186,13 @@ clean_task :gem => [ :gem_spec ] do
218
186
  $gem.rm_f
219
187
  end
220
188
 
221
- desc 'Re-generate a GEM package'
222
- task :regem => [ :clobber_gem, :gem ]
189
+ desc 'Re-generate the GEM package'
190
+ task :regem => [ :clobber_gem, :gem ]
223
191
 
192
+ desc 'Install the GEM package'
193
+ task :gemi => [ :gem ] do
194
+ sh "sudo gem i #$gem"
195
+ end
224
196
 
225
197
 
226
198
  task :rdoc_spec => [ :spec ] do
@@ -239,11 +211,11 @@ end
239
211
 
240
212
 
241
213
  # desc 'Update the Gem specification'
242
- file GEM_SPEC.to_s => [ :spec, :spec_pkg_files, :dyn_spec, :rdoc_spec ] do
214
+ file GEM_SPEC.to_s => [ :spec, :spec_pkg_files, :rdoc_spec ] do
243
215
  spec = Gem::Specification.new do |s|
244
216
  s.platform = Gem::Platform::RUBY
245
- s.name = SPEC.name
246
- s.version = SPEC.dyn.version.to_s
217
+ s.name = SPEC.version.name
218
+ s.version = SPEC.version.to_rubygems_version_string
247
219
  s.summary = SPEC.summary
248
220
  s.description = SPEC.description
249
221
  bin = 'bin'.to_path
@@ -271,7 +243,7 @@ file GEM_SPEC.to_s => [ :spec, :spec_pkg_files, :dyn_spec, :rdoc_spec ] do
271
243
  s.rdoc_options = SPEC.rdoc.option_list.map { |x| x[/^'?(.*?)'?$/, 1] }
272
244
  end
273
245
 
274
- authors_file = YAML::load(AUTHORS.read).values.first
246
+ authors_file = YAML.load(AUTHORS.read).values.first
275
247
  list = authors_file.map { |x| /^(.*?)\s*<(.*)>/.match(x.keys.first)[1..2] }
276
248
  s.author = s.authors
277
249
  s.authors = list.map { |x| x.first }
@@ -284,6 +256,14 @@ end
284
256
 
285
257
 
286
258
 
259
+ module Rake
260
+ class GemPackageTask < PackageTask
261
+ def package_name
262
+ "#{SPEC.version.name}-#{SPEC.version.to_rubygems_version_string}"
263
+ end
264
+ end
265
+ end
266
+
287
267
  task :gem_spec => [ GEM_SPEC.to_s ] do
288
268
  spec = eval(GEM_SPEC.read)
289
269
 
@@ -291,157 +271,145 @@ task :gem_spec => [ GEM_SPEC.to_s ] do
291
271
  p.gem_spec = spec
292
272
  p.package_files = SPEC.pkg_files.map { |x| x.to_s }
293
273
  end
294
- gtask.instance_eval { $gem = 'pkg'.to_path + gem_file }
274
+ if false # gem files must have a specific name
275
+ the_gem_file = nil
276
+ gtask.instance_eval { the_gem_file = PKG + gem_file }
277
+ $gem = PKG + "#{SPEC.version.short_string}.gem"
278
+ file $gem => [ the_gem_file ] do
279
+ verbose(true) {
280
+ mv the_gem_file.to_s, $gem.to_s
281
+ }
282
+ end
283
+ else
284
+ gtask.instance_eval { $gem = PKG + gem_file }
285
+ end
286
+ task :gem => [ $gem ]
295
287
  end
296
288
  clean_task :gem_spec do
297
289
  GEM_SPEC.rm_f
298
290
  end
299
291
 
300
292
 
301
- task :vcs do
302
- require_gem('vcs', SPEC.vcs_version || '~> 0.3.0')
303
- end
304
-
305
-
306
- desc 'Commit with Vcs'
307
- task :commit => [ :vcs ] do
308
- pos = ARGV.index('--')
309
- args = (pos.nil?)? [] : ARGV[pos .. -1]
310
- cmd = SPEC.commit_command || 'commit'
311
- Dir.chdir(SPEC.commit_dir || '.') do
312
- sh 'vcs-svn', cmd, *args
313
- end
293
+ task :commit do
294
+ default = "svn commit -m 'Bump to #{SPEC.version}'"
295
+ $commit_cmd ||= ask "Type the command that you use to commit,
296
+ by default it\'s svn so you can just hit enter.
297
+ If you must commit from another directory, type
298
+ something like \"cd .. && svn ci\". [#{default}]: "
299
+ $commit_cmd = default if $commit_cmd =~ /^\s*$/
300
+ sh $commit_cmd
314
301
  end
315
302
 
316
303
 
317
304
 
318
- desc 'Make an Svn tag'
319
- task :tag => [ :spec, :dyn_spec ] do
320
- tag_name = (SPEC.release)? SPEC.release : "#{SPEC.name}-#{SPEC.dyn.version}"
305
+ desc 'Make a SVN tag'
306
+ task :tag => [ :spec ] do
307
+ tag_name = SPEC.version.short_string
321
308
  tags = SPEC.tags_url.to_s + "/#{tag_name}"
322
- trunk = SPEC.trunk_url || SPEC.dyn.url
323
- while agree "Make the SVN tag (#{trunk} -> #{tags}) (y/n)", true
324
- begin
325
- svn.copy(trunk.to_s, tags, '-m', "'Releasing #{tag_name}'")
326
- break
327
- rescue RuntimeError => ex
328
- STDERR.puts ex
329
- end
330
- end
309
+ trunk = SPEC.trunk_url || SPEC.vcs_url
310
+ say "Make the SVN tag (#{trunk} -> #{tags})"
311
+ sh 'svn', 'copy', trunk.to_s, tags.to_s, '-m', "'Releasing #{tag_name}'"
331
312
  end
332
313
 
333
314
 
334
315
 
335
- desc 'Publish to RubyForge'
316
+ desc 'Publish the documentation'
336
317
  task :publish_doc => [ :spec ] do
337
- while agree 'Publish the documentation? ', true
338
- begin
339
- user = SPEC.user || ENV['USER']
340
- Rake::SshDirPublisher.new(
341
- # "#{user}@rubyforge.org",
342
- # "/var/www/gforge-projects/#{SPEC.name}/test",
343
- "#{user}@ssh.feydakins.org",
344
- "/var/www/api.feydakins.org/public/#{SPEC.name}/",
345
- SPEC.rdoc_dir
346
- ).upload
347
- break
348
- rescue Exception => ex
349
- STDERR.puts ex
350
- end
351
- end
318
+ user = SPEC.user || ENV['USER']
319
+ Rake::SshDirPublisher.new(
320
+ # "#{user}@rubyforge.org",
321
+ # "/var/www/gforge-projects/#{SPEC.version.name}/test",
322
+ "#{user}@ssh.feydakins.org",
323
+ "/var/www/api.feydakins.org/public/#{SPEC.version.name}/",
324
+ SPEC.rdoc_dir
325
+ ).upload
352
326
  end
353
327
 
354
328
 
355
329
 
356
- # desc 'Common tasks for a release'
357
- task :common_release =>
358
- [
359
- :uttk,
360
- :vcs,
361
-
362
- :release_confirm,
363
- :check,
364
- :doc,
365
- :package,
366
- :distcheck,
367
- :commit,
368
- :tag,
369
- :publish_doc,
370
- :publish_package
371
- ]
372
-
373
-
374
-
375
- task :release_confirm => [ :spec, :dyn_spec ] do
376
- SPEC.release = SPEC.name + '-' + SPEC.dyn.version.to_s
377
- SPEC.release += '-' + SPEC.dyn.version_id unless SPEC.dyn.version_id.empty?
378
- say "Release that: #{SPEC.release}."
379
- exit unless agree 'Are you sure? (y/n)', true
380
- end
381
-
382
-
330
+ module Rake
331
+ class ReleaseTask < TaskLib
332
+ def initialize(name, &block)
333
+ @name = name
334
+ block[self] unless block.nil?
335
+ define unless name.nil?
336
+ end
383
337
 
384
- [:major, :minor, :build].each do |release_mode|
385
- name = :"#{release_mode}_release"
386
- desc "Make a new #{release_mode} release"
387
- task name => [ :update_dyn_spec ] do
388
- SPEC.dyn.version.send(name)
389
- q = 'Specify an identifier for this version (or press return): '
390
- SPEC.dyn.version_id = ask(q)
391
- TempPath.new('SPEC.dyn.yml.bak') do |bak|
392
- SPEC_DYN_YML.mv(bak)
393
- SPEC_DYN_YML.open('w') do |out|
394
- out.puts(SPEC.dyn.to_yaml)
338
+ def define
339
+ descr = "Make a new: #{@name.to_s.humanize}"
340
+ desc descr
341
+ task @name => [ :spec ] do
342
+ SPEC.version = SPEC.version.send @name
343
+ q = 'Specify an identifier for this version (or press return): '
344
+ SPEC.version.release_name = ask(q)
345
+ say "Releasing that: #{SPEC.version}"
346
+ TempPath.new('SPEC.yml.bak') do |bak|
347
+ contents = SPEC_YML.read.gsub(/^(version\s*:\s+)(.*)\s*$/) { $1 + SPEC.version.to_yaml.gsub(/^---\s*/, '') }
348
+ SPEC_YML.mv(bak)
349
+ SPEC_YML.overwrite(contents)
350
+ begin
351
+ task_loop :clobber, :check, :doc, :package, :distcheck, :commit
352
+ rescue Exception => ex
353
+ bak.mv(SPEC_YML)
354
+ raise ex
355
+ end
356
+ bak.rm_f
357
+ task_loop :"after_commit_#@name"
358
+ end
395
359
  end
396
- begin
397
- sh 'rake', 'clobber'
398
- sh 'rake', 'common_release'
399
- rescue
400
- bak.mv(SPEC_DYN_YML)
360
+ task :"after_commit_#@name" => [ :spec ] do
361
+ task_loop :tag, :publish_doc, :publish_package
362
+ end
363
+ end
364
+
365
+ def task_loop ( *tasks )
366
+ until tasks.empty? do
367
+ begin
368
+ if agree("Shall we do that task: #{tasks.first}? (y/n) ")
369
+ Rake::Task[tasks.first].invoke
370
+ end
371
+ tasks.shift
372
+ rescue Exception => ex
373
+ STDERR.puts ex
374
+ choose do |menu|
375
+ menu.prompt = 'Retry, skip, or abort? '
376
+
377
+ menu.choice :retry do end
378
+ menu.choice :skip do tasks.shift end
379
+ menu.choice :abort do tasks.clear end
380
+ end
381
+ raise ex
382
+ end
401
383
  end
402
384
  end
403
385
  end
404
386
  end
405
387
 
388
+ releases = [ :major_release,
389
+ :minor_release,
390
+ :patch_level_release,
391
+ :release_candidate,
392
+ :alpha_release,
393
+ :beta_release,
394
+ :pre_release ]
395
+
396
+ for release in releases do
397
+ Rake::ReleaseTask.new release
398
+ end
406
399
 
407
- release_notes = ',release_notes'.to_path
408
- release_changes = ',release_changes'.to_path
400
+
401
+ release_notes = '+release_notes'.to_path
402
+ release_changes = '+release_changes'.to_path
409
403
 
410
404
 
411
405
  desc "Publish the release files to RubyForge."
412
406
  task :publish_package => [ :spec, :package ] do
413
- type_map = {
414
- '.deb' => 1000,
415
- '.rpm' => 2000,
416
- '.zip' => 3000,
417
- '.bz2' => 3100,
418
- '.tbz2' => 3100,
419
- '.gz' => 3110,
420
- '.tgz' => 3110,
421
- '.jpg' => 8000,
422
- '.text' => 8100,
423
- '.html' => 8200,
424
- '.pdf' => 8300,
425
- '.ebuild' => 1300,
426
- '.exe' => 1100,
427
- '.dmg' => 1200,
428
- '.gem' => 1400,
429
- '.sig' => 8150,
430
- # 'Source .zip' => 5000,
431
- # 'Source .bz2' => 5010,
432
- # 'Source .gz' => 5020,
433
- # 'Source .rpm' => 5100,
434
- # 'Other Source File' => 5900,
435
- }
436
- type_map.default = 9999
437
-
438
- pkg = 'pkg'.to_path
439
- files = PathList[pkg/"*{#{type_map.keys.join(',')}}"]
407
+
408
+ files = PathList[PKG/"*{gem,tar.*,tgz}"]
440
409
 
441
410
  rubyforge_user = SPEC.rubyforge_user || SPEC.user || ENV['USER']
442
- rubyforge_project = SPEC.rubyforge_project || SPEC.name
443
- default = (SPEC.release)? SPEC.release : "#{SPEC.name}-#{SPEC.dyn.version}"
444
- release_name = ask("Release name: ") { |q| q.default = default }
411
+ rubyforge_project = SPEC.rubyforge_project || SPEC.version.name
412
+ release_name = SPEC.version.short_string
445
413
 
446
414
  require 'net/http'
447
415
  require 'open-uri'
@@ -450,116 +418,43 @@ task :publish_package => [ :spec, :package ] do
450
418
  project_data = open(project_uri) { |data| data.read }
451
419
  group_id = project_data[/[?&]group_id=(\d+)/, 1]
452
420
  raise "Couldn't get group id" unless group_id
453
-
454
- if ENV['RUBY_FORGE_PASSWORD']
455
- password = ENV['RUBY_FORGE_PASSWORD']
456
- else
457
- password = ask("#{rubyforge_user}@rubyforge.org's password: ") do |q|
458
- q.echo = false
459
- end
460
- end
461
-
462
- login_response = Net::HTTP.start('rubyforge.org', 80) do |http|
463
- data = [
464
- 'login=1',
465
- "form_loginname=#{rubyforge_user}",
466
- "form_pw=#{password}"
467
- ].join('&')
468
- http.post('/account/login.php', data)
469
- end
470
-
471
- cookie = login_response['set-cookie']
472
- raise 'Login failed' unless cookie
473
- headers = { 'Cookie' => cookie }
474
-
475
- release_uri = "http://rubyforge.org/frs/admin/?group_id=#{group_id}"
476
- release_data = open(release_uri, headers) { |data| data.read }
477
- ids, names = [], []
478
- release_data.gsub(/name="package_id" value="(\d+)"/) { ids << $1 ; nil }
479
- release_data.gsub(/name="package_name" value="([^"]+)"/) { names << $1 ; nil }
480
- package_name = SPEC.rubyforge_sub_package_name || SPEC.name
481
-
482
- package_id = names.zip(ids).find { |name, id| name == package_name }.last
483
- raise "Couldn't get package id or package name" unless package_id
484
-
485
- first_file = true
486
- release_id = ''
487
-
421
+ package_name = SPEC.rubyforge_sub_package_name || SPEC.version.name
422
+
423
+ # if ENV['RUBY_FORGE_PASSWORD']
424
+ # password = ENV['RUBY_FORGE_PASSWORD']
425
+ # else
426
+ # password = ask("#{rubyforge_user}@rubyforge.org's password: ") do |q|
427
+ # q.echo = false
428
+ # end
429
+ # end
430
+
431
+ system "rubyforge login"
432
+ release_id = nil
488
433
  files.each do |path|
489
- path = path.to_path # FIXME
490
- basename = path.basename
491
- file_ext = path.extname
492
- file_data = path.read
493
-
494
- say "Releasing #{basename}..."
434
+ say "Releasing #{path.basename}..."
495
435
  next unless agree 'Agree? (y/n)', true
496
436
 
497
- release_response = Net::HTTP.start('rubyforge.org', 80) do |http|
498
- release_date = Time.now.strftime('%Y-%m-%d %H:%M')
499
- type = type_map[file_ext].to_s
500
- boundary = "rubyqMY6QN9bp6e4kS21H4y0zxcvoor"
501
-
502
- if first_file then
503
- release = { :notes => release_notes, :changes => release_changes }
504
- [:notes, :changes].each do |x|
505
- while not release[x].exist?
437
+ unless release_id then
438
+ release = { :notes => release_notes, :changes => release_changes }
439
+ [:notes, :changes].each do |x|
440
+ loop do
441
+ loop do
506
442
  say "No release #{x} (editing...)"
507
443
  edit release[x]
444
+ break if release[x].exist?
508
445
  end
509
446
  say "Publish these release #{x}:"
510
447
  say release[x].read
511
- exit unless agree 'Agree? (y/n) ', true
448
+ break if agree 'Agree? (y/n) ', true
512
449
  end
513
- query_hash = {
514
- 'group_id' => group_id,
515
- 'package_id' => package_id,
516
- 'release_name' => release_name,
517
- 'release_date' => release_date,
518
- 'type_id' => type,
519
- 'processor_id' => '8000', # Any
520
- 'release_notes' => release[:notes].read,
521
- 'release_changes' => release[:changes].read,
522
- 'preformatted' => '1',
523
- 'submit' => '1'
524
- }
525
- else
526
- query_hash = {
527
- 'group_id' => group_id,
528
- 'release_id' => release_id,
529
- 'package_id' => package_id,
530
- 'step2' => '1',
531
- 'type_id' => type,
532
- 'processor_id' => '8000', # Any
533
- 'submit' => 'Add This File'
534
- }
535
450
  end
536
-
537
- query = "?" + query_hash.map do |name, value|
538
- [name, URI.encode(value)].join("=")
539
- end.join("&")
540
-
541
- data = [
542
- '--' + boundary,
543
- "Content-Disposition: form-data; name=\"userfile\"; filename=\"#{basename}\"",
544
- 'Content-Type: application/octet-stream',
545
- 'Content-Transfer-Encoding: binary',
546
- '', file_data, ''
547
- ].join("\x0D\x0A")
548
-
549
- release_headers = headers.merge(
550
- 'Content-Type' => "multipart/form-data; boundary=#{boundary}"
551
- )
552
-
553
- target = first_file ? '/frs/admin/qrs.php' : '/frs/admin/editrelease.php'
554
- http.post(target + query, data, release_headers)
555
- end
556
-
557
- if first_file then
558
- release_id = release_response.body[/release_id=(\d+)/, 1]
559
- raise("Couldn't get release id") unless release_id
451
+ res = `rubyforge add_release #{group_id} #{package_name} #{release_name} #{path} -n #{release_notes} -a #{release_changes} -f`
452
+ release_id = res[/release_id: (\d+)/, 1]
453
+ puts "release_id: #{release_id}"
454
+ else
455
+ system "rubyforge add_release #{group_id} #{package_name} #{release_name} #{path} -R #{release_id} -n #{release_notes} -a #{release_changes} -f"
560
456
  end
561
457
 
562
- first_file = false
563
458
  end
564
459
  end
565
460
 
@@ -576,15 +471,16 @@ task :vendor => [ :spec, :ruby_ex ] do
576
471
  unless VENDOR.directory?
577
472
  say "Creating the #{(dev)? 'developpement ' : ''}vendor directory..."
578
473
  VENDOR.mkpath
579
- require 'uri_ex'
474
+ URI::GenericEx.import!
580
475
  if SPEC.dependencies
581
476
  SPEC.dependencies.each do |name, version|
582
- url = nil
477
+ url, vcs = nil, false
583
478
  case version
584
479
  when Array then url = version.last
585
480
  when Hash
586
481
  if dev and version['vcs']
587
482
  url = version['vcs']
483
+ vcs = true
588
484
  else
589
485
  url = version['tarball']
590
486
  end
@@ -600,8 +496,8 @@ task :vendor => [ :spec, :ruby_ex ] do
600
496
  out = FileType.guess(url.checkout.first)
601
497
  out = out.extract if out.extractable?
602
498
  out.path.mv(dest)
603
- if dev and version['vcs'] and (dest + 'SPEC.yml').exist?
604
- cmd = $0.to_cmd['vendor_dev'] > [STDOUT, STDERR]
499
+ if dev and vcs and (dest + 'SPEC.yml').exist?
500
+ cmd = $0.to_cmd['revendor_dev'] > [STDOUT, STDERR]
605
501
  cmd.dir = dest
606
502
  data = cmd.run($runner)
607
503
  end