maven-tools 0.34.5 → 1.0.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/lib/maven/tools/artifact.rb +18 -12
  3. data/lib/maven/tools/dsl.rb +282 -121
  4. data/lib/maven/tools/gemfile_lock.rb +0 -6
  5. data/lib/maven/tools/model.rb +78 -69
  6. data/lib/maven/tools/pom.rb +8 -8
  7. data/lib/maven/tools/version.rb +1 -1
  8. data/lib/maven/tools/versions.rb +4 -4
  9. data/lib/maven/tools/visitor.rb +2 -2
  10. data/spec/gemfile_with_lock/bouncy-castle-version.rb +4 -0
  11. data/spec/pom_maven_alternative_style/pom.rb +116 -169
  12. data/spec/pom_maven_hash_style/pom.rb +134 -100
  13. data/spec/pom_maven_style/pom.rb +160 -163
  14. data/spec/pom_spec.rb +3 -1
  15. metadata +12 -90
  16. data/lib/maven/model/dependencies.rb +0 -249
  17. data/lib/maven/model/model.rb +0 -618
  18. data/lib/maven/model/utils.rb +0 -393
  19. data/lib/maven/tools/execute_in_phase.rb +0 -28
  20. data/lib/maven/tools/gem_project.rb +0 -513
  21. data/lib/maven/tools/maven_project.rb +0 -72
  22. data/lib/maven/tools/minimal_project.rb +0 -84
  23. data/lib/maven/tools/pom_generator.rb +0 -83
  24. data/lib/maven/tools/rails_project.rb +0 -133
  25. data/rspec/maven/model/dependencies_spec.rb +0 -260
  26. data/rspec/maven/model/model_spec.rb +0 -714
  27. data/rspec/maven/tools/Gemfile.gems +0 -11
  28. data/rspec/maven/tools/Gemfile.groups +0 -15
  29. data/rspec/maven/tools/Gemfile.ignored +0 -30
  30. data/rspec/maven/tools/Gemfile.lockfile +0 -8
  31. data/rspec/maven/tools/Gemfile.lockfile.lock +0 -53
  32. data/rspec/maven/tools/Gemfile.minimal +0 -1
  33. data/rspec/maven/tools/Gemfile.nolock +0 -1
  34. data/rspec/maven/tools/Gemfile.rails +0 -16
  35. data/rspec/maven/tools/Gemfile.simple +0 -7
  36. data/rspec/maven/tools/Gemfile.withlock +0 -1
  37. data/rspec/maven/tools/Gemfile.withlock.lock +0 -28
  38. data/rspec/maven/tools/Jarfile.with +0 -2
  39. data/rspec/maven/tools/Jarfile.with.lock +0 -1
  40. data/rspec/maven/tools/Jarfile.without +0 -2
  41. data/rspec/maven/tools/deps.gemspec +0 -8
  42. data/rspec/maven/tools/gem_project_spec.rb +0 -1126
  43. data/rspec/maven/tools/maven-tools.gemspec +0 -17
  44. data/rspec/maven/tools/minimal.gemspec +0 -5
  45. data/rspec/maven/tools/no-deps.gemspec +0 -27
  46. data/rspec/maven/tools/rails_project_spec.rb +0 -284
  47. data/rspec/maven/tools/spec_helper.rb +0 -22
@@ -1,393 +0,0 @@
1
- #
2
- # Copyright (C) 2013 Christian Meier
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining a copy of
5
- # this software and associated documentation files (the "Software"), to deal in
6
- # the Software without restriction, including without limitation the rights to
7
- # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8
- # the Software, and to permit persons to whom the Software is furnished to do so,
9
- # subject to the following conditions:
10
- #
11
- # The above copyright notice and this permission notice shall be included in all
12
- # copies or substantial portions of the Software.
13
- #
14
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16
- # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17
- # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18
- # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
- # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
- #
21
- module Maven
22
- module Model
23
- class Tag
24
-
25
- def self.prepend_tags(*tags)
26
- _tags(true, *tags)
27
- end
28
-
29
- def self.tags(*tags)
30
- _tags(false, *tags)
31
- end
32
-
33
- def self._tags(prepend, *tags)
34
- if tags.size == 0
35
- @tags
36
- else
37
- #self.send :attr_accessor, *tags
38
- tags.each do |tag|
39
- eval <<-EOF
40
- def #{tag.to_s}(val = nil)
41
- @#{tag.to_s} = val if val
42
- @#{tag.to_s}
43
- end
44
- def #{tag.to_s}=(val)
45
- @#{tag.to_s} = val
46
- end
47
- EOF
48
- end
49
- if self.superclass.respond_to?:tags
50
- @tags ||= (self.superclass.tags || []).dup
51
- else
52
- @tags ||= []
53
- end
54
- unless @tags.include? tags[0]
55
- if prepend
56
- @tags.replace([tags, @tags].flatten)
57
- else
58
- @tags.replace([@tags, tags].flatten)
59
- end
60
- end
61
- @tags
62
- end
63
- end
64
-
65
- def _name
66
- self.class.to_s.downcase.sub(/.*::/, '')
67
- end
68
-
69
- def initialize(args = {})
70
- warn "deprecated #{args.inspect}" if args.size > 0
71
- args.each do |k,v|
72
- send("#{k}=".to_sym, v)
73
- end
74
- end
75
-
76
- def comment(c)
77
- @comment = c if c
78
- @comment
79
- end
80
-
81
- def to_xml(buf = "", indent = "")
82
- buf << "#{indent}<#{_name}>\n"
83
- buf << "#{indent}<!--\n#{indent}#{@comment}\n#{indent}-->\n" if @comment
84
- self.class.tags.each do |var|
85
- val = instance_variable_get("@#{var}".to_sym)
86
- var = var.to_s.gsub(/_(.)/) { $1.upcase }
87
- case val
88
- when Array
89
- val.flatten!
90
- if val.size > 0
91
- buf << "#{indent} <#{var}>\n"
92
- val.each do |v|
93
- if v.is_a? Tag
94
- v.to_xml(buf, indent + " ")
95
- else
96
- buf << "#{indent} <#{var.to_s.sub(/s$/, '')}>#{v}</#{var.to_s.sub(/s$/, '')}>\n"
97
- end
98
- end
99
- buf << "#{indent} </#{var}>\n"
100
- end
101
- when Hash
102
- if val.size > 0
103
- buf << "#{indent} <#{var}>\n"
104
- val.keys.each do |k|
105
- v = val[k]
106
- if v.is_a? Tag
107
- v.to_xml(buf, indent + " ")
108
- else
109
- buf << "#{indent} <#{k}>#{v}</#{k}>\n"
110
- end
111
- end
112
- buf << "#{indent} </#{var}>\n"
113
- end
114
- when Tag
115
- val.to_xml(buf, indent + " ")
116
- else
117
- #when String
118
- buf << "#{indent} <#{var}>#{val}</#{var}>\n" if val
119
- end
120
- end
121
- buf << "#{indent}</#{_name.sub(/ .*$/, '')}>\n"
122
- buf
123
- end
124
- end
125
-
126
- class NamedArray < Array
127
- attr_reader :name
128
- def initialize(name, &block)
129
- @name = name.to_s
130
- if block
131
- block.call(self)
132
- end
133
- self
134
- end
135
- end
136
-
137
- class ResourceArray < Array
138
-
139
- def initialize( name = 'resources', child = Resource, &block )
140
- @_child = child
141
- #super( name, &block )
142
- if block
143
- block.call self
144
- end
145
- self
146
- end
147
-
148
- alias :do_add :<<
149
-
150
- def add( &block )
151
- r = @_child.new
152
- block.call( r )
153
- do_add r
154
- r
155
- end
156
- alias :<< :add
157
-
158
- end
159
-
160
- class ModelHash < Hash
161
-
162
- def initialize(clazz)
163
- @clazz = clazz
164
- end
165
-
166
- def keys
167
- @keys ||= []
168
- end
169
-
170
- def get(key, &block)
171
- key = key.to_sym if key
172
- result = self[key]
173
- if result.nil?
174
- keys << key
175
- result = (self[key] = @clazz.new(key))
176
- end
177
- if block
178
- block.call(result)
179
- end
180
- result
181
- end
182
- alias :new :get
183
- alias :add :get
184
-
185
- def default_model
186
- @default_model ||=
187
- begin
188
- model = @clazz.new
189
- self[nil] = model
190
- model
191
- end
192
- end
193
-
194
- def method_missing(method, *args, &block)
195
- default_model.send(method, *args, &block)
196
- end
197
- end
198
-
199
- class NamedHash < Hash
200
-
201
- def keys
202
- @keys ||= []
203
- end
204
-
205
- def new_instance( clazz, args )
206
- if args.size == 1 && args[0].is_a?(clazz)
207
- args[0]
208
- else
209
- clazz.new(*args)
210
- end
211
- end
212
-
213
- def do_get( clazz, args, method, block = nil)
214
- value = new_instance( clazz, args )
215
- key = value.send method
216
- keys << key unless keys.member? key
217
- self[ key ] = value
218
- if block
219
- block.call( value )
220
- end
221
- value
222
- end
223
- def get; end
224
- end
225
-
226
- class DeveloperHash < NamedHash
227
-
228
- def get( *args, &block )
229
- do_get( Developer, args, :id, block )
230
- end
231
- alias :new :get
232
- alias :add :get
233
- end
234
-
235
- class LicenseHash < NamedHash
236
-
237
- def get( *args, &block )
238
- do_get( License, args, :name, block )
239
- end
240
- alias :new :get
241
- alias :add :get
242
- end
243
-
244
- class PluginHash < Hash
245
-
246
- def adjust_key(name)
247
- name = name.to_s
248
- if (name =~ /\:/).nil?
249
- if [:jruby, :gem, :rspec, :rake, :minitest, :rails3, :gemify, :cucumber, :runit, :bundler].member? name.to_sym
250
- "de.saumya.mojo:#{name}-maven-plugin"
251
- else
252
- "maven-#{name}-plugin"
253
- end
254
- else
255
- name
256
- end
257
- end
258
-
259
- def key?(k)
260
- super( adjust_key(k).to_sym )
261
- end
262
-
263
- def keys
264
- @keys ||= []
265
- end
266
-
267
- def get(*args, &block)
268
- case args.size
269
- when 3
270
- name = "#{args[0]}:#{args[1]}"
271
- version = args[2]
272
- when 2
273
- name = args[0].to_s
274
- version = args[1]
275
- when 1
276
- name = args[0].to_s
277
- else
278
- raise "need name"
279
- end
280
-
281
- name = adjust_key(name)
282
- group_id = name =~ /\:/ ? name.sub(/:.+$/, '') : nil
283
- artifact_id = name.sub(/^.+:/, '')
284
-
285
- k = "#{group_id}:#{artifact_id}".to_sym
286
- result = self[k]
287
- if result.nil?
288
- keys << k
289
- result = (self[k] = Plugin.new(group_id, artifact_id, version))
290
- end
291
- result.version = version if version
292
- if block
293
- block.call(result)
294
- end
295
- result
296
- end
297
- alias :new :get
298
- alias :add :get
299
-
300
- end
301
-
302
- class ListItems < Tag
303
-
304
- def initialize(name = nil)
305
- @name = name
306
- end
307
-
308
- def add(item)
309
- @items ||= Array.new
310
- @items << item
311
- end
312
- alias :<< :add
313
-
314
- def to_xml(buf = "", indent = "")
315
- buf << "#{indent}<#{@name}>\n" if @name
316
- buf << "#{indent}<!--\n#{indent}#{@comment}\n#{indent}-->\n" if @comment
317
- @items.each do |i|
318
- i.to_xml(buf, indent)
319
- end
320
- buf << "#{indent}</#{@name}>\n" if @name
321
- end
322
-
323
- end
324
-
325
- class HashTag < Tag
326
-
327
- def initialize(name, args = {})
328
- @name = name
329
- @props = args
330
- end
331
-
332
- def [](key)
333
- @props ||= {}
334
- @props[key]
335
- end
336
-
337
- def []=(key, value)
338
- @props ||= {}
339
- @props[key] = value
340
- end
341
-
342
- def to_xml(buf = "", indent = "")
343
- buf << "#{indent}<#{@name}>\n"
344
- buf << "#{indent}<!--\n#{indent}#{@comment}\n#{indent}-->\n" if @comment
345
- map_to_xml(buf, indent, @props)
346
- buf << "#{indent}</#{@name}>\n"
347
- end
348
-
349
- def map_to_xml(buf, indent, map)
350
- map.each do |k,v|
351
- case v
352
- when Hash
353
- buf << "#{indent} <#{k}>\n"
354
- map_to_xml(buf, indent + " ", v)
355
- buf << "#{indent} </#{k}>\n"
356
- when NamedArray
357
- buf << "#{indent} <#{k}>\n"
358
- v.each do|i|
359
- buf << "#{indent} <#{v.name}>\n"
360
- case i
361
- when Hash
362
- map_to_xml(buf, indent + " ", i)
363
- end
364
- buf << "#{indent} </#{v.name}>\n"
365
- end
366
- buf << "#{indent} </#{k}>\n"
367
- when Array
368
- buf << "#{indent} <#{k}>\n"
369
- singular = k.to_s.sub(/s$/, '')
370
- v.each do |i|
371
- case i
372
- when Hash
373
- buf << "#{indent} <#{singular}>\n"
374
- map_to_xml(buf, indent + " ", i)
375
- buf << "#{indent} </#{singular}>\n"
376
- when /^<.*>$/ #allow any kind of xml as is
377
- buf << "#{indent} #{i}\n"
378
- else
379
- buf << "#{indent} <#{singular}>#{i}</#{singular}>\n"
380
- end
381
- end
382
- buf << "#{indent} </#{k}>\n"
383
- when /\n$/
384
- buf << "#{indent} <#{k}>#{v}"
385
- buf << "#{indent} </#{k}>\n"
386
- else
387
- buf << "#{indent} <#{k}>#{v}</#{k}>\n"
388
- end
389
- end
390
- end
391
- end
392
- end
393
- end
@@ -1,28 +0,0 @@
1
- #
2
- # Copyright (C) 2013 Christian Meier
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining a copy of
5
- # this software and associated documentation files (the "Software"), to deal in
6
- # the Software without restriction, including without limitation the rights to
7
- # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8
- # the Software, and to permit persons to whom the Software is furnished to do so,
9
- # subject to the following conditions:
10
- #
11
- # The above copyright notice and this permission notice shall be included in all
12
- # copies or substantial portions of the Software.
13
- #
14
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16
- # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17
- # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18
- # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
- # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
- #
21
- require File.join(File.dirname(__FILE__), 'gem_project.rb')
22
-
23
- proj = Maven::Tools::GemProject.new("in_phase_execution")
24
-
25
- proj.load_mavenfile(ARGV[0])
26
-
27
- block = proj.executions_in_phase[ARGV[1]]
28
- block.call if block
@@ -1,513 +0,0 @@
1
- #
2
- # Copyright (C) 2013 Christian Meier
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining a copy of
5
- # this software and associated documentation files (the "Software"), to deal in
6
- # the Software without restriction, including without limitation the rights to
7
- # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8
- # the Software, and to permit persons to whom the Software is furnished to do so,
9
- # subject to the following conditions:
10
- #
11
- # The above copyright notice and this permission notice shall be included in all
12
- # copies or substantial portions of the Software.
13
- #
14
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16
- # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17
- # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18
- # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
- # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
- require File.join(File.dirname(__FILE__), 'gemfile_lock.rb')
21
- require File.join(File.dirname(__FILE__), 'versions.rb')
22
- require File.join(File.dirname(__FILE__), 'maven_project.rb')
23
-
24
- module Maven
25
- module Tools
26
-
27
- class GemProject < MavenProject
28
- tags :dummy
29
-
30
- def initialize(artifact_id = dir_name, version = "0.0.0", &block)
31
- super("rubygems", artifact_id, version, &block)
32
- packaging "gem"
33
- end
34
-
35
- def add_param(config, name, list, default = [])
36
- if list.is_a? Array
37
- config[name] = list.join(",").to_s unless (list || []) == default
38
- else
39
- # list == nil => (list || []) == default is true
40
- config[name] = list.to_s unless (list || []) == default
41
- end
42
- end
43
- private :add_param
44
-
45
- def load_gemspec(specfile)
46
- require 'rubygems'
47
- if specfile.is_a? ::Gem::Specification
48
- spec = specfile
49
- else
50
- spec = ::Gem::Specification.load(specfile)
51
- @gemspec = specfile
52
- end
53
- raise "file not found '#{specfile}'" unless spec
54
- @current_file = specfile
55
- artifact_id spec.name
56
- version spec.version
57
- name spec.summary || "#{self.artifact_id} - gem"
58
- description spec.description if spec.description
59
- url spec.homepage if spec.homepage
60
- done_authors = []
61
- (spec.email || []).zip(spec.authors || []).map do |email, author|
62
- done_authors << author
63
- self.developers.new(author, email)
64
- end
65
- (spec.authors - done_authors).each do |author|
66
- self.developers.new(author, nil)
67
- end
68
-
69
- # flatten the array since copyright-header-1.0.3.gemspec has a double
70
- # nested array
71
- (spec.licenses + spec.files.select {|file| file.to_s =~ /license|gpl/i }).flatten.each do |license|
72
- # TODO make this better, i.e. detect the right license name from the file itself
73
- self.licenses.new(license)
74
- end
75
-
76
- config = {}
77
- if @gemspec
78
- relative = File.expand_path(@gemspec).sub(/#{File.expand_path('.')}/, '').sub(/^\//, '')
79
- add_param(config, "gemspec", relative)
80
- end
81
- add_param(config, "autorequire", spec.autorequire)
82
- add_param(config, "defaultExecutable", spec.default_executable)
83
- add_param(config, "testFiles", spec.test_files)
84
- #has_rdoc always gives true => makes not sense to keep it then
85
- #add_param(config, "hasRdoc", spec.has_rdoc)
86
- add_param(config, "extraRdocFiles", spec.extra_rdoc_files)
87
- add_param(config, "rdocOptions", spec.rdoc_options)
88
- add_param(config, "requirePaths", spec.require_paths, ["lib"])
89
- add_param(config, "rubyforgeProject", spec.rubyforge_project)
90
- add_param(config, "requiredRubygemsVersion",
91
- spec.required_rubygems_version && spec.required_rubygems_version.to_s != ">= 0" ? "<![CDATA[#{spec.required_rubygems_version}]]>" : nil)
92
- add_param(config, "bindir", spec.bindir, "bin")
93
- add_param(config, "requiredRubyVersion",
94
- spec.required_ruby_version && spec.required_ruby_version.to_s != ">= 0" ? "<![CDATA[#{spec.required_ruby_version}]]>" : nil)
95
- add_param(config, "postInstallMessage",
96
- spec.post_install_message ? "<![CDATA[#{spec.post_install_message}]]>" : nil)
97
- add_param(config, "executables", spec.executables)
98
- add_param(config, "extensions", spec.extensions)
99
- add_param(config, "platform", spec.platform, 'ruby')
100
-
101
- # # TODO maybe calculate extra files
102
- # files = spec.files.dup
103
- # (Dir['lib/**/*'] + Dir['spec/**/*'] + Dir['features/**/*'] + Dir['test/**/*'] + spec.licenses + spec.extra_rdoc_files).each do |f|
104
- # files.delete(f)
105
- # if f =~ /^.\//
106
- # files.delete(f.sub(/^.\//, ''))
107
- # else
108
- # files.delete("./#{f}")
109
- # end
110
- # end
111
- #add_param(config, "extraFiles", files)
112
- add_param(config, "files", spec.files)
113
-
114
- plugin('gem').with(config) if config.size > 0
115
-
116
- spec.dependencies.each do |dep|
117
- scope =
118
- case dep.type
119
- when :runtime
120
- "compile"
121
- when :development
122
- "test"
123
- else
124
- warn "unknown scope: #{dep.type}"
125
- "compile"
126
- end
127
-
128
- versions = dep.requirement.requirements.collect do |req|
129
- # use this construct to get the same result in 1.8.x and 1.9.x
130
- req.collect{ |i| i.to_s }.join
131
- end
132
- add_gem(dep.name, versions).scope = scope
133
- if @lock
134
- # add its dependencies as well to have the version
135
- # determine by the dependencyManagement
136
- @lock.dependency_hull(dep.name).map.each do |d|
137
- add_gem(d[0], d[1]).scope = scope unless gem? d[0]
138
- end
139
- end
140
- end
141
-
142
- spec.requirements.each do |req|
143
- begin
144
- eval req
145
- rescue => e
146
- # TODO requirements is a list !!!
147
- add_param(config, "requirements", req)
148
- rescue SyntaxError => e
149
- # TODO requirements is a list !!!
150
- add_param(config, "requirements", req)
151
- rescue NameError => e
152
- # TODO requirements is a list !!!
153
- add_param(config, "requirements", req)
154
- end
155
- end
156
- end
157
-
158
- def load_gemfile(file)
159
- file = file.path if file.is_a?(File)
160
- if File.exists? file
161
- @current_file = file
162
- content = File.read(file)
163
- #loaded_files << file
164
- if @lock.nil?
165
- @lock = GemfileLock.new(file + ".lock")
166
- if @lock.size == 0
167
- @lock = nil
168
- else
169
- @lock.hull.each do |dep|
170
- dependency_management.gem dep
171
- end
172
- end
173
- end
174
- eval content
175
-
176
- # we have a Gemfile so we add the bundler plugin
177
- plugin(:bundler)
178
-
179
- # cleanup versions from deps
180
- if @lock
181
- dependencies.each do |d|
182
- if d.group_id == 'rubygems' && @lock.keys.member?( d.artifact_id )
183
- d.version = nil
184
- end
185
- end
186
- end
187
- else
188
- self
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
- has_prereleases = dependencies.detect { |d| d.type.to_sym == :gem && d.version =~ /[a-zA-Z]/ }
208
- if has_prereleases && repository("rubygems-prereleases").url.nil?
209
- repository("rubygems-prereleases") do |r|
210
- r.url = "http://rubygems-proxy.torquebox.org/prereleases"
211
- # r.releases(:enabled => false)
212
- r.snapshots(:enabled => true)
213
- end
214
- end
215
-
216
- # TODO go through all plugins to find out any SNAPSHOT version !!
217
- if versions[:jruby_plugins] =~ /-SNAPSHOT$/ || properties['jruby.plugins.version'] =~ /-SNAPSHOT$/
218
- plugin_repository("sonatype-snapshots") do |nexus|
219
- nexus.url = "http://oss.sonatype.org/content/repositories/snapshots"
220
- nexus.releases(:enabled => false)
221
- nexus.snapshots(:enabled => true)
222
- end
223
- end
224
-
225
- if packaging =~ /gem/ || plugin?(:gem)
226
- gem = plugin(:gem)
227
- gem.version = "${jruby.plugins.version}" unless gem.version
228
- if packaging =~ /gem/
229
- gem.extensions = true
230
- if @gemspec && !(self.gem?('jruby-openssl') || self.gem?('jruby-openssl-maven'))
231
- gem.gem('jruby-openssl')
232
- end
233
- end
234
- if File.exists?('lib') && File.exists?(File.join('src', 'main', 'java'))
235
- plugin(:jar) do |j|
236
- j.version = versions[:jar_plugin] unless j.version
237
- j.in_phase('prepare-package').execute_goal(:jar).with :outputDirectory => '${project.basedir}/lib', :finalName => '${project.artifactId}'
238
- end
239
- end
240
- end
241
-
242
- if @bundler_deps && @bundler_deps.size > 0
243
- plugin(:bundler)
244
- bdeps = []
245
- # first get the locked gems
246
- @bundler_deps.each do |args, dep|
247
- if @lock
248
- # add its dependencies as well to have the version
249
- # determine by the dependencyManagement
250
- @lock.dependency_hull(dep.artifact_id).map.each do |d|
251
- bdeps << d unless has_gem? d[0]
252
- end
253
- end
254
- end
255
- # any unlocked gems now
256
- @bundler_deps.each do |args, dep|
257
- bdeps << args unless has_gem? args[0]
258
- end
259
-
260
- # now add the deps to bundler plugin
261
- # avoid to setup bundler if it has no deps
262
- if bdeps.size > 0
263
- plugin(:bundler) do |bundler|
264
- # install will be triggered on initialize phase
265
- bundler.execution.goals << "install"
266
-
267
- bdeps.each do |d|
268
- bundler.gem(d)
269
- end
270
-
271
- # use the locked down version if available
272
- if @lock
273
- bundler.dependencies.each do |d|
274
- if d.group_id == 'rubygems' && @lock.keys.member?( d.artifact_id )
275
- d.version = @lock[ d.artifact_id ].version
276
- end
277
- end
278
- end
279
- end
280
- end
281
- end
282
-
283
- if plugin?(:bundler)
284
- bundler = plugin(:bundler)
285
- bundler.version = "${jruby.plugins.version}" unless bundler.version
286
- unless gem?(:bundler)
287
- gem("bundler").scope :test
288
- end
289
- end
290
-
291
- if gem?('bundler') && !gem('bundler').version?
292
- gem('bundler').version = nil
293
- dependency_management.gem 'bundler', versions[:bundler_version]
294
- end
295
-
296
- if versions[:jruby_plugins]
297
- #add_test_plugin(nil, "test")
298
- add_test_plugin("rspec", "spec")
299
- add_test_plugin("cucumber", "features")
300
- add_test_plugin("minitest", "test")
301
- add_test_plugin("minitest", "spec", 'spec')
302
- end
303
-
304
- self.properties = {
305
- "project.build.sourceEncoding" => "UTF-8",
306
- "gem.home" => "${project.build.directory}/rubygems",
307
- "gem.path" => "${project.build.directory}/rubygems",
308
- "jruby.plugins.version" => versions[:jruby_plugins]
309
- }.merge(self.properties)
310
-
311
- has_plugin_gems = build.plugins.detect do |k, pl|
312
- pl.dependencies.detect { |d| d.type.to_sym == :gem } if pl.dependencies
313
- end
314
-
315
- if has_plugin_gems
316
- plugin_repository("rubygems-releases").url = "http://rubygems-proxy.torquebox.org/releases" unless plugin_repository("rubygems-releases").url
317
-
318
- # unless plugin_repository("rubygems-prereleases").url
319
- # plugin_repository("rubygems-prereleases") do |r|
320
- # r.url = "http://rubygems-proxy.torquebox.org/prereleases"
321
- # r.releases(:enabled => false)
322
- # r.snapshots(:enabled => true)
323
- # end
324
- # end
325
- end
326
- # TODO
327
- configs = {
328
- :gem => [:initialize],
329
- :rails3 => [:initialize, :pom],
330
- :bundler => [:install]
331
- }.collect do |name, goals|
332
- if plugin?(name)
333
- {
334
- :pluginExecutionFilter => {
335
- :groupId => 'de.saumya.mojo',
336
- :artifactId => "#{name}-maven-plugin",
337
- :versionRange => '[0,)',
338
- :goals => goals
339
- },
340
- :action => { :ignore => nil }
341
- }
342
- end
343
- end
344
- configs.delete_if { |c| c.nil? }
345
- if configs.size > 0
346
- build.plugin_management do |pm|
347
- options = {
348
- :lifecycleMappingMetadata => {
349
- :pluginExecutions => Maven::Model::NamedArray.new(:pluginExecution) do |e|
350
- # sort them - handy for testing
351
- configs.sort {|m,n| m[:pluginExecutionFilter][:artifactId].to_s <=> n[:pluginExecutionFilter][:artifactId].to_s }.each { |c| e << c }
352
- end
353
- }
354
- }
355
- pm.plugins.get('org.eclipse.m2e:lifecycle-mapping', '1.0.0').configuration(options)
356
- end
357
- end
358
-
359
- if packaging =~ /gem/ || plugin?(:gem)
360
- profile('executable') do |exe|
361
- exe.jar('de.saumya.mojo:gem-assembly-descriptors', '${jruby.plugins.version}').scope :runtime
362
- exe.plugin(:assembly) do |a|
363
- a.version = versions[:assembly_plugin] unless a.version
364
- options = {
365
- :descriptorRefs => ['jar-with-dependencies-and-gems'],
366
- :archive => {:manifest => { :mainClass => 'de.saumya.mojo.assembly.Main' } }
367
- }
368
- a.configuration(options)
369
- a.in_phase(:package).execute_goal(:assembly)
370
- a.jar 'de.saumya.mojo:gem-assembly-descriptors', '${jruby.plugins.version}'
371
- end
372
- end
373
- end
374
- end
375
-
376
- def has_gem?(gem)
377
- self.gem?(gem)
378
- end
379
-
380
- def add_test_plugin(name, test_dir, goal = 'test')
381
- unless plugin?(name)
382
- has_gem = name.nil? ? true : gem?(name)
383
- if has_gem && File.exists?(test_dir)
384
- plugin(name || 'runit', "${jruby.plugins.version}").execution.goals << goal
385
- end
386
- else
387
- pl = plugin(name || 'runit')
388
- pl.version = "${jruby.plugins.version}" unless pl.version
389
- end
390
- end
391
- private :add_test_plugin
392
-
393
- def stack
394
- @stack ||= [[:default]]
395
- end
396
- private :stack
397
-
398
- def group(*args, &block)
399
- stack << args
400
- block.call if block
401
- stack.pop
402
- end
403
-
404
- def gemspec(name = nil)
405
- if name
406
- load_gemspec(File.join(File.dirname(@current_file), name))
407
- else
408
- Dir[File.join(File.dirname(@current_file), "*.gemspec")].each do |file|
409
- load_gemspec(file)
410
- end
411
- end
412
- end
413
-
414
- def source(*args)
415
- warn "ignore source #{args}" if !(args[0].to_s =~ /^https?:\/\/rubygems.org/) && args[0] != :rubygems
416
- end
417
-
418
- def path(*args)
419
- end
420
-
421
- def git(*args)
422
- end
423
-
424
- def is_jruby_platform(*args)
425
- args.detect { |a| :jruby == a.to_sym }
426
- end
427
- private :is_jruby_platform
428
-
429
- def platforms(*args, &block)
430
- if is_jruby_platform(*args)
431
- block.call
432
- end
433
- end
434
-
435
- def gem(*args, &block)
436
- dep = nil
437
- if args.last.is_a?(Hash)
438
- options = args.delete(args.last)
439
- unless options.key?(:git) || options.key?(:path)
440
- if (options[:platform].nil? && options[:platforms].nil?) || is_jruby_platform(*(options[:platform] || options[:platforms] || []))
441
- group = options[:group] || options[:groups]
442
- if group
443
- [group].flatten.each do |g|
444
- if dep
445
- profile(g).dependencies << dep
446
- else
447
- dep = profile(g).gem(args, &block)
448
- end
449
- end
450
- else
451
- self.gem(args, &block)
452
- end
453
- end
454
- end
455
- else
456
- stack.last.each do |c|
457
- if c == :default
458
- if @lock.nil? || args[0]== 'bundler'
459
- dep = add_gem(args, &block)
460
- else
461
- dep = add_gem(args[0], &block)
462
-
463
- # add its dependencies as well to have the version
464
- # determine by the dependencyManagement
465
- @lock.dependency_hull(args[0]).map.each do |d|
466
- add_gem d[0], nil
467
- end
468
- end
469
- else
470
- if @lock.nil?
471
- if dep
472
- profile(c).dependencies << dep
473
- else
474
- dep = profile(c).gem(args, &block)
475
- end
476
- else
477
- if dep
478
- profile(c).dependencies << dep
479
- else
480
- dep = profile(c).gem(args[0], nil, &block)
481
- end
482
- # add its dependencies as well to have the version
483
- # determine by the dependencyManagement
484
- @lock.dependency_hull(args[0]).map.each do |d|
485
- profile(c).gem d[0], nil unless gem? d[0]
486
- end
487
- end
488
- end
489
- end
490
- end
491
- if dep
492
- # first collect the missing deps it any
493
- @bundler_deps ||= []
494
- # use a dep with version so just create it from the args
495
- @bundler_deps << [args, dep]
496
- end
497
- dep
498
- end
499
- end
500
- end
501
- end
502
-
503
- if $0 == __FILE__
504
- proj = Maven::Tools::GemProject.new("test_gem")
505
- if ARGV[0] =~ /\.gemspec$/
506
- proj.load_gemspec(ARGV[0])
507
- else
508
- proj.load(ARGV[0] || 'Gemfile')
509
- end
510
- proj.load(ARGV[1] || 'Mavenfile')
511
- proj.add_defaults
512
- puts proj.to_xml
513
- end