Class: Buildr::Ivy::IvyConfig
- Inherits:
-
Object
- Object
- Buildr::Ivy::IvyConfig
- Defined in:
- lib/buildr/ivy_extension.rb
Constant Summary collapse
- TARGETS =
[:compile, :test, :package]
- TYPES =
[:conf, :type, :include, :exclude]
Instance Attribute Summary collapse
-
#extension_dir ⇒ Object
Returns the value of attribute extension_dir.
-
#post_resolve_task_list ⇒ Object
readonly
Returns the value of attribute post_resolve_task_list.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
-
#publish_mappings ⇒ Object
readonly
Hash of all artifacts to publish with mapping from artifact name to ivy publish name.
-
#resolved ⇒ Object
Returns the value of attribute resolved.
Instance Method Summary collapse
-
#__publish__ ⇒ Object
Publishs the project as defined in ivy file if it has not been published already.
-
#__resolve__ ⇒ Object
Resolves the configured file once.
-
#caching_enabled? ⇒ Boolean
Returns if ivy result caching is enabled via build or user properties or by existence of the marker file.
-
#caching_marker ⇒ Object
Returns the use ivy result caching marker file.
-
#cleancache ⇒ Object
Cleans the ivy cache.
-
#configure ⇒ Object
Configures the ivy instance with additional properties and loading the settings file if it was provided.
-
#deps(*args) ⇒ Object
Returns the artifacts for given configurations as array this is a post resolve task.
- #enabled? ⇒ Boolean
-
#file ⇒ Object
Returns the absolute ivy file path to use.
-
#file_project ⇒ Object
Returns name of the project the ivy file belongs to.
-
#filter(*confs) ⇒ Object
Filter artifacts for given configuration with provided filter values, this is a post resolve task like #deps.
- #home ⇒ Object
-
#info ⇒ Object
Returns ivy info for configured ivy file using a new ivy4r instance.
-
#initialize(project) ⇒ IvyConfig
constructor
Store the current project and initialize ivy ant wrapper.
-
#ivy4r ⇒ Object
Returns the correct ivy4r instance to use, if project has its own ivy file uses the ivy file of project, if not uses the ivy file of parent project.
-
#ivy_xml_filename ⇒ Object
The basic file name to use in project dir as ivy.xml file.
- #lib_dir ⇒ Object
-
#local_repository(*local_repository) ⇒ Object
Sets the local repository for ivy files.
-
#makepom(filename = 'pom.xml') ⇒ Object
Simple call to makepom with projects ivy.xml as input.
-
#manifest ⇒ Object
Returns the additional infos for the manifest file.
-
#method_missing(methodname, *args, &block) ⇒ Object
:call-seq: for types: project.ivy.include(:compile => [/.jar/, /.gz/], :package => ‘cglib.jar’) project.ivy.exclude(:test => ‘cglib.jar’) project.ivy.conf(:compile => ‘compile’, :test => ‘test’, :package => ‘prod’) for targets: project.ivy.compile(:conf => ‘compile’, :exclude => /cglib.jar/) project.ivy.test(:conf => ‘test’) project.ivy.package(:conf => ‘prod’, :include => /.*.jar/, :exclude => /cglib.jar/) or verbose: project.ivy.compile_conf or project.ivy.conf_compile project.ivy.compile_include or project.ivy.include_compile the same for the other possible options.
- #name(*args) ⇒ Object
- #own_file? ⇒ Boolean
-
#post_resolve(&block) ⇒ Object
Adds given block as post resolve action that is executed directly after #resolve has been called.
-
#properties(*properties) ⇒ Object
Sets the additional properties for the ivy process use a Hash with the properties to set.
-
#publish(*publish_mappings) ⇒ Object
:call-seq: ivy.publish(package(:jar) => ‘new_name_without_version_number.jar’) #deprecated! ivy.name(package(:jar) => ‘new_name_without_version_number.jar’).
-
#publish_from(*publish_dir) ⇒ Object
Sets the directory to publish artifacts from.
-
#publish_options(*options, &block) ⇒ Object
Sets the publish options to use for the project.
-
#report ⇒ Object
Creates the standard ivy dependency report.
-
#report_dir(*report_dir) ⇒ Object
Sets the directory to create dependency reports in.
-
#result_cache_dir ⇒ Object
Returns the dir to store ivy caching results in.
-
#revision(*revision, &block) ⇒ Object
Sets the revision to use for the project, this is useful for development revisions that have an appended timestamp or any other dynamic revisioning.
- #settings ⇒ Object
-
#status(*status, &block) ⇒ Object
Sets the status to use for the project, this is useful for custom status handling like integration, alpha, gold.
Constructor Details
#initialize(project) ⇒ IvyConfig
Store the current project and initialize ivy ant wrapper
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/buildr/ivy_extension.rb', line 36 def initialize(project) @project = project @post_resolve_task_list = [] @extension_dir = project.parent.nil? ? @project.base_dir : @project.parent.ivy.extension_dir @base_ivy = @project.parent.ivy unless own_file? @target_config = Hash.new do |hash, key| hash[key] = {} end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(methodname, *args, &block) ⇒ Object
:call-seq: for types:
project.ivy.include(:compile => [/\.jar/, /\.gz/], :package => 'cglib.jar')
project.ivy.exclude(:test => 'cglib.jar')
project.ivy.conf(:compile => 'compile', :test => 'test', :package => 'prod')
for targets:
project.ivy.compile(:conf => 'compile', :exclude => /cglib.jar/)
project.ivy.test(:conf => 'test')
project.ivy.package(:conf => 'prod', :include => /.*.jar/, :exclude => /cglib.jar/)
or verbose:
project.ivy.compile_conf or project.ivy.conf_compile
project.ivy.compile_include or project.ivy.include_compile
the same for the other possible options.
Uses #method_missing to handle the options. Generic handling of settings for target
and type
. All calls in the form target_type({})
or type_target({})
are handled via this method see #TARGETS #TYPES for more information about valid targets and types.
441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 |
# File 'lib/buildr/ivy_extension.rb', line 441 def method_missing(methodname, *args, &block) if block.nil? && valid_config_call?(methodname) target, type = target(methodname), type(methodname) if target && type handle_variable(target, type, *args) elsif target && args.size == 1 && args.last.kind_of?(Hash) args[0].each { |type, value| handle_variable(target, type, *value) } self elsif type && args.size == 1 && args.last.kind_of?(Hash) args[0].each { |target, value| handle_variable(target, type, *value) } self else raise "Could not recognize config call for method '#{methodname}', args=#{args.inspect}" end else super.method_missing(methodname, *args, &block) end end |
Instance Attribute Details
#extension_dir ⇒ Object
Returns the value of attribute extension_dir.
26 27 28 |
# File 'lib/buildr/ivy_extension.rb', line 26 def extension_dir @extension_dir end |
#post_resolve_task_list ⇒ Object (readonly)
Returns the value of attribute post_resolve_task_list.
28 29 30 |
# File 'lib/buildr/ivy_extension.rb', line 28 def post_resolve_task_list @post_resolve_task_list end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
30 31 32 |
# File 'lib/buildr/ivy_extension.rb', line 30 def project @project end |
#publish_mappings ⇒ Object (readonly)
Hash of all artifacts to publish with mapping from artifact name to ivy publish name
33 34 35 |
# File 'lib/buildr/ivy_extension.rb', line 33 def publish_mappings @publish_mappings end |
#resolved ⇒ Object
Returns the value of attribute resolved.
26 27 28 |
# File 'lib/buildr/ivy_extension.rb', line 26 def resolved @resolved end |
Instance Method Details
#__publish__ ⇒ Object
Publishs the project as defined in ivy file if it has not been published already
197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/buildr/ivy_extension.rb', line 197 def __publish__ if @base_ivy @base_ivy.__publish__ else unless @published = {:status => status, :pubrevision => revision, :artifactspattern => "#{publish_from}/[artifact].[ext]"} = * ivy4r.publish @published = true end end end |
#__resolve__ ⇒ Object
Resolves the configured file once.
154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/buildr/ivy_extension.rb', line 154 def __resolve__ if @base_ivy @base_ivy.__resolve__ else unless @resolved @resolved = ivy4r.resolve :file => file @project.send(:info, "Calling '#{post_resolve_tasks.size}' post_resolve tasks for '#{@project.name}'") post_resolve_tasks.each { |p| p.call(self) } end end end |
#caching_enabled? ⇒ Boolean
Returns if ivy result caching is enabled via build or user properties or by existence of the marker file.
80 81 82 |
# File 'lib/buildr/ivy_extension.rb', line 80 def caching_enabled? Ivy.user_setting('caching.enabled') || Ivy.setting('caching.enabled') || File.exists?(caching_marker) end |
#caching_marker ⇒ Object
Returns the use ivy result caching marker file
85 86 87 |
# File 'lib/buildr/ivy_extension.rb', line 85 def caching_marker @project.path_to('use_ivy_caching') end |
#cleancache ⇒ Object
Cleans the ivy cache
185 186 187 |
# File 'lib/buildr/ivy_extension.rb', line 185 def cleancache ivy4r.cleancache end |
#configure ⇒ Object
Configures the ivy instance with additional properties and loading the settings file if it was provided
140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/buildr/ivy_extension.rb', line 140 def configure if @base_ivy @base_ivy.configure else unless @configured ivy4r.property['ivy.status'] = status if status ivy4r.property['ivy.home'] = home if home properties.each {|key, value| ivy4r.property[key.to_s] = value } @configured = ivy4r.settings :file => settings if settings end end end |
#deps(*args) ⇒ Object
Returns the artifacts for given configurations as array this is a post resolve task. the arguments are checked for the following:
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/buildr/ivy_extension.rb', line 107 def deps(*args) if args.size == 1 && args[0].kind_of?(Hash) confs, types = [args[0][:conf]].flatten, [args[0][:type]].flatten elsif args.size == 2 && args[0].kind_of?(Array) && args[1].kind_of?(Array) confs, types = args[0], args[1] else confs, types = args.flatten, [] end [confs, types].each do |t| t.reject! {|c| c.nil? || c.empty? } end unless confs.empty? pathid = "ivy.deps." + confs.join('.') + '.' + types.join('.') params = {:conf => confs.join(','), :pathid => pathid} params[:type] = types.join(',') unless types.nil? || types.size == 0 ivy4r.cachepath params end end |
#enabled? ⇒ Boolean
47 48 49 50 |
# File 'lib/buildr/ivy_extension.rb', line 47 def enabled? setting = Ivy.setting('enabled') @enabled ||= setting.nil? ? true : setting end |
#file ⇒ Object
Returns the absolute ivy file path to use
229 230 231 |
# File 'lib/buildr/ivy_extension.rb', line 229 def file @project.path_to(ivy_xml_filename) end |
#file_project ⇒ Object
Returns name of the project the ivy file belongs to.
97 98 99 |
# File 'lib/buildr/ivy_extension.rb', line 97 def file_project own_file? ? @project : @base_ivy.file_project end |
#filter(*confs) ⇒ Object
Filter artifacts for given configuration with provided filter values, this is a post resolve task like #deps. project.ivy.filter('server', 'client', :include => /b.*.jar/, :exclude => [/a\.jar/, /other.*\.jar/])
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 |
# File 'lib/buildr/ivy_extension.rb', line 403 def filter(*confs) filter = confs.last.kind_of?(Hash) ? confs.pop : {} unless (filter.keys - (TYPES - [:conf])).empty? raise ArgumentError, "Invalid filter use :include and/or :exclude only: given #{filter.keys.inspect}" end includes, excludes, types = filter[:include] || [], filter[:exclude] || [], filter[:type] || [] artifacts = deps(confs.flatten, types.flatten) if artifacts artifacts = artifacts.find_all do |lib| lib = File.basename(lib) includes = includes.reject {|i| i.nil? || (i.respond_to?(:empty?) && i.empty?) || (i.respond_to?(:source) && i.source.empty?) } should_include = includes.empty? || includes.any? {|include| include === lib } should_include && !excludes.any? {|exclude| exclude === lib} end end artifacts end |
#home ⇒ Object
210 211 212 |
# File 'lib/buildr/ivy_extension.rb', line 210 def home @ivy_home_dir ||= Ivy.setting('home.dir') end |
#info ⇒ Object
Returns ivy info for configured ivy file using a new ivy4r instance.
130 131 132 133 134 135 136 137 |
# File 'lib/buildr/ivy_extension.rb', line 130 def info if @base_ivy @base_ivy.info else configure ivy4r.info :file => file end end |
#ivy4r ⇒ Object
Returns the correct ivy4r instance to use, if project has its own ivy file uses the ivy file of project, if not uses the ivy file of parent project. Use this for low-level access to ivy functions as needed, i.e. in post_resolve
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/buildr/ivy_extension.rb', line 59 def ivy4r unless @ivy4r if own_file? @ivy4r = ::Ivy4r.new do |i| i.ant = @project.ant('ivy') if caching_enabled? i.cache_dir = result_cache_dir @project.send(:info, "Using IVY result caching in dir '#{i.cache_dir}'") end end @ivy4r.lib_dir = lib_dir if lib_dir @ivy4r.project_dir = @extension_dir else @ivy4r = @project.parent.ivy.ivy4r end end @ivy4r end |
#ivy_xml_filename ⇒ Object
The basic file name to use in project dir as ivy.xml file. Normally this should be ivy.xml If the file resides in a sub directory the relative path from project can be set with this method
224 225 226 |
# File 'lib/buildr/ivy_extension.rb', line 224 def ivy_xml_filename @ivy_file ||= Ivy.setting('ivy.file') || 'ivy.xml' end |
#lib_dir ⇒ Object
214 215 216 |
# File 'lib/buildr/ivy_extension.rb', line 214 def lib_dir @lib_dir ||= Ivy.setting('lib.dir') end |
#local_repository(*local_repository) ⇒ Object
Sets the local repository for ivy files
323 324 325 326 327 328 329 330 331 332 333 334 335 336 |
# File 'lib/buildr/ivy_extension.rb', line 323 def local_repository(*local_repository) if local_repository.empty? if own_file? @local_repository ||= Ivy.setting('local.repository.dir') || "#{home}/repository" else @project.parent.ivy.local_repository end else raise "Could not set 'local_repository' for '#{@project.name}' without own ivy file!" unless own_file? raise "local_repository value invalid #{local_repository.join(', ')}" unless local_repository.size == 1 @local_repository = local_repository[0] self end end |
#makepom(filename = 'pom.xml') ⇒ Object
Simple call to makepom with projects ivy.xml as input. The filename in target folder can be changed with the optional filename parameter
191 192 193 |
# File 'lib/buildr/ivy_extension.rb', line 191 def makepom(filename = 'pom.xml') ivy4r.makepom :ivyfile => file, :pomfile => project.path_to(:target, filename) end |
#manifest ⇒ Object
Returns the additional infos for the manifest file.
167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/buildr/ivy_extension.rb', line 167 def manifest if @base_ivy @base_ivy.manifest else { 'organisation' => @resolved['ivy.organisation'], 'module' => @resolved['ivy.module'], 'revision' => revision } end end |
#name(*args) ⇒ Object
356 357 358 359 |
# File 'lib/buildr/ivy_extension.rb', line 356 def name(*args) puts "name(*args) is deprecated use publish(*args)!" publish(*args) end |
#own_file? ⇒ Boolean
52 53 54 |
# File 'lib/buildr/ivy_extension.rb', line 52 def own_file? @own_file ||= File.exists?(file) end |
#post_resolve(&block) ⇒ Object
Adds given block as post resolve action that is executed directly after #resolve has been called. Yields this ivy config object into block. project.ivy.post_resolve { |ivy| p "all deps:" + ivy.deps('all').join(", ") }
396 397 398 |
# File 'lib/buildr/ivy_extension.rb', line 396 def post_resolve(&block) post_resolve_tasks << block if block end |
#properties(*properties) ⇒ Object
Sets the additional properties for the ivy process use a Hash with the properties to set.
312 313 314 315 316 317 318 319 320 |
# File 'lib/buildr/ivy_extension.rb', line 312 def properties(*properties) if properties.empty? @properties ||= {} else raise "properties value invalid #{properties.join(', ')}" unless properties.size == 1 @properties = properties[0] self end end |
#publish(*publish_mappings) ⇒ Object
:call-seq: ivy.publish(package(:jar) => ‘new_name_without_version_number.jar’) #deprecated! ivy.name(package(:jar) => ‘new_name_without_version_number.jar’)
Maps a package to a different name for publishing. This name is used instead of the default name for publishing use a hash with the package
as key and the newly mapped name as value. I.e. ivy.name(package(:jar) => 'new_name_without_version_number.jar')
Note that this method is additive, a second call adds the names to the first.
346 347 348 349 350 351 352 353 354 |
# File 'lib/buildr/ivy_extension.rb', line 346 def publish(*publish_mappings) if publish_mappings.empty? @publish_mappings ||= {} else raise "publish_mappings value invalid #{publish_mappings.join(', ')}" unless publish_mappings.size == 1 @publish_mappings = @publish_mappings ? @publish_mappings + publish_mappings[0] : publish_mappings[0].dup self end end |
#publish_from(*publish_dir) ⇒ Object
Sets the directory to publish artifacts from.
362 363 364 365 366 367 368 369 370 371 372 373 374 375 |
# File 'lib/buildr/ivy_extension.rb', line 362 def publish_from(*publish_dir) if publish_dir.empty? if own_file? @publish_from ||= Ivy.setting('publish.from') || @project.path_to(:target) else @project.parent.ivy.publish_from end else raise "Could not set 'publish_from' for '#{@project.name}' without own ivy file!" unless own_file? raise "publish_from value invalid #{publish_dir.join(', ')}" unless publish_dir.size == 1 @publish_from = publish_dir[0] self end end |
#publish_options(*options, &block) ⇒ Object
Sets the publish options to use for the project. The options are merged with the default options including value set via #publish_from and overwrite all of them.
To set the options this method can be used in different ways.
-
project.ivy.publish_options(options) to set the options directly
-
project.ivy.publish_options { |ivy| [calculate options] } use the block for dynamic calculation of options. You can access ivy4r via
ivy.ivy4r.[method]
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
# File 'lib/buildr/ivy_extension.rb', line 290 def (*, &block) raise "Invalid call with parameters and block!" if .size > 0 && block if .empty? && block.nil? if @publish_options_calc @publish_options ||= @publish_options_calc.call(self) else @publish_options ||= Ivy.setting('publish.options') || {} end else raise "Could not set 'publish_options' for '#{@project.name}' without own ivy file!" unless own_file? if .size > 0 && block.nil? raise "publish options value invalid #{.join(', ')}" unless .size == 1 @publish_options = [0] self else @publish_options_calc = block self end end end |
#report ⇒ Object
Creates the standard ivy dependency report
180 181 182 |
# File 'lib/buildr/ivy_extension.rb', line 180 def report ivy4r.report :todir => report_dir end |
#report_dir(*report_dir) ⇒ Object
Sets the directory to create dependency reports in.
378 379 380 381 382 383 384 385 386 387 388 389 390 391 |
# File 'lib/buildr/ivy_extension.rb', line 378 def report_dir(*report_dir) if report_dir.empty? if own_file? @report_dir ||= Ivy.setting('report.dir') || @project.path_to(:reports, 'ivy') else @project.parent.ivy.report_dir end else raise "Could not set 'report_dir' for '#{@project.name}' without own ivy file!" unless own_file? raise "publish_from value invalid #{report_dir.join(', ')}" unless report_dir.size == 1 @report_dir = report_dir[0] self end end |
#result_cache_dir ⇒ Object
Returns the dir to store ivy caching results in.
90 91 92 93 94 |
# File 'lib/buildr/ivy_extension.rb', line 90 def result_cache_dir dir = @project.path_to('target', 'ivycaching') FileUtils.mkdir_p dir dir end |
#revision(*revision, &block) ⇒ Object
Sets the revision to use for the project, this is useful for development revisions that have an appended timestamp or any other dynamic revisioning.
To set a different revision this method can be used in different ways.
-
project.ivy.revision(revision) to set the revision directly
-
project.ivy.revision { |ivy| [calculate revision] } use the block for dynamic calculation of the revision. You can access ivy4r via
ivy.ivy4r.[method]
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/buildr/ivy_extension.rb', line 240 def revision(*revision, &block) raise "Invalid call with parameters and block!" if revision.size > 0 && block if revision.empty? && block.nil? if @revision_calc @revision ||= @revision_calc.call(self) else @revision ||= @project.version end elsif block.nil? raise "revision value invalid #{revision.join(', ')}" unless revision.size == 1 @revision = revision[0] self else @revision_calc = block self end end |
#settings ⇒ Object
218 219 220 |
# File 'lib/buildr/ivy_extension.rb', line 218 def settings @settings ||= Ivy.setting('settings.file') || "#{@extension_dir}/ivysettings.xml" end |
#status(*status, &block) ⇒ Object
Sets the status to use for the project, this is useful for custom status handling like integration, alpha, gold.
To set a different status this method can be used in different ways.
-
project.ivy.status(status) to set the status directly
-
project.ivy.status { |ivy| [calculate status] } use the block for dynamic calculation of the status. You can access ivy4r via
ivy.ivy4r.[method]
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
# File 'lib/buildr/ivy_extension.rb', line 265 def status(*status, &block) raise "Invalid call with parameters and block!" if status.size > 0 && block if status.empty? && block.nil? if @status_calc @status ||= @status_calc.call(self) else @status end elsif status.empty? && block.nil? raise "status value invalid #{status.join(', ')}" unless status.size == 1 @status = status[0] self else @status_calc = block self end end |