maven-tools 0.29.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,528 @@
1
+ # TODO make nice require after ruby-maven uses the same ruby files
2
+ require File.join(File.dirname(__FILE__), 'dependencies.rb')
3
+ #require 'maven/model/dependencies'
4
+
5
+ module Maven
6
+ module Model
7
+
8
+ class Build < Tag
9
+ tags :source_directory, :script_source_directory, :test_source_directory, :output_directory, :test_output_directory, :default_goal, :directory, :final_name, :plugins, :plugin_management
10
+
11
+ def plugins(&block)
12
+ @plugins ||= PluginHash.new
13
+ if block
14
+ block.call(@plugins)
15
+ end
16
+ @plugins
17
+ end
18
+
19
+ def plugin?(name)
20
+ plugins.key?(name)
21
+ end
22
+
23
+ def plugin_management(&block)
24
+ @plugin_management ||= PluginManagement.new
25
+ if block
26
+ block.call(@plugin_management)
27
+ end
28
+ @plugin_management
29
+ end
30
+
31
+ def to_xml(buf = "", indent = "")
32
+ if @final_name.nil? && (@plugins.nil? || @plugins.size == 0) && @plugin_management.nil? #TODO check the rest
33
+ ""
34
+ else
35
+ super
36
+ end
37
+ end
38
+ end
39
+
40
+ class PluginManagement < Tag
41
+ tags :plugins
42
+
43
+ def plugins(&block)
44
+ @plugins ||= PluginHash.new
45
+ if block
46
+ block.call(@plugins)
47
+ end
48
+ @plugins
49
+ end
50
+
51
+ def plugin?(name)
52
+ plugins.key?(name)
53
+ end
54
+
55
+ def to_xml(buf = "", indent = "")
56
+ if @plugins.nil? || @plugins.size == 0
57
+ ""
58
+ else
59
+ super
60
+ end
61
+ end
62
+
63
+ def _name
64
+ "pluginManagement"
65
+ end
66
+ end
67
+
68
+ class Plugin < Coordinate
69
+ tags :extensions, :configuration, :executions
70
+
71
+ include Dependencies
72
+
73
+ def initialize(*args, &block)
74
+ super(*args)
75
+ raise "plugin version must be a concrete version" if version =~ /^[\[\(].+,.*[\]\)]$/
76
+ if block
77
+ block.call(self)
78
+ end
79
+ self
80
+ end
81
+
82
+ def with(config)
83
+ self.configuration config
84
+ end
85
+
86
+ def in_phase(phase, name = nil, &block)
87
+ name = "in_phase_#{phase.to_s.gsub(/-/,'_')}" unless name
88
+ self.executions.get(name) do |exe|
89
+ exe.phase = phase
90
+ block.call(exe) if block
91
+ exe
92
+ end
93
+ end
94
+
95
+ def execute_goal(goal)
96
+ execution.execute_goal(goal)
97
+ end
98
+
99
+ def executions
100
+ @executions ||= ModelHash.new(Execution)
101
+ end
102
+
103
+ def execution(name = nil, &block)
104
+ executions.get(name, &block)
105
+ end
106
+
107
+ def configuration(c = nil)
108
+ @configuration = Configuration.new(c) if c
109
+ @configuration ||= Configuration.new({})
110
+ end
111
+ end
112
+
113
+ class Execution < Tag
114
+ tags :id, :phase, :goals, :inherited, :configuration
115
+
116
+ def initialize(id = nil)
117
+ self.id id if id
118
+ end
119
+
120
+ def configuration(c = nil)
121
+ @configuration = Configuration.new(c) if c
122
+ @configuration ||= Configuration.new({})
123
+ end
124
+
125
+ def execute_goal(g)
126
+ self.goals = g
127
+ self
128
+ end
129
+
130
+ def with(config)
131
+ self.configuration config
132
+ end
133
+
134
+ def goals
135
+ @goals ||= []
136
+ end
137
+
138
+ def goals=(goals)
139
+ @goals = goals.is_a?(Array) ? goals: [goals]
140
+ end
141
+ end
142
+
143
+ class DependencyManagement < Tag
144
+
145
+ include Dependencies
146
+
147
+ def _name
148
+ "dependencyManagement"
149
+ end
150
+ end
151
+
152
+ class Profile < Tag
153
+ tags :id, :activation, :repositories, :plugin_repositories
154
+
155
+ include Dependencies
156
+
157
+ tags :dependency_management, :properties, :build
158
+
159
+ def initialize(id, &block)
160
+ self.id id
161
+ if block
162
+ block.call(self)
163
+ end
164
+ self
165
+ end
166
+
167
+ def properties
168
+ @properties ||= Properties.new
169
+ @properties.map
170
+ end
171
+
172
+ def properties=(props)
173
+ if props.is_a? Hash
174
+ @properties = Properties.new(props)
175
+ else
176
+ @properties = props
177
+ end
178
+ end
179
+
180
+ def build
181
+ @build ||= Build.new
182
+ end
183
+
184
+ def activation(name = nil, value = nil, &block)
185
+ @activation ||= Activation.new
186
+ if name || value
187
+ warn "deprecated, use 'property_activation' instead"
188
+ @activation.property(name, value)
189
+ else
190
+ block.call(@activation) if block
191
+ @activation
192
+ end
193
+ end
194
+
195
+ def repositories(&block)
196
+ @repositories ||= ModelHash.new(Repository)
197
+ if block
198
+ block.call(@repositories)
199
+ end
200
+ @repositories
201
+ end
202
+
203
+ def repository(id, url = nil, &block)
204
+ repo = repositories.get(id, &block)
205
+ repo.url = url if url
206
+ repo
207
+ end
208
+
209
+ def plugin_repositories(&block)
210
+ @plugin_repositories ||= ModelHash.new(PluginRepository)
211
+ if block
212
+ block.call(@plugin_repositories)
213
+ end
214
+ @plugin_repositories
215
+ end
216
+
217
+ def plugin_repository(id, url = nil, &block)
218
+ repo = plugin_repositories.get(id, &block)
219
+ repo.url = url if url
220
+ repo
221
+ end
222
+
223
+ def plugin(*args, &block)
224
+ build.plugins.get(*args, &block)
225
+ end
226
+
227
+ def dependency_management(&block)
228
+ @dependency_management ||= DependencyManagement.new
229
+ if block
230
+ block.call(@dependency_management)
231
+ end
232
+ @dependency_management
233
+ end
234
+ end
235
+
236
+ class Developer < Tag
237
+ tags :id, :name, :email
238
+
239
+ def initialize(*args)
240
+ case args.size
241
+ when 1
242
+ @email = args[0].sub(/.*</, '').sub(/>.*/, '')
243
+ @name = args[0].sub(/\s*<.*/, '')
244
+ when 2
245
+ @name = args[0]
246
+ @email = args[1]
247
+ when 3
248
+ @id = args[0]
249
+ @name = args[1]
250
+ @email = args[2]
251
+ end
252
+ @email = @email[0] if @email.is_a? Array # this produces a partial list
253
+ @id = @email.sub(/@/, '_at_').gsub(/\./, '_dot_') unless @id
254
+ self
255
+ end
256
+ end
257
+
258
+ class License < Tag
259
+ tags :name, :url, :distribution
260
+
261
+ def initialize(*args)
262
+ case args.size
263
+ when 1
264
+ @url = args[0]
265
+ @name = args[0].sub(/.*\//, '').sub(/\.\w+/, '')
266
+ when 2
267
+ @url = args[0]
268
+ @name = args[1]
269
+ when 3
270
+ @url = args[0]
271
+ @name = args[1]
272
+ @distribution = args[2]
273
+ end
274
+ @url = "./#{url}" unless @url =~ /^\.\// || @url =~ /^https?:\/\//
275
+ @distribution = "repo" unless @distribution
276
+ self
277
+ end
278
+ end
279
+
280
+
281
+ class Project < Coordinate
282
+ prepend_tags :model_version, :parent
283
+
284
+ tags :name, :packaging, :description, :url, :developers, :licenses, :repositories, :plugin_repositories
285
+
286
+ include Dependencies
287
+
288
+ tags :dependency_management, :properties, :build, :profiles
289
+
290
+ def initialize(*args, &block)
291
+ super(*args)
292
+ model_version "4.0.0"
293
+ if block
294
+ block.call(self)
295
+ end
296
+ self
297
+ end
298
+
299
+ def _name
300
+ 'project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"'
301
+ end
302
+
303
+ def version(val = nil)
304
+ self.version = val if val
305
+ @version ||= (@parent.nil? ? '0.0.0' : @parent.version)
306
+ end
307
+
308
+ def name(val = nil)
309
+ self.name = val if val
310
+ @name
311
+ end
312
+
313
+ def name=(val)
314
+ @name = "<![CDATA[#{val}]]>"
315
+ end
316
+
317
+ def description(val = nil)
318
+ self.description = val if val
319
+ @description
320
+ end
321
+
322
+ def description=(val)
323
+ @description = "<![CDATA[#{val}]]>"
324
+ end
325
+
326
+ def parent(*args, &block)
327
+ @parent ||= Parent.new(*args)
328
+ @parent.call(block) if block
329
+ @parent
330
+ end
331
+
332
+ def execute_in_phase(phase, name = nil, &block)
333
+ gem_plugin = plugin("gem")
334
+ gem_plugin.in_phase(phase.to_s, name).execute_goal("execute_in_phase").with(:file => File.basename(current_file), :phase => phase)
335
+ executions_in_phase[phase.to_s] = block
336
+ gem_plugin
337
+ end
338
+
339
+ def executions_in_phase
340
+ @executions_in_phase ||= {}
341
+ end
342
+
343
+ def plugin(*args, &block)
344
+ build.plugins.get(*args, &block)
345
+ end
346
+
347
+ def plugin?(name)
348
+ build.plugin?(name)
349
+ end
350
+
351
+ def profile(*args, &block)
352
+ profiles.get(*args, &block)
353
+ end
354
+
355
+ def build
356
+ @build ||= Build.new
357
+ end
358
+
359
+ def developers(&block)
360
+ @developers ||= DeveloperHash.new
361
+ if block
362
+ block.call(@developers)
363
+ end
364
+ @developers
365
+ end
366
+
367
+ def licenses(&block)
368
+ @licenses ||= LicenseHash.new
369
+ if block
370
+ block.call(@licenses)
371
+ end
372
+ @licenses
373
+ end
374
+
375
+ def repositories(&block)
376
+ @repositories ||= ModelHash.new(Repository)
377
+ if block
378
+ block.call(@repositories)
379
+ end
380
+ @repositories
381
+ end
382
+
383
+ def repository(id, url = nil, &block)
384
+ repo = repositories.get(id, &block)
385
+ repo.url = url if url
386
+ repo
387
+ end
388
+
389
+ def plugin_repositories(&block)
390
+ @plugin_repositories ||= ModelHash.new(PluginRepository)
391
+ if block
392
+ block.call(@plugin_repositories)
393
+ end
394
+ @plugin_repositories
395
+ end
396
+
397
+ def plugin_repository(id, url = nil, &block)
398
+ repo = plugin_repositories.get(id, &block)
399
+ repo.url = url if url
400
+ repo
401
+ end
402
+
403
+ def dependency_management(&block)
404
+ @dependency_management ||= DependencyManagement.new
405
+ if block
406
+ block.call(@dependency_management)
407
+ end
408
+ @dependency_management
409
+ end
410
+
411
+ def properties
412
+ @properties ||= Properties.new
413
+ @properties.map
414
+ end
415
+
416
+ def properties=(props)
417
+ if props.is_a? Hash
418
+ @properties = Properties.new(props)
419
+ else
420
+ @properties = props
421
+ end
422
+ end
423
+
424
+ def profile(id, &block)
425
+ profiles.get(id, &block)
426
+ end
427
+
428
+ def profiles(&block)
429
+ @profiles ||= ModelHash.new(Profile)
430
+ if block
431
+ block.call(@profiles)
432
+ end
433
+ @profiles
434
+ end
435
+ end
436
+
437
+ class Configuration < HashTag
438
+
439
+ def initialize(args = {})
440
+ super("configuration", args)
441
+ end
442
+ end
443
+
444
+ class Properties < HashTag
445
+
446
+ def initialize(args = {})
447
+ super("properties", args)
448
+ end
449
+
450
+ def map
451
+ @props
452
+ end
453
+ end
454
+
455
+ class OS < Tag
456
+ tags :name, :family, :arch, :version
457
+ end
458
+
459
+ class Activation < Tag
460
+ tags :activeByDefault, :property, :os
461
+ def initialize
462
+ super({})
463
+ end
464
+
465
+ def add_property(name, value)
466
+ warn "deprecated, use 'property' instead"
467
+ property(name, value)
468
+ end
469
+
470
+ def property(name, value)
471
+ if name && value
472
+ # TODO make more then one property
473
+ raise "more then one property is not implemented: #{@property.name} => #{@property.value}" if @property
474
+ @property ||= ListItems.new
475
+ @property << Property.new(name, value)
476
+ end
477
+ self
478
+ end
479
+
480
+ def os(&block)
481
+ @os ||= OS.new
482
+ block.call(@os) if block
483
+ @os
484
+ end
485
+
486
+ def by_default(value = true)
487
+ @activeByDefault = value
488
+ self
489
+ end
490
+ end
491
+
492
+ class Property < Tag
493
+ tags :name, :value
494
+
495
+ def initialize(name, value)
496
+ self.name name
497
+ self.value value
498
+ end
499
+ end
500
+
501
+ class Repository < Tag
502
+ tags :id, :name, :url, :releases, :snapshots
503
+ def initialize(id, &block)
504
+ super({})
505
+ self.id id
506
+ if block
507
+ block.call(self)
508
+ end
509
+ self
510
+ end
511
+
512
+ def releases(args = {})
513
+ @releases ||= args
514
+ end
515
+
516
+ def snapshots(args = {})
517
+ @snapshots ||= args
518
+ end
519
+ end
520
+
521
+ class PluginRepository < Repository
522
+ tags :dummy
523
+ def _name
524
+ "pluginRepository"
525
+ end
526
+ end
527
+ end
528
+ end