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.
-
#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.
-
#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
-
#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.
- #lib_dir ⇒ Object
-
#local_repository(*local_repository) ⇒ Object
Sets the local repository for ivy files.
-
#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(*publish_mappings) ⇒ Object
(also: #publish)
:call-seq: ivy.publish(package(:jar) => ‘new_name_without_version_number.jar’) #deprecated! ivy.name(package(:jar) => ‘new_name_without_version_number.jar’).
- #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_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.
-
#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
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/buildr/ivy_extension.rb', line 26 def initialize(project) @project = project if project.parent.nil? @extension_dir = @project.base_dir @post_resolve_task_list = [] else @extension_dir = @project.parent.ivy.extension_dir @base_ivy = @project.parent.ivy unless own_file? end @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.
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 |
# File 'lib/buildr/ivy_extension.rb', line 385 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.
18 19 20 |
# File 'lib/buildr/ivy_extension.rb', line 18 def extension_dir @extension_dir end |
#post_resolve_task_list ⇒ Object (readonly)
Returns the value of attribute post_resolve_task_list.
20 21 22 |
# File 'lib/buildr/ivy_extension.rb', line 20 def post_resolve_task_list @post_resolve_task_list end |
#publish_mappings ⇒ Object (readonly)
Hash of all artifacts to publish with mapping from artifact name to ivy publish name
23 24 25 |
# File 'lib/buildr/ivy_extension.rb', line 23 def publish_mappings @publish_mappings end |
#resolved ⇒ Object
Returns the value of attribute resolved.
18 19 20 |
# File 'lib/buildr/ivy_extension.rb', line 18 def resolved @resolved end |
Instance Method Details
#__publish__ ⇒ Object
Publishs the project as defined in ivy file if it has not been published already
152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/buildr/ivy_extension.rb', line 152 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.
121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/buildr/ivy_extension.rb', line 121 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 |
#configure ⇒ Object
Configures the ivy instance with additional properties and loading the settings file if it was provided
107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/buildr/ivy_extension.rb', line 107 def configure if @base_ivy @base_ivy.configure else unless @configured ivy4r.property['ivy.status'] = status ivy4r.property['ivy.home'] = home properties.each {|key, value| ivy4r.property[key.to_s] = value } @configured = ivy4r.settings :file => settings if settings end end end |
#deps(*args) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/buildr/ivy_extension.rb', line 74 def deps(*args) if 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.blank? } 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
40 41 42 |
# File 'lib/buildr/ivy_extension.rb', line 40 def enabled? @enabled ||= Ivy.setting('enabled') || true end |
#file ⇒ Object
177 178 179 |
# File 'lib/buildr/ivy_extension.rb', line 177 def file @ivy_file ||= Ivy.setting('ivy.file') || 'ivy.xml' end |
#file_project ⇒ Object
Returns name of the project the ivy file belongs to.
65 66 67 |
# File 'lib/buildr/ivy_extension.rb', line 65 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/])
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 |
# File 'lib/buildr/ivy_extension.rb', line 347 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.blank? } should_include = includes.empty? || includes.any? {|include| include === lib } should_include && !excludes.any? {|exclude| exclude === lib} end end artifacts end |
#home ⇒ Object
165 166 167 |
# File 'lib/buildr/ivy_extension.rb', line 165 def home @ivy_home_dir ||= Ivy.setting('home.dir') || "#{@extension_dir}/ivy-home" end |
#info ⇒ Object
Returns ivy info for configured ivy file using a new ivy4r instance.
95 96 97 98 99 100 101 102 103 104 |
# File 'lib/buildr/ivy_extension.rb', line 95 def info if @base_ivy @base_ivy.info else ivy4r.settings :id => 'ivy.info.settingsref' result = ivy4r.info :file => file, :settingsRef => 'ivy.info.settingsref' @ivy4r = nil result 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
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/buildr/ivy_extension.rb', line 51 def ivy4r unless @ivy4r if own_file? @ivy4r = ::Ivy4r.new(@project.ant('ivy')) @ivy4r.lib_dir = lib_dir if lib_dir @ivy4r.project_dir = @extension_dir else @ivy4r = @project.parent.ivy.ivy4r end end @ivy4r end |
#lib_dir ⇒ Object
169 170 171 |
# File 'lib/buildr/ivy_extension.rb', line 169 def lib_dir @lib_dir ||= Ivy.setting('lib.dir') end |
#local_repository(*local_repository) ⇒ Object
Sets the local repository for ivy files
271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
# File 'lib/buildr/ivy_extension.rb', line 271 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 |
#manifest ⇒ Object
Returns the additional infos for the manifest file.
134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/buildr/ivy_extension.rb', line 134 def manifest if @base_ivy @base_ivy.manifest else { 'organisation' => @resolved['ivy.organisation'], 'module' => @resolved['ivy.organisation'], 'revision' => revision } end end |
#name(*publish_mappings) ⇒ Object Also known as: publish
: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.
294 295 296 297 298 299 300 301 302 |
# File 'lib/buildr/ivy_extension.rb', line 294 def name(*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 |
#own_file? ⇒ Boolean
44 45 46 |
# File 'lib/buildr/ivy_extension.rb', line 44 def own_file? @own_file ||= File.exists?(@project.path_to(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(", ") }
340 341 342 |
# File 'lib/buildr/ivy_extension.rb', line 340 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.
260 261 262 263 264 265 266 267 268 |
# File 'lib/buildr/ivy_extension.rb', line 260 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_from(*publish_dir) ⇒ Object
Sets the directory to publish artifacts from.
306 307 308 309 310 311 312 313 314 315 316 317 318 319 |
# File 'lib/buildr/ivy_extension.rb', line 306 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]
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/buildr/ivy_extension.rb', line 238 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
147 148 149 |
# File 'lib/buildr/ivy_extension.rb', line 147 def report ivy4r.report :todir => report_dir end |
#report_dir(*report_dir) ⇒ Object
Sets the directory to create dependency reports in.
322 323 324 325 326 327 328 329 330 331 332 333 334 335 |
# File 'lib/buildr/ivy_extension.rb', line 322 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 |
#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]
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/buildr/ivy_extension.rb', line 188 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
173 174 175 |
# File 'lib/buildr/ivy_extension.rb', line 173 def settings @settings ||= Ivy.setting('settings.file') || "#{@extension_dir}/ant-scripts/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]
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/buildr/ivy_extension.rb', line 213 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 ||= Ivy.setting('status') || 'integration' 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 |