Class: Rake::Ivy::IvyConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/rake/ivy_extension.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(application) ⇒ IvyConfig

Store the current rake application and initialize ivy ant wrapper



23
24
25
26
27
# File 'lib/rake/ivy_extension.rb', line 23

def initialize(application)
  @application = application
  @extension_dir = File.join("#{@application.original_dir}", "#{ENV['IVY_EXT_DIR']}")
  @post_resolve_tasks = []
end

Instance Attribute Details

#extension_dirObject

The extension directory containing ivy settings, the local repository and cache



15
16
17
# File 'lib/rake/ivy_extension.rb', line 15

def extension_dir
  @extension_dir
end

#lib_dirObject

The directory to load ivy jars and its dependencies from, leave __nil__ to use default



12
13
14
# File 'lib/rake/ivy_extension.rb', line 12

def lib_dir
  @lib_dir
end

#post_resolve_tasksObject (readonly)

Returns the value of attribute post_resolve_tasks.



20
21
22
# File 'lib/rake/ivy_extension.rb', line 20

def post_resolve_tasks
  @post_resolve_tasks
end

#resolvedObject (readonly)

Returns the resolve result



18
19
20
# File 'lib/rake/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



117
118
119
120
121
122
123
124
125
126
# File 'lib/rake/ivy_extension.rb', line 117

def __publish__
  unless @published
    options = {:artifactspattern => "#{publish_from}/[artifact].[ext]"}
    options[:pubrevision] = revision if revision
    options[:status] = status if status
    options = publish_options * options
    ivy4r.publish options
    @published = true
  end
end

#__resolve__Object

Resolves the configured file once.



103
104
105
106
107
108
109
# File 'lib/rake/ivy_extension.rb', line 103

def __resolve__
  unless @resolved
    @resolved = ivy4r.resolve :file => file
    post_resolve_tasks.each { |p| p.call(self) }
  end
  @resolved
end

#caching_enabled?Boolean

Returns if ivy result caching is enabled by existence of the marker file.

Returns:

  • (Boolean)


42
43
44
# File 'lib/rake/ivy_extension.rb', line 42

def caching_enabled?
  File.exists? caching_marker
end

#caching_markerObject

Returns the use ivy result caching marker file



47
48
49
# File 'lib/rake/ivy_extension.rb', line 47

def caching_marker
  File.expand_path 'use_ivy_caching'
end

#configureObject

Configures the ivy instance with additional properties and loading the settings file if it was provided



93
94
95
96
97
98
99
100
# File 'lib/rake/ivy_extension.rb', line 93

def configure
  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

#deps(*args) ⇒ Object

Returns the artifacts for given configurations as array this is a post resolve task. the arguments are checked for the following:

  1. if an Hash is given :conf is used for confs and :type is used for types

  2. if exactly two arrays are given args is used for confs and args is used for types

  3. if not exactly two arrays all args are used as confs



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/rake/ivy_extension.rb', line 64

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

#fileObject



136
137
138
# File 'lib/rake/ivy_extension.rb', line 136

def file
  @ivy_file ||= 'ivy.xml'
end

#homeObject



128
129
130
# File 'lib/rake/ivy_extension.rb', line 128

def home
  @ivy_home_dir
end

#infoObject

Returns ivy info for configured ivy file.



87
88
89
90
# File 'lib/rake/ivy_extension.rb', line 87

def info
  ivy4r.settings :id => 'ivy.info.settingsref'
  ivy4r.info :file => file, :settingsRef => 'ivy.info.settingsref'
end

#ivy4rObject

Returns the correct ant instance to use.



30
31
32
33
34
35
36
37
38
39
# File 'lib/rake/ivy_extension.rb', line 30

def ivy4r
  unless @ivy4r
    @ivy4r = ::Ivy4r.new do |i|
      i.cache_dir = result_cache_dir if caching_enabled?
    end
    @ivy4r.lib_dir = lib_dir if lib_dir
    @ivy4r.project_dir = @extension_dir
  end
  @ivy4r
end

#local_repository(*local_repository) ⇒ Object

Sets the local repository for ivy files



229
230
231
232
233
234
235
236
237
# File 'lib/rake/ivy_extension.rb', line 229

def local_repository(*local_repository)
  if local_repository.empty?
    @local_repository ||= "#{home}/repository"
  else
    raise "local_repository value invalid #{local_repository.join(', ')}" unless local_repository.size == 1
    @local_repository = local_repository[0]
    self
  end
end

#properties(*properties) ⇒ Object

Sets the additional properties for the ivy process use a Hash with the properties to set.



218
219
220
221
222
223
224
225
226
# File 'lib/rake/ivy_extension.rb', line 218

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.



240
241
242
243
244
245
246
247
248
# File 'lib/rake/ivy_extension.rb', line 240

def publish_from(*publish_dir)
  if publish_dir.empty?
    @publish_from ||= @application.original_dir
  else
    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.

  1. project.ivy.publish_options(options) to set the options directly

  2. project.ivy.publish_options { |ivy| [calculate options] } use the block for dynamic calculation of options. You can access ivy4r via ivy.ivy4r.[method]



197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/rake/ivy_extension.rb', line 197

def publish_options(*options, &block)
  raise "Invalid call with parameters and block!" if options.size > 0 && block
  if options.empty? && block.nil?
    if @publish_options_calc
      @publish_options ||= @publish_options_calc.call(self)
    else
      @publish_options ||= {}
    end
  else
    if options.size > 0 && block.nil?
      raise "publish options value invalid #{options.join(', ')}" unless options.size == 1
      @publish_options = options[0]
      self
    else
      @publish_options_calc = block
      self
    end
  end
end

#reportObject

Creates the standard ivy dependency report



112
113
114
# File 'lib/rake/ivy_extension.rb', line 112

def report
  ivy4r.report :todir => report_dir
end

#report_dir(*report_dir) ⇒ Object

Sets the directory to create dependency reports in.



251
252
253
254
255
256
257
258
259
# File 'lib/rake/ivy_extension.rb', line 251

def report_dir(*report_dir)
  if report_dir.empty?
    @report_dir ||= @application.original_dir
  else
    raise "publish_from value invalid #{report_dir.join(', ')}" unless report_dir.size == 1
    @report_dir = report_dir[0]
    self
  end
end

#result_cache_dirObject

Returns the dir to store ivy caching results in.



52
53
54
55
56
# File 'lib/rake/ivy_extension.rb', line 52

def result_cache_dir
  dir = File.expand_path('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.

  1. project.ivy.revision(revision) to set the revision directly

  2. project.ivy.revision { |ivy| [calculate revision] } use the block for dynamic calculation of the revision. You can access ivy4r via ivy.ivy4r.[method]



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/rake/ivy_extension.rb', line 147

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
    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

#settingsObject



132
133
134
# File 'lib/rake/ivy_extension.rb', line 132

def settings
  @settings ||= "#{@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.

  1. project.ivy.status(status) to set the status directly

  2. project.ivy.status { |ivy| [calculate status] } use the block for dynamic calculation of the status. You can access ivy4r via ivy.ivy4r.[method]



172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/rake/ivy_extension.rb', line 172

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