@@ -395,7 +395,7 @@ def needed?
395
395
# Timestamp for this task. Basic tasks return the current time for
396
396
# their time stamp. Other tasks can be more sophisticated.
397
397
def timestamp
398
- @prerequisites . collect { |p | Rake :: Task [ p ] . timestamp } . max || Time . now
398
+ @prerequisites . collect { |p | application [ p ] . timestamp } . max || Time . now
399
399
end
400
400
401
401
# Add a comment to the task. If a comment alread exists, separate
@@ -419,12 +419,12 @@ def investigation
419
419
result << "task needed: #{ needed? } \n "
420
420
result << "timestamp: #{ timestamp } \n "
421
421
result << "pre-requisites: \n "
422
- prereqs = @prerequisites . collect { |name | Rake :: Task [ name ] }
422
+ prereqs = @prerequisites . collect { |name | application [ name ] }
423
423
prereqs . sort! { |a , b | a . timestamp <=> b . timestamp }
424
424
prereqs . each do |p |
425
425
result << "--#{ p . name } (#{ p . timestamp } )\n "
426
426
end
427
- latest_prereq = @prerequisites . collect { |n | Rake :: Task [ n ] . timestamp } . max
427
+ latest_prereq = @prerequisites . collect { |n | application [ n ] . timestamp } . max
428
428
result << "latest-prerequisite time: #{ latest_prereq } \n "
429
429
result << "................................\n \n "
430
430
return result
@@ -513,7 +513,7 @@ def timestamp
513
513
# Are there any prerequisites with a later time than the given
514
514
# time stamp?
515
515
def out_of_date? ( stamp )
516
- @prerequisites . any? { |n | Rake :: Task [ n ] . timestamp > stamp }
516
+ @prerequisites . any? { |n | application [ n ] . timestamp > stamp }
517
517
end
518
518
519
519
# ----------------------------------------------------------------
@@ -555,7 +555,7 @@ def timestamp
555
555
class MultiTask < Task
556
556
def invoke_prerequisites
557
557
threads = @prerequisites . collect { |p |
558
- Thread . new ( p ) { |r | Task [ r ] . invoke }
558
+ Thread . new ( p ) { |r | application [ r ] . invoke }
559
559
}
560
560
threads . each { |t | t . join }
561
561
end
@@ -710,11 +710,7 @@ module FileUtils
710
710
# end
711
711
#
712
712
def sh ( *cmd , &block )
713
- if Hash === cmd . last then
714
- options = cmd . pop
715
- else
716
- options = { }
717
- end
713
+ options = ( Hash === cmd . last ) ? cmd . pop : { }
718
714
unless block_given?
719
715
show_command = cmd . join ( " " )
720
716
show_command = show_command [ 0 , 42 ] + "..." if show_command . length > 45
@@ -736,11 +732,7 @@ def sh(*cmd, &block)
736
732
# ruby %{-pe '$_.upcase!' <README}
737
733
#
738
734
def ruby ( *args , &block )
739
- if Hash === args . last
740
- options = args . pop
741
- else
742
- options = { }
743
- end
735
+ options = ( Hash === args . last ) ? args . pop : { }
744
736
if args . length > 1 then
745
737
sh ( *( [ RUBY ] + args + [ options ] ) , &block )
746
738
else
@@ -758,7 +750,7 @@ def safe_ln(*args)
758
750
else
759
751
begin
760
752
ln ( *args )
761
- rescue StandardError , NotImplementedError
753
+ rescue StandardError , NotImplementedError => ex
762
754
LN_SUPPORTED [ 0 ] = false
763
755
cp ( *args )
764
756
end
@@ -1125,7 +1117,7 @@ def calculate_exclude_regexp
1125
1117
case pat
1126
1118
when Regexp
1127
1119
ignores << pat
1128
- when /[*. ]/
1120
+ when /[*? ]/
1129
1121
Dir [ pat ] . each do |p | ignores << p end
1130
1122
else
1131
1123
ignores << Regexp . quote ( pat )
@@ -1141,8 +1133,6 @@ def calculate_exclude_regexp
1141
1133
1142
1134
def resolve_add ( fn )
1143
1135
case fn
1144
- when Array
1145
- fn . each { |f | self . resolve_add ( f ) }
1146
1136
when %r{[*?]}
1147
1137
add_matching ( fn )
1148
1138
else
@@ -1156,7 +1146,7 @@ def resolve_exclude
1156
1146
case pat
1157
1147
when Regexp
1158
1148
reject! { |fn | fn =~ pat }
1159
- when /[*. ]/
1149
+ when /[*? ]/
1160
1150
reject_list = Dir [ pat ]
1161
1151
reject! { |fn | reject_list . include? ( fn ) }
1162
1152
else
@@ -1427,7 +1417,6 @@ def define_task(task_class, args, &block)
1427
1417
deps = [ deps ] unless deps . respond_to? ( :to_ary )
1428
1418
deps = deps . collect { |d | d . to_s }
1429
1419
task = intern ( task_class , task_name )
1430
- task . application = self
1431
1420
task . add_comment ( @last_comment )
1432
1421
@last_comment = nil
1433
1422
task . enhance ( deps , &block )
@@ -1602,9 +1591,9 @@ class Application
1602
1591
include TaskManager
1603
1592
1604
1593
# The original directory where rake was invoked.
1605
- attr_reader :original_dir
1594
+ attr_reader :original_dir , :rakefile
1606
1595
1607
- RAKEFILES = [ 'rakefile' , 'Rakefile' , 'rakefile.rb' , 'Rakefile.rb' ]
1596
+ DEFAULT_RAKEFILES = [ 'rakefile' , 'Rakefile' , 'rakefile.rb' , 'Rakefile.rb' ] . freeze
1608
1597
1609
1598
OPTIONS = [
1610
1599
[ '--dry-run' , '-n' , GetoptLong ::NO_ARGUMENT ,
@@ -1644,6 +1633,7 @@ class Application
1644
1633
# Create a Rake::Application object.
1645
1634
def initialize
1646
1635
super
1636
+ @rakefiles = DEFAULT_RAKEFILES . dup
1647
1637
@rakefile = nil
1648
1638
@pending_imports = [ ]
1649
1639
@imported = [ ]
@@ -1662,7 +1652,7 @@ def options
1662
1652
# True if one of the files in RAKEFILES is in the current directory.
1663
1653
# If a match is found, it is copied into @rakefile.
1664
1654
def have_rakefile
1665
- RAKEFILES . each do |fn |
1655
+ @rakefiles . each do |fn |
1666
1656
if File . exist? ( fn ) || fn == ''
1667
1657
@rakefile = fn
1668
1658
return true
@@ -1695,20 +1685,18 @@ def help
1695
1685
1696
1686
# Display the tasks and dependencies.
1697
1687
def display_tasks_and_comments
1698
- displayable_tasks = Rake :: Task . tasks . select { |t |
1688
+ displayable_tasks = tasks . select { |t |
1699
1689
t . comment && t . name =~ options . show_task_pattern
1700
1690
}
1701
- width = displayable_tasks . collect { |t |
1702
- t . name . length
1703
- } . max
1691
+ width = displayable_tasks . collect { |t | t . name . length } . max
1704
1692
displayable_tasks . each do |t |
1705
1693
printf "rake %-#{ width } s # %s\n " , t . name , t . comment
1706
1694
end
1707
1695
end
1708
1696
1709
1697
# Display the tasks and prerequisites
1710
1698
def display_prerequisites
1711
- Rake :: Task . tasks . each do |t |
1699
+ tasks . each do |t |
1712
1700
puts "rake #{ t . name } "
1713
1701
t . prerequisites . each { |pre | puts " #{ pre } " }
1714
1702
end
@@ -1740,8 +1728,8 @@ def do_option(opt, value)
1740
1728
when '--quiet'
1741
1729
verbose ( false )
1742
1730
when '--rakefile'
1743
- RAKEFILES . clear
1744
- RAKEFILES << value
1731
+ @rakefiles . clear
1732
+ @rakefiles << value
1745
1733
when '--rakelibdir'
1746
1734
options . rakelib = value . split ( ':' )
1747
1735
when '--require'
@@ -1774,8 +1762,6 @@ def do_option(opt, value)
1774
1762
when '--classic-namespace'
1775
1763
require 'rake/classic_namespace'
1776
1764
options . classic_namespace = true
1777
- else
1778
- fail "Unknown option: #{ opt } "
1779
1765
end
1780
1766
end
1781
1767
@@ -1819,7 +1805,7 @@ def load_rakefile
1819
1805
while ! have_rakefile
1820
1806
Dir . chdir ( ".." )
1821
1807
if Dir . pwd == here || options . nosearch
1822
- fail "No Rakefile found (looking for: #{ RAKEFILES . join ( ', ' ) } )"
1808
+ fail "No Rakefile found (looking for: #{ @rakefiles . join ( ', ' ) } )"
1823
1809
end
1824
1810
here = Dir . pwd
1825
1811
end
@@ -1833,7 +1819,7 @@ def load_rakefile
1833
1819
end
1834
1820
1835
1821
# Collect the list of tasks on the command line. If no tasks are
1836
- # give , return a list containing only the default task.
1822
+ # given , return a list containing only the default task.
1837
1823
# Environmental assignments are processed at this time as well.
1838
1824
def collect_tasks
1839
1825
tasks = [ ]
@@ -1857,7 +1843,9 @@ def add_import(fn)
1857
1843
def load_imports
1858
1844
while fn = @pending_imports . shift
1859
1845
next if @imported . member? ( fn )
1860
- Rake ::Task [ fn ] . invoke if Rake ::Task . task_defined? ( fn )
1846
+ if fn_task = lookup ( fn )
1847
+ fn_task . invoke
1848
+ end
1861
1849
ext = File . extname ( fn )
1862
1850
loader = @loaders [ ext ] || @default_loader
1863
1851
loader . load ( fn )
@@ -1903,7 +1891,7 @@ def run
1903
1891
elsif options . show_prereqs
1904
1892
display_prerequisites
1905
1893
else
1906
- tasks . each { |task_name | Rake :: Task [ task_name ] . invoke }
1894
+ tasks . each { |task_name | self [ task_name ] . invoke }
1907
1895
end
1908
1896
rescue SystemExit , GetoptLong ::InvalidOption => ex
1909
1897
# Exit silently
0 commit comments