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,56 +0,0 @@
1
- module JBundler
2
- module MavenUtil
3
-
4
- def to_coordinate(line)
5
- if line =~ /^\s*(jar|pom)\s/
6
-
7
- group_id, artifact_id, version, second_version = line.sub(/\s*[a-z]+\s+/, '').sub(/#.*/,'').gsub(/\s+/,'').gsub(/['"],/, ':').gsub(/['"]/, '').split(/:/)
8
- mversion = second_version ? to_version(version, second_version) : to_version(version)
9
- extension = line.strip.sub(/\s+.*/, '')
10
- "#{group_id}:#{artifact_id}:#{extension}:#{mversion}"
11
- end
12
- end
13
-
14
- def to_version(*args)
15
- if args.size == 0 || (args.size == 1 && args[0].nil?)
16
- "[0,)"
17
- else
18
- low, high = convert(args[0])
19
- low, high = convert(args[1], low, high) if args[1] =~ /[=~><]/
20
- if low == high
21
- low
22
- else
23
- "#{low || '[0'},#{high || ')'}"
24
- end
25
- end
26
- end
27
-
28
- private
29
-
30
- def convert(arg, low = nil, high = nil)
31
- if arg =~ /~>/
32
- val = arg.sub(/~>\s*/, '')
33
- last = val.sub(/\.[^.]+$/, '.99999')
34
- ["[#{val}", "#{last}]"]
35
- elsif arg =~ />=/
36
- val = arg.sub(/>=\s*/, '')
37
- ["[#{val}", (nil || high)]
38
- elsif arg =~ /<=/
39
- val = arg.sub(/<=\s*/, '')
40
- [(nil || low), "#{val}]"]
41
- # treat '!' the same way as '>' since maven can not describe such range
42
- elsif arg =~ /[!>]/
43
- val = arg.sub(/[!>]\s*/, '')
44
- ["(#{val}", (nil || high)]
45
- elsif arg =~ /</
46
- val = arg.sub(/<\s*/, '')
47
- [(nil || low), "#{val})"]
48
- elsif arg =~ /\=/
49
- val = arg.sub(/=\s*/, '')
50
- ["[" + val, val + '.0.0.0.0.1)']
51
- else
52
- [arg, arg]
53
- end
54
- end
55
- end
56
- end
@@ -1,247 +0,0 @@
1
- require File.join(File.dirname(__FILE__), "..", "tools", 'model.rb')
2
-
3
- module Maven
4
- module Model
5
-
6
- class DependencyArray < Array
7
- def <<(dep)
8
- d = detect { |item| item == dep }
9
- if d
10
- d.version = arg.version
11
- self
12
- else
13
- super
14
- end
15
- end
16
- alias :push :<<
17
- end
18
-
19
- class ExclusionArray < Array
20
- def <<(dep)
21
- excl = dep.is_a?(Exclusion) ? dep: Exclusion.new(dep)
22
- d = detect { |item| item == excl }
23
- if d
24
- delete d
25
- end
26
- super excl
27
- end
28
- alias :push :<<
29
- end
30
-
31
- class Coordinate < Maven::Tools::Tag
32
- tags :group_id, :artifact_id, :version
33
- def initialize(*args)
34
- @group_id, @artifact_id, @version = *coordinate(*args.flatten)
35
- end
36
-
37
- def coordinate(*args)
38
- if args[0] =~ /:/
39
- [args[0].sub(/:[^:]+$/, ''), args[0].sub(/.*:/, ''), version(*args[1, 2])]
40
- else
41
- [args[0], args[1], version(*args[2,3])]
42
- end
43
- end
44
-
45
- def version(*args)
46
- if args.size == 0
47
- nil
48
- else
49
- low, high = convert(args[0])
50
- low, high = convert(args[1], low, high) if args[1]
51
- if low == high
52
- low
53
- else
54
- "#{low || '[0.0.0'},#{high || ')'}"
55
- end
56
- end
57
- end
58
-
59
- def convert(arg, low = nil, high = nil)
60
- if arg =~ /~>/
61
- val = arg.sub(/~>\s*/, '')
62
- last = val.sub(/\.[^.]+$/, '.99999')
63
- ["[#{val}", "#{last}]"]
64
- elsif arg =~ />=/
65
- val = arg.sub(/>=\s*/, '')
66
- ["[#{val}", (nil || high)]
67
- elsif arg =~ /<=/
68
- val = arg.sub(/<=\s*/, '')
69
- [(nil || low), "#{val}]"]
70
- elsif arg =~ />/
71
- val = arg.sub(/>\s*/, '')
72
- ["(#{val}", (nil || high)]
73
- elsif arg =~ /</
74
- val = arg.sub(/<\s*/, '')
75
- [(nil || low), "#{val})"]
76
- else
77
- [arg, arg]
78
- end
79
- end
80
-
81
- def hash
82
- "#{group_id}:#{artifact_id}".hash
83
- end
84
-
85
- def ==(other)
86
- group_id == other.group_id && artifact_id == other.artifact_id
87
- end
88
- alias :eql? :==
89
- end
90
-
91
- class Exclusion < Maven::Tools::Tag
92
- tags :group_id, :artifact_id
93
- def initialize(*args)
94
- @group_id, @artifact_id = *coordinate(*args)
95
- end
96
-
97
- def coordinate(*args)
98
- case args.size
99
- when 1
100
- name = args[0].sub(/^mvn:/, '')
101
- if name =~ /:/
102
- [name.sub(/:[^:]+$/, ''), name.sub(/.*:/, '')]
103
- else
104
- ["rubygems", name]
105
- end
106
- else
107
- [args[0], args[1]]
108
- end
109
- end
110
-
111
- def hash
112
- "#{group_id}:#{artifact_id}".hash
113
- end
114
-
115
- def ==(other)
116
- group_id == other.group_id && artifact_id == other.artifact_id
117
- end
118
- alias :eql? :==
119
- end
120
-
121
- class Dependency < Coordinate
122
- tags :type, :scope, :classifier, :exclusions
123
- def initialize(type, *args)
124
- super(*args)
125
- @type = type
126
- end
127
-
128
- def hash
129
- "#{group_id}:#{artifact_id}:#{@type}".hash
130
- end
131
-
132
- def ==(other)
133
- super && @type == other.instance_variable_get(:@type)
134
- end
135
- alias :eql? :==
136
-
137
- def self.new_gem(gemname, *args)
138
- if gemname =~ /^mvn:/
139
- new(:maven_gem, gemname.sub(/^mvn:/, ''), *args)
140
- else
141
- new(:gem, "rubygems", gemname, *args)
142
- end
143
- end
144
-
145
- def self.new_jar(*args)
146
- new(:jar, *args)
147
- end
148
-
149
- def self.new_test_jar(*args)
150
- new(:test_jar, *args)
151
- end
152
-
153
- def exclusions(&block)
154
- @exclusions ||= ExclusionArray.new
155
- if block
156
- block.call(@exclusions)
157
- end
158
- @exclusions
159
- end
160
-
161
- end
162
-
163
- module Dependencies
164
-
165
- def jar?(*args)
166
- dependencies.member?(Dependency.new(:jar, *args))
167
- end
168
-
169
- def test_jar?(*args)
170
- dependencies.member?(Dependency.new(:test_jar, *args))
171
- end
172
-
173
- def gem?(*args)
174
- dependencies.member?(Dependency.new(:gem, *args))
175
- end
176
-
177
- def maven_gem?(*args)
178
- dependencies.member?(Dependency.new(:maven_gem, *args))
179
- end
180
-
181
- def dependencies(&block)
182
- @dependencies ||= DependencyArray.new
183
- if block
184
- block.call(@dependencies)
185
- end
186
- @dependencies
187
- end
188
-
189
- def lock_file
190
- nil
191
- end
192
-
193
- def add_dependency(dep, &block)
194
- dependencies << dep
195
- block.call(dep) if block
196
- dep
197
- end
198
- private :add_dependency
199
-
200
- def add_gem(*args, &block)
201
- if lock_file.nil? #|| !lock_file.hull.member?(args[0])
202
- args[1] = ">= 0.0.0" unless args[1]
203
- add_dependency(:gem, args, block)
204
- else
205
- result = add_dependency(:gem, args[0], block)
206
-
207
- # add its dependencies as well to have the version
208
- # determine by the dependencyManagement
209
- lock_file.dependency_hull(args[0]).map.each do |d|
210
- add_dependency(:gem, d[0], block)
211
- end
212
-
213
- result
214
- end
215
- end
216
- private :add_gem
217
-
218
- def jar(*args, &block)
219
- if args.last.is_a?(Hash)
220
- raise "hash not allowed for jar"
221
- end
222
- add_dependency(:jar, args, block)
223
- end
224
-
225
- def test_jar(*args, &block)
226
- if args.last.is_a?(Hash)
227
- raise "hash not allowed for test_jar"
228
- end
229
- add_dependency(:test_jar, args, block)
230
- end
231
-
232
- def gem(*args, &block)
233
- if args.last.is_a?(Hash)
234
- raise "hash not allowed in that context"
235
- end
236
- add_gem(args, block)
237
- end
238
-
239
- def maven_gem(*args, &block)
240
- if args.last.is_a?(Hash)
241
- raise "hash not allowed in that context"
242
- end
243
- add_dependency(:maven_gem, args, block)
244
- end
245
- end
246
- end
247
- end
@@ -1,528 +0,0 @@
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