ivy4r 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,19 @@
1
+ === 0.7.0 / 2009-07-20
2
+
3
+ * It is possible to register +post_resolve+ actions via blocks:
4
+ ivy.post_resolve {...}
5
+ * support for generic configuration syntax via +method_missing+:
6
+ Any method combination of TARGETS [:compile, :test, :package] and TYPES [:conf, :include, :exclude] is valid.
7
+ It is possible to set all confs at once:
8
+ +ivy.conf :compile => 'conf', :package => 'other', :test => ['still', 'other']
9
+ Or to set the complete package options:
10
+ +ivy.package :conf => 'prod', :include => /includepattern/, :exclude => /excludepattern/+
11
+ Or to set a specific value via a complete call like:
12
+ +ivy.compile_conf [...] or ivy.conf_test [...] or ivy.package.include [...]
13
+ * more include/exclude possibilities, support to include and exclude for compile and test targets using
14
+ +ivy.include :compile => [pattern list]+ or +ivy.exclude+
15
+ * small refactorings
16
+
1
17
  === 0.6.0 / 2009-07-08
2
18
 
3
19
  * added support for the +ide+ targets +eclipse+, +idea+ and +idea7x+
data/Rakefile CHANGED
@@ -12,6 +12,8 @@ hoe = Hoe.spec 'ivy4r' do |p|
12
12
  p.extra_deps << ['Antwrap', '>=0.7.0']
13
13
  p.extra_deps << ['ivy4r-jars', '>=1.0.0']
14
14
  p.extra_deps << ['facets', '>=2.5.2']
15
+ #p.extra_deps << ['thoughtbot-shoulda', '>=2.5.2']
16
+ #p.extra_deps << ['rr', '>=0.10.0']
15
17
  File.open(File.join(File.dirname(__FILE__), 'VERSION'), 'w') do |file|
16
18
  file.puts Ivy4r::VERSION
17
19
  end
@@ -4,7 +4,7 @@ module Buildr
4
4
  module Ivy
5
5
 
6
6
  # TODO extend extension to download ivy stuff with dependencies automatically
7
- # VERSION = '2.1.0-rc1'
7
+ # VERSION = '2.1.0-rc1'
8
8
 
9
9
  class << self
10
10
 
@@ -14,33 +14,41 @@ module Buildr
14
14
  setting
15
15
  end
16
16
 
17
- # def version
18
- # setting['version'] || VERSION
19
- # end
20
- # def dependencies
21
- # @dependencies ||= [
22
- # "org.apache.ivy:ivy:jar:#{version}",
23
- # 'com.jcraft:jsch:jar:1.41',
24
- # 'oro:oro:jar:2.08'
25
- # ]
26
- # end
17
+ # def version
18
+ # setting['version'] || VERSION
19
+ # end
20
+ # def dependencies
21
+ # @dependencies ||= [
22
+ # "org.apache.ivy:ivy:jar:#{version}",
23
+ # 'com.jcraft:jsch:jar:1.41',
24
+ # 'oro:oro:jar:2.08'
25
+ # ]
26
+ # end
27
27
  end
28
28
 
29
29
  class IvyConfig
30
+ TARGETS = [:compile, :test, :package]
31
+ TYPES = [:conf, :include, :exclude]
30
32
 
31
33
  attr_accessor :extension_dir, :resolved
32
34
 
35
+ attr_reader :post_resolve_task_list
36
+
33
37
  # Store the current project and initialize ivy ant wrapper
34
38
  def initialize(project)
35
39
  @project = project
36
40
  if project.parent.nil?
37
41
  @extension_dir = @project.base_dir
42
+ @post_resolve_task_list = []
38
43
  else
39
44
  @extension_dir = @project.parent.ivy.extension_dir
40
45
  @base_ivy = @project.parent.ivy unless own_file?
41
46
  end
47
+ @target_config = Hash.new do
48
+ |hash, key| hash[key] = {}
49
+ end
42
50
  end
43
-
51
+
44
52
  def enabled?
45
53
  @enabled ||= Ivy.setting('enabled') || true
46
54
  end
@@ -70,10 +78,14 @@ module Buildr
70
78
  end
71
79
 
72
80
  # Returns the artifacts for given configurations as array
81
+ # this is a post resolve task.
73
82
  def deps(*confs)
74
83
  configure
75
- pathid = "ivy.deps." + confs.join('.')
76
- ant.cachepath :conf => confs.join(','), :pathid => pathid
84
+ confs = confs.reject {|c| c.nil? || c.blank? }
85
+ unless confs.empty?
86
+ pathid = "ivy.deps." + confs.join('.')
87
+ ant.cachepath :conf => confs.join(','), :pathid => pathid
88
+ end
77
89
  end
78
90
 
79
91
  # Returns ivy info for configured ivy file using a new ant instance.
@@ -109,6 +121,8 @@ module Buildr
109
121
  else
110
122
  unless @resolved
111
123
  @resolved = ant.resolve :file => file
124
+ @project.send(:info, "Calling '#{post_resolve_tasks.size}' post_resolve tasks for '#{@project.name}'")
125
+ post_resolve_tasks.each { |p| p.call(self) }
112
126
  end
113
127
  end
114
128
  end
@@ -312,63 +326,112 @@ module Buildr
312
326
  end
313
327
  end
314
328
 
315
- # Set the configuration artifacts to use in package tasks like +:war+ or +:ear+.
316
- # <tt>project.ivy.package_conf('server', 'client')</tt>
317
- # or
318
- # <tt>project.ivy.package_conf(['server', 'client'])</tt>
319
- def package_conf(*package_conf)
320
- if package_conf.empty?
321
- @package_conf ||= [Ivy.setting('package.conf') || 'prod'].flatten.uniq
322
- else
323
- @package_conf = [package_conf].flatten.uniq
324
- self
325
- end
329
+ # Adds given block as post resolve action that is executed directly after #resolve has been called.
330
+ # Yields this ivy config object into block.
331
+ # <tt>project.ivy.post_resolve { |ivy| p "all deps:" + ivy.deps('all').join(", ") }</tt>
332
+ def post_resolve(&block)
333
+ post_resolve_tasks << block if block
326
334
  end
327
335
 
328
- # Sets the includes pattern(s) to use for packages. I.e.
329
- # <tt>project.ivy.package_include(/\.jar/, /\.gz/)</tt>
330
- def package_include(*includes)
331
- if includes.empty?
332
- @package_include ||= [Ivy.setting('package.include') || /\.jar/].flatten.uniq
333
- else
334
- @package_include = [includes].flatten.uniq
335
- self
336
+ # Filter artifacts for given configuration with provided filter values, this is a post resolve
337
+ # task like #deps.
338
+ # <tt>project.ivy.filter('server', 'client', :include => /b.*.jar/, :exclude => [/a\.jar/, /other.*\.jar/])</tt>
339
+ def filter(*confs)
340
+ filter = confs.last.kind_of?(Hash) ? confs.pop : {}
341
+ unless (filter.keys - [:include, :exclude]).empty?
342
+ raise ArgumentError, "Invalid filter use :include and/or :exclude only: given #{filter.keys.inspect}"
343
+ end
344
+ includes, excludes = filter[:include] || [], filter[:exclude] || []
345
+
346
+ artifacts = deps(*confs.flatten)
347
+ if artifacts
348
+ artifacts = artifacts.find_all do |lib|
349
+ lib = File.basename(lib)
350
+ includes = includes.reject {|i| i.nil? || i.blank? }
351
+ should_include = includes.empty? || includes.any? {|include| include === lib }
352
+ should_include && !excludes.any? {|exclude| exclude === lib}
353
+ end
336
354
  end
337
- end
338
355
 
339
- # Sets the exclude pattern(s) to use for packages. I.e.
340
- # <tt>project.ivy.package_exclude(/\.zip/, /\.tar/)</tt>
341
- def package_exclude(*excludes)
342
- if excludes.empty?
343
- @package_exclude ||= [Ivy.setting('package.exlude') || ''].flatten.uniq
356
+ artifacts
357
+ end
358
+
359
+ # :call-seq:
360
+ # for types:
361
+ # project.ivy.include(:compile => [/\.jar/, /\.gz/], :package => 'cglib.jar')
362
+ # project.ivy.exclude(:test => 'cglib.jar')
363
+ # project.ivy.conf(:compile => 'compile', :test => 'test', :package => 'prod')
364
+ # for targets:
365
+ # project.ivy.compile(:conf => 'compile', :exclude => /cglib.jar/)
366
+ # project.ivy.test(:conf => 'test')
367
+ # project.ivy.package(:conf => 'prod', :include => /.*.jar/, :exclude => /cglib.jar/)
368
+ # or verbose:
369
+ # project.ivy.compile_conf or project.ivy.conf_compile
370
+ # project.ivy.compile_include or project.ivy.include_compile
371
+ # the same for the other possible options.
372
+ #
373
+ # Uses #method_missing to handle the options.
374
+ # Generic handling of settings for +target+ and +type+. All calls in the form
375
+ # <tt>target_type({})</tt> or <tt>type_target({})</tt> are handled via this method see
376
+ # #TARGETS #TYPES for more information about valid targets and types.
377
+ def method_missing(methodname, *args, &block)
378
+ if block.nil? && valid_config_call?(methodname)
379
+ target, type = target(methodname), type(methodname)
380
+ if target && type
381
+ handle_variable(target, type, *args)
382
+ elsif target && args.size == 1 && args.last.kind_of?(Hash)
383
+ args[0].each { |type, value| handle_variable(target, type, *value) }
384
+ self
385
+ elsif type && args.size == 1 && args.last.kind_of?(Hash)
386
+ args[0].each { |target, value| handle_variable(target, type, *value) }
387
+ self
388
+ else
389
+ raise "Could not recognize config call for method '#{methodname}', args=#{args.inspect}"
390
+ end
344
391
  else
345
- @package_exclude = [excludes].flatten.uniq
346
- self
392
+ super.method_missing(methodname, *args, &block)
347
393
  end
348
394
  end
395
+
396
+ private
397
+ def target(targets)
398
+ t = targets.to_s.split('_').find { |t| TARGETS.member? t.to_sym }
399
+ t ? t.to_sym : nil
400
+ end
349
401
 
350
- # Set the configuration artifacts to use for compile tasks, added to <tt>compile.with</tt>
351
- # <tt>project.ivy.compile_conf('server', 'client')</tt>
352
- def compile_conf(*compile_conf)
353
- if compile_conf.empty?
354
- @compile_conf ||= [Ivy.setting('compile.conf') || 'compile'].flatten.uniq
355
- else
356
- @compile_conf = [compile_conf].flatten.uniq
357
- self
402
+ def type(types)
403
+ t = types.to_s.split('_').find { |t| TYPES.member? t.to_sym }
404
+ t ? t.to_sym : nil
405
+ end
406
+
407
+ def valid_config_call?(method_name)
408
+ valid_calls = []
409
+ TYPES.each do|type|
410
+ TARGETS.each do|target|
411
+ valid_calls << type.to_s << target.to_s << "#{type}_#{target}" << "#{target}_#{type}"
412
+ end
358
413
  end
414
+ valid_calls.member? method_name.to_s
359
415
  end
360
416
 
361
- # Set the configuration artifacts to use for test tasks, added to <tt>test.compile.with</tt>
362
- # and <tt>test.with</tt>. Note that all artifacts from #compile_conf are added automatically.
363
- # <tt>project.ivy.test_conf('server', 'test')</tt>
364
- def test_conf(*test_conf)
365
- if test_conf.empty?
366
- @test_conf ||= [Ivy.setting('test.conf') || 'test'].flatten.uniq
417
+ # Sets a variable for given basename and type to given values. If values are empty returns the
418
+ # current value.
419
+ # I.e. <tt>handle_variable(:package, :include, /blua.*\.jar/, /da.*\.jar/)</tt>
420
+ def handle_variable(target, type, *values)
421
+ unless TARGETS.member?(target) && TYPES.member?(type)
422
+ raise ArgumentError, "Unknown config value for target #{target.inspect} and type #{type.inspect}"
423
+ end
424
+ if values.empty?
425
+ @target_config[target][type] ||= [Ivy.setting("#{target.to_s}.#{type.to_s}") || ''].flatten.uniq
367
426
  else
368
- @test_conf = [test_conf].flatten.uniq
427
+ @target_config[target][type] = [values].flatten.uniq
369
428
  self
370
429
  end
371
430
  end
431
+
432
+ def post_resolve_tasks
433
+ @base_ivy ? @base_ivy.post_resolve_task_list : post_resolve_task_list
434
+ end
372
435
  end
373
436
 
374
437
  =begin rdoc
@@ -398,24 +461,34 @@ For more configuration options see IvyConfig.
398
461
  def add_ivy_deps_to_java_tasks(project)
399
462
  resolve_target = project.ivy.file_project.task('ivy:resolve')
400
463
  project.task :compiledeps => resolve_target do
401
- compile_conf = [project.ivy.compile_conf].flatten
402
- project.compile.with project.ivy.deps(compile_conf)
403
- info "Ivy adding compile dependencies '#{compile_conf.join(', ')}' to project '#{project.name}'"
464
+ includes = project.ivy.compile_include
465
+ excludes = project.ivy.compile_exclude
466
+ confs = [project.ivy.compile_conf].flatten
467
+ if deps = project.ivy.filter(confs, :include => includes, :exclude => excludes)
468
+ project.compile.with deps
469
+ info "Ivy adding compile dependencies '#{confs.join(', ')}' to project '#{project.name}'"
470
+ end
404
471
  end
405
472
 
406
473
  project.task :compile => "#{project.name}:compiledeps"
407
474
 
408
475
  project.task :testdeps => resolve_target do
476
+ includes = project.ivy.test_include
477
+ excludes = project.ivy.test_exclude
409
478
  confs = [project.ivy.test_conf, project.ivy.compile_conf].flatten.uniq
410
- project.test.with project.ivy.deps(confs)
411
- info "Ivy adding test dependencies '#{confs.join(', ')}' to project '#{project.name}'"
479
+ if deps = project.ivy.filter(confs, :include => includes, :exclude => excludes)
480
+ project.test.with deps
481
+ info "Ivy adding test dependencies '#{confs.join(', ')}' to project '#{project.name}'"
482
+ end
412
483
  end
413
484
  project.task "test:compile" => "#{project.name}:testdeps"
414
485
 
415
486
  project.task :javadocdeps => resolve_target do
416
487
  confs = [project.ivy.test_conf, project.ivy.compile_conf].flatten.uniq
417
- project.javadoc.with project.ivy.deps(confs)
418
- info "Ivy adding javadoc dependencies '#{confs.join(', ')}' to project '#{project.name}'"
488
+ if deps = project.ivy.deps(confs)
489
+ project.javadoc.with deps
490
+ info "Ivy adding javadoc dependencies '#{confs.join(', ')}' to project '#{project.name}'"
491
+ end
419
492
  end
420
493
  project.task :javadoc => "#{project.name}:javadocdeps"
421
494
 
@@ -437,22 +510,17 @@ For more configuration options see IvyConfig.
437
510
  end
438
511
 
439
512
  def add_prod_libs_to_distributeables(project)
440
- includes = project.ivy.package_include
441
- excludes = project.ivy.package_exclude
442
513
  pkgs = project.packages.find_all { |pkg| [:war, :ear].member? pkg.type }
443
514
  pkgs.each do |pkg|
444
515
  name = "#{pkg.name}deps"
445
516
  task = project.task name => project.ivy.file_project.task('ivy:resolve') do
517
+ includes = project.ivy.package_include
518
+ excludes = project.ivy.package_exclude
446
519
  confs = project.ivy.package_conf
447
- libs = project.ivy.deps(confs).find_all do |lib|
448
- lib = File.basename(lib)
449
- use = includes.any? {|include| include === lib } && !excludes.any? {|exclude| exclude === lib}
450
- verbose "Including '#{lib}' from package '#{pkg}' in project '#{project.name}'" if use
451
- info "Excluding '#{lib}' from package '#{pkg}' in project '#{project.name}'" unless use
452
- use
520
+ if deps = project.ivy.filter(confs, :include => includes, :exclude => excludes)
521
+ pkg.with :libs => deps
522
+ info "Adding production libs from conf '#{confs.join(', ')}' to package '#{pkg.name}' in project '#{project.name}'"
453
523
  end
454
- pkg.with :libs => libs
455
- info "Adding production libs from conf '#{confs.join(', ')}' to package '#{pkg.name}' in project '#{project.name}'"
456
524
  end
457
525
  project.task :build => task
458
526
  end
data/lib/ivy4r.rb CHANGED
@@ -35,7 +35,7 @@ is
35
35
  }
36
36
  =end
37
37
  class Ivy4r
38
- VERSION = '0.6.0'
38
+ VERSION = '0.7.0'
39
39
 
40
40
  # Set the ant home directory to load ant classes from if no custom __antwrap__ is provided
41
41
  # and the default provided ant version 1.7.1 should not be used.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ivy4r
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Klaas Prause
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-08 00:00:00 +02:00
12
+ date: 2009-07-21 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency