Module: Buildr::Ivy::IvyExtension
- Includes:
- Extension
- Defined in:
- lib/buildr/ivy_extension.rb
Overview
The Ivy Buildr extension adding the new tasks for ivy.
To use ivy in a buildfile
do something like:
ENV['BUILDR_EXT_DIR'] ||= '../Ivy'
require 'buildr/ivy_extension'
define 'ivy_project' do
[...]
ivy.compile_conf('compile').test_conf('test').package_conf('prod', 'server')
[...]
end
-
This will add the
compile
configuration to compile and test tasks -
Add the
test
configuration to test compilation and execution -
include the artifacts from
prod
andserver
to any generated war or ear -
The ENV variable is needed to automatically configure the load path for ivy libs. It assumes that you have the following dir structure
[BUILDR_EXT_DIR]/ivy-home/jars
For more configuration options see IvyConfig.
Class Method Summary collapse
- .add_copy_tasks_for_publish(project) ⇒ Object
- .add_ivy_deps_to_java_tasks(project) ⇒ Object
- .add_manifest_to_distributeables(project) ⇒ Object
- .add_prod_libs_to_distributeables(project) ⇒ Object
-
.sort_dependencies(deps, ivy_deps, project_path) ⇒ Object
Sorts the dependencies in #deps replacing the old order.
Instance Method Summary collapse
-
#ivy ⇒ Object
Returns the
ivy
configuration for the project.
Class Method Details
.add_copy_tasks_for_publish(project) ⇒ Object
587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 |
# File 'lib/buildr/ivy_extension.rb', line 587 def add_copy_tasks_for_publish(project) if project.ivy.own_file? Buildr.projects.each do |current| current.packages.each do |pkg| target_file = current.ivy.name[pkg] || File.basename(pkg.name).gsub(/-#{project.version}/, '') taskname = current.path_to(project.ivy.publish_from, target_file) if taskname != pkg.name project.file taskname => pkg.name do verbose "Ivy copying '#{pkg.name}' to '#{taskname}' for publishing" FileUtils.mkdir File.dirname(taskname) unless File.directory?(File.dirname(taskname)) FileUtils.cp pkg.name, taskname end end project.task 'ivy:publish' => taskname end end end end |
.add_ivy_deps_to_java_tasks(project) ⇒ Object
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 |
# File 'lib/buildr/ivy_extension.rb', line 470 def add_ivy_deps_to_java_tasks(project) resolve_target = project.ivy.file_project.task('ivy:resolve') project.task :compiledeps => resolve_target do includes = project.ivy.compile_include excludes = project.ivy.compile_exclude types = project.ivy.compile_type confs = [project.ivy.compile_conf].flatten if deps = project.ivy.filter(confs, :type => types, :include => includes, :exclude => excludes) project.compile.with [deps, project.compile.dependencies].flatten sort_dependencies(project.compile.dependencies, deps, project.path_to('')) info "Ivy adding compile dependencies '#{confs.join(', ')}' to project '#{project.name}'" end end project.task :compile => "#{project.name}:compiledeps" project.task :testdeps => resolve_target do includes = project.ivy.test_include excludes = project.ivy.test_exclude types = project.ivy.test_type confs = [project.ivy.test_conf, project.ivy.compile_conf].flatten.uniq if deps = project.ivy.filter(confs, :type => types, :include => includes, :exclude => excludes) project.test.with [deps, project.test.dependencies].flatten sort_dependencies(project.test.dependencies, deps, project.path_to('')) sort_dependencies(project.test.compile.dependencies, deps, project.path_to('')) info "Ivy adding test dependencies '#{confs.join(', ')}' to project '#{project.name}'" end end project.task "test:compile" => "#{project.name}:testdeps" project.task :javadocdeps => resolve_target do confs = [project.ivy.test_conf, project.ivy.compile_conf].flatten.uniq if deps = project.ivy.deps(confs) project.javadoc.with deps info "Ivy adding javadoc dependencies '#{confs.join(', ')}' to project '#{project.name}'" end end project.task :javadoc => "#{project.name}:javadocdeps" [project.task(:eclipse), project.task(:idea), project.task(:idea7x)].each do |task| task.prerequisites.each{|p| p.enhance ["#{project.name}:compiledeps", "#{project.name}:testdeps"]} end end |
.add_manifest_to_distributeables(project) ⇒ Object
543 544 545 546 547 548 549 550 551 552 553 |
# File 'lib/buildr/ivy_extension.rb', line 543 def add_manifest_to_distributeables(project) pkgs = project.packages.find_all { |pkg| [:jar, :war, :ear].member? pkg.type } pkgs.each do |pkg| name = "#{pkg.name}manifest" task = project.task name => project.ivy.file_project.task('ivy:resolve') do pkg.with :manifest => project.manifest.merge(project.ivy.manifest) info "Adding manifest entries to package '#{pkg.name}'" end project.task :build => task end end |
.add_prod_libs_to_distributeables(project) ⇒ Object
555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 |
# File 'lib/buildr/ivy_extension.rb', line 555 def add_prod_libs_to_distributeables(project) pkgs = project.packages.find_all { |pkg| [:war].member? pkg.type } pkgs.each do |pkg| task = project.task "#{pkg.name}deps" => project.ivy.file_project.task('ivy:resolve') do includes = project.ivy.package_include excludes = project.ivy.package_exclude types = project.ivy.package_type confs = project.ivy.package_conf if deps = project.ivy.filter(confs, :type => types, :include => includes, :exclude => excludes) pkg.with :libs => [deps, pkg.libs].flatten info "Adding production libs from conf '#{confs.join(', ')}' to WAR '#{pkg.name}' in project '#{project.name}'" end end project.task :build => task end pkgs = project.packages.find_all { |pkg| [:ear].member? pkg.type } pkgs.each do |pkg| task = project.task "#{pkg.name}deps" => project.ivy.file_project.task('ivy:resolve') do includes = project.ivy.package_include excludes = project.ivy.package_exclude types = project.ivy.package_type confs = project.ivy.package_conf if deps = project.ivy.filter(confs, :type => types, :include => includes, :exclude => excludes) pkg.add deps, :type => :lib, :path => '' info "Adding production libs from conf '#{confs.join(', ')}' to EAR '#{pkg.name}' in project '#{project.name}'" end end project.task :build => task end end |
.sort_dependencies(deps, ivy_deps, project_path) ⇒ Object
Sorts the dependencies in #deps replacing the old order. Sorting is done as follows:
-
all dependencies that belong to the project identified by #project_path, .i.e. instrumented-classes, resources in the order the are contained in the array
-
all ivy dependencies identified by #ivy_deps
-
all dependencies added automatically by buildr
520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 |
# File 'lib/buildr/ivy_extension.rb', line 520 def sort_dependencies(deps, ivy_deps, project_path) old_deps = deps.dup belongs_to_project = /#{project_path}/ deps.sort! do |a, b| a_belongs_to_project = belongs_to_project.match(a.to_s) b_belongs_to_project = belongs_to_project.match(b.to_s) a_ivy = ivy_deps.member? a b_ivy = ivy_deps.member? b if a_belongs_to_project && !b_belongs_to_project -1 elsif !a_belongs_to_project && b_belongs_to_project 1 elsif a_ivy && !b_ivy -1 elsif !a_ivy && b_ivy 1 else old_deps.index(a) <=> old_deps.index(b) end end end |