ivy4r 0.10.0 → 0.10.1

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,9 @@
1
+ === 0.10.1 / 2010-03-30
2
+ * Some fixes for the rake ivy result caching.
3
+ * Renamed the targets from ivy:enableresultcache, ivy:disableresultcache and ivy:cleanresultcache
4
+ into ivy:enable_result_cache, ivy:disable_result_cache and ivy:clean_result_cache for better
5
+ readability
6
+
1
7
  === 0.10.0 / 2010-03-30
2
8
 
3
9
  * Add caching support to ivy4r. Ivy4r has now an optional parameter to a caching directory where it
@@ -11,7 +17,6 @@
11
17
  * add a marker file to your project under the path project.path_to('use_ivy_caching') Note that this is
12
18
  a marker file only the existence of the file is checked not the content!! If the file exists caching
13
19
  will be used!
14
-
15
20
 
16
21
  === 0.9.15 / 2010-03-20
17
22
 
data/README.txt CHANGED
@@ -1,102 +1,102 @@
1
- = ivy4r
2
-
3
- * http://github.com/klaas1979/ivy4r/tree/master
4
-
5
- == DESCRIPTION:
6
-
7
- Apache Ivy dependency manager wrapper for ruby (see {Apache Ivy}[http://ant.apache.org/ivy/index.html] for more information).
8
- Use {Apache Ivy}[http://ant.apache.org/ivy/index.html] via a ruby wrapper without the need to use Apache Ant.
9
- The wrapper uses Antwrap[http://antwrap.rubyforge.org/] to interface with Ivy.
10
-
11
- Includes a Extension for Buildr[http://buildr.apache.org/] and Rake[http://rake.rubyforge.org] to use
12
- {Apache Ivy}[http://ant.apache.org/ivy/index.html] for dependency management.
13
-
14
- == FEATURES/PROBLEMS:
15
-
16
- Supports most standard Ivy Ant targets via Antwrap. Provides a caching feature so that long running ivy tasks
17
- like resolve can be cached and are not rerun for local builds. For more information about caching see the History.txt
18
- and checkout the source of buildr/ivy_extension.rb and rake/ivy_extension.rb.
19
-
20
- === Supported Ivy targets:
21
- * info
22
- * settings
23
- * configure
24
- * cleancache
25
- * buildnumber
26
- * findrevision
27
- * cachepath
28
- * artifactreport
29
- * resolve
30
- * makepom
31
- * retrieve
32
- * publish
33
- * artifactproperty
34
- * report
35
- * buildlist
36
- * deliver
37
- * install
38
- * repreport
39
-
40
- === Currently not working Ivy targets:
41
- * listmodules
42
-
43
- === Ivy targets that need to be implemented:
44
- * deliver
45
- * install
46
- * repreport
47
-
48
- === Unsupported Ivy Targets (they make no sense for the wrapper):
49
- * cachefileset
50
- * var
51
-
52
- === Caching of Ivy results:
53
- For Buildr the targets ivy:enableresultcache, ivy:disableresultcache and ivy:cleanresultcache have been added.
54
- Additionally the result cache can be enabled via the build.yaml or the global buildr settings.yaml by setting
55
- the variable "ivy: caching.enabled: true".
56
-
57
- For Rake the targets ivy:enableresultcache, ivy:disableresultcache and ivy:cleanresultcache have been added as
58
- well. For Rake there is no other way to enable the caching beside this targets.
59
-
60
- == SYNOPSIS:
61
-
62
- To init a new Ivy4r instance set the ANT_HOME and the Ivy lib dir
63
- ivy4r = Ivy4r.new
64
- ivy4r.ant_home = 'PATH TO YOUR ANTHOME'
65
- ivy4r.lib_dir = 'PATH TO IVY LIB DIR'
66
- as an alternative to setting the ANT_HOME you can set an +Antwrap+ instance directly:
67
- ivy4r.ant = Buildr.ant('ivy')
68
-
69
- == REQUIREMENTS:
70
-
71
- * Installed Apache Ant, to call Ivy via Antwrap
72
- * Ivy and dependencies in a single directory. Dependencies depends on used features, see the ivy homepage for more information.
73
-
74
- == INSTALL:
75
-
76
- You can use gemcutter to install
77
- sudo gem install ivy4r
78
-
79
- == LICENSE:
80
-
81
- (The MIT License)
82
-
83
- Copyright (c) 2009 blau Mobilfunk GmbH
84
-
85
- Permission is hereby granted, free of charge, to any person obtaining
86
- a copy of this software and associated documentation files (the
87
- 'Software'), to deal in the Software without restriction, including
88
- without limitation the rights to use, copy, modify, merge, publish,
89
- distribute, sublicense, and/or sell copies of the Software, and to
90
- permit persons to whom the Software is furnished to do so, subject to
91
- the following conditions:
92
-
93
- The above copyright notice and this permission notice shall be
94
- included in all copies or substantial portions of the Software.
95
-
96
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
97
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
98
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
99
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
100
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
101
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
102
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ = ivy4r
2
+
3
+ * http://github.com/klaas1979/ivy4r/tree/master
4
+
5
+ == DESCRIPTION:
6
+
7
+ Apache Ivy dependency manager wrapper for ruby (see {Apache Ivy}[http://ant.apache.org/ivy/index.html] for more information).
8
+ Use {Apache Ivy}[http://ant.apache.org/ivy/index.html] via a ruby wrapper without the need to use Apache Ant.
9
+ The wrapper uses Antwrap[http://antwrap.rubyforge.org/] to interface with Ivy.
10
+
11
+ Includes a Extension for Buildr[http://buildr.apache.org/] and Rake[http://rake.rubyforge.org] to use
12
+ {Apache Ivy}[http://ant.apache.org/ivy/index.html] for dependency management.
13
+
14
+ == FEATURES/PROBLEMS:
15
+
16
+ Supports most standard Ivy Ant targets via Antwrap. Provides a caching feature so that long running ivy tasks
17
+ like resolve can be cached and are not rerun for local builds. For more information about caching see the History.txt
18
+ and checkout the source of buildr/ivy_extension.rb and rake/ivy_extension.rb.
19
+
20
+ === Supported Ivy targets:
21
+ * info
22
+ * settings
23
+ * configure
24
+ * cleancache
25
+ * buildnumber
26
+ * findrevision
27
+ * cachepath
28
+ * artifactreport
29
+ * resolve
30
+ * makepom
31
+ * retrieve
32
+ * publish
33
+ * artifactproperty
34
+ * report
35
+ * buildlist
36
+ * deliver
37
+ * install
38
+ * repreport
39
+
40
+ === Currently not working Ivy targets:
41
+ * listmodules
42
+
43
+ === Ivy targets that need to be implemented:
44
+ * deliver
45
+ * install
46
+ * repreport
47
+
48
+ === Unsupported Ivy Targets (they make no sense for the wrapper):
49
+ * cachefileset
50
+ * var
51
+
52
+ === Caching of Ivy results:
53
+ For Buildr the targets ivy:enable_result_cache, ivy:disable_result_cache and ivy:clean_result_cache have been added.
54
+ Additionally the result cache can be enabled via the build.yaml or the global buildr settings.yaml by setting
55
+ the variable "ivy: caching.enabled: true".
56
+
57
+ For Rake the targets ivy:enable_result_cache, ivy:disable_result_cache and ivy:clean_result_cache have been added as
58
+ well. For Rake there is no other way to enable the caching beside this targets.
59
+
60
+ == SYNOPSIS:
61
+
62
+ To init a new Ivy4r instance set the ANT_HOME and the Ivy lib dir
63
+ ivy4r = Ivy4r.new
64
+ ivy4r.ant_home = 'PATH TO YOUR ANTHOME'
65
+ ivy4r.lib_dir = 'PATH TO IVY LIB DIR'
66
+ as an alternative to setting the ANT_HOME you can set an +Antwrap+ instance directly:
67
+ ivy4r.ant = Buildr.ant('ivy')
68
+
69
+ == REQUIREMENTS:
70
+
71
+ * Installed Apache Ant, to call Ivy via Antwrap
72
+ * Ivy and dependencies in a single directory. Dependencies depends on used features, see the ivy homepage for more information.
73
+
74
+ == INSTALL:
75
+
76
+ You can use gemcutter to install
77
+ sudo gem install ivy4r
78
+
79
+ == LICENSE:
80
+
81
+ (The MIT License)
82
+
83
+ Copyright (c) 2009 blau Mobilfunk GmbH
84
+
85
+ Permission is hereby granted, free of charge, to any person obtaining
86
+ a copy of this software and associated documentation files (the
87
+ 'Software'), to deal in the Software without restriction, including
88
+ without limitation the rights to use, copy, modify, merge, publish,
89
+ distribute, sublicense, and/or sell copies of the Software, and to
90
+ permit persons to whom the Software is furnished to do so, subject to
91
+ the following conditions:
92
+
93
+ The above copyright notice and this permission notice shall be
94
+ included in all copies or substantial portions of the Software.
95
+
96
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
97
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
98
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
99
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
100
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
101
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
102
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -690,18 +690,18 @@ module IvyExtension
690
690
  project.ivy.cleancache
691
691
  end
692
692
 
693
- task :cleanresultcache do
693
+ task :clean_result_cache do
694
694
  project.send(:info, "Deleting IVY result cache dir '#{project.ivy.result_cache_dir}'")
695
695
  rm_rf project.ivy.result_cache_dir
696
696
  end
697
697
 
698
- task :enableresultcache do
698
+ task :enable_result_cache do
699
699
  project.send(:info, "Creating IVY caching marker file '#{project.ivy.caching_marker}'")
700
700
  touch project.ivy.caching_marker
701
701
  end
702
702
 
703
- task :disableresultcache do
704
- project.send(:info, "Deleting IVY aching marker file '#{project.ivy.caching_marker}'")
703
+ task :disable_result_cache do
704
+ project.send(:info, "Deleting IVY caching marker file '#{project.ivy.caching_marker}'")
705
705
  rm_f project.ivy.caching_marker
706
706
  end
707
707
 
@@ -729,21 +729,21 @@ namespace 'ivy' do
729
729
  end
730
730
  end
731
731
 
732
- task :cleanresultcache do
732
+ task :clean_result_cache do
733
733
  Buildr.projects.find_all{ |p| p.ivy.own_file? }.each do |project|
734
- project.task('ivy:cleanresultcache').invoke
734
+ project.task('ivy:clean_result_cache').invoke
735
735
  end
736
736
  end
737
737
 
738
- task :enableresultcache do
738
+ task :enable_result_cache do
739
739
  Buildr.projects.find_all{ |p| p.ivy.own_file? }.each do |project|
740
- project.task('ivy:enableresultcache').invoke
740
+ project.task('ivy:enable_result_cache').invoke
741
741
  end
742
742
  end
743
743
 
744
- task :disableresultcache do
744
+ task :disable_result_cache do
745
745
  Buildr.projects.find_all{ |p| p.ivy.own_file? }.each do |project|
746
- project.task('ivy:disableresultcache').invoke
746
+ project.task('ivy:disable_result_cache').invoke
747
747
  end
748
748
  end
749
749
 
data/lib/ivy4r.rb CHANGED
@@ -35,7 +35,8 @@ is
35
35
  }
36
36
  =end
37
37
  class Ivy4r
38
- VERSION = '0.10.0'
38
+
39
+ VERSION = '0.10.1'
39
40
 
40
41
  # Set the ant home directory to load ant classes from if no custom __antwrap__ is provided
41
42
  # and the default provided ant version 1.7.1 should not be used.
@@ -1,345 +1,349 @@
1
- require 'ivy4r'
2
-
3
- class Rake::Application
4
- attr_accessor :ivy
5
- end
6
-
7
- module Rake
8
- module Ivy
9
- class IvyConfig
10
-
11
- # The directory to load ivy jars and its dependencies from, leave __nil__ to use default
12
- attr_accessor :lib_dir
13
-
14
- # The extension directory containing ivy settings, the local repository and cache
15
- attr_accessor :extension_dir
16
-
17
- # Returns the resolve result
18
- attr_reader :resolved
19
-
20
- attr_reader :post_resolve_tasks
21
-
22
- # Store the current rake application and initialize ivy ant wrapper
23
- def initialize(application)
24
- @application = application
25
- @extension_dir = File.join("#{@application.original_dir}", "#{ENV['IVY_EXT_DIR']}")
26
- @post_resolve_tasks = []
27
- end
28
-
29
- # Returns the correct ant instance to use.
30
- def ivy4r
31
- unless @ivy4r
32
- @ivy4r = ::Ivy4r.new do |i|
33
- if caching_enabled?
34
- end
35
- end
36
- @ivy4r.lib_dir = lib_dir if lib_dir
37
- @ivy4r.project_dir = @extension_dir
38
- end
39
- @ivy4r
40
- end
41
-
42
- # Returns if ivy result caching is enabled by existence of the marker file.
43
- def caching_enabled?
44
- File.exists? 'use_ivy_caching'
45
- end
46
-
47
- # Returns the dir to store ivy caching results in.
48
- def result_cache_dir
49
- dir = File.expand_path('ivycaching')
50
- FileUtils.mkdir_p dir
51
- dir
52
- end
53
-
54
- # Returns the artifacts for given configurations as array
55
- # this is a post resolve task.
56
- # the arguments are checked for the following:
57
- # 1. if an Hash is given :conf is used for confs and :type is used for types
58
- # 2. if exactly two arrays are given args[0] is used for confs and args[1] is used for types
59
- # 3. if not exactly two arrays all args are used as confs
60
- def deps(*args)
61
- if args.size == 1 && args[0].kind_of?(Hash)
62
- confs, types = [args[0][:conf]].flatten, [args[0][:type]].flatten
63
- elsif args.size == 2 && args[0].kind_of?(Array) && args[1].kind_of?(Array)
64
- confs, types = args[0], args[1]
65
- else
66
- confs, types = args.flatten, []
67
- end
68
-
69
- [confs, types].each do |t|
70
- t.reject! {|c| c.nil? || c.blank? }
71
- end
72
-
73
- unless confs.empty?
74
- pathid = "ivy.deps." + confs.join('.') + '.' + types.join('.')
75
- params = {:conf => confs.join(','), :pathid => pathid}
76
- params[:type] = types.join(',') unless types.nil? || types.size == 0
77
-
78
- ivy4r.cachepath params
79
- end
80
- end
81
-
82
- # Returns ivy info for configured ivy file.
83
- def info
84
- ivy4r.settings :id => 'ivy.info.settingsref'
85
- ivy4r.info :file => file, :settingsRef => 'ivy.info.settingsref'
86
- end
87
-
88
- # Configures the ivy instance with additional properties and loading the settings file if it was provided
89
- def configure
90
- unless @configured
91
- ivy4r.property['ivy.status'] = status
92
- ivy4r.property['ivy.home'] = home
93
- properties.each {|key, value| ivy4r.property[key.to_s] = value }
94
- @configured = ivy4r.settings :file => settings if settings
95
- end
96
- end
97
-
98
- # Resolves the configured file once.
99
- def __resolve__
100
- unless @resolved
101
- @resolved = ivy4r.resolve :file => file
102
- post_resolve_tasks.each { |p| p.call(self) }
103
- end
104
- @resolved
105
- end
106
-
107
- # Creates the standard ivy dependency report
108
- def report
109
- ivy4r.report :todir => report_dir
110
- end
111
-
112
- # Publishs the project as defined in ivy file if it has not been published already
113
- def __publish__
114
- unless @published
115
- options = {:artifactspattern => "#{publish_from}/[artifact].[ext]"}
116
- options[:pubrevision] = revision if revision
117
- options[:status] = status if status
118
- options = publish_options * options
119
- ivy4r.publish options
120
- @published = true
121
- end
122
- end
123
-
124
- def home
125
- @ivy_home_dir ||= "#{@extension_dir}/ivy-home"
126
- end
127
-
128
- def settings
129
- @settings ||= "#{@extension_dir}/ant-scripts/ivysettings.xml"
130
- end
131
-
132
- def file
133
- @ivy_file ||= 'ivy.xml'
134
- end
135
-
136
- # Sets the revision to use for the project, this is useful for development revisions that
137
- # have an appended timestamp or any other dynamic revisioning.
138
- #
139
- # To set a different revision this method can be used in different ways.
140
- # 1. project.ivy.revision(revision) to set the revision directly
141
- # 2. project.ivy.revision { |ivy| [calculate revision] } use the block for dynamic
142
- # calculation of the revision. You can access ivy4r via <tt>ivy.ivy4r.[method]</tt>
143
- def revision(*revision, &block)
144
- raise "Invalid call with parameters and block!" if revision.size > 0 && block
145
- if revision.empty? && block.nil?
146
- if @revision_calc
147
- @revision ||= @revision_calc.call(self)
148
- else
149
- @revision
150
- end
151
- elsif block.nil?
152
- raise "revision value invalid #{revision.join(', ')}" unless revision.size == 1
153
- @revision = revision[0]
154
- self
155
- else
156
- @revision_calc = block
157
- self
158
- end
159
- end
160
-
161
- # Sets the status to use for the project, this is useful for custom status handling
162
- # like integration, alpha, gold.
163
- #
164
- # To set a different status this method can be used in different ways.
165
- # 1. project.ivy.status(status) to set the status directly
166
- # 2. project.ivy.status { |ivy| [calculate status] } use the block for dynamic
167
- # calculation of the status. You can access ivy4r via <tt>ivy.ivy4r.[method]</tt>
168
- def status(*status, &block)
169
- raise "Invalid call with parameters and block!" if status.size > 0 && block
170
- if status.empty? && block.nil?
171
- if @status_calc
172
- @status ||= @status_calc.call(self)
173
- else
174
- @status
175
- end
176
- elsif status.empty? && block.nil?
177
- raise "status value invalid #{status.join(', ')}" unless status.size == 1
178
- @status = status[0]
179
- self
180
- else
181
- @status_calc = block
182
- self
183
- end
184
- end
185
-
186
- # Sets the publish options to use for the project. The options are merged with the default
187
- # options including value set via #publish_from and overwrite all of them.
188
- #
189
- # To set the options this method can be used in different ways.
190
- # 1. project.ivy.publish_options(options) to set the options directly
191
- # 2. project.ivy.publish_options { |ivy| [calculate options] } use the block for dynamic
192
- # calculation of options. You can access ivy4r via <tt>ivy.ivy4r.[method]</tt>
193
- def publish_options(*options, &block)
194
- raise "Invalid call with parameters and block!" if options.size > 0 && block
195
- if options.empty? && block.nil?
196
- if @publish_options_calc
197
- @publish_options ||= @publish_options_calc.call(self)
198
- else
199
- @publish_options ||= {}
200
- end
201
- else
202
- if options.size > 0 && block.nil?
203
- raise "publish options value invalid #{options.join(', ')}" unless options.size == 1
204
- @publish_options = options[0]
205
- self
206
- else
207
- @publish_options_calc = block
208
- self
209
- end
210
- end
211
- end
212
-
213
- # Sets the additional properties for the ivy process use a Hash with the properties to set.
214
- def properties(*properties)
215
- if properties.empty?
216
- @properties ||= {}
217
- else
218
- raise "properties value invalid #{properties.join(', ')}" unless properties.size == 1
219
- @properties = properties[0]
220
- self
221
- end
222
- end
223
-
224
- # Sets the local repository for ivy files
225
- def local_repository(*local_repository)
226
- if local_repository.empty?
227
- @local_repository ||= "#{home}/repository"
228
- else
229
- raise "local_repository value invalid #{local_repository.join(', ')}" unless local_repository.size == 1
230
- @local_repository = local_repository[0]
231
- self
232
- end
233
- end
234
-
235
- # Sets the directory to publish artifacts from.
236
- def publish_from(*publish_dir)
237
- if publish_dir.empty?
238
- @publish_from ||= @application.original_dir
239
- else
240
- raise "publish_from value invalid #{publish_dir.join(', ')}" unless publish_dir.size == 1
241
- @publish_from = publish_dir[0]
242
- self
243
- end
244
- end
245
-
246
- # Sets the directory to create dependency reports in.
247
- def report_dir(*report_dir)
248
- if report_dir.empty?
249
- @report_dir ||= @application.original_dir
250
- else
251
- raise "publish_from value invalid #{report_dir.join(', ')}" unless report_dir.size == 1
252
- @report_dir = report_dir[0]
253
- self
254
- end
255
- end
256
- end
257
-
258
- # Adds given block as post resolve action that is executed directly after #resolve has been called.
259
- # Yields this ivy config object into block.
260
- # <tt>project.ivy.post_resolve { |ivy| p "all deps:" + ivy.deps('all').join(", ") }</tt>
261
- def post_resolve(&block)
262
- post_resolve_tasks << block if block
263
- end
264
-
265
- # Filter artifacts for given configuration with provided filter values, this is a post resolve
266
- # task like #deps.
267
- # <tt>project.ivy.filter('server', 'client', :include => /b.*.jar/, :exclude => [/a\.jar/, /other.*\.jar/])</tt>
268
- def filter(*confs)
269
- filter = confs.last.kind_of?(Hash) ? confs.pop : {}
270
- unless (filter.keys - (TYPES - [:conf])).empty?
271
- raise ArgumentError, "Invalid filter use :include and/or :exclude only: given #{filter.keys.inspect}"
272
- end
273
- includes, excludes, types = filter[:include] || [], filter[:exclude] || [], filter[:type] || []
274
-
275
- artifacts = deps(confs.flatten, types.flatten)
276
- if artifacts
277
- artifacts = artifacts.find_all do |lib|
278
- lib = File.basename(lib)
279
- includes = includes.reject {|i| i.nil? || i.blank? }
280
- should_include = includes.empty? || includes.any? {|include| include === lib }
281
- should_include && !excludes.any? {|exclude| exclude === lib}
282
- end
283
- end
284
-
285
- artifacts
286
- end
287
-
288
- class Tasks < ::Rake::TaskLib
289
- def initialize(ivy = nil, &block)
290
- @ivy = ivy || Rake::Ivy::IvyConfig.new(Rake.application)
291
- yield @ivy if block_given?
292
- Rake.application.ivy = @ivy
293
-
294
- define
295
- end
296
-
297
- private
298
- def define
299
- namespace 'ivy' do
300
- task :configure do
301
- Rake.application.ivy.configure
302
- end
303
-
304
- desc 'Resolves the ivy dependencies'
305
- task :resolve => "ivy:configure" do
306
- Rake.application.ivy.__resolve__
307
- end
308
-
309
- desc 'Publish the artifacts to ivy repository'
310
- task :publish => "ivy:resolve" do
311
- Rake.application.ivy.__publish__
312
- end
313
-
314
- desc 'Creates a dependency report for the project'
315
- task :report => "ivy:resolve" do
316
- Rake.application.ivy.report
317
- end
318
-
319
- desc 'Clean the local Ivy cache and the local ivy repository'
320
- task :clean do
321
- Rake.application.ivy.ivy4r.clean
322
- end
323
-
324
- desc 'Clean the local Ivy result cache to force execution of ivy targets'
325
- task :cleanresultcache do
326
- puts "Deleting IVY result cache dir '#{Rake.application.ivy.result_cache_dir}'"
327
- rm_rf Rake.application.ivy.result_cache_dir
328
- end
329
-
330
- desc 'Enable the local Ivy result cache by creating the marker file'
331
- task :enableresultcache do
332
- puts "Creating IVY caching marker file '#{Rake.application.ivy.caching_marker}'"
333
- touch Rake.application.ivy.caching_marker
334
- end
335
-
336
- desc 'Disable the local Ivy result cache by removing the marker file'
337
- task :disableresultcache do
338
- puts "Deleting IVY aching marker file '#{Rake.application.ivy.caching_marker}'"
339
- rm_f Rake.application.ivy.caching_marker
340
- end
341
- end
342
- end
343
- end
344
- end
345
- end
1
+ require 'ivy4r'
2
+
3
+ class Rake::Application
4
+ attr_accessor :ivy
5
+ end
6
+
7
+ module Rake
8
+ module Ivy
9
+ class IvyConfig
10
+
11
+ # The directory to load ivy jars and its dependencies from, leave __nil__ to use default
12
+ attr_accessor :lib_dir
13
+
14
+ # The extension directory containing ivy settings, the local repository and cache
15
+ attr_accessor :extension_dir
16
+
17
+ # Returns the resolve result
18
+ attr_reader :resolved
19
+
20
+ attr_reader :post_resolve_tasks
21
+
22
+ # Store the current rake application and initialize ivy ant wrapper
23
+ def initialize(application)
24
+ @application = application
25
+ @extension_dir = File.join("#{@application.original_dir}", "#{ENV['IVY_EXT_DIR']}")
26
+ @post_resolve_tasks = []
27
+ end
28
+
29
+ # Returns the correct ant instance to use.
30
+ def ivy4r
31
+ unless @ivy4r
32
+ @ivy4r = ::Ivy4r.new do |i|
33
+ i.cache_dir = result_cache_dir if caching_enabled?
34
+ end
35
+ @ivy4r.lib_dir = lib_dir if lib_dir
36
+ @ivy4r.project_dir = @extension_dir
37
+ end
38
+ @ivy4r
39
+ end
40
+
41
+ # Returns if ivy result caching is enabled by existence of the marker file.
42
+ def caching_enabled?
43
+ File.exists? caching_marker
44
+ end
45
+
46
+ # Returns the use ivy result caching marker file
47
+ def caching_marker
48
+ File.expand_path 'use_ivy_caching'
49
+ end
50
+
51
+ # Returns the dir to store ivy caching results in.
52
+ def result_cache_dir
53
+ dir = File.expand_path('ivycaching')
54
+ FileUtils.mkdir_p dir
55
+ dir
56
+ end
57
+
58
+ # Returns the artifacts for given configurations as array
59
+ # this is a post resolve task.
60
+ # the arguments are checked for the following:
61
+ # 1. if an Hash is given :conf is used for confs and :type is used for types
62
+ # 2. if exactly two arrays are given args[0] is used for confs and args[1] is used for types
63
+ # 3. if not exactly two arrays all args are used as confs
64
+ def deps(*args)
65
+ if args.size == 1 && args[0].kind_of?(Hash)
66
+ confs, types = [args[0][:conf]].flatten, [args[0][:type]].flatten
67
+ elsif args.size == 2 && args[0].kind_of?(Array) && args[1].kind_of?(Array)
68
+ confs, types = args[0], args[1]
69
+ else
70
+ confs, types = args.flatten, []
71
+ end
72
+
73
+ [confs, types].each do |t|
74
+ t.reject! {|c| c.nil? || c.blank? }
75
+ end
76
+
77
+ unless confs.empty?
78
+ pathid = "ivy.deps." + confs.join('.') + '.' + types.join('.')
79
+ params = {:conf => confs.join(','), :pathid => pathid}
80
+ params[:type] = types.join(',') unless types.nil? || types.size == 0
81
+
82
+ ivy4r.cachepath params
83
+ end
84
+ end
85
+
86
+ # Returns ivy info for configured ivy file.
87
+ def info
88
+ ivy4r.settings :id => 'ivy.info.settingsref'
89
+ ivy4r.info :file => file, :settingsRef => 'ivy.info.settingsref'
90
+ end
91
+
92
+ # Configures the ivy instance with additional properties and loading the settings file if it was provided
93
+ def configure
94
+ unless @configured
95
+ ivy4r.property['ivy.status'] = status
96
+ ivy4r.property['ivy.home'] = home
97
+ properties.each {|key, value| ivy4r.property[key.to_s] = value }
98
+ @configured = ivy4r.settings :file => settings if settings
99
+ end
100
+ end
101
+
102
+ # Resolves the configured file once.
103
+ def __resolve__
104
+ unless @resolved
105
+ @resolved = ivy4r.resolve :file => file
106
+ post_resolve_tasks.each { |p| p.call(self) }
107
+ end
108
+ @resolved
109
+ end
110
+
111
+ # Creates the standard ivy dependency report
112
+ def report
113
+ ivy4r.report :todir => report_dir
114
+ end
115
+
116
+ # Publishs the project as defined in ivy file if it has not been published already
117
+ def __publish__
118
+ unless @published
119
+ options = {:artifactspattern => "#{publish_from}/[artifact].[ext]"}
120
+ options[:pubrevision] = revision if revision
121
+ options[:status] = status if status
122
+ options = publish_options * options
123
+ ivy4r.publish options
124
+ @published = true
125
+ end
126
+ end
127
+
128
+ def home
129
+ @ivy_home_dir ||= "#{@extension_dir}/ivy-home"
130
+ end
131
+
132
+ def settings
133
+ @settings ||= "#{@extension_dir}/ant-scripts/ivysettings.xml"
134
+ end
135
+
136
+ def file
137
+ @ivy_file ||= 'ivy.xml'
138
+ end
139
+
140
+ # Sets the revision to use for the project, this is useful for development revisions that
141
+ # have an appended timestamp or any other dynamic revisioning.
142
+ #
143
+ # To set a different revision this method can be used in different ways.
144
+ # 1. project.ivy.revision(revision) to set the revision directly
145
+ # 2. project.ivy.revision { |ivy| [calculate revision] } use the block for dynamic
146
+ # calculation of the revision. You can access ivy4r via <tt>ivy.ivy4r.[method]</tt>
147
+ def revision(*revision, &block)
148
+ raise "Invalid call with parameters and block!" if revision.size > 0 && block
149
+ if revision.empty? && block.nil?
150
+ if @revision_calc
151
+ @revision ||= @revision_calc.call(self)
152
+ else
153
+ @revision
154
+ end
155
+ elsif block.nil?
156
+ raise "revision value invalid #{revision.join(', ')}" unless revision.size == 1
157
+ @revision = revision[0]
158
+ self
159
+ else
160
+ @revision_calc = block
161
+ self
162
+ end
163
+ end
164
+
165
+ # Sets the status to use for the project, this is useful for custom status handling
166
+ # like integration, alpha, gold.
167
+ #
168
+ # To set a different status this method can be used in different ways.
169
+ # 1. project.ivy.status(status) to set the status directly
170
+ # 2. project.ivy.status { |ivy| [calculate status] } use the block for dynamic
171
+ # calculation of the status. You can access ivy4r via <tt>ivy.ivy4r.[method]</tt>
172
+ def status(*status, &block)
173
+ raise "Invalid call with parameters and block!" if status.size > 0 && block
174
+ if status.empty? && block.nil?
175
+ if @status_calc
176
+ @status ||= @status_calc.call(self)
177
+ else
178
+ @status
179
+ end
180
+ elsif status.empty? && block.nil?
181
+ raise "status value invalid #{status.join(', ')}" unless status.size == 1
182
+ @status = status[0]
183
+ self
184
+ else
185
+ @status_calc = block
186
+ self
187
+ end
188
+ end
189
+
190
+ # Sets the publish options to use for the project. The options are merged with the default
191
+ # options including value set via #publish_from and overwrite all of them.
192
+ #
193
+ # To set the options this method can be used in different ways.
194
+ # 1. project.ivy.publish_options(options) to set the options directly
195
+ # 2. project.ivy.publish_options { |ivy| [calculate options] } use the block for dynamic
196
+ # calculation of options. You can access ivy4r via <tt>ivy.ivy4r.[method]</tt>
197
+ def publish_options(*options, &block)
198
+ raise "Invalid call with parameters and block!" if options.size > 0 && block
199
+ if options.empty? && block.nil?
200
+ if @publish_options_calc
201
+ @publish_options ||= @publish_options_calc.call(self)
202
+ else
203
+ @publish_options ||= {}
204
+ end
205
+ else
206
+ if options.size > 0 && block.nil?
207
+ raise "publish options value invalid #{options.join(', ')}" unless options.size == 1
208
+ @publish_options = options[0]
209
+ self
210
+ else
211
+ @publish_options_calc = block
212
+ self
213
+ end
214
+ end
215
+ end
216
+
217
+ # Sets the additional properties for the ivy process use a Hash with the properties to set.
218
+ def properties(*properties)
219
+ if properties.empty?
220
+ @properties ||= {}
221
+ else
222
+ raise "properties value invalid #{properties.join(', ')}" unless properties.size == 1
223
+ @properties = properties[0]
224
+ self
225
+ end
226
+ end
227
+
228
+ # Sets the local repository for ivy files
229
+ def local_repository(*local_repository)
230
+ if local_repository.empty?
231
+ @local_repository ||= "#{home}/repository"
232
+ else
233
+ raise "local_repository value invalid #{local_repository.join(', ')}" unless local_repository.size == 1
234
+ @local_repository = local_repository[0]
235
+ self
236
+ end
237
+ end
238
+
239
+ # Sets the directory to publish artifacts from.
240
+ def publish_from(*publish_dir)
241
+ if publish_dir.empty?
242
+ @publish_from ||= @application.original_dir
243
+ else
244
+ raise "publish_from value invalid #{publish_dir.join(', ')}" unless publish_dir.size == 1
245
+ @publish_from = publish_dir[0]
246
+ self
247
+ end
248
+ end
249
+
250
+ # Sets the directory to create dependency reports in.
251
+ def report_dir(*report_dir)
252
+ if report_dir.empty?
253
+ @report_dir ||= @application.original_dir
254
+ else
255
+ raise "publish_from value invalid #{report_dir.join(', ')}" unless report_dir.size == 1
256
+ @report_dir = report_dir[0]
257
+ self
258
+ end
259
+ end
260
+ end
261
+
262
+ # Adds given block as post resolve action that is executed directly after #resolve has been called.
263
+ # Yields this ivy config object into block.
264
+ # <tt>project.ivy.post_resolve { |ivy| p "all deps:" + ivy.deps('all').join(", ") }</tt>
265
+ def post_resolve(&block)
266
+ post_resolve_tasks << block if block
267
+ end
268
+
269
+ # Filter artifacts for given configuration with provided filter values, this is a post resolve
270
+ # task like #deps.
271
+ # <tt>project.ivy.filter('server', 'client', :include => /b.*.jar/, :exclude => [/a\.jar/, /other.*\.jar/])</tt>
272
+ def filter(*confs)
273
+ filter = confs.last.kind_of?(Hash) ? confs.pop : {}
274
+ unless (filter.keys - (TYPES - [:conf])).empty?
275
+ raise ArgumentError, "Invalid filter use :include and/or :exclude only: given #{filter.keys.inspect}"
276
+ end
277
+ includes, excludes, types = filter[:include] || [], filter[:exclude] || [], filter[:type] || []
278
+
279
+ artifacts = deps(confs.flatten, types.flatten)
280
+ if artifacts
281
+ artifacts = artifacts.find_all do |lib|
282
+ lib = File.basename(lib)
283
+ includes = includes.reject {|i| i.nil? || i.blank? }
284
+ should_include = includes.empty? || includes.any? {|include| include === lib }
285
+ should_include && !excludes.any? {|exclude| exclude === lib}
286
+ end
287
+ end
288
+
289
+ artifacts
290
+ end
291
+
292
+ class Tasks < ::Rake::TaskLib
293
+ def initialize(ivy = nil, &block)
294
+ @ivy = ivy || Rake::Ivy::IvyConfig.new(Rake.application)
295
+ yield @ivy if block_given?
296
+ Rake.application.ivy = @ivy
297
+
298
+ define
299
+ end
300
+
301
+ private
302
+ def define
303
+ namespace 'ivy' do
304
+ task :configure do
305
+ Rake.application.ivy.configure
306
+ end
307
+
308
+ desc 'Resolves the ivy dependencies'
309
+ task :resolve => "ivy:configure" do
310
+ Rake.application.ivy.__resolve__
311
+ end
312
+
313
+ desc 'Publish the artifacts to ivy repository'
314
+ task :publish => "ivy:resolve" do
315
+ Rake.application.ivy.__publish__
316
+ end
317
+
318
+ desc 'Creates a dependency report for the project'
319
+ task :report => "ivy:resolve" do
320
+ Rake.application.ivy.report
321
+ end
322
+
323
+ desc 'Clean the local Ivy cache and the local ivy repository'
324
+ task :clean do
325
+ Rake.application.ivy.ivy4r.clean
326
+ end
327
+
328
+ desc 'Clean the local Ivy result cache to force execution of ivy targets'
329
+ task :clean_result_cache do
330
+ puts "Deleting IVY result cache dir '#{Rake.application.ivy.result_cache_dir}'"
331
+ rm_rf Rake.application.ivy.result_cache_dir
332
+ end
333
+
334
+ desc 'Enable the local Ivy result cache by creating the marker file'
335
+ task :enable_result_cache do
336
+ puts "Creating IVY caching marker file '#{Rake.application.ivy.caching_marker}'"
337
+ touch Rake.application.ivy.caching_marker
338
+ end
339
+
340
+ desc 'Disable the local Ivy result cache by removing the marker file'
341
+ task :disable_result_cache do
342
+ puts "Deleting IVY caching marker file '#{Rake.application.ivy.caching_marker}'"
343
+ rm_f Rake.application.ivy.caching_marker
344
+ end
345
+ end
346
+ end
347
+ end
348
+ end
349
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ivy4r
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.10.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Klaas Prause
@@ -73,11 +73,11 @@ dependencies:
73
73
  version: 2.5.0
74
74
  version:
75
75
  description: |-
76
- Apache Ivy dependency manager wrapper for ruby (see {Apache Ivy}[http://ant.apache.org/ivy/index.html] for more information).
77
- Use {Apache Ivy}[http://ant.apache.org/ivy/index.html] via a ruby wrapper without the need to use Apache Ant.
78
- The wrapper uses Antwrap[http://antwrap.rubyforge.org/] to interface with Ivy.
79
-
80
- Includes a Extension for Buildr[http://buildr.apache.org/] and Rake[http://rake.rubyforge.org] to use
76
+ Apache Ivy dependency manager wrapper for ruby (see {Apache Ivy}[http://ant.apache.org/ivy/index.html] for more information).
77
+ Use {Apache Ivy}[http://ant.apache.org/ivy/index.html] via a ruby wrapper without the need to use Apache Ant.
78
+ The wrapper uses Antwrap[http://antwrap.rubyforge.org/] to interface with Ivy.
79
+
80
+ Includes a Extension for Buildr[http://buildr.apache.org/] and Rake[http://rake.rubyforge.org] to use
81
81
  {Apache Ivy}[http://ant.apache.org/ivy/index.html] for dependency management.
82
82
  email:
83
83
  - klaas.prause@googlemail.com
@@ -130,7 +130,7 @@ files:
130
130
  - test/ivy/test_targets.rb
131
131
  - test/test_ivy4r.rb
132
132
  has_rdoc: true
133
- homepage: http://github.com/klaas1979/ivy4r/tree/master
133
+ homepage: http://github.com/klaas1979/ivy4r/tree/master
134
134
  licenses: []
135
135
 
136
136
  post_install_message: