vic-buildr 1.3.1 → 1.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (127) hide show
  1. data/CHANGELOG +90 -8
  2. data/{README → README.rdoc} +29 -16
  3. data/Rakefile +17 -19
  4. data/_buildr +50 -0
  5. data/addon/buildr/cobertura.rb +47 -44
  6. data/addon/buildr/emma.rb +237 -0
  7. data/addon/buildr/jetty.rb +1 -1
  8. data/addon/buildr/nailgun.rb +581 -661
  9. data/{lib/buildr/java → addon/buildr}/org/apache/buildr/BuildrNail$Main.class +0 -0
  10. data/{lib/buildr/java → addon/buildr}/org/apache/buildr/BuildrNail.class +0 -0
  11. data/{lib/buildr/java → addon/buildr}/org/apache/buildr/BuildrNail.java +0 -0
  12. data/addon/buildr/xmlbeans.rb +1 -1
  13. data/bin/buildr +9 -2
  14. data/buildr.buildfile +53 -0
  15. data/buildr.gemspec +23 -15
  16. data/doc/css/default.css +51 -48
  17. data/doc/css/print.css +60 -55
  18. data/doc/css/syntax.css +40 -31
  19. data/doc/images/growl-icon.tiff +0 -0
  20. data/doc/images/project-structure.png +0 -0
  21. data/doc/pages/artifacts.textile +46 -156
  22. data/doc/pages/building.textile +63 -324
  23. data/doc/pages/contributing.textile +116 -88
  24. data/doc/pages/download.textile +20 -15
  25. data/doc/pages/extending.textile +27 -81
  26. data/doc/pages/getting_started.textile +47 -111
  27. data/doc/pages/index.textile +19 -37
  28. data/doc/pages/languages.textile +407 -0
  29. data/doc/pages/more_stuff.textile +92 -173
  30. data/doc/pages/packaging.textile +72 -237
  31. data/doc/pages/projects.textile +58 -233
  32. data/doc/pages/recipes.textile +19 -43
  33. data/doc/pages/settings_profiles.textile +39 -104
  34. data/doc/pages/testing.textile +41 -304
  35. data/doc/pages/troubleshooting.textile +29 -47
  36. data/doc/pages/whats_new.textile +66 -157
  37. data/doc/print.haml +0 -1
  38. data/doc/print.toc.yaml +1 -0
  39. data/doc/scripts/buildr-git.rb +1 -1
  40. data/doc/scripts/install-jruby.sh +1 -1
  41. data/doc/scripts/install-linux.sh +4 -4
  42. data/doc/site.toc.yaml +8 -5
  43. data/{KEYS → etc/KEYS} +0 -0
  44. data/etc/git-svn-authors +16 -0
  45. data/lib/buildr.rb +2 -13
  46. data/lib/buildr/core/application.rb +200 -95
  47. data/lib/buildr/core/application_cli.rb +6 -1
  48. data/lib/buildr/core/build.rb +140 -91
  49. data/lib/buildr/core/checks.rb +5 -5
  50. data/lib/buildr/core/common.rb +1 -1
  51. data/lib/buildr/core/compile.rb +14 -12
  52. data/lib/buildr/core/filter.rb +151 -46
  53. data/lib/buildr/core/generate.rb +9 -7
  54. data/lib/buildr/core/progressbar.rb +1 -1
  55. data/lib/buildr/core/project.rb +8 -7
  56. data/lib/buildr/core/test.rb +54 -29
  57. data/lib/buildr/core/transports.rb +25 -20
  58. data/lib/buildr/core/util.rb +80 -26
  59. data/lib/buildr/groovy.rb +18 -0
  60. data/lib/buildr/groovy/bdd.rb +105 -0
  61. data/lib/buildr/groovy/compiler.rb +138 -0
  62. data/lib/buildr/ide/eclipse.rb +102 -71
  63. data/lib/buildr/ide/idea.rb +7 -12
  64. data/lib/buildr/ide/idea7x.rb +20 -20
  65. data/lib/buildr/java.rb +4 -7
  66. data/lib/buildr/java/ant.rb +26 -5
  67. data/lib/buildr/java/bdd.rb +447 -0
  68. data/lib/buildr/java/commands.rb +8 -9
  69. data/lib/buildr/java/{compilers.rb → compiler.rb} +8 -90
  70. data/lib/buildr/java/jruby.rb +29 -11
  71. data/lib/buildr/java/jtestr_runner.rb.erb +114 -0
  72. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  73. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +4 -1
  74. data/lib/buildr/java/packaging.rb +23 -16
  75. data/lib/buildr/java/pom.rb +1 -1
  76. data/lib/buildr/java/rjb.rb +21 -8
  77. data/lib/buildr/java/test_result.rb +277 -0
  78. data/lib/buildr/java/{test_frameworks.rb → tests.rb} +121 -88
  79. data/lib/buildr/packaging/artifact.rb +12 -11
  80. data/lib/buildr/packaging/artifact_namespace.rb +7 -4
  81. data/lib/buildr/packaging/gems.rb +3 -3
  82. data/lib/buildr/packaging/zip.rb +13 -10
  83. data/lib/buildr/resources/buildr.icns +0 -0
  84. data/lib/buildr/scala.rb +19 -0
  85. data/lib/buildr/scala/compiler.rb +109 -0
  86. data/lib/buildr/scala/tests.rb +203 -0
  87. data/rakelib/apache.rake +31 -41
  88. data/rakelib/doc.rake +2 -2
  89. data/rakelib/package.rake +31 -2
  90. data/rakelib/rspec.rake +22 -20
  91. data/rakelib/rubyforge.rake +1 -0
  92. data/rakelib/setup.rake +34 -9
  93. data/spec/addon/cobertura_spec.rb +77 -0
  94. data/spec/addon/emma_spec.rb +120 -0
  95. data/spec/addon/test_coverage_spec.rb +249 -0
  96. data/spec/{application_spec.rb → core/application_spec.rb} +82 -4
  97. data/spec/{artifact_namespace_spec.rb → core/artifact_namespace_spec.rb} +12 -1
  98. data/spec/core/build_spec.rb +415 -0
  99. data/spec/{checks_spec.rb → core/checks_spec.rb} +1 -1
  100. data/spec/{common_spec.rb → core/common_spec.rb} +119 -30
  101. data/spec/{compile_spec.rb → core/compile_spec.rb} +17 -13
  102. data/spec/{project_spec.rb → core/project_spec.rb} +9 -6
  103. data/spec/{test_spec.rb → core/test_spec.rb} +226 -32
  104. data/spec/{transport_spec.rb → core/transport_spec.rb} +35 -23
  105. data/spec/groovy/bdd_spec.rb +80 -0
  106. data/spec/{groovy_compilers_spec.rb → groovy/compiler_spec.rb} +1 -1
  107. data/spec/ide/eclipse_spec.rb +243 -0
  108. data/spec/{java_spec.rb → java/ant.rb} +7 -17
  109. data/spec/java/bdd_spec.rb +358 -0
  110. data/spec/{java_compilers_spec.rb → java/compiler_spec.rb} +1 -1
  111. data/spec/java/java_spec.rb +88 -0
  112. data/spec/{java_packaging_spec.rb → java/packaging_spec.rb} +65 -4
  113. data/spec/{java_test_frameworks_spec.rb → java/tests_spec.rb} +50 -10
  114. data/spec/{archive_spec.rb → packaging/archive_spec.rb} +12 -2
  115. data/spec/{artifact_spec.rb → packaging/artifact_spec.rb} +10 -3
  116. data/spec/{packaging_helper.rb → packaging/packaging_helper.rb} +0 -0
  117. data/spec/{packaging_spec.rb → packaging/packaging_spec.rb} +1 -1
  118. data/spec/sandbox.rb +25 -4
  119. data/spec/{scala_compilers_spec.rb → scala/compiler_spec.rb} +1 -1
  120. data/spec/scala/tests_spec.rb +215 -0
  121. data/spec/spec_helpers.rb +38 -17
  122. metadata +119 -69
  123. data/lib/buildr/java/bdd_frameworks.rb +0 -265
  124. data/lib/buildr/java/groovyc.rb +0 -137
  125. data/spec/build_spec.rb +0 -193
  126. data/spec/java_bdd_frameworks_spec.rb +0 -238
  127. data/spec/spec.opts +0 -6
@@ -27,7 +27,6 @@
27
27
  %body
28
28
  #wrap
29
29
  #header
30
- %img{ :src=>'images/apache-incubator-logo.png', :alt=>'Apache Incubator', :style=>'float:right;width:10em' }
31
30
  %img{ :src=>'images/buildr-hires.png', :alt=>collection.title, :style=>'width:20em' }
32
31
  .tagline= ''
33
32
  #content
@@ -21,6 +21,7 @@
21
21
  - Packaging: packaging.html
22
22
  - Testing: testing.html
23
23
  - Settings/Profiles: settings_profiles.html
24
+ - Languages: languages.html
24
25
  - More Stuff: more_stuff.html
25
26
  - Extending: extending.html
26
27
  - Recipes: recipes.html
@@ -28,7 +28,7 @@ require 'ostruct'
28
28
 
29
29
  # Pager from http://nex-3.com/posts/73-git-style-automatic-paging-in-ruby
30
30
  def run_pager
31
- return if PLATFORM =~ /win32/
31
+ return if RUBY_PLATFORM =~ /win32/
32
32
  return unless STDOUT.tty?
33
33
 
34
34
  read, write = IO.pipe
@@ -18,7 +18,7 @@ if [ -z `which jruby` ] ; then
18
18
  target=/opt/jruby
19
19
  echo "Installing JRuby ${version} in ${target}"
20
20
  sudo mkdir -p $(dirname ${target})
21
- curl -OL http://dist.codehaus.org/jruby/jruby-bin-${version}.tar.gz
21
+ wget http://dist.codehaus.org/jruby/jruby-bin-${version}.tar.gz
22
22
  tar -xz < jruby-bin-${version}.tar.gz
23
23
  sudo mv jruby-${version} ${target}
24
24
  rm jruby-bin-${version}.tar.gz
@@ -26,12 +26,12 @@ if [ -z `which ruby` ] ; then
26
26
  sudo apt-get install ruby-full ruby1.8-dev libopenssl-ruby build-essential
27
27
  # RubyGems broken on Ubunutu, installing directly from source.
28
28
  echo "Installing RubyGems from RubyForge"
29
- curl -OL http://rubyforge.org/frs/download.php/29548/rubygems-1.0.1.tgz
30
- tar xzf rubygems-1.0.1.tgz
31
- cd rubygems-1.0.1
29
+ wget http://rubyforge.org/frs/download.php/38646/rubygems-1.2.0.tgz
30
+ tar xzf rubygems-1.2.0.tgz
31
+ cd rubygems-1.2.0
32
32
  sudo ruby setup.rb
33
33
  cd ..
34
- rm -rf rubygems-1.0.1
34
+ rm -rf rubygems-1.2.0
35
35
  # ruby is same as ruby1.8, we need gem that is same as gem1.8
36
36
  sudo ln -s /usr/bin/gem1.8 /usr/bin/gem
37
37
  else
@@ -13,11 +13,12 @@
13
13
  # License for the specific language governing permissions and limitations under
14
14
  # the License.
15
15
 
16
- - Main:
16
+ - Start Here:
17
17
  - Welcome: index.html
18
18
  - Download and Installation: download.html
19
- - Printable PDF: buildr.pdf
20
- - New: whats_new.html
19
+ - User Guide (PDF): buildr.pdf
20
+ - What's New: whats_new.html
21
+ - Community Wiki: http://cwiki.apache.org/confluence/display/BUILDR/Index
21
22
  - Using Buildr:
22
23
  - Getting Started: getting_started.html
23
24
  - Projects: projects.html
@@ -26,6 +27,7 @@
26
27
  - Packaging: packaging.html
27
28
  - Testing: testing.html
28
29
  - Settings/Profiles: settings_profiles.html
30
+ - Languages: languages.html
29
31
  - More Stuff: more_stuff.html
30
32
  - Extending: extending.html
31
33
  - Recipes: recipes.html
@@ -34,11 +36,12 @@
34
36
  - Rake: http://docs.rubyrake.org
35
37
  - Antwrap: http://antwrap.rubyforge.org
36
38
  - Troubleshooting: troubleshooting.html
37
- - Getting Involved:
38
- - Contributing: contributing.html
39
+ - Get Involved:
39
40
  - Mailing Lists: mailing_lists.html
40
41
  - Issues/Bugs: http://issues.apache.org/jira/browse/Buildr
42
+ - Contributing: contributing.html
41
43
  - Project Status:
42
44
  - License: license.html
43
45
  - Change Log: changelog.html
44
46
  - Specs: specs.html
47
+ - Coverage: coverage/index.html
File without changes
@@ -0,0 +1,16 @@
1
+ # This file is used by git-svn
2
+ #
3
+ # Format is
4
+ # <apache svn login> = John Doe <john.doe@hacker.mail>
5
+ #
6
+ # If you are a committer and want to use git-svn to hack on
7
+ # buildr, please add yourself here and commit this file via svn.
8
+ # Then run the buildr-git.rb script to obtain and configure
9
+ # a local buildr-git copy.
10
+ #
11
+
12
+ assaf = Assaf Arkin <assaf@apache.org>
13
+ boisvert = Alex Boisvert <alex.boisvert@gmail.com>
14
+ lacton = Lacton <lacton@apache.org>
15
+ mriou = Matthieu Riou <mriou@apache.org>
16
+ vborja = Victor Hugo Borja <vic.borja@gmail.com>
@@ -13,18 +13,8 @@
13
13
  # License for the specific language governing permissions and limitations under
14
14
  # the License.
15
15
 
16
-
17
- $KCODE = 'utf8'
18
- # in order to work around a bug in jruby (1.0.1 and trunk as of oct11, 2007)
19
- # needle and net/ssh need to be loaded before -anything- else. please see
20
- # http://jira.codehaus.org/browse/JRUBY-1188 for more info.
21
- require 'net/ssh'
22
-
23
- require 'highline/import'
24
- require 'builder' # A different kind of buildr, one we use to create XML.
25
-
26
16
  module Buildr
27
- VERSION = '1.3.1'.freeze # unless const_defined?(:VERSION)
17
+ VERSION = '1.3.3'.freeze
28
18
  end
29
19
 
30
20
  require 'buildr/core'
@@ -42,5 +32,4 @@ class Object #:nodoc:
42
32
  end
43
33
 
44
34
  # Prevent RSpec runner from running at_exit.
45
- require 'spec'
46
- Spec.run = true
35
+ require 'spec'
@@ -35,7 +35,7 @@
35
35
  # SOFTWARE.
36
36
 
37
37
 
38
- require 'benchmark'
38
+ require 'highline/import'
39
39
  require 'rake'
40
40
  require 'rubygems/source_info_cache'
41
41
  require 'buildr/core/application_cli'
@@ -46,12 +46,13 @@ require 'buildr/core/util'
46
46
  ENV["HOME"] ||= File.expand_path(Gem::user_home)
47
47
  ENV['BUILDR_ENV'] ||= 'development'
48
48
 
49
+
49
50
  module Buildr
50
51
 
51
52
  # Provide settings that come from three sources.
52
53
  #
53
54
  # User settings are placed in the .buildr/settings.yaml file located in the user's home directory.
54
- # The should only be used for settings that are specific to the user and applied the same way
55
+ # They should only be used for settings that are specific to the user and applied the same way
55
56
  # across all builds. Example for user settings are preferred repositories, path to local repository,
56
57
  # user/name password for uploading to remote repository.
57
58
  #
@@ -92,11 +93,12 @@ module Buildr
92
93
  private
93
94
 
94
95
  def load_from(base_name, dir = nil)
95
- file_name = ['yaml', 'yml'].map { |ext| File.expand_path("#{base_name}.#{ext}", dir) }.find { |fn| File.exist?(fn) }
96
+ base_name = File.expand_path(base_name, dir) if dir
97
+ file_name = ['yaml', 'yml'].map { |ext| "#{base_name}.#{ext}" }.find { |fn| File.exist?(fn) }
96
98
  return {} unless file_name
97
99
  yaml = YAML.load(File.read(file_name)) || {}
98
100
  fail "Expecting #{file_name} to be a map (name: value)!" unless Hash === yaml
99
- @application.build_files << file_name
101
+ @application.buildfile.enhance [file_name]
100
102
  yaml
101
103
  end
102
104
 
@@ -120,10 +122,11 @@ module Buildr
120
122
  @top_level_tasks = []
121
123
  parse_options
122
124
  collect_tasks
123
- top_level_tasks.unshift 'buildr:initialize'
124
125
  @home_dir = File.expand_path('.buildr', ENV['HOME'])
125
- mkpath @home_dir unless File.exist?(@home_dir)
126
+ mkpath @home_dir, :verbose=>false unless File.exist?(@home_dir)
126
127
  @environment = ENV['BUILDR_ENV'] ||= 'development'
128
+ @on_completion = []
129
+ @on_failure = []
127
130
  end
128
131
 
129
132
  # Returns list of Gems associated with this buildfile, as listed in build.yaml.
@@ -138,23 +141,80 @@ module Buildr
138
141
 
139
142
  # Returns the Settings associated with this build.
140
143
  def settings
144
+ fail "Internal error: Called Buildr.settings before buildfile located" unless rakefile
141
145
  @settings ||= Settings.new(self)
142
146
  end
143
147
 
144
148
  # :call-seq:
145
149
  # buildfile
150
+ # Returns the buildfile as a task that you can use as a dependency.
146
151
  def buildfile
147
- rakefile
152
+ @buildfile_task ||= BuildfileTask.define_task(File.expand_path(rakefile))
153
+ end
154
+
155
+ # Files that complement the buildfile itself
156
+ def build_files #:nodoc:
157
+ buildfile.prerequisites
158
+ end
159
+
160
+ def run
161
+ standard_exception_handling do
162
+ find_buildfile
163
+ load_gems
164
+ load_artifacts
165
+ load_tasks
166
+ load_requires
167
+ load_buildfile
168
+ load_imports
169
+ task('buildr:initialize').invoke
170
+ top_level
171
+ end
172
+ title, message = 'Your build has completed', "#{Dir.pwd}\nbuildr #{@top_level_tasks.join(' ')}"
173
+ @on_completion.each { |block| block.call(title, message) rescue nil }
174
+ end
175
+
176
+ # Yields to block on successful completion. Primarily used for notifications.
177
+ def on_completion(&block)
178
+ @on_completion << block
179
+ end
180
+
181
+ # Yields to block on failure with exception. Primarily used for notifications.
182
+ def on_failure(&block)
183
+ @on_failure << block
184
+ end
185
+
186
+ # Not for external consumption.
187
+ def switch_to_namespace(names) #:nodoc:
188
+ current, @scope = @scope, names
189
+ begin
190
+ yield
191
+ ensure
192
+ @scope = current
193
+ end
148
194
  end
149
195
 
150
196
  # :call-seq:
151
- # build_files => files
197
+ # deprecated(message)
152
198
  #
153
- # Returns a list of build files. These are files used by the build,
154
- def build_files
155
- [buildfile].compact + Array(@build_files)
199
+ # Use with deprecated methods and classes. This method automatically adds the file name and line number,
200
+ # and the text 'Deprecated' before the message, and eliminated duplicate warnings. It only warns when
201
+ # running in verbose mode.
202
+ #
203
+ # For example:
204
+ # deprecated 'Please use new_foo instead of foo.'
205
+ def deprecated(message) #:nodoc:
206
+ return unless verbose
207
+ "#{caller[1]}: Deprecated: #{message}".tap do |message|
208
+ @deprecated ||= {}
209
+ unless @deprecated[message]
210
+ @deprecated[message] = true
211
+ warn message
212
+ end
213
+ end
156
214
  end
157
215
 
216
+ private
217
+
158
218
  # Returns Gem::Specification for every listed and installed Gem, Gem::Dependency
159
219
  # for listed and uninstalled Gem, which is the installed before loading the buildfile.
160
220
  def listed_gems #:nodoc:
@@ -166,27 +226,6 @@ module Buildr
166
226
  Gem::SourceIndex.from_installed_gems.search(dep).last || dep
167
227
  end
168
228
  end
169
- private :listed_gems
170
-
171
- def run
172
- times = Benchmark.measure do
173
- standard_exception_handling do
174
- find_buildfile
175
- load_gems
176
- load_artifacts
177
- load_tasks
178
- load_buildfile
179
- top_level
180
- end
181
- end
182
- if verbose
183
- real = []
184
- real << ("%ih" % (times.real / 3600)) if times.real >= 3600
185
- real << ("%im" % ((times.real / 60) % 60)) if times.real >= 60
186
- real << ("%.3fs" % (times.real % 60))
187
- puts "Completed in #{real.join}"
188
- end
189
- end
190
229
 
191
230
  # Load artifact specs from the build.yaml file, making them available
192
231
  # by name ( ruby symbols ).
@@ -202,36 +241,27 @@ module Buildr
202
241
  def load_gems #:nodoc:
203
242
  missing_deps, installed = listed_gems.partition { |gem| gem.is_a?(Gem::Dependency) }
204
243
  unless missing_deps.empty?
205
- remote = missing_deps.map { |dep| Gem::SourceInfoCache.search(dep).last || dep }
206
- not_found_deps, install = remote.partition { |gem| gem.is_a?(Gem::Dependency) }
207
- fail Gem::LoadError, "Build requires the gems #{not_found_deps.join(', ')}, which cannot be found in local or remote repository." unless not_found_deps.empty?
208
- uses = "This build requires the gems #{install.map(&:full_name).join(', ')}:"
209
- fail Gem::LoadError, "#{uses} to install, run Buildr interactively." unless $stdout.isatty
210
- unless agree("#{uses} do you want me to install them? [Y/n]", true)
211
- fail Gem::LoadError, 'Cannot build without these gems.'
212
- end
213
- install.each do |spec|
214
- say "Installing #{spec.full_name} ... " if verbose
215
- Util.ruby 'install', spec.name, '-v', spec.version.to_s, :command => 'gem', :sudo => true, :verbose => false
216
- Gem.source_index.load_gems_in Gem::SourceIndex.installed_spec_directories
217
- end
218
- installed += install
244
+ newly_installed = Util::Gems.install(*missing_deps)
245
+ installed += newly_installed
219
246
  end
220
-
221
247
  installed.each do |spec|
222
248
  if gem(spec.name, spec.version.to_s)
223
- # FileList[spec.require_paths.map { |path| File.expand_path("#{path}/*.rb", spec.full_gem_path) }].
224
- # map { |path| File.basename(path) }.each { |file| require file }
225
- # FileList[File.expand_path('tasks/*.rake', spec.full_gem_path)].each do |file|
226
- # Buildr.application.add_import file
227
- # end
249
+ # TODO: is this intended to load rake tasks from the installed gems?
250
+ # We should use a convention like .. if the gem has a _buildr.rb file, load it.
251
+
252
+ #FileList[spec.require_paths.map { |path| File.expand_path("#{path}/*.rb", spec.full_gem_path) }].
253
+ # map { |path| File.basename(path) }.each { |file| require file }
254
+ #FileList[File.expand_path('tasks/*.rake', spec.full_gem_path)].each do |file|
255
+ # Buildr.application.add_import file
256
+ #end
228
257
  end
229
258
  end
230
259
  @gems = installed
231
260
  end
232
261
 
233
- def find_buildfile
234
- here = Dir.pwd
262
+ def find_buildfile #:nodoc:
263
+ here = original_dir
264
+ Dir.chdir(here) unless Dir.pwd == here
235
265
  while ! have_rakefile
236
266
  Dir.chdir('..')
237
267
  if Dir.pwd == here || options.nosearch
@@ -247,61 +277,81 @@ module Buildr
247
277
  end
248
278
  end
249
279
 
250
- def load_buildfile
251
- @requires.each { |name| require name }
252
- puts "(in #{Dir.pwd}, #{environment})"
280
+ def load_buildfile #:nodoc:
281
+ info "(in #{Dir.pwd}, #{environment})"
253
282
  load File.expand_path(@rakefile) if @rakefile != ''
254
- load_imports
283
+ buildfile.enhance @requires.select { |f| File.file?(f) }.map{ |f| File.expand_path(f) }
255
284
  end
256
285
 
257
- # Loads buildr.rake files from users home directory and project directory.
286
+ def load_requires #:nodoc:
287
+ @requires.each { |name| require name }
288
+ end
289
+
290
+ # Loads buildr.rb files from users home directory and project directory.
258
291
  # Loads custom tasks from .rake files in tasks directory.
259
292
  def load_tasks #:nodoc:
260
- @build_files = [ File.expand_path('buildr.rb', ENV['HOME']), 'buildr.rb' ].select { |file| File.exist?(file) }
261
- @build_files += [ File.expand_path('buildr.rake', ENV['HOME']), File.expand_path('buildr.rake') ].
293
+ files = [ File.expand_path('buildr.rb', ENV['HOME']), 'buildr.rb' ].select { |file| File.exist?(file) }
294
+ files += [ File.expand_path('buildr.rake', ENV['HOME']), File.expand_path('buildr.rake') ].
262
295
  select { |file| File.exist?(file) }.each { |file| warn "Please use '#{file.ext('rb')}' instead of '#{file}'" }
263
296
  #Load local tasks that can be used in the Buildfile.
264
- @build_files += Dir["#{Dir.pwd}/tasks/*.rake"]
265
- @build_files.each do |file|
297
+ files += Dir[File.expand_path('tasks/*.rake', original_dir)]
298
+ files.each do |file|
266
299
  unless $LOADED_FEATURES.include?(file)
267
300
  load file
268
301
  $LOADED_FEATURES << file
269
302
  end
270
303
  end
304
+ buildfile.enhance files
271
305
  true
272
306
  end
273
- private :load_tasks
274
307
 
275
- # :call-seq:
276
- # deprecated(message)
277
- #
278
- # Use with deprecated methods and classes. This method automatically adds the file name and line number,
279
- # and the text 'Deprecated' before the message, and eliminated duplicate warnings. It only warns when
280
- # running in verbose mode.
281
- #
282
- # For example:
283
- # deprecated 'Please use new_foo instead of foo.'
284
- def deprecated(message) #:nodoc:
285
- return unless verbose
286
- "#{caller[1]}: Deprecated: #{message}".tap do |message|
287
- @deprecated ||= {}
288
- unless @deprecated[message]
289
- @deprecated[message] = true
290
- warn message
308
+ def display_prerequisites
309
+ invoke_task('buildr:initialize')
310
+ tasks.each do |task|
311
+ if task.name =~ options.show_task_pattern
312
+ puts "buildr #{task.name}"
313
+ task.prerequisites.each { |prereq| puts " #{prereq}" }
291
314
  end
292
315
  end
293
316
  end
294
-
295
- # Not for external consumption.
296
- def switch_to_namespace(names) #:nodoc:
297
- current, @scope = @scope, names
317
+
318
+ # Provide standard execption handling for the given block.
319
+ def standard_exception_handling
298
320
  begin
299
321
  yield
300
- ensure
301
- @scope = current
322
+ rescue SystemExit => ex
323
+ # Exit silently with current status
324
+ exit(ex.status)
325
+ rescue SystemExit, GetoptLong::InvalidOption => ex
326
+ # Exit silently
327
+ exit(1)
328
+ rescue Exception => ex
329
+ title, message = 'Your build failed with an error', "#{Dir.pwd}:\n#{ex.message}"
330
+ @on_failure.each { |block| block.call(title, message, ex) rescue nil }
331
+ # Exit with error message
332
+ $stderr.puts "buildr aborted!"
333
+ $stderr.puts $terminal.color(ex.message, :red)
334
+ if options.trace
335
+ $stderr.puts ex.backtrace.join("\n")
336
+ else
337
+ $stderr.puts ex.backtrace.select { |str| str =~ /#{buildfile}/ }.map { |line| $terminal.color(line, :red) }.join("\n")
338
+ $stderr.puts "(See full trace by running task with --trace)"
339
+ end
340
+ exit(1)
302
341
  end
303
342
  end
304
-
343
+
344
+ end
345
+
346
+
347
+ # This task stands for the buildfile and all its associated helper files (e.g., buildr.rb, build.yaml).
348
+ # By using this task as a prerequisite for other tasks, you can ensure these tasks will be needed
349
+ # whenever the buildfile changes.
350
+ class BuildfileTask < Rake::FileTask
351
+
352
+ def timestamp
353
+ ([name] + prerequisites).map { |f| File.stat(f).mtime }.max rescue Time.now
354
+ end
305
355
  end
306
356
 
307
357
 
@@ -337,22 +387,72 @@ module Buildr
337
387
  end
338
388
 
339
389
 
340
- # Add a touch of colors (red) to warnings.
390
+ # Add a touch of color when available and running in terminal.
341
391
  if $stdout.isatty
342
392
  begin
343
393
  require 'Win32/Console/ANSI' if Config::CONFIG['host_os'] =~ /mswin/
344
394
  HighLine.use_color = true
345
395
  rescue LoadError
346
396
  end
397
+ else
398
+ HighLine.use_color = false
347
399
  end
348
400
 
349
- if HighLine.use_color?
350
- module Kernel #:nodoc:
351
- alias :warn_without_color :warn
352
- def warn(message)
353
- warn_without_color $terminal.color(message.to_s, :red)
401
+
402
+ # Let's see if we can use Growl. We do this at the very end, loading Ruby Cocoa
403
+ # could slow the build down, so later is better. We only do this when running
404
+ # from the console in verbose mode.
405
+ if $stdout.isatty && verbose && RUBY_PLATFORM =~ /darwin/
406
+ begin
407
+ require 'osx/cocoa'
408
+ icon = OSX::NSApplication.sharedApplication.applicationIconImage
409
+ icon = OSX::NSImage.alloc.initWithContentsOfFile(File.join(File.dirname(__FILE__), '../resources/buildr.icns'))
410
+
411
+ # Register with Growl, that way you can turn notifications on/off from system preferences.
412
+ OSX::NSDistributedNotificationCenter.defaultCenter.
413
+ postNotificationName_object_userInfo_deliverImmediately(:GrowlApplicationRegistrationNotification, nil,
414
+ { :ApplicationName=>'Buildr', :AllNotifications=>['Completed', 'Failed'],
415
+ :ApplicationIcon=>icon.TIFFRepresentation }, true)
416
+
417
+ notify = lambda do |type, title, message|
418
+ OSX::NSDistributedNotificationCenter.defaultCenter.
419
+ postNotificationName_object_userInfo_deliverImmediately(:GrowlNotification, nil,
420
+ { :ApplicationName=>'Buildr', :NotificationName=>type,
421
+ :NotificationTitle=>title, :NotificationDescription=>message }, true)
354
422
  end
423
+ Buildr.application.on_completion { |title, message| notify['Completed', title, message] }
424
+ Buildr.application.on_failure { |title, message, ex| notify['Failed', title, message] }
425
+ rescue Exception # No growl
355
426
  end
427
+ elsif $stdout.isatty && verbose
428
+ notify = lambda { |type, title, message| $stdout.puts "[#{type}] #{title}: #{message}" }
429
+ Buildr.application.on_completion { |title, message| notify['Completed', title, message] }
430
+ Buildr.application.on_failure { |title, message, ex| notify['Failed', title, message] }
431
+ end
432
+
433
+
434
+ alias :warn_without_color :warn
435
+
436
+ # Show warning message.
437
+ def warn(message)
438
+ warn_without_color $terminal.color(message.to_s, :blue) if verbose
439
+ end
440
+
441
+ # Show error message. Use this when you need to show an error message and not throwing
442
+ # an exception that will stop the build.
443
+ def error(message)
444
+ puts $terminal.color(message.to_s, :red)
445
+ end
446
+
447
+ # Show optional information. The message is printed only when running in verbose
448
+ # mode (the default).
449
+ def info(message)
450
+ puts message if verbose
451
+ end
452
+
453
+ # Show message. The message is printed out only when running in trace mode.
454
+ def trace(message)
455
+ puts message if Buildr.application.options.trace
356
456
  end
357
457
 
358
458
 
@@ -371,7 +471,12 @@ module Rake #:nodoc
371
471
  end
372
472
  return if @already_invoked
373
473
  @already_invoked = true
374
- invoke_prerequisites(task_args, new_chain)
474
+ begin
475
+ invoke_prerequisites(task_args, new_chain)
476
+ rescue
477
+ trace "Exception while invoking prerequisites of task #{self.inspect}"
478
+ raise
479
+ end
375
480
  begin
376
481
  old_chain, Thread.current[:rake_chain] = Thread.current[:rake_chain], new_chain
377
482
  execute(task_args) if needed?
@@ -381,4 +486,4 @@ module Rake #:nodoc
381
486
  end
382
487
  end
383
488
  end
384
- end
489
+ end