buildr 1.4.25-java → 1.5.0.dev2-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +50 -0
  3. data/NOTICE +1 -1
  4. data/README.rdoc +1 -1
  5. data/addon/buildr/bnd.rb +0 -6
  6. data/addon/buildr/custom_pom.rb +6 -0
  7. data/addon/buildr/org/apache/buildr/BuildrNail$Main.class +0 -0
  8. data/addon/buildr/org/apache/buildr/BuildrNail.class +0 -0
  9. data/addon/buildr/org/apache/buildr/JettyWrapper$1.class +0 -0
  10. data/addon/buildr/org/apache/buildr/JettyWrapper$BuildrHandler.class +0 -0
  11. data/addon/buildr/org/apache/buildr/JettyWrapper.class +0 -0
  12. data/addon/buildr/wsgen.rb +27 -27
  13. data/buildr.buildfile +1 -1
  14. data/buildr.gemspec +13 -9
  15. data/doc/_config.yml +3 -1
  16. data/doc/_layouts/default.html +1 -1
  17. data/doc/artifacts.textile +42 -0
  18. data/doc/download.textile +18 -6
  19. data/doc/languages.textile +15 -1
  20. data/doc/packaging.textile +1 -1
  21. data/doc/preface.textile +1 -1
  22. data/doc/projects.textile +13 -0
  23. data/doc/releasing.textile +14 -0
  24. data/doc/settings_profiles.textile +4 -0
  25. data/lib/buildr.rb +1 -0
  26. data/lib/buildr/core/application.rb +2 -3
  27. data/lib/buildr/core/build.rb +21 -34
  28. data/lib/buildr/core/compile.rb +0 -12
  29. data/lib/buildr/core/filter.rb +7 -0
  30. data/lib/buildr/core/generate.rb +1 -0
  31. data/lib/buildr/core/project.rb +14 -4
  32. data/lib/buildr/core/test.rb +2 -4
  33. data/lib/buildr/core/transports.rb +2 -0
  34. data/lib/buildr/groovy/bdd.rb +0 -7
  35. data/lib/buildr/ide/eclipse.rb +3 -3
  36. data/lib/buildr/java/ant.rb +0 -6
  37. data/lib/buildr/java/bdd.rb +0 -7
  38. data/lib/buildr/java/commands.rb +1 -1
  39. data/lib/buildr/java/deprecated.rb +0 -60
  40. data/lib/buildr/java/ecj.rb +16 -3
  41. data/lib/buildr/java/jruby.rb +19 -1
  42. data/lib/buildr/java/packaging.rb +4 -8
  43. data/lib/buildr/java/pom.rb +17 -12
  44. data/lib/buildr/java/rjb.rb +21 -3
  45. data/lib/buildr/java/tests.rb +0 -21
  46. data/lib/buildr/packaging/archive.rb +1 -1
  47. data/lib/buildr/packaging/artifact.rb +132 -3
  48. data/lib/buildr/packaging/zip.rb +32 -29
  49. data/lib/buildr/packaging/ziptask.rb +7 -5
  50. data/lib/buildr/scala.rb +0 -1
  51. data/lib/buildr/scala/bdd.rb +28 -122
  52. data/lib/buildr/scala/compiler.rb +24 -10
  53. data/lib/buildr/scala/doc.rb +0 -1
  54. data/lib/buildr/scala/org/apache/buildr/Specs2Runner.class +0 -0
  55. data/lib/buildr/scala/org/apache/buildr/Specs2Runner.java +4 -3
  56. data/lib/buildr/scala/org/apache/buildr/ZincRunner.class +0 -0
  57. data/lib/buildr/scala/org/apache/buildr/ZincRunner.java +37 -0
  58. data/lib/buildr/scala/tests.rb +18 -26
  59. data/lib/buildr/version.rb +1 -1
  60. data/spec/addon/bnd_spec.rb +5 -5
  61. data/spec/addon/custom_pom_spec.rb +38 -32
  62. data/spec/addon/jaxb_xjc_spec.rb +0 -4
  63. data/spec/core/application_spec.rb +4 -5
  64. data/spec/core/build_spec.rb +10 -51
  65. data/spec/core/common_spec.rb +7 -0
  66. data/spec/core/compile_spec.rb +0 -6
  67. data/spec/core/console_spec.rb +1 -1
  68. data/spec/core/generate_from_eclipse_spec.rb +22 -8
  69. data/spec/core/project_spec.rb +34 -70
  70. data/spec/core/test_spec.rb +6 -9
  71. data/spec/core/transport_spec.rb +16 -7
  72. data/spec/groovy/compiler_spec.rb +2 -2
  73. data/spec/java/ant_spec.rb +0 -5
  74. data/spec/java/compiler_spec.rb +4 -4
  75. data/spec/java/ecj_spec.rb +244 -45
  76. data/spec/java/java_spec.rb +7 -9
  77. data/spec/java/packaging_spec.rb +23 -23
  78. data/spec/java/pom_spec.rb +37 -0
  79. data/spec/java/tests_spec.rb +0 -5
  80. data/spec/packaging/archive_spec.rb +1 -1
  81. data/spec/packaging/artifact_spec.rb +129 -7
  82. data/spec/packaging/packaging_spec.rb +1 -1
  83. data/spec/sandbox.rb +2 -2
  84. data/spec/scala/bdd_spec.rb +0 -101
  85. data/spec/scala/compiler_spec.rb +20 -16
  86. data/spec/scala/doc_spec.rb +0 -11
  87. data/spec/scala/tests_spec.rb +6 -15
  88. data/spec/spec_helpers.rb +1 -1
  89. data/spec/xpath_matchers.rb +2 -1
  90. metadata +30 -16
  91. data/addon/buildr/cobertura.rb +0 -21
  92. data/addon/buildr/emma.rb +0 -21
@@ -234,12 +234,6 @@ describe Buildr::CompileTask, '#dependencies' do
234
234
  compile_task.dependencies.should == project('bar').packages
235
235
  end
236
236
 
237
- it 'should be accessible as classpath up to version 1.5 since it was deprecated in version 1.3' do
238
- Buildr::VERSION.should < '1.5'
239
- lambda { compile_task.classpath = jars }.should change(compile_task, :dependencies).to(jars)
240
- lambda { compile_task.dependencies = [] }.should change(compile_task, :classpath).to([])
241
- end
242
-
243
237
  end
244
238
 
245
239
 
@@ -20,7 +20,7 @@ describe Buildr::Console do
20
20
  describe 'console_dimensions' do
21
21
 
22
22
  it 'should return a value' do
23
- Buildr::Console.console_dimensions.should_not be_nil
23
+ Buildr::Console.console_dimensions.should_not be_nil if $stdout.isatty # have to ask again as stdout may be redirected.
24
24
  end if $stdout.isatty && !ENV["TRAVIS"] && !Buildr::Util.win_os?
25
25
  end
26
26
 
@@ -116,6 +116,7 @@ describe Buildr::Generate do
116
116
  buildFile = File.join(top, 'buildfile')
117
117
  file(buildFile).should exist
118
118
  file(buildFile).should contain("GROUP = \"#{top}\"")
119
+ chdir(top)
119
120
  lambda { Buildr.application.run }.should_not raise_error
120
121
  end
121
122
 
@@ -127,17 +128,19 @@ describe Buildr::Generate do
127
128
  file(buildFile).should exist
128
129
  file(buildFile).should contain('define "single"')
129
130
  file(buildFile).should_not contain('define "myproject"')
131
+ chdir(top)
130
132
  lambda { Buildr.application.run }.should_not raise_error
131
133
  end
132
134
 
133
- it 'should honour Bundle-Version in MANIFEST.MF' do
134
- define('bundle_version')
135
- buildFile = File.join(top, 'buildfile')
136
- file(buildFile).should exist
137
- file(buildFile).should contain('define "single"')
138
- file(buildFile).should contain('define "single", :version => "1.1"')
139
- lambda { Buildr.application.run }.should_not raise_error
140
- end
135
+ it 'should honour Bundle-Version in MANIFEST.MF' do
136
+ define('bundle_version')
137
+ buildFile = File.join(top, 'buildfile')
138
+ file(buildFile).should exist
139
+ file(buildFile).should contain('define "single"')
140
+ file(buildFile).should contain('define "single", :version => "1.1"')
141
+ chdir(top)
142
+ lambda { Buildr.application.run }.should_not raise_error
143
+ end
141
144
 
142
145
  it "should pass source in build.properties to layout[:source, :main, :java] and layout[:source, :main, :scala]" do
143
146
  define('layout_source')
@@ -147,6 +150,7 @@ describe Buildr::Generate do
147
150
  file(buildFile).should contain('define "single"')
148
151
  file(buildFile).should contain('layout[:source, :main, :java]')
149
152
  file(buildFile).should contain('layout[:source, :main, :scala]')
153
+ chdir(top)
150
154
  lambda { Buildr.application.run }.should_not raise_error
151
155
  end
152
156
 
@@ -159,6 +163,7 @@ describe Buildr::Generate do
159
163
  file(buildFile).should contain('layout[:target, :main]')
160
164
  file(buildFile).should contain('layout[:target, :main, :java]')
161
165
  file(buildFile).should contain('layout[:target, :main, :scala]')
166
+ chdir(top)
162
167
  lambda { Buildr.application.run }.should_not raise_error
163
168
  end
164
169
 
@@ -168,6 +173,7 @@ describe Buildr::Generate do
168
173
  file(buildFile).should exist
169
174
  file(buildFile).should contain('define')
170
175
  file(buildFile).should contain('package(:jar)')
176
+ chdir(top)
171
177
  lambda { Buildr.application.run }.should_not raise_error
172
178
  end
173
179
 
@@ -183,6 +189,7 @@ describe Buildr::Generate do
183
189
  buildFile = File.join(top, 'buildfile')
184
190
  file(buildFile).should exist
185
191
  file(buildFile).should contain('define "singleSymbolicName"')
192
+ chdir(top)
186
193
  lambda { Buildr.application.run }.should_not raise_error
187
194
  end
188
195
  end
@@ -198,6 +205,7 @@ describe Buildr::Generate do
198
205
  buildFile = File.join(top, 'buildfile')
199
206
  file(buildFile).should exist
200
207
  file(buildFile).should contain('define "singleSymbolicName"')
208
+ chdir(top)
201
209
  lambda { Buildr.application.run }.should_not raise_error
202
210
  end
203
211
  end
@@ -218,6 +226,7 @@ describe Buildr::Generate do
218
226
  buildFile = File.join(top, 'buildfile')
219
227
  file(buildFile).should contain("GROUP = \"#{top}\"")
220
228
  file(buildFile).should contain('define "single"')
229
+ chdir(top)
221
230
  lambda { Buildr.application.run }.should_not raise_error
222
231
  end
223
232
 
@@ -227,6 +236,7 @@ describe Buildr::Generate do
227
236
  file(buildFile).should exist
228
237
  file(buildFile).should contain('define "single"')
229
238
  file(buildFile).should contain('define "single", :version => "1.1", :base_dir => "nested/single"')
239
+ chdir(top)
230
240
  lambda { Buildr.application.run }.should_not raise_error
231
241
  end
232
242
 
@@ -251,6 +261,7 @@ describe Buildr::Generate do
251
261
  file(buildFile).should exist
252
262
  file(buildFile).should contain('compile.with dependencies')
253
263
  file(buildFile).should contain('resources')
264
+ chdir(top)
254
265
  lambda { Buildr.application.run }.should_not raise_error
255
266
  end
256
267
  #dependencies << projects("first")
@@ -258,10 +269,12 @@ describe Buildr::Generate do
258
269
  it 'should honour Require-Bundle in MANIFEST.MF' do
259
270
  define('base_dir')
260
271
  buildFile = File.join(top, 'buildfile')
272
+
261
273
  file(buildFile).should exist
262
274
  file(buildFile).should contain(/define "second"/)
263
275
  file(buildFile).should contain( /dependencies << projects\("first"\)/)
264
276
  file(buildFile).should contain(/define "second".*do.*dependencies << projects\("first"\).* end/m)
277
+ chdir(top)
265
278
  lambda { Buildr.application.run }.should_not raise_error
266
279
  end
267
280
 
@@ -272,6 +285,7 @@ describe Buildr::Generate do
272
285
  file(buildFile).should exist
273
286
  # system("cat #{buildFile}") # if $VERBOSE
274
287
  file(buildFile).should contain('define "first"')
288
+ chdir(top)
275
289
  lambda { Buildr.application.run }.should_not raise_error
276
290
  end
277
291
 
@@ -83,6 +83,16 @@ describe Project do
83
83
  Buildr.define('foo') { define('bar') { project('baz:bar') } }
84
84
  lambda { project('foo') }.should raise_error(RuntimeError, /Circular dependency/)
85
85
  end
86
+
87
+ it 'should handle non-circular dependencies' do
88
+ Buildr.define "root" do
89
+ define "child" do
90
+ puts project('root')._('foo.resource')
91
+ end
92
+ end
93
+
94
+ lambda { project('root') }.should_not raise_error
95
+ end
86
96
  end
87
97
 
88
98
  describe Project, ' property' do
@@ -318,70 +328,22 @@ describe Project, '#path_to' do
318
328
  end
319
329
 
320
330
 
321
- describe Project, '#on_define' do
322
- it 'should be called when project is defined' do
323
- names = []
324
- Project.on_define { |project| names << project.name }
325
- define 'foo' ; define 'bar'
326
- names.should eql(['foo', 'bar'])
327
- end
328
-
329
- it 'should be called with project object' do
330
- Project.on_define { |project| project.name.should eql('foo') }
331
- define('foo')
332
- end
333
-
334
- it 'should be called with project object and set properties' do
335
- Project.on_define { |project| project.version.should eql('2.0') }
336
- define('foo', :version=>'2.0')
337
- end
338
-
339
- it 'should execute in namespace of project' do
340
- scopes = []
341
- Project.on_define { |project| scopes << Buildr.application.current_scope }
342
- define('foo') { define 'bar' }
343
- scopes.should eql([['foo'], ['foo', 'bar']])
344
- end
345
-
346
- it 'should be called before project block' do
347
- order = []
348
- Project.on_define { |project| order << 'on_define' }
349
- define('foo') { order << 'define' }
350
- order.should eql(['on_define', 'define'])
351
- end
352
-
353
- it 'should accept enhancement and call it after project block' do
354
- order = []
355
- Project.on_define { |project| project.enhance { order << 'enhance' } }
356
- define('foo') { order << 'define' }
357
- order.should eql(['define', 'enhance'])
358
- end
359
-
360
- it 'should accept enhancement and call it with project' do
361
- Project.on_define { |project| project.enhance { |project| project.name.should eql('foo') } }
362
- define('foo')
363
- end
364
-
365
- it 'should execute enhancement in namespace of project' do
366
- scopes = []
367
- Project.on_define { |project| project.enhance { scopes << Buildr.application.current_scope } }
368
- define('foo') { define 'bar' }
369
- scopes.should eql([['foo'], ['foo', 'bar']])
370
- end
371
-
372
- it 'should be removed in version 1.5 since it was deprecated in version 1.3' do
373
- Buildr::VERSION.should < '1.5'
374
- end
375
- end
376
-
377
-
378
331
  describe Rake::Task, ' recursive' do
379
332
  before do
380
- @order = []
381
- Project.on_define do |project| # TODO on_define is deprecated
382
- project.recursive_task('doda') { @order << project.name }
383
- end
384
- define('foo') { define('bar') { define('baz') } }
333
+ define('foo') {
334
+ @order = []
335
+ def order
336
+ @order
337
+ end
338
+ recursive_task('doda') { project('foo').order << 'foo' }
339
+ define('bar') {
340
+ recursive_task('doda') { project('foo').order << 'foo:bar' }
341
+ define('baz') {
342
+ recursive_task('doda') { project('foo').order << 'foo:bar:baz' }
343
+ }
344
+ }
345
+ }
346
+ @order = project('foo').order
385
347
  end
386
348
 
387
349
  it 'should invoke same task in child project' do
@@ -533,7 +495,7 @@ describe Buildr, '#project' do
533
495
  project('foo:bar').project('baz').should be(project('foo:baz'))
534
496
  end
535
497
 
536
- it 'should fine a project from its parent by proximity' do
498
+ it 'should find a project from its parent by proximity' do
537
499
  define 'foo' do
538
500
  define('bar') { define 'baz' }
539
501
  define 'baz'
@@ -542,11 +504,6 @@ describe Buildr, '#project' do
542
504
  project('foo:bar').project('baz').should be(project('foo:bar:baz'))
543
505
  end
544
506
 
545
- it 'should invoke project before returning it' do
546
- define('foo').should_receive(:invoke).once
547
- project('foo')
548
- end
549
-
550
507
  it 'should fail if called without a project name' do
551
508
  lambda { project }.should raise_error(ArgumentError)
552
509
  end
@@ -621,11 +578,12 @@ end
621
578
  describe Rake::Task, ' local directory' do
622
579
  before do
623
580
  @task = Project.local_task(task(('doda')))
624
- Project.on_define { |project| task('doda') { |task| @task.from project.name } }
581
+
625
582
  end
626
583
 
627
584
  it 'should execute project in local directory' do
628
585
  define 'foo'
586
+ project('foo').tap { |project| task('doda') { |task| @task.from project.name } }
629
587
  @task.should_receive(:from).with('foo')
630
588
  @task.invoke
631
589
  end
@@ -633,18 +591,24 @@ describe Rake::Task, ' local directory' do
633
591
  it 'should execute sub-project in local directory' do
634
592
  @task.should_receive(:from).with('foo:bar')
635
593
  define('foo') { define 'bar' }
594
+ project('foo:bar').tap { |project| task('doda') { |task| @task.from project.name } }
636
595
  in_original_dir(project('foo:bar').base_dir) { @task.invoke }
637
596
  end
638
597
 
639
598
  it 'should do nothing if no project in local directory' do
640
599
  @task.should_not_receive(:from)
641
- define('foo') { define 'bar' }
600
+ define('foo') {
601
+ task('doda') { |task| @task.from project.name }
602
+ define 'bar'
603
+ }
604
+
642
605
  in_original_dir('../not_foo') { @task.invoke }
643
606
  end
644
607
 
645
608
  it 'should find closest project that matches current directory' do
646
609
  mkpath 'bar/src/main'
647
610
  define('foo') { define 'bar' }
611
+ project('foo:bar').tap { |project| task('doda') { |task| @task.from project.name } }
648
612
  @task.should_receive(:from).with('foo:bar')
649
613
  in_original_dir('bar/src/main') { @task.invoke }
650
614
  end
@@ -141,13 +141,6 @@ describe Buildr::TestTask do
141
141
  test_task.options[:bar].should eql('BAR')
142
142
  end
143
143
 
144
- it 'should respond to :using with deprecated parameter style and set value options to true, up to version 1.5 since this usage was deprecated in version 1.3' do
145
- Buildr::VERSION.should < '1.5'
146
- test_task.using('foo', 'bar')
147
- test_task.options[:foo].should eql(true)
148
- test_task.options[:bar].should eql(true)
149
- end
150
-
151
144
  it 'should start without pre-selected test framework' do
152
145
  test_task.framework.should be_nil
153
146
  end
@@ -555,7 +548,8 @@ describe Buildr::Project, '#test.compile' do
555
548
  end
556
549
 
557
550
  it 'should compile to target/test/<code>' do
558
- define 'foo', :target=>'targeted' do
551
+ define 'foo' do
552
+ layout[:target] = _('targeted')
559
553
  test.compile.using(:javac)
560
554
  test.compile.target.should eql(file('targeted/test/classes'))
561
555
  end
@@ -607,7 +601,10 @@ describe Buildr::Project, '#test.resources' do
607
601
 
608
602
  it 'should copy to the resources target directory' do
609
603
  write 'src/test/resources/config.xml', '</xml>'
610
- define('foo', :target=>'targeted').test.invoke
604
+ define('foo') do
605
+ layout[:target] = _('targeted')
606
+ end.test.invoke
607
+
611
608
  file('targeted/test/resources/config.xml').should contain('</xml>')
612
609
  end
613
610
 
@@ -119,9 +119,6 @@ end
119
119
 
120
120
 
121
121
  describe URI::FILE do
122
- it 'should complain about file:' do
123
- lambda { URI('file:') }.should raise_error(URI::InvalidURIError)
124
- end
125
122
 
126
123
  it 'should accept file:something as file:///something' do
127
124
  URI('file:something').should eql(URI('file:///something'))
@@ -135,10 +132,6 @@ describe URI::FILE do
135
132
  URI('file:/something').should eql(URI('file:///something'))
136
133
  end
137
134
 
138
- it 'should complain about file://' do
139
- lambda { URI('file://').should eql(URI('file:///')) }.should raise_error(URI::InvalidURIError)
140
- end
141
-
142
135
  it 'should accept file://something as file://something/' do
143
136
  URI('file://something').should eql(URI('file://something/'))
144
137
  end
@@ -253,6 +246,22 @@ describe URI::HTTP, '#read' do
253
246
  @http.should_receive(:use_ssl=).with(true)
254
247
  URI(@uri.to_s.sub(/http/, 'https')).read
255
248
  end
249
+
250
+ it 'should use custom SSL CA certificates if provided through the environment variable SSL_CA_CERTS' do
251
+ ENV['SSL_VERIFY_MODE'] = 'VERIFY_PEER'
252
+ Net::HTTP.should_receive(:new).with(@host_domain, 443).and_return(@http)
253
+ @http.should_receive(:use_ssl=).with(true)
254
+ @http.should_receive(:verify_mode=).with(OpenSSL::SSL::VERIFY_PEER)
255
+ URI(@uri.to_s.sub(/http/, 'https')).read
256
+ end
257
+
258
+ it 'should use custom verify mode if provided through the environment variable SSL_VERIFY_MODE' do
259
+ ENV['SSL_CA_CERTS'] = 'tmp/certs'
260
+ Net::HTTP.should_receive(:new).with(@host_domain, 443).and_return(@http)
261
+ @http.should_receive(:use_ssl=).with(true)
262
+ @http.should_receive(:ca_path=).with('tmp/certs')
263
+ URI(@uri.to_s.sub(/http/, 'https')).read
264
+ end
256
265
 
257
266
  it 'should use proxy from environment variable HTTP_PROXY when using http' do
258
267
  ENV['HTTP_PROXY'] = @proxy
@@ -140,8 +140,8 @@ describe 'groovyc compiler' do
140
140
  write 'src/main/groovy/some/Example.groovy', 'package some; class Example { }'
141
141
  define('foo', :version => '1.0').package.invoke
142
142
  file('target/foo-1.0.jar').should exist
143
- Zip::ZipFile.open(project('foo').package(:jar).to_s) do |jar|
144
- jar.file.exist?('some/Example.class').should be_true
143
+ Zip::File.open(project('foo').package(:jar).to_s) do |jar|
144
+ jar.exist?('some/Example.class').should be_true
145
145
  end
146
146
  end
147
147
 
@@ -29,9 +29,4 @@ describe Buildr::Ant do
29
29
  end
30
30
  end
31
31
 
32
- it 'should have REQUIRES up to version 1.5 since it was deprecated in version 1.3.3' do
33
- Buildr::VERSION.should < '1.5'
34
- lambda { Ant::REQUIRES }.should_not raise_error
35
- end
36
-
37
32
  end
@@ -99,12 +99,12 @@ describe 'javac compiler' do
99
99
  end
100
100
 
101
101
  it 'should include tools.jar dependency' do
102
- write 'src/main/java/UseApt.java', <<-JAVA
103
- import com.sun.mirror.apt.AnnotationProcessor;
104
- public class UseApt { }
102
+ write 'src/main/java/UseJarSigner.java', <<-JAVA
103
+ import sun.tools.jar.Manifest;
104
+ public class UseJarSigner { }
105
105
  JAVA
106
106
  define('foo').compile.invoke
107
- file('target/classes/UseApt.class').should exist
107
+ file('target/classes/UseJarSigner.class').should exist
108
108
  end
109
109
 
110
110
  it 'should ignore package-info.java files in up-to-date check' do
@@ -15,47 +15,250 @@
15
15
 
16
16
  require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helpers'))
17
17
 
18
- describe Buildr::Compiler::Ecj do
19
-
20
- before(:all) do
21
- #Make ecj appear as a compiler that applies:
22
- class Buildr::Compiler::Ecj
23
- class << self
24
- def applies_to?(project, task)
25
- paths = task.sources + [sources].flatten.map { |src| Array(project.path_to(:source, task.usage, src.to_sym)) }
26
- paths.flatten.each { |path|
27
- path = path.to_s
28
- Find.find(path) {|found|
29
- if (!File.directory?(found)) && found.match(/.*\.#{Array(source_ext).join('|')}/)
30
- return true
31
- end
32
- } if File.exist? path
33
- }
34
- false
35
- end
18
+
19
+ describe 'ecj compiler' do
20
+ it 'should be explicitly referenced' do
21
+ write 'src/main/java/com/example/Test.java', 'package com.example; class Test {}'
22
+ define('foo').compile.using(:ecj).compiler.should eql(:ecj)
23
+ end
24
+
25
+ it 'should report the language as :java' do
26
+ define('foo').compile.using(:ecj).language.should eql(:java)
27
+ end
28
+
29
+ it 'should set the target directory to target/classes' do
30
+ define 'foo' do
31
+ lambda { compile.using(:ecj) }.should change { compile.target.to_s }.to(File.expand_path('target/classes'))
32
+ end
33
+ end
34
+
35
+ it 'should not override existing target directory' do
36
+ define 'foo' do
37
+ compile.into('classes')
38
+ lambda { compile.using(:ecj) }.should_not change { compile.target }
39
+ end
40
+ end
41
+
42
+ it 'should accept a task to compile from' do
43
+ p = define 'foo' do
44
+ project.version = '1'
45
+ f = file(_(:target, :generated, 'myjava')) do
46
+ mkdir_p _(:target, :generated, 'myjava')
47
+ File.open("#{_(:target, :generated, 'myjava')}/Foo.java", "wb") do |f|
48
+ f.write "public class Foo {}"
36
49
  end
37
50
  end
51
+
52
+ compile.from(f)
53
+ package(:jar)
54
+ end.compile.invoke
55
+ file('target/classes/Foo.class').should exist
56
+ end
57
+
58
+ it 'should not change existing list of sources' do
59
+ define 'foo' do
60
+ compile.from('sources')
61
+ lambda { compile.using(:ecj) }.should_not change { compile.sources }
62
+ end
63
+ end
64
+
65
+ # Doesn't work under jdk1.5 - caused in one of the commits 1167678, 1170604, 1170605, 1180125
66
+ if Java.java.lang.System.getProperty("java.runtime.version") >= "1.6"
67
+ it 'should include classpath dependencies' do
68
+ write 'src/dependency/Dependency.java', 'class Dependency {}'
69
+ define 'dependency', :version=>'1.0' do
70
+ compile.from('src/dependency').into('target/dependency')
71
+ package(:jar)
72
+ end
73
+ write 'src/test/DependencyTest.java', 'class DependencyTest { Dependency _var; }'
74
+ define('foo').compile.from('src/test').with(project('dependency')).invoke
75
+ file('target/classes/DependencyTest.class').should exist
38
76
  end
77
+ end
78
+
79
+ it 'should include tools.jar dependency' do
80
+ repositories.remote << "http://repo1.maven.org/maven2/"
81
+ write 'src/main/java/UseJarSigner.java', <<-JAVA
82
+ import sun.tools.jar.Manifest;
83
+ public class UseJarSigner { }
84
+ JAVA
85
+ define('foo').compile.invoke
86
+ file('target/classes/UseJarSigner.class').should exist
87
+ end
88
+
89
+ it 'should ignore package-info.java files in up-to-date check' do
90
+ write 'src/main/java/foo/Test.java', 'package foo; class Test { public void foo() {} }'
91
+ write 'src/main/java/foo/package-info.java', 'package foo;'
92
+ lambda{ define('foo').compile.invoke }.should run_task('foo:compile')
93
+ lambda{ define('bar').compile.invoke }.should_not run_task('bar:compile')
94
+ end
95
+ end
96
+
97
+
98
+ describe 'ecj compiler options' do
99
+ def compile_task
100
+ @compile_task ||= define('foo').compile.using(:ecj)
101
+ end
102
+
103
+ def ecj_args
104
+ compile_task.instance_eval { @compiler }.send(:ecj_args)
105
+ end
106
+
107
+ it 'should set warnings option to false by default' do
108
+ compile_task.options.warnings.should be_false
109
+ end
110
+
111
+ it 'should set warnings option to true when running with --verbose option' do
112
+ verbose true
113
+ compile_task.options.warnings.should be_false
114
+ end
115
+
116
+ it 'should use -nowarn argument when warnings is false' do
117
+ compile_task.using(:warnings=>false)
118
+ ecj_args.should include('-warn:none')
119
+ end
120
+
121
+ it 'should not use -nowarn argument when warnings is true' do
122
+ compile_task.using(:warnings=>true)
123
+ ecj_args.should_not include('-warn:none')
124
+ end
125
+
126
+ it 'should not use -verbose argument by default' do
127
+ ecj_args.should_not include('-verbose')
128
+ end
129
+
130
+ it 'should use -verbose argument when running with --trace=ecj option' do
131
+ Buildr.application.options.trace_categories = [:ecj]
132
+ ecj_args.should include('-verbose')
133
+ end
134
+
135
+ it 'should set debug option to true by default' do
136
+ compile_task.options.debug.should be_true
137
+ end
138
+
139
+ it 'should set debug option to false based on Buildr.options' do
140
+ Buildr.options.debug = false
141
+ compile_task.options.debug.should be_false
142
+ end
143
+
144
+ it 'should set debug option to false based on debug environment variable' do
145
+ ENV['debug'] = 'no'
146
+ compile_task.options.debug.should be_false
147
+ end
148
+
149
+ it 'should set debug option to false based on DEBUG environment variable' do
150
+ ENV['DEBUG'] = 'no'
151
+ compile_task.options.debug.should be_false
152
+ end
153
+
154
+ it 'should use -g argument when debug option is true' do
155
+ compile_task.using(:debug=>true)
156
+ ecj_args.should include('-g')
157
+ end
158
+
159
+ it 'should not use -g argument when debug option is false' do
160
+ compile_task.using(:debug=>false)
161
+ ecj_args.should_not include('-g')
162
+ end
163
+
164
+ it 'should set deprecation option to false by default' do
165
+ compile_task.options.deprecation.should be_false
166
+ end
167
+
168
+ it 'should use -deprecation argument when deprecation is true' do
169
+ compile_task.using(:deprecation=>true)
170
+ ecj_args.should include('-deprecation')
171
+ end
172
+
173
+ it 'should not use -deprecation argument when deprecation is false' do
174
+ compile_task.using(:deprecation=>false)
175
+ ecj_args.should_not include('-deprecation')
176
+ end
177
+
178
+ it 'should not set source option by default' do
179
+ compile_task.options.source.should be_nil
180
+ ecj_args.should_not include('-source')
181
+ end
182
+
183
+ it 'should not set target option by default' do
184
+ compile_task.options.target.should be_nil
185
+ ecj_args.should_not include('-target')
186
+ end
187
+
188
+ it 'should use -source nn argument if source option set' do
189
+ compile_task.using(:source=>'1.5')
190
+ ecj_args.should include('-source', '1.5')
191
+ end
192
+
193
+ it 'should use -target nn argument if target option set' do
194
+ compile_task.using(:target=>'1.5')
195
+ ecj_args.should include('-target', '1.5')
196
+ end
197
+
198
+ it 'should set lint option to false by default' do
199
+ compile_task.options.lint.should be_false
200
+ end
39
201
 
40
- it "should be the default Java compiler once loaded" do
41
- write 'src/main/java/Foo.java', 'public class Foo {}'
42
- foo = define('foo')
43
- foo.compile.compiler.should == :ecj
202
+ it 'should use -lint argument if lint option is true' do
203
+ compile_task.using(:lint=>true)
204
+ ecj_args.should include('-Xlint')
44
205
  end
45
206
 
46
- describe "should compile a Java project just in the same way javac does" do
47
- javac_spec = File.read(File.join(File.dirname(__FILE__), "compiler_spec.rb"))
48
- javac_spec = javac_spec.match(Regexp.escape("require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helpers'))\n")).post_match
49
- javac_spec.gsub!("javac", "ecj")
50
- javac_spec.gsub!("nowarn", "warn:none")
51
- eval(javac_spec)
207
+ it 'should use -lint argument with value of option' do
208
+ compile_task.using(:lint=>'all')
209
+ ecj_args.should include('-Xlint:all')
210
+ end
211
+
212
+ it 'should use -lint argument with value of option as array' do
213
+ compile_task.using(:lint=>['path', 'serial'])
214
+ ecj_args.should include('-Xlint:path,serial')
215
+ end
216
+
217
+ it 'should not set other option by default' do
218
+ compile_task.options.other.should be_nil
219
+ end
220
+
221
+ it 'should pass other argument if other option is string' do
222
+ compile_task.using(:other=>'-Xprint')
223
+ ecj_args.should include('-Xprint')
224
+ end
225
+
226
+ it 'should pass other argument if other option is array' do
227
+ compile_task.using(:other=>['-Xstdout', 'msgs'])
228
+ ecj_args.should include('-Xstdout', 'msgs')
229
+ end
230
+
231
+ it 'should complain about options it doesn\'t know' do
232
+ repositories.remote << "http://repo1.maven.org/maven2/"
233
+ write 'source/Test.java', 'class Test {}'
234
+ compile_task.using(:unknown=>'option')
235
+ lambda { compile_task.from('source').invoke }.should raise_error(ArgumentError, /no such option/i)
236
+ end
237
+
238
+ it 'should inherit options from parent' do
239
+ define 'foo' do
240
+ compile.using(:warnings=>true, :debug=>true, :deprecation=>true, :source=>'1.5', :target=>'1.4')
241
+ define 'bar' do
242
+ compile.using(:ecj)
243
+ compile.options.warnings.should be_true
244
+ compile.options.debug.should be_true
245
+ compile.options.deprecation.should be_true
246
+ compile.options.source.should eql('1.5')
247
+ compile.options.target.should eql('1.4')
248
+ end
249
+ end
250
+ end
251
+
252
+ after do
253
+ Buildr.options.debug = nil
254
+ ENV.delete "debug"
255
+ ENV.delete "DEBUG"
52
256
  end
53
257
 
54
258
  # Redirect the java error ouput, yielding so you can do something while it is
55
259
  # and returning the content of the error buffer.
56
260
  #
57
261
  def redirect_java_err
58
- pending "RJB doesn't support well instantiating a class that has several constructors" unless RUBY_PLATFORM =~ /java/
59
262
  err = Java.java.io.ByteArrayOutputStream.new
60
263
  original_err = Java.java.lang.System.err
61
264
  begin
@@ -75,7 +278,7 @@ describe Buildr::Compiler::Ecj do
75
278
  compile.options.source = "1.5"
76
279
  compile.options.target = "1.5"
77
280
  }
78
- redirect_java_err { foo.compile.invoke }.should_not match(/WARNING/)
281
+ redirect_java_err { foo.compile.invoke }.should_not match(/warning/)
79
282
  end
80
283
 
81
284
  it "should issue warnings for type casting when warnings are set" do
@@ -85,21 +288,17 @@ describe Buildr::Compiler::Ecj do
85
288
  compile.options.target = "1.5"
86
289
  compile.options.warnings = true
87
290
  }
88
- redirect_java_err { foo.compile.invoke }.should match(/WARNING/)
89
- end
90
-
91
- after(:all) do
92
- #Make ecj appear as a compiler that doesn't apply:
93
- module Buildr
94
- module Compiler
95
- class Ecj
96
- class << self
97
- def applies_to?(project, task)
98
- false
99
- end
100
- end
101
- end
102
- end
291
+ redirect_java_err { foo.compile.invoke }.should match(/warning/)
292
+ end
293
+
294
+ it 'should pick Ecj version from ecj build settings' do
295
+ begin
296
+ Buildr::Compiler::Ecj.instance_eval { @dependencies = nil }
297
+ write 'build.yaml', 'ecj: 3.5.1'
298
+ Buildr::Compiler::Ecj.dependencies.should include("org.eclipse.jdt.core.compiler:ecj:jar:3.5.1")
299
+ ensure
300
+ Buildr::Compiler::Ecj.instance_eval { @dependencies = nil }
103
301
  end
104
302
  end
303
+
105
304
  end