buildr 1.3.2-java → 1.3.3-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. data/CHANGELOG +66 -4
  2. data/{README → README.rdoc} +29 -16
  3. data/Rakefile +16 -20
  4. data/_buildr +38 -0
  5. data/addon/buildr/cobertura.rb +49 -45
  6. data/addon/buildr/emma.rb +238 -0
  7. data/addon/buildr/jetty.rb +1 -1
  8. data/addon/buildr/nailgun.rb +585 -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/bin/buildr +9 -2
  13. data/buildr.buildfile +53 -0
  14. data/buildr.gemspec +21 -14
  15. data/doc/css/default.css +51 -48
  16. data/doc/css/print.css +60 -55
  17. data/doc/images/favicon.png +0 -0
  18. data/doc/images/growl-icon.tiff +0 -0
  19. data/doc/images/project-structure.png +0 -0
  20. data/doc/pages/artifacts.textile +46 -156
  21. data/doc/pages/building.textile +63 -323
  22. data/doc/pages/contributing.textile +112 -102
  23. data/doc/pages/download.textile +19 -27
  24. data/doc/pages/extending.textile +27 -81
  25. data/doc/pages/getting_started.textile +44 -119
  26. data/doc/pages/index.textile +26 -47
  27. data/doc/pages/languages.textile +407 -0
  28. data/doc/pages/more_stuff.textile +92 -173
  29. data/doc/pages/packaging.textile +71 -239
  30. data/doc/pages/projects.textile +58 -233
  31. data/doc/pages/recipes.textile +19 -43
  32. data/doc/pages/settings_profiles.textile +39 -104
  33. data/doc/pages/testing.textile +41 -304
  34. data/doc/pages/troubleshooting.textile +29 -47
  35. data/doc/pages/whats_new.textile +69 -167
  36. data/doc/print.haml +0 -1
  37. data/doc/print.toc.yaml +1 -0
  38. data/doc/scripts/buildr-git.rb +1 -1
  39. data/doc/site.haml +1 -0
  40. data/doc/site.toc.yaml +8 -5
  41. data/{KEYS → etc/KEYS} +0 -0
  42. data/etc/git-svn-authors +16 -0
  43. data/lib/buildr.rb +2 -5
  44. data/lib/buildr/core/application.rb +192 -98
  45. data/lib/buildr/core/build.rb +140 -91
  46. data/lib/buildr/core/checks.rb +5 -5
  47. data/lib/buildr/core/common.rb +1 -1
  48. data/lib/buildr/core/compile.rb +12 -10
  49. data/lib/buildr/core/filter.rb +151 -46
  50. data/lib/buildr/core/generate.rb +9 -9
  51. data/lib/buildr/core/progressbar.rb +1 -1
  52. data/lib/buildr/core/project.rb +8 -7
  53. data/lib/buildr/core/test.rb +51 -26
  54. data/lib/buildr/core/transports.rb +22 -38
  55. data/lib/buildr/core/util.rb +78 -26
  56. data/lib/buildr/groovy.rb +18 -0
  57. data/lib/buildr/groovy/bdd.rb +105 -0
  58. data/lib/buildr/groovy/compiler.rb +138 -0
  59. data/lib/buildr/ide/eclipse.rb +102 -71
  60. data/lib/buildr/ide/idea.rb +7 -12
  61. data/lib/buildr/ide/idea7x.rb +7 -8
  62. data/lib/buildr/java.rb +4 -7
  63. data/lib/buildr/java/ant.rb +26 -5
  64. data/lib/buildr/java/bdd.rb +449 -0
  65. data/lib/buildr/java/commands.rb +9 -9
  66. data/lib/buildr/java/{compilers.rb → compiler.rb} +8 -90
  67. data/lib/buildr/java/jruby.rb +29 -11
  68. data/lib/buildr/java/jtestr_runner.rb.erb +116 -0
  69. data/lib/buildr/java/packaging.rb +23 -16
  70. data/lib/buildr/java/pom.rb +1 -1
  71. data/lib/buildr/java/rjb.rb +21 -8
  72. data/lib/buildr/java/test_result.rb +308 -0
  73. data/lib/buildr/java/tests.rb +324 -0
  74. data/lib/buildr/packaging/artifact.rb +12 -11
  75. data/lib/buildr/packaging/artifact_namespace.rb +7 -4
  76. data/lib/buildr/packaging/gems.rb +3 -3
  77. data/lib/buildr/packaging/zip.rb +13 -10
  78. data/lib/buildr/resources/buildr.icns +0 -0
  79. data/lib/buildr/scala.rb +19 -0
  80. data/lib/buildr/scala/compiler.rb +109 -0
  81. data/lib/buildr/scala/tests.rb +203 -0
  82. data/rakelib/apache.rake +71 -45
  83. data/rakelib/doc.rake +2 -2
  84. data/rakelib/package.rake +3 -2
  85. data/rakelib/rspec.rake +23 -21
  86. data/rakelib/setup.rake +34 -9
  87. data/rakelib/stage.rake +4 -1
  88. data/spec/addon/cobertura_spec.rb +77 -0
  89. data/spec/addon/emma_spec.rb +120 -0
  90. data/spec/addon/test_coverage_spec.rb +255 -0
  91. data/spec/{application_spec.rb → core/application_spec.rb} +82 -4
  92. data/spec/{artifact_namespace_spec.rb → core/artifact_namespace_spec.rb} +12 -1
  93. data/spec/core/build_spec.rb +415 -0
  94. data/spec/{checks_spec.rb → core/checks_spec.rb} +2 -2
  95. data/spec/{common_spec.rb → core/common_spec.rb} +119 -30
  96. data/spec/{compile_spec.rb → core/compile_spec.rb} +17 -13
  97. data/spec/core/generate_spec.rb +33 -0
  98. data/spec/{project_spec.rb → core/project_spec.rb} +9 -6
  99. data/spec/{test_spec.rb → core/test_spec.rb} +222 -28
  100. data/spec/{transport_spec.rb → core/transport_spec.rb} +5 -9
  101. data/spec/groovy/bdd_spec.rb +80 -0
  102. data/spec/{groovy_compilers_spec.rb → groovy/compiler_spec.rb} +1 -1
  103. data/spec/ide/eclipse_spec.rb +243 -0
  104. data/spec/{java_spec.rb → java/ant.rb} +7 -17
  105. data/spec/java/bdd_spec.rb +358 -0
  106. data/spec/{java_compilers_spec.rb → java/compiler_spec.rb} +1 -1
  107. data/spec/java/java_spec.rb +88 -0
  108. data/spec/{java_packaging_spec.rb → java/packaging_spec.rb} +65 -4
  109. data/spec/{java_test_frameworks_spec.rb → java/tests_spec.rb} +31 -10
  110. data/spec/{archive_spec.rb → packaging/archive_spec.rb} +12 -2
  111. data/spec/{artifact_spec.rb → packaging/artifact_spec.rb} +12 -5
  112. data/spec/{packaging_helper.rb → packaging/packaging_helper.rb} +0 -0
  113. data/spec/{packaging_spec.rb → packaging/packaging_spec.rb} +1 -1
  114. data/spec/sandbox.rb +22 -5
  115. data/spec/{scala_compilers_spec.rb → scala/compiler_spec.rb} +1 -1
  116. data/spec/{scala_test_frameworks_spec.rb → scala/tests_spec.rb} +11 -12
  117. data/spec/spec_helpers.rb +38 -17
  118. metadata +93 -70
  119. data/lib/buildr/java/bdd_frameworks.rb +0 -265
  120. data/lib/buildr/java/groovyc.rb +0 -137
  121. data/lib/buildr/java/test_frameworks.rb +0 -450
  122. data/spec/build_spec.rb +0 -193
  123. data/spec/java_bdd_frameworks_spec.rb +0 -238
  124. data/spec/spec.opts +0 -6
@@ -120,7 +120,7 @@ module Buildr
120
120
  mkpath File.dirname(installed)
121
121
  cp name, installed
122
122
  end
123
- puts "Installed #{installed}" if verbose
123
+ info "Installed #{installed}"
124
124
  end
125
125
  end
126
126
 
@@ -161,7 +161,7 @@ module Buildr
161
161
  uri.password = upload_to[:password] if upload_to[:password]
162
162
 
163
163
  # Upload artifact relative to base URL, need to create path before uploading.
164
- puts "Deploying #{to_spec}" if verbose
164
+ info "Deploying #{to_spec}"
165
165
  path = group.gsub('.', '/') + "/#{id}/#{version}/#{File.basename(name)}"
166
166
  URI.upload uri + path, name, :permissions=>upload_to[:permissions]
167
167
  end
@@ -298,7 +298,7 @@ module Buildr
298
298
  # so don't perform it if the task found a different way to create the artifact.
299
299
  task.enhance do
300
300
  unless File.exist?(name)
301
- puts "Downloading #{to_spec}" if verbose
301
+ info "Downloading #{to_spec}"
302
302
  download
303
303
  pom.invoke rescue nil if pom && pom != self
304
304
  end
@@ -320,7 +320,7 @@ module Buildr
320
320
  mkpath File.dirname(name)
321
321
  pom.invoke unless type == :pom
322
322
  cp path, name
323
- puts "Installed #{path} as #{to_spec}" if verbose
323
+ info "Installed #{path} as #{to_spec}"
324
324
  end
325
325
  end
326
326
  unless type == :pom
@@ -346,7 +346,7 @@ module Buildr
346
346
  # This method attempts to download the artifact from each repository in the order in
347
347
  # which they are returned from #remote, until successful. It always downloads the POM first.
348
348
  def download
349
- puts "Downloading #{to_spec}" if Buildr.application.options.trace
349
+ trace "Downloading #{to_spec}"
350
350
  remote = Buildr.repositories.remote.map { |repo_url| URI === repo_url ? repo_url : URI.parse(repo_url) }
351
351
  remote = remote.each { |repo_url| repo_url.path += '/' unless repo_url.path[-1] == '/' }
352
352
  fail 'No remote repositories defined!' if remote.empty?
@@ -358,8 +358,8 @@ module Buildr
358
358
  rescue URI::NotFoundError
359
359
  false
360
360
  rescue Exception=>error
361
- puts error if verbose
362
- puts error.backtrace.join("\n") if Buildr.application.options.trace
361
+ info error
362
+ trace error.backtrace.join("\n")
363
363
  false
364
364
  end
365
365
  end
@@ -602,7 +602,7 @@ module Buildr
602
602
  # artifacts(*spec) => artifacts
603
603
  #
604
604
  # Handles multiple artifacts at a time. This method is the plural equivalent of
605
- # #artifacts, but can do more things.
605
+ # #artifact, but can do more things.
606
606
  #
607
607
  # Returns an array of artifacts built using the supplied
608
608
  # specifications, each of which can be:
@@ -671,10 +671,11 @@ module Buildr
671
671
  # :call-seq:
672
672
  # group(ids, :under=>group_name, :version=>number) => artifacts
673
673
  #
674
- # Convenience method for defining multiple artifacts that belong to the same group and version.
675
- # Accepts multiple artifact identifiers follows by two hash values:
674
+ # Convenience method for defining multiple artifacts that belong to the same group, type and version.
675
+ # Accepts multiple artifact identifiers followed by two or three hash values:
676
676
  # * :under -- The group identifier
677
677
  # * :version -- The version number
678
+ # * :type -- The artifact type (optional)
678
679
  #
679
680
  # For example:
680
681
  # group 'xbean', 'xbean_xpath', 'xmlpublic', :under=>'xmlbeans', :version=>'2.1.0'
@@ -682,7 +683,7 @@ module Buildr
682
683
  # group %w{xbean xbean_xpath xmlpublic}, :under=>'xmlbeans', :version=>'2.1.0'
683
684
  def group(*args)
684
685
  hash = args.pop
685
- args.flatten.map { |id| artifact :group=>hash[:under], :version=>hash[:version], :id=>id }
686
+ args.flatten.map { |id| artifact :group=>hash[:under], :type=>hash[:type], :version=>hash[:version], :id=>id }
686
687
  end
687
688
 
688
689
  # :call-seq:
@@ -697,10 +697,13 @@ module Buildr
697
697
  raise "Unsatisfied dependency #{previous} " +
698
698
  "not satisfied by #{artifact}" unless satisfied
699
699
  previous.version = artifact.version # OK, set new version
700
+ artifact = previous # use the same object for aliases
700
701
  else # not a requirement, set the new values
701
- previous.copy_attrs(artifact)
702
+ unless artifact.id == previous.id && name != previous.name
703
+ previous.copy_attrs(artifact)
704
+ artifact = previous
705
+ end
702
706
  end
703
- artifact = previous # use the same object for aliases
704
707
  else
705
708
  if unvers.nil? && # we only have the version
706
709
  (previous = get(unvers, true, false, false))
@@ -722,8 +725,8 @@ module Buildr
722
725
  group(name, *(names + [{:namespace => self}]))
723
726
  elsif artifact.id
724
727
  unvers = artifact.unversioned_spec
725
- registry[unvers] = artifact
726
- registry.alias name, unvers unless name.to_s[/^\s*$/]
728
+ registry[name] = artifact
729
+ registry.alias unvers, name
727
730
  else
728
731
  registry[name] = artifact
729
732
  end
@@ -40,11 +40,11 @@ module Buildr
40
40
  end
41
41
 
42
42
  def install
43
- Util.ruby 'install', name, :command => 'gem', :sudo => true
43
+ Util::Gems.command 'install', name
44
44
  end
45
45
 
46
46
  def uninstall
47
- Util.ruby 'uninstall', spec.name, '-v', spec.version.to_s, :command => 'gem', :sudo => true
47
+ Util::Gems.command 'uninstall', spec.name, '-v', spec.version.to_s
48
48
  end
49
49
 
50
50
  def upload
@@ -79,7 +79,7 @@ module Buildr
79
79
 
80
80
  def package_as_gem(file_name) #:nodoc:
81
81
  PackageGemTask.define_task(file_name).tap do |gem|
82
- %{ lib test doc }.each do |dir|
82
+ %w{ lib test doc }.each do |dir|
83
83
  gem.include :from=>_(dir), :path=>dir if File.directory?(_(dir))
84
84
  end
85
85
  gem.spec do |spec|
@@ -14,6 +14,7 @@
14
14
  # the License.
15
15
 
16
16
 
17
+ $LOADED_FEATURES.unshift 'ftools' if RUBY_VERSION >= '1.9.0'
17
18
  require 'zip/zip'
18
19
  require 'zip/zipfilesystem'
19
20
 
@@ -45,11 +46,11 @@ module Buildr
45
46
  if File.directory?(path)
46
47
  in_directory path do |file, rel_path|
47
48
  dest = "#{@path}#{rel_path}"
48
- puts "Adding #{dest}" if Buildr.application.options.trace
49
+ trace "Adding #{dest}"
49
50
  file_map[dest] = file
50
51
  end
51
52
  else
52
- puts "Adding #{@path}#{File.basename(path)}" if Buildr.application.options.trace
53
+ trace "Adding #{@path}#{File.basename(path)}"
53
54
  file_map["#{@path}#{File.basename(path)}"] = path
54
55
  end
55
56
  end
@@ -150,11 +151,11 @@ module Buildr
150
151
  path = rel_path.split('/')[1..-1]
151
152
  path.unshift as unless as == '.'
152
153
  dest = "#{@path}#{path.join('/')}"
153
- puts "Adding #{dest}" if Buildr.application.options.trace
154
+ trace "Adding #{dest}"
154
155
  file_map[dest] = file
155
156
  end
156
157
  else
157
- puts "Adding #{@path}#{as}" if Buildr.application.options.trace
158
+ trace "Adding #{@path}#{as}"
158
159
  file_map["#{@path}#{as}"] = file
159
160
  end
160
161
  end
@@ -218,7 +219,7 @@ module Buildr
218
219
  if @includes.any? { |pattern| File.fnmatch(pattern, entry.name, File::FNM_PATHNAME) } &&
219
220
  !@excludes.any? { |pattern| File.fnmatch(pattern, entry.name, File::FNM_PATHNAME) }
220
221
  dest = path =~ /^\/?$/ ? entry.name : Util.relative_path(path + "/" + entry.name)
221
- puts "Adding #{dest}" if Buildr.application.options.trace
222
+ trace "Adding #{dest}"
222
223
  file_map[dest] = lambda { |output| output.write source.read(entry) }
223
224
  end
224
225
  end
@@ -546,7 +547,7 @@ module Buildr
546
547
  patterns.map(entries).each do |dest, entry|
547
548
  next if entry.directory?
548
549
  dest = File.expand_path(dest, target.to_s)
549
- puts "Extracting #{dest}" if Buildr.application.options.trace
550
+ trace "Extracting #{dest}"
550
551
  mkpath File.dirname(dest), :verbose=>false rescue nil
551
552
  entry.extract(dest) { true }
552
553
  end
@@ -653,10 +654,12 @@ module Buildr
653
654
  includes = @include || ['**/*']
654
655
  excludes = @exclude || []
655
656
  entries.inject({}) do |map, entry|
656
- short = entry.name.sub(@path, '')
657
- if includes.any? { |pat| File.fnmatch(pat, short, File::FNM_PATHNAME) } &&
658
- !excludes.any? { |pat| File.fnmatch(pat, short, File::FNM_PATHNAME) }
659
- map[short] = entry
657
+ if entry.name =~ /^#{@path}/
658
+ short = entry.name.sub(@path, '')
659
+ if includes.any? { |pat| File.fnmatch(pat, short, File::FNM_PATHNAME) } &&
660
+ !excludes.any? { |pat| File.fnmatch(pat, short, File::FNM_PATHNAME) }
661
+ map[short] = entry
662
+ end
660
663
  end
661
664
  map
662
665
  end
@@ -0,0 +1,19 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with this
3
+ # work for additional information regarding copyright ownership. The ASF
4
+ # licenses this file to you under the Apache License, Version 2.0 (the
5
+ # "License"); you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations under
14
+ # the License.
15
+
16
+
17
+ require 'buildr/scala/compiler'
18
+ require 'buildr/scala/tests'
19
+ Object::Scala = Buildr::Scala
@@ -0,0 +1,109 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with this
3
+ # work for additional information regarding copyright ownership. The ASF
4
+ # licenses this file to you under the Apache License, Version 2.0 (the
5
+ # "License"); you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations under
14
+ # the License.
15
+
16
+ require 'buildr/core/project'
17
+ require 'buildr/core/common'
18
+ require 'buildr/core/compile'
19
+ require 'buildr/packaging'
20
+
21
+
22
+ module Buildr::Scala
23
+
24
+ # Scalac compiler:
25
+ # compile.using(:scalac)
26
+ # Used by default if .scala files are found in the src/main/scala directory (or src/test/scala)
27
+ # and sets the target directory to target/classes (or target/test/classes).
28
+ #
29
+ # Accepts the following options:
30
+ # * :warnings -- Generate warnings if true (opposite of -nowarn).
31
+ # * :deprecation -- Output source locations where deprecated APIs are used.
32
+ # * :optimise -- Generates faster bytecode by applying optimisations to the program.
33
+ # * :target -- Class file compatibility with specified release.
34
+ # * :debug -- Generate debugging info.
35
+ # * :other -- Array of options to pass to the Scalac compiler as is, e.g. -Xprint-types
36
+ class Scalac < Buildr::Compiler::Base
37
+ class << self
38
+ def scala_home
39
+ @home ||= ENV['SCALA_HOME']
40
+ end
41
+
42
+ def dependencies
43
+ [ 'scala-library.jar', 'scala-compiler.jar'].map { |jar| File.expand_path("lib/#{jar}", scala_home) }
44
+ end
45
+
46
+ def use_fsc
47
+ ENV["USE_FSC"] =~ /^(yes|on|true)$/i
48
+ end
49
+ end
50
+
51
+ OPTIONS = [:warnings, :deprecation, :optimise, :target, :debug, :other]
52
+ Java.classpath << dependencies
53
+
54
+ specify :language=>:scala, :target=>'classes', :target_ext=>'class', :packaging=>:jar
55
+
56
+ def initialize(project, options) #:nodoc:
57
+ super
58
+ options[:debug] = Buildr.options.debug if options[:debug].nil?
59
+ options[:warnings] = verbose if options[:warnings].nil?
60
+ options[:deprecation] ||= false
61
+ options[:optimise] ||= false
62
+ end
63
+
64
+ def compile(sources, target, dependencies) #:nodoc:
65
+ check_options options, OPTIONS
66
+
67
+ cmd_args = []
68
+ cmd_args << '-classpath' << (dependencies + Scalac.dependencies).join(File::PATH_SEPARATOR)
69
+ source_paths = sources.select { |source| File.directory?(source) }
70
+ cmd_args << '-sourcepath' << source_paths.join(File::PATH_SEPARATOR) unless source_paths.empty?
71
+ cmd_args << '-d' << File.expand_path(target)
72
+ cmd_args += scalac_args
73
+ cmd_args += files_from_sources(sources)
74
+
75
+ unless Buildr.application.options.dryrun
76
+ Scalac.scala_home or fail 'Are we forgetting something? SCALA_HOME not set.'
77
+ trace((['scalac'] + cmd_args).join(' '))
78
+ if Scalac.use_fsc
79
+ system(([File.expand_path('bin/fsc', Scalac.scala_home)] + cmd_args).join(' ')) or
80
+ fail 'Failed to compile, see errors above'
81
+ else
82
+ Java.load
83
+ Java.scala.tools.nsc.Main.process(cmd_args.to_java(Java.java.lang.String))
84
+ fail 'Failed to compile, see errors above' if Java.scala.tools.nsc.Main.reporter.hasErrors
85
+ end
86
+ end
87
+ end
88
+
89
+ private
90
+
91
+ # Returns Scalac command line arguments from the set of options.
92
+ def scalac_args #:nodoc:
93
+ args = []
94
+ args << "-nowarn" unless options[:warnings]
95
+ args << "-verbose" if Buildr.application.options.trace
96
+ args << "-g" if options[:debug]
97
+ args << "-deprecation" if options[:deprecation]
98
+ args << "-optimise" if options[:optimise]
99
+ args << "-target:jvm-" + options[:target].to_s if options[:target]
100
+ args + Array(options[:other])
101
+ end
102
+
103
+ end
104
+
105
+ end
106
+
107
+ # Scala compiler comes first, ahead of Javac, this allows it to pick
108
+ # projects that mix Scala and Java code by spotting Scala code first.
109
+ Buildr::Compiler.compilers.unshift Buildr::Scala::Scalac
@@ -0,0 +1,203 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with this
3
+ # work for additional information regarding copyright ownership. The ASF
4
+ # licenses this file to you under the Apache License, Version 2.0 (the
5
+ # "License"); you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations under
14
+ # the License.
15
+
16
+
17
+ require 'buildr/core/build'
18
+ require 'buildr/core/compile'
19
+ require 'buildr/java/ant'
20
+ require 'buildr/java/tests'
21
+
22
+
23
+ module Buildr::Scala
24
+
25
+ # Scala::Specs is available when using Scala::Test
26
+ module ScalaSpecs
27
+ VERSION = '1.2.9'
28
+
29
+ class << self
30
+ def version
31
+ Buildr.settings.build['scala.specs'] || VERSION
32
+ end
33
+
34
+ def dependencies
35
+ ["org.specs:specs:jar:#{version}"]
36
+ end
37
+
38
+ private
39
+ def const_missing(const)
40
+ return super unless const == :REQUIRES # TODO: remove in 1.5
41
+ Buildr.application.deprecated "Please use Scala::Specs.dependencies/.version instead of ScalaSpecs::REQUIRES/VERSION"
42
+ dependencies
43
+ end
44
+ end
45
+ end
46
+
47
+
48
+ # Scala::Check is available when using Scala::Test
49
+ module ScalaCheck
50
+ VERSION = '1.3'
51
+
52
+ class << self
53
+ def version
54
+ Buildr.settings.build['scala.check'] || VERSION
55
+ end
56
+
57
+ def dependencies
58
+ ["org.scalacheck:scalacheck:jar:#{version}"]
59
+ end
60
+
61
+ private
62
+ def const_missing(const)
63
+ return super unless const == :REQUIRES # TODO: remove in 1.5
64
+ Buildr.application.deprecated "Please use Scala::Check.dependencies/.version instead of ScalaCheck::REQUIRES/VERSION"
65
+ dependencies
66
+ end
67
+ end
68
+ end
69
+
70
+
71
+ # ScalaTest framework, the default test framework for Scala tests.
72
+ #
73
+ # Support the following options:
74
+ # * :properties -- Hash of system properties available to the test case.
75
+ # * :environment -- Hash of environment variables available to the test case.
76
+ # * :java_args -- Arguments passed as is to the JVM.
77
+ class ScalaTest < TestFramework::Java
78
+
79
+ VERSION = '0.9.3'
80
+
81
+ class << self
82
+ def version
83
+ Buildr.settings.build['scala.test'] || VERSION
84
+ end
85
+
86
+ def dependencies
87
+ ["org.scalatest:scalatest:jar:#{version}"] + ScalaSpecs.dependencies +
88
+ ScalaCheck.dependencies + JMock.dependencies
89
+ end
90
+
91
+ def applies_to?(project) #:nodoc:
92
+ project.test.compile.language == :scala
93
+ end
94
+
95
+ private
96
+ def const_missing(const)
97
+ return super unless const == :REQUIRES # TODO: remove in 1.5
98
+ Buildr.application.deprecated "Please use Scala::Test.dependencies/.version instead of ScalaTest::REQUIRES/VERSION"
99
+ dependencies
100
+ end
101
+ end
102
+
103
+ # annotation-based group inclusion
104
+ attr_accessor :group_includes
105
+
106
+ # annotation-based group exclusion
107
+ attr_accessor :group_excludes
108
+
109
+ def initialize(test_task, options)
110
+ super
111
+ @group_includes = []
112
+ @group_excludes = []
113
+ end
114
+
115
+ def tests(dependencies) #:nodoc:
116
+ suites = filter_classes(dependencies, :interfaces => %w{org.scalatest.Suite})
117
+ # we should really filter using :class => %w{org.specs.Specification} instead of naming convention
118
+ specs = filter_classes(dependencies, :class_names => [/Specs?$/])
119
+ [suites, specs].flatten
120
+ end
121
+
122
+ def run(tests, dependencies) #:nodoc:
123
+ mkpath task.report_to.to_s
124
+ success = []
125
+ scalatest = tests.select { |t| t !~ /Specs?$/ }
126
+ specs = tests.select { |t| t =~ /Specs?$/ }
127
+
128
+ # Specs
129
+ nostacktrace = (options[:nostacktrace]) ? "-ns" : ""
130
+ cmd_options = { :properties => options[:properties],
131
+ :java_args => options[:java_args],
132
+ :classpath => dependencies}
133
+ specs.each do |spec|
134
+ Java.load
135
+ begin
136
+ Java::Commands.java(spec, cmd_options)
137
+ rescue => e
138
+ print e.message
139
+ else
140
+ success << spec
141
+ end
142
+ end
143
+
144
+ # ScalaTest
145
+ reporter_options = 'TFGBSAR' # testSucceeded, testFailed, testIgnored, suiteAborted, runStopped, runAborted, runCompleted
146
+ scalatest.each do |suite|
147
+ info "ScalaTest #{suite.inspect}"
148
+ # Use Ant to execute the ScalaTest task, gives us performance and reporting.
149
+ reportFile = File.join(task.report_to.to_s, "TEST-#{suite}.txt")
150
+ taskdef = Buildr.artifacts(self.class.dependencies).each(&:invoke).map(&:to_s)
151
+ Buildr.ant('scalatest') do |ant|
152
+ ant.taskdef :name=>'scalatest', :classname=>'org.scalatest.tools.ScalaTestTask',
153
+ :classpath=>taskdef.join(File::PATH_SEPARATOR)
154
+ ant.scalatest :runpath=>dependencies.join(File::PATH_SEPARATOR) do
155
+ ant.suite :classname=>suite
156
+ ant.reporter :type=>'stdout', :config=>reporter_options
157
+ ant.reporter :type=>'file', :filename=> reportFile, :config=>reporter_options
158
+ ant.includes group_includes.join(" ") if group_includes
159
+ ant.excludes group_excludes.join(" ") if group_excludes
160
+ (options[:properties] || []).each { |name, value| ant.property :name=>name, :value=>value }
161
+ end
162
+ end
163
+
164
+ # Parse for failures, errors, etc.
165
+ # This is a bit of a pain right now because ScalaTest doesn't flush its
166
+ # output synchronously before the Ant test finishes so we have to loop
167
+ # and wait for an indication that the test run was completed.
168
+ failed = false
169
+ completed = false
170
+ wait = 0
171
+ while (!completed) do
172
+ File.open(reportFile, "r") do |input|
173
+ while (line = input.gets) do
174
+ failed = (line =~ /(TEST FAILED -)|(RUN STOPPED)|(RUN ABORTED)/) unless failed
175
+ completed |= (line =~ /Run completed\./)
176
+ break if (failed || completed)
177
+ end
178
+ end
179
+ wait += 1
180
+ break if (failed || wait > 10)
181
+ unless completed
182
+ sleep(1)
183
+ end
184
+ end
185
+ success << suite if (completed && !failed)
186
+ end
187
+
188
+ success
189
+ end # run
190
+
191
+ end # ScalaTest
192
+
193
+ end
194
+
195
+
196
+ # Backwards compatibility stuff. Remove in 1.5.
197
+ module Buildr
198
+ ScalaSpecs = Scala::ScalaSpecs
199
+ ScalaCheck = Scala::ScalaCheck
200
+ ScalaTest = Scala::ScalaTest
201
+ end
202
+
203
+ Buildr::TestFramework << Buildr::Scala::ScalaTest