rake 10.3.2 → 10.4.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rake might be problematic. Click here for more details.

Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.rdoc +3 -3
  3. data/History.rdoc +24 -0
  4. data/Manifest.txt +5 -1
  5. data/README.rdoc +5 -2
  6. data/Rakefile +2 -2
  7. data/doc/rake.1 +141 -0
  8. data/lib/rake.rb +2 -1
  9. data/lib/rake/application.rb +8 -2
  10. data/lib/rake/backtrace.rb +1 -1
  11. data/lib/rake/cloneable.rb +1 -1
  12. data/lib/rake/contrib/sshpublisher.rb +4 -4
  13. data/lib/rake/cpu_counter.rb +23 -7
  14. data/lib/rake/dsl_definition.rb +2 -1
  15. data/lib/rake/ext/module.rb +1 -0
  16. data/lib/rake/ext/pathname.rb +25 -0
  17. data/lib/rake/ext/string.rb +1 -1
  18. data/lib/rake/ext/time.rb +3 -2
  19. data/lib/rake/file_list.rb +18 -4
  20. data/lib/rake/file_task.rb +2 -2
  21. data/lib/rake/file_utils.rb +16 -4
  22. data/lib/rake/invocation_chain.rb +1 -1
  23. data/lib/rake/late_time.rb +17 -0
  24. data/lib/rake/packagetask.rb +3 -6
  25. data/lib/rake/task_manager.rb +2 -2
  26. data/test/helper.rb +5 -2
  27. data/test/support/rakefile_definitions.rb +1 -1
  28. data/test/support/ruby_runner.rb +6 -5
  29. data/test/test_rake_application.rb +14 -12
  30. data/test/test_rake_backtrace.rb +1 -1
  31. data/test/test_rake_clean.rb +7 -1
  32. data/test/test_rake_cpu_counter.rb +46 -28
  33. data/test/test_rake_definitions.rb +5 -0
  34. data/test/test_rake_directory_task.rb +13 -0
  35. data/test/test_rake_file_list.rb +28 -0
  36. data/test/test_rake_file_task.rb +19 -8
  37. data/test/test_rake_late_time.rb +18 -0
  38. data/test/test_rake_multi_task.rb +6 -0
  39. data/test/test_rake_pathname_extensions.rb +15 -0
  40. data/test/test_rake_task.rb +2 -1
  41. data/test/test_rake_task_argument_parsing.rb +10 -0
  42. data/test/test_rake_task_with_arguments.rb +1 -0
  43. data/test/test_rake_test_task.rb +1 -1
  44. data/test/test_rake_thread_pool.rb +4 -1
  45. metadata +17 -32
  46. checksums.yaml.gz.sig +0 -2
  47. data.tar.gz.sig +0 -0
  48. data/doc/rake.1.gz +0 -0
  49. metadata.gz.sig +0 -0
@@ -1 +1,2 @@
1
+
1
2
  # TODO: remove in Rake 11
@@ -0,0 +1,25 @@
1
+ require 'rake/ext/core'
2
+ require 'pathname'
3
+
4
+ class Pathname
5
+
6
+ rake_extension("ext") do
7
+ # Return a new Pathname with <tt>String#ext</tt> applied to it.
8
+ #
9
+ # This Pathname extension comes from Rake
10
+ def ext(newext='')
11
+ Pathname.new(Rake.from_pathname(self).ext(newext))
12
+ end
13
+ end
14
+
15
+ rake_extension("pathmap") do
16
+ # Apply the pathmap spec to the Pathname, returning a
17
+ # new Pathname with the modified paths. (See String#pathmap for
18
+ # details.)
19
+ #
20
+ # This Pathname extension comes from Rake
21
+ def pathmap(spec=nil, &block)
22
+ Pathname.new(Rake.from_pathname(self).pathmap(spec, &block))
23
+ end
24
+ end
25
+ end
@@ -49,7 +49,7 @@ class String
49
49
  end
50
50
  protected :pathmap_partial
51
51
 
52
- # Preform the pathmap replacement operations on the given path. The
52
+ # Perform the pathmap replacement operations on the given path. The
53
53
  # patterns take the form 'pat1,rep1;pat2,rep2...'.
54
54
  #
55
55
  # This String extension comes from Rake
@@ -1,12 +1,13 @@
1
1
  #--
2
- # Extensions to time to allow comparisons with an early time class.
2
+ # Extensions to time to allow comparisons with early and late time classes.
3
3
 
4
4
  require 'rake/early_time'
5
+ require 'rake/late_time'
5
6
 
6
7
  class Time # :nodoc: all
7
8
  alias rake_original_time_compare :<=>
8
9
  def <=>(other)
9
- if Rake::EarlyTime === other
10
+ if Rake::EarlyTime === other || Rake::LateTime === other
10
11
  - other.<=>(self)
11
12
  else
12
13
  rake_original_time_compare(other)
@@ -49,7 +49,7 @@ module Rake
49
49
 
50
50
  # List of methods that should not be delegated here (we define special
51
51
  # versions of them explicitly below).
52
- MUST_NOT_DEFINE = %w[to_a to_ary partition *]
52
+ MUST_NOT_DEFINE = %w[to_a to_ary partition * <<]
53
53
 
54
54
  # List of delegated methods that return new array values which need
55
55
  # wrapping.
@@ -119,7 +119,7 @@ module Rake
119
119
  if fn.respond_to? :to_ary
120
120
  include(*fn.to_ary)
121
121
  else
122
- @pending_add << fn
122
+ @pending_add << Rake.from_pathname(fn)
123
123
  end
124
124
  end
125
125
  @pending = true
@@ -149,7 +149,7 @@ module Rake
149
149
  #
150
150
  def exclude(*patterns, &block)
151
151
  patterns.each do |pat|
152
- @exclude_patterns << pat
152
+ @exclude_patterns << Rake.from_pathname(pat)
153
153
  end
154
154
  @exclude_procs << block if block_given?
155
155
  resolve_exclude unless @pending
@@ -196,6 +196,12 @@ module Rake
196
196
  end
197
197
  end
198
198
 
199
+ def <<(obj)
200
+ resolve
201
+ @items << Rake.from_pathname(obj)
202
+ self
203
+ end
204
+
199
205
  # Resolve all the pending adds now.
200
206
  def resolve
201
207
  if @pending
@@ -346,7 +352,7 @@ module Rake
346
352
 
347
353
  # Should the given file name be excluded from the list?
348
354
  #
349
- # NOTE: This method was formally named "exclude?", but Rails
355
+ # NOTE: This method was formerly named "exclude?", but Rails
350
356
  # introduced an exclude? method as an array method and setup a
351
357
  # conflict with file list. We renamed the method to avoid
352
358
  # confusion. If you were using "FileList#exclude?" in your user
@@ -410,5 +416,13 @@ module Rake
410
416
  dir = File.dirname(dir)
411
417
  end
412
418
  end
419
+
420
+ # Convert Pathname and Pathname-like objects to strings;
421
+ # leave everything else alone
422
+ def from_pathname(path) # :nodoc:
423
+ path = path.to_path if path.respond_to?(:to_path)
424
+ path = path.to_str if path.respond_to?(:to_str)
425
+ path
426
+ end
413
427
  end
414
428
  end # module Rake
@@ -21,7 +21,7 @@ module Rake
21
21
  if File.exist?(name)
22
22
  File.mtime(name.to_s)
23
23
  else
24
- Rake::EARLY
24
+ Rake::LATE
25
25
  end
26
26
  end
27
27
 
@@ -39,7 +39,7 @@ module Rake
39
39
  # Apply the scope to the task name according to the rules for this kind
40
40
  # of task. File based tasks ignore the scope when creating the name.
41
41
  def scope_name(scope, task_name)
42
- task_name
42
+ Rake.from_pathname(task_name)
43
43
  end
44
44
  end
45
45
  end
@@ -14,12 +14,24 @@ module FileUtils
14
14
  OPT_TABLE['sh'] = %w(noop verbose)
15
15
  OPT_TABLE['ruby'] = %w(noop verbose)
16
16
 
17
- # Run the system command +cmd+. If multiple arguments are given the command
18
- # is not run with the shell (same semantics as Kernel::exec and
17
+ # Run the system command +cmd+. If multiple arguments are given the command
18
+ # is run directly (without the shell, same semantics as Kernel::exec and
19
19
  # Kernel::system).
20
20
  #
21
- # Example:
22
- # sh %{ls -ltr}
21
+ # It is recommended you use the multiple argument form over interpolating
22
+ # user input for both usability and security reasons. With the multiple
23
+ # argument form you can easily process files with spaces or other shell
24
+ # reserved characters in them. With the multiple argument form your rake
25
+ # tasks are not vulnerable to users providing an argument like
26
+ # <code>; rm # -rf /</code>.
27
+ #
28
+ # If a block is given, upon command completion the block is called with an
29
+ # OK flag (true on a zero exit status) and a Process::Status object.
30
+ # Without a block a RuntimeError is raised when the command exits non-zero.
31
+ #
32
+ # Examples:
33
+ #
34
+ # sh 'ls -ltr'
23
35
  #
24
36
  # sh 'ls', 'file with spaces'
25
37
  #
@@ -31,7 +31,7 @@ module Rake
31
31
  private
32
32
 
33
33
  def prefix
34
- "#{tail.to_s} => "
34
+ "#{tail} => "
35
35
  end
36
36
 
37
37
  # Null object for an empty chain.
@@ -0,0 +1,17 @@
1
+ module Rake
2
+ # LateTime is a fake timestamp that occurs _after_ any other time value.
3
+ class LateTime
4
+ include Comparable
5
+ include Singleton
6
+
7
+ def <=>(other)
8
+ 1
9
+ end
10
+
11
+ def to_s
12
+ '<LATE TIME>'
13
+ end
14
+ end
15
+
16
+ LATE = LateTime.instance
17
+ end
@@ -127,7 +127,7 @@ module Rake
127
127
  file "#{package_dir}/#{file}" =>
128
128
  [package_dir_path] + package_files do
129
129
  chdir(package_dir) do
130
- sh %{#{@tar_command} #{flag}cvf #{file} #{package_name}}
130
+ sh @tar_command, "#{flag}cvf", file, package_name
131
131
  end
132
132
  end
133
133
  end
@@ -138,15 +138,12 @@ module Rake
138
138
  file "#{package_dir}/#{zip_file}" =>
139
139
  [package_dir_path] + package_files do
140
140
  chdir(package_dir) do
141
- sh %{#{@zip_command} -r #{zip_file} #{package_name}}
141
+ sh @zip_command, "-r", zip_file, package_name
142
142
  end
143
143
  end
144
144
  end
145
145
 
146
- directory package_dir
147
-
148
- file package_dir_path => @package_files do
149
- mkdir_p package_dir rescue nil
146
+ directory package_dir_path => @package_files do
150
147
  @package_files.each do |fn|
151
148
  f = File.join(package_dir_path, fn)
152
149
  fdir = File.dirname(f)
@@ -35,7 +35,7 @@ module Rake
35
35
 
36
36
  task_name = task_class.scope_name(@scope, task_name)
37
37
  deps = [deps] unless deps.respond_to?(:to_ary)
38
- deps = deps.map { |d| d.to_s }
38
+ deps = deps.map { |d| Rake.from_pathname(d).to_s }
39
39
  task = intern(task_class, task_name)
40
40
  task.set_arg_names(arg_names) unless arg_names.empty?
41
41
  if Rake::TaskManager.record_task_metadata
@@ -111,7 +111,7 @@ module Rake
111
111
  if args.empty?
112
112
  task_name = key
113
113
  arg_names = []
114
- deps = value
114
+ deps = value || []
115
115
  else
116
116
  task_name = args.shift
117
117
  arg_names = key
@@ -1,7 +1,10 @@
1
1
  require 'rubygems'
2
2
  $:.unshift File.expand_path('../../lib', __FILE__)
3
3
 
4
- gem 'minitest', '~> 4'
4
+ begin
5
+ gem 'minitest', '~> 5'
6
+ rescue Gem::LoadError
7
+ end
5
8
 
6
9
  require 'minitest/autorun'
7
10
  require 'rake'
@@ -19,7 +22,7 @@ rescue NoMethodError, LoadError
19
22
  require 'test/support/rakefile_definitions'
20
23
  end
21
24
 
22
- class Rake::TestCase < MiniTest::Unit::TestCase
25
+ class Rake::TestCase < Minitest::Test
23
26
  include FileCreation
24
27
 
25
28
  include Rake::DSL
@@ -460,7 +460,7 @@ end
460
460
  TEST_TASK
461
461
  open 'a_test.rb', 'w' do |io|
462
462
  io << "require 'minitest/autorun'\n"
463
- io << "class ExitTaskTest < MiniTest::Unit::TestCase\n"
463
+ io << "class ExitTaskTest < Minitest::Test\n"
464
464
  io << " def test_exit\n"
465
465
  io << " assert false, 'this should fail'\n"
466
466
  io << " end\n"
@@ -18,12 +18,13 @@ module RubyRunner
18
18
  def run_ruby(option_list)
19
19
  puts "COMMAND: [#{RUBY} #{option_list.join ' '}]" if @verbose
20
20
 
21
- inn, out, err, wait = Open3.popen3(RUBY, *option_list)
22
- inn.close
21
+ Open3.popen3(RUBY, *option_list) {|inn, out, err, wait|
22
+ inn.close
23
23
 
24
- @exit = wait ? wait.value : $?
25
- @out = out.read
26
- @err = err.read
24
+ @exit = wait ? wait.value : $?
25
+ @out = out.read
26
+ @err = err.read
27
+ }
27
28
 
28
29
  puts "OUTPUT: [#{@out}]" if @verbose
29
30
  puts "ERROR: [#{@err}]" if @verbose
@@ -10,15 +10,17 @@ class TestRakeApplication < Rake::TestCase
10
10
  end
11
11
 
12
12
  def setup_command_line(*options)
13
- ARGV.clear
13
+ @app.argv.clear
14
14
  options.each do |option|
15
- ARGV << option
15
+ @app.argv << option
16
16
  end
17
17
  end
18
18
 
19
19
  def test_display_exception_details
20
+ obj = Object.new
21
+ obj.instance_eval("def #{__method__}; raise 'test'; end", "ruby")
20
22
  begin
21
- raise 'test'
23
+ obj.__send__(__method__)
22
24
  rescue => ex
23
25
  end
24
26
 
@@ -266,7 +268,7 @@ class TestRakeApplication < Rake::TestCase
266
268
  end
267
269
 
268
270
  def test_load_rakefile_not_found
269
- ARGV.clear
271
+ @app.argv.clear
270
272
  Dir.chdir @tempdir
271
273
  ENV['RAKE_SYSTEM'] = 'not_exist'
272
274
 
@@ -376,7 +378,7 @@ class TestRakeApplication < Rake::TestCase
376
378
 
377
379
  @app.handle_options
378
380
 
379
- assert !ARGV.include?(valid_option)
381
+ assert !@app.argv.include?(valid_option)
380
382
  assert @app.options.trace
381
383
  end
382
384
 
@@ -404,14 +406,14 @@ class TestRakeApplication < Rake::TestCase
404
406
  setup_command_line("--trace", "sometask")
405
407
 
406
408
  @app.handle_options
407
- assert ARGV.include?("sometask")
409
+ assert @app.argv.include?("sometask")
408
410
  assert @app.options.trace
409
411
  end
410
412
 
411
413
  def test_good_run
412
414
  ran = false
413
415
 
414
- ARGV << '--rakelib=""'
416
+ @app.argv << '--rakelib=""'
415
417
 
416
418
  @app.options.silent = true
417
419
 
@@ -466,7 +468,7 @@ class TestRakeApplication < Rake::TestCase
466
468
  }
467
469
  assert_match(/see full trace/i, err)
468
470
  ensure
469
- ARGV.clear
471
+ @app.argv.clear
470
472
  end
471
473
 
472
474
  def test_bad_run_with_trace
@@ -477,7 +479,7 @@ class TestRakeApplication < Rake::TestCase
477
479
  }
478
480
  refute_match(/see full trace/i, err)
479
481
  ensure
480
- ARGV.clear
482
+ @app.argv.clear
481
483
  end
482
484
 
483
485
  def test_bad_run_with_backtrace
@@ -490,7 +492,7 @@ class TestRakeApplication < Rake::TestCase
490
492
  }
491
493
  refute_match(/see full trace/, err)
492
494
  ensure
493
- ARGV.clear
495
+ @app.argv.clear
494
496
  end
495
497
 
496
498
  CustomError = Class.new(RuntimeError)
@@ -547,7 +549,7 @@ class TestRakeApplication < Rake::TestCase
547
549
  end
548
550
  assert_match(/Secondary Error/, err)
549
551
  ensure
550
- ARGV.clear
552
+ @app.argv.clear
551
553
  end
552
554
 
553
555
  def test_run_with_bad_options
@@ -557,7 +559,7 @@ class TestRakeApplication < Rake::TestCase
557
559
  capture_io { @app.run }
558
560
  }
559
561
  ensure
560
- ARGV.clear
562
+ @app.argv.clear
561
563
  end
562
564
 
563
565
  def test_standard_exception_handling_invalid_option
@@ -42,7 +42,7 @@ class TestRakeBacktrace < Rake::TestCase
42
42
  super
43
43
 
44
44
  skip 'tmpdir is suppressed in backtrace' if
45
- Dir.pwd =~ Rake::Backtrace::SUPPRESS_PATTERN
45
+ Rake::Backtrace::SUPPRESS_PATTERN =~ Dir.pwd
46
46
  end
47
47
 
48
48
  def invoke(*args)
@@ -41,7 +41,13 @@ class TestRakeClean < Rake::TestCase
41
41
  FileUtils.touch(file_name)
42
42
  FileUtils.chmod(0, file_name)
43
43
  FileUtils.chmod(0, dir_name)
44
- file_name
44
+ begin
45
+ FileUtils.chmod(0644, file_name)
46
+ rescue
47
+ file_name
48
+ else
49
+ skip "Permission to delete files is different on thie system"
50
+ end
45
51
  end
46
52
 
47
53
  def remove_undeletable_file
@@ -8,43 +8,61 @@ class TestRakeCpuCounter < Rake::TestCase
8
8
  @cpu_counter = Rake::CpuCounter.new
9
9
  end
10
10
 
11
- def test_count_via_win32
12
- if Rake::Win32.windows? then
13
- assert_kind_of Numeric, @cpu_counter.count_via_win32
14
- else
15
- assert_nil @cpu_counter.count_via_win32
16
- end
11
+ def test_count
12
+ num = @cpu_counter.count
13
+ skip 'cannot count CPU' if num == nil
14
+ assert_kind_of Numeric, num
15
+ assert_operator num, :>=, 1
17
16
  end
18
17
 
19
- def test_in_path_command
20
- with_ruby_in_path do |ruby|
21
- assert_equal ruby, @cpu_counter.in_path_command(ruby)
22
- end
23
- rescue Errno::ENOENT => e
24
- raise unless e.message =~ /\bwhich\b/
18
+ def test_count_with_default_nil
19
+ def @cpu_counter.count; nil; end
20
+ assert_equal(8, @cpu_counter.count_with_default(8))
21
+ assert_equal(4, @cpu_counter.count_with_default)
22
+ end
25
23
 
26
- skip 'cannot find which for this test'
24
+ def test_count_with_default_raise
25
+ def @cpu_counter.count; raise; end
26
+ assert_equal(8, @cpu_counter.count_with_default(8))
27
+ assert_equal(4, @cpu_counter.count_with_default)
27
28
  end
28
29
 
29
- def test_run
30
- with_ruby_in_path do |ruby|
31
- assert_equal 7, @cpu_counter.run(ruby, '-e', 'puts 3 + 4')
30
+ class TestClassMethod < Rake::TestCase
31
+ def setup
32
+ super
33
+
34
+ @klass = Class.new(Rake::CpuCounter)
32
35
  end
33
- end
34
36
 
35
- def with_ruby_in_path
36
- ruby = File.basename Gem.ruby
37
- ruby_dir = File.dirname Gem.ruby
37
+ def test_count
38
+ @klass.class_eval do
39
+ def count; 8; end
40
+ end
41
+ assert_equal(8, @klass.count)
42
+ end
38
43
 
39
- begin
40
- orig_path, ENV['PATH'] =
41
- ENV['PATH'], [ruby_dir, *ENV['PATH']].join(File::PATH_SEPARATOR)
44
+ def test_count_nil
45
+ counted = false
46
+ @klass.class_eval do
47
+ define_method(:count) do
48
+ counted = true
49
+ nil
50
+ end
51
+ end
52
+ assert_equal(4, @klass.count)
53
+ assert_equal(true, counted)
54
+ end
42
55
 
43
- yield ruby
44
- ensure
45
- ENV['PATH'] = orig_path
56
+ def test_count_raise
57
+ counted = false
58
+ @klass.class_eval do
59
+ define_method(:count) do
60
+ counted = true
61
+ raise
62
+ end
63
+ end
64
+ assert_equal(4, @klass.count)
65
+ assert_equal(true, counted)
46
66
  end
47
67
  end
48
-
49
68
  end
50
-