buildr 1.3.5-java → 1.4.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. data/CHANGELOG +153 -8
  2. data/README.rdoc +1 -1
  3. data/addon/buildr/antlr.rb +5 -5
  4. data/addon/buildr/drb.rb +18 -18
  5. data/addon/buildr/hibernate.rb +18 -14
  6. data/addon/buildr/javacc.rb +4 -4
  7. data/addon/buildr/jetty.rb +5 -5
  8. data/addon/buildr/nailgun.rb +23 -23
  9. data/addon/buildr/openjpa.rb +1 -1
  10. data/addon/buildr/org/apache/buildr/BuildrNail$Main.class +0 -0
  11. data/addon/buildr/org/apache/buildr/BuildrNail.class +0 -0
  12. data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
  13. data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
  14. data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
  15. data/addon/buildr/protobuf.rb +75 -0
  16. data/addon/buildr/xmlbeans.rb +5 -5
  17. data/buildr.buildfile +2 -2
  18. data/buildr.gemspec +8 -7
  19. data/doc/_layouts/default.html +2 -2
  20. data/doc/artifacts.textile +4 -4
  21. data/doc/building.textile +35 -3
  22. data/doc/contributing.textile +5 -0
  23. data/doc/download.textile +16 -5
  24. data/doc/extending.textile +38 -12
  25. data/doc/installing.textile +6 -5
  26. data/doc/languages.textile +182 -42
  27. data/doc/more_stuff.textile +2 -2
  28. data/doc/packaging.textile +14 -15
  29. data/doc/projects.textile +7 -2
  30. data/doc/quick_start.textile +4 -4
  31. data/doc/scripts/buildr-git.rb +63 -63
  32. data/doc/scripts/gitflow.rb +21 -21
  33. data/doc/settings_profiles.textile +9 -2
  34. data/doc/testing.textile +16 -5
  35. data/etc/KEYS +38 -0
  36. data/lib/buildr.rb +1 -1
  37. data/lib/buildr/core.rb +1 -0
  38. data/lib/buildr/core/application.rb +33 -27
  39. data/lib/buildr/core/build.rb +41 -28
  40. data/lib/buildr/core/cc.rb +172 -0
  41. data/lib/buildr/core/checks.rb +1 -1
  42. data/lib/buildr/core/common.rb +7 -6
  43. data/lib/buildr/core/compile.rb +7 -8
  44. data/lib/buildr/core/doc.rb +263 -0
  45. data/lib/buildr/core/environment.rb +6 -6
  46. data/lib/buildr/core/filter.rb +77 -35
  47. data/lib/buildr/core/generate.rb +7 -7
  48. data/lib/buildr/core/help.rb +1 -1
  49. data/lib/buildr/core/osx.rb +6 -6
  50. data/lib/buildr/core/progressbar.rb +4 -4
  51. data/lib/buildr/core/project.rb +144 -36
  52. data/lib/buildr/core/shell.rb +34 -34
  53. data/lib/buildr/core/test.rb +89 -20
  54. data/lib/buildr/core/transports.rb +8 -7
  55. data/lib/buildr/core/util.rb +77 -23
  56. data/lib/buildr/groovy/bdd.rb +5 -5
  57. data/lib/buildr/groovy/compiler.rb +19 -15
  58. data/lib/buildr/groovy/shell.rb +6 -6
  59. data/lib/buildr/ide/eclipse.rb +148 -75
  60. data/lib/buildr/ide/eclipse/java.rb +3 -3
  61. data/lib/buildr/ide/eclipse/plugin.rb +8 -5
  62. data/lib/buildr/ide/eclipse/scala.rb +4 -2
  63. data/lib/buildr/ide/idea.rb +2 -2
  64. data/lib/buildr/ide/idea7x.rb +23 -4
  65. data/lib/buildr/java.rb +1 -0
  66. data/lib/buildr/java/ant.rb +4 -4
  67. data/lib/buildr/java/bdd.rb +51 -54
  68. data/lib/buildr/java/cobertura.rb +57 -35
  69. data/lib/buildr/java/commands.rb +14 -5
  70. data/lib/buildr/java/compiler.rb +3 -217
  71. data/lib/buildr/java/deprecated.rb +4 -4
  72. data/lib/buildr/java/doc.rb +70 -0
  73. data/lib/buildr/java/emma.rb +22 -22
  74. data/lib/buildr/java/jruby.rb +4 -4
  75. data/lib/buildr/java/jtestr_runner.rb.erb +27 -25
  76. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  77. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +8 -3
  78. data/lib/buildr/java/packaging.rb +30 -29
  79. data/lib/buildr/java/pom.rb +4 -4
  80. data/lib/buildr/java/rjb.rb +6 -6
  81. data/lib/buildr/java/test_result.rb +61 -85
  82. data/lib/buildr/java/tests.rb +44 -27
  83. data/lib/buildr/java/version_requirement.rb +8 -8
  84. data/lib/buildr/packaging/archive.rb +55 -22
  85. data/lib/buildr/packaging/artifact.rb +75 -36
  86. data/lib/buildr/packaging/artifact_namespace.rb +90 -78
  87. data/lib/buildr/packaging/artifact_search.rb +5 -5
  88. data/lib/buildr/packaging/gems.rb +11 -7
  89. data/lib/buildr/packaging/package.rb +10 -7
  90. data/lib/buildr/packaging/tar.rb +14 -14
  91. data/lib/buildr/packaging/version_requirement.rb +30 -10
  92. data/lib/buildr/packaging/ziptask.rb +51 -13
  93. data/lib/buildr/scala.rb +1 -0
  94. data/lib/buildr/scala/bdd.rb +25 -20
  95. data/lib/buildr/scala/compiler.rb +87 -40
  96. data/lib/buildr/scala/doc.rb +106 -0
  97. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.class +0 -0
  98. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.java +57 -0
  99. data/lib/buildr/scala/shell.rb +14 -9
  100. data/lib/buildr/scala/tests.rb +33 -26
  101. data/lib/buildr/shell.rb +33 -33
  102. data/rakelib/all-in-one.rake +113 -0
  103. data/rakelib/checks.rake +1 -1
  104. data/rakelib/doc.rake +7 -0
  105. data/rakelib/package.rake +1 -1
  106. data/rakelib/release.rake +9 -6
  107. data/rakelib/rspec.rake +26 -7
  108. data/rakelib/setup.rake +15 -3
  109. data/rakelib/stage.rake +18 -11
  110. data/spec/addon/drb_spec.rb +25 -25
  111. data/spec/core/application_spec.rb +111 -21
  112. data/spec/core/build_spec.rb +16 -15
  113. data/spec/core/cc_spec.rb +174 -0
  114. data/spec/core/checks_spec.rb +34 -34
  115. data/spec/core/common_spec.rb +51 -5
  116. data/spec/core/compile_spec.rb +89 -14
  117. data/spec/core/extension_spec.rb +127 -19
  118. data/spec/core/generate_spec.rb +2 -2
  119. data/spec/core/project_spec.rb +10 -10
  120. data/spec/core/test_spec.rb +144 -35
  121. data/spec/core/transport_spec.rb +8 -8
  122. data/spec/core/util_spec.rb +63 -5
  123. data/spec/groovy/bdd_spec.rb +5 -5
  124. data/spec/groovy/compiler_spec.rb +29 -18
  125. data/spec/ide/eclipse_spec.rb +185 -9
  126. data/spec/ide/idea7x_spec.rb +22 -10
  127. data/spec/java/ant_spec.rb +9 -5
  128. data/spec/java/bdd_spec.rb +29 -37
  129. data/spec/java/cobertura_spec.rb +12 -12
  130. data/spec/java/commands_spec.rb +34 -0
  131. data/spec/java/compiler_spec.rb +53 -53
  132. data/spec/java/emma_spec.rb +11 -11
  133. data/spec/java/java_spec.rb +10 -10
  134. data/spec/java/packaging_spec.rb +67 -20
  135. data/spec/java/test_coverage_helper.rb +18 -18
  136. data/spec/java/tests_spec.rb +13 -9
  137. data/spec/packaging/archive_spec.rb +187 -20
  138. data/spec/packaging/artifact_namespace_spec.rb +172 -83
  139. data/spec/packaging/artifact_spec.rb +83 -18
  140. data/spec/packaging/packaging_spec.rb +41 -14
  141. data/spec/sandbox.rb +23 -12
  142. data/spec/scala/bdd_spec.rb +13 -8
  143. data/spec/scala/compiler_spec.rb +18 -13
  144. data/spec/scala/scala.rb +3 -3
  145. data/spec/scala/tests_spec.rb +46 -24
  146. data/spec/spec_helpers.rb +28 -10
  147. data/spec/version_requirement_spec.rb +25 -11
  148. metadata +148 -132
  149. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner$.class +0 -0
  150. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.scala +0 -35
  151. data/rakelib/stage.rake~ +0 -213
@@ -49,7 +49,7 @@ module Buildr
49
49
  end
50
50
 
51
51
  # Adds a test framework to the list of supported frameworks.
52
- #
52
+ #
53
53
  # For example:
54
54
  # Buildr::TestFramework << Buildr::JUnit
55
55
  def add(framework)
@@ -126,7 +126,7 @@ module Buildr
126
126
  end
127
127
 
128
128
  end
129
-
129
+
130
130
  end
131
131
 
132
132
 
@@ -176,6 +176,13 @@ module Buildr
176
176
  # all sub-projects, but only invoke test on the local project.
177
177
  Project.projects.each { |project| project.test.send :only_run, tests }
178
178
  end
179
+
180
+ # Used by the test/integration rule to only run tests that failed the last time.
181
+ def only_run_failed() #:nodoc:
182
+ # Since the tests may reside in a sub-project, we need to set the include/exclude pattern on
183
+ # all sub-projects, but only invoke test on the local project.
184
+ Project.projects.each { |project| project.test.send :only_run_failed }
185
+ end
179
186
  end
180
187
 
181
188
  # Default options already set on each test task.
@@ -195,7 +202,12 @@ module Buildr
195
202
  else
196
203
  @options = OpenObject.new(default_options)
197
204
  end
198
- enhance [application.buildfile.name] do
205
+
206
+ unless ENV["IGNORE_BUILDFILE"] =~ /(true)|(yes)/i
207
+ enhance [ application.buildfile.name ]
208
+ enhance application.buildfile.prerequisites
209
+ end
210
+ enhance do
199
211
  run_tests if framework
200
212
  end
201
213
  end
@@ -203,18 +215,18 @@ module Buildr
203
215
  # The dependencies used for running the tests. Includes the compiled files (compile.target)
204
216
  # and their dependencies. Will also include anything you pass to #with, shared between the
205
217
  # testing compile and run dependencies.
206
- attr_reader :dependencies
218
+ attr_accessor :dependencies
207
219
 
208
220
  # *Deprecated*: Use dependencies instead.
209
221
  def classpath
210
222
  Buildr.application.deprecated 'Use dependencies instead.'
211
- dependencies
223
+ @dependencies
212
224
  end
213
225
 
214
226
  # *Deprecated*: Use dependencies= instead.
215
227
  def classpath=(artifacts)
216
228
  Buildr.application.deprecated 'Use dependencies= instead.'
217
- self.dependencies = artifacts
229
+ @dependencies = artifacts
218
230
  end
219
231
 
220
232
  def execute(args) #:nodoc:
@@ -226,7 +238,7 @@ module Buildr
226
238
  begin
227
239
  super
228
240
  rescue RuntimeError
229
- raise if options[:fail_on_failure]
241
+ raise if options[:fail_on_failure] && Buildr.options.test != :all
230
242
  ensure
231
243
  teardown.invoke
232
244
  end
@@ -247,7 +259,7 @@ module Buildr
247
259
  def compile(*sources, &block)
248
260
  @project.task('test:compile').from(sources).enhance &block
249
261
  end
250
-
262
+
251
263
  # :call-seq:
252
264
  # resources(*prereqs) => ResourcesTask
253
265
  # resources(*prereqs) { |task| .. } => ResourcesTask
@@ -323,7 +335,7 @@ module Buildr
323
335
  Buildr.application.deprecated "Please replace with using(:#{name}=>true)"
324
336
  options[name.to_sym] = true
325
337
  end
326
- end
338
+ end
327
339
  self
328
340
  end
329
341
 
@@ -395,16 +407,35 @@ module Buildr
395
407
  @report_to ||= file(@project.path_to(:reports, framework)=>self)
396
408
  end
397
409
 
410
+ # :call-seq:
411
+ # failures_to => file
412
+ #
413
+ # We record the list of failed tests for the current framework in this file.
414
+ #
415
+ #
416
+ def failures_to
417
+ @failures_to ||= file(@project.path_to(:target, "#{framework}-failed")=>self)
418
+ end
419
+
420
+ # :call-seq:
421
+ # last_failures => array
422
+ #
423
+ # We read the last test failures if any and return them.
424
+ #
425
+ def last_failures
426
+ @last_failures ||= failures_to.exist? ? File.read(failures_to.to_s).split('\n') : []
427
+ end
428
+
398
429
  # The path to the file that stores the time stamp of the last successful test run.
399
430
  def last_successful_run_file #:nodoc:
400
431
  File.join(report_to.to_s, 'last_successful_run')
401
432
  end
402
-
433
+
403
434
  # The time stamp of the last successful test run. Or Rake::EARLY if no successful test run recorded.
404
435
  def timestamp #:nodoc:
405
436
  File.exist?(last_successful_run_file) ? File.mtime(last_successful_run_file) : Rake::EARLY
406
437
  end
407
-
438
+
408
439
  # The project this task belongs to.
409
440
  attr_reader :project
410
441
 
@@ -435,8 +466,9 @@ module Buildr
435
466
 
436
467
  # Runs the tests using the selected test framework.
437
468
  def run_tests
438
- dependencies = Buildr.artifacts(self.dependencies).map(&:to_s).uniq
469
+ dependencies = (Buildr.artifacts(self.dependencies + compile.dependencies) + [compile.target]).map(&:to_s).uniq
439
470
  rm_rf report_to.to_s
471
+ rm_rf failures_to.to_s
440
472
  @tests = @framework.tests(dependencies).select { |test| include?(test) }.sort
441
473
  if @tests.empty?
442
474
  @passed_tests, @failed_tests = [], []
@@ -444,7 +476,7 @@ module Buildr
444
476
  info "Running tests in #{@project.name}"
445
477
  begin
446
478
  # set the baseDir system property if not set
447
- @framework.options[:properties] = { 'baseDir' => @project.test.compile.target.to_s }.merge(@framework.options[:properties] || {})
479
+ @framework.options[:properties] = { 'baseDir' => compile.target.to_s }.merge(@framework.options[:properties] || {})
448
480
  @passed_tests = @framework.run(@tests, dependencies)
449
481
  rescue Exception=>ex
450
482
  error "Test framework error: #{ex.message}"
@@ -453,6 +485,7 @@ module Buildr
453
485
  end
454
486
  @failed_tests = @tests - @passed_tests
455
487
  unless @failed_tests.empty?
488
+ Buildr::write(failures_to.to_s, @failed_tests.join("\n"))
456
489
  error "The following tests failed:\n#{@failed_tests.join("\n")}"
457
490
  fail 'Tests failed!'
458
491
  end
@@ -465,7 +498,7 @@ module Buildr
465
498
  mkdir_p report_to.to_s
466
499
  touch last_successful_run_file
467
500
  end
468
-
501
+
469
502
  # Limit running tests to specific list.
470
503
  def only_run(tests)
471
504
  @include = Array(tests)
@@ -473,6 +506,13 @@ module Buildr
473
506
  @forced_need = true
474
507
  end
475
508
 
509
+ # Limit running tests to those who failed the last time.
510
+ def only_run_failed()
511
+ @include = Array(last_failures)
512
+ @exclude.clear
513
+ @forced_need = true
514
+ end
515
+
476
516
  def invoke_prerequisites(args, chain) #:nodoc:
477
517
  @prerequisites |= FileList[@dependencies.uniq]
478
518
  super
@@ -543,6 +583,12 @@ module Buildr
543
583
  desc 'Run all tests'
544
584
  task('test') { TestTask.run_local_tests false }
545
585
 
586
+ desc 'Run failed tests'
587
+ task('test:failed') {
588
+ TestTask.only_run_failed
589
+ task('test').invoke
590
+ }
591
+
546
592
  # This rule takes a suffix and runs that tests in the current project. For example;
547
593
  # buildr test:MyTest
548
594
  # will run the test com.example.MyTest, if such a test exists for this project.
@@ -567,8 +613,8 @@ module Buildr
567
613
  end
568
614
 
569
615
  end
570
-
571
- before_define do |project|
616
+
617
+ before_define(:test) do |project|
572
618
  # Define a recursive test task, and pass it a reference to the project so it can discover all other tasks.
573
619
  test = TestTask.define_task('test')
574
620
  test.send :associate_with, project
@@ -578,8 +624,26 @@ module Buildr
578
624
  resources.send :associate_with, project, :test
579
625
  project.path_to(:source, :test, :resources).tap { |dir| resources.from dir if File.exist?(dir) }
580
626
 
627
+ # We define a module inline that will inject cancelling the task if tests are skipped.
628
+ module SkipIfNoTest
629
+
630
+ def self.extended(base)
631
+ base.instance_eval {alias :execute_before_skip_if_no_test :execute}
632
+ base.instance_eval {alias :execute :execute_after_skip_if_no_test}
633
+ end
634
+
635
+ def execute_after_skip_if_no_test(args) #:nodoc:
636
+ if Buildr.options.test == false
637
+ trace "Skipping #{to_s} for #{project.name} as tests are skipped"
638
+ return
639
+ end
640
+ execute_before_skip_if_no_test(args)
641
+ end
642
+ end
643
+
581
644
  # Similar to the regular compile task but using different paths.
582
645
  compile = CompileTask.define_task('test:compile'=>[project.compile, resources])
646
+ compile.extend SkipIfNoTest
583
647
  compile.send :associate_with, project, :test
584
648
  test.enhance [compile]
585
649
 
@@ -587,17 +651,20 @@ module Buildr
587
651
  test.setup ; test.teardown
588
652
  end
589
653
 
590
- after_define do |project|
654
+
655
+
656
+ after_define(:test => :compile) do |project|
591
657
  test = project.test
592
658
  # Dependency on compiled tests and resources. Dependencies added using with.
593
659
  test.dependencies.concat [test.compile.target, test.resources.target].compact
660
+ test.dependencies.concat test.compile.dependencies
594
661
  # Dependency on compiled code, its dependencies and resources.
595
662
  test.with [project.compile.target, project.resources.target].compact
596
663
  test.with project.compile.dependencies
597
664
  # Picking up the test frameworks adds further dependencies.
598
665
  test.framework
599
-
600
- project.build test unless test.options[:integration]
666
+
667
+ project.build test unless test.options[:integration] || Buildr.options.test == :only
601
668
 
602
669
  project.clean do
603
670
  rm_rf test.compile.target.to_s if test.compile.target
@@ -629,7 +696,7 @@ module Buildr
629
696
  def test(*prereqs, &block)
630
697
  task('test').enhance prereqs, &block
631
698
  end
632
-
699
+
633
700
  # :call-seq:
634
701
  # integration { |task| .... }
635
702
  # integration => IntegrationTestTask
@@ -682,6 +749,8 @@ module Buildr
682
749
  false
683
750
  when /^all$/i
684
751
  :all
752
+ when /^only$/i
753
+ :only
685
754
  when /^(yes|on|true)$/i, nil
686
755
  true
687
756
  else
@@ -76,7 +76,7 @@ module URI
76
76
  uri = URI.parse(uri.to_s) unless URI === uri
77
77
  uri.download target, options
78
78
  end
79
-
79
+
80
80
  # :call-seq:
81
81
  # write(uri, content, options?)
82
82
  # write(uri, options?) { |bytes| .. }
@@ -98,7 +98,7 @@ module URI
98
98
  uri = URI.parse(uri.to_s) unless URI === uri
99
99
  uri.write *args, &block
100
100
  end
101
-
101
+
102
102
  # :call-seq:
103
103
  # upload(uri, source, options?)
104
104
  #
@@ -162,7 +162,7 @@ module URI
162
162
  target.flush
163
163
  end
164
164
  end
165
-
165
+
166
166
  # :call-seq:
167
167
  # write(content, options?)
168
168
  # write(options?) { |bytes| .. }
@@ -527,11 +527,12 @@ module URI
527
527
  "file://#{host}#{path}"
528
528
  end
529
529
 
530
- # The URL path always starts with a backslash. On most operating systems (Linux, Darwin, BSD) it points
531
- # to the absolute path on the file system. But on Windows, it comes before the drive letter, creating an
532
- # unusable path, so real_path fixes that. Ugly but necessary hack.
530
+ # Returns the file system path based that corresponds to the URL path.
531
+ # On windows this method strips the leading slash off of the path.
532
+ # On all platforms this method unescapes the URL path.
533
533
  def real_path #:nodoc:
534
- RUBY_PLATFORM =~ /win32/ && path =~ /^\/[a-zA-Z]:\// ? path[1..-1] : path
534
+ real_path = Buildr::Util.win_os? && path =~ /^\/[a-zA-Z]:\// ? path[1..-1] : path
535
+ URI.unescape(real_path)
535
536
  end
536
537
 
537
538
  protected
@@ -25,7 +25,7 @@ require 'highline/import'
25
25
 
26
26
 
27
27
  module Buildr
28
-
28
+
29
29
  module Util
30
30
  extend self
31
31
 
@@ -37,7 +37,7 @@ module Buildr
37
37
  # prefer this function instead of using Gem.win_platform?.
38
38
  #
39
39
  # Gem.win_platform? only checks these RUBY_PLATFORM global,
40
- # that in some cases like when running on JRuby is not
40
+ # that in some cases like when running on JRuby is not
41
41
  # succifient for our purpose:
42
42
  #
43
43
  # For JRuby, the value for RUBY_PLATFORM will always be 'java'
@@ -77,7 +77,7 @@ module Buildr
77
77
  path
78
78
  end
79
79
  end
80
-
80
+
81
81
  # Return the timestamp of file, without having to create a file task
82
82
  def timestamp(file)
83
83
  if File.exist?(file)
@@ -121,7 +121,7 @@ module Buildr
121
121
 
122
122
  # Install gems specified by each Gem::Dependency if they are missing. This method prompts the user
123
123
  # for permission before installing anything.
124
- #
124
+ #
125
125
  # Returns the installed Gem::Dependency objects or fails if permission not granted or when buildr
126
126
  # is not running interactively (on a tty)
127
127
  def install(*dependencies)
@@ -334,11 +334,11 @@ if Buildr::Util.java_platform?
334
334
  end
335
335
  private :mv
336
336
  end
337
-
337
+
338
338
  module RakeFileUtils #:nodoc:
339
339
  def rake_merge_option(args, defaults)
340
340
  defaults[:verbose] = false if defaults[:verbose] == :default
341
-
341
+
342
342
  if Hash === args.last
343
343
  defaults.update(args.last)
344
344
  args.pop
@@ -348,56 +348,56 @@ if Buildr::Util.java_platform?
348
348
  end
349
349
  private :rake_merge_option
350
350
  end
351
-
351
+
352
352
  module Buildr
353
353
  class ProcessStatus
354
354
  attr_reader :pid, :termsig, :stopsig, :exitstatus
355
-
355
+
356
356
  def initialize(pid, success, exitstatus)
357
357
  @pid = pid
358
358
  @success = success
359
359
  @exitstatus = exitstatus
360
-
360
+
361
361
  @termsig = nil
362
362
  @stopsig = nil
363
363
  end
364
-
364
+
365
365
  def &(num)
366
366
  pid & num
367
367
  end
368
-
368
+
369
369
  def ==(other)
370
370
  pid == other.pid
371
371
  end
372
-
372
+
373
373
  def >>(num)
374
374
  pid >> num
375
375
  end
376
-
376
+
377
377
  def coredump?
378
378
  false
379
379
  end
380
-
380
+
381
381
  def exited?
382
382
  true
383
383
  end
384
-
384
+
385
385
  def stopped?
386
386
  false
387
387
  end
388
-
388
+
389
389
  def success?
390
390
  @success
391
391
  end
392
-
392
+
393
393
  def to_i
394
394
  pid
395
395
  end
396
-
396
+
397
397
  def to_int
398
398
  pid
399
399
  end
400
-
400
+
401
401
  def to_s
402
402
  pid.to_s
403
403
  end
@@ -406,18 +406,21 @@ if Buildr::Util.java_platform?
406
406
 
407
407
  module FileUtils
408
408
  extend FFI::Library
409
+
410
+ ffi_lib FFI::Platform::LIBC
411
+
409
412
  alias_method :__jruby_system__, :system
410
413
  attach_function :system, [:string], :int
411
414
  alias_method :__native_system__, :system
412
415
  alias_method :system, :__jruby_system__
413
-
416
+
414
417
  # code "borrowed" directly from Rake
415
418
  def sh(*cmd, &block)
416
419
  options = (Hash === cmd.last) ? cmd.pop : {}
417
420
  unless block_given?
418
421
  show_command = cmd.join(" ")
419
422
  show_command = show_command[0,42] + "..."
420
-
423
+
421
424
  block = lambda { |ok, status|
422
425
  ok or fail "Command failed with status (#{status.exitstatus}): [#{show_command}]"
423
426
  }
@@ -431,9 +434,16 @@ if Buildr::Util.java_platform?
431
434
  rake_check_options options, :noop, :verbose
432
435
  rake_output_message cmd.join(" ") if options[:verbose]
433
436
  unless options[:noop]
434
- cd = "cd '#{Dir.pwd}' && "
437
+ if Buildr::Util.win_os?
438
+ # Ruby uses forward slashes regardless of platform,
439
+ # unfortunately cd c:/some/path fails on Windows
440
+ pwd = Dir.pwd.gsub(%r{/}, '\\')
441
+ cd = "cd /d \"#{pwd}\" && "
442
+ else
443
+ cd = "cd '#{Dir.pwd}' && "
444
+ end
435
445
  args = if cmd.size > 1 then cmd[1..cmd.size] else [] end
436
-
446
+
437
447
  res = if Buildr::Util.win_os? && cmd.size == 1
438
448
  __native_system__("#{cd} call #{cmd.first}")
439
449
  else
@@ -446,4 +456,48 @@ if Buildr::Util.java_platform?
446
456
  end
447
457
 
448
458
  end
459
+ else
460
+ module FileUtils
461
+ # code "borrowed" directly from Rake
462
+ def sh(*cmd, &block)
463
+ options = (Hash === cmd.last) ? cmd.pop : {}
464
+ unless block_given?
465
+ show_command = cmd.join(" ")
466
+ show_command = show_command[0,42] + "..."
467
+
468
+ block = lambda { |ok, status|
469
+ ok or fail "Command failed with status (#{status.exitstatus}): [#{show_command}]"
470
+ }
471
+ end
472
+ if RakeFileUtils.verbose_flag == :default
473
+ options[:verbose] = false
474
+ else
475
+ options[:verbose] ||= RakeFileUtils.verbose_flag
476
+ end
477
+ options[:noop] ||= RakeFileUtils.nowrite_flag
478
+ rake_check_options options, :noop, :verbose
479
+ rake_output_message cmd.join(" ") if options[:verbose]
480
+ unless options[:noop]
481
+ if Buildr::Util.win_os?
482
+ # Ruby uses forward slashes regardless of platform,
483
+ # unfortunately cd c:/some/path fails on Windows
484
+ pwd = Dir.pwd.gsub(%r{/}, '\\')
485
+ cd = "cd /d \"#{pwd}\" && "
486
+ else
487
+ cd = "cd '#{Dir.pwd}' && "
488
+ end
489
+
490
+ args = if cmd.size > 1 then cmd[1..cmd.size] else [] end
491
+
492
+ res = if Buildr::Util.win_os? && cmd.size == 1
493
+ system("#{cd} call #{cmd.first}")
494
+ else
495
+ arg_str = args.map { |a| "'#{a}'" }
496
+ system(cd + cmd.first + ' ' + arg_str.join(' '))
497
+ end
498
+
499
+ block.call(res, $?)
500
+ end
501
+ end
502
+ end
449
503
  end