buildr 1.3.2 → 1.3.3

Sign up to get free protection for your applications and to get access to all the features.
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 +103 -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
@@ -14,15 +14,15 @@
14
14
  # the License.
15
15
 
16
16
 
17
- require 'md5'
18
- require 'sha1'
17
+ require 'digest/md5'
18
+ require 'digest/sha1'
19
19
 
20
20
 
21
21
  # Tasks specific to Apache projects (license, release, etc).
22
22
  namespace 'apache' do
23
23
 
24
24
  desc 'Upload snapshot packages over to people.apache.org'
25
- task 'snapshot'=>'package' do
25
+ task 'snapshot'=>['spec', 'package'] do
26
26
  rm_rf 'snapshot' # Always start with empty directory
27
27
  puts "Copying existing gems from Apache"
28
28
  sh 'rsync', '--progress', '--recursive', 'people.apache.org:public_html/buildr/snapshot', './'
@@ -40,18 +40,18 @@ namespace 'apache' do
40
40
  print 'Checking that files contain the Apache license ... '
41
41
  required = task.prerequisites.select { |fn| File.file?(fn) }
42
42
  missing = required.reject { |fn|
43
- comments = File.read(fn).scan(/(\/\*(.*?)\*\/)|^#\s+(.*?)$|<!--(.*?)-->/m).
43
+ comments = File.read(fn).scan(/(\/\*(.*?)\*\/)|^#\s+(.*?)$|^-#\s+(.*?)$|<!--(.*?)-->/m).
44
44
  map { |match| match.compact }.flatten.join("\n")
45
45
  comments =~ /Licensed to the Apache Software Foundation/ && comments =~ /http:\/\/www.apache.org\/licenses\/LICENSE-2.0/
46
46
  }
47
47
  fail "#{missing.join(', ')} missing Apache License, please add it before making a release!" unless missing.empty?
48
48
  puts 'OK'
49
49
  end
50
- task('license').prerequisites.exclude('.class', '.png', '.jar', '.tif', '.textile', '.haml',
51
- 'README', 'LICENSE', 'CHANGELOG', 'DISCLAIMER', 'NOTICE', 'KEYS', 'spec/spec.opts')
52
-
53
- task 'check' do
54
- ENV['GPG_USER'] or fail 'Please set GPG_USER (--local-user) environment variable so we know which key to use.'
50
+
51
+ # Staging checks specific for Apache.
52
+ task 'check'=>'license' do |task, args|
53
+ args.gpg_user or fail "Please run with gpg_user=<argument for gpg --local-user>"
54
+ fail "No GPG user #{args.gpg_user}" if `gpg --list-keys #{args.gpg_user}`.empty?
55
55
  end
56
56
 
57
57
 
@@ -63,15 +63,16 @@ namespace 'apache' do
63
63
  end
64
64
  end
65
65
 
66
- task 'sign'=>['KEYS', 'staged/distro'] do
67
- gpg_user = ENV['GPG_USER'] or fail 'Please set GPG_USER (--local-user) environment variable so we know which key to use.'
66
+ task 'sign'=>['etc/KEYS', 'staged/distro'] do |task, args|
67
+ gpg_user = args.gpg_user or fail "Please run with gpg_user=<argument for gpg --local-user>"
68
+ puts "Signing packages in staged/distro as user #{gpg_user}"
68
69
  FileList['staged/distro/*.{gem,zip,tgz}'].each do |pkg|
69
70
  bytes = File.open(pkg, 'rb') { |file| file.read }
70
- File.open(pkg + '.md5', 'w') { |file| file.write MD5.hexdigest(bytes) << ' ' << File.basename(pkg) }
71
- File.open(pkg + '.sha1', 'w') { |file| file.write SHA1.hexdigest(bytes) << ' ' << File.basename(pkg) }
71
+ File.open(pkg + '.md5', 'w') { |file| file.write Digest::MD5.hexdigest(bytes) << ' ' << File.basename(pkg) }
72
+ File.open(pkg + '.sha1', 'w') { |file| file.write Digest::SHA1.hexdigest(bytes) << ' ' << File.basename(pkg) }
72
73
  sh 'gpg', '--local-user', gpg_user, '--armor', '--output', pkg + '.asc', '--detach-sig', pkg, :verbose=>true
73
74
  end
74
- cp 'KEYS', 'staged/distro'
75
+ cp 'etc/KEYS', 'staged/distro'
75
76
  end
76
77
 
77
78
  # Publish prerequisites to distro server.
@@ -90,7 +91,7 @@ namespace 'apache' do
90
91
  url = args.incubating ? "http://www.apache.org/dist/incubator/#{spec.name}/#{spec.version}-incubating" :
91
92
  "http://www.apache.org/dist/#{spec.name}/#{spec.version}"
92
93
  rows = FileList['staged/distro/*.{gem,tgz,zip}'].map { |pkg|
93
- name, md5 = File.basename(pkg), MD5.file(pkg).to_s
94
+ name, md5 = File.basename(pkg), Digest::MD5.file(pkg).to_s
94
95
  %{| "#{name}":#{url}/#{name} | "#{md5}":#{url}/#{name}.md5 | "Sig":#{url}/#{name}.asc |}
95
96
  }
96
97
  textile = <<-TEXTILE
@@ -110,34 +111,6 @@ p>. ("Release signing keys":#{url}/KEYS)
110
111
  puts 'Done'
111
112
  end
112
113
 
113
- =begin
114
- task 'distro-links'=>['staged/site', 'apache:sign'] do |task, args|
115
- rows = FileList['staged/distro/*.{gem,tgz,zip}'].map { |pkg|
116
- name, md5 = File.basename(pkg), File.read("#{pkg}.md5").split.first
117
- <<-HTML
118
- <tr>
119
- <td><a href="#{url}/#{name}">#{name}</a></td>
120
- <td><a href="#{url}/#{name}.md5">#{md5}</a></td>
121
- <td><a href="#{url}/#{name}.asc">Sig</a></td>
122
- </tr>
123
- HTML
124
- }
125
- html = <<-HTML
126
- <h3>#{spec.name} #{spec.version}#{args.incubating && "-incubating"} (#{Time.now.strftime('%Y-%m-%d')})</h3>
127
- <table>
128
- <thead><th>Package</th><th>MD5 Checksum</th><th>PGP</th></thead>
129
- #{rows.join("\n")}
130
- </table>
131
- <p style="text-align:right"> (<a href="#{url}/KEYS">Release signing keys</a>)</p>
132
- HTML
133
- file_name = 'staged/site/download.html'
134
- modified = File.read(file_name).sub(/<h2.*binaries.*source.*<\/h2>.*/i) { |header| "#{header}\n#{html}\n" }
135
- File.open file_name, 'w' do |file|
136
- file.write modified
137
- end
138
- end
139
- =end
140
-
141
114
  file 'staged/site'=>['distro-links', 'staged', 'site'] do
142
115
  rm_rf 'staged/site'
143
116
  cp_r 'site', 'staged'
@@ -151,15 +124,68 @@ p>. ("Release signing keys":#{url}/KEYS)
151
124
  sh 'rsync', '--progress', '--recursive', '--delete', 'published/site/', target
152
125
  puts 'Done'
153
126
  end
127
+
128
+
129
+ file 'release-vote-email.txt'=>'CHANGELOG' do |task|
130
+ # Need to know who you are on Apache, local user may be different (see .ssh/config).
131
+ whoami = `ssh people.apache.org whoami`.strip
132
+ base_url = "http://people.apache.org/~#{whoami}/buildr/#{spec.version}"
133
+ # Need changes for this release only.
134
+ changelog = File.read('CHANGELOG').scan(/(^(\d+\.\d+(?:\.\d+)?)\s+\(\d{4}-\d{2}-\d{2}\)\s*((:?^[^\n]+\n)*))/)
135
+ changes = changelog[0][2]
136
+ previous_version = changelog[1][1]
137
+
138
+ email = <<-EMAIL
139
+ To: buildr-dev@incubator.apache.org
140
+ Subject: [VOTE] Buildr #{spec.version} release
141
+
142
+ We're voting on the source distributions available here:
143
+ #{base_url}/distro/
144
+
145
+ Specifically:
146
+ #{base_url}/distro/buildr-#{spec.version}-incubating.tgz
147
+ #{base_url}/distro/buildr-#{spec.version}-incubating.zip
148
+
149
+ The documentation generated for this release is available here:
150
+ #{base_url}/site/
151
+ #{base_url}/site/buildr.pdf
154
152
 
153
+ The official specification against which this release was tested:
154
+ #{base_url}/site/specs.html
155
+
156
+ Test coverage report:
157
+ #{base_url}/site/coverage/index.html
158
+
159
+
160
+ The following changes were made since #{previous_version}:
161
+
162
+ #{changes}
163
+ EMAIL
164
+ File.open task.name, 'w' do |file|
165
+ file.write email
166
+ end
167
+ puts "Created release vote email template in '#{task.name}':"
168
+ puts email
169
+ end
170
+
171
+ end
172
+
173
+ task 'clobber' do
174
+ rm_rf 'snapshot'
175
+ rm_f 'release-vote-email.txt'
155
176
  end
156
177
 
157
178
 
158
- task 'stage:check'=>['apache:license', 'apache:check']
179
+ task 'stage:check'=>['apache:check']
159
180
  task 'stage:prepare'=>['staged/distro', 'staged/site'] do |task|
160
181
  # Since this requires input (passphrase), do it at the very end.
161
182
  task.enhance do
162
183
  task('apache:sign').invoke
163
184
  end
164
185
  end
165
- task 'release:publish'=>['apache:publish:distro', 'apache:publish:site']
186
+ task 'stage' do
187
+ task('apache:snapshot').invoke
188
+ end
189
+ task 'stage:wrapup'=>'release-vote-email.txt'
190
+
191
+ task 'release:publish'=>['apache:publish:distro', 'apache:publish:site']
@@ -51,7 +51,7 @@ begin
51
51
  collection = Docter.collection(spec.name).using('doc/site.toc.yaml').include('doc/pages', 'LICENSE', 'CHANGELOG')
52
52
  # TODO: Add coverage reports when we get them to run.
53
53
  template = Docter.template('doc/site.haml').
54
- include('doc/css', 'doc/images', 'doc/scripts', 'reports/specs.html', 'rdoc', 'print/buildr.pdf')
54
+ include('doc/css', 'doc/images', 'doc/scripts', 'reports/coverage', 'reports/specs.html', 'rdoc', 'print/buildr.pdf')
55
55
 
56
56
  desc 'Run Docter server on port 3000'
57
57
  Docter::Rake.serve 'docter', collection, template, :port=>3000
@@ -60,7 +60,7 @@ begin
60
60
  Docter::Rake.generate 'site', collection, template
61
61
 
62
62
  Docter::Rake.generate 'print',
63
- Docter.collection(spec.name).using('doc/print.toc.yaml').include('doc/pages', 'LICENSE'),
63
+ Docter.collection(spec.name).using('doc/print.toc.yaml').include('doc/pages'),
64
64
  Docter.template('doc/print.haml').include('doc/css', 'doc/images'), :one_page
65
65
 
66
66
  file('print/buildr.pdf'=>'print') do |task|
@@ -29,7 +29,7 @@ desc 'Install the package locally'
29
29
  task 'install'=>['setup', "#{package.package_dir}/#{package.gem_file}"] do |task|
30
30
  print "Installing #{spec.name} ... "
31
31
  args = [Config::CONFIG['ruby_install_name'], '-S', 'gem', 'install', "#{package.package_dir}/#{package.gem_file}"]
32
- args.unshift('sudo') unless windows?
32
+ args.unshift('sudo') if sudo_needed?
33
33
  sh *args
34
34
  puts 'Done'
35
35
  end
@@ -38,7 +38,7 @@ desc 'Uninstall previously installed packaged'
38
38
  task 'uninstall' do |task|
39
39
  print "Uninstalling #{spec.name} ... "
40
40
  args = [Config::CONFIG['ruby_install_name'], '-S', 'gem', 'uninstall', spec.name, '--version', spec.version.to_s]
41
- args.unshift('sudo') unless windows?
41
+ args.unshift('sudo') if sudo_needed?
42
42
  sh *args
43
43
  puts 'Done'
44
44
  end
@@ -46,6 +46,7 @@ end
46
46
 
47
47
  desc 'Look for new dependencies, check transitive dependencies'
48
48
  task 'dependency' do
49
+ puts "Checking that all dependencies are up to date ..."
49
50
  # Find if anything has a more recent dependency. These are not errors, just reports.
50
51
  for dep in spec.dependencies
51
52
  current = Gem::SourceInfoCache.search(dep, true, true).last
@@ -19,36 +19,39 @@ begin
19
19
 
20
20
  directory 'reports'
21
21
  task 'clobber' do
22
- rm 'failing' rescue nil
22
+ rm_f 'failed'
23
23
  rm_rf 'reports'
24
24
  end
25
25
 
26
26
  desc 'Run all specs'
27
27
  Spec::Rake::SpecTask.new('spec'=>'reports') do |task|
28
- task.spec_files = FileList['spec/**/*_spec.rb']
29
- task.spec_opts << '--options' << 'spec/spec.opts' << '--format' << 'failing_examples:failing' <<
30
- '--format' << 'html:reports/specs.html' << '--backtrace'
28
+ task.spec_files = Dir['spec/**/*_spec.rb']
29
+ task.spec_opts = %w{--format specdoc --format failing_examples:failed --format html:reports/specs.html --loadby mtime --backtrace}
30
+ task.spec_opts << '--colour' if $stdout.isatty
31
31
  end
32
32
  file 'reports/specs.html'=>'spec'
33
33
 
34
- desc 'Run all failing examples from previous run'
35
- Spec::Rake::SpecTask.new('failing') do |task|
36
- task.spec_files = FileList['spec/**/*_spec.rb']
37
- task.spec_opts << '--options' << 'spec/spec.opts' << '--format' << 'failing_examples:failing' << '--example' << 'failing'
34
+ desc 'Run all failed examples from previous run'
35
+ Spec::Rake::SpecTask.new('failed') do |task|
36
+ task.spec_files = Dir['spec/**/*_spec.rb']
37
+ task.spec_opts = %w{--format specdoc --format failing_examples:failed --example failed --backtrace}
38
+ task.spec_opts << '--colour' if $stdout.isatty
38
39
  end
39
40
 
41
+ # TODO: Horribly broken! Fix some other time.
42
+ desc 'Run RSpec and generate Spec and coverage reports (slow)'
43
+ Spec::Rake::SpecTask.new('coverage'=>'reports') do |task|
44
+ task.spec_files = Dir['spec/**/*_spec.rb']
45
+ task.spec_opts = %W{--format progress --format failing_examples:failed --format html:reports/specs.html --backtrace}
46
+ task.spec_opts << '--colour' if $stdout.isatty
47
+ task.rcov = true
48
+ task.rcov_dir = 'reports/coverage'
49
+ task.rcov_opts << '--exclude / --include-file ^lib --include-file ^addon --text-summary'
50
+ end
51
+ file 'reports/coverage'=>'coverage'
52
+
40
53
  # Useful for testing with JRuby when using Ruby and vice versa.
41
54
  namespace 'spec' do
42
- =begin
43
- # TODO: Horribly broken! Fix some other time.
44
- desc 'Run RSpec and generate Spec and coverage reports (slow)'
45
- Spec::Rake::SpecTask.new('rcov') do |task|
46
- task.spec_files = FileList['spec/**/*spec.rb']
47
- task.rcov = true
48
- task.rcov_opts = '--exclude', 'spec,bin'
49
- task.rcov_dir = 'coverage'
50
- end
51
- =end
52
55
 
53
56
  desc 'Run all specs specifically with Ruby'
54
57
  task 'ruby' do
@@ -65,7 +68,7 @@ begin
65
68
  end
66
69
 
67
70
  task 'setup' do
68
- install_gem 'win32console' if Gem.win_platform? # Colors for RSpec, only on Windows platform.
71
+ install_gem 'win32console' if windows? && !RUBY_PLATFORM[/java/] # Colors for RSpec, only on Windows platform.
69
72
  end
70
73
 
71
74
  rescue LoadError
@@ -77,5 +80,4 @@ end
77
80
 
78
81
 
79
82
  task 'stage:prepare'=>'spec'
80
- task 'stage:prepare'=>RUBY_PLATFORM =~ /java/ ? 'spec:ruby' : 'spec:jruby'
81
- # TODO: Add Rcov when we get it working again.
83
+ task 'stage:prepare'=>RUBY_PLATFORM =~ /java/ ? 'spec:ruby' : 'spec:jruby' # Test the *other* platform
@@ -12,17 +12,32 @@
12
12
  # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
13
  # License for the specific language governing permissions and limitations under
14
14
  # the License.
15
- # True if running on the Windows operating sytem. Different from Gem.win_platform?
16
- # which returns true if running on the Windows platform of MRI, false when using JRuby.
17
15
 
18
16
 
19
17
  require 'rubygems/source_info_cache'
20
18
  require 'stringio' # for Gem::RemoteFetcher
19
+ require 'jruby' if RUBY_PLATFORM[/java/]
21
20
 
21
+ # True if running on the Windows operating sytem. Different from Gem.win_platform?
22
+ # which returns true if running on the Windows platform of MRI, false when using JRuby.
22
23
  def windows?
23
24
  Config::CONFIG['host_os'] =~ /windows|cygwin|bccwin|cygwin|djgpp|mingw|mswin|wince/i
24
25
  end
25
26
 
27
+ def set_java_home
28
+ if !ENV['JAVA_HOME'] && RUBY_PLATFORM[/java/]
29
+ ENV['JAVA_HOME'] = java.lang.System.getProperty('java.home')
30
+ end
31
+ fail "Please set JAVA_HOME first #{'(no need to run as sudo)' if ENV['USER'] == 'root'}" unless ENV['JAVA_HOME']
32
+ end
33
+
34
+ def set_gem_home
35
+ ENV['GEM_HOME'] ||= Gem.path.find { |f| File.writable?(f) }
36
+ end
37
+
38
+ def sudo_needed?
39
+ !( windows? || ENV['GEM_HOME'] )
40
+ end
26
41
 
27
42
  # Finds and returns path to executable. Consults PATH environment variable.
28
43
  # Returns nil if executable not found.
@@ -35,25 +50,35 @@ def which(name)
35
50
  FileList[path].existing.first
36
51
  end
37
52
 
53
+ # Execute a GemRunner command
54
+ def gem_run(*args)
55
+ rb_bin = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
56
+ args.unshift rb_bin, '-S', 'gem'
57
+ args.unshift 'sudo', 'env', 'JAVA_HOME=' + ENV['JAVA_HOME'] if sudo_needed?
58
+ sh *args.map{ |a| a.inspect }.join(' ')
59
+ end
38
60
 
39
61
  def install_gem(name, ver_requirement = ['> 0'])
40
62
  dep = Gem::Dependency.new(name, ver_requirement)
41
- rb_bin = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
63
+ @load_cache = true
42
64
  if Gem::SourceIndex.from_installed_gems.search(dep).empty?
43
- spec = Gem::SourceInfoCache.search(dep, true, true).last
65
+ spec = Gem::SourceInfoCache.search(dep, true, @load_cache).last
44
66
  fail "#{dep} not found in local or remote repository!" unless spec
45
67
  puts "Installing #{spec.full_name} ..."
46
- args = [rb_bin, '-S', 'gem', 'install', spec.name, '-v', spec.version.to_s]
47
- args.unshift('sudo', 'env', 'JAVA_HOME=' + ENV['JAVA_HOME']) unless windows?
48
- args = args.map{|a| a.inspect}.join(' ') if windows?
49
- sh *args
68
+ args = ['install']
69
+ args.push '--install-dir', ENV['GEM_HOME'] if ENV['GEM_HOME']
70
+ args.push spec.name, '-v', spec.version.to_s
71
+ gem_run *args
72
+ @load_cache = false # Just update the Gem cache once
50
73
  end
51
74
  end
52
75
 
53
76
  # Setup environment for running this Rakefile (RSpec, Docter, etc).
54
- desc "If you're building from sources, run this task one to setup the necessary dependencies."
77
+ desc "If you're building from sources, run this task first to setup the necessary dependencies."
55
78
  missing = spec.dependencies.select { |dep| Gem::SourceIndex.from_installed_gems.search(dep).empty? }
56
79
  task 'setup' do
80
+ set_java_home
81
+ set_gem_home
57
82
  missing.each do |dep|
58
83
  install_gem dep.name, dep.version_requirements
59
84
  end
@@ -39,7 +39,10 @@ namespace 'stage' do
39
39
  sh 'rsync', '--progress', '--recursive', 'staged/', args.staging
40
40
  puts 'Done'
41
41
  end
42
+
43
+ # Put anything that happens post staging here, e.g. release vote email template.
44
+ task 'wrapup'
42
45
  end
43
46
 
44
47
  desc 'Stage files for the release, upload them to staging server'
45
- task 'stage'=>['stage:check', 'stage:prepare', 'stage:upload']
48
+ task 'stage'=>['stage:check', 'stage:prepare', 'stage:upload', 'stage:wrapup']
@@ -0,0 +1,77 @@
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 File.join(File.dirname(__FILE__), 'test_coverage_spec')
18
+ Sandbox.require_addon 'buildr/cobertura'
19
+
20
+ Buildr::Cobertura::requires
21
+
22
+
23
+ describe Buildr::Cobertura do
24
+ before do
25
+ # Reloading the addon because the sandbox removes all its actions
26
+ load File.expand_path('../addon/buildr/cobertura.rb')
27
+ @tool_module = Buildr::Cobertura
28
+ end
29
+
30
+ it_should_behave_like 'test coverage tool'
31
+
32
+ describe 'project-specific' do
33
+
34
+ describe 'data file' do
35
+ it 'should have a default value' do
36
+ define('foo').cobertura.data_file.should point_to_path('reports/cobertura.ser')
37
+ end
38
+
39
+ it 'should be overridable' do
40
+ define('foo') { cobertura.data_file = path_to('target/data.cobertura') }
41
+ project('foo').cobertura.data_file.should point_to_path('target/data.cobertura')
42
+ end
43
+
44
+ it 'should be created during instrumentation' do
45
+ write 'src/main/java/Foo.java', 'public class Foo {}'
46
+ define('foo')
47
+ task('foo:cobertura:instrument').invoke
48
+ file(project('foo').cobertura.data_file).should exist
49
+ end
50
+ end
51
+
52
+ describe 'instrumentation' do
53
+ before do
54
+ ['Foo', 'Bar'].each { |cls| write File.join('src/main/java', "#{cls}.java"), "public class #{cls} {}" }
55
+ end
56
+
57
+ it 'should instrument only included classes' do
58
+ define('foo') { cobertura.include 'Foo' }
59
+ task("foo:cobertura:instrument").invoke
60
+ Dir.chdir('target/instrumented/classes') { Dir.glob('*').sort.should == ['Foo.class'] }
61
+ end
62
+
63
+ it 'should not instrument excluded classes' do
64
+ define('foo') { cobertura.exclude 'Foo' }
65
+ task("foo:cobertura:instrument").invoke
66
+ Dir.chdir('target/instrumented/classes') { Dir.glob('*').sort.should == ['Bar.class'] }
67
+ end
68
+
69
+ it 'should instrument classes that are included but not excluded' do
70
+ write 'src/main/java/Baz.java', 'public class Baz {}'
71
+ define('foo') { cobertura.include('Ba').exclude('ar') }
72
+ task("foo:cobertura:instrument").invoke
73
+ Dir.chdir('target/instrumented/classes') { Dir.glob('*').sort.should == ['Baz.class'] }
74
+ end
75
+ end
76
+ end
77
+ end