buildr 1.3.4-java → 1.3.5-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. data/CHANGELOG +35 -0
  2. data/README.rdoc +1 -1
  3. data/Rakefile +3 -3
  4. data/buildr.buildfile +6 -1
  5. data/buildr.gemspec +10 -9
  6. data/doc/_config.yml +1 -0
  7. data/doc/_layouts/default.html +25 -19
  8. data/doc/artifacts.textile +0 -36
  9. data/doc/building.textile +0 -38
  10. data/doc/contributing.textile +51 -15
  11. data/doc/css/default.css +11 -4
  12. data/doc/css/print.css +32 -24
  13. data/doc/download.textile +33 -22
  14. data/doc/extending.textile +10 -20
  15. data/doc/images/1442160941-frontcover.jpg +0 -0
  16. data/doc/images/asf-logo.png +0 -0
  17. data/doc/images/note.png +0 -0
  18. data/doc/images/project-structure.png +0 -0
  19. data/doc/images/tip.png +0 -0
  20. data/doc/images/zbuildr.png +0 -0
  21. data/doc/index.textile +39 -17
  22. data/doc/{getting_started.textile → installing.textile} +3 -80
  23. data/doc/languages.textile +50 -52
  24. data/doc/more_stuff.textile +154 -62
  25. data/doc/packaging.textile +0 -82
  26. data/doc/preface.textile +41 -15
  27. data/doc/projects.textile +0 -18
  28. data/doc/quick_start.textile +210 -0
  29. data/doc/scripts/install-linux.sh +10 -2
  30. data/doc/settings_profiles.textile +1 -33
  31. data/doc/testing.textile +6 -32
  32. data/lib/buildr.rb +2 -1
  33. data/lib/buildr/core.rb +6 -0
  34. data/lib/buildr/core/application.rb +2 -5
  35. data/lib/buildr/core/build.rb +29 -19
  36. data/lib/buildr/core/compile.rb +22 -4
  37. data/lib/buildr/core/filter.rb +2 -4
  38. data/lib/buildr/core/project.rb +5 -4
  39. data/lib/buildr/core/shell.rb +198 -0
  40. data/lib/buildr/core/test.rb +2 -0
  41. data/lib/buildr/core/transports.rb +18 -19
  42. data/lib/buildr/core/util.rb +178 -9
  43. data/lib/buildr/groovy.rb +1 -0
  44. data/lib/buildr/groovy/bdd.rb +5 -5
  45. data/lib/buildr/groovy/shell.rb +48 -0
  46. data/lib/buildr/ide/eclipse.rb +148 -36
  47. data/lib/buildr/ide/eclipse/java.rb +53 -0
  48. data/lib/buildr/ide/eclipse/plugin.rb +68 -0
  49. data/lib/buildr/ide/eclipse/scala.rb +66 -0
  50. data/lib/buildr/java/bdd.rb +16 -8
  51. data/lib/buildr/java/cobertura.rb +44 -13
  52. data/lib/buildr/java/commands.rb +5 -3
  53. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.class +0 -0
  54. data/lib/buildr/java/org/apache/buildr/JavaTestFilter.java +18 -0
  55. data/lib/buildr/java/packaging.rb +2 -2
  56. data/lib/buildr/java/rjb.rb +1 -1
  57. data/lib/buildr/java/test_result.rb +48 -1
  58. data/lib/buildr/java/tests.rb +8 -5
  59. data/lib/buildr/packaging/artifact_namespace.rb +1 -1
  60. data/lib/buildr/packaging/package.rb +6 -2
  61. data/lib/buildr/packaging/zip.rb +10 -1
  62. data/lib/buildr/packaging/ziptask.rb +5 -2
  63. data/lib/buildr/scala.rb +1 -0
  64. data/lib/buildr/scala/bdd.rb +17 -8
  65. data/lib/buildr/scala/compiler.rb +66 -21
  66. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner$.class +0 -0
  67. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.class +0 -0
  68. data/lib/buildr/scala/org/apache/buildr/SpecsSingletonRunner.scala +35 -0
  69. data/lib/buildr/scala/shell.rb +55 -0
  70. data/lib/buildr/scala/tests.rb +6 -5
  71. data/lib/buildr/shell.rb +180 -0
  72. data/rakelib/doc.rake +2 -3
  73. data/rakelib/jekylltask.rb +42 -32
  74. data/rakelib/package.rake +4 -2
  75. data/rakelib/release.rake +8 -8
  76. data/rakelib/rspec.rake +3 -3
  77. data/rakelib/setup.rake +7 -1
  78. data/rakelib/stage.rake +9 -2
  79. data/rakelib/stage.rake~ +213 -0
  80. data/spec/core/application_spec.rb +84 -1
  81. data/spec/core/build_spec.rb +54 -2
  82. data/spec/core/common_spec.rb +1 -1
  83. data/spec/core/compile_spec.rb +2 -1
  84. data/spec/core/extension_spec.rb +93 -0
  85. data/spec/core/test_spec.rb +2 -2
  86. data/spec/core/transport_spec.rb +1 -1
  87. data/spec/groovy/bdd_spec.rb +6 -6
  88. data/spec/groovy/compiler_spec.rb +1 -0
  89. data/spec/ide/eclipse_spec.rb +262 -72
  90. data/spec/java/{ant.rb → ant_spec.rb} +0 -0
  91. data/spec/java/bdd_spec.rb +15 -0
  92. data/spec/java/cobertura_spec.rb +9 -1
  93. data/spec/java/emma_spec.rb +1 -1
  94. data/spec/java/java_spec.rb +26 -0
  95. data/spec/java/packaging_spec.rb +9 -7
  96. data/spec/java/{test_coverage_spec.rb → test_coverage_helper.rb} +6 -4
  97. data/spec/java/tests_spec.rb +22 -0
  98. data/spec/packaging/archive_spec.rb +14 -0
  99. data/spec/packaging/artifact_spec.rb +2 -2
  100. data/spec/packaging/packaging_spec.rb +97 -2
  101. data/spec/sandbox.rb +3 -1
  102. data/spec/scala/bdd_spec.rb +17 -48
  103. data/spec/scala/compiler_spec.rb +31 -2
  104. data/spec/scala/tests_spec.rb +1 -0
  105. data/spec/spec_helpers.rb +12 -0
  106. metadata +145 -148
@@ -443,6 +443,8 @@ module Buildr
443
443
  else
444
444
  info "Running tests in #{@project.name}"
445
445
  begin
446
+ # set the baseDir system property if not set
447
+ @framework.options[:properties] = { 'baseDir' => @project.test.compile.target.to_s }.merge(@framework.options[:properties] || {})
446
448
  @passed_tests = @framework.run(@tests, dependencies)
447
449
  rescue Exception=>ex
448
450
  error "Test framework error: #{ex.message}"
@@ -16,7 +16,6 @@
16
16
 
17
17
  require 'uri'
18
18
  require 'net/http'
19
- Net.autoload :HTTPS, 'net/https'
20
19
  # PATCH: On Windows, Net::SSH 2.0.2 attempts to load the Pageant DLLs which break on JRuby.
21
20
  $LOADED_FEATURES << 'net/ssh/authentication/pageant.rb' if RUBY_PLATFORM =~ /java/
22
21
  gem 'net-ssh' ; Net.autoload :SSH, 'net/ssh'
@@ -148,11 +147,10 @@ module URI
148
147
  # worse than not having a file at all, so download to temporary
149
148
  # file and then move over.
150
149
  modified = File.stat(target).mtime if File.exist?(target)
151
- temp = nil
152
- Tempfile.open File.basename(target) do |temp|
153
- temp.binmode
154
- read({:progress=>verbose}.merge(options || {}).merge(:modified=>modified)) { |chunk| temp.write chunk }
155
- end
150
+ temp = Tempfile.new(File.basename(target))
151
+ temp.binmode
152
+ read({:progress=>verbose}.merge(options || {}).merge(:modified=>modified)) { |chunk| temp.write chunk }
153
+ temp.close
156
154
  mkpath File.dirname(target)
157
155
  mv temp.path, target
158
156
  when File
@@ -366,7 +364,10 @@ module URI
366
364
  else
367
365
  http = Net::HTTP.new(host, port)
368
366
  end
369
- http.use_ssl = true if self.instance_of? URI::HTTPS
367
+ if self.instance_of? URI::HTTPS
368
+ require 'net/https'
369
+ http.use_ssl = true
370
+ end
370
371
  yield http
371
372
  end
372
373
 
@@ -537,20 +538,18 @@ module URI
537
538
 
538
539
  def write_internal(options, &block) #:nodoc:
539
540
  raise ArgumentError, 'Either you\'re attempting to write a file to another host (which we don\'t support), or you used two slashes by mistake, where you should have file:///<path>.' if host
540
- temp = nil
541
- Tempfile.open File.basename(path) do |temp|
542
- temp.binmode
543
- with_progress_bar options[:progress] && options[:size], path.split('/'), options[:size] || 0 do |progress|
544
- while chunk = yield(RW_CHUNK_SIZE)
545
- temp.write chunk
546
- progress << chunk
547
- end
541
+ temp = Tempfile.new(File.basename(path))
542
+ temp.binmode
543
+ with_progress_bar options[:progress] && options[:size], path.split('/'), options[:size] || 0 do |progress|
544
+ while chunk = yield(RW_CHUNK_SIZE)
545
+ temp.write chunk
546
+ progress << chunk
548
547
  end
549
548
  end
550
- real_path.tap do |path|
551
- mkpath File.dirname(path)
552
- mv temp.path, path
553
- end
549
+ temp.close
550
+ mkpath File.dirname(real_path)
551
+ mv temp.path, real_path
552
+ real_path
554
553
  end
555
554
 
556
555
  @@schemes['FILE'] = FILE
@@ -159,24 +159,54 @@ module Buildr
159
159
  end
160
160
 
161
161
 
162
- if RUBY_VERSION < '1.9.0'
163
- module Kernel #:nodoc:
164
- # Borrowed from Ruby 1.9.
162
+ class Object #:nodoc:
163
+ unless defined? instance_exec # 1.9
164
+ module InstanceExecMethods #:nodoc:
165
+ end
166
+ include InstanceExecMethods
167
+
168
+ # Evaluate the block with the given arguments within the context of
169
+ # this object, so self is set to the method receiver.
170
+ #
171
+ # From Mauricio's http://eigenclass.org/hiki/bounded+space+instance_exec
172
+ def instance_exec(*args, &block)
173
+ begin
174
+ old_critical, Thread.critical = Thread.critical, true
175
+ n = 0
176
+ n += 1 while respond_to?(method_name = "__instance_exec#{n}")
177
+ InstanceExecMethods.module_eval { define_method(method_name, &block) }
178
+ ensure
179
+ Thread.critical = old_critical
180
+ end
181
+
182
+ begin
183
+ send(method_name, *args)
184
+ ensure
185
+ InstanceExecMethods.module_eval { remove_method(method_name) } rescue nil
186
+ end
187
+ end
188
+ end
189
+ end
190
+
191
+ module Kernel #:nodoc:
192
+ unless defined? tap # 1.9
165
193
  def tap
166
194
  yield self if block_given?
167
195
  self
168
- end unless method_defined?('tap')
196
+ end
169
197
  end
198
+ end
170
199
 
171
-
172
- class Symbol #:nodoc:
200
+ class Symbol #:nodoc:
201
+ unless defined? to_proc # 1.9
173
202
  # Borrowed from Ruby 1.9.
174
203
  def to_proc
175
204
  Proc.new{|*args| args.shift.__send__(self, *args)}
176
- end unless method_defined?('to_proc')
205
+ end
177
206
  end
207
+ end
178
208
 
179
- # Also borrowed from Ruby 1.9.
209
+ unless defined? BasicObject # 1.9
180
210
  class BasicObject #:nodoc:
181
211
  (instance_methods - ['__send__', '__id__', '==', 'send', 'send!', 'respond_to?', 'equal?', 'object_id']).
182
212
  each do |method|
@@ -230,7 +260,9 @@ class Hash
230
260
  # and the Hash doesn't work the way we need it to. Unfortunately, we can call toString on MRI's object,
231
261
  # but not on the JRuby one; calling to_s on the JRuby object returns what we need, but ... you guessed it.
232
262
  # So this seems like the one hack to unite them both.
233
- key = Java.java.lang.String.valueOf(keys.next)
263
+ #key = Java.java.lang.String.valueOf(keys.next.to_s)
264
+ key = keys.next
265
+ key = key.toString unless String === key
234
266
  hash[key] = java_properties.getProperty(key)
235
267
  end
236
268
  hash
@@ -278,3 +310,140 @@ class Hash
278
310
  end
279
311
 
280
312
  end
313
+
314
+ if Buildr::Util.java_platform?
315
+ require 'ffi'
316
+
317
+ # Fix for BUILDR-292.
318
+ # JRuby fails to rename a file on different devices
319
+ # this monkey-patch wont be needed when JRUBY-3381 gets resolved.
320
+ module FileUtils #:nodoc:
321
+ alias_method :__mv_native, :mv
322
+
323
+ def mv(from, to, options = nil)
324
+ dir_to = File.directory?(to) ? to : File.dirname(to)
325
+ Array(from).each do |from|
326
+ dir_from = File.dirname(from)
327
+ if File.stat(dir_from).dev != File.stat(dir_to).dev
328
+ cp from, to, options
329
+ rm from, options
330
+ else
331
+ __mv_native from, to, options
332
+ end
333
+ end
334
+ end
335
+ private :mv
336
+ end
337
+
338
+ module RakeFileUtils #:nodoc:
339
+ def rake_merge_option(args, defaults)
340
+ defaults[:verbose] = false if defaults[:verbose] == :default
341
+
342
+ if Hash === args.last
343
+ defaults.update(args.last)
344
+ args.pop
345
+ end
346
+ args.push defaults
347
+ args
348
+ end
349
+ private :rake_merge_option
350
+ end
351
+
352
+ module Buildr
353
+ class ProcessStatus
354
+ attr_reader :pid, :termsig, :stopsig, :exitstatus
355
+
356
+ def initialize(pid, success, exitstatus)
357
+ @pid = pid
358
+ @success = success
359
+ @exitstatus = exitstatus
360
+
361
+ @termsig = nil
362
+ @stopsig = nil
363
+ end
364
+
365
+ def &(num)
366
+ pid & num
367
+ end
368
+
369
+ def ==(other)
370
+ pid == other.pid
371
+ end
372
+
373
+ def >>(num)
374
+ pid >> num
375
+ end
376
+
377
+ def coredump?
378
+ false
379
+ end
380
+
381
+ def exited?
382
+ true
383
+ end
384
+
385
+ def stopped?
386
+ false
387
+ end
388
+
389
+ def success?
390
+ @success
391
+ end
392
+
393
+ def to_i
394
+ pid
395
+ end
396
+
397
+ def to_int
398
+ pid
399
+ end
400
+
401
+ def to_s
402
+ pid.to_s
403
+ end
404
+ end
405
+ end
406
+
407
+ module FileUtils
408
+ extend FFI::Library
409
+ alias_method :__jruby_system__, :system
410
+ attach_function :system, [:string], :int
411
+ alias_method :__native_system__, :system
412
+ alias_method :system, :__jruby_system__
413
+
414
+ # code "borrowed" directly from Rake
415
+ def sh(*cmd, &block)
416
+ options = (Hash === cmd.last) ? cmd.pop : {}
417
+ unless block_given?
418
+ show_command = cmd.join(" ")
419
+ show_command = show_command[0,42] + "..."
420
+
421
+ block = lambda { |ok, status|
422
+ ok or fail "Command failed with status (#{status.exitstatus}): [#{show_command}]"
423
+ }
424
+ end
425
+ if RakeFileUtils.verbose_flag == :default
426
+ options[:verbose] = false
427
+ else
428
+ options[:verbose] ||= RakeFileUtils.verbose_flag
429
+ end
430
+ options[:noop] ||= RakeFileUtils.nowrite_flag
431
+ rake_check_options options, :noop, :verbose
432
+ rake_output_message cmd.join(" ") if options[:verbose]
433
+ unless options[:noop]
434
+ cd = "cd '#{Dir.pwd}' && "
435
+ args = if cmd.size > 1 then cmd[1..cmd.size] else [] end
436
+
437
+ res = if Buildr::Util.win_os? && cmd.size == 1
438
+ __native_system__("#{cd} call #{cmd.first}")
439
+ else
440
+ arg_str = args.map { |a| "'#{a}'" }
441
+ __native_system__(cd + cmd.first + ' ' + arg_str.join(' '))
442
+ end
443
+ $? = Buildr::ProcessStatus.new(0, res == 0, res) # KLUDGE
444
+ block.call(res == 0, $?)
445
+ end
446
+ end
447
+
448
+ end
449
+ end
@@ -16,3 +16,4 @@
16
16
 
17
17
  require 'buildr/groovy/compiler'
18
18
  require 'buildr/groovy/bdd'
19
+ require 'buildr/groovy/shell'
@@ -23,7 +23,7 @@ module Buildr::Groovy
23
23
  #
24
24
  # This framework will search in your project for:
25
25
  # src/spec/groovy/**/*Story.groovy
26
- # src/spec/groovy/**/*Behavior.groovy
26
+ # src/spec/groovy/**/*Specification.groovy
27
27
  #
28
28
  # Support the following options:
29
29
  # * :format -- Report format :txt or :xml, default is :txt
@@ -33,8 +33,8 @@ module Buildr::Groovy
33
33
  @lang = :groovy
34
34
  @bdd_dir = :spec
35
35
 
36
- VERSION = "0.7"
37
- TESTS_PATTERN = [ /(Story|Behavior).groovy$/ ]
36
+ VERSION = "0.9"
37
+ TESTS_PATTERN = [ /(Story|Specification).groovy$/ ]
38
38
  OPTIONS = [:format, :properties, :java_args]
39
39
 
40
40
  class << self
@@ -50,7 +50,7 @@ module Buildr::Groovy
50
50
 
51
51
  def applies_to?(project) #:nodoc:
52
52
  %w{
53
- **/*Behaviour.groovy **/*Behavior.groovy **/*Story.groovy
53
+ **/*Specification.groovy **/*Story.groovy
54
54
  }.any? { |glob| !Dir[project.path_to(:source, bdd_dir, lang, glob)].empty? }
55
55
  end
56
56
 
@@ -78,7 +78,7 @@ module Buildr::Groovy
78
78
  raise "Invalid format #{options[:format]} expected one of :txt :xml"
79
79
  end
80
80
 
81
- cmd_args = [ 'org.disco.easyb.SpecificationRunner' ]
81
+ cmd_args = [ 'org.disco.easyb.BehaviorRunner' ]
82
82
  cmd_options = { :properties => options[:properties],
83
83
  :java_args => options[:java_args],
84
84
  :classpath => dependencies }
@@ -0,0 +1,48 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with this
3
+ # work for additional information regarding copyright ownership. The ASF
4
+ # licenses this file to you under the Apache License, Version 2.0 (the
5
+ # "License"); you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ # License for the specific language governing permissions and limitations under
14
+ # the License.
15
+
16
+ require 'buildr/shell'
17
+
18
+ module Buildr
19
+ module Groovy
20
+ class GroovySH < Buildr::Shell::Base
21
+ SUFFIX = if Util.win_os? then '.bat' else '' end
22
+
23
+ class << self
24
+ def lang
25
+ :groovy
26
+ end
27
+ end
28
+
29
+ def launch
30
+ fail 'Are we forgetting something? GROOVY_HOME not set.' unless groovy_home
31
+
32
+ cp = project.compile.dependencies.join(File::PATH_SEPARATOR) +
33
+ File::PATH_SEPARATOR + project.path_to(:target, :classes)
34
+
35
+ cmd_args = " -classpath '#{cp}'"
36
+ trace "groovysh #{cmd_args}"
37
+ system(File.expand_path("bin#{File::SEPARATOR}groovysh#{SUFFIX}", groovy_home) + cmd_args)
38
+ end
39
+
40
+ private
41
+ def groovy_home
42
+ @home ||= ENV['GROOVY_HOME']
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ Buildr::ShellProviders << Buildr::Groovy::GroovySH
@@ -20,13 +20,127 @@ require 'buildr/packaging'
20
20
 
21
21
  module Buildr
22
22
  module Eclipse #:nodoc:
23
-
24
23
  include Extension
25
24
 
25
+ class Eclipse
26
+
27
+ attr_reader :options
28
+
29
+ def initialize(project)
30
+ @project = project
31
+ @options = Options.new(project)
32
+ end
33
+
34
+ # :call-seq:
35
+ # natures=(natures)
36
+ # Sets the Eclipse project natures on the project.
37
+ #
38
+ def natures=(var)
39
+ @natures = arrayfy(var)
40
+ end
41
+
42
+ # :call-seq:
43
+ # natures() => [n1, n2]
44
+ # Returns the Eclipse project natures on the project.
45
+ # They may be derived from the parent project if no specific natures have been set
46
+ # on the project.
47
+ #
48
+ # An Eclipse project nature is used internally by Eclipse to determine the aspects of a project.
49
+ def natures(*values)
50
+ if values.size > 0
51
+ @natures ||= []
52
+ @natures += values
53
+ else
54
+ @natures || (@project.parent ? @project.parent.eclipse.natures : [])
55
+ end
56
+ end
57
+
58
+ # :call-seq:
59
+ # classpath_containers=(cc)
60
+ # Sets the Eclipse project classpath containers on the project.
61
+ #
62
+ def classpath_containers=(var)
63
+ @classpath_containers = arrayfy(var)
64
+ end
65
+
66
+ # :call-seq:
67
+ # classpath_containers() => [con1, con2]
68
+ # Returns the Eclipse project classpath containers on the project.
69
+ # They may be derived from the parent project if no specific classpath containers have been set
70
+ # on the project.
71
+ #
72
+ # A classpath container is an Eclipse pre-determined ensemble of dependencies made available to
73
+ # the project classpath.
74
+ def classpath_containers(*values)
75
+ if values.size > 0
76
+ @classpath_containers ||= []
77
+ @classpath_containers += values
78
+ else
79
+ @classpath_containers || (@project.parent ? @project.parent.eclipse.classpath_containers : [])
80
+ end
81
+ end
82
+
83
+ # :call-seq:
84
+ # builders=(builders)
85
+ # Sets the Eclipse project builders on the project.
86
+ #
87
+ def builders=(var)
88
+ @builders = arrayfy(var)
89
+ end
90
+
91
+ # :call-seq:
92
+ # builders() => [b1, b2]
93
+ # Returns the Eclipse project builders on the project.
94
+ # They may be derived from the parent project if no specific builders have been set
95
+ # on the project.
96
+ #
97
+ # A builder is an Eclipse background job that parses the source code to produce built artifacts.
98
+ def builders(*values)
99
+ if values.size > 0
100
+ @builders ||= []
101
+ @builders += values
102
+ else
103
+ @builders || (@project.parent ? @project.parent.eclipse.builders : [])
104
+ end
105
+ end
106
+
107
+ private
108
+
109
+ def arrayfy(obj)
110
+ obj.is_a?(Array) ? obj : [obj]
111
+ end
112
+ end
113
+
114
+ class Options
115
+
116
+ attr_writer :m2_repo_var
117
+
118
+ def initialize(project)
119
+ @project = project
120
+ end
121
+
122
+ # The classpath variable used to point at the local maven2 repository.
123
+ # Example:
124
+ # eclipse.options.m2_repo_var = 'M2_REPO'
125
+ def m2_repo_var(*values)
126
+ fail "m2_repo_var can only accept one value: #{values}" if values.size > 1
127
+ if values.size > 0
128
+ @m2_repo_var = values[0]
129
+ else
130
+ @m2_repo_var || (@project.parent ? @project.parent.eclipse.options.m2_repo_var : 'M2_REPO')
131
+ end
132
+ end
133
+ end
134
+
135
+ def eclipse
136
+ @eclipse ||= Eclipse.new(self)
137
+ @eclipse
138
+ end
139
+
26
140
  first_time do
27
141
  # Global task "eclipse" generates artifacts for all projects.
28
142
  desc 'Generate Eclipse artifacts for all projects'
29
- Project.local_task 'eclipse'=>'artifacts'
143
+ Project.local_task('eclipse'=>'artifacts') { |name| "Generating Eclipse project for #{name}" }
30
144
  end
31
145
 
32
146
  before_define do |project|
@@ -36,19 +150,11 @@ module Buildr
36
150
  after_define do |project|
37
151
  eclipse = project.task('eclipse')
38
152
 
39
- # Check if project has scala facet
40
- scala = project.compile.language == :scala
41
-
42
- # Only for projects that we support
43
- supported_languages = [:java, :scala]
44
- supported_packaging = %w(jar war rar mar aar)
45
- if (supported_languages.include?(project.compile.language) ||
46
- supported_languages.include?(project.test.compile.language) ||
47
- project.packages.detect { |pkg| supported_packaging.include?(pkg.type.to_s) })
48
- eclipse.enhance [ file(project.path_to('.classpath')), file(project.path_to('.project')) ]
153
+ eclipse.enhance [ file(project.path_to('.classpath')), file(project.path_to('.project')) ]
49
154
 
50
- # The only thing we need to look for is a change in the Buildfile.
51
- file(project.path_to('.classpath')=>Buildr.application.buildfile) do |task|
155
+ # The only thing we need to look for is a change in the Buildfile.
156
+ file(project.path_to('.classpath')=>Buildr.application.buildfile) do |task|
157
+ if (project.eclipse.natures.reject { |x| x.is_a?(Symbol) }.size > 0)
52
158
  info "Writing #{task.name}"
53
159
 
54
160
  m2repo = Buildr::Repositories.instance.local
@@ -69,8 +175,8 @@ module Buildr
69
175
  # Separate artifacts from Maven2 repository
70
176
  m2_libs, others = others.partition { |path| path.to_s.index(m2repo) == 0 }
71
177
 
72
- # Generated: classpath elements in the project are assumed to be generated
73
- generated, libs = others.partition { |path| path.to_s.index(project.path_to.to_s) == 0 }
178
+ # Generated: Any non-file classpath elements in the project are assumed to be generated
179
+ libs, generated = others.partition { |path| File.file?(path.to_s) }
74
180
 
75
181
  classpathentry.src project.compile.sources + generated
76
182
  classpathentry.src project.resources
@@ -85,16 +191,19 @@ module Buildr
85
191
 
86
192
  classpathentry.output project.compile.target if project.compile.target
87
193
  classpathentry.lib libs
88
- classpathentry.var m2_libs, 'M2_REPO', m2repo
194
+ classpathentry.var m2_libs, project.eclipse.options.m2_repo_var, m2repo
89
195
 
90
- classpathentry.con 'ch.epfl.lamp.sdt.launching.SCALA_CONTAINER' if scala
91
- classpathentry.con 'org.eclipse.jdt.launching.JRE_CONTAINER'
196
+ project.eclipse.classpath_containers.each { |container|
197
+ classpathentry.con container
198
+ }
92
199
  end
93
200
  end
94
201
  end
202
+ end
95
203
 
96
- # The only thing we need to look for is a change in the Buildfile.
97
- file(project.path_to('.project')=>Buildr.application.buildfile) do |task|
204
+ # The only thing we need to look for is a change in the Buildfile.
205
+ file(project.path_to('.project')=>Buildr.application.buildfile) do |task|
206
+ if (project.eclipse.natures.reject { |x| x.is_a?(Symbol) }.size > 0)
98
207
  info "Writing #{task.name}"
99
208
  File.open(task.name, 'w') do |file|
100
209
  xml = Builder::XmlMarkup.new(:target=>file, :indent=>2)
@@ -102,27 +211,24 @@ module Buildr
102
211
  xml.name project.id
103
212
  xml.projects
104
213
  xml.buildSpec do
105
- if scala
106
- xml.buildCommand do
107
- xml.name 'ch.epfl.lamp.sdt.core.scalabuilder'
108
- end
109
- else
214
+ project.eclipse.builders.each { |builder|
110
215
  xml.buildCommand do
111
- xml.name 'org.eclipse.jdt.core.javabuilder'
216
+ xml.name builder
112
217
  end
113
- end
218
+ }
114
219
  end
115
220
  xml.natures do
116
- xml.nature 'ch.epfl.lamp.sdt.core.scalanature' if scala
117
- xml.nature 'org.eclipse.jdt.core.javanature'
221
+ project.eclipse.natures.each { |nature|
222
+ xml.nature nature unless nature.is_a? Symbol
223
+ }
118
224
  end
119
225
  end
120
226
  end
121
227
  end
122
228
  end
123
-
124
229
  end
125
230
 
231
+
126
232
  # Writes 'classpathentry' tags in an xml file.
127
233
  # It converts tasks to paths.
128
234
  # It converts absolute paths to relative paths.
@@ -134,11 +240,11 @@ module Buildr
134
240
  @excludes = [ '**/.svn/', '**/CVS/' ].join('|')
135
241
  @paths_written = []
136
242
  end
137
-
243
+
138
244
  def write &block
139
245
  @xml.classpath &block
140
246
  end
141
-
247
+
142
248
  def con path
143
249
  @xml.classpathentry :kind=>'con', :path=>path
144
250
  end
@@ -166,7 +272,7 @@ module Buildr
166
272
  @xml.classpathentry :kind=>'src', :combineaccessrules=>'false', :path=>"/#{project_id}"
167
273
  end
168
274
  end
169
-
275
+
170
276
  def output target
171
277
  @xml.classpathentry :kind=>'output', :path=>relative(target)
172
278
  end
@@ -185,7 +291,7 @@ module Buildr
185
291
  @xml.classpathentry :kind=>'var', :path=>relative_lib_path, :sourcepath=>relative_source_path
186
292
  end
187
293
  end
188
-
294
+
189
295
  private
190
296
 
191
297
  # Find a path relative to the project's root directory.
@@ -214,9 +320,15 @@ module Buildr
214
320
  end
215
321
 
216
322
  end
217
- end # module Buildr
218
323
 
324
+ end # module Buildr
219
325
 
220
326
  class Buildr::Project
221
327
  include Buildr::Eclipse
222
328
  end
329
+
330
+ # Order is significant for auto-detection, from most specific to least
331
+ require 'buildr/ide/eclipse/plugin'
332
+ require 'buildr/ide/eclipse/scala'
333
+ require 'buildr/ide/eclipse/java'
334
+