maven-tools 0.31.0 → 0.32.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,322 +0,0 @@
1
- module Maven
2
- module Model
3
- class Tag
4
-
5
- def self.prepend_tags(*tags)
6
- _tags(true, *tags)
7
- end
8
-
9
- def self.tags(*tags)
10
- _tags(false, *tags)
11
- end
12
-
13
- def self._tags(prepend, *tags)
14
- if tags.size == 0
15
- @tags
16
- else
17
- #self.send :attr_accessor, *tags
18
- tags.each do |tag|
19
- eval <<-EOF
20
- def #{tag.to_s}(val = nil)
21
- @#{tag.to_s} = val if val
22
- @#{tag.to_s}
23
- end
24
- def #{tag.to_s}=(val)
25
- @#{tag.to_s} = val
26
- end
27
- EOF
28
- end
29
- if self.superclass.respond_to?:tags
30
- @tags ||= (self.superclass.tags || []).dup
31
- else
32
- @tags ||= []
33
- end
34
- unless @tags.include? tags[0]
35
- if prepend
36
- @tags.replace([tags, @tags].flatten)
37
- else
38
- @tags.replace([@tags, tags].flatten)
39
- end
40
- end
41
- @tags
42
- end
43
- end
44
-
45
- def _name
46
- self.class.to_s.downcase.sub(/.*::/, '')
47
- end
48
-
49
- def initialize(args = {})
50
- warn "deprecated #{args.inspect}" if args.size > 0
51
- args.each do |k,v|
52
- send("#{k}=".to_sym, v)
53
- end
54
- end
55
-
56
- def comment(c)
57
- @comment = c if c
58
- @comment
59
- end
60
-
61
- def to_xml(buf = "", indent = "")
62
- buf << "#{indent}<#{_name}>\n"
63
- buf << "#{indent}<!--\n#{indent}#{@comment}\n#{indent}-->\n" if @comment
64
- self.class.tags.each do |var|
65
- val = instance_variable_get("@#{var}".to_sym)
66
- var = var.to_s.gsub(/_(.)/) { $1.upcase }
67
- case val
68
- when Array
69
- val.flatten!
70
- if val.size > 0
71
- buf << "#{indent} <#{var}>\n"
72
- val.each do |v|
73
- if v.is_a? Tag
74
- v.to_xml(buf, indent + " ")
75
- else
76
- buf << "#{indent} <#{var.to_s.sub(/s$/, '')}>#{v}</#{var.to_s.sub(/s$/, '')}>\n"
77
- end
78
- end
79
- buf << "#{indent} </#{var}>\n"
80
- end
81
- when Hash
82
- if val.size > 0
83
- buf << "#{indent} <#{var}>\n"
84
- val.each do |k, v|
85
- if v.is_a? Tag
86
- v.to_xml(buf, indent + " ")
87
- else
88
- buf << "#{indent} <#{k}>#{v}</#{k}>\n"
89
- end
90
- end
91
- buf << "#{indent} </#{var}>\n"
92
- end
93
- when Tag
94
- val.to_xml(buf, indent + " ")
95
- else
96
- #when String
97
- buf << "#{indent} <#{var}>#{val}</#{var}>\n" if val
98
- end
99
- end
100
- buf << "#{indent}</#{_name.sub(/ .*$/, '')}>\n"
101
- buf
102
- end
103
- end
104
-
105
- class NamedArray < Array
106
- attr_reader :name
107
- def initialize(name, &block)
108
- @name = name.to_s
109
- if block
110
- block.call(self)
111
- end
112
- self
113
- end
114
- end
115
-
116
- class ModelHash < Hash
117
-
118
- def initialize(clazz)
119
- @clazz = clazz
120
- end
121
-
122
- def get(key, &block)
123
- key = key.to_sym if key
124
- result = self[key]
125
- if result.nil?
126
- result = (self[key] = @clazz.new(key))
127
- end
128
- if block
129
- block.call(result)
130
- end
131
- result
132
- end
133
- alias :new :get
134
- alias :add :get
135
-
136
- def default_model
137
- @default_model ||=
138
- begin
139
- model = @clazz.new
140
- self[nil] = model
141
- model
142
- end
143
- end
144
-
145
- def method_missing(method, *args, &block)
146
- default_model.send(method, *args, &block)
147
- end
148
- end
149
-
150
- class DeveloperHash < Hash
151
-
152
- def get(*args, &block)
153
- developer = if args.size == 1 && args[0].is_a?(Developer)
154
- args[0]
155
- else
156
- Developer.new(*args)
157
- end
158
- self[developer.id] = developer
159
- if block
160
- block.call(developer)
161
- end
162
- developer
163
- end
164
- alias :new :get
165
- alias :add :get
166
- end
167
-
168
- class LicenseHash < Hash
169
-
170
- def get(*args, &block)
171
- license = if args.size == 1 && args[0].is_a?(License)
172
- args[0]
173
- else
174
- License.new(*args)
175
- end
176
- self[license.name] = license
177
- if block
178
- block.call(license)
179
- end
180
- license
181
- end
182
- alias :new :get
183
- alias :add :get
184
- end
185
-
186
- class PluginHash < Hash
187
-
188
- def adjust_key(name)
189
- name = name.to_s
190
- if (name =~ /\:/).nil?
191
- if [:jruby, :gem, :rspec, :rake, :minitest, :rails3, :gemify, :cucumber, :runit, :bundler].member? name.to_sym
192
- "de.saumya.mojo:#{name}-maven-plugin"
193
- else
194
- "maven-#{name}-plugin"
195
- end
196
- else
197
- name
198
- end
199
- end
200
-
201
- def key?(k)
202
- super( adjust_key(k).to_sym )
203
- end
204
-
205
- def get(*args, &block)
206
- case args.size
207
- when 3
208
- name = "#{args[0]}:#{args[1]}"
209
- version = args[2]
210
- when 2
211
- name = args[0].to_s
212
- version = args[1]
213
- when 1
214
- name = args[0].to_s
215
- else
216
- raise "need name"
217
- end
218
-
219
- name = adjust_key(name)
220
- group_id = name =~ /\:/ ? name.sub(/:.+$/, '') : nil
221
- artifact_id = name.sub(/^.+:/, '')
222
-
223
- k = "#{group_id}:#{artifact_id}".to_sym
224
- result = self[k]
225
- if result.nil?
226
- result = (self[k] = Plugin.new(group_id, artifact_id, version))
227
- end
228
- result.version = version if version
229
- if block
230
- block.call(result)
231
- end
232
- result
233
- end
234
- alias :new :get
235
- alias :add :get
236
-
237
- end
238
-
239
- class ListItems < Tag
240
-
241
- def initialize(name = nil)
242
- @name = name
243
- end
244
-
245
- def add(item)
246
- @items ||= Array.new
247
- @items << item
248
- end
249
- alias :<< :add
250
-
251
- def to_xml(buf = "", indent = "")
252
- buf << "#{indent}<#{@name}>\n" if @name
253
- buf << "#{indent}<!--\n#{indent}#{@comment}\n#{indent}-->\n" if @comment
254
- @items.each do |i|
255
- i.to_xml(buf, indent)
256
- end
257
- buf << "#{indent}</#{@name}>\n" if @name
258
- end
259
-
260
- end
261
-
262
- class HashTag < Tag
263
-
264
- def initialize(name, args = {})
265
- @name = name
266
- @props = args
267
- end
268
-
269
- def [](key)
270
- @props ||= {}
271
- @props[key]
272
- end
273
-
274
- def []=(key, value)
275
- @props ||= {}
276
- @props[key] = value
277
- end
278
-
279
- def to_xml(buf = "", indent = "")
280
- buf << "#{indent}<#{@name}>\n"
281
- buf << "#{indent}<!--\n#{indent}#{@comment}\n#{indent}-->\n" if @comment
282
- map_to_xml(buf, indent, @props)
283
- buf << "#{indent}</#{@name}>\n"
284
- end
285
-
286
- def map_to_xml(buf, indent, map)
287
- # sort the hash over the keys
288
- map.collect { |k,v| [k.to_s, v]}.sort.each do |k,v|
289
- case v
290
- when Hash
291
- buf << "#{indent} <#{k}>\n"
292
- map_to_xml(buf, indent + " ", v)
293
- buf << "#{indent} </#{k}>\n"
294
- when NamedArray
295
- buf << "#{indent} <#{k}>\n"
296
- v.each do|i|
297
- buf << "#{indent} <#{v.name}>\n"
298
- case i
299
- when Hash
300
- map_to_xml(buf, indent + " ", i)
301
- end
302
- buf << "#{indent} </#{v.name}>\n"
303
- end
304
- buf << "#{indent} </#{k}>\n"
305
- when Array
306
- buf << "#{indent} <#{k}>\n"
307
- singular = k.to_s.sub(/s$/, '')
308
- v.each do |i|
309
- buf << "#{indent} <#{singular}>#{i}</#{singular}>\n"
310
- end
311
- buf << "#{indent} </#{k}>\n"
312
- when /\n$/
313
- buf << "#{indent} <#{k}>#{v}"
314
- buf << "#{indent} </#{k}>\n"
315
- else
316
- buf << "#{indent} <#{k}>#{v}</#{k}>\n"
317
- end
318
- end
319
- end
320
- end
321
- end
322
- end
@@ -1,81 +0,0 @@
1
- puts "=-------------------"
2
- module Maven
3
- module Tools
4
- module Coordinate
5
-
6
- def to_coordinate(line)
7
- if line =~ /^\s*(jar|pom)\s/
8
-
9
- group_id, artifact_id, version, second_version = line.sub(/\s*[a-z]+\s+/, '').sub(/#.*/,'').gsub(/\s+/,'').gsub(/['"],/, ':').gsub(/['"]/, '').split(/:/)
10
- mversion = second_version ? to_version(version, second_version) : to_version(version)
11
- extension = line.strip.sub(/\s+.*/, '')
12
- "#{group_id}:#{artifact_id}:#{extension}:#{mversion}"
13
- end
14
- end
15
-
16
- def group_artifact(*args)
17
- case args.size
18
- when 1
19
- name = args[0]
20
- if name =~ /:/
21
- [name.sub(/:[^:]+$/, ''), name.sub(/.*:/, '')]
22
- else
23
- ["rubygems", name]
24
- end
25
- else
26
- [args[0], args[1]]
27
- end
28
- end
29
-
30
- def gav(*args)
31
- if args[0] =~ /:/
32
- [args[0].sub(/:[^:]+$/, ''), args[0].sub(/.*:/, ''), to_version(*args[1, 2])]
33
- else
34
- [args[0], args[1], to_version(*args[2,3])]
35
- end
36
- end
37
-
38
- def to_version(*args)
39
- if args.size == 0 || (args.size == 1 && args[0].nil?)
40
- "[0,)"
41
- else
42
- low, high = convert(args[0])
43
- low, high = convert(args[1], low, high) if args[1] =~ /[=~><]/
44
- if low == high
45
- low
46
- else
47
- "#{low || '[0'},#{high || ')'}"
48
- end
49
- end
50
- end
51
-
52
- private
53
-
54
- def convert(arg, low = nil, high = nil)
55
- if arg =~ /~>/
56
- val = arg.sub(/~>\s*/, '')
57
- last = val.sub(/\.[^.]+$/, '.99999')
58
- ["[#{val}", "#{last}]"]
59
- elsif arg =~ />=/
60
- val = arg.sub(/>=\s*/, '')
61
- ["[#{val}", (nil || high)]
62
- elsif arg =~ /<=/
63
- val = arg.sub(/<=\s*/, '')
64
- [(nil || low), "#{val}]"]
65
- # treat '!' the same way as '>' since maven can not describe such range
66
- elsif arg =~ /[!>]/
67
- val = arg.sub(/[!>]\s*/, '')
68
- ["(#{val}", (nil || high)]
69
- elsif arg =~ /</
70
- val = arg.sub(/<\s*/, '')
71
- [(nil || low), "#{val})"]
72
- elsif arg =~ /\=/
73
- val = arg.sub(/=\s*/, '')
74
- ["[" + val, val + '.0.0.0.0.1)']
75
- else
76
- [arg, arg]
77
- end
78
- end
79
- end
80
- end
81
- end
@@ -1,498 +0,0 @@
1
- # TODO make nice require after ruby-maven uses the same ruby files
2
- require File.join(File.dirname(File.dirname(__FILE__)), 'model', 'model.rb')
3
- require File.join(File.dirname(__FILE__), 'gemfile_lock.rb')
4
- require File.join(File.dirname(__FILE__), 'versions.rb')
5
- require File.join(File.dirname(__FILE__), 'jarfile.rb')
6
-
7
- module Maven
8
- module Tools
9
-
10
- class ArtifactPassthrough
11
-
12
- def initialize(&block)
13
- @block = block
14
- end
15
-
16
- def add_artifact(a)
17
- @block.call(a)
18
- end
19
-
20
- def add_repository(name, url)
21
- end
22
- end
23
-
24
- class GemProject < Maven::Model::Project
25
- tags :dummy
26
-
27
- def initialize(artifact_id = dir_name, version = "0.0.0", &block)
28
- super("rubygems", artifact_id, version, &block)
29
- packaging "gem"
30
- end
31
-
32
- def add_param(config, name, list, default = [])
33
- if list.is_a? Array
34
- config[name] = list.join(",").to_s unless (list || []) == default
35
- else
36
- # list == nil => (list || []) == default is true
37
- config[name] = list.to_s unless (list || []) == default
38
- end
39
- end
40
- private :add_param
41
-
42
- def load_gemspec(specfile)
43
- require 'rubygems'
44
- if specfile.is_a? ::Gem::Specification
45
- spec = specfile
46
- else
47
- spec = ::Gem::Specification.load(specfile)
48
- @gemspec = specfile
49
- end
50
- raise "file not found '#{specfile}'" unless spec
51
- @current_file = specfile
52
- artifact_id spec.name
53
- version spec.version
54
- name spec.summary || "#{self.artifact_id} - gem"
55
- description spec.description if spec.description
56
- url spec.homepage if spec.homepage
57
- (spec.email || []).zip(spec.authors || []).map do |email, author|
58
- self.developers.new(author, email)
59
- end
60
-
61
- # TODO work with collection of licenses - there can be more than one !!!
62
- (spec.licenses + spec.files.select {|file| file.to_s =~ /license|gpl/i }).each do |license|
63
- # TODO make this better, i.e. detect the right license name from the file itself
64
- self.licenses.new(license)
65
- end
66
-
67
- config = {}
68
- if @gemspec
69
- relative = File.expand_path(@gemspec).sub(/#{File.expand_path('.')}/, '').sub(/^\//, '')
70
- add_param(config, "gemspec", relative)
71
- end
72
- add_param(config, "autorequire", spec.autorequire)
73
- add_param(config, "defaultExecutable", spec.default_executable)
74
- add_param(config, "testFiles", spec.test_files)
75
- #has_rdoc always gives true => makes not sense to keep it then
76
- #add_param(config, "hasRdoc", spec.has_rdoc)
77
- add_param(config, "extraRdocFiles", spec.extra_rdoc_files)
78
- add_param(config, "rdocOptions", spec.rdoc_options)
79
- add_param(config, "requirePaths", spec.require_paths, ["lib"])
80
- add_param(config, "rubyforgeProject", spec.rubyforge_project)
81
- add_param(config, "requiredRubygemsVersion",
82
- spec.required_rubygems_version && spec.required_rubygems_version != ">= 0" ? "<![CDATA[#{spec.required_rubygems_version}]]>" : nil)
83
- add_param(config, "bindir", spec.bindir, "bin")
84
- add_param(config, "requiredRubyVersion",
85
- spec.required_ruby_version && spec.required_ruby_version != ">= 0" ? "<![CDATA[#{spec.required_ruby_version}]]>" : nil)
86
- add_param(config, "postInstallMessage",
87
- spec.post_install_message ? "<![CDATA[#{spec.post_install_message}]]>" : nil)
88
- add_param(config, "executables", spec.executables)
89
- add_param(config, "extensions", spec.extensions)
90
- add_param(config, "platform", spec.platform, 'ruby')
91
-
92
- # # TODO maybe calculate extra files
93
- # files = spec.files.dup
94
- # (Dir['lib/**/*'] + Dir['spec/**/*'] + Dir['features/**/*'] + Dir['test/**/*'] + spec.licenses + spec.extra_rdoc_files).each do |f|
95
- # files.delete(f)
96
- # if f =~ /^.\//
97
- # files.delete(f.sub(/^.\//, ''))
98
- # else
99
- # files.delete("./#{f}")
100
- # end
101
- # end
102
- #add_param(config, "extraFiles", files)
103
- add_param(config, "files", spec.files)
104
-
105
- plugin('gem').with(config) if config.size > 0
106
-
107
- spec.dependencies.each do |dep|
108
- scope =
109
- case dep.type
110
- when :runtime
111
- "compile"
112
- when :development
113
- "test"
114
- else
115
- warn "unknown scope: #{dep.type}"
116
- "compile"
117
- end
118
-
119
- versions = dep.requirement.requirements.collect do |req|
120
- # use this construct to get the same result in 1.8.x and 1.9.x
121
- req.collect{ |i| i.to_s }.join
122
- end
123
- gem(dep.name, versions).scope = scope
124
- end
125
-
126
- spec.requirements.each do |req|
127
- begin
128
- eval req
129
- rescue => e
130
- # TODO requirements is a list !!!
131
- add_param(config, "requirements", req)
132
- warn e
133
- rescue SyntaxError => e
134
- # TODO requirements is a list !!!
135
- add_param(config, "requirements", req)
136
- end
137
- end
138
- end
139
-
140
- def load_mavenfile(file)
141
- file = file.path if file.is_a?(File)
142
- if File.exists? file
143
- @current_file = file
144
- content = File.read(file)
145
- eval content
146
- else
147
- self
148
- end
149
- end
150
-
151
- def load_gemfile(file)
152
- file = file.path if file.is_a?(File)
153
- if File.exists? file
154
- @current_file = file
155
- content = File.read(file)
156
- #loaded_files << file
157
- if @lock.nil?
158
- @lock = GemfileLock.new(file + ".lock")
159
- if @lock.size == 0
160
- @lock = nil
161
- else
162
- # loaded_files << file + ".lock"
163
- # just make sure bundler is there and has a version
164
- @lock.hull.each do |dep|
165
- dependency_management.gem dep
166
- end
167
- end
168
- end
169
- eval content
170
-
171
- # we have a Gemfile so we add the bundler plugin
172
- plugin(:bundler)
173
- else
174
- self
175
- end
176
- end
177
-
178
- def load_jarfile(file)
179
- jars = Jarfile.new(file)
180
- if jars.exists?
181
- container = ArtifactPassthrough.new do |a|
182
- artifactId, groupId, extension, version = a.split(/:/)
183
- send(extension.to_sym, "#{artifactId}:#{groupId}", version)
184
- end
185
- if !jars.exists_lock? || jars.mtime > jars.mtime_lock
186
- jars.populate_unlocked container
187
- end
188
- jars.populate_locked container
189
- end
190
- end
191
-
192
- def dir_name
193
- File.basename(File.expand_path("."))
194
- end
195
- private :dir_name
196
-
197
- def add_defaults(args = {})
198
- versions = VERSIONS
199
- versions = versions.merge(args) if args
200
-
201
- name "#{dir_name} - gem" unless name
202
-
203
- packaging "gem" unless packaging
204
-
205
- repository("rubygems-releases").url = "http://rubygems-proxy.torquebox.org/releases" unless repository("rubygems-releases").url
206
-
207
- unless repository("rubygems-prereleases").url
208
- repository("rubygems-prereleases") do |r|
209
- r.url = "http://rubygems-proxy.torquebox.org/prereleases"
210
- r.releases(:enabled => false)
211
- r.snapshots(:enabled => true)
212
- end
213
- end
214
-
215
- # TODO go through all plugins to find out any SNAPSHOT version !!
216
- if versions[:jruby_plugins] =~ /-SNAPSHOT$/ || properties['jruby.plugins.version'] =~ /-SNAPSHOT$/
217
- plugin_repository("sonatype-snapshots") do |nexus|
218
- nexus.url = "http://oss.sonatype.org/content/repositories/snapshots"
219
- nexus.releases(:enabled => false)
220
- nexus.snapshots(:enabled => true)
221
- end
222
- end
223
-
224
- if packaging =~ /gem/ || plugin?(:gem)
225
- gem = plugin(:gem)
226
- gem.version = "${jruby.plugins.version}" unless gem.version
227
- if packaging =~ /gem/
228
- gem.extensions = true
229
- if @gemspec && !(self.gem?('jruby-openssl') || self.gem?('jruby-openssl-maven'))
230
- gem.gem('jruby-openssl-maven')
231
- end
232
- end
233
- if File.exists?('lib') && File.exists?(File.join('src', 'main', 'java'))
234
- plugin(:jar) do |j|
235
- j.version = versions[:jar_plugin] unless j.version
236
- j.in_phase('prepare-package').execute_goal(:jar).with :outputDirectory => '${project.basedir}/lib', :finalName => '${project.artifactId}'
237
- end
238
- end
239
- end
240
-
241
- if @bundler_deps && @bundler_deps.size > 0
242
- plugin(:bundler)
243
- bdeps = []
244
- # first get the locked gems
245
- @bundler_deps.each do |args, dep|
246
- if @lock
247
- # add its dependencies as well to have the version
248
- # determine by the dependencyManagement
249
- @lock.dependency_hull(dep.artifact_id).map.each do |d|
250
- bdeps << d unless has_gem? d[0]
251
- end
252
- end
253
- end
254
- # any unlocked gems now
255
- @bundler_deps.each do |args, dep|
256
- bdeps << args unless has_gem? args[0]
257
- end
258
-
259
- # now add the deps to bundler plugin
260
- # avoid to setup bundler if it has no deps
261
- if bdeps.size > 0
262
- plugin(:bundler) do |bundler|
263
- # install will be triggered on initialize phase
264
- bundler.executions.goals << "install"
265
- bdeps.each do |d|
266
- bundler.gem(d)
267
- end
268
- end
269
- end
270
- end
271
-
272
- if plugin?(:bundler)
273
- bundler = plugin(:bundler)
274
- bundler.version = "${jruby.plugins.version}" unless bundler.version
275
- unless gem?(:bundler)
276
- gem("bundler")
277
- end
278
- end
279
-
280
- if gem?('bundler') && !gem('bundler').version?
281
- gem('bundler').version = nil
282
- dependency_management.gem 'bundler', versions[:bundler_version]
283
- end
284
-
285
- if versions[:jruby_plugins]
286
- #add_test_plugin(nil, "test")
287
- add_test_plugin("rspec", "spec")
288
- add_test_plugin("cucumber", "features")
289
- add_test_plugin("minitest", "test")
290
- add_test_plugin("minitest", "spec", 'spec')
291
- end
292
-
293
- self.properties = {
294
- "project.build.sourceEncoding" => "UTF-8",
295
- "gem.home" => "${project.build.directory}/rubygems",
296
- "gem.path" => "${project.build.directory}/rubygems",
297
- "jruby.plugins.version" => versions[:jruby_plugins]
298
- }.merge(self.properties)
299
-
300
- has_plugin_gems = build.plugins.detect do |k, pl|
301
- pl.dependencies.detect { |d| d.type.to_sym == :gem } if pl.dependencies
302
- end
303
-
304
- if has_plugin_gems
305
- plugin_repository("rubygems-releases").url = "http://rubygems-proxy.torquebox.org/releases" unless plugin_repository("rubygems-releases").url
306
-
307
- unless plugin_repository("rubygems-prereleases").url
308
- plugin_repository("rubygems-prereleases") do |r|
309
- r.url = "http://rubygems-proxy.torquebox.org/prereleases"
310
- r.releases(:enabled => false)
311
- r.snapshots(:enabled => true)
312
- end
313
- end
314
- end
315
- # TODO
316
- configs = {
317
- :gem => [:initialize],
318
- :rails3 => [:initialize, :pom],
319
- :bundler => [:install]
320
- }.collect do |name, goals|
321
- if plugin?(name)
322
- {
323
- :pluginExecutionFilter => {
324
- :groupId => 'de.saumya.mojo',
325
- :artifactId => "#{name}-maven-plugin",
326
- :versionRange => '[0,)',
327
- :goals => goals
328
- },
329
- :action => { :ignore => nil }
330
- }
331
- end
332
- end
333
- configs.delete_if { |c| c.nil? }
334
- if configs.size > 0
335
- build.plugin_management do |pm|
336
- options = {
337
- :lifecycleMappingMetadata => {
338
- :pluginExecutions => Maven::Model::NamedArray.new(:pluginExecution) do |e|
339
- configs.each { |c| e << c }
340
- end
341
- }
342
- }
343
- pm.plugins.get('org.eclipse.m2e:lifecycle-mapping', '1.0.0').configuration(options)
344
- end
345
- end
346
-
347
- profile('executable') do |exe|
348
- exe.jar('de.saumya.mojo:gem-assembly-descriptors', '${jruby.plugins.version}').scope :runtime
349
- exe.plugin(:assembly, '2.2-beta-5') do |a|
350
- options = {
351
- :descriptorRefs => ['jar-with-dependencies-and-gems'],
352
- :archive => {:manifest => { :mainClass => 'de.saumya.mojo.assembly.Main' } }
353
- }
354
- a.configuration(options)
355
- a.in_phase(:package).execute_goal(:assembly)
356
- a.jar 'de.saumya.mojo:gem-assembly-descriptors', '${jruby.plugins.version}'
357
- end
358
- end
359
- end
360
-
361
- def has_gem?(gem)
362
- self.gem?(gem)
363
- end
364
-
365
- def add_test_plugin(name, test_dir, goal = 'test')
366
- unless plugin?(name)
367
- has_gem = name.nil? ? true : gem?(name)
368
- if has_gem && File.exists?(test_dir)
369
- plugin(name || 'runit', "${jruby.plugins.version}").execution.goals << goal
370
- end
371
- else
372
- pl = plugin(name || 'runit')
373
- pl.version = "${jruby.plugins.version}" unless pl.version
374
- end
375
- end
376
- private :add_test_plugin
377
-
378
- def stack
379
- @stack ||= [[:default]]
380
- end
381
- private :stack
382
-
383
- def group(*args, &block)
384
- stack << args
385
- block.call if block
386
- stack.pop
387
- end
388
-
389
- def gemspec(name = nil)
390
- if name
391
- load_gemspec(File.join(File.dirname(@current_file), name))
392
- else
393
- Dir[File.join(File.dirname(@current_file), "*.gemspec")].each do |file|
394
- load_gemspec(file)
395
- end
396
- end
397
- end
398
-
399
- def source(*args)
400
- warn "ignore source #{args}" if !(args[0].to_s =~ /^https?:\/\/rubygems.org/) && args[0] != :rubygems
401
- end
402
-
403
- def path(*args)
404
- end
405
-
406
- def git(*args)
407
- end
408
-
409
- def is_jruby_platform(*args)
410
- args.detect { |a| :jruby == a.to_sym }
411
- end
412
- private :is_jruby_platform
413
-
414
- def platforms(*args, &block)
415
- if is_jruby_platform(*args)
416
- block.call
417
- end
418
- end
419
-
420
- def gem(*args, &block)
421
- dep = nil
422
- if args.last.is_a?(Hash)
423
- options = args.delete(args.last)
424
- unless options.key?(:git) || options.key?(:path)
425
- if options[:platforms].nil? || is_jruby_platform(*(options[:platforms] || []))
426
- group = options[:group] || options[:groups]
427
- if group
428
- [group].flatten.each do |g|
429
- if dep
430
- profile(g).dependencies << dep
431
- else
432
- dep = profile(g).gem(args, &block)
433
- end
434
- end
435
- else
436
- self.gem(args, &block)
437
- end
438
- end
439
- end
440
- else
441
- stack.last.each do |c|
442
- if c == :default
443
- if @lock.nil? || args[0]== 'bundler'
444
- dep = add_gem(args, &block)
445
- else
446
- dep = add_gem(args[0], &block)
447
-
448
- # add its dependencies as well to have the version
449
- # determine by the dependencyManagement
450
- @lock.dependency_hull(args[0]).map.each do |d|
451
- add_gem d[0], nil
452
- end
453
- end
454
- else
455
- if @lock.nil?
456
- if dep
457
- profile(c).dependencies << dep
458
- else
459
- dep = profile(c).gem(args, &block)
460
- end
461
- else
462
- if dep
463
- profile(c).dependencies << dep
464
- else
465
- dep = profile(c).gem(args[0], nil, &block)
466
- end
467
- # add its dependencies as well to have the version
468
- # determine by the dependencyManagement
469
- @lock.dependency_hull(args[0]).map.each do |d|
470
- profile(c).gem d[0], nil unless gem? d[0]
471
- end
472
- end
473
- end
474
- end
475
- end
476
- if dep
477
- # first collect the missing deps it any
478
- @bundler_deps ||= []
479
- # use a dep with version so just create it from the args
480
- @bundler_deps << [args, dep]
481
- end
482
- dep
483
- end
484
- end
485
- end
486
- end
487
-
488
- if $0 == __FILE__
489
- proj = Maven::Tools::GemProject.new("test_gem")
490
- if ARGV[0] =~ /\.gemspec$/
491
- proj.load_gemspec(ARGV[0])
492
- else
493
- proj.load(ARGV[0] || 'Gemfile')
494
- end
495
- proj.load(ARGV[1] || 'Mavenfile')
496
- proj.add_defaults
497
- puts proj.to_xml
498
- end