necktie 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (214) hide show
  1. data/README.rdoc +174 -0
  2. data/bin/necktie +2 -1
  3. data/lib/necktie/files.rb +29 -0
  4. data/lib/necktie/rake.rb +127 -0
  5. data/lib/necktie/services.rb +11 -7
  6. data/lib/necktie.rb +4 -54
  7. data/necktie.gemspec +3 -3
  8. data/vendor/rake/CHANGES +477 -0
  9. data/vendor/rake/MIT-LICENSE +21 -0
  10. data/vendor/rake/README.rdoc +194 -0
  11. data/vendor/rake/Rakefile +421 -0
  12. data/vendor/rake/TODO +20 -0
  13. data/vendor/rake/bin/rake +31 -0
  14. data/vendor/rake/doc/command_line_usage.rdoc +102 -0
  15. data/vendor/rake/doc/example/Rakefile1 +38 -0
  16. data/vendor/rake/doc/example/Rakefile2 +35 -0
  17. data/vendor/rake/doc/example/a.c +6 -0
  18. data/vendor/rake/doc/example/b.c +6 -0
  19. data/vendor/rake/doc/example/main.c +11 -0
  20. data/vendor/rake/doc/glossary.rdoc +51 -0
  21. data/vendor/rake/doc/jamis.rb +591 -0
  22. data/vendor/rake/doc/proto_rake.rdoc +127 -0
  23. data/vendor/rake/doc/rake.1.gz +0 -0
  24. data/vendor/rake/doc/rakefile.rdoc +566 -0
  25. data/vendor/rake/doc/rational.rdoc +151 -0
  26. data/vendor/rake/doc/release_notes/rake-0.4.14.rdoc +23 -0
  27. data/vendor/rake/doc/release_notes/rake-0.4.15.rdoc +35 -0
  28. data/vendor/rake/doc/release_notes/rake-0.5.0.rdoc +53 -0
  29. data/vendor/rake/doc/release_notes/rake-0.5.3.rdoc +78 -0
  30. data/vendor/rake/doc/release_notes/rake-0.5.4.rdoc +46 -0
  31. data/vendor/rake/doc/release_notes/rake-0.6.0.rdoc +141 -0
  32. data/vendor/rake/doc/release_notes/rake-0.7.0.rdoc +119 -0
  33. data/vendor/rake/doc/release_notes/rake-0.7.1.rdoc +59 -0
  34. data/vendor/rake/doc/release_notes/rake-0.7.2.rdoc +121 -0
  35. data/vendor/rake/doc/release_notes/rake-0.7.3.rdoc +47 -0
  36. data/vendor/rake/doc/release_notes/rake-0.8.0.rdoc +114 -0
  37. data/vendor/rake/doc/release_notes/rake-0.8.2.rdoc +165 -0
  38. data/vendor/rake/doc/release_notes/rake-0.8.3.rdoc +112 -0
  39. data/vendor/rake/doc/release_notes/rake-0.8.4.rdoc +147 -0
  40. data/vendor/rake/doc/release_notes/rake-0.8.5.rdoc +53 -0
  41. data/vendor/rake/doc/release_notes/rake-0.8.6.rdoc +55 -0
  42. data/vendor/rake/doc/release_notes/rake-0.8.7.rdoc +55 -0
  43. data/vendor/rake/install.rb +88 -0
  44. data/vendor/rake/lib/rake/alt_system.rb +108 -0
  45. data/vendor/rake/lib/rake/application.rb +579 -0
  46. data/vendor/rake/lib/rake/classic_namespace.rb +9 -0
  47. data/vendor/rake/lib/rake/clean.rb +35 -0
  48. data/vendor/rake/lib/rake/cloneable.rb +25 -0
  49. data/vendor/rake/lib/rake/contrib/compositepublisher.rb +24 -0
  50. data/vendor/rake/lib/rake/contrib/ftptools.rb +153 -0
  51. data/vendor/rake/lib/rake/contrib/publisher.rb +75 -0
  52. data/vendor/rake/lib/rake/contrib/rubyforgepublisher.rb +18 -0
  53. data/vendor/rake/lib/rake/contrib/sshpublisher.rb +47 -0
  54. data/vendor/rake/lib/rake/contrib/sys.rb +209 -0
  55. data/vendor/rake/lib/rake/default_loader.rb +10 -0
  56. data/vendor/rake/lib/rake/dsl.rb +136 -0
  57. data/vendor/rake/lib/rake/early_time.rb +18 -0
  58. data/vendor/rake/lib/rake/environment.rb +40 -0
  59. data/vendor/rake/lib/rake/ext/module.rb +60 -0
  60. data/vendor/rake/lib/rake/ext/string.rb +165 -0
  61. data/vendor/rake/lib/rake/ext/time.rb +14 -0
  62. data/vendor/rake/lib/rake/file_creation_task.rb +24 -0
  63. data/vendor/rake/lib/rake/file_list.rb +395 -0
  64. data/vendor/rake/lib/rake/file_task.rb +47 -0
  65. data/vendor/rake/lib/rake/file_utils.rb +108 -0
  66. data/vendor/rake/lib/rake/gempackagetask.rb +97 -0
  67. data/vendor/rake/lib/rake/invocation_chain.rb +51 -0
  68. data/vendor/rake/lib/rake/invocation_exception_mixin.rb +16 -0
  69. data/vendor/rake/lib/rake/lib/project.rake +24 -0
  70. data/vendor/rake/lib/rake/loaders/makefile.rb +44 -0
  71. data/vendor/rake/lib/rake/multi_task.rb +16 -0
  72. data/vendor/rake/lib/rake/name_space.rb +25 -0
  73. data/vendor/rake/lib/rake/packagetask.rb +184 -0
  74. data/vendor/rake/lib/rake/psuedo_status.rb +24 -0
  75. data/vendor/rake/lib/rake/rake_file_utils.rb +133 -0
  76. data/vendor/rake/lib/rake/rake_module.rb +25 -0
  77. data/vendor/rake/lib/rake/rake_test_loader.rb +15 -0
  78. data/vendor/rake/lib/rake/rdoctask.rb +209 -0
  79. data/vendor/rake/lib/rake/ruby182_test_unit_fix.rb +25 -0
  80. data/vendor/rake/lib/rake/rule_recursion_overflow_error.rb +20 -0
  81. data/vendor/rake/lib/rake/runtest.rb +23 -0
  82. data/vendor/rake/lib/rake/task.rb +318 -0
  83. data/vendor/rake/lib/rake/task_argument_error.rb +7 -0
  84. data/vendor/rake/lib/rake/task_arguments.rb +78 -0
  85. data/vendor/rake/lib/rake/task_manager.rb +328 -0
  86. data/vendor/rake/lib/rake/tasklib.rb +24 -0
  87. data/vendor/rake/lib/rake/testtask.rb +175 -0
  88. data/vendor/rake/lib/rake/win32.rb +55 -0
  89. data/vendor/rake/lib/rake.rb +72 -0
  90. data/vendor/rake/rake.blurb +19 -0
  91. data/vendor/rake/rake.gemspec +214 -0
  92. data/vendor/rake/rakelib/extra.rake +8 -0
  93. data/vendor/rake/rakelib/publish.rake +22 -0
  94. data/vendor/rake/rakelib/rbx.rake +82 -0
  95. data/vendor/rake/rakelib/ruby19.rake +88 -0
  96. data/vendor/rake/rakelib/tags.rake +18 -0
  97. data/vendor/rake/test/capture_stdout.rb +26 -0
  98. data/vendor/rake/test/check_expansion.rb +5 -0
  99. data/vendor/rake/test/check_no_expansion.rb +5 -0
  100. data/vendor/rake/test/contrib/test_sys.rb +47 -0
  101. data/vendor/rake/test/data/chains/Rakefile +15 -0
  102. data/vendor/rake/test/data/comments/Rakefile +18 -0
  103. data/vendor/rake/test/data/default/Rakefile +19 -0
  104. data/vendor/rake/test/data/dryrun/Rakefile +22 -0
  105. data/vendor/rake/test/data/file_creation_task/Rakefile +33 -0
  106. data/vendor/rake/test/data/imports/Rakefile +19 -0
  107. data/vendor/rake/test/data/imports/deps.mf +1 -0
  108. data/vendor/rake/test/data/multidesc/Rakefile +17 -0
  109. data/vendor/rake/test/data/namespace/Rakefile +66 -0
  110. data/vendor/rake/test/data/nosearch/dummy +1 -0
  111. data/vendor/rake/test/data/rakelib/test1.rb +5 -0
  112. data/vendor/rake/test/data/rakelib/test2.rake +3 -0
  113. data/vendor/rake/test/data/rbext/rakefile.rb +3 -0
  114. data/vendor/rake/test/data/sample.mf +14 -0
  115. data/vendor/rake/test/data/statusreturn/Rakefile +8 -0
  116. data/vendor/rake/test/data/sys/sys1.rake +3 -0
  117. data/vendor/rake/test/data/unittest/Rakefile +1 -0
  118. data/vendor/rake/test/data/unittest/subdir/README +0 -0
  119. data/vendor/rake/test/data/verbose/Rakefile +34 -0
  120. data/vendor/rake/test/filecreation.rb +32 -0
  121. data/vendor/rake/test/functional/functional_test.rb +15 -0
  122. data/vendor/rake/test/functional/session_based_tests.rb +442 -0
  123. data/vendor/rake/test/in_environment.rb +32 -0
  124. data/vendor/rake/test/lib/application_test.rb +769 -0
  125. data/vendor/rake/test/lib/clean_test.rb +15 -0
  126. data/vendor/rake/test/lib/definitions_test.rb +85 -0
  127. data/vendor/rake/test/lib/dsl_test.rb +41 -0
  128. data/vendor/rake/test/lib/earlytime_test.rb +35 -0
  129. data/vendor/rake/test/lib/environment_test.rb +18 -0
  130. data/vendor/rake/test/lib/extension_test.rb +63 -0
  131. data/vendor/rake/test/lib/file_creation_task_test.rb +62 -0
  132. data/vendor/rake/test/lib/file_task_test.rb +143 -0
  133. data/vendor/rake/test/lib/filelist_test.rb +623 -0
  134. data/vendor/rake/test/lib/fileutils_test.rb +251 -0
  135. data/vendor/rake/test/lib/ftp_test.rb +59 -0
  136. data/vendor/rake/test/lib/invocation_chain_test.rb +81 -0
  137. data/vendor/rake/test/lib/makefile_loader_test.rb +26 -0
  138. data/vendor/rake/test/lib/multitask_test.rb +53 -0
  139. data/vendor/rake/test/lib/namespace_test.rb +55 -0
  140. data/vendor/rake/test/lib/package_task_test.rb +118 -0
  141. data/vendor/rake/test/lib/pathmap_test.rb +210 -0
  142. data/vendor/rake/test/lib/pseudo_status_test.rb +26 -0
  143. data/vendor/rake/test/lib/rake_test.rb +41 -0
  144. data/vendor/rake/test/lib/rdoc_task_test.rb +88 -0
  145. data/vendor/rake/test/lib/require_test.rb +35 -0
  146. data/vendor/rake/test/lib/rules_test.rb +349 -0
  147. data/vendor/rake/test/lib/task_arguments_test.rb +89 -0
  148. data/vendor/rake/test/lib/task_manager_test.rb +173 -0
  149. data/vendor/rake/test/lib/task_test.rb +376 -0
  150. data/vendor/rake/test/lib/tasklib_test.rb +12 -0
  151. data/vendor/rake/test/lib/test_task_test.rb +77 -0
  152. data/vendor/rake/test/lib/testtask_test.rb +49 -0
  153. data/vendor/rake/test/lib/top_level_functions_test.rb +86 -0
  154. data/vendor/rake/test/lib/win32_test.rb +72 -0
  155. data/vendor/rake/test/rake_test_setup.rb +24 -0
  156. data/vendor/rake/test/reqfile.rb +3 -0
  157. data/vendor/rake/test/reqfile2.rb +3 -0
  158. data/vendor/rake/test/reqfile3.rake +3 -0
  159. data/vendor/rake/test/shellcommand.rb +3 -0
  160. data/vendor/rake/test/test_helper.rb +13 -0
  161. metadata +212 -56
  162. /data/{rush → vendor/rush}/README.rdoc +0 -0
  163. /data/{rush → vendor/rush}/Rakefile +0 -0
  164. /data/{rush → vendor/rush}/VERSION +0 -0
  165. /data/{rush → vendor/rush}/bin/rush +0 -0
  166. /data/{rush → vendor/rush}/bin/rushd +0 -0
  167. /data/{rush → vendor/rush}/lib/rush/access.rb +0 -0
  168. /data/{rush → vendor/rush}/lib/rush/array_ext.rb +0 -0
  169. /data/{rush → vendor/rush}/lib/rush/box.rb +0 -0
  170. /data/{rush → vendor/rush}/lib/rush/commands.rb +0 -0
  171. /data/{rush → vendor/rush}/lib/rush/config.rb +0 -0
  172. /data/{rush → vendor/rush}/lib/rush/dir.rb +0 -0
  173. /data/{rush → vendor/rush}/lib/rush/embeddable_shell.rb +0 -0
  174. /data/{rush → vendor/rush}/lib/rush/entry.rb +0 -0
  175. /data/{rush → vendor/rush}/lib/rush/exceptions.rb +0 -0
  176. /data/{rush → vendor/rush}/lib/rush/file.rb +0 -0
  177. /data/{rush → vendor/rush}/lib/rush/find_by.rb +0 -0
  178. /data/{rush → vendor/rush}/lib/rush/fixnum_ext.rb +0 -0
  179. /data/{rush → vendor/rush}/lib/rush/head_tail.rb +0 -0
  180. /data/{rush → vendor/rush}/lib/rush/local.rb +0 -0
  181. /data/{rush → vendor/rush}/lib/rush/process.rb +0 -0
  182. /data/{rush → vendor/rush}/lib/rush/process_set.rb +0 -0
  183. /data/{rush → vendor/rush}/lib/rush/remote.rb +0 -0
  184. /data/{rush → vendor/rush}/lib/rush/search_results.rb +0 -0
  185. /data/{rush → vendor/rush}/lib/rush/server.rb +0 -0
  186. /data/{rush → vendor/rush}/lib/rush/shell.rb +0 -0
  187. /data/{rush → vendor/rush}/lib/rush/ssh_tunnel.rb +0 -0
  188. /data/{rush → vendor/rush}/lib/rush/string_ext.rb +0 -0
  189. /data/{rush → vendor/rush}/lib/rush.rb +0 -0
  190. /data/{rush → vendor/rush}/rush.gemspec +0 -0
  191. /data/{rush → vendor/rush}/spec/access_spec.rb +0 -0
  192. /data/{rush → vendor/rush}/spec/array_ext_spec.rb +0 -0
  193. /data/{rush → vendor/rush}/spec/base.rb +0 -0
  194. /data/{rush → vendor/rush}/spec/box_spec.rb +0 -0
  195. /data/{rush → vendor/rush}/spec/commands_spec.rb +0 -0
  196. /data/{rush → vendor/rush}/spec/config_spec.rb +0 -0
  197. /data/{rush → vendor/rush}/spec/dir_spec.rb +0 -0
  198. /data/{rush → vendor/rush}/spec/embeddable_shell_spec.rb +0 -0
  199. /data/{rush → vendor/rush}/spec/entry_spec.rb +0 -0
  200. /data/{rush → vendor/rush}/spec/file_spec.rb +0 -0
  201. /data/{rush → vendor/rush}/spec/find_by_spec.rb +0 -0
  202. /data/{rush → vendor/rush}/spec/fixnum_ext_spec.rb +0 -0
  203. /data/{rush → vendor/rush}/spec/local_spec.rb +0 -0
  204. /data/{rush → vendor/rush}/spec/process_set_spec.rb +0 -0
  205. /data/{rush → vendor/rush}/spec/process_spec.rb +0 -0
  206. /data/{rush → vendor/rush}/spec/remote_spec.rb +0 -0
  207. /data/{rush → vendor/rush}/spec/rush_spec.rb +0 -0
  208. /data/{rush → vendor/rush}/spec/search_results_spec.rb +0 -0
  209. /data/{rush → vendor/rush}/spec/shell_spec.rb +0 -0
  210. /data/{rush → vendor/rush}/spec/ssh_tunnel_spec.rb +0 -0
  211. /data/{rush → vendor/rush}/spec/string_ext_spec.rb +0 -0
  212. /data/{session → vendor/session}/lib/session-2.4.0.rb +0 -0
  213. /data/{session → vendor/session}/lib/session.rb +0 -0
  214. /data/{session → vendor/session}/test/session.rb +0 -0
@@ -0,0 +1,60 @@
1
+ require 'rake/task'
2
+ require 'rake/file_task'
3
+ require 'rake/file_creation_task'
4
+ require 'rake/application'
5
+ require 'rake/task_manager'
6
+
7
+ ######################################################################
8
+ # Rake extensions to Module.
9
+ #
10
+ class Module
11
+ # Check for an existing method in the current class before extending. IF
12
+ # the method already exists, then a warning is printed and the extension is
13
+ # not added. Otherwise the block is yielded and any definitions in the
14
+ # block will take effect.
15
+ #
16
+ # Usage:
17
+ #
18
+ # class String
19
+ # rake_extension("xyz") do
20
+ # def xyz
21
+ # ...
22
+ # end
23
+ # end
24
+ # end
25
+ #
26
+ def rake_extension(method)
27
+ if method_defined?(method)
28
+ $stderr.puts "WARNING: Possible conflict with Rake extension: #{self}##{method} already exists"
29
+ else
30
+ yield
31
+ end
32
+ end
33
+
34
+ # Rename the original handler to make it available.
35
+ alias :rake_original_const_missing :const_missing
36
+
37
+ # Check for deprecated uses of top level (i.e. in Object) uses of
38
+ # Rake class names. If someone tries to reference the constant
39
+ # name, display a warning and return the proper object. Using the
40
+ # --classic-namespace command line option will define these
41
+ # constants in Object and avoid this handler.
42
+ def const_missing(const_name)
43
+ case const_name
44
+ when :Task
45
+ Rake.application.const_warning(const_name)
46
+ Rake::Task
47
+ when :FileTask
48
+ Rake.application.const_warning(const_name)
49
+ Rake::FileTask
50
+ when :FileCreationTask
51
+ Rake.application.const_warning(const_name)
52
+ Rake::FileCreationTask
53
+ when :RakeApp
54
+ Rake.application.const_warning(const_name)
55
+ Rake::Application
56
+ else
57
+ rake_original_const_missing(const_name)
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,165 @@
1
+ ######################################################################
2
+ # Rake extension methods for String.
3
+ #
4
+ class String
5
+ rake_extension("ext") do
6
+ # Replace the file extension with +newext+. If there is no extension on
7
+ # the string, append the new extension to the end. If the new extension
8
+ # is not given, or is the empty string, remove any existing extension.
9
+ #
10
+ # +ext+ is a user added method for the String class.
11
+ def ext(newext='')
12
+ return self.dup if ['.', '..'].include? self
13
+ if newext != ''
14
+ newext = (newext =~ /^\./) ? newext : ("." + newext)
15
+ end
16
+ self.chomp(File.extname(self)) << newext
17
+ end
18
+ end
19
+
20
+ rake_extension("pathmap") do
21
+ # Explode a path into individual components. Used by +pathmap+.
22
+ def pathmap_explode
23
+ head, tail = File.split(self)
24
+ return [self] if head == self
25
+ return [tail] if head == '.' || tail == '/'
26
+ return [head, tail] if head == '/'
27
+ return head.pathmap_explode + [tail]
28
+ end
29
+ protected :pathmap_explode
30
+
31
+ # Extract a partial path from the path. Include +n+ directories from the
32
+ # front end (left hand side) if +n+ is positive. Include |+n+|
33
+ # directories from the back end (right hand side) if +n+ is negative.
34
+ def pathmap_partial(n)
35
+ dirs = File.dirname(self).pathmap_explode
36
+ partial_dirs =
37
+ if n > 0
38
+ dirs[0...n]
39
+ elsif n < 0
40
+ dirs.reverse[0...-n].reverse
41
+ else
42
+ "."
43
+ end
44
+ File.join(partial_dirs)
45
+ end
46
+ protected :pathmap_partial
47
+
48
+ # Preform the pathmap replacement operations on the given path. The
49
+ # patterns take the form 'pat1,rep1;pat2,rep2...'.
50
+ def pathmap_replace(patterns, &block)
51
+ result = self
52
+ patterns.split(';').each do |pair|
53
+ pattern, replacement = pair.split(',')
54
+ pattern = Regexp.new(pattern)
55
+ if replacement == '*' && block_given?
56
+ result = result.sub(pattern, &block)
57
+ elsif replacement
58
+ result = result.sub(pattern, replacement)
59
+ else
60
+ result = result.sub(pattern, '')
61
+ end
62
+ end
63
+ result
64
+ end
65
+ protected :pathmap_replace
66
+
67
+ # Map the path according to the given specification. The specification
68
+ # controls the details of the mapping. The following special patterns are
69
+ # recognized:
70
+ #
71
+ # * <b>%p</b> -- The complete path.
72
+ # * <b>%f</b> -- The base file name of the path, with its file extension,
73
+ # but without any directories.
74
+ # * <b>%n</b> -- The file name of the path without its file extension.
75
+ # * <b>%d</b> -- The directory list of the path.
76
+ # * <b>%x</b> -- The file extension of the path. An empty string if there
77
+ # is no extension.
78
+ # * <b>%X</b> -- Everything *but* the file extension.
79
+ # * <b>%s</b> -- The alternate file separater if defined, otherwise use
80
+ # the standard file separator.
81
+ # * <b>%%</b> -- A percent sign.
82
+ #
83
+ # The %d specifier can also have a numeric prefix (e.g. '%2d'). If the
84
+ # number is positive, only return (up to) +n+ directories in the path,
85
+ # starting from the left hand side. If +n+ is negative, return (up to)
86
+ # |+n+| directories from the right hand side of the path.
87
+ #
88
+ # Examples:
89
+ #
90
+ # 'a/b/c/d/file.txt'.pathmap("%2d") => 'a/b'
91
+ # 'a/b/c/d/file.txt'.pathmap("%-2d") => 'c/d'
92
+ #
93
+ # Also the %d, %p, %f, %n, %x, and %X operators can take a
94
+ # pattern/replacement argument to perform simple string substititions on a
95
+ # particular part of the path. The pattern and replacement are speparated
96
+ # by a comma and are enclosed by curly braces. The replacement spec comes
97
+ # after the % character but before the operator letter. (e.g.
98
+ # "%{old,new}d"). Muliple replacement specs should be separated by
99
+ # semi-colons (e.g. "%{old,new;src,bin}d").
100
+ #
101
+ # Regular expressions may be used for the pattern, and back refs may be
102
+ # used in the replacement text. Curly braces, commas and semi-colons are
103
+ # excluded from both the pattern and replacement text (let's keep parsing
104
+ # reasonable).
105
+ #
106
+ # For example:
107
+ #
108
+ # "src/org/onestepback/proj/A.java".pathmap("%{^src,bin}X.class")
109
+ #
110
+ # returns:
111
+ #
112
+ # "bin/org/onestepback/proj/A.class"
113
+ #
114
+ # If the replacement text is '*', then a block may be provided to perform
115
+ # some arbitrary calculation for the replacement.
116
+ #
117
+ # For example:
118
+ #
119
+ # "/path/to/file.TXT".pathmap("%X%{.*,*}x") { |ext|
120
+ # ext.downcase
121
+ # }
122
+ #
123
+ # Returns:
124
+ #
125
+ # "/path/to/file.txt"
126
+ #
127
+ def pathmap(spec=nil, &block)
128
+ return self if spec.nil?
129
+ result = ''
130
+ spec.scan(/%\{[^}]*\}-?\d*[sdpfnxX%]|%-?\d+d|%.|[^%]+/) do |frag|
131
+ case frag
132
+ when '%f'
133
+ result << File.basename(self)
134
+ when '%n'
135
+ result << File.basename(self).ext
136
+ when '%d'
137
+ result << File.dirname(self)
138
+ when '%x'
139
+ result << File.extname(self)
140
+ when '%X'
141
+ result << self.ext
142
+ when '%p'
143
+ result << self
144
+ when '%s'
145
+ result << (File::ALT_SEPARATOR || File::SEPARATOR)
146
+ when '%-'
147
+ # do nothing
148
+ when '%%'
149
+ result << "%"
150
+ when /%(-?\d+)d/
151
+ result << pathmap_partial($1.to_i)
152
+ when /^%\{([^}]*)\}(\d*[dpfnxX])/
153
+ patterns, operator = $1, $2
154
+ result << pathmap('%' + operator).pathmap_replace(patterns, &block)
155
+ when /^%/
156
+ fail ArgumentError, "Unknown pathmap specifier #{frag} in '#{spec}'"
157
+ else
158
+ result << frag
159
+ end
160
+ end
161
+ result
162
+ end
163
+ end
164
+ end # class String
165
+
@@ -0,0 +1,14 @@
1
+ # ###########################################################################
2
+ # Extensions to time to allow comparisons with an early time class.
3
+ #
4
+ class Time
5
+ alias rake_original_time_compare :<=>
6
+ def <=>(other)
7
+ if Rake::EarlyTime === other
8
+ - other.<=>(self)
9
+ else
10
+ rake_original_time_compare(other)
11
+ end
12
+ end
13
+ end # class Time
14
+
@@ -0,0 +1,24 @@
1
+ require 'rake/file_task'
2
+ require 'rake/early_time'
3
+
4
+ module Rake
5
+
6
+ # A FileCreationTask is a file task that when used as a dependency will be
7
+ # needed if and only if the file has not been created. Once created, it is
8
+ # not re-triggered if any of its dependencies are newer, nor does trigger
9
+ # any rebuilds of tasks that depend on it whenever it is updated.
10
+ #
11
+ class FileCreationTask < FileTask
12
+ # Is this file task needed? Yes if it doesn't exist.
13
+ def needed?
14
+ ! File.exist?(name)
15
+ end
16
+
17
+ # Time stamp for file creation task. This time stamp is earlier
18
+ # than any other time stamp.
19
+ def timestamp
20
+ Rake::EARLY
21
+ end
22
+ end
23
+
24
+ end
@@ -0,0 +1,395 @@
1
+ require 'rake/cloneable'
2
+ require 'rake/rake_file_utils'
3
+
4
+ ######################################################################
5
+ module Rake
6
+
7
+ # #########################################################################
8
+ # A FileList is essentially an array with a few helper methods defined to
9
+ # make file manipulation a bit easier.
10
+ #
11
+ # FileLists are lazy. When given a list of glob patterns for possible files
12
+ # to be included in the file list, instead of searching the file structures
13
+ # to find the files, a FileList holds the pattern for latter use.
14
+ #
15
+ # This allows us to define a number of FileList to match any number of
16
+ # files, but only search out the actual files when then FileList itself is
17
+ # actually used. The key is that the first time an element of the
18
+ # FileList/Array is requested, the pending patterns are resolved into a real
19
+ # list of file names.
20
+ #
21
+ class FileList
22
+
23
+ include Cloneable
24
+
25
+ # == Method Delegation
26
+ #
27
+ # The lazy evaluation magic of FileLists happens by implementing all the
28
+ # array specific methods to call +resolve+ before delegating the heavy
29
+ # lifting to an embedded array object (@items).
30
+ #
31
+ # In addition, there are two kinds of delegation calls. The regular kind
32
+ # delegates to the @items array and returns the result directly. Well,
33
+ # almost directly. It checks if the returned value is the @items object
34
+ # itself, and if so will return the FileList object instead.
35
+ #
36
+ # The second kind of delegation call is used in methods that normally
37
+ # return a new Array object. We want to capture the return value of these
38
+ # methods and wrap them in a new FileList object. We enumerate these
39
+ # methods in the +SPECIAL_RETURN+ list below.
40
+
41
+ # List of array methods (that are not in +Object+) that need to be
42
+ # delegated.
43
+ ARRAY_METHODS = (Array.instance_methods - Object.instance_methods).map { |n| n.to_s }
44
+
45
+ # List of additional methods that must be delegated.
46
+ MUST_DEFINE = %w[to_a inspect]
47
+
48
+ # List of methods that should not be delegated here (we define special
49
+ # versions of them explicitly below).
50
+ MUST_NOT_DEFINE = %w[to_a to_ary partition *]
51
+
52
+ # List of delegated methods that return new array values which need
53
+ # wrapping.
54
+ SPECIAL_RETURN = %w[
55
+ map collect sort sort_by select find_all reject grep
56
+ compact flatten uniq values_at
57
+ + - & |
58
+ ]
59
+
60
+ DELEGATING_METHODS = (ARRAY_METHODS + MUST_DEFINE - MUST_NOT_DEFINE).collect{ |s| s.to_s }.sort.uniq
61
+
62
+ # Now do the delegation.
63
+ DELEGATING_METHODS.each_with_index do |sym, i|
64
+ if SPECIAL_RETURN.include?(sym)
65
+ ln = __LINE__+1
66
+ class_eval %{
67
+ def #{sym}(*args, &block)
68
+ resolve
69
+ result = @items.send(:#{sym}, *args, &block)
70
+ FileList.new.import(result)
71
+ end
72
+ }, __FILE__, ln
73
+ else
74
+ ln = __LINE__+1
75
+ class_eval %{
76
+ def #{sym}(*args, &block)
77
+ resolve
78
+ result = @items.send(:#{sym}, *args, &block)
79
+ result.object_id == @items.object_id ? self : result
80
+ end
81
+ }, __FILE__, ln
82
+ end
83
+ end
84
+
85
+ # Create a file list from the globbable patterns given. If you wish to
86
+ # perform multiple includes or excludes at object build time, use the
87
+ # "yield self" pattern.
88
+ #
89
+ # Example:
90
+ # file_list = FileList.new('lib/**/*.rb', 'test/test*.rb')
91
+ #
92
+ # pkg_files = FileList.new('lib/**/*') do |fl|
93
+ # fl.exclude(/\bCVS\b/)
94
+ # end
95
+ #
96
+ def initialize(*patterns)
97
+ @pending_add = []
98
+ @pending = false
99
+ @exclude_patterns = DEFAULT_IGNORE_PATTERNS.dup
100
+ @exclude_procs = DEFAULT_IGNORE_PROCS.dup
101
+ @items = []
102
+ patterns.each { |pattern| include(pattern) }
103
+ yield self if block_given?
104
+ end
105
+
106
+ # Add file names defined by glob patterns to the file list. If an array
107
+ # is given, add each element of the array.
108
+ #
109
+ # Example:
110
+ # file_list.include("*.java", "*.cfg")
111
+ # file_list.include %w( math.c lib.h *.o )
112
+ #
113
+ def include(*filenames)
114
+ # TODO: check for pending
115
+ filenames.each do |fn|
116
+ if fn.respond_to? :to_ary
117
+ include(*fn.to_ary)
118
+ else
119
+ @pending_add << fn
120
+ end
121
+ end
122
+ @pending = true
123
+ self
124
+ end
125
+ alias :add :include
126
+
127
+ # Register a list of file name patterns that should be excluded from the
128
+ # list. Patterns may be regular expressions, glob patterns or regular
129
+ # strings. In addition, a block given to exclude will remove entries that
130
+ # return true when given to the block.
131
+ #
132
+ # Note that glob patterns are expanded against the file system. If a file
133
+ # is explicitly added to a file list, but does not exist in the file
134
+ # system, then an glob pattern in the exclude list will not exclude the
135
+ # file.
136
+ #
137
+ # Examples:
138
+ # FileList['a.c', 'b.c'].exclude("a.c") => ['b.c']
139
+ # FileList['a.c', 'b.c'].exclude(/^a/) => ['b.c']
140
+ #
141
+ # If "a.c" is a file, then ...
142
+ # FileList['a.c', 'b.c'].exclude("a.*") => ['b.c']
143
+ #
144
+ # If "a.c" is not a file, then ...
145
+ # FileList['a.c', 'b.c'].exclude("a.*") => ['a.c', 'b.c']
146
+ #
147
+ def exclude(*patterns, &block)
148
+ patterns.each do |pat|
149
+ @exclude_patterns << pat
150
+ end
151
+ if block_given?
152
+ @exclude_procs << block
153
+ end
154
+ resolve_exclude if ! @pending
155
+ self
156
+ end
157
+
158
+
159
+ # Clear all the exclude patterns so that we exclude nothing.
160
+ def clear_exclude
161
+ @exclude_patterns = []
162
+ @exclude_procs = []
163
+ self
164
+ end
165
+
166
+ # Define equality.
167
+ def ==(array)
168
+ to_ary == array
169
+ end
170
+
171
+ # Return the internal array object.
172
+ def to_a
173
+ resolve
174
+ @items
175
+ end
176
+
177
+ # Return the internal array object.
178
+ def to_ary
179
+ to_a
180
+ end
181
+
182
+ # Lie about our class.
183
+ def is_a?(klass)
184
+ klass == Array || super(klass)
185
+ end
186
+ alias kind_of? is_a?
187
+
188
+ # Redefine * to return either a string or a new file list.
189
+ def *(other)
190
+ result = @items * other
191
+ case result
192
+ when Array
193
+ FileList.new.import(result)
194
+ else
195
+ result
196
+ end
197
+ end
198
+
199
+ # Resolve all the pending adds now.
200
+ def resolve
201
+ if @pending
202
+ @pending = false
203
+ @pending_add.each do |fn| resolve_add(fn) end
204
+ @pending_add = []
205
+ resolve_exclude
206
+ end
207
+ self
208
+ end
209
+
210
+ def resolve_add(fn)
211
+ case fn
212
+ when %r{[*?\[\{]}
213
+ add_matching(fn)
214
+ else
215
+ self << fn
216
+ end
217
+ end
218
+ private :resolve_add
219
+
220
+ def resolve_exclude
221
+ reject! { |fn| exclude?(fn) }
222
+ self
223
+ end
224
+ private :resolve_exclude
225
+
226
+ # Return a new FileList with the results of running +sub+ against each
227
+ # element of the oringal list.
228
+ #
229
+ # Example:
230
+ # FileList['a.c', 'b.c'].sub(/\.c$/, '.o') => ['a.o', 'b.o']
231
+ #
232
+ def sub(pat, rep)
233
+ inject(FileList.new) { |res, fn| res << fn.sub(pat,rep) }
234
+ end
235
+
236
+ # Return a new FileList with the results of running +gsub+ against each
237
+ # element of the original list.
238
+ #
239
+ # Example:
240
+ # FileList['lib/test/file', 'x/y'].gsub(/\//, "\\")
241
+ # => ['lib\\test\\file', 'x\\y']
242
+ #
243
+ def gsub(pat, rep)
244
+ inject(FileList.new) { |res, fn| res << fn.gsub(pat,rep) }
245
+ end
246
+
247
+ # Same as +sub+ except that the oringal file list is modified.
248
+ def sub!(pat, rep)
249
+ each_with_index { |fn, i| self[i] = fn.sub(pat,rep) }
250
+ self
251
+ end
252
+
253
+ # Same as +gsub+ except that the original file list is modified.
254
+ def gsub!(pat, rep)
255
+ each_with_index { |fn, i| self[i] = fn.gsub(pat,rep) }
256
+ self
257
+ end
258
+
259
+ # Apply the pathmap spec to each of the included file names, returning a
260
+ # new file list with the modified paths. (See String#pathmap for
261
+ # details.)
262
+ def pathmap(spec=nil)
263
+ collect { |fn| fn.pathmap(spec) }
264
+ end
265
+
266
+ # Return a new FileList with <tt>String#ext</tt> method applied
267
+ # to each member of the array.
268
+ #
269
+ # This method is a shortcut for:
270
+ #
271
+ # array.collect { |item| item.ext(newext) }
272
+ #
273
+ # +ext+ is a user added method for the Array class.
274
+ def ext(newext='')
275
+ collect { |fn| fn.ext(newext) }
276
+ end
277
+
278
+
279
+ # Grep each of the files in the filelist using the given pattern. If a
280
+ # block is given, call the block on each matching line, passing the file
281
+ # name, line number, and the matching line of text. If no block is given,
282
+ # a standard emac style file:linenumber:line message will be printed to
283
+ # standard out.
284
+ def egrep(pattern, *options)
285
+ each do |fn|
286
+ open(fn, "rb", *options) do |inf|
287
+ count = 0
288
+ inf.each do |line|
289
+ count += 1
290
+ if pattern.match(line)
291
+ if block_given?
292
+ yield fn, count, line
293
+ else
294
+ puts "#{fn}:#{count}:#{line}"
295
+ end
296
+ end
297
+ end
298
+ end
299
+ end
300
+ end
301
+
302
+ # Return a new file list that only contains file names from the current
303
+ # file list that exist on the file system.
304
+ def existing
305
+ select { |fn| File.exist?(fn) }
306
+ end
307
+
308
+ # Modify the current file list so that it contains only file name that
309
+ # exist on the file system.
310
+ def existing!
311
+ resolve
312
+ @items = @items.select { |fn| File.exist?(fn) }
313
+ self
314
+ end
315
+
316
+ # FileList version of partition. Needed because the nested arrays should
317
+ # be FileLists in this version.
318
+ def partition(&block) # :nodoc:
319
+ resolve
320
+ result = @items.partition(&block)
321
+ [
322
+ FileList.new.import(result[0]),
323
+ FileList.new.import(result[1]),
324
+ ]
325
+ end
326
+
327
+ # Convert a FileList to a string by joining all elements with a space.
328
+ def to_s
329
+ resolve
330
+ self.join(' ')
331
+ end
332
+
333
+ # Add matching glob patterns.
334
+ def add_matching(pattern)
335
+ Dir[pattern].each do |fn|
336
+ self << fn unless exclude?(fn)
337
+ end
338
+ end
339
+ private :add_matching
340
+
341
+ # Should the given file name be excluded?
342
+ def exclude?(fn)
343
+ return true if @exclude_patterns.any? do |pat|
344
+ case pat
345
+ when Regexp
346
+ fn =~ pat
347
+ when /[*?]/
348
+ File.fnmatch?(pat, fn, File::FNM_PATHNAME)
349
+ else
350
+ fn == pat
351
+ end
352
+ end
353
+ @exclude_procs.any? { |p| p.call(fn) }
354
+ end
355
+
356
+ DEFAULT_IGNORE_PATTERNS = [
357
+ /(^|[\/\\])CVS([\/\\]|$)/,
358
+ /(^|[\/\\])\.svn([\/\\]|$)/,
359
+ /\.bak$/,
360
+ /~$/
361
+ ]
362
+ DEFAULT_IGNORE_PROCS = [
363
+ proc { |fn| fn =~ /(^|[\/\\])core$/ && ! File.directory?(fn) }
364
+ ]
365
+
366
+ def import(array)
367
+ @items = array
368
+ self
369
+ end
370
+
371
+ class << self
372
+ # Create a new file list including the files listed. Similar to:
373
+ #
374
+ # FileList.new(*args)
375
+ def [](*args)
376
+ new(*args)
377
+ end
378
+ end
379
+ end
380
+ end
381
+
382
+ module Rake
383
+ class << self
384
+
385
+ # Yield each file or directory component.
386
+ def each_dir_parent(dir) # :nodoc:
387
+ old_length = nil
388
+ while dir != '.' && dir.length != old_length
389
+ yield(dir)
390
+ old_length = dir.length
391
+ dir = File.dirname(dir)
392
+ end
393
+ end
394
+ end
395
+ end # module Rake
@@ -0,0 +1,47 @@
1
+ require 'rake/task.rb'
2
+ require 'rake/early_time'
3
+
4
+ module Rake
5
+ # #########################################################################
6
+ # A FileTask is a task that includes time based dependencies. If any of a
7
+ # FileTask's prerequisites have a timestamp that is later than the file
8
+ # represented by this task, then the file must be rebuilt (using the
9
+ # supplied actions).
10
+ #
11
+ class FileTask < Task
12
+
13
+ # Is this file task needed? Yes if it doesn't exist, or if its time stamp
14
+ # is out of date.
15
+ def needed?
16
+ ! File.exist?(name) || out_of_date?(timestamp)
17
+ end
18
+
19
+ # Time stamp for file task.
20
+ def timestamp
21
+ if File.exist?(name)
22
+ File.mtime(name.to_s)
23
+ else
24
+ Rake::EARLY
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ # Are there any prerequisites with a later time than the given time stamp?
31
+ def out_of_date?(stamp)
32
+ @prerequisites.any? { |n| application[n, @scope].timestamp > stamp}
33
+ end
34
+
35
+ # ----------------------------------------------------------------
36
+ # Task class methods.
37
+ #
38
+ class << self
39
+ # Apply the scope to the task name according to the rules for this kind
40
+ # of task. File based tasks ignore the scope when creating the name.
41
+ def scope_name(scope, task_name)
42
+ task_name
43
+ end
44
+ end
45
+ end
46
+ end
47
+