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,832 +0,0 @@
1
- module Maven
2
- module Model
3
- class Tag
4
-
5
- def self.tags(*tags)
6
- if tags.size == 0
7
- @tags
8
- else
9
- #self.send :attr_accessor, *tags
10
- tags.each do |tag|
11
- eval <<-EOF
12
- def #{tag.to_s}(val = nil)
13
- @#{tag.to_s} = val if val
14
- @#{tag.to_s}
15
- end
16
- def #{tag.to_s}=(val)
17
- @#{tag.to_s} = val
18
- end
19
- EOF
20
- end
21
- @tags ||= []
22
- if self.superclass.respond_to?:tags
23
- @tags = self.superclass.tags || []
24
- else
25
- @tags ||= []
26
- end
27
- @tags.replace([ @tags, tags].flatten)
28
- end
29
- end
30
-
31
- def _name
32
- self.class.to_s.downcase.sub(/.*::/, '')
33
- end
34
-
35
- def initialize(args = {})
36
- args.each do |k,v|
37
- send("#{k}=".to_sym, v)
38
- end
39
- end
40
-
41
- def to_xml(buf = "", indent = "")
42
- buf << "#{indent}<#{_name}>\n"
43
- self.class.tags.each do |var|
44
- val = instance_variable_get("@#{var}".to_sym)
45
- var = var.to_s.gsub(/_(.)/) { $1.upcase }
46
- case val
47
- when Array
48
- val.flatten!
49
- if val.size > 0
50
- buf << "#{indent} <#{var}>\n"
51
- val.each do |v|
52
- if v.is_a? Tag
53
- v.to_xml(buf, indent + " ")
54
- else
55
- buf << "#{indent} <#{var.to_s.sub(/s$/, '')}>#{v}</#{var.to_s.sub(/s$/, '')}>\n"
56
- end
57
- end
58
- buf << "#{indent} </#{var}>\n"
59
- end
60
- when Hash
61
- if val.size > 0
62
- buf << "#{indent} <#{var}>\n"
63
- val.each do |k, v|
64
- if v.is_a? Tag
65
- v.to_xml(buf, indent + " ")
66
- else
67
- buf << "#{indent} <#{k}>#{v}</#{k}>\n"
68
- end
69
- end
70
- buf << "#{indent} </#{var}>\n"
71
- end
72
- when Tag
73
- val.to_xml(buf, indent + " ")
74
- else
75
- #when String
76
- buf << "#{indent} <#{var}>#{val}</#{var}>\n" if val
77
- end
78
- end
79
- buf << "#{indent}</#{_name}>\n"
80
- buf
81
- end
82
- end
83
-
84
- # class Coordinate < Tag
85
- # tags :group_id, :artifact_id, :version
86
- # def initialize(args = {})
87
- # super
88
- # end
89
-
90
- # def ==(other)
91
- # group_id == other.group_id && artifact_id == other.artifact_id
92
- # end
93
- # end
94
-
95
- # class Dependency < Coordinate
96
- # tags :type, :scope, :classifier
97
- # def initialize(group_id, artifact_id, version = nil, type = nil)
98
- # super(:group_id => group_id, :artifact_id => artifact_id, :version => version, :type => type)
99
- # end
100
- # end
101
-
102
- # class Gem < Dependency
103
- # tags :dummy
104
- # def initialize(gemname, version = nil)
105
- # super("rubygems", gemname, version, "gem")
106
- # end
107
-
108
- # def _name
109
- # "dependency"
110
- # end
111
- # end
112
-
113
- class NamedArray < Array
114
- attr_reader :name
115
- def initialize(name, &block)
116
- @name = name.to_s
117
- if block
118
- block.call(self)
119
- end
120
- self
121
- end
122
- end
123
-
124
- # class DepArray < Array
125
- # def <<(args)
126
- # item =
127
- # case args
128
- # when Dependency
129
- # args
130
- # when Array
131
- # if args.size == 1
132
- # args << "[0.0.0,)"
133
- # elsif args.size == 2 && args.last.is_a?(Hash)
134
- # args = [args[0], "[0.0.0,)", args[1]]
135
- # elsif args.size >= 2
136
- # if args[1] =~ /~>/
137
- # val = args[1].sub(/~>\s*/, '')
138
- # last = val.sub(/\.[^.]+$/, '.99999')
139
- # args[1] = "[#{val}, #{last}]"
140
- # elsif args[1] =~ />=/
141
- # val = args[1].sub(/>=\s*/, '')
142
- # args[1] = "[#{val},)"
143
- # elsif args[1] =~ /<=/
144
- # val = args[1].sub(/<=\s*/, '')
145
- # args[1] = "[0.0.0,#{val}]"
146
- # elsif args[1] =~ />/
147
- # val = args[1].sub(/>\s*/, '')
148
- # args[1] = "(#{val},)"
149
- # elsif args[1] =~ /</
150
- # val = args[1].sub(/<\s*/, '')
151
- # args[1] = "[0.0.0,#{val})"
152
- # end
153
- # end
154
- # if args[0] =~ /:/
155
- # Dependency.new(args[0].sub(/:[^:]+$/, ''),
156
- # args[0].sub(/.*:/, ''),
157
- # args[1])
158
- # else
159
- # args = args.delete(2) if args[2]
160
- # Gem.new(*args)
161
- # end
162
- # when String
163
- # if args =~ /:/
164
- # Dependency.new(args.sub(/:[^:]+$/, ''),
165
- # args.sub(/.*:/, ''))
166
- # else
167
- # Gem.new(args)
168
- # end
169
- # else
170
- # args
171
- # end
172
- # super item unless member? item
173
- # item
174
- # end
175
-
176
- # end
177
-
178
- class Build < Tag
179
- tags :finalName, :plugins
180
- def plugins(&block)
181
- @plugins ||= PluginHash.new
182
- if block
183
- block.call(@plugins)
184
- end
185
- @plugins
186
- end
187
-
188
- def plugin?(name)
189
- plugins.key?(name)
190
- end
191
-
192
- def to_xml(buf = "", indent = "")
193
- if @finalName.nil? && (@plugins.nil? || @plugins.size == 0)
194
- ""
195
- else
196
- super
197
- end
198
- end
199
- end
200
-
201
- class Plugin < Coordinate
202
- tags :extensions, :configuration, :executions, :dependencies
203
- def initialize(group_id, artifact_id, version, &block)
204
- super(:artifact_id => artifact_id, :version => version)
205
- @group_id = group_id if group_id
206
- if block
207
- block.call(self)
208
- end
209
- self
210
- end
211
-
212
- def dependencies(&block)
213
- @dependencies ||= DepArray.new
214
- if block
215
- block.call(@dependencies)
216
- end
217
- @dependencies
218
- end
219
-
220
- def with(config)
221
- self.configuration = config
222
- end
223
-
224
- def in_phase(phase, name = nil, &block)
225
- name = "in_phase_#{phase.gsub(/-/,'_')}" unless name
226
- self.executions.get(name) do |exe|
227
- exe.phase = phase
228
- block.call(exe) if block
229
- exe
230
- end
231
- end
232
-
233
- def executions
234
- @executions ||= ModelHash.new(Execution)
235
- end
236
-
237
- def execution(name = nil, &block)
238
- executions.get(name, &block)
239
- end
240
-
241
- def configuration=(c)
242
- if c.is_a? Hash
243
- @configuration = Configuration.new(c)
244
- else
245
- @configuration = c
246
- end
247
- end
248
- end
249
-
250
- class Execution < Tag
251
- tags :id, :phase, :goals, :inherited, :configuration
252
-
253
- def initialize(id = nil)
254
- super({ :id => id })
255
- end
256
-
257
- def configuration=(c)
258
- if c.is_a? Hash
259
- @configuration = Configuration.new(c)
260
- else
261
- @configuration = c
262
- end
263
- end
264
-
265
- def execute_goal(g)
266
- self.goals = g
267
- self
268
- end
269
-
270
- def with(config)
271
- self.configuration = config
272
- end
273
-
274
- def goals
275
- @goals ||= []
276
- end
277
-
278
- def goals=(goals)
279
- @goals = goals.is_a?(Array) ? goals: [goals]
280
- end
281
- end
282
-
283
- class DependencyManagement < Tag
284
- tags :dependencies
285
-
286
- def _name
287
- "dependencyManagement"
288
- end
289
-
290
- def dependencies(&block)
291
- @dependencies ||= DepArray.new
292
- if block
293
- block.call(@dependencies)
294
- end
295
- @dependencies
296
- end
297
- end
298
-
299
- class Profile < Tag
300
- tags :id, :activation, :dependencies, :dependency_management, :properties, :build
301
-
302
- def initialize(id, &block)
303
- super(:id => id)
304
- if block
305
- block.call(self)
306
- end
307
- self
308
- end
309
-
310
- def properties
311
- (@properties || Properties.new).map
312
- end
313
-
314
- def properties=(props)
315
- if props.is_a? Hash
316
- @properties = Properties.new(props)
317
- else
318
- @properties = props
319
- end
320
- end
321
-
322
- def build
323
- @build ||= Build.new
324
- end
325
-
326
- def activation(name = nil, value = nil, &block)
327
- @activation ||= Activation.new
328
- if name || value
329
- warn "deprecated, use 'property_activation' instead"
330
- @activation.property(name, value)
331
- else
332
- block.call(@activation) if block
333
- @activation
334
- end
335
- end
336
-
337
- def default_activation(name = nil, value = nil)
338
- warn "deprecated, use 'activation.by_default.property(name.value)' instead"
339
- activation.property(name, value).by_default
340
- end
341
-
342
- def plugin(*args, &block)
343
- build.plugins.get(*args, &block)
344
- end
345
-
346
- def dependencies(&block)
347
- @dependencies ||= DepArray.new
348
- if block
349
- block.call(@dependencies)
350
- end
351
- @dependencies
352
- end
353
-
354
- def dependency_management(&block)
355
- @dependency_management ||= DependencyManagement.new
356
- if block
357
- block.call(@dependency_management.dependencies)
358
- end
359
- @dependency_management.dependencies
360
- end
361
- end
362
-
363
- class ModelHash < Hash
364
-
365
- def initialize(clazz)
366
- @clazz = clazz
367
- end
368
-
369
- def get(key, &block)
370
- key = key.to_sym if key
371
- result = self[key]
372
- if result.nil?
373
- result = (self[key] = @clazz.new(key))
374
- end
375
- if block
376
- block.call(result)
377
- end
378
- result
379
- end
380
- alias :new :get
381
-
382
- def default_model
383
- @default_model ||=
384
- begin
385
- model = @clazz.new
386
- self[nil] = model
387
- model
388
- end
389
- end
390
-
391
- def method_missing(method, *args, &block)
392
- default_model.send(method, *args, &block)
393
- end
394
- end
395
-
396
- class DeveloperHash < Hash
397
-
398
- def get(*args, &block)
399
- developer = if args.size == 1 && args[0].is_a?(Developer)
400
- args[0]
401
- else
402
- Developer.new(*args)
403
- end
404
- self[developer.id] = developer
405
- if block
406
- block.call(developer)
407
- end
408
- developer
409
- end
410
- alias :new :get
411
- alias :add :get
412
- end
413
-
414
- class LicenseHash < Hash
415
-
416
- def get(*args, &block)
417
- license = if args.size == 1 && args[0].is_a?(License)
418
- args[0]
419
- else
420
- License.new(*args)
421
- end
422
- self[license.name] = license
423
- if block
424
- block.call(license)
425
- end
426
- license
427
- end
428
- alias :new :get
429
- alias :add :get
430
- end
431
-
432
- class PluginHash < Hash
433
-
434
- def adjust_key(name)
435
- name = name.to_s
436
- if (name =~ /\:/).nil?
437
- if [:jruby, :gem, :rspec, :rake, :rails2, :rails3, :gemify, :cucumber, :runit, :bundler].member? name.to_sym
438
- "de.saumya.mojo:#{name}-maven-plugin"
439
- else
440
- "maven-#{name}-plugin"
441
- end
442
- else
443
- name
444
- end
445
- end
446
-
447
- def key?(k)
448
- super( adjust_key(k).to_sym )
449
- end
450
-
451
- def get(*args, &block)
452
- case args.size
453
- when 3
454
- name = args[0] + ":" + args[1]
455
- version = args[2]
456
- when 2
457
- name = args[0].to_s
458
- version = args[1]
459
- when 1
460
- name = args[0].to_s
461
- else
462
- raise "need name"
463
- end
464
-
465
- name = adjust_key(name)
466
- group_id = name =~ /\:/ ? name.sub(/:.+$/, '') : nil
467
- artifact_id = name.sub(/^.+:/, '')
468
-
469
- k = "#{group_id}:#{artifact_id}".to_sym
470
- result = self[k]
471
- if result.nil?
472
- result = (self[k] = Plugin.new(group_id, artifact_id, version))
473
- end
474
- result.version = version if version
475
- if block
476
- block.call(result)
477
- end
478
- result
479
- end
480
- alias :new :get
481
- alias :add :get
482
-
483
- end
484
-
485
- class Developer < Tag
486
- tags :id, :name, :email
487
-
488
- def initialize(*args)
489
- case args.size
490
- when 1
491
- @email = args[0].sub(/.*</, '').sub(/>.*/, '')
492
- @name = args[0].sub(/\s*<.*/, '')
493
- when 2
494
- @name = args[0]
495
- @email = args[1]
496
- when 3
497
- @id = args[0]
498
- @name = args[1]
499
- @email = args[2]
500
- end
501
- @id = @email.sub(/@/, '_at_').gsub(/\./, '_dot_') unless @id
502
- self
503
- end
504
- end
505
-
506
- class License < Tag
507
- tags :name, :url, :distribution
508
-
509
- def initialize(*args)
510
- case args.size
511
- when 1
512
- @url = args[0]
513
- @name = args[0].sub(/.*\//, '').sub(/\.\w+/, '')
514
- when 2
515
- @url = args[0]
516
- @name = args[1]
517
- when 3
518
- @url = args[0]
519
- @name = args[1]
520
- @distribution = args[2]
521
- end
522
- @url = "./#{url}" unless @url =~ /^\.\//
523
- @distribution = "repo" unless @distribution
524
- self
525
- end
526
- end
527
-
528
- class Project < Tag
529
- tags :model_version, :group_id, :artifact_id, :version, :name, :packaging, :description, :url, :developers, :licenses, :repositories, :plugin_repositories, :dependencies, :dependency_management, :properties, :build, :profiles
530
-
531
- def initialize(group_id, artifact_id, version = "0.0.0", &block)
532
- super(:model_version => "4.0.0", :artifact_id => artifact_id, :group_id => group_id, :version => version)
533
- if block
534
- block.call(self)
535
- end
536
- self
537
- end
538
-
539
- def _name
540
- "project"
541
- end
542
-
543
- def name(val = nil)
544
- self.name = val if val
545
- @name
546
- end
547
-
548
- def name=(val)
549
- @name = "<![CDATA[#{val}]]>"
550
- end
551
-
552
- def description(val = nil)
553
- self.description = val if val
554
- @description
555
- end
556
-
557
- def description=(val)
558
- @description = "<![CDATA[#{val}]]>"
559
- end
560
-
561
- def execute_in_phase(phase, name = nil, &block)
562
- gem_plugin = plugin("gem")
563
- gem_plugin.in_phase(phase.to_s, name).execute_goal("execute_in_phase").with(:file => File.basename(current_file), :phase => phase)
564
- executions_in_phase[phase.to_s] = block
565
- gem_plugin
566
- end
567
-
568
- def executions_in_phase
569
- @executions_in_phase ||= {}
570
- end
571
-
572
- def plugin(*args, &block)
573
- build.plugins.get(*args, &block)
574
- end
575
-
576
- def plugin?(name)
577
- build.plugin?(name)
578
- end
579
-
580
- def profile(*args, &block)
581
- profiles.get(*args, &block)
582
- end
583
-
584
- def build
585
- @build ||= Build.new
586
- end
587
-
588
- def developers(&block)
589
- @developers ||= DeveloperHash.new
590
- if block
591
- block.call(@developers)
592
- end
593
- @developers
594
- end
595
-
596
- def licenses(&block)
597
- @licenses ||= LicenseHash.new
598
- if block
599
- block.call(@licenses)
600
- end
601
- @licenses
602
- end
603
-
604
- def repositories(&block)
605
- @repositories ||= ModelHash.new(Repository)
606
- if block
607
- block.call(@repositories)
608
- end
609
- @repositories
610
- end
611
-
612
- def repository(*args, &block)
613
- repositories.get(*args, &block)
614
- end
615
-
616
- def plugin_repositories(&block)
617
- @plugin_repositories ||= ModelHash.new(PluginRepository)
618
- if block
619
- block.call(@plugin_repositories)
620
- end
621
- @plugin_repositories
622
- end
623
-
624
- def plugin_repository(*args, &block)
625
- plugin_repositories.get(*args, &block)
626
- end
627
-
628
- def dependencies(&block)
629
- @dependencies ||= DepArray.new
630
- if block
631
- block.call(@dependencies)
632
- end
633
- @dependencies
634
- end
635
-
636
- def dependency_management(&block)
637
- @dependency_management ||= DependencyManagement.new
638
- if block
639
- block.call(@dependency_management.dependencies)
640
- end
641
- @dependency_management.dependencies
642
- end
643
-
644
- def properties
645
- @properties ||= Properties.new
646
- @properties.map
647
- end
648
-
649
- def properties=(props)
650
- if props.is_a? Hash
651
- @properties = Properties.new(props)
652
- else
653
- @properties = props
654
- end
655
- end
656
-
657
- def profiles(&block)
658
- @profiles ||= ModelHash.new(Profile)
659
- if block
660
- block.call(@profiles)
661
- end
662
- @profiles
663
- end
664
- end
665
-
666
- class HashTag < Tag
667
-
668
- def initialize(name, args = {})
669
- @name = name
670
- @props = args
671
- end
672
-
673
- def [](key, value)
674
- @props ||= {}
675
- @props[key] = value
676
- end
677
-
678
- def to_xml(buf = "", indent = "")
679
- buf << "#{indent}<#{@name}>\n"
680
- map_to_xml(buf, indent, @props)
681
- buf << "#{indent}</#{@name}>\n"
682
- end
683
-
684
- def map_to_xml(buf, indent, map)
685
- # sort the hash over the keys
686
- map.collect { |k,v| [k.to_s, v]}.sort.each do |k,v|
687
- case v
688
- when Hash
689
- buf << "#{indent} <#{k}>\n"
690
- map_to_xml(buf, indent + " ", v)
691
- buf << "#{indent} </#{k}>\n"
692
- when NamedArray
693
- buf << "#{indent} <#{k}>\n"
694
- v.each do|i|
695
- buf << "#{indent} <#{v.name}>\n"
696
- case i
697
- when Hash
698
- map_to_xml(buf, indent + " ", i)
699
- end
700
- buf << "#{indent} </#{v.name}>\n"
701
- end
702
- buf << "#{indent} </#{k}>\n"
703
- when Array
704
- buf << "#{indent} <#{k}>\n"
705
- singular = k.to_s.sub(/s$/, '')
706
- v.each do |i|
707
- buf << "#{indent} <#{singular}>#{i}</#{singular}>\n"
708
- end
709
- buf << "#{indent} </#{k}>\n"
710
- when /\n$/
711
- buf << "#{indent} <#{k}>#{v}"
712
- buf << "#{indent} </#{k}>\n"
713
- else
714
- buf << "#{indent} <#{k}>#{v}</#{k}>\n"
715
- end
716
- end
717
- end
718
- end
719
-
720
- class Configuration < HashTag
721
-
722
- def initialize(args = {})
723
- super("configuration", args)
724
- end
725
- end
726
-
727
- class Properties < HashTag
728
-
729
- def initialize(args = {})
730
- super("properties", args)
731
- end
732
-
733
- def map
734
- @props
735
- end
736
- end
737
-
738
- class ListItems < Tag
739
-
740
- def initialize(name = nil)
741
- @name = name
742
- end
743
-
744
- def add(item)
745
- @items ||= Array.new
746
- @items << item
747
- end
748
- alias :<< :add
749
-
750
- def to_xml(buf = "", indent = "")
751
- buf << "#{indent}<#{@name}>\n" if @name
752
- @items.each do |i|
753
- i.to_xml(buf, indent)
754
- end
755
- buf << "#{indent}</#{@name}>\n" if @name
756
- end
757
-
758
- end
759
-
760
- class OS < Tag
761
- tags :name, :family, :arch, :version
762
- end
763
-
764
- class Activation < Tag
765
- tags :activeByDefault, :property, :os
766
- def initialize
767
- super({})
768
- end
769
-
770
- def add_property(name, value)
771
- warn "deprecated, use 'property' instead"
772
- property(name, value)
773
- end
774
-
775
- def property(name, value)
776
- if name && value
777
- # TODO make more then one property
778
- raise "more then one property is not implemented: #{@property.name} => #{@property.value}" if @property
779
- @property ||= ListItems.new
780
- @property << Property.new(:name => name, :value => value)
781
- end
782
- self
783
- end
784
-
785
- def os(&block)
786
- @os ||= OS.new
787
- block.call(@os) if block
788
- @os
789
- end
790
-
791
- def as_default
792
- warn "deprecated, use 'by_default' instead"
793
- by_default
794
- end
795
-
796
- def by_default(value = true)
797
- @activeByDefault = value
798
- self
799
- end
800
- end
801
-
802
- class Property < Tag
803
- tags :name, :value
804
- end
805
-
806
- class Repository < Tag
807
- tags :id, :name, :url, :releases, :snapshots
808
- def initialize(id, &block)
809
- super({:id => id, :url => url})
810
- if block
811
- block.call(self)
812
- end
813
- self
814
- end
815
-
816
- def releases(args = {})
817
- @releases ||= args
818
- end
819
-
820
- def snapshots(args = {})
821
- @snapshots ||= args
822
- end
823
- end
824
-
825
- class PluginRepository < Repository
826
- tags :dummy
827
- def _name
828
- "pluginRepository"
829
- end
830
- end
831
- end
832
- end