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
@@ -14,31 +14,42 @@
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
+ desc 'Upload snapshot packages over to people.apache.org'
25
+ task 'snapshot'=>['spec', 'package'] do
26
+ rm_rf 'snapshot' # Always start with empty directory
27
+ puts "Copying existing gems from Apache"
28
+ sh 'rsync', '--progress', '--recursive', 'people.apache.org:public_html/buildr/snapshot', './'
29
+ puts "Copying new gems over"
30
+ cp FileList['pkg/{*.gem,*.tgz,*.zip}'], 'snapshot/gems'
31
+ puts "Generating gem index ..."
32
+ sh 'gem', 'generate_index', '--directory', 'snapshot'
33
+ puts "Copying gem and index back to Apache"
34
+ sh 'rsync', '--progress', '--recursive', 'snapshot', 'people.apache.org:public_html/buildr/'
35
+ end
36
+
37
+
24
38
  desc 'Check that source files contain the Apache license'
25
39
  task 'license' do |task|
26
40
  print 'Checking that files contain the Apache license ... '
27
41
  required = task.prerequisites.select { |fn| File.file?(fn) }
28
42
  missing = required.reject { |fn|
29
- comments = File.read(fn).scan(/(\/\*(.*?)\*\/)|^#\s+(.*?)$|<!--(.*?)-->/m).
43
+ comments = File.read(fn).scan(/(\/\*(.*?)\*\/)|^#\s+(.*?)$|^-#\s+(.*?)$|<!--(.*?)-->/m).
30
44
  map { |match| match.compact }.flatten.join("\n")
31
45
  comments =~ /Licensed to the Apache Software Foundation/ && comments =~ /http:\/\/www.apache.org\/licenses\/LICENSE-2.0/
32
46
  }
33
47
  fail "#{missing.join(', ')} missing Apache License, please add it before making a release!" unless missing.empty?
34
48
  puts 'OK'
35
49
  end
36
- task('license').prerequisites.exclude('.class', '.png', '.jar', '.tif', '.textile', '.haml',
37
- 'README', 'LICENSE', 'CHANGELOG', 'DISCLAIMER', 'NOTICE', 'KEYS', 'spec/spec.opts')
38
-
39
- task 'check' do
40
- ENV['GPG_USER'] or fail 'Please set GPG_USER (--local-user) environment variable so we know which key to use.'
41
- end
50
+
51
+ # Staging checks specific for Apache.
52
+ task 'check'=>'license'
42
53
 
43
54
 
44
55
  file 'staged/distro'=>'package' do
@@ -49,15 +60,16 @@ namespace 'apache' do
49
60
  end
50
61
  end
51
62
 
52
- task 'sign'=>['KEYS', 'staged/distro'] do
53
- gpg_user = ENV['GPG_USER'] or fail 'Please set GPG_USER (--local-user) environment variable so we know which key to use.'
63
+ task 'sign'=>['etc/KEYS', 'staged/distro'] do |task, args|
64
+ gpg_user = args.gpg_user or fail "Please run with gpg_user=<argument for gpg --local-user>"
65
+ puts "Signing packages in staged/distro as user #{gpg_user}"
54
66
  FileList['staged/distro/*.{gem,zip,tgz}'].each do |pkg|
55
67
  bytes = File.open(pkg, 'rb') { |file| file.read }
56
68
  File.open(pkg + '.md5', 'w') { |file| file.write MD5.hexdigest(bytes) << ' ' << File.basename(pkg) }
57
69
  File.open(pkg + '.sha1', 'w') { |file| file.write SHA1.hexdigest(bytes) << ' ' << File.basename(pkg) }
58
70
  sh 'gpg', '--local-user', gpg_user, '--armor', '--output', pkg + '.asc', '--detach-sig', pkg, :verbose=>true
59
71
  end
60
- cp 'KEYS', 'staged/distro'
72
+ cp 'etc/KEYS', 'staged/distro'
61
73
  end
62
74
 
63
75
  # Publish prerequisites to distro server.
@@ -96,34 +108,6 @@ p>. ("Release signing keys":#{url}/KEYS)
96
108
  puts 'Done'
97
109
  end
98
110
 
99
- =begin
100
- task 'distro-links'=>['staged/site', 'apache:sign'] do |task, args|
101
- rows = FileList['staged/distro/*.{gem,tgz,zip}'].map { |pkg|
102
- name, md5 = File.basename(pkg), File.read("#{pkg}.md5").split.first
103
- <<-HTML
104
- <tr>
105
- <td><a href="#{url}/#{name}">#{name}</a></td>
106
- <td><a href="#{url}/#{name}.md5">#{md5}</a></td>
107
- <td><a href="#{url}/#{name}.asc">Sig</a></td>
108
- </tr>
109
- HTML
110
- }
111
- html = <<-HTML
112
- <h3>#{spec.name} #{spec.version}#{args.incubating && "-incubating"} (#{Time.now.strftime('%Y-%m-%d')})</h3>
113
- <table>
114
- <thead><th>Package</th><th>MD5 Checksum</th><th>PGP</th></thead>
115
- #{rows.join("\n")}
116
- </table>
117
- <p style="text-align:right"> (<a href="#{url}/KEYS">Release signing keys</a>)</p>
118
- HTML
119
- file_name = 'staged/site/download.html'
120
- modified = File.read(file_name).sub(/<h2.*binaries.*source.*<\/h2>.*/i) { |header| "#{header}\n#{html}\n" }
121
- File.open file_name, 'w' do |file|
122
- file.write modified
123
- end
124
- end
125
- =end
126
-
127
111
  file 'staged/site'=>['distro-links', 'staged', 'site'] do
128
112
  rm_rf 'staged/site'
129
113
  cp_r 'site', 'staged'
@@ -141,11 +125,17 @@ p>. ("Release signing keys":#{url}/KEYS)
141
125
  end
142
126
 
143
127
 
144
- task 'stage:check'=>['apache:license', 'apache:check']
128
+ task 'stage:check'=>['apache:check']
145
129
  task 'stage:prepare'=>['staged/distro', 'staged/site'] do |task|
146
130
  # Since this requires input (passphrase), do it at the very end.
147
131
  task.enhance do
148
132
  task('apache:sign').invoke
149
133
  end
150
134
  end
135
+ task 'stage' do
136
+ task('apache:snapshot').invoke
137
+ end
151
138
  task 'release:publish'=>['apache:publish:distro', 'apache:publish:site']
139
+ task 'clobber' do
140
+ rm_rf 'snapshot'
141
+ end
@@ -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,36 @@ 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
45
+
46
+
47
+ desc 'Look for new dependencies, check transitive dependencies'
48
+ task 'dependency' do
49
+ puts "Checking that all dependencies are up to date ..."
50
+ # Find if anything has a more recent dependency. These are not errors, just reports.
51
+ for dep in spec.dependencies
52
+ current = Gem::SourceInfoCache.search(dep, true, true).last
53
+ latest = Gem::SourceInfoCache.search(Gem::Dependency.new(dep.name, '>0'), true, true).last
54
+ puts "A new version of #{dep.name} is available, #{latest.version} replaces #{current.version}" if latest.version > current.version
55
+ end
56
+
57
+ # Returns orderd list of transitive dependencies for the given dependency.
58
+ transitive = lambda { |depend|
59
+ dep_spec = Gem::SourceIndex.from_installed_gems.search(depend).last
60
+ dep_spec.dependencies.map { |trans| transitive[trans].push(trans) }.flatten.uniq }
61
+ # For each dependency, make sure *all* its transitive dependencies are listed
62
+ # as a Buildr dependency, and order is preserved.
63
+ spec.dependencies.each_with_index do |dep, index|
64
+ puts "checking #{dep.name}"
65
+ for trans in transitive[dep]
66
+ matching = spec.dependencies.find { |existing| trans =~ existing }
67
+ fail "#{trans} required by #{dep} and missing from spec" unless matching
68
+ fail "#{trans} must come before #{dep} in dependency list" unless spec.dependencies.index(matching) < index
69
+ end
70
+ end
71
+ end
72
+
73
+ task 'stage:check'=>'dependency'
@@ -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 --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
@@ -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
@@ -41,6 +41,7 @@ namespace 'rubyforge' do
41
41
  files = FileList['published/rubyforge/*.{gem,tgz,zip}'].exclude(changes).existing
42
42
  print "Uploading #{spec.version} to RubyForge ... "
43
43
  rubyforge = RubyForge.new
44
+ rubyforge.configure
44
45
  rubyforge.login
45
46
  rubyforge.userconfig.merge!('release_changes'=>changes, 'preformatted' => true) if changes
46
47
  rubyforge.add_release spec.rubyforge_project.downcase, spec.name.downcase, spec.version.to_s, *files
@@ -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
@@ -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
@@ -0,0 +1,120 @@
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/emma'
19
+
20
+
21
+ Buildr::Emma::requires
22
+
23
+
24
+ describe Buildr::Emma do
25
+ before do
26
+ # Reloading the addon because the sandbox removes all its actions
27
+ load File.expand_path('../addon/buildr/emma.rb')
28
+ @tool_module = Buildr::Emma
29
+ end
30
+
31
+ it_should_behave_like 'test coverage tool'
32
+
33
+ describe 'project-specific' do
34
+ describe 'metadata file' do
35
+ it 'should have a default value' do
36
+ define('foo').emma.metadata_file.should point_to_path('reports/emma/coverage.em')
37
+ end
38
+
39
+ it 'should be overridable' do
40
+ define('foo') { emma.metadata_file = path_to('target/metadata.emma') }
41
+ project('foo').emma.metadata_file.should point_to_path('target/metadata.emma')
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:emma:instrument').invoke
48
+ file(project('foo').emma.metadata_file).should exist
49
+ end
50
+ end
51
+
52
+ describe 'coverage file' do
53
+ it 'should have a default value' do
54
+ define('foo').emma.coverage_file.should point_to_path('reports/emma/coverage.ec')
55
+ end
56
+
57
+ it 'should be overridable' do
58
+ define('foo') { emma.coverage_file = path_to('target/coverage.emma') }
59
+ project('foo').emma.coverage_file.should point_to_path('target/coverage.emma')
60
+ end
61
+
62
+ it 'should be created during test' do
63
+ write 'src/main/java/Foo.java', 'public class Foo {}'
64
+ write_test :for=>'Foo', :in=>'src/test/java'
65
+ define('foo')
66
+ task('foo:test').invoke
67
+ file(project('foo').emma.coverage_file).should exist
68
+ end
69
+ end
70
+
71
+ describe 'instrumentation' do
72
+ before do
73
+ ['Foo', 'Bar'].each { |cls| write File.join('src/main/java', "#{cls}.java"), "public class #{cls} {}" }
74
+ end
75
+
76
+ it 'should instrument only included classes' do
77
+ define('foo') { emma.include 'Foo' }
78
+ task("foo:emma:instrument").invoke
79
+ Dir.chdir('target/instrumented/classes') { Dir.glob('*').sort.should == ['Foo.class'] }
80
+ end
81
+
82
+ it 'should not instrument excluded classes' do
83
+ define('foo') { emma.exclude 'Foo' }
84
+ task("foo:emma:instrument").invoke
85
+ Dir.chdir('target/instrumented/classes') { Dir.glob('*').sort.should == ['Bar.class'] }
86
+ end
87
+
88
+ it 'should instrument classes that are included but not excluded' do
89
+ write 'src/main/java/Baz.java', 'public class Baz {}'
90
+ define('foo') { emma.include('Ba*').exclude('*ar') }
91
+ task("foo:emma:instrument").invoke
92
+ Dir.chdir('target/instrumented/classes') { Dir.glob('*').sort.should == ['Baz.class'] }
93
+ end
94
+ end
95
+
96
+ describe 'reports' do
97
+ before do
98
+ write 'src/main/java/Foo.java', 'public class Foo {}'
99
+ write_test :for=>'Foo', :in=>'src/test/java'
100
+ end
101
+
102
+ describe 'in html' do
103
+ it 'should inform the user if no coverage data' do
104
+ rm 'src/test/java/FooTest.java'
105
+ define('foo')
106
+ lambda { task('foo:emma:html').invoke }.
107
+ should show_info(/No test coverage report for foo. Missing: #{project('foo').emma.coverage_file}/)
108
+ end
109
+ end
110
+
111
+ describe 'in xml' do
112
+ it 'should have an xml file' do
113
+ define('foo')
114
+ task('foo:emma:xml').invoke
115
+ file(File.join(project('foo').emma.report_dir, 'coverage.xml')).should exist
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end