pepijnve-ivy4r 0.12.11
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +14 -0
- data/.gitignore +7 -0
- data/.project +17 -0
- data/.rspec +2 -0
- data/CHANGELOG +280 -0
- data/Gemfile +5 -0
- data/README.txt +124 -0
- data/Rakefile +36 -0
- data/autotest/discover.rb +1 -0
- data/ivy4r.gemspec +30 -0
- data/lib/buildr/ivy_extension.rb +808 -0
- data/lib/ivy/artifactproperty.rb +34 -0
- data/lib/ivy/artifactreport.rb +24 -0
- data/lib/ivy/buildlist.rb +37 -0
- data/lib/ivy/buildnumber.rb +34 -0
- data/lib/ivy/cachepath.rb +30 -0
- data/lib/ivy/cleancache.rb +20 -0
- data/lib/ivy/configure.rb +29 -0
- data/lib/ivy/findrevision.rb +34 -0
- data/lib/ivy/info.rb +36 -0
- data/lib/ivy/install.rb +33 -0
- data/lib/ivy/java/all_version_matcher.rb +31 -0
- data/lib/ivy/java/java_object_wrapper.rb +160 -0
- data/lib/ivy/listmodules.rb +35 -0
- data/lib/ivy/makepom.rb +30 -0
- data/lib/ivy/publish.rb +37 -0
- data/lib/ivy/report.rb +33 -0
- data/lib/ivy/resolve.rb +44 -0
- data/lib/ivy/retrieve.rb +27 -0
- data/lib/ivy/settings.rb +15 -0
- data/lib/ivy/target.rb +162 -0
- data/lib/ivy/targets.rb +50 -0
- data/lib/ivy4r.rb +252 -0
- data/lib/ivy4r/version.rb +3 -0
- data/lib/ivy4r_java_extensions.rb +42 -0
- data/lib/rake/ivy_extension.rb +349 -0
- data/spec/ivy/target_spec.rb +86 -0
- data/spec/ivy/targets_spec.rb +27 -0
- data/spec/ivy4r_spec.rb +50 -0
- data/spec/spec_helper.rb +10 -0
- data/spec_files/buildlist/p1/buildfile +0 -0
- data/spec_files/buildlist/p1/ivy.xml +7 -0
- data/spec_files/buildlist/sub/p2/buildfile +0 -0
- data/spec_files/buildlist/sub/p2/ivy.xml +11 -0
- data/spec_files/buildlist/sub/p3/buildfile +0 -0
- data/spec_files/buildlist/sub/p3/ivy.xml +11 -0
- data/spec_files/ivy.xml +18 -0
- data/spec_files/ivysettings.xml +11 -0
- data/spec_functional/ivy4r_spec.rb +131 -0
- metadata +214 -0
data/lib/ivy4r.rb
ADDED
@@ -0,0 +1,252 @@
|
|
1
|
+
require 'ivy4r/version'
|
2
|
+
require 'ivy4r_jars'
|
3
|
+
require 'antwrap'
|
4
|
+
require 'ivy/targets'
|
5
|
+
|
6
|
+
=begin rdoc
|
7
|
+
Simple wrapper that maps the ant ivy targets one to one to ruby. See the {Apache Ivy}[http://ant.apache.org/ivy/index.html]
|
8
|
+
for more informations about the parameters for a call. All ivy ant targets have the equivalent
|
9
|
+
name in this class.
|
10
|
+
|
11
|
+
The standard parameters are provided as Hash, i.e.:
|
12
|
+
<ivy:configure file="settings.xml" settingsId="my.id" />
|
13
|
+
is
|
14
|
+
ivy4r.configure :file => "settings.xml", :settingsId => 'my.id'
|
15
|
+
|
16
|
+
You can use nested options via the nested attribute:
|
17
|
+
<ivy:buildlist reference="testpath">
|
18
|
+
<fileset dir="target/p1" includes="buildfile" />
|
19
|
+
</ivy:buildlist>
|
20
|
+
is
|
21
|
+
@ivy4r.buildlist :reference => 'testpath', :nested => {
|
22
|
+
:fileset => {:dir => 'target/p1', :includes => 'buildfile'}
|
23
|
+
}
|
24
|
+
|
25
|
+
you can nest more than on element of the same type using an array:
|
26
|
+
<ivy:buildlist reference="testpath">
|
27
|
+
<fileset dir="target/sub" includes="**/buildfile" />
|
28
|
+
<fileset dir="target/p1" includes="buildfile" />
|
29
|
+
</ivy:buildlist>
|
30
|
+
is
|
31
|
+
@ivy4r.buildlist :reference => 'testpath', :nested => {
|
32
|
+
:fileset => [
|
33
|
+
{:dir => 'target/sub', :includes => '**/buildfile'},
|
34
|
+
{:dir => 'target/p1', :includes => 'buildfile'}
|
35
|
+
]
|
36
|
+
}
|
37
|
+
=end
|
38
|
+
class Ivy4r
|
39
|
+
|
40
|
+
# Set the ant home directory to load ant classes from if no custom __antwrap__ is provided
|
41
|
+
# and the default provided ant version 1.7.1 should not be used.
|
42
|
+
# Must be set before any call to method that uses the ivy is made.
|
43
|
+
attr_accessor :ant_home
|
44
|
+
|
45
|
+
# Defines the directory to load ivy libs and its dependencies from
|
46
|
+
attr_accessor :lib_dir
|
47
|
+
|
48
|
+
# Optional ant variable <tt>ivy.project.dir</tt> to add to ant environment before loading ivy
|
49
|
+
# defaults to the __lib_dir__
|
50
|
+
attr_accessor :project_dir
|
51
|
+
|
52
|
+
# The ant property name to use for references to environment properties in ant and ivy,
|
53
|
+
# defaults to 'env'
|
54
|
+
attr_accessor :environment_property
|
55
|
+
|
56
|
+
# To provide a custom __antwrap__ to use instead of default one
|
57
|
+
attr_accessor :ant
|
58
|
+
|
59
|
+
# Access to ivy settings set via configure or settings method.
|
60
|
+
attr_accessor :settings_file
|
61
|
+
|
62
|
+
# Donates the base directory for the cached files, if nil no caching is enabled
|
63
|
+
attr_accessor :cache_dir
|
64
|
+
|
65
|
+
# Initalizes ivy4r with optional ant wrapper object. Sets ant home dir and ivy lib dir
|
66
|
+
# to default values from __Ivy4rJars__ gem.
|
67
|
+
def initialize(ant_instance = nil, &block)
|
68
|
+
@ant_home = ::Ivy4rJars.ant_home_dir
|
69
|
+
@lib_dir = ::Ivy4rJars.lib_dir
|
70
|
+
@project_dir = @lib_dir
|
71
|
+
@environment_property = 'env'
|
72
|
+
@ant = ant_instance
|
73
|
+
|
74
|
+
if block
|
75
|
+
if block.arity > 1
|
76
|
+
raise ArgumentError, "To many arguments expected=1 given=#{block.arity}"
|
77
|
+
elsif block.arity == 1
|
78
|
+
yield self
|
79
|
+
else
|
80
|
+
instance_eval(&block)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# Calls the __cleancache__ ivy target with given parameters.
|
86
|
+
def cleancache(*params)
|
87
|
+
Ivy::Cleancache.new(ant, cache_dir).execute(*params)
|
88
|
+
end
|
89
|
+
|
90
|
+
# Calls the __settings__ ivy target with given parameters.
|
91
|
+
def settings(*params)
|
92
|
+
settings_task = Ivy::Settings.new(ant, nil) # do not cache settings
|
93
|
+
result = settings_task.execute(*params)
|
94
|
+
@settings_file = settings_task.params[:file]
|
95
|
+
result
|
96
|
+
end
|
97
|
+
|
98
|
+
# Calls the __configure__ ivy target with given parameters.
|
99
|
+
def configure(*params)
|
100
|
+
configure_task = Ivy::Configure.new(ant, nil) # do not cache configure
|
101
|
+
result = configure_task.execute(*params)
|
102
|
+
@settings_file = configure_task.params[:file]
|
103
|
+
result
|
104
|
+
end
|
105
|
+
|
106
|
+
# Calls the __info__ ivy target with given parameters and returns info as hash.
|
107
|
+
def info(*params)
|
108
|
+
Ivy::Info.new(ant, cache_dir).execute(*params)
|
109
|
+
end
|
110
|
+
|
111
|
+
# Calls the __buildnumber__ ivy target with given parameters and returns info as hash.
|
112
|
+
def buildnumber(*params)
|
113
|
+
Ivy::Buildnumber.new(ant, cache_dir).execute(*params)
|
114
|
+
end
|
115
|
+
|
116
|
+
# Calls the __listmodules__ ivy target with given parameters and returns info as hash.
|
117
|
+
def listmodules(*params) #:nodoc:
|
118
|
+
Ivy::Listmodules.new(ant, cache_dir).execute(*params)
|
119
|
+
end
|
120
|
+
|
121
|
+
# Calls the __makepom__ ivy target with given parameters and returns pom content.
|
122
|
+
def makepom(*params)
|
123
|
+
Ivy::Makepom.new(ant, cache_dir).execute(*params)
|
124
|
+
end
|
125
|
+
|
126
|
+
# Calls the __resolve__ ivy target with given parameters and returns info as hash.
|
127
|
+
def resolve(*params)
|
128
|
+
Ivy::Resolve.new(ant, cache_dir).execute(*params)
|
129
|
+
end
|
130
|
+
|
131
|
+
# Calls the __retrieve__ ivy target with given parameters.
|
132
|
+
def retrieve(*params)
|
133
|
+
Ivy::Retrieve.new(ant, cache_dir).execute(*params)
|
134
|
+
end
|
135
|
+
|
136
|
+
# Calls the __publish__ ivy target with given parameters.
|
137
|
+
def publish(*params)
|
138
|
+
Ivy::Publish.new(ant, cache_dir).execute(*params)
|
139
|
+
end
|
140
|
+
|
141
|
+
# Calls the __cachepath__ ivy target with given parameters and returns
|
142
|
+
# array containing absolute file paths to all artifacts contained in result
|
143
|
+
def cachepath(*params)
|
144
|
+
Ivy::Cachepath.new(ant, cache_dir).execute(*params)
|
145
|
+
end
|
146
|
+
|
147
|
+
# Calls the __findrevision__ ivy target with given parameters and returns
|
148
|
+
# array containing absolute file paths to all artifacts contained in result
|
149
|
+
def findrevision(*params)
|
150
|
+
Ivy::Findrevision.new(ant, cache_dir).execute(*params)
|
151
|
+
end
|
152
|
+
|
153
|
+
# Calls the __install__ ivy target with given parameters always returns nil
|
154
|
+
def install(*params)
|
155
|
+
Ivy::Install.new(ant, cache_dir).execute(*params)
|
156
|
+
end
|
157
|
+
|
158
|
+
# Calls the __artifactproperty__ ivy target with given parameters and returns
|
159
|
+
# map with all defined properties
|
160
|
+
def artifactproperty(*params)
|
161
|
+
Ivy::Artifactproperty.new(ant, cache_dir).execute(*params)
|
162
|
+
end
|
163
|
+
|
164
|
+
# Calls the __buildlist__ ivy target with given parameters and returns
|
165
|
+
# the resulting buildlist
|
166
|
+
def buildlist(*params)
|
167
|
+
Ivy::Buildlist.new(ant, cache_dir).execute(*params)
|
168
|
+
end
|
169
|
+
|
170
|
+
# Calls the __artifactreport__ ivy target with given parameters and returns
|
171
|
+
# the created xml.
|
172
|
+
def artifactreport(*params)
|
173
|
+
Ivy::Artifactreport.new(ant, cache_dir).execute(*params)
|
174
|
+
end
|
175
|
+
|
176
|
+
# Calls the __report__ ivy target with given parameters
|
177
|
+
def report(*params)
|
178
|
+
Ivy::Report.new(ant, cache_dir).execute(*params)
|
179
|
+
end
|
180
|
+
|
181
|
+
# Used to get or set ant properties.
|
182
|
+
# [set] <tt>property['name'] = value</tt> sets the ant property with name to given value no overwrite
|
183
|
+
# [get] <tt>property[matcher]</tt> gets property that is equal via case equality operator (<tt>===</tt>)
|
184
|
+
def property
|
185
|
+
AntPropertyHelper.new(ant, ant_properties)
|
186
|
+
end
|
187
|
+
|
188
|
+
# Returns the __antwrap__ instance to use for all internal calls creates a default
|
189
|
+
# instance if no instance has been set before.
|
190
|
+
def ant
|
191
|
+
@ant ||= ::Antwrap::AntProject.new(:ant_home => ant_home,
|
192
|
+
:name => "ivy-ant", :basedir => Dir.pwd, :declarative => true)
|
193
|
+
init(@ant) if should_init?
|
194
|
+
@ant
|
195
|
+
end
|
196
|
+
|
197
|
+
private
|
198
|
+
def should_init?
|
199
|
+
@init_done.nil? || @init_done == false
|
200
|
+
end
|
201
|
+
|
202
|
+
def init(ant)
|
203
|
+
@init_done = true
|
204
|
+
ant.property :environment => environment_property
|
205
|
+
ant.property :name => 'ivy.project.dir', :value => project_dir
|
206
|
+
ant.path :id => 'ivy.lib.path' do
|
207
|
+
ant.fileset :dir => lib_dir, :includes => '*.jar'
|
208
|
+
end
|
209
|
+
|
210
|
+
ant.typedef :name => "ivy_settings", :classname => "org.apache.ivy.ant.IvyAntSettings", :classpathref => "ivy.lib.path", :loaderRef => 'ivy.lib.path.loader', :loaderRef => 'ivy.lib.path.loader'
|
211
|
+
ant.taskdef :name => "ivy_configure", :classname => "org.apache.ivy.ant.IvyConfigure", :classpathref => "ivy.lib.path", :loaderRef => 'ivy.lib.path.loader'
|
212
|
+
ant.taskdef :name => "ivy_resolve", :classname => "org.apache.ivy.ant.IvyResolve", :classpathref => "ivy.lib.path", :loaderRef => 'ivy.lib.path.loader'
|
213
|
+
ant.taskdef :name => "ivy_retrieve", :classname => "org.apache.ivy.ant.IvyRetrieve", :classpathref => "ivy.lib.path", :loaderRef => 'ivy.lib.path.loader'
|
214
|
+
ant.taskdef :name => "ivy_deliver", :classname => "org.apache.ivy.ant.IvyDeliver", :classpathref => "ivy.lib.path", :loaderRef => 'ivy.lib.path.loader'
|
215
|
+
ant.taskdef :name => "ivy_publish", :classname => "org.apache.ivy.ant.IvyPublish", :classpathref => "ivy.lib.path", :loaderRef => 'ivy.lib.path.loader'
|
216
|
+
ant.taskdef :name => "ivy_extract", :classname => "org.apache.ivy.ant.IvyExtractFromSources", :classpathref => "ivy.lib.path", :loaderRef => 'ivy.lib.path.loader'
|
217
|
+
ant.taskdef :name => "ivy_cachepath", :classname => "org.apache.ivy.ant.IvyCachePath", :classpathref => "ivy.lib.path", :loaderRef => 'ivy.lib.path.loader'
|
218
|
+
ant.taskdef :name => "ivy_cachefileset", :classname => "org.apache.ivy.ant.IvyCacheFileset", :classpathref => "ivy.lib.path", :loaderRef => 'ivy.lib.path.loader'
|
219
|
+
ant.taskdef :name => "ivy_report", :classname => "org.apache.ivy.ant.IvyReport", :classpathref => "ivy.lib.path", :loaderRef => 'ivy.lib.path.loader'
|
220
|
+
ant.taskdef :name => "ivy_repreport", :classname => "org.apache.ivy.ant.IvyRepositoryReport", :classpathref => "ivy.lib.path", :loaderRef => 'ivy.lib.path.loader'
|
221
|
+
ant.taskdef :name => "ivy_var", :classname => "org.apache.ivy.ant.IvyVar", :classpathref => "ivy.lib.path", :loaderRef => 'ivy.lib.path.loader'
|
222
|
+
ant.taskdef :name => "ivy_check", :classname => "org.apache.ivy.ant.IvyCheck", :classpathref => "ivy.lib.path", :loaderRef => 'ivy.lib.path.loader'
|
223
|
+
ant.taskdef :name => "ivy_artifactproperty", :classname => "org.apache.ivy.ant.IvyArtifactProperty", :classpathref => "ivy.lib.path", :loaderRef => 'ivy.lib.path.loader'
|
224
|
+
ant.taskdef :name => "ivy_buildlist", :classname => "org.apache.ivy.ant.IvyBuildList", :classpathref => "ivy.lib.path", :loaderRef => 'ivy.lib.path.loader'
|
225
|
+
ant.taskdef :name => "ivy_install", :classname => "org.apache.ivy.ant.IvyInstall", :classpathref => "ivy.lib.path", :loaderRef => 'ivy.lib.path.loader'
|
226
|
+
ant.taskdef :name => "ivy_convertpom", :classname => "org.apache.ivy.ant.IvyConvertPom", :classpathref => "ivy.lib.path", :loaderRef => 'ivy.lib.path.loader'
|
227
|
+
ant.taskdef :name => "ivy_makepom", :classname => "org.apache.ivy.ant.IvyMakePom", :classpathref => "ivy.lib.path", :loaderRef => 'ivy.lib.path.loader'
|
228
|
+
ant.taskdef :name => "ivy_artifactreport", :classname => "org.apache.ivy.ant.IvyArtifactReport", :classpathref => "ivy.lib.path", :loaderRef => 'ivy.lib.path.loader'
|
229
|
+
ant.taskdef :name => "ivy_info", :classname => "org.apache.ivy.ant.IvyInfo", :classpathref => "ivy.lib.path", :loaderRef => 'ivy.lib.path.loader'
|
230
|
+
ant.taskdef :name => "ivy_addpath", :classname => "org.apache.ivy.ant.AddPathTask", :classpathref => "ivy.lib.path", :loaderRef => 'ivy.lib.path.loader'
|
231
|
+
ant.taskdef :name => "ivy_listmodules", :classname => "org.apache.ivy.ant.IvyListModules", :classpathref => "ivy.lib.path", :loaderRef => 'ivy.lib.path.loader'
|
232
|
+
ant.taskdef :name => "ivy_findrevision", :classname => "org.apache.ivy.ant.IvyFindRevision", :classpathref => "ivy.lib.path", :loaderRef => 'ivy.lib.path.loader'
|
233
|
+
ant.taskdef :name => "ivy_buildnumber", :classname => "org.apache.ivy.ant.IvyBuildNumber", :classpathref => "ivy.lib.path", :loaderRef => 'ivy.lib.path.loader'
|
234
|
+
ant.taskdef :name => "ivy_cleancache", :classname => "org.apache.ivy.ant.IvyCleanCache", :classpathref => "ivy.lib.path", :loaderRef => 'ivy.lib.path.loader'
|
235
|
+
end
|
236
|
+
|
237
|
+
# Returns the ant properties, note that this are java objects.
|
238
|
+
def ant_properties
|
239
|
+
ant.project.properties
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
AntPropertyHelper = Struct.new(:ant, :ant_properties) do #:nodoc:
|
244
|
+
def []=(name, value) #:nodoc:
|
245
|
+
ant.property :name => name, :value => value
|
246
|
+
end
|
247
|
+
|
248
|
+
def [](matcher) #:nodoc:
|
249
|
+
property = ant_properties.find {|p| matcher === p[0] }
|
250
|
+
property ? property[1] : nil
|
251
|
+
end
|
252
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# basic stuff
|
2
|
+
require 'ivy4r'
|
3
|
+
|
4
|
+
# java extensions
|
5
|
+
Dir[Ivy4rJars.lib_dir + "/*.jar"].each {|jar| require jar}
|
6
|
+
require 'ivy/java/all_version_matcher'
|
7
|
+
|
8
|
+
class Ivy4r
|
9
|
+
# Returns the ivy instance for underlying ant project with the current ivy settings.
|
10
|
+
def ivy_instance
|
11
|
+
unless @ivy_instance
|
12
|
+
variable_container = Java::OrgApacheIvyAnt::IvyAntVariableContainer.new(ant.project)
|
13
|
+
settings_file = find_settings_file(variable_container) unless settings_file
|
14
|
+
raise "no settings file set and no default settings found, cannot create ivy instance" unless settings_file
|
15
|
+
raise "settings file does not exist: #{settings_file}" unless File.exists? settings_file
|
16
|
+
|
17
|
+
settings = Java::OrgApacheIvyCoreSettings::IvySettings.new(variable_container)
|
18
|
+
settings.base_dir = ant.project.base_dir
|
19
|
+
@ivy_instance = Java::OrgApacheIvy::Ivy.new_instance(settings)
|
20
|
+
@ivy_instance.configure(Java::JavaIo::File.new(settings_file))
|
21
|
+
end
|
22
|
+
|
23
|
+
@ivy_instance
|
24
|
+
end
|
25
|
+
|
26
|
+
# Returns the ant references, note that this are java objects.
|
27
|
+
def ant_references
|
28
|
+
ant.project.references
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
def find_settings_file(variable_container)
|
33
|
+
settings_file_name = variable_container.get_variable("ivy.conf.file") || variable_container.get_variable("ivy.settings.file")
|
34
|
+
setting_locations = [
|
35
|
+
File.join(ant.project.base_dir.absolute_path, settings_file_name),
|
36
|
+
File.join(ant.project.base_dir.absolute_path, 'ivyconf.xml'),
|
37
|
+
settings_file_name,
|
38
|
+
'ivyconf.xml'
|
39
|
+
]
|
40
|
+
setting_locations.find {|path| File.exists? path }
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +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
|
+
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.empty? }
|
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 if status
|
96
|
+
ivy4r.property['ivy.home'] = home if 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
|
130
|
+
end
|
131
|
+
|
132
|
+
def settings
|
133
|
+
@settings ||= "#{@extension_dir}/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.respond_to?(:empty?) && i.empty?) || (i.respond_to?(:source) && i.source.empty?) }
|
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
|