lib/buildr/ivy_extension.rb in ivy4r-0.12.8 vs lib/buildr/ivy_extension.rb in ivy4r-0.12.9
- old
+ new
@@ -469,36 +469,36 @@
end
def valid_config_call?(method_name)
valid_calls = []
TYPES.each do|type|
- TARGETS.each do|target|
- valid_calls << type.to_s << target.to_s << "#{type}_#{target}" << "#{target}_#{type}"
+ TARGETS.each do|target|
+ valid_calls << type.to_s << target.to_s << "#{type}_#{target}" << "#{target}_#{type}"
+ end
+ end
+ valid_calls.member? method_name.to_s
end
- end
- valid_calls.member? method_name.to_s
- end
- # Sets a variable for given basename and type to given values. If values are empty returns the
- # current value.
- # I.e. <tt>handle_variable(:package, :include, /blua.*\.jar/, /da.*\.jar/)</tt>
- def handle_variable(target, type, *values)
- unless TARGETS.member?(target) && TYPES.member?(type)
- raise ArgumentError, "Unknown config value for target #{target.inspect} and type #{type.inspect}"
- end
- if values.empty?
- @target_config[target][type] ||= [Ivy.setting("#{target.to_s}.#{type.to_s}") || ''].flatten.uniq
- else
- @target_config[target][type] = [values].flatten.uniq
- self
- end
- end
+ # Sets a variable for given basename and type to given values. If values are empty returns the
+ # current value.
+ # I.e. <tt>handle_variable(:package, :include, /blua.*\.jar/, /da.*\.jar/)</tt>
+ def handle_variable(target, type, *values)
+ unless TARGETS.member?(target) && TYPES.member?(type)
+ raise ArgumentError, "Unknown config value for target #{target.inspect} and type #{type.inspect}"
+ end
+ if values.empty?
+ @target_config[target][type] ||= [Ivy.setting("#{target.to_s}.#{type.to_s}") || ''].flatten.uniq
+ else
+ @target_config[target][type] = [values].flatten.uniq
+ self
+ end
+ end
- def post_resolve_tasks
- @base_ivy ? @base_ivy.post_resolve_task_list : post_resolve_task_list
- end
-end
+ def post_resolve_tasks
+ @base_ivy ? @base_ivy.post_resolve_task_list : post_resolve_task_list
+ end
+ end
=begin rdoc
The Ivy Buildr extension adding the new tasks for ivy.
To use ivy in a +buildfile+ do something like:
@@ -516,292 +516,292 @@
- The ENV variable is needed to automatically configure the load path for ivy libs.
It assumes that you have the following dir structure <tt>[BUILDR_EXT_DIR]/ivy-home/jars</tt>
For more configuration options see IvyConfig.
=end
-module IvyExtension
- include Buildr::Extension
+ module IvyExtension
+ include Buildr::Extension
- class << self
+ class << self
- 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
+ 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 :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 :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 :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
+ [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
- # Sorts the dependencies in #deps replacing the old order.
- # Sorting is done as follows:
- # 1. 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
- # 2. all ivy dependencies identified by #ivy_deps
- # 3. all dependencies added automatically by buildr
- 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
+ # Sorts the dependencies in #deps replacing the old order.
+ # Sorting is done as follows:
+ # 1. 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
+ # 2. all ivy dependencies identified by #ivy_deps
+ # 3. all dependencies added automatically by buildr
+ 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)
+ 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
- end
- end
- def add_manifest_to_distributeables(project)
- pkgs = project.packages.find_all { |pkg| ['jar', 'war', 'ear'].member? pkg.type.to_s }
- pkgs.each do |pkg|
- name = "#{pkg.name}manifest"
- task = project.task name => project.ivy.file_project.task('ivy:resolve') do
- if pkg.manifest # source jars have no manifest, only add to existing manifest files
- pkg.with :manifest => pkg.manifest.merge(project.manifest.merge(project.ivy.manifest))
- info "Adding manifest entries to package '#{pkg.name}'"
- else
- info "Could not merge info to package '#{pkg.to_s}' it has no manifest!"
+ def add_manifest_to_distributeables(project)
+ pkgs = project.packages.find_all { |pkg| ['jar', 'war', 'ear'].member? pkg.type.to_s }
+ pkgs.each do |pkg|
+ name = "#{pkg.name}manifest"
+ task = project.task name => project.ivy.file_project.task('ivy:resolve') do
+ if pkg.manifest # source jars have no manifest, only add to existing manifest files
+ pkg.with :manifest => pkg.manifest.merge(project.manifest.merge(project.ivy.manifest))
+ info "Adding manifest entries to package '#{pkg.name}'"
+ else
+ info "Could not merge info to package '#{pkg.to_s}' it has no manifest!"
+ end
+ end
+ project.task :build => task
end
end
- project.task :build => task
- end
- end
- def add_prod_libs_to_distributeables(project)
- pkgs = project.packages.find_all { |pkg| ['war'].member? pkg.type.to_s }
- 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}'"
+ def add_prod_libs_to_distributeables(project)
+ pkgs = project.packages.find_all { |pkg| ['war'].member? pkg.type.to_s }
+ 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
- end
- project.task :build => task
- end
- pkgs = project.packages.find_all { |pkg| ['ear'].member? pkg.type.to_s }
- 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}'"
+ pkgs = project.packages.find_all { |pkg| ['ear'].member? pkg.type.to_s }
+ 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
- project.task :build => task
- end
- end
- def add_copy_tasks_for_publish(project)
- ivy_project = project
- until ivy_project.ivy.own_file?
- ivy_project = ivy_project.parent
- end
- project.packages.each do |pkg|
- target_file = project.ivy.publish[pkg] || File.basename(pkg.name).gsub(/-#{project.version}/, '')
- taskname = ivy_project.path_to(ivy_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_p File.dirname(taskname) unless File.directory?(File.dirname(taskname))
- FileUtils.cp pkg.name, taskname
+ def add_copy_tasks_for_publish(project)
+ ivy_project = project
+ until ivy_project.ivy.own_file?
+ ivy_project = ivy_project.parent
end
- end
+ project.packages.each do |pkg|
+ target_file = project.ivy.publish[pkg] || File.basename(pkg.name).gsub(/-#{project.version}/, '')
+ taskname = ivy_project.path_to(ivy_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_p File.dirname(taskname) unless File.directory?(File.dirname(taskname))
+ FileUtils.cp pkg.name, taskname
+ end
+ end
- ivy_project.task 'ivy:publish' => taskname
+ ivy_project.task 'ivy:publish' => taskname
+ end
+ end
end
- end
- end
- # Returns the +ivy+ configuration for the project. Use this to configure Ivy.
- # see IvyConfig for more details about configuration options.
- def ivy
- @ivy_config ||= IvyConfig.new(self)
- end
+ # Returns the +ivy+ configuration for the project. Use this to configure Ivy.
+ # see IvyConfig for more details about configuration options.
+ def ivy
+ @ivy_config ||= IvyConfig.new(self)
+ end
- first_time do
- namespace 'ivy' do
- desc 'Resolves the ivy dependencies'
- task :resolve
+ first_time do
+ namespace 'ivy' do
+ desc 'Resolves the ivy dependencies'
+ task :resolve
- desc 'Publish the artifacts to ivy repository as defined by environment'
- task :publish
+ desc 'Publish the artifacts to ivy repository as defined by environment'
+ task :publish
- desc 'Creates a dependency report for the project'
- task :report
+ desc 'Creates a dependency report for the project'
+ task :report
- desc 'Clean the local Ivy cache and the local ivy repository'
- task :clean
+ desc 'Clean the local Ivy cache and the local ivy repository'
+ task :clean
- desc 'Creates default Maven POM for project from ivy.xml'
- task :makepom
+ desc 'Creates default Maven POM for project from ivy.xml'
+ task :makepom
- desc 'Clean the local Ivy result cache to force execution of ivy targets'
- task :clean_result_cache
+ desc 'Clean the local Ivy result cache to force execution of ivy targets'
+ task :clean_result_cache
- desc 'Enable the local Ivy result cache by creating the marker file'
- task :enable_result_cache
+ desc 'Enable the local Ivy result cache by creating the marker file'
+ task :enable_result_cache
- desc 'Disable the local Ivy result cache by removing the marker file'
- task :disable_result_cache
- end
- end
+ desc 'Disable the local Ivy result cache by removing the marker file'
+ task :disable_result_cache
+ end
+ end
- after_define do |project|
- if project.ivy.enabled?
- IvyExtension.add_ivy_deps_to_java_tasks(project)
- IvyExtension.add_manifest_to_distributeables(project)
- IvyExtension.add_prod_libs_to_distributeables(project)
- IvyExtension.add_copy_tasks_for_publish(project)
+ after_define do |project|
+ if project.ivy.enabled?
+ IvyExtension.add_ivy_deps_to_java_tasks(project)
+ IvyExtension.add_manifest_to_distributeables(project)
+ IvyExtension.add_prod_libs_to_distributeables(project)
+ IvyExtension.add_copy_tasks_for_publish(project)
- namespace 'ivy' do
- task :configure do
- project.ivy.configure
- end
+ namespace 'ivy' do
+ task :configure do
+ project.ivy.configure
+ end
- task :clean => :configure do
- # TODO This is redundant, refactor ivy_ant_wrap and this to use a single config object
- rm_rf project.path_to(:reports, 'ivy')
- project.ivy.cleancache
- end
+ task :clean => :configure do
+ # TODO This is redundant, refactor ivy_ant_wrap and this to use a single config object
+ rm_rf project.path_to(:reports, 'ivy')
+ project.ivy.cleancache
+ end
- task :clean_result_cache do
- project.send(:info, "Deleting IVY result cache dir '#{project.ivy.result_cache_dir}'")
- rm_rf project.ivy.result_cache_dir
- end
+ task :clean_result_cache do
+ project.send(:info, "Deleting IVY result cache dir '#{project.ivy.result_cache_dir}'")
+ rm_rf project.ivy.result_cache_dir
+ end
- task :enable_result_cache do
- project.send(:info, "Creating IVY caching marker file '#{project.ivy.caching_marker}'")
- touch project.ivy.caching_marker
- end
+ task :enable_result_cache do
+ project.send(:info, "Creating IVY caching marker file '#{project.ivy.caching_marker}'")
+ touch project.ivy.caching_marker
+ end
- task :disable_result_cache do
- project.send(:info, "Deleting IVY caching marker file '#{project.ivy.caching_marker}'")
- rm_f project.ivy.caching_marker
- end
+ task :disable_result_cache do
+ project.send(:info, "Deleting IVY caching marker file '#{project.ivy.caching_marker}'")
+ rm_f project.ivy.caching_marker
+ end
- task :resolve => "#{project.name}:ivy:configure" do
- project.ivy.__resolve__
- end
+ task :resolve => "#{project.name}:ivy:configure" do
+ project.ivy.__resolve__
+ end
- task :report => "#{project.name}:ivy:resolve" do
- project.ivy.report
- end
+ task :report => "#{project.name}:ivy:resolve" do
+ project.ivy.report
+ end
- task :publish => "#{project.name}:ivy:resolve" do
- project.ivy.__publish__
- end
+ task :publish => "#{project.name}:ivy:resolve" do
+ project.ivy.__publish__
+ end
- task :makepom => "#{project.name}:ivy:resolve" do
- project.ivy.makepom
+ task :makepom => "#{project.name}:ivy:resolve" do
+ project.ivy.makepom
+ end
+ end
end
end
end
- end
-end
-# Global targets that are not bound to a project
-namespace 'ivy' do
- task :clean do
- Buildr.projects.find_all{ |p| p.ivy.own_file? }.each do |project|
- project.task('ivy:clean').invoke
- end
- end
+ # Global targets that are not bound to a project
+ namespace 'ivy' do
+ task :clean do
+ Buildr.projects.find_all{ |p| p.ivy.own_file? }.each do |project|
+ project.task('ivy:clean').invoke
+ end
+ end
- task :clean_result_cache do
- Buildr.projects.find_all{ |p| p.ivy.own_file? }.each do |project|
- project.task('ivy:clean_result_cache').invoke
- end
- end
+ task :clean_result_cache do
+ Buildr.projects.find_all{ |p| p.ivy.own_file? }.each do |project|
+ project.task('ivy:clean_result_cache').invoke
+ end
+ end
- task :enable_result_cache do
- Buildr.projects.find_all{ |p| p.ivy.own_file? }.each do |project|
- project.task('ivy:enable_result_cache').invoke
- end
- end
+ task :enable_result_cache do
+ Buildr.projects.find_all{ |p| p.ivy.own_file? }.each do |project|
+ project.task('ivy:enable_result_cache').invoke
+ end
+ end
- task :disable_result_cache do
- Buildr.projects.find_all{ |p| p.ivy.own_file? }.each do |project|
- project.task('ivy:disable_result_cache').invoke
- end
- end
+ task :disable_result_cache do
+ Buildr.projects.find_all{ |p| p.ivy.own_file? }.each do |project|
+ project.task('ivy:disable_result_cache').invoke
+ end
+ end
- task :resolve do
- info "Resolving all distinct ivy files"
- Buildr.projects.find_all{ |p| p.ivy.own_file? }.each do |project|
- project.task('ivy:resolve').invoke
- end
- end
+ task :resolve do
+ info "Resolving all distinct ivy files"
+ Buildr.projects.find_all{ |p| p.ivy.own_file? }.each do |project|
+ project.task('ivy:resolve').invoke
+ end
+ end
- task :publish => :package do
- info "Publishing all distinct ivy files"
- Buildr.projects.find_all{ |p| p.ivy.own_file? }.each do |project|
- project.task('ivy:publish').invoke
+ task :publish => :package do
+ info "Publishing all distinct ivy files"
+ Buildr.projects.find_all{ |p| p.ivy.own_file? }.each do |project|
+ project.task('ivy:publish').invoke
+ end
+ end
+
+ task :makepom => :resolve do
+ info "Create Maven POMs for all projects with distinct ivy files"
+ Buildr.projects.find_all{ |p| p.ivy.own_file? }.each do |project|
+ project.task('ivy:makepom').invoke
+ end
+ end
end
- end
- task :makepom => :resolve do
- info "Create Maven POMs for all projects with distinct ivy files"
- Buildr.projects.find_all{ |p| p.ivy.own_file? }.each do |project|
- project.task('ivy:makepom').invoke
+ class Buildr::Project # :nodoc:
+ include IvyExtension
end
end
-end
-
-class Buildr::Project # :nodoc:
- include IvyExtension
-end
-end
end