buildr 1.3.1.1-java → 1.3.2-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/CHANGELOG +26 -0
  2. data/NOTICE +3 -5
  3. data/README +1 -0
  4. data/Rakefile +4 -3
  5. data/addon/buildr/nailgun.rb +3 -2
  6. data/addon/buildr/xmlbeans.rb +1 -1
  7. data/buildr.gemspec +7 -7
  8. data/doc/css/syntax.css +40 -31
  9. data/doc/pages/building.textile +0 -1
  10. data/doc/pages/contributing.textile +21 -1
  11. data/doc/pages/download.textile +18 -5
  12. data/doc/pages/getting_started.textile +23 -12
  13. data/doc/pages/index.textile +1 -1
  14. data/doc/pages/packaging.textile +10 -7
  15. data/doc/pages/projects.textile +3 -3
  16. data/doc/pages/whats_new.textile +19 -0
  17. data/doc/scripts/install-jruby.sh +1 -1
  18. data/doc/scripts/install-linux.sh +4 -4
  19. data/lib/buildr.rb +1 -9
  20. data/lib/buildr/core/application.rb +11 -0
  21. data/lib/buildr/core/application_cli.rb +6 -1
  22. data/lib/buildr/core/build.rb +1 -1
  23. data/lib/buildr/core/compile.rb +6 -6
  24. data/lib/buildr/core/project.rb +1 -0
  25. data/lib/buildr/core/test.rb +3 -3
  26. data/lib/buildr/core/transports.rb +4 -2
  27. data/lib/buildr/core/util.rb +2 -0
  28. data/lib/buildr/ide/idea7x.rb +13 -12
  29. data/lib/buildr/java/compilers.rb +2 -4
  30. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  31. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +4 -1
  32. data/lib/buildr/java/test_frameworks.rb +162 -3
  33. data/rakelib/apache.rake +14 -0
  34. data/rakelib/package.rake +28 -0
  35. data/rakelib/setup.rake +3 -2
  36. data/spec/compile_spec.rb +9 -8
  37. data/spec/java_test_frameworks_spec.rb +19 -0
  38. data/spec/project_spec.rb +12 -0
  39. data/spec/sandbox.rb +4 -0
  40. data/spec/scala_compilers_spec.rb +1 -12
  41. data/spec/scala_test_frameworks_spec.rb +216 -0
  42. data/spec/test_spec.rb +20 -4
  43. data/spec/transport_spec.rb +30 -14
  44. data/spec/version_requirement_spec.rb +5 -1
  45. metadata +23 -9
@@ -21,6 +21,20 @@ require 'sha1'
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'=>'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 ... '
@@ -42,3 +42,31 @@ task 'uninstall' do |task|
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
+ # Find if anything has a more recent dependency. These are not errors, just reports.
50
+ for dep in spec.dependencies
51
+ current = Gem::SourceInfoCache.search(dep, true, true).last
52
+ latest = Gem::SourceInfoCache.search(Gem::Dependency.new(dep.name, '>0'), true, true).last
53
+ puts "A new version of #{dep.name} is available, #{latest.version} replaces #{current.version}" if latest.version > current.version
54
+ end
55
+
56
+ # Returns orderd list of transitive dependencies for the given dependency.
57
+ transitive = lambda { |depend|
58
+ dep_spec = Gem::SourceIndex.from_installed_gems.search(depend).last
59
+ dep_spec.dependencies.map { |trans| transitive[trans].push(trans) }.flatten.uniq }
60
+ # For each dependency, make sure *all* its transitive dependencies are listed
61
+ # as a Buildr dependency, and order is preserved.
62
+ spec.dependencies.each_with_index do |dep, index|
63
+ puts "checking #{dep.name}"
64
+ for trans in transitive[dep]
65
+ matching = spec.dependencies.find { |existing| trans =~ existing }
66
+ fail "#{trans} required by #{dep} and missing from spec" unless matching
67
+ fail "#{trans} must come before #{dep} in dependency list" unless spec.dependencies.index(matching) < index
68
+ end
69
+ end
70
+ end
71
+
72
+ task 'stage:check'=>'dependency'
@@ -36,15 +36,16 @@ def which(name)
36
36
  end
37
37
 
38
38
 
39
- def install_gem(name, ver_requirement = nil)
39
+ def install_gem(name, ver_requirement = ['> 0'])
40
40
  dep = Gem::Dependency.new(name, ver_requirement)
41
41
  rb_bin = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
42
42
  if Gem::SourceIndex.from_installed_gems.search(dep).empty?
43
43
  spec = Gem::SourceInfoCache.search(dep, true, true).last
44
44
  fail "#{dep} not found in local or remote repository!" unless spec
45
- puts "Installing #{spec} ..."
45
+ puts "Installing #{spec.full_name} ..."
46
46
  args = [rb_bin, '-S', 'gem', 'install', spec.name, '-v', spec.version.to_s]
47
47
  args.unshift('sudo', 'env', 'JAVA_HOME=' + ENV['JAVA_HOME']) unless windows?
48
+ args = args.map{|a| a.inspect}.join(' ') if windows?
48
49
  sh *args
49
50
  end
50
51
  end
@@ -23,19 +23,18 @@ module CompilerHelper
23
23
  end
24
24
 
25
25
  def sources
26
- @sources ||= ['Test1.java', 'Test2.java'].map { |f| File.join('src/java', f) }.
26
+ @sources ||= ['Test1.java', 'Test2.java'].map { |f| File.join('src/main/java', f) }.
27
27
  each { |src| write src, "class #{src.pathmap('%n')} {}" }
28
28
  end
29
29
 
30
30
  def jars
31
31
  @jars ||= begin
32
- write 'src/main/java/Dependency.java', 'class Dependency { }'
33
- define 'jars', :version=>'1.0' do
34
- compile.into('dependency')
32
+ write 'jars/src/main/java/Dependency.java', 'class Dependency { }'
33
+ define 'jars', :version=>'1.0', :base_dir => 'jars' do
35
34
  package(:jar, :id=>'jar1')
36
35
  package(:jar, :id=>'jar2')
37
36
  end
38
- project('jars').packages.each(&:invoke).map(&:to_s)
37
+ project('jars').packages.map(&:to_s)
39
38
  end
40
39
  end
41
40
  end
@@ -188,7 +187,7 @@ describe Buildr::CompileTask, '#dependencies' do
188
187
  end
189
188
 
190
189
  it 'should allow artifacts' do
191
- artifact('group:id:jar:1.0') { |task| mkpath File.dirname(task.to_s) ; cp jars.first.to_s, task.to_s }
190
+ artifact('group:id:jar:1.0') { |task| mkpath File.dirname(task.to_s) ; cp jars.first.to_s, task.to_s }.enhance jars
192
191
  compile_task.from(sources).with('group:id:jar:1.0').into('classes').invoke
193
192
  end
194
193
 
@@ -325,6 +324,7 @@ describe Buildr::CompileTask, '#invoke' do
325
324
  end
326
325
 
327
326
  it 'should force compilation if dependencies newer than compiled' do
327
+ jars; project('jars').task("package").invoke
328
328
  # On my machine the times end up the same, so need to push dependencies in the past.
329
329
  time = Time.now
330
330
  sources.map { |src| src.pathmap("#{compile_task.target}/%n.class") }.
@@ -334,10 +334,11 @@ describe Buildr::CompileTask, '#invoke' do
334
334
  end
335
335
 
336
336
  it 'should not force compilation if dependencies older than compiled' do
337
+ jars; project('jars').task("package").invoke
337
338
  time = Time.now
338
- sources.map { |src| src.pathmap("#{compile_task.target}/%n.class") }.
339
+ jars.each { |jar| File.utime(time - 1 , time - 1, jar) }
340
+ sources.map { |src| File.utime(time, time, src); src.pathmap("#{compile_task.target}/%n.class") }.
339
341
  each { |kls| write kls ; File.utime(time, time, kls) }
340
- jars.each { |jar| File.utime(time - 1, time - 1, jar) }
341
342
  lambda { compile_task.from(sources).with(jars).invoke }.should_not run_task('foo:compile')
342
343
  end
343
344
 
@@ -121,6 +121,25 @@ describe Buildr::JUnit do
121
121
  project('foo').test.tests.should eql(['InnerClassTest'])
122
122
  end
123
123
 
124
+ it 'should ignore abstract classes' do
125
+ write 'src/test/java/AbstractClassTest.java', <<-JAVA
126
+ public abstract class AbstractClassTest extends junit.framework.TestCase {
127
+ public void testNothing() { }
128
+ }
129
+ JAVA
130
+ define('foo').test.invoke
131
+ project('foo').test.tests.should be_empty
132
+ end
133
+
134
+ it 'should ignore classes with no tests in them' do
135
+ write 'src/test/java/NoTests.java', <<-JAVA
136
+ public class NoTests {
137
+ }
138
+ JAVA
139
+ define('foo').test.invoke
140
+ project('foo').test.tests.should be_empty
141
+ end
142
+
124
143
  it 'should pass when JUnit test case passes' do
125
144
  write 'src/test/java/PassingTest.java', <<-JAVA
126
145
  public class PassingTest extends junit.framework.TestCase {
@@ -194,6 +194,18 @@ describe Layout do
194
194
  @layout[:foo, :bar] = 'none'
195
195
  @layout.expand(:foo, :bar).should eql('none')
196
196
  end
197
+
198
+ it 'should map strings to path' do
199
+ @layout[:foo, "bar"] = 'none'
200
+ @layout.expand(:foo, :bar).should eql('none')
201
+ @layout.expand(:foo, 'bar').should eql('none')
202
+ end
203
+
204
+ it 'should ignore nil elements' do
205
+ @layout[:foo, :bar] = 'none'
206
+ @layout.expand(:foo, nil, :bar).should eql('none')
207
+ @layout.expand(nil, :foo).should eql('foo')
208
+ end
197
209
 
198
210
  it 'should return nil if path not mapped' do
199
211
  @layout[:foo].should be_nil
@@ -19,8 +19,12 @@
19
19
  # repository and cache these across test cases.
20
20
  Buildr.application.instance_eval { @rakefile = File.expand_path('buildfile') }
21
21
  repositories.remote << 'http://repo1.maven.org/maven2'
22
+ repositories.remote << 'http://scala-tools.org/repo-releases'
23
+
22
24
  require 'buildr/java/groovyc'
23
25
  Java.load # Anything added to the classpath.
26
+ task('buildr:scala:download').invoke
27
+ Buildr::ScalaTest::ENABLED = true
24
28
  artifacts(TestFramework.frameworks.map(&:dependencies).flatten).each { |a| file(a).invoke }
25
29
 
26
30
  ENV['HOME'] = File.expand_path('tmp/home')
@@ -177,21 +177,11 @@ describe 'scalac compiler options' do
177
177
  scalac_args.should_not include('-optimise')
178
178
  end
179
179
 
180
- it 'should not set source option by default' do
181
- compile_task.options.source.should be_nil
182
- scalac_args.should_not include('-source')
183
- end
184
-
185
180
  it 'should not set target option by default' do
186
181
  compile_task.options.target.should be_nil
187
182
  scalac_args.should_not include('-target')
188
183
  end
189
184
 
190
- it 'should use -source nn argument if source option set' do
191
- compile_task.using(:source=>'1.5')
192
- scalac_args.should include('-source', '1.5')
193
- end
194
-
195
185
  it 'should use -target:xxx argument if target option set' do
196
186
  compile_task.using(:target=>'1.5')
197
187
  scalac_args.should include('-target:jvm-1.5')
@@ -219,13 +209,12 @@ describe 'scalac compiler options' do
219
209
 
220
210
  it 'should inherit options from parent' do
221
211
  define 'foo' do
222
- compile.using(:warnings=>true, :debug=>true, :deprecation=>true, :source=>'1.5', :target=>'1.4')
212
+ compile.using(:warnings=>true, :debug=>true, :deprecation=>true, :target=>'1.4')
223
213
  define 'bar' do
224
214
  compile.using(:scalac)
225
215
  compile.options.warnings.should be_true
226
216
  compile.options.debug.should be_true
227
217
  compile.options.deprecation.should be_true
228
- compile.options.source.should eql('1.5')
229
218
  compile.options.target.should eql('1.4')
230
219
  end
231
220
  end
@@ -0,0 +1,216 @@
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__), 'spec_helpers')
18
+
19
+
20
+ # TODO's
21
+ # -test w/ Specs
22
+ # -test w/ ScalaCheck
23
+ # -failing test
24
+ # -test passing System props
25
+ # -test passing ENV variables
26
+ # -test exclude group
27
+ # -test include Suite's
28
+ # -test exclude Suite's
29
+
30
+
31
+ describe Buildr::ScalaTest do
32
+ it 'should be the default test framework when test cases are in Scala' do
33
+ write 'src/test/scala/com/example/MySuite.scala', <<-SCALA
34
+ package com.example
35
+ import org.scalatest.FunSuite
36
+ class MySuite extends FunSuite {
37
+ test("addition") {
38
+ val sum = 1 + 1
39
+ assert(sum === 2)
40
+ }
41
+ }
42
+ SCALA
43
+ define 'foo'
44
+ project('foo').test.framework.should eql(:scalatest)
45
+ end
46
+
47
+ it 'should be picked if the test language is Scala' do
48
+ define 'foo' do
49
+ test.compile.using(:scalac)
50
+ test.framework.should eql(:scalatest)
51
+ end
52
+ end
53
+
54
+ it 'should include Scalatest dependencies' do
55
+ define('foo') { test.using(:scalatest) }
56
+ project('foo').test.compile.dependencies.should include(*artifacts(ScalaTest::REQUIRES))
57
+ project('foo').test.dependencies.should include(*artifacts(ScalaTest::REQUIRES))
58
+ end
59
+
60
+ it 'should include JMock dependencies' do
61
+ define('foo') { test.using(:scalatest) }
62
+ project('foo').test.compile.dependencies.should include(*artifacts(JMock::REQUIRES))
63
+ project('foo').test.dependencies.should include(*artifacts(JMock::REQUIRES))
64
+ end
65
+
66
+ it 'should include Specs dependencies' do
67
+ define('foo') { test.using(:scalatest) }
68
+ project('foo').test.compile.dependencies.should include(*artifacts(ScalaSpecs::REQUIRES))
69
+ project('foo').test.dependencies.should include(*artifacts(ScalaSpecs::REQUIRES))
70
+ end
71
+
72
+ it 'should include ScalaCheck dependencies' do
73
+ define('foo') { test.using(:scalatest) }
74
+ project('foo').test.compile.dependencies.should include(*artifacts(ScalaCheck::REQUIRES))
75
+ project('foo').test.dependencies.should include(*artifacts(ScalaCheck::REQUIRES))
76
+ end
77
+
78
+ it 'should include public classes extending org.scalatest.FunSuite' do
79
+ write 'src/test/scala/com/example/MySuite.scala', <<-SCALA
80
+ package com.example
81
+ import org.scalatest.FunSuite
82
+ class MySuite extends FunSuite {
83
+ test("addition") {
84
+ val sum = 1 + 1
85
+ assert(sum === 2)
86
+ }
87
+ }
88
+ SCALA
89
+ define('foo').test.invoke
90
+ project('foo').test.tests.should include('com.example.MySuite')
91
+ end
92
+
93
+ it 'should ignore classes not extending org.scalatest.FunSuite' do
94
+ write 'src/test/scala/com/example/NotASuite.scala', <<-SCALA
95
+ package com.example
96
+ class Another {
97
+ }
98
+ SCALA
99
+ define('foo').test.invoke
100
+ project('foo').test.tests.should be_empty
101
+ end
102
+
103
+ it 'should ignore inner classes' do
104
+ write 'src/test/scala/com/example/InnerClassTest.scala', <<-SCALA
105
+ package com.example
106
+ import org.scalatest.FunSuite
107
+ class InnerClassTest extends FunSuite {
108
+ test("addition") {
109
+ val sum = 1 + 1
110
+ assert(sum === 2)
111
+ }
112
+
113
+ class InnerSuite extends FunSuite {
114
+ test("addition") {
115
+ val sum = 1 + 1
116
+ assert(sum === 2)
117
+ }
118
+ }
119
+ }
120
+ SCALA
121
+ define('foo').test.invoke
122
+ project('foo').test.tests.should eql(['com.example.InnerClassTest'])
123
+ end
124
+
125
+ it 'should pass when ScalaTest test case passes' do
126
+ write 'src/test/scala/PassingSuite.scala', <<-SCALA
127
+ class PassingSuite extends org.scalatest.FunSuite {
128
+ test("addition") {
129
+ val sum = 1 + 1
130
+ assert(sum === 2)
131
+ }
132
+ }
133
+ SCALA
134
+ lambda { define('foo').test.invoke }.should_not raise_error
135
+ end
136
+
137
+ it 'should fail when ScalaTest test case fails' do
138
+ write 'src/test/scala/FailingSuite.scala', <<-SCALA
139
+ class FailingSuite extends org.scalatest.FunSuite {
140
+ test("failing") {
141
+ assert(false)
142
+ }
143
+ }
144
+ SCALA
145
+ lambda { define('foo').test.invoke }.should raise_error(RuntimeError, /Tests failed/) rescue nil
146
+ end
147
+
148
+ it 'should report failed test names' do
149
+ write 'src/test/scala/FailingSuite.scala', <<-SCALA
150
+ class FailingSuite extends org.scalatest.FunSuite {
151
+ test("failing") {
152
+ assert(false)
153
+ }
154
+ }
155
+ SCALA
156
+ define('foo').test.invoke rescue
157
+ project('foo').test.failed_tests.should include('FailingSuite')
158
+ end
159
+
160
+ it 'should report to reports/scalatest/TEST-TestSuiteName.txt' do
161
+ write 'src/test/scala/PassingSuite.scala', <<-SCALA
162
+ class PassingSuite extends org.scalatest.FunSuite {
163
+ test("passing") {
164
+ assert(true)
165
+ }
166
+ }
167
+ SCALA
168
+ define 'foo' do
169
+ test.report_to.should be(file('reports/scalatest'))
170
+ end
171
+ project('foo').test.invoke
172
+ project('foo').file('reports/scalatest/TEST-PassingSuite.txt').should exist
173
+ end
174
+
175
+ it 'should pass properties to Suite' do
176
+ write 'src/test/scala/PropertyTestSuite.scala', <<-SCALA
177
+ import org.scalatest._
178
+ class PropertyTestSuite extends FunSuite {
179
+ var properties = Map[String, Any]()
180
+ test("testProperty") {
181
+ assert(properties("name") === "value")
182
+ }
183
+
184
+ protected override def runTests(testName: Option[String], reporter: Reporter, stopper: Stopper,
185
+ includes: Set[String], excludes: Set[String], properties: Map[String, Any]) {
186
+ this.properties = properties;
187
+ super.runTests(testName, reporter, stopper, includes, excludes, properties)
188
+ }
189
+ }
190
+ SCALA
191
+ define('foo').test.using :properties=>{ 'name'=>'value' }
192
+ project('foo').test.invoke
193
+ end
194
+
195
+ it 'should set current directory' do
196
+ mkpath 'baz'
197
+ expected = File.expand_path('baz')
198
+ expected.gsub!('/', '\\') if expected =~ /^[A-Z]:/ # Java returns back slashed paths for windows
199
+ write 'baz/src/test/scala/CurrentDirectoryTestSuite.scala', <<-SCALA
200
+ class CurrentDirectoryTestSuite extends org.scalatest.FunSuite {
201
+ test("testCurrentDirectory") {
202
+ assert("value" === System.getenv("NAME"))
203
+ assert(#{expected.inspect} === new java.io.File(".").getCanonicalPath())
204
+ }
205
+ }
206
+ SCALA
207
+ define 'bar' do
208
+ define 'baz' do
209
+ test.include 'CurrentDirectoryTest'
210
+ end
211
+ end
212
+ project('bar:baz').test.invoke
213
+ end
214
+
215
+ end
216
+
@@ -189,7 +189,7 @@ describe Buildr::TestTask do
189
189
  end
190
190
 
191
191
  it 'should include the main resources target in its dependencies' do
192
- write 'src/main/resources/test'
192
+ write 'src/main/resources/config.xml'
193
193
  define('foo').test.dependencies.should include(project('foo').resources.target)
194
194
  end
195
195
 
@@ -203,11 +203,27 @@ describe Buildr::TestTask do
203
203
  project('foo').test.dependencies.should include(project('foo').test.compile.target)
204
204
  end
205
205
 
206
+ it 'should add test compile target ahead of regular compile target' do
207
+ write 'src/main/java/Code.java'
208
+ write 'src/test/java/Test.java'
209
+ define 'foo'
210
+ depends = project('foo').test.dependencies
211
+ depends.index(project('foo').test.compile.target).should < depends.index(project('foo').compile.target)
212
+ end
213
+
206
214
  it 'should include the test resources target in its dependencies' do
207
- write 'src/test/resources/test'
215
+ write 'src/test/resources/config.xml'
208
216
  define('foo').test.dependencies.should include(project('foo').test.resources.target)
209
217
  end
210
218
 
219
+ it 'should add test resource target ahead of regular resource target' do
220
+ write 'src/main/resources/config.xml'
221
+ write 'src/test/resources/config.xml'
222
+ define 'foo'
223
+ depends = project('foo').test.dependencies
224
+ depends.index(project('foo').test.resources.target).should < depends.index(project('foo').resources.target)
225
+ end
226
+
211
227
  it 'should clean after itself (test files)' do
212
228
  define('foo') { test.compile.using(:javac) }
213
229
  mkpath project('foo').test.compile.target.to_s
@@ -467,9 +483,9 @@ describe Buildr::Project, 'test:resources' do
467
483
  end
468
484
 
469
485
  it 'should copy to the resources target directory' do
470
- write 'src/test/resources/foo', 'Foo'
486
+ write 'src/test/resources/config.xml', '</xml>'
471
487
  define('foo', :target=>'targeted').test.invoke
472
- file('targeted/test/resources/foo').should contain('Foo')
488
+ file('targeted/test/resources/config.xml').should contain('</xml>')
473
489
  end
474
490
 
475
491
  it 'should create target directory even if no files to copy' do